prolog

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

Is “almost pure” Prolog expressive?

…衆ロ難τιáo~ 提交于 2021-01-13 09:37:11
问题 @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 if_/3 , would there still be gaps in its expressiveness, i.e. things that are trivial to define in, say, Scheme, but are much harder to state in such extended (almost pure) Prolog? In particular, does such a Prolog allow manipulating Prolog

Pure Prolog δλ-Calculus Equality

旧街凉风 提交于 2021-01-07 01:35:18
问题 It is not so difficult to conceive an appartness relation for Peano numbers. Its even possible to make a reified eq/3 predicate like here. Question is now, whether we can push the boundary and also implement Scheme equal? predicate in a pure and reified manner? Problem would be for example to realize this reductions, also known as δ-rule (see Chapter 6 Extensions here): δxx ~~> T δxy ~~> F if x and y are not identical In case terms are represented with deBruijn indexes. This would incorporate

Pure Prolog δλ-Calculus Equality

元气小坏坏 提交于 2021-01-07 01:29:35
问题 It is not so difficult to conceive an appartness relation for Peano numbers. Its even possible to make a reified eq/3 predicate like here. Question is now, whether we can push the boundary and also implement Scheme equal? predicate in a pure and reified manner? Problem would be for example to realize this reductions, also known as δ-rule (see Chapter 6 Extensions here): δxx ~~> T δxy ~~> F if x and y are not identical In case terms are represented with deBruijn indexes. This would incorporate

How to find the Nth element of a list in Prolog

↘锁芯ラ 提交于 2021-01-06 09:17:53
问题 I am trying to write a Prolog code finding the n -th element of a list. I wrote the below code but it doesn't return the element right. match([Elem|Tail],Num,Num,Elem). match([Elem|Tail],Num,C,MatchedNumber):- match(Tail,Num,N,Elem), C is N+1. In the first line I say, if the requested element number is equal to counter, then give the first element of the current list to the variable called MatchedNumber . This code returns the Num and Counter right but I don't know why when I want to set the

How to find the Nth element of a list in Prolog

你。 提交于 2021-01-06 09:13:25
问题 I am trying to write a Prolog code finding the n -th element of a list. I wrote the below code but it doesn't return the element right. match([Elem|Tail],Num,Num,Elem). match([Elem|Tail],Num,C,MatchedNumber):- match(Tail,Num,N,Elem), C is N+1. In the first line I say, if the requested element number is equal to counter, then give the first element of the current list to the variable called MatchedNumber . This code returns the Num and Counter right but I don't know why when I want to set the

Truly Tail-Recursive modInverse() in Prolog

半城伤御伤魂 提交于 2021-01-05 11:50:56
问题 Rosetta code delivers me the following code snippet for modinv/3. It does calculate extended GCD via egcd/4 and then derives from it modinv/3: egcd(_, 0, 1, 0) :- !. egcd(A, B, X, Y) :- divmod(A, B, Q, R), egcd(B, R, S, X), Y is S - Q*X. modinv(A, B, N) :- egcd(A, B, X, Y), A*X + B*Y =:= 1, N is X mod B. Example queries: ?- modinv(42, 2017, N). N = 1969. ?- modinv(42, 64, X). false. There is a slight problem with the solution. It is not tail recursive. Namely the (is)/2 is the last call of

Can higher order Prolog help closure expansion?

自作多情 提交于 2021-01-05 07:28:29
问题 If I enter this code in SWI-Prolog: goal_expansion(println(X), (write(X), nl)). test :- call(println, 'Hello World!'). Listing shows me this result: test :- call('__aux_wrapper_8a89205eca9a6ffb31dd01cc968a2aa022fa1f49', 'Hello World!'). '__aux_wrapper_8a89205eca9a6ffb31dd01cc968a2aa022fa1f49'(A) :- write(A), nl. Would a higher order Prolog do the same? Are there higher order Prologs that have goal expansion and/or closure expansion? 来源: https://stackoverflow.com/questions/65289298/can-higher