-1

I am trying to Implement plus(X,Y,Z) , which should return all triples of elements in the ring Z_m that satisfy the property X + Y = Z, etc.

Here is my codes:

plus(X,Y,Z):-read(M),A is mod(X,M),B is mod(Y,M),Sum is A+B,Z is Sum mod M.
times(X,Y,Z):-read(M),A is mod(X,M),B is mod(Y,M),Product is A*B,Z is Product mod M.

But it is said:

Arguments are not sufficiently instantiated
In:
   [2] _1430 is _1436 mod 5
   [1] plus(_1490,_1492,_1494) at  line 10

I am new to Prolog and I feel so clueless...

Miu
  • 3
  • 2

1 Answers1

1

You've only shown a tiny portion of the program.

The usual choices are:

  • Instantiate the variables (obvious)

  • Use freeze or when to delay usage

  • Use e.g. clpfd or clpBNR, which can handle arithmetic on vars

brebs
  • 3,462
  • 2
  • 3
  • 12