Sem 7‎ > ‎AI‎ > ‎

WAP to perform simple arithmetic operations.

posted Jul 30, 2013, 12:11 AM by Neil Mathew

COMMANDS ON SWI-Prolog Shell









    //  Note the variables should not be in small case. It needs to have at least one Upper Case character.

1 ?- a is 2.
false.

2 ?- A is 2.
A = 2.

3 ?- number is 2.
false.

4 ?- Number is 2.
Number = 2.
    //  Note:  Commands like 'is' is case sensitive.


1 ?- A IS 7.
ERROR: Syntax error: Operator expected
ERROR: A 
ERROR: ** here **
ERROR: IS 7 . 
1 ?- A is 7.
A = 7.
// Note:  Separate the statements using commas. End the line with a dot.


1 ?- X is 7. Y is 3. Z is X+Y.

X = 7.


Y = 3.

ERROR: is/2: Arguments are not sufficiently instantiated
4 ?- X is 7, Y is 3, Z is X+Y.
X = 7,
Y = 3,
Z = 10.
// NOte the difference between = and is


1 ?- X is 7, Y = 10, C is X + Y.
X = 7,
Y = 10,
C = 17.

2 ?- X is 7, Y = 10, C = X + Y.
X = 7,
Y = 10,
C = 7+10.


Comments