Questions tagged [logical-purity]

Logical purity is the property of logic programs that are written only using Horn clauses.

There are two equally justifiable ways to characterise purity:

The first is based on the intrinsic property of the program being composed of pure predicates. A pure predicate is a true relation, which is logically sound, preserving algebraic laws like commutativity of conjunction.

The second way to characterise purity is based on the operational properties of predicates: Only monotonic (also called: "monotone") predicates are pure: If the predicate succeeds for any arguments, then it does not fail for any generalisation of these arguments, and if it fails for any combination of arguments, then it does not succeed for any specialisation of these arguments.

In addition, pure predicates must not produce side-effects.

Examples of pure predicates are (=)/2, dif/2 and CLP(FD) constraints like (#=)/2. Further examples would be (=)/2 from any E-unification.

57 questions
4
votes
2 answers

Source of pure prolog small programs

The question: is there a place with some programs that I can check out? I'm talking rosetta code style, but I went there and saw that almost every program is solved with non pure prolog syntax (using cut, using IS, that type of thing), which doesn't…
keont
  • 653
  • 1
  • 9
  • 26
4
votes
1 answer

Prolog - Return result instead of printing in algorithm

I know there is technically no 'return' in Prolog but I did not know how to formulate the question otherwise. I found some sample code of an algorithm for finding routes between metro stations. It works well, however it is supposed to just print the…
skamsie
  • 2,614
  • 5
  • 36
  • 48
4
votes
2 answers

Order of Goals in Pure Prolog

I am very new to prolog. As per my knowledge Pure Prolog is restricted to Horn clauses. Here is a very simple prolog program - % student( Snr , FirstName , LastName , Semester ). student( 1000 , 'Anna' , 'Arm' , 'ti2' ) . …
Srijani Ghosh
  • 3,935
  • 7
  • 37
  • 68
4
votes
1 answer

Prolog: Can you make a predicate behave differently depending on whether a value is ground or not?

I have a somewhat complex predicate with four arguments that need to work when both the first and last arguments are ground/not ground, not ground/ground or ground/ground, and the second and third arguments are ground. i.e. predicate(A,B,C,D). I…
Wolff
  • 1,051
  • 3
  • 18
  • 31
4
votes
4 answers

Why is SWI-Prolog only giving one solution?

I'll be honest, I'm a Prolog newbie, so please excuse my ignorance. I have a simple predicate to count the occurences of an atom in a list, as follows: count(L, B, C) :- L = [], C = 0, !; L = [H|T], H \= B, count(T, B, C), !; L = [H|T],…
luksan
  • 7,661
  • 3
  • 36
  • 38
3
votes
2 answers

Proper unify_with_occurs_check/2 in SWI-Prolog?

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 :- …
user502187
3
votes
3 answers

Pure Prolog Peano Number Apartness

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…
user502187
3
votes
3 answers

Combining pure predicates

I am trying to combine some pure predicates from previous stack overflow questions to make my own predicate. I want to give a list of c's (which have associated facts -'ats' with them) and a 'feature' term which has an operator and a threshold for…
user27815
  • 4,767
  • 14
  • 28
3
votes
2 answers

Eliminate consecutive duplicates

Eliminate consecutive duplicates of list elements. My solution for this is: compress([X,X|Xs], Q) :- compress([X|Xs], Q). compress([X,Y|Xs], Q) :- X \= Y, compress([Y|Xs], QR), append([X], QR, Q). compress([X|[]], Q) :- compress([],…
Gilgamesz
  • 4,727
  • 3
  • 28
  • 63
3
votes
2 answers

Redundant answers of reified predicate variant of append/3

I wanted to offer a logically pure solution to some other recent problem in this forum. As a start, I implemented a reified variant of append/3 and named it appendR/4. It is based on the predicates if_/3 and (=)/3 implemented by @false in Prolog…
repeat
  • 18,496
  • 4
  • 54
  • 166
2
votes
3 answers

Pure Prolog Meta-Interpreter with one Rule

I wonder whether there is a pure Prolog meta-interpreter with only one rule. The usual Prolog vanilla meta-interpreter has two rules. It reads as follows: solve(true). solve((A, B)) :- solve(A), solve(B). /* rule 1 */ solve(H) :- program(H, B),…
user502187
2
votes
3 answers

Is "almost pure" Prolog expressive?

@false commented earlier: Yes, you can implement a Turing machine without dif/2. But you cannot even implement intersection or similar predicates. Suppose we do extend pure Prolog (Horn FOL + CWA + UNA) with call/N, dif/2, and (=)/3, to be used in…
2
votes
2 answers

NU-Prolog's and Gödel's logical and sound `if-then-else` extension

A paper about mercury says the following: The if-then-else and negation constructs in most variants of Prolog are non-logical and unsound: they can cause the system to compute answers which are inconsistent with the program viewed as a logical…
MWB
  • 11,740
  • 6
  • 46
  • 91
2
votes
1 answer

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

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 code1 on the left—but I want it to look like the one on the right. if_(Cond1_1, % ( Cond1_1 …
repeat
  • 18,496
  • 4
  • 54
  • 166
2
votes
2 answers

Prolog, about how to form better clauses

I have following clauses: num_parent(adam, X) :- !, X = 0. num_parent(eve, X) :- !, X = 0. num_parent(X, 2). When I typed the query: num_parent(eve,X). It only returns: X = 0. which is what I want. But when I typed this query:…