logical-purity

`less/2` relation in Peano arithmetic

眉间皱痕 提交于 2021-02-16 14:48:07
问题 This less-than predicate in Peano arithmetic less(0, s(_)). less(s(X), s(Y)) :- less(X, Y). loops when ?- less(X, Y), X=s(0), Y=0. Is there a better way to write less/2 (using Horn clauses only)? 回答1: You can use when/2 . Making it not anymore an infinitely enumerating predicate and still keeping it 100% pure. The when/2 modifies the S (selection rule) in SLD-Resolution, an idea that can be traced back to Alain Colmerauer. less(X, Y) :- when((nonvar(X),nonvar(Y)), less2(X,Y)). less2(0, s(_)).

Goal expansion for an `if_/3` operator in Prolog

帅比萌擦擦* 提交于 2021-02-09 11:20:08
问题 I'm writing a tokeniser and I want to use if_/3 to preserve logical-purity in my code. The code looks like the following code 1 on the left—but I want it to look like the one on the right. if_(Cond1_1, % ( Cond1_1 Then1, % *=> Then1 if_(Cond2_1, % ; Cond2_1 Then2, % *=> Then2 if_(Cond3_1, % ; Cond3_1 Then3, % *=> Then3 if_(Cond4_1, % ; Cond4_1 Then4, % *=> Then4 if_(Cond5_1, % ; Cond5_1 Then5, % *=> Then5 Else5 % ; Else5 ) ) ) ) ). % ). To do the rewriting of (*=>)/2 to if_/3 in SWI-Prolog I

Is pure Prolog Turing-complete, and if so, why can't it implement list intersection?

∥☆過路亽.° 提交于 2021-02-04 04:58:19
问题 The Wikipedia section on this topic is a mess. It states: Pure Prolog is based on a subset of first-order predicate logic, Horn clauses, which is Turing-complete. Turing completeness of Prolog can be shown by using it to simulate a Turing machine: (emphasis added) And then it goes on to show code that uses things that are not Horn clauses ( ! and once ): turing(Tape0, Tape) :- perform(q0, [], Ls, Tape0, Rs), reverse(Ls, Ls1), append(Ls1, Rs, Tape). perform(qf, Ls, Ls, Rs, Rs) :- !. perform(Q0

Is pure Prolog Turing-complete, and if so, why can't it implement list intersection?

喜夏-厌秋 提交于 2021-02-04 04:56:57
问题 The Wikipedia section on this topic is a mess. It states: Pure Prolog is based on a subset of first-order predicate logic, Horn clauses, which is Turing-complete. Turing completeness of Prolog can be shown by using it to simulate a Turing machine: (emphasis added) And then it goes on to show code that uses things that are not Horn clauses ( ! and once ): turing(Tape0, Tape) :- perform(q0, [], Ls, Tape0, Rs), reverse(Ls, Ls1), append(Ls1, Rs, Tape). perform(qf, Ls, Ls, Rs, Rs) :- !. perform(Q0

Is pure Prolog Turing-complete, and if so, why can't it implement list intersection?

与世无争的帅哥 提交于 2021-02-04 04:56:29
问题 The Wikipedia section on this topic is a mess. It states: Pure Prolog is based on a subset of first-order predicate logic, Horn clauses, which is Turing-complete. Turing completeness of Prolog can be shown by using it to simulate a Turing machine: (emphasis added) And then it goes on to show code that uses things that are not Horn clauses ( ! and once ): turing(Tape0, Tape) :- perform(q0, [], Ls, Tape0, Rs), reverse(Ls, Ls1), append(Ls1, Rs, Tape). perform(qf, Ls, Ls, Rs, Rs) :- !. perform(Q0

Proper unify_with_occurs_check/2 in SWI-Prolog?

余生颓废 提交于 2021-01-16 01:13:52
问题 Got this strange behaviour. I was running these test cases: s1 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), unify_with_occurs_check(P, Q). s2 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), freeze(_3514, (write(bar), nl)), unify_with_occurs_check(P, Q). Now I get these results, where the outcome of s2 is wrong. The outcome is

Proper unify_with_occurs_check/2 in SWI-Prolog?

北慕城南 提交于 2021-01-16 01:09:28
问题 Got this strange behaviour. I was running these test cases: s1 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), unify_with_occurs_check(P, Q). s2 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), freeze(_3514, (write(bar), nl)), unify_with_occurs_check(P, Q). Now I get these results, where the outcome of s2 is wrong. The outcome is

Proper unify_with_occurs_check/2 in SWI-Prolog?

好久不见. 提交于 2021-01-16 01:08:47
问题 Got this strange behaviour. I was running these test cases: s1 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), unify_with_occurs_check(P, Q). s2 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), freeze(_3514, (write(bar), nl)), unify_with_occurs_check(P, Q). Now I get these results, where the outcome of s2 is wrong. The outcome is

Proper unify_with_occurs_check/2 in SWI-Prolog?

戏子无情 提交于 2021-01-16 01:08:46
问题 Got this strange behaviour. I was running these test cases: s1 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), unify_with_occurs_check(P, Q). s2 :- Q=[[lambda,symbol(_3026),[cons,[quote,_3434], [quote,_3514]]],[quote,_3206]], P=[_3434|_3514], freeze(_3434, (write(foo), nl)), freeze(_3514, (write(bar), nl)), unify_with_occurs_check(P, Q). Now I get these results, where the outcome of s2 is wrong. The outcome is

Pure Prolog Peano Number Apartness

▼魔方 西西 提交于 2021-01-15 22:47:17
问题 Lets assume there is pure_2 Prolog with dif/2 and pure_1 Prolog without dif/2. Can we realize Peano apartness for values, i.e. Peano numbers, without using dif/2? Thus lets assume we have Peano apartness like this in pure_2 Prolog: /* pure_2 Prolog */ neq(X, Y) :- dif(X, Y). Can we replace neq(X,Y) by a more pure definition, namely from pure_1 Prolog that doesn't use dif/2? So that we have a terminating neq/2 predicate that can decide inequality for Peano numbers? So what would be its