Suppose we have a programming language ℤ which has the following syntax:
ℤ := 0 | 1 | (+ ℤ ℤ) | (* ℤ ℤ) | (- ℤ ℤ) | (max ℤ ℤ)
For convenience, we can define new binding forms in our language as follows:
(not x) = (- 1 x)
(abs x) = (- (max 0 (+ x x)) x)
(min x y) = (- 0 (max (- 0 x) (- 0 y)))
(nil x) = (not (min 1 (abs x)))
This language is powerful enough to express branching and comparison operators:
(if x y z) = (+ (* x y) (* (not x) z))
(eq x y) = (nil (- x y))
(ne x y) = (not (eq x y))
(le x y) = (nil (max 0 (- x y)))
(gt x y) = (not (le x y))
(ge x y) = (le y x)
(lt x y) = (not (ge x y))
Now, the question is whether we can define integer division is this language:
(div x y) = ?
(rem x y) = (- x (* y (div x y)))
I don't think that it's possible to define (div x y)
because ℤ doesn't have loops. However, I don't know how to prove it. Note that if it's possible then the result of (div x 0)
doesn't matter. Hence, either define (div x y)
or prove that it's impossible to do so.