-1

Doing a remainder operation gives an error in z3py code

Following is my code

    x = Real("x")
    solve( x%2 == 3 )

The Code gives the following Error :

    z3.z3types.Z3Exception: Z3 integer expression expected

whereas when I am doing division operation it is working perfectly

    solve( x/2 == 3 )

(It gives an answer of 6)

Is remainder operation not supported in z3? If it is how can achieve it?

infiNity9819
  • 536
  • 2
  • 7
  • 19
  • Does the error happen on the `solve()` line, or the `x = Real()` line? – John Gordon Sep 23 '18 at 19:22
  • solve(). The error is happening when I call solve(...) – infiNity9819 Sep 23 '18 at 19:23
  • 1
    Is it possible for _any_ number to have `x % 2 == 3`? If you're dividing by two, the largest possible remainder would be 1 (or 1.999), would it not? – John Gordon Sep 23 '18 at 19:26
  • That's what. Technically z3 should output 'unsat' as that equation is not satisfiable for any real value for x. Also this '%' operator is not working anywhere however it is used, whether a satisfiable soln exists or not. – infiNity9819 Sep 23 '18 at 19:33
  • _Also this '%' operator is not working anywhere_ Modulo operations typically have many solutions, i.e. `x % 2 == 1` is true for any odd number. What is `solve()` supposed to do if there are many possible solutions? – John Gordon Sep 23 '18 at 19:38
  • According to z3 manual if there are many satisfying assignments, it gives any one of them. – infiNity9819 Sep 23 '18 at 19:45
  • _According to z3 manual_ Have you tried one of the modulo examples in the manual, and does it behave as advertised? – John Gordon Sep 23 '18 at 19:46
  • Perhaps the issue is that the `%` operator returns a floating-point value, not an integer, if either of the operands is a floating-point value? Although division works the same way, so I would have expected the other operation to have the same issue. – John Gordon Sep 23 '18 at 19:52
  • There is no modulo example in the manual. – infiNity9819 Sep 23 '18 at 20:19

1 Answers1

2

Modulus for a real-value doesn't make sense; as real-valued division is precise.

It does make sense for integers. Is that what you intended? (Note your definition of x being Real.)

alias
  • 28,120
  • 2
  • 23
  • 40