Question: why this difference in evaluation when using named variables?

Without trying it or looking down more, should these two code fragments give same output or not

# CASE 1

restart;
A   :=   2;
B   :=   x+2*y;
t^2 * ( A * B );


#CASE 2
restart;
t^2*( 2 * (x+2*y)  );

One would expect both to give same output, right? CASE 1 just uses variables and CASE 2 just uses the values of these variables. I mean the semantics of CASE 1 and 2 are the same, given that Maple replaces each variable with its value when evaluating.

But Maple does not give same result.

One way to force same result when using variables is to use t^2*(eval(A*B));

My question is why CASE 1 gives different result from CASE 2?  I would have expected same output.

Maple 2021.2 on windows 10. Worksheet.

interface(version);

`Standard Worksheet Interface, Maple 2021.2, Windows 10, November 23 2021 Build ID 1576349`

restart;

A:=2;
B:=x+2*y;
t^2*(A*B);

2

x+2*y

2*t^2*(x+2*y)

restart;

t^2*(2*(x+2*y));

t^2*(2*x+4*y)

restart;

A:=2;
B:=x+2*y;
t^2*(eval(A*B));

2

x+2*y

t^2*(2*x+4*y)

 

Download why_different.mw

Please Wait...