logo
down
shadow

PROLOG QUESTIONS

different behavior of predicates in prolog
different behavior of predicates in prolog
I wish this helpful for you In your second example, test(1,2,3) is just a structure. In a conventional language, something like [test(1,2,3)] would cause the language to go and evaluate some function. Python for instance:
TAG : prolog
Date : January 11 2021, 03:28 PM , By : JSebok
Are there alternative ways to display a list other than by using loop?
Are there alternative ways to display a list other than by using loop?
Hope that helps it's not very clear what it is that you're trying to achieve.I'm not sure from your description whether you have quite got to grips with the declarative style of Prolog. When you wrote your rule for loop you were providing a set of co
TAG : prolog
Date : January 10 2021, 01:45 PM , By : user185939
How to solve a knapsack problem in CLP(B)
How to solve a knapsack problem in CLP(B)
should help you out You can model size(weight) constraints by issuing new variables to account for the weight, then use card constraint to model capacity of the backpack and finally using weighted_maximum/2 to maximize objective:
TAG : prolog
Date : January 02 2021, 06:48 AM , By : Amin Amini
Equality of sets
Equality of sets
Any of those help It really really depends on how the predicate is going to be used.Assuming that a "set" is indeed a Prolog list without duplicates but not in any particular order; then two sets in that presentation "coincide" if they are permutatio
TAG : prolog
Date : January 02 2021, 06:48 AM , By : Zelos
When does Prolog break lines?
When does Prolog break lines?
Hope this helps All bindings (Var = Value) appear on their own line, except when two or more variables are bound to the same value. In that case it uses the following syntax on a single line.
TAG : prolog
Date : January 02 2021, 06:48 AM , By : Chris Hanley
Assigning values in a predicate
Assigning values in a predicate
Hope that helps Please don't do it like this. is/2 is for evaluating arithmetic expressions.Without any context whatsoever it is difficult impossible to suggest what is the right way to do it. The traditional way is to have a predicate that looks lik
TAG : prolog
Date : January 02 2021, 06:48 AM , By : boney M
Generating a sequence of leap years using clpfd
Generating a sequence of leap years using clpfd
seems to work fine The code below checks whether a given year is a leap year or not. The arithmetic is formulated using declarative integer arithmetic from the library clpfd, in order that the query can be run in 'reverse' to generate a sequence of l
TAG : prolog
Date : January 02 2021, 06:48 AM , By : dbarbot
Hints to understand splendid program to solve Queens
Hints to understand splendid program to solve Queens
With these it helps Let us first look at the top predicate. Here we solve the N×N queens problem by calling queens(N,Qs). The first call in the body length(Qs, N) constructs a list of variables with length N. Next it calls place_queens/4 with place_q
TAG : prolog
Date : January 02 2021, 06:48 AM , By : stu73
Prolog stucks after giving the result
Prolog stucks after giving the result
This might help you So I have this knowledge base and I am trying to achieve the goals in the code given as comments. , What causes it?
TAG : prolog
Date : January 02 2021, 06:48 AM , By : UpperLuck
Generate list and check if the values are increasing
Generate list and check if the values are increasing
it fixes the issue I do not really see why you specify a function gen/3 here. You can use an accumulator, and thus each time update the accumulator, like:
TAG : prolog
Date : January 02 2021, 06:48 AM , By : user185144
Turning off warnings in swi-prolog
Turning off warnings in swi-prolog
this one helps. Instead, you could fix the warning.The discontiguous directive is needed when the clauses of a static (compiled) predicate cannot be compiled as a single unit. This happens when the clause definitions are:
TAG : prolog
Date : January 02 2021, 06:48 AM , By : Andrew L.
In swi-prolog; How to create dup(L1, L2), where the elements of L2 are duplicated elements of L1?
In swi-prolog; How to create dup(L1, L2), where the elements of L2 are duplicated elements of L1?
To fix the issue you can do The key to all of these list operations in Prolog is basically to think inductively. What would dup([], X) give? Probably X = []:
TAG : prolog
Date : December 31 2020, 02:31 AM , By : rixtertech
Prolog: Reflect (X,Y) -> (Y,X)
Prolog: Reflect (X,Y) -> (Y,X)
around this issue I am attempting to generate a second, reflected point besides the input in prolog without using Inbuilt functions (i.e. swap etc). , You program is simply this clause.
TAG : prolog
Date : December 27 2020, 04:54 PM , By : Kilimanjaro
Rule matching regarding lists in SWI Prolog
Rule matching regarding lists in SWI Prolog
it fixes the issue Recently I started learning Prolog and as an exercise I tried to implement a predicate penultimate/2 giving the penultimate element of a list that would not backtrack. , Try:
TAG : prolog
Date : December 27 2020, 04:45 PM , By : littlefuzz
How can I localize the reasons for excessive goal expansion?
How can I localize the reasons for excessive goal expansion?
help you fix your problem SICStus tries to be clever when there is no goal expansion that can be applicable. In that case the call to call_goal_expansion can often be avoided. However, if there is a goal expansion visible (e.g. by loading clpz) and t
TAG : prolog
Date : December 25 2020, 08:30 PM , By : jumpingmattflash
Mutually exclusion in a logic task
Mutually exclusion in a logic task
wish of those help First we need to capture the fact that each name has one of the given surnames.
TAG : prolog
Date : December 25 2020, 07:01 PM , By : Chris Hubbard
I am new to Prolog. I have tried to develop a major selection simple expert system, but I am stuck
I am new to Prolog. I have tried to develop a major selection simple expert system, but I am stuck
wish helps you I want to be able to let users choose a few options and not all to get the hypothesis to show. Example: The user is interested in computers, programming, and technology but not apps, i still want the system to show that user can major
TAG : prolog
Date : December 25 2020, 05:02 PM , By : chintown
CHR behavior in SWI Prolog for simple and() rule
CHR behavior in SWI Prolog for simple and() rule
With these it helps I think it was a silly question on my part... As a beginner I forgot sometimes about the host language.Y = 0 in the guard in Prolog unified Y with 0 so I guess this is why I got the second rule in store.
TAG : prolog
Date : December 25 2020, 09:27 AM , By : user183275
Prolog beginner, combining rules question?
Prolog beginner, combining rules question?
this one helps. Prolog cannot unify variables that are hidden inside predicate bodies. There is no relationship between the A in alive_after/1 and the A in alive_before/1. Prolog actually told you that it didn't know what you were doing when it repor
TAG : prolog
Date : December 25 2020, 03:30 AM , By : Mario Tristan
Reading out text from an editor in XPCE
Reading out text from an editor in XPCE
should help you out adapted from XPCE guide
TAG : prolog
Date : December 24 2020, 10:30 PM , By : Derek
CHR solution output in Prolog
CHR solution output in Prolog
help you fix your problem Had to hunt in the source code for a solution to this, but you can turn it off by setting a flag to false:
TAG : prolog
Date : December 22 2020, 06:30 AM , By : Monev
Knight's tour in Prolog: Stack limit exceeded
Knight's tour in Prolog: Stack limit exceeded
Hope that helps The problem was that Warnsdorff's rule does not provide a solution for the case where the first (last in terms of the stack) square is 1/1. I have to write
TAG : prolog
Date : December 22 2020, 04:01 AM , By : Terrence Poon
SWI-Prolog stack limit exceeded with tiny problem space using clpfd
SWI-Prolog stack limit exceeded with tiny problem space using clpfd
I hope this helps . (Let's ignore programming style, see @Capelli's comment for that.)The actual source of non-termination is due to a weakness in SWI's CLP(FD) system. Here is the actual culprit:
TAG : prolog
Date : December 21 2020, 04:41 AM , By : LucaN
switch between 1 and 0 in a list
switch between 1 and 0 in a list
hope this fix your issue So we've got a bunch of people who, with nothing better to do in their lives, want to sequentially switch some numbers in a list. Someone needs to introduce them to Prolog, they could make better use of their time. But this i
TAG : prolog
Date : December 09 2020, 05:30 AM , By : dyarborough
Zebra puzzle - who lives on which floor?
Zebra puzzle - who lives on which floor?
I wish did fix the issue. The query is correct for the given code.The code contains an error.
TAG : prolog
Date : December 06 2020, 11:48 PM , By : druta
make list consists of the same item
make list consists of the same item
should help you out The easy way to do this is to declare that the list has that length, and that every element unifies with your item:
TAG : prolog
Date : December 05 2020, 12:02 PM , By : Adam May
Prolog Euclidian Square
Prolog Euclidian Square
seems to work fine There are three problems here:your version for two empty lists should unify the second parameter with 0, not ED, since then it remains a free variable, so:
TAG : prolog
Date : November 28 2020, 04:01 AM , By : Robby
Prolog- How does a cut work in combination with OR operator?
Prolog- How does a cut work in combination with OR operator?
may help you . imagine you have the equivalent definition married_to(X,Y):- true, !, married(X,Y) ; married(Y,X).. If true were to fail, then we'd jump to the alternative, but since it's not going to, we're firmly on the consequent branch (of the dis
TAG : prolog
Date : November 22 2020, 11:17 AM , By : Brian
Constraint Values on Local Variable
Constraint Values on Local Variable
it should still fix some issue After some searching I found the problem. The code was able to generate the correct schedule from the beginning. The problem was only the Starting 'start times' of the tasks were minimized if they needed to be for minim
TAG : prolog
Date : November 22 2020, 10:54 AM , By : jgood
Listing facts with uncertainty
Listing facts with uncertainty
With these it helps Why don't you use a tuple predicate like fact/2?Then you specify:
TAG : prolog
Date : November 22 2020, 10:31 AM , By : Jay Crockett
Prolog array in rules and operation
Prolog array in rules and operation
wish help you to fix your issue I have a little problem with define facts and search in array in Prolog. I dont know, how add to rule my array and result of it. , You are missing a member/2 call to get an element out of an array:
TAG : prolog
Date : November 22 2020, 01:01 AM , By : nonkelhans
Get the length of a list in prolog in a non-recursive way
Get the length of a list in prolog in a non-recursive way
should help you out I have the following code for getting the length of a list in prolog, it works recursively. Is there any other way for getting the length? , Here is an iterative solution that uses repeat/0 predicate:
TAG : prolog
Date : November 22 2020, 01:01 AM , By : n1ckless_id
Number decomposition in Prolog
Number decomposition in Prolog
this one helps. Use clpfd constraints to see that there are more solutions than you show:
TAG : prolog
Date : November 21 2020, 09:01 AM , By : Derek
Prolog evaluating a number in a list
Prolog evaluating a number in a list
like below fixes the issue I'm working on a Prolog application that will go through a list of values and copy the values to another list. If a value is a number, then I want to square that number, otherwise, copy the value. , What about
TAG : prolog
Date : November 20 2020, 11:01 PM , By : Vasiliy
What is the arity of the following complex terms?
What is the arity of the following complex terms?
wish help you to fix your issue Notice that what you call "complex terms" are normally called coumpound terms in Prolog. You can easily check for the arity of Prolog terms yourself in the following way:
TAG : prolog
Date : November 20 2020, 01:01 AM , By : ralph okochu
Simple Prolog setof
Simple Prolog setof
This might help you this is simple yet cannot seem to grasp it I have these "colors" , I suppose you meant this with combinations:
TAG : prolog
Date : November 19 2020, 04:06 PM , By : Nandor Devai
Looping number in menu prolog
Looping number in menu prolog
fixed the issue. Will look into that further One of the few things Prolog does have in common with other languages is that it's best to think modularly. It looks like you're trying to capture all functionality in one predicate clause which is awkward
TAG : prolog
Date : November 18 2020, 03:01 PM , By : MP.
Cannot load prolog source file
Cannot load prolog source file
Hope this helps If you typed exactly [test.pl] as you wrote in your question, then the error is due to not using an atom as the argument to the list notation shortcut to compile and load files. Try instead ['test.pl'] or simply [test].
TAG : prolog
Date : November 18 2020, 09:01 AM , By : Gerhard Miller
Prolog "Out of local stack" Error
Prolog "Out of local stack" Error
seems to work fine Here is my simple Prolog program: , The error is in the second clause. It should be instead:
TAG : prolog
Date : November 17 2020, 12:01 PM , By : ranja
prolog,using the right algorithm but getting the wrong answer
prolog,using the right algorithm but getting the wrong answer
should help you out i am trying to find the maximum number out of a list and even used write() for every recursion to verify my steps.here is my code , The problem is in this clause:
TAG : prolog
Date : November 17 2020, 11:55 AM , By : Guyou
Filtering and modifiying a list in Prolog
Filtering and modifiying a list in Prolog
I hope this helps you . The issue when adding the append([X]|['CCC'], [Result]) is that you instantiate Result=[X,'CCC']. You are not just adding 'CCC' to Result but you append [X] with ['CCC'] and the result is the list Result (so Result=[X,'CCC']).
TAG : prolog
Date : November 15 2020, 11:01 PM , By : Boyer C.
Generate a 3d List
Generate a 3d List
wish helps you I am trying to make a List of Lists of Lists without values. If N_meses = 4 I want List =[[[A,B,C,D]]]. I get what I want ( List = [[[]]] ) but every lists have the same values as you can see in the print I attached. How can I change t
TAG : prolog
Date : November 15 2020, 04:01 AM , By : Icyflash
Best way to update/add fact in the db?
Best way to update/add fact in the db?
Any of those help Say I have facts like this : , I would write
TAG : prolog
Date : November 14 2020, 07:01 AM , By : Funkwarrior
How to run plunit tests in prolog
How to run plunit tests in prolog
it fixes the issue From the plunit manual:
TAG : prolog
Date : November 11 2020, 09:01 AM , By : scotta01
How do I surround an Atom value with double quotation marks in Prolog?
How do I surround an Atom value with double quotation marks in Prolog?
this will help , You're looking for atom_string/2.Example:
TAG : prolog
Date : November 11 2020, 09:01 AM , By : Dean
How to 'return' value in prolog?
How to 'return' value in prolog?
Does that help I have written program, which calculates how much odd numbers given list contains. In order to use it, you need to type your query in this form knelyg([1,2,3],K).. Here is my issue, now, my program would return false, rather then K=2.
TAG : prolog
Date : November 07 2020, 01:33 PM , By : pdkent
Prolog Compilation Error "Undefined reference to predicate"
Prolog Compilation Error "Undefined reference to predicate"
it should still fix some issue We have just started working on Prolog in one of my programming classes. I am getting a few errors and I am not completely sure on what is causing them. This is homework so I am not expecting any written out answers, bu
TAG : prolog
Date : November 06 2020, 03:59 AM , By : Francis
prolog -- generate integers "unwindably"
prolog -- generate integers "unwindably"
it should still fix some issue I suspect it's because Prolog tries to evaluate length/2 predicate during search. According to manual, it raises an error if the second argument is bound to a non-integer. That differs from simply failing the check.You
TAG : prolog
Date : November 04 2020, 04:01 AM , By : MJRider
SWI-Prolog rule assertion from passed List
SWI-Prolog rule assertion from passed List
help you fix your problem While it probably is possible to add rules to the store dynamically using assertz/1 et. al. I have never really had to do it, because it's too easy to get Prolog to evaluate other data structures.For your particular database
TAG : prolog
Date : November 02 2020, 03:01 PM , By : nemof
Exchange parameters
Exchange parameters
hop of those help? The reason for the infinite derivation is that it is possible to flip the arguments back (and forth, as long as you like). You can introduce a new name for the flipping predicate:
TAG : prolog
Date : October 31 2020, 05:57 AM , By : Tink
Can I prepend the argument list in call/2?
Can I prepend the argument list in call/2?
will help you call(Goal,Arg) allows to append the argument Arg to the arguments of Goal and call the resulting goal, e.g. , For an arbitrary number of arguments, you could define it as
TAG : prolog
Date : October 31 2020, 05:55 AM , By : Dennizzz
Sums of the elements in list
Sums of the elements in list
wish of those help The short answer: unification.When, within the scope of a predicate clause, a variable name occurs more than once, all occurrences will be unified with each other. The predicate for unification is =/2, and is declared as operator,
TAG : prolog
Date : October 29 2020, 12:01 AM , By : Jim Davis
word processing in prolog
word processing in prolog
Hope this helps This program will basically apply the rules you mention, but I don't think it will make a good tool for word processing.
TAG : prolog
Date : October 24 2020, 01:32 PM , By : usingtechnology
How to read data from file into Prolog
How to read data from file into Prolog
wish of those help You need to open the file, read its lines, and for each one, split the line into the terms you want to use. Then, you can can place the terms in some variable or assert/1 them into the dynamic db. In the example below I assert them
TAG : prolog
Date : October 23 2020, 03:00 PM , By : Zinovate
How should I handle repeated updating in logical programming?
How should I handle repeated updating in logical programming?
I think the issue was by ths following , What you suggest may seem tempting: Simulate global updates with assertz/0 and retract/1.However, there are major drawbacks if you do it this way:
TAG : prolog
Date : October 22 2020, 01:59 PM , By : doctorbigtime
How to make box a free, in the situation with the boxes on a table, SWI-Prolog?
How to make box a free, in the situation with the boxes on a table, SWI-Prolog?
hope this fix your issue You take the wrong representation. Using facts is fine for representing an immutable world, but once you start searching you want to represent a mutable state of the world, which is best achieved in logical variables. That wa
TAG : prolog
Date : October 19 2020, 01:08 AM , By : Robert MacGregor
Prolog Error Catching
Prolog Error Catching
will be helpful for those in need Given: , Set Prolog Flags and Use Catch/3Assuming SWI Prolog
TAG : prolog
Date : October 14 2020, 11:12 PM , By : Bin
(prolog) Can i abstract all the permutations of this pattern instead of having to write each one individually?
(prolog) Can i abstract all the permutations of this pattern instead of having to write each one individually?
like below fixes the issue I'm just starting out with prolog and though I think I'm getting a pretty good handle on how to use it, I've hit a wall here. I have a rule like this: , This is what I would do:
TAG : prolog
Date : October 08 2020, 12:00 AM , By : kuba53280
Prolog query with default for missing values
Prolog query with default for missing values
Does that help Say I have the following database in Prolog. , OK. I worked it out :
TAG : prolog
Date : October 07 2020, 07:00 AM , By : user177837
What is the equivalent of an "outer join" in Prolog?
What is the equivalent of an "outer join" in Prolog?
Does that help You can approximate the behaviour of (a specific) SQL query in this way:
TAG : prolog
Date : October 07 2020, 07:00 AM , By : gopal

shadow
Privacy Policy - Terms - Contact Us © scrbit.com