🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.prolog
3 messages
3 total messages Started by Mild Shock Tue, 03 Nov 2026 00:28
Is (\+)/1 enough for executable specifications?
#39
Author: Mild Shock
Date: Tue, 03 Nov 2026 00:28
32 lines
1924 bytes
Hi,

Using the EyeProlog example code, I get this
result in a ISO compliant Prolog processor.
The predicate turns out to be non-deterministic
operational:

?- normal_form(append(append(append(a,b),c),d), X).
X = append(a, append(b, append(c, d))) ;
X = append(a, append(b, append(c, d))) ;
false.

So normal form has spurious choice points. And
would explode in practice, when deployed as a
normal form routine and when supplied larger terms.

A fix would be:

normal_form(Term, Term) :-
      \+ rewrite_once(Term, _, _).
normal_form(Term, Normal) :-
      once(rewrite_once(Term, Next, _)),
      normal_form(Next, Normal).

But once/1 is not among your list of "by" justifications?
Lean 4 does solve this problem in that already match/with
is deterministic. But Lean 4 can make it declarative

by a recursor / motive translation.

Bye
What would Robert Stärk say? [Have Fun!] (Was: Is (\+)/1 enough for executable specifications?)
#44
Author: Mild Shock
Date: Tue, 03 Nov 2026 14:59
82 lines
3644 bytes
Hi,

Well the interesting part of the normal_form/2
predicate, is also that negation as failure is
not called with a ground goal argument, so the
example leans out of the framework

of SLDNF, where \+ G are supposed to have G ground
at runtime. If it were ground, as a next step in
some Datalog frameworks it can then indeed be
interpreted as absence of a fact or

derived fact, due to negation stratification. But
Robert Stärk already observed that the two extra
variables _and _, in the call, make it basically
asking a not exists query,

and therefore the justifiation is not only
absence but rather the proof tree of a finite
failure. But if we look at the example it is also
not stead fast, an input 2nd argument

my divert the derivation, and last but not least
rewrite_once is left recursive, and has an infinite
answer set, i.e. all normal terms. One might wonder
whether Robert Stärk left academia back then,

because such a large number of problems is just too
much for a Human. Just joking. The resilient Prologer
might also see it as the birth place of cuts, since
an alternative formulation often

found in the wild would be:

normal_form(Term, Normal) :-
      rewrite_once(Term, Next, _), !,
      normal_form(Next, Normal).
normal_form(Term, Term).

Its even steadfast now in the 2nd argument, and
calls rewrite_once/3 not in two different places,
but only in one place, giving yet anoter inch
more performance.

Have Fun!

Bye

Mild Shock schrieb:
> Hi,
> 
> Using the EyeProlog example code, I get this
> result in a ISO compliant Prolog processor.
> The predicate turns out to be non-deterministic
> operational:
> 
> ?- normal_form(append(append(append(a,b),c),d), X).
> X = append(a, append(b, append(c, d))) ;
> X = append(a, append(b, append(c, d))) ;
> false.
> 
> So normal form has spurious choice points. And
> would explode in practice, when deployed as a
> normal form routine and when supplied larger terms.
> 
> A fix would be:
> 
> normal_form(Term, Term) :-
>       \+ rewrite_once(Term, _, _).
> normal_form(Term, Normal) :-
>       once(rewrite_once(Term, Next, _)),
>       normal_form(Next, Normal).
> 
> But once/1 is not among your list of "by" justifications?
> Lean 4 does solve this problem in that already match/with
> is deterministic. But Lean 4 can make it declarative
> 
> by a recursor / motive translation.
> 
> Bye
> 
Where would steadfastness be needed? (Was: What would Robert Stärk say? [Have Fun!])
#40
Author: Mild Shock
Date: Tue, 03 Nov 2026 15:07
97 lines
4069 bytes
Hi,

Well in this definition, the second
normal_form/2 call is with mode (+,+),
ad not anymore with mode (+,-):

joined_pair(Name) :-
   critical_pair(Name, Left, Right),
   normal_form(Left, Normal),
   normal_form(Right, Normal).

Bye

Mild Shock schrieb:
> Hi,
> 
> Well the interesting part of the normal_form/2
> predicate, is also that negation as failure is
> not called with a ground goal argument, so the
> example leans out of the framework
> 
> of SLDNF, where \+ G are supposed to have G ground
> at runtime. If it were ground, as a next step in
> some Datalog frameworks it can then indeed be
> interpreted as absence of a fact or
> 
> derived fact, due to negation stratification. But
> Robert Stärk already observed that the two extra
> variables _and _, in the call, make it basically
> asking a not exists query,
> 
> and therefore the justifiation is not only
> absence but rather the proof tree of a finite
> failure. But if we look at the example it is also
> not stead fast, an input 2nd argument
> 
> my divert the derivation, and last but not least
> rewrite_once is left recursive, and has an infinite
> answer set, i.e. all normal terms. One might wonder
> whether Robert Stärk left academia back then,
> 
> because such a large number of problems is just too
> much for a Human. Just joking. The resilient Prologer
> might also see it as the birth place of cuts, since
> an alternative formulation often
> 
> found in the wild would be:
> 
> normal_form(Term, Normal) :-
>       rewrite_once(Term, Next, _), !,
>       normal_form(Next, Normal).
> normal_form(Term, Term).
> 
> Its even steadfast now in the 2nd argument, and
> calls rewrite_once/3 not in two different places,
> but only in one place, giving yet anoter inch
> more performance.
> 
> Have Fun!
> 
> Bye
> 
> Mild Shock schrieb:
>> Hi,
>>
>> Using the EyeProlog example code, I get this
>> result in a ISO compliant Prolog processor.
>> The predicate turns out to be non-deterministic
>> operational:
>>
>> ?- normal_form(append(append(append(a,b),c),d), X).
>> X = append(a, append(b, append(c, d))) ;
>> X = append(a, append(b, append(c, d))) ;
>> false.
>>
>> So normal form has spurious choice points. And
>> would explode in practice, when deployed as a
>> normal form routine and when supplied larger terms.
>>
>> A fix would be:
>>
>> normal_form(Term, Term) :-
>>       \+ rewrite_once(Term, _, _).
>> normal_form(Term, Normal) :-
>>       once(rewrite_once(Term, Next, _)),
>>       normal_form(Next, Normal).
>>
>> But once/1 is not among your list of "by" justifications?
>> Lean 4 does solve this problem in that already match/with
>> is deterministic. But Lean 4 can make it declarative
>>
>> by a recursor / motive translation.
>>
>> Bye
>>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads