Questions tagged [instantiation-error]

An instantiation error occurs in Prolog when an argument is insufficiently instantiated. It is frequently encountered with (is)/2 and the built-ins for arithmetical comparison like (>)/2 and (=:=)/2 that all expect variable free expressions.

An "instantiation" error occurs in when an argument is insufficiently instantiated. It is frequently encountered with (is)/2 and the built-ins for arithmetical comparison like (>)/2, (=:=)/2 that all expect fully instantiated, ground terms (i.e. without uninstantiated logical variables in them) as arguments.

In many cases, there are more general predicates available that work also if their arguments are not fully instantiated. For example, many Prolog systems support the CLP(FD) constraints (#=)/2 and (#>)/2 which can be used as pure alternatives.

Another course of action is to delay the call until such time that all arguments become instantiated, with such tools as freeze/2 of SWI Prolog (as can be seen e.g. in this answer).

87 questions
32
votes
4 answers

Prolog - Arguments are not sufficiently instantiated

I am writing a little program which counts how many elements in a list are not numbers. Here is my code: not_number([],0). not_number([X|T],R):- not(number(X)), R1 is R+1, not_number(T,R1). not_number([_|Tail],Result):- …
Eddwhis
  • 1,124
  • 2
  • 16
  • 33
10
votes
5 answers

Simple prolog program. Getting error: >/2: Arguments are not sufficiently instantiated

I made a Prolog predicate posAt(List1,P,List2) that tests whether the element at position P of List1 and List2 are equal: posAt([X|Z], 1, [Y|W]) :- X = Y. posAt([Z|X], K, [W|Y]) :- K > 1, Kr is K - 1, posAt(X, Kr, Y). When testing: …
user1279812
  • 115
  • 2
  • 2
  • 8
5
votes
1 answer

Can this be made tail-recursive in Prolog?

I'm learning Prolog, and as an exercise, I'm experimenting with a simple database that calculates the sum of all numbers up to the given number (i.e. 0=0, 1=1, 2=3, 3=6, 4=10, ...). Easy enough: counting_sum(0, 0). counting_sum(Num, Sum) :- Num > 0,…
Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
5
votes
4 answers

Program to generate fibonacci series in GNU Prolog is giving an instantiation error

This is my code:- fib(0,0). fib(1,1). fib(F,N) :- N>1, N1 is N-1, N2 is N-2, F is F1+F2, fib(F1,N1), fib(F2,N2), write(F," ,"). On consulting in GNU Prolog, I am getting: | ?-…
user3341381
  • 53
  • 1
  • 1
  • 4
5
votes
3 answers

Prolog Arguments are not sufficiently instantiated

I'm trying to match a subset of the facts I'm creating, and my testcase was working great! x([1,2,3,4],'bleah'). x([1,2,4],'bleah2'). x([1,2],'bleah8'). x([1,3,4],'bleah3'). x([5,6,7,8],'bleah5'). x([6,7,8,9],'bleah6'). fuzzy(X,R) :- x(Z, R), …
Demosthenex
  • 4,343
  • 2
  • 26
  • 22
4
votes
2 answers

Not sufficiently instantiated arguments in `is/2`

For my "Declarative Languages" class we have to write a prolog program that solves Tangram puzzles. A puzzle is identified by a list of coordinates of the points of the puzzle. For example, puzzle(7,[(0,0),(8,0),(4,4)]) is a puzzle with identifier…
HDW
  • 308
  • 2
  • 14
4
votes
2 answers

Should I enforce mode declarations by throwing instantiation errors?

I have been working on some code in which I have predicates that either do not terminate or give incorrect solutions if they are used in certain modes. Here is an example: %! list_without_duplicates(+List1, -List2) is det. % % True if List2…
Nicholas Hubbard
  • 527
  • 2
  • 15
4
votes
1 answer

Prolog: Head of a variable list is not instantated

I'm writing a simple code generating a simple list with 5 numbers whose first variable should be positive and I'm trying to understand why this code fails test([H|T]) :- H > 0, length(T,4). when I call with length(X,5), test(X). it shows me the…
4
votes
1 answer

Prolog ERROR: is/2: Arguments are not sufficiently instantiated

I'm new to Prolog. I wrote a very short program as follows: plus(X,Y,R):- R is X+Y. When I run it, I get the following problem: ?- plus(1,1,2). true ?- plus(1,1,X). X=2 ?- plus(1,X,2). ERROR: is/2: Arguments are not sufficiently instantiated Why…
pfc
  • 1,831
  • 4
  • 27
  • 50
4
votes
2 answers

Enumerating binary trees in Prolog

I am trying to create Prolog rules to enumerate 'binary trees' in list form in Prolog. I am new to Prolog. A tree with 0 nodes is an empty list: [] A tree with 1 node is: [[],[]] A tree with 2 nodes has 2…
3
votes
2 answers

Keep getting the error message "Arguments are not sufficiently instantiated" can't understand why

Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition rule I wrote as shown below. mult(_, 0, 0). %base case for multiplying by 0 mult(X, 1, X). …
3
votes
1 answer

Insert into open-ended list without binding its tail variable

Is it possible to solve the following problem in Prolog? Let A and B be lists of numbers and let N be a number. It is known that B is sorted decreasingly. Check if N can be inserted into A so that the result is B, but do not bind any variable that…
Milos
  • 518
  • 7
  • 22
3
votes
1 answer

Correct use of is/2 predicate in Prolog recursion

I am a Prolog beginner with an imperative programming background. While solving assignments from this site, I bumped into two exercises: the first one regards finding the k-th elements of a list, the second one is about finding a list's length.…
3
votes
1 answer

Arguments not sufficiently instantiated when consulting file

I'm running SWI-Prolog on a Mac through the Terminal. I'm trying to access an Atom file by writing the usual after opening up swipl in the terminal: ?- [hwk1-my_name]. Instead of swipl having the knowledge base to play with, it's giving me…
quantumferret
  • 473
  • 6
  • 12
3
votes
1 answer

Error using string_to_atom: Arguments are not sufficiently instantiated

I'm working on a URI parser in Prolog, but at the moment I'm stuck with something much simpler. I am exploring a string to find a particular char, ":", and when I find it, I want to have a string that only contains the concatenated chars before…
Jonny
  • 45
  • 5
1
2 3 4 5 6