Assume I have a number X and I wish to solve system of equations, say Y+Z=X, Z*Y = 1.
Now, this has solutions Y=1/Z and Z = (sqrt(X*X-4)+X)/2 or (X-(sqrt(X*X-4)))/2.
So I can write in Prolog:
solve(X,Y,Z):- Y is (sqrt(X*X-4)+X)/2, Z is 1/Y.
solve(X,Y,Z):- Y is (X-(sqrt(X*X-4)))/2,Z is 1/Y.
This works.
BUT
it requires a lot of preliminary work from my part, essentially solving it beforehand and just asking Prolog to evaluate the answer.
Is there some way I can get Z and Y, without solving X beforehand?
I cannot just write stuff like
solve(X,Y,Z):- X is Y+Z, Z is 1/Y.
because of instantiation error.