Question: Prolog arithmetic expression examples & exercise. It addition multiplication subtraction division A power Imod mod In prolog 'is' has a special functionality in evaluating arithmetic


Prolog arithmetic expression examples & exercise. It addition multiplication subtraction division A power Imod mod In prolog 'is' has a special functionality in evaluating arithmetic expressions. But with condition that the expression should be on the right side of 'is' otherwise it will give an error. On Prolog Query Prompt : ?- X is 3+2. X = 5. // expression on right side of 'is' ? - 3+2 is X. // expression on left side of 'is' ERROR: is/2: Arguments are not sufficiently instantiated ?- X = 3+2. // just instantiate variable X to value 3+2 X = 3+2. ?- 3+2 = X. X = 3+2. ?- X is +(3,2). X = 5. ?- 5 is 3+2. true. ? - 3+2 is 5. false. ?- X is 3*2. X = 6. ?- X is 3-2. X = 1. Exercise :- How does Prolog answer to below Queries (1) ? - 35. (4) ?- 123)=(4>3). (20) ?- X = 3, C is X*X*X. (21) ?- X = 3, X*X*X is C. (22) ?- is(Y,^(2,2)). // don't type space between 'is' and bracket =
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
