Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

21 May, 2024: Computers section is temporarily disabled for maintenance. It will take several days before it's back.


devel / comp.lang.prolog / Goal reordering or advanced program transformation?

SubjectAuthor
* Goal reordering or advanced program transformation?Mostowski Collapse
`* Re: Goal reordering or advanced program transformation?Mostowski Collapse
 `* Re: Goal reordering or advanced program transformation?Mostowski Collapse
  `* Re: Goal reordering or advanced program transformation?Mostowski Collapse
   `- Re: Goal reordering or advanced program transformation?Mostowski Collapse

1
Goal reordering or advanced program transformation?

<64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=803&group=comp.lang.prolog#803

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:ad4:4973:: with SMTP id p19mr6212467qvy.30.1629246185621; Tue, 17 Aug 2021 17:23:05 -0700 (PDT)
X-Received: by 2002:a25:2e42:: with SMTP id b2mr8045138ybn.28.1629246185433; Tue, 17 Aug 2021 17:23:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Tue, 17 Aug 2021 17:23:05 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com>
Subject: Goal reordering or advanced program transformation?
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Wed, 18 Aug 2021 00:23:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 30
 by: Mostowski Collapse - Wed, 18 Aug 2021 00:23 UTC

It is often said that compared to SQL, Prolog lacks
goal reordering. But is it true that query planning boils
down to goal reordering? I found an example

which is more than goal reordering. You don't get anc2/2
from anc/2 by simple goal reordering, even if both were
formulated with edge/2. Take this example here (*):

setup :- between(1,1024,N), M is N//2, assertz(edge(M,N)), fail.
setup :- edge(M,N), assertz(edge2(N,M)), fail.
setup.

anc(X,Y) :- edge(X, Y).
anc(X,Y) :- edge(X, Z), anc(Z, Y).

anc2(X,Y) :- edge2(Y, X).
anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).

Its the same transitive closure, only once computed from
the left and the other time computed from the right:

?- time((between(1,1000,_), anc(0,1024), fail; true)).
% 3,076,001 inferences, 0.178 CPU in 0.181 seconds (98% CPU, 17298884 Lips)
true.

?- time((between(1,1000,_), anc2(0,1024), fail; true)).
% 37,001 inferences, 0.003 CPU in 0.003 seconds (99% CPU, 14659667 Lips)
true.

(*) I am using edge/2 and edge2/2 so that the testing also works
for a Prolog system that has only first argument indexing.

Re: Goal reordering or advanced program transformation?

<6db70a01-92b1-4b99-ae5b-85df6c392b5cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=804&group=comp.lang.prolog#804

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a37:2f47:: with SMTP id v68mr4955302qkh.190.1629396042644;
Thu, 19 Aug 2021 11:00:42 -0700 (PDT)
X-Received: by 2002:a25:9241:: with SMTP id e1mr20674156ybo.38.1629396042407;
Thu, 19 Aug 2021 11:00:42 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Thu, 19 Aug 2021 11:00:42 -0700 (PDT)
In-Reply-To: <64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6db70a01-92b1-4b99-ae5b-85df6c392b5cn@googlegroups.com>
Subject: Re: Goal reordering or advanced program transformation?
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Thu, 19 Aug 2021 18:00:42 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mostowski Collapse - Thu, 19 Aug 2021 18:00 UTC

Woa! The JavaScript JIT compiler is quite impressive. I now
ported Dogelog runtime to Python as well, so that I can compare
JavaScript and Python, and tested without clause indexing:

between(L,H,L) :- L =< H.
between(L,H,X) :- L < H, Y is L+1, between(Y,H,X).

setup :- between(1,255,N), M is N//2, assertz(edge(M,N)), fail.
setup :- edge(M,N), assertz(edge2(N,M)), fail.
setup.

anc(X,Y) :- edge(X, Y).
anc(X,Y) :- edge(X, Z), anc(Z, Y).

anc2(X,Y) :- edge2(Y, X).
anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).

:- setup.
:- time((between(1,10,_), anc2(0,255), fail; true)).
:- time((between(1,10,_), anc(0,255), fail; true)).

The results are:

/* Python 3.10.0rc1 */
% Wall 188 ms, trim 0 ms
% Wall 5537 ms, trim 0 ms

/* JavaScript Chrome 92.0.4515.159 */
% Wall 5 ms, trim 0 ms
% Wall 147 ms, trim 0 ms

Mostowski Collapse schrieb am Mittwoch, 18. August 2021 um 02:23:06 UTC+2:
> It is often said that compared to SQL, Prolog lacks
> goal reordering. But is it true that query planning boils
> down to goal reordering? I found an example
>
> which is more than goal reordering. You don't get anc2/2
> from anc/2 by simple goal reordering, even if both were
> formulated with edge/2. Take this example here (*):
>
> setup :- between(1,1024,N), M is N//2, assertz(edge(M,N)), fail.
> setup :- edge(M,N), assertz(edge2(N,M)), fail.
> setup.
>
> anc(X,Y) :- edge(X, Y).
> anc(X,Y) :- edge(X, Z), anc(Z, Y).
>
> anc2(X,Y) :- edge2(Y, X).
> anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
>
> Its the same transitive closure, only once computed from
> the left and the other time computed from the right:
>
> ?- time((between(1,1000,_), anc(0,1024), fail; true)).
> % 3,076,001 inferences, 0.178 CPU in 0.181 seconds (98% CPU, 17298884 Lips)
> true.
>
> ?- time((between(1,1000,_), anc2(0,1024), fail; true)).
> % 37,001 inferences, 0.003 CPU in 0.003 seconds (99% CPU, 14659667 Lips)
> true.
>
> (*) I am using edge/2 and edge2/2 so that the testing also works
> for a Prolog system that has only first argument indexing.

Re: Goal reordering or advanced program transformation?

<ed715013-b5e3-46ca-ad48-051c1f3132e1n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=805&group=comp.lang.prolog#805

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a37:6447:: with SMTP id y68mr4826770qkb.296.1629396107575; Thu, 19 Aug 2021 11:01:47 -0700 (PDT)
X-Received: by 2002:a25:aaa4:: with SMTP id t33mr19968908ybi.256.1629396107369; Thu, 19 Aug 2021 11:01:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Thu, 19 Aug 2021 11:01:47 -0700 (PDT)
In-Reply-To: <6db70a01-92b1-4b99-ae5b-85df6c392b5cn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com> <6db70a01-92b1-4b99-ae5b-85df6c392b5cn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ed715013-b5e3-46ca-ad48-051c1f3132e1n@googlegroups.com>
Subject: Re: Goal reordering or advanced program transformation?
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Thu, 19 Aug 2021 18:01:47 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 73
 by: Mostowski Collapse - Thu, 19 Aug 2021 18:01 UTC

Thats a factor 37.8 faster! I tested the a variant of
the Albufeira instructions Prolog VM aka ZIP, which
was also the inspiration for SWI-Prolog.

Open Source:

The Python Version of the Dogelog Runtime
https://github.com/jburse/dogelog-moon/tree/main/devel/runtimepy

The Python Test Harness
https://gist.github.com/jburse/bf6c01c7524f2611d606cb88983da9d6#file-test-py

Mostowski Collapse schrieb am Donnerstag, 19. August 2021 um 20:00:43 UTC+2:
> Woa! The JavaScript JIT compiler is quite impressive. I now
> ported Dogelog runtime to Python as well, so that I can compare
> JavaScript and Python, and tested without clause indexing:
>
> between(L,H,L) :- L =< H.
> between(L,H,X) :- L < H, Y is L+1, between(Y,H,X).
>
> setup :- between(1,255,N), M is N//2, assertz(edge(M,N)), fail.
> setup :- edge(M,N), assertz(edge2(N,M)), fail.
> setup.
>
> anc(X,Y) :- edge(X, Y).
> anc(X,Y) :- edge(X, Z), anc(Z, Y).
>
> anc2(X,Y) :- edge2(Y, X).
> anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
> :- setup.
> :- time((between(1,10,_), anc2(0,255), fail; true)).
> :- time((between(1,10,_), anc(0,255), fail; true)).
>
> The results are:
>
> /* Python 3.10.0rc1 */
> % Wall 188 ms, trim 0 ms
> % Wall 5537 ms, trim 0 ms
>
> /* JavaScript Chrome 92.0.4515.159 */
> % Wall 5 ms, trim 0 ms
> % Wall 147 ms, trim 0 ms
> Mostowski Collapse schrieb am Mittwoch, 18. August 2021 um 02:23:06 UTC+2:
> > It is often said that compared to SQL, Prolog lacks
> > goal reordering. But is it true that query planning boils
> > down to goal reordering? I found an example
> >
> > which is more than goal reordering. You don't get anc2/2
> > from anc/2 by simple goal reordering, even if both were
> > formulated with edge/2. Take this example here (*):
> >
> > setup :- between(1,1024,N), M is N//2, assertz(edge(M,N)), fail.
> > setup :- edge(M,N), assertz(edge2(N,M)), fail.
> > setup.
> >
> > anc(X,Y) :- edge(X, Y).
> > anc(X,Y) :- edge(X, Z), anc(Z, Y).
> >
> > anc2(X,Y) :- edge2(Y, X).
> > anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
> >
> > Its the same transitive closure, only once computed from
> > the left and the other time computed from the right:
> >
> > ?- time((between(1,1000,_), anc(0,1024), fail; true)).
> > % 3,076,001 inferences, 0.178 CPU in 0.181 seconds (98% CPU, 17298884 Lips)
> > true.
> >
> > ?- time((between(1,1000,_), anc2(0,1024), fail; true)).
> > % 37,001 inferences, 0.003 CPU in 0.003 seconds (99% CPU, 14659667 Lips)
> > true.
> >
> > (*) I am using edge/2 and edge2/2 so that the testing also works
> > for a Prolog system that has only first argument indexing.

Re: Goal reordering or advanced program transformation?

<ebd5fc26-1df1-43da-9a4b-1788036e5a9fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=806&group=comp.lang.prolog#806

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:aed:20a2:: with SMTP id 31mr14169796qtb.69.1629397148356;
Thu, 19 Aug 2021 11:19:08 -0700 (PDT)
X-Received: by 2002:a25:4086:: with SMTP id n128mr19552918yba.247.1629397148229;
Thu, 19 Aug 2021 11:19:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Thu, 19 Aug 2021 11:19:08 -0700 (PDT)
In-Reply-To: <ed715013-b5e3-46ca-ad48-051c1f3132e1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com>
<6db70a01-92b1-4b99-ae5b-85df6c392b5cn@googlegroups.com> <ed715013-b5e3-46ca-ad48-051c1f3132e1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ebd5fc26-1df1-43da-9a4b-1788036e5a9fn@googlegroups.com>
Subject: Re: Goal reordering or advanced program transformation?
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Thu, 19 Aug 2021 18:19:08 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mostowski Collapse - Thu, 19 Aug 2021 18:19 UTC

So this week , was coding Python as if there
were no tomorrow, only to arrive at the conclusion:

- Ha Ha Python is useless

Lets see. Next I will try to bring first argument clause
indexing also to the Python version and redo the

Datalog-ish benchmark.

Mostowski Collapse schrieb am Donnerstag, 19. August 2021 um 20:01:48 UTC+2:
> Thats a factor 37.8 faster! I tested the a variant of
> the Albufeira instructions Prolog VM aka ZIP, which
> was also the inspiration for SWI-Prolog.
>
> Open Source:
>
> The Python Version of the Dogelog Runtime
> https://github.com/jburse/dogelog-moon/tree/main/devel/runtimepy
>
> The Python Test Harness
> https://gist.github.com/jburse/bf6c01c7524f2611d606cb88983da9d6#file-test-py
> Mostowski Collapse schrieb am Donnerstag, 19. August 2021 um 20:00:43 UTC+2:
> > Woa! The JavaScript JIT compiler is quite impressive. I now
> > ported Dogelog runtime to Python as well, so that I can compare
> > JavaScript and Python, and tested without clause indexing:
> >
> > between(L,H,L) :- L =< H.
> > between(L,H,X) :- L < H, Y is L+1, between(Y,H,X).
> >
> > setup :- between(1,255,N), M is N//2, assertz(edge(M,N)), fail.
> > setup :- edge(M,N), assertz(edge2(N,M)), fail.
> > setup.
> >
> > anc(X,Y) :- edge(X, Y).
> > anc(X,Y) :- edge(X, Z), anc(Z, Y).
> >
> > anc2(X,Y) :- edge2(Y, X).
> > anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
> > :- setup.
> > :- time((between(1,10,_), anc2(0,255), fail; true)).
> > :- time((between(1,10,_), anc(0,255), fail; true)).
> >
> > The results are:
> >
> > /* Python 3.10.0rc1 */
> > % Wall 188 ms, trim 0 ms
> > % Wall 5537 ms, trim 0 ms
> >
> > /* JavaScript Chrome 92.0.4515.159 */
> > % Wall 5 ms, trim 0 ms
> > % Wall 147 ms, trim 0 ms
> > Mostowski Collapse schrieb am Mittwoch, 18. August 2021 um 02:23:06 UTC+2:
> > > It is often said that compared to SQL, Prolog lacks
> > > goal reordering. But is it true that query planning boils
> > > down to goal reordering? I found an example
> > >
> > > which is more than goal reordering. You don't get anc2/2
> > > from anc/2 by simple goal reordering, even if both were
> > > formulated with edge/2. Take this example here (*):
> > >
> > > setup :- between(1,1024,N), M is N//2, assertz(edge(M,N)), fail.
> > > setup :- edge(M,N), assertz(edge2(N,M)), fail.
> > > setup.
> > >
> > > anc(X,Y) :- edge(X, Y).
> > > anc(X,Y) :- edge(X, Z), anc(Z, Y).
> > >
> > > anc2(X,Y) :- edge2(Y, X).
> > > anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
> > >
> > > Its the same transitive closure, only once computed from
> > > the left and the other time computed from the right:
> > >
> > > ?- time((between(1,1000,_), anc(0,1024), fail; true)).
> > > % 3,076,001 inferences, 0.178 CPU in 0.181 seconds (98% CPU, 17298884 Lips)
> > > true.
> > >
> > > ?- time((between(1,1000,_), anc2(0,1024), fail; true)).
> > > % 37,001 inferences, 0.003 CPU in 0.003 seconds (99% CPU, 14659667 Lips)
> > > true.
> > >
> > > (*) I am using edge/2 and edge2/2 so that the testing also works
> > > for a Prolog system that has only first argument indexing.

Re: Goal reordering or advanced program transformation?

<b00b2651-fc6d-4981-894f-7b1f61f108f4n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=807&group=comp.lang.prolog#807

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a05:6214:194b:: with SMTP id q11mr16919294qvk.33.1629410092297;
Thu, 19 Aug 2021 14:54:52 -0700 (PDT)
X-Received: by 2002:a25:541:: with SMTP id 62mr20487485ybf.367.1629410092085;
Thu, 19 Aug 2021 14:54:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Thu, 19 Aug 2021 14:54:51 -0700 (PDT)
In-Reply-To: <ebd5fc26-1df1-43da-9a4b-1788036e5a9fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.57.53.70; posting-account=UjEXBwoAAAAOk5fiB8WdHvZddFg9nJ9r
NNTP-Posting-Host: 77.57.53.70
References: <64ee7b32-1a38-4185-b371-9fb1248ffeddn@googlegroups.com>
<6db70a01-92b1-4b99-ae5b-85df6c392b5cn@googlegroups.com> <ed715013-b5e3-46ca-ad48-051c1f3132e1n@googlegroups.com>
<ebd5fc26-1df1-43da-9a4b-1788036e5a9fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b00b2651-fc6d-4981-894f-7b1f61f108f4n@googlegroups.com>
Subject: Re: Goal reordering or advanced program transformation?
From: bursejan@gmail.com (Mostowski Collapse)
Injection-Date: Thu, 19 Aug 2021 21:54:52 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mostowski Collapse - Thu, 19 Aug 2021 21:54 UTC

Maybe Python has some niche like Julia, in that its
possible to override or some such the basic operations
(+)/2, etc.. and do some amazing autodiff stuff.

uncertainties
https://pythonhosted.org/uncertainties/user_guide.html

And other niche might be, Python itself is a fairy tale:

Learn Python through Nursery Rhymes & Fairy Tales
https://www.kickstarter.com/projects/914595512/learn-python-through-nursery-rhymes-and-fairy-tales

LoL

P.S.: Didn't we do autodiff somewhere with Prolog? Isn't
there a some years old thread on SWI-Prolog discourse
about autodiff and how to do it in Prolog?

Mostowski Collapse schrieb am Donnerstag, 19. August 2021 um 20:19:08 UTC+2:
> So this week , was coding Python as if there
> were no tomorrow, only to arrive at the conclusion:
>
> - Ha Ha Python is useless
>
> Lets see. Next I will try to bring first argument clause
> indexing also to the Python version and redo the
>
> Datalog-ish benchmark.
> Mostowski Collapse schrieb am Donnerstag, 19. August 2021 um 20:01:48 UTC+2:
> > Thats a factor 37.8 faster! I tested the a variant of
> > the Albufeira instructions Prolog VM aka ZIP, which
> > was also the inspiration for SWI-Prolog.
> >
> > Open Source:
> >
> > The Python Version of the Dogelog Runtime
> > https://github.com/jburse/dogelog-moon/tree/main/devel/runtimepy
> >
> > The Python Test Harness
> > https://gist.github.com/jburse/bf6c01c7524f2611d606cb88983da9d6#file-test-py
> > Mostowski Collapse schrieb am Donnerstag, 19. August 2021 um 20:00:43 UTC+2:
> > > Woa! The JavaScript JIT compiler is quite impressive. I now
> > > ported Dogelog runtime to Python as well, so that I can compare
> > > JavaScript and Python, and tested without clause indexing:
> > >
> > > between(L,H,L) :- L =< H.
> > > between(L,H,X) :- L < H, Y is L+1, between(Y,H,X).
> > >
> > > setup :- between(1,255,N), M is N//2, assertz(edge(M,N)), fail.
> > > setup :- edge(M,N), assertz(edge2(N,M)), fail.
> > > setup.
> > >
> > > anc(X,Y) :- edge(X, Y).
> > > anc(X,Y) :- edge(X, Z), anc(Z, Y).
> > >
> > > anc2(X,Y) :- edge2(Y, X).
> > > anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
> > > :- setup.
> > > :- time((between(1,10,_), anc2(0,255), fail; true)).
> > > :- time((between(1,10,_), anc(0,255), fail; true)).
> > >
> > > The results are:
> > >
> > > /* Python 3.10.0rc1 */
> > > % Wall 188 ms, trim 0 ms
> > > % Wall 5537 ms, trim 0 ms
> > >
> > > /* JavaScript Chrome 92.0.4515.159 */
> > > % Wall 5 ms, trim 0 ms
> > > % Wall 147 ms, trim 0 ms
> > > Mostowski Collapse schrieb am Mittwoch, 18. August 2021 um 02:23:06 UTC+2:
> > > > It is often said that compared to SQL, Prolog lacks
> > > > goal reordering. But is it true that query planning boils
> > > > down to goal reordering? I found an example
> > > >
> > > > which is more than goal reordering. You don't get anc2/2
> > > > from anc/2 by simple goal reordering, even if both were
> > > > formulated with edge/2. Take this example here (*):
> > > >
> > > > setup :- between(1,1024,N), M is N//2, assertz(edge(M,N)), fail.
> > > > setup :- edge(M,N), assertz(edge2(N,M)), fail.
> > > > setup.
> > > >
> > > > anc(X,Y) :- edge(X, Y).
> > > > anc(X,Y) :- edge(X, Z), anc(Z, Y).
> > > >
> > > > anc2(X,Y) :- edge2(Y, X).
> > > > anc2(X,Y) :- edge2(Y, Z), anc2(X, Z).
> > > >
> > > > Its the same transitive closure, only once computed from
> > > > the left and the other time computed from the right:
> > > >
> > > > ?- time((between(1,1000,_), anc(0,1024), fail; true)).
> > > > % 3,076,001 inferences, 0.178 CPU in 0.181 seconds (98% CPU, 17298884 Lips)
> > > > true.
> > > >
> > > > ?- time((between(1,1000,_), anc2(0,1024), fail; true)).
> > > > % 37,001 inferences, 0.003 CPU in 0.003 seconds (99% CPU, 14659667 Lips)
> > > > true.
> > > >
> > > > (*) I am using edge/2 and edge2/2 so that the testing also works
> > > > for a Prolog system that has only first argument indexing.


devel / comp.lang.prolog / Goal reordering or advanced program transformation?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor