prolog Questions
7
Solved
The fringe of a binary tree is the sequence composed by its leaves, from
left to right. The same-fringe problem [Hewitt & Patterson, 1970]
consists of determining whether two binary trees have ...
Sefton asked 15/6, 2024 at 15:38
2
Solved
I am trying to run a simple gprolog to run on my Linux machine, GNU Prolog was installed from the Ubuntu Software Center.
From the GNU Prolog Intro I got the following example, stored in HelloWorl...
Sprout asked 15/3, 2014 at 8:25
2
I want to use a Python script as a frontend to a Prolog program that uses the SWI-PL engine.
So, the components of the setup are:
Python (2.7 or higher)
SWI-PL: website here
I've been looking ...
Domitiladomonic asked 26/6, 2013 at 17:24
4
Solved
Do they exist? How are they implemented?
The coroutining predicates of SWI-Prolog (freeze, when, dif etc.) have the functionality of guards. How do they fit in the preferred Prolog programming sty...
Dangle asked 7/12, 2012 at 9:8
11
I was just introduced to Prolog and am trying to write a predicate that finds the Max value of a list of integers. I need to write one that compares from the beginning and the other that compares f...
Chrominance asked 5/11, 2013 at 20:58
1
As a simple exercise, I wrote my own permutation.
This stack overflows:
without(_, [], []).
without(A, [A|T], T).
without(A, [H|T], [H|G]) :- without(A, T, G).
my_permutation([], []).
my_permutati...
Semicentennial asked 23/3, 2024 at 19:53
3
Solved
I've written a predicate, shuffle/3, which generates "shuffles" of two lists. When the second and third argument are instantiated, the first argument becomes a list which has all the elements of bo...
Nisa asked 21/6, 2018 at 1:39
8
Solved
For example:
isin([1,2,3], [1,0,1,2,3,0])
will yield true because 123 is inside of 101230
I wrote the following code:
isin([AH|AT],[AH|AT]).
isin([AH|AT],[BH|BT]):- AH = BH, isin(AT,BT), isin([AH...
3
Solved
I'm trying to learn the basics of Prolog and keep running into a existence_error with the following code.
comes_after(m1, m2).
comes_after(m2, m3).
comes_after(m3, m4).
comes_after(m4, m5).
comes_...
Polonium asked 4/11, 2017 at 5:34
4
I was testing my new version of SWI prolog and keep coming across the error :singleton variable.
Example:
member(X,[X|T]).
member(X,[X|T]) :- member(X,T).
finds the member of a list such as :
...
Evadnee asked 14/3, 2013 at 17:31
3
Solved
I'd appreciate it if someone could elaborate on the difference between the is keyword and the = operator in prolog. I saw this discussion in == and =, but it excludes is. The documentation talks ab...
5
Solved
What is the best way to convert binary bits (it might be a list of 0/1, for example) into numbers in a reversible way. I've written a native predicate in swi, but is there better solution ?
Best re...
6
I am beginner in Prolog programming.
I wrote this program to calculate the length of a list. Why is below program wrong?
length(0, []).
length(L+l, H|T) :- length(L, T).
I wrote below program an...
9
Solved
All lists with one single element is easy to define using the Prolog prologue:
?- maplist(=(_),L).
L = []
; L = [_A]
; L = [_A,_A]
; L = [_A,_A,_A]
; ... .
So this element is repeated over and ov...
Amplification asked 3/6, 2023 at 12:50
7
Solved
I wrote the following program based on the logic that a prime number is only divisible by 1 and itself. So I just go through the process of dividing it to all numbers that are greater than one and ...
4
My professor gave this as an example of Prolog. It is a program that solves the Tower of Hanoi puzzle, where you have to move a stack of disks to another peg by moving one disk after the other, wit...
Coy asked 28/5, 2016 at 13:17
4
Solved
I'm trying to write a rule which decides whether an item X occurs exactly one in a list L.
unique(X, [X|T]):- !, \+ member(X, T).
unique(X, [_|T]):- unique(X, T).
The rule works for determining ...
Bradshaw asked 6/11, 2016 at 8:53
5
Solved
I am currently trying to learn some basic prolog. As I learn I want to stay away from if else statements to really understand the language. I am having trouble doing this though. I have a simple fu...
8
Solved
I have finished a homework assignment for my programming class. I was supposed to create a Prolog program that reverses a list. I, however, am having trouble understanding why exactly it works.
%...
Salvation asked 19/10, 2013 at 22:17
4
Can anyone explain the concept of free variables in Prolog. Is it similar to anonymous variables ? Or is there a difference. Also could be great if an example is given to explain.
Trigonous asked 26/1, 2021 at 12:4
10
Solved
I've been given the question:
Define a predicate ordered/1, which checks if a list of integers is correctly in ascending order. For example, the goal ordered([1,3,7,11]) should succeed, as shoul...
4
I came across this natural number evaluation of logical numbers in a tutorial and it's been giving me some headache:
natural_number(0).
natural_number(s(N)) :- natural_number(N).
The rule roughl...
Bicker asked 21/1, 2012 at 16:6
4
Being a beginner to prolog, I am trying to remove all duplicates from a list.
I do get a satisfying answer but this should be the only answer. Instead,
prolog keeps on providing other answers.
I tr...
Donitadonjon asked 22/6, 2022 at 18:48
3
Solved
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 apa...
Tacet asked 23/12, 2020 at 16:11
6
So as the title says - how do you convert a string into an integer?
the idea is something like this:
convert(String,Integer).
examples:
convert('1',1).
convert('33',33).
I'm using swi prolog
1 Next >
© 2022 - 2025 — McMap. All rights reserved.