Question: solve is misbehaving

Here is a simple sequcnce of commands that execute without a problem:
restart;
eq1 := 5+3*x=0:
eq2 := 2+7*x-3*y-5*x*y=0:
x:=solve(eq1,x):
y:=solve(eq2,y):
lprint('x'=x,'y'=y);


x = -5/3, y = 29/16


If I put the commands into a procedure there are problems:


restart;
f:=proc()
local x,y,eq1,eq2;
eq1 := 5+3*x=0:
eq2 := 2+7*x-3*y-5*x*y=0:
x:=solve(eq1,x):
y:=solve(eq2,y):
lprint('x'=x,'y'=y);
end proc:

f();
x = -5/3, y = (2+7*x)/(3+5*x)

Usung assign in place of x :=solve... does not help:

restart;
g:=proc()
local x,y,eq1,eq2;
eq1 := 5+3*x=0:
eq2 := 2+7*x-3*y-5*x*y=0:
assign(solve(eq1,{x})):
assign(solve(eq2,{y})):
lprint('x'=x,'y'= y)
end proc:
g();
x = -5/3, y = (2+7*x)/(3+5*x)

The way to get the procedure to work is to not use the variables eq1 and eq2 but to stuff the equations into the solve command, e.g.,

restart;
h:=proc()
local x,y;
assign(solve(5+3*x=0,{x})):
assign(solve(2+7*x-3*y-5*x*y=0,{y})):
lprint('x'=x,'y'= y);
end proc:
h();
x = -5/3, y = 29/16
 
This is a toy problem; in real life I am dealing with 11 complicated equations and cutting and pasting them into the solve command is not practical or desirable.
Does anyone have any idea what is going on?

I think solve is changing x in some way.

Here is another peculiar set of commands;

restart;
x:=3:
lprint(`x = `||x):
lprint(`x is `||x):
`x = 3`
`x is 3`
restart;
eq := 5+3*x=0:
x:=solve(eq,x):
lprint(`x is `||x);
lprint(`x = `||x);
`x is ` || (-5/3)
`x = ` || (-5/3)
restart;
eq := 9+3*x=0:
x:=solve(eq,x):
lprint(`x is `||x);
lprint(`x = `||x);
`x is -3`
`x = -3`

Obviuosly for certain values of c the solution of the equation c+3x = 0 print nicely, for other values the || appears. How strange!
(Further experimenting shows that if c is divisble by 3, i.e., if the answer is an integer then it prints correctly.
 

Please Wait...