prolog

λProlog rejecting hypothetical reasoning queries?

Deadly 提交于 2021-01-27 12:46:59
问题 I suspect that teyjus, the main implementation of λProlog, might be a bit of abandonware, but λProlog is a fascinating Prolog that is supposed to let you use higher-order logic, hypothetical reasoning and other things, which is why I'm trying to use it. File "example.sig": sig example. kind person, language type. type hans person. type german, french, italian language. type grade person -> o. type take person -> language -> o. File "example.mod": module example. (grade P) :- (take P german),

Is there a higher order Prolog that wouldn't need a type system?

大兔子大兔子 提交于 2021-01-27 10:08:39
问题 I suspect that λProlog needs a type system to make their higher order unification sound. Otherwise through self application some Russell type anomalies can appear. Are there alternative higher order Prologs that don't need .sig files? Maybe by a much simpler type system, that doesn't need that many declarations but still has some form of higher order unification? Can this dilemma be solved? 回答1: Is there a higher order Prolog that wouldn't need a type system? These are type-free: HiLog HiOrd

Is there a higher order Prolog that wouldn't need a type system?

為{幸葍}努か 提交于 2021-01-27 10:07:27
问题 I suspect that λProlog needs a type system to make their higher order unification sound. Otherwise through self application some Russell type anomalies can appear. Are there alternative higher order Prologs that don't need .sig files? Maybe by a much simpler type system, that doesn't need that many declarations but still has some form of higher order unification? Can this dilemma be solved? 回答1: Is there a higher order Prolog that wouldn't need a type system? These are type-free: HiLog HiOrd

How to solve this arithmetic expression puzzle in Prolog?

北城余情 提交于 2021-01-27 07:46:01
问题 I have a programming problem (https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions): Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. E.g.: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100. I solved this problem with Python to get 11 answers : import itertools for operator in [p for p in itertools.product(['+','-',''], repeat=8)]: values = zip(

How to solve this arithmetic expression puzzle in Prolog?

自闭症网瘾萝莉.ら 提交于 2021-01-27 07:45:24
问题 I have a programming problem (https://blog.svpino.com/2015/05/08/solution-to-problem-5-and-some-other-thoughts-about-this-type-of-questions): Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. E.g.: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100. I solved this problem with Python to get 11 answers : import itertools for operator in [p for p in itertools.product(['+','-',''], repeat=8)]: values = zip(

What occurs-check optimizations is SWI Prolog using?

笑着哭i 提交于 2021-01-27 07:07:40
问题 To quote the SICStus Prolog manual: The usual mathematical theory behind Logic Programming forbids the creation of cyclic terms, dictating that an occurs-check should be done each time a variable is unified with a term. Unfortunately, an occurs-check would be so expensive as to render Prolog impractical as a programming language. However, I ran these benchmarks (The Prolog ones) and saw fairly minor differences (less than 20%) in SWI Prolog between the occurs check (OC) being on and off: OC

About building a list until it meets conditions

Deadly 提交于 2021-01-27 06:13:06
问题 I wanted to solve "the giant cat army riddle" by Dan Finkel using Prolog. Basically you start with [0] , then you build this list by using one of three operations: adding 5 , adding 7 , or taking sqrt . You successfully complete the game when you have managed to build a list such that 2 , 10 and 14 appear on the list, in that order, and there can be other numbers between them. The rules also require that all the elements are distinct, they're all <=60 and are all only integers. For example,

About building a list until it meets conditions

非 Y 不嫁゛ 提交于 2021-01-27 06:12:29
问题 I wanted to solve "the giant cat army riddle" by Dan Finkel using Prolog. Basically you start with [0] , then you build this list by using one of three operations: adding 5 , adding 7 , or taking sqrt . You successfully complete the game when you have managed to build a list such that 2 , 10 and 14 appear on the list, in that order, and there can be other numbers between them. The rules also require that all the elements are distinct, they're all <=60 and are all only integers. For example,

valid bracket list in prolog

会有一股神秘感。 提交于 2021-01-27 04:10:36
问题 I'm trying to test if a list of brackets is valid. My code: checkbrackets([]). checkbrackets(['('|T]):- T = [')'|List], checkbrackets(List). checkbrackets(['('|T]):- T = ['('|List], append(Rest,[')'],T), checkbrackets(Rest). My code works for ['(', '(', ')', '(', '(', ')', ')', ')'] but it fails for ['(', '(', ')', ')', '(', ')'] . What am I doing wrong? Is it possible to write such a test without additional arguments like counters? 回答1: For the sake of completeness, here is a solution

valid bracket list in prolog

痞子三分冷 提交于 2021-01-27 04:10:36
问题 I'm trying to test if a list of brackets is valid. My code: checkbrackets([]). checkbrackets(['('|T]):- T = [')'|List], checkbrackets(List). checkbrackets(['('|T]):- T = ['('|List], append(Rest,[')'],T), checkbrackets(Rest). My code works for ['(', '(', ')', '(', '(', ')', ')', ')'] but it fails for ['(', '(', ')', ')', '(', ')'] . What am I doing wrong? Is it possible to write such a test without additional arguments like counters? 回答1: For the sake of completeness, here is a solution