equal(a,0) tests whether the expression a can be determined to be 0, while
a=0 tests whether it is the exact expression 0. For example:
assume(equal(a,3))$ is(equal(a-3,0) ) => true; is(a-3=0) => false; while
is(equal(b,0)) => unknown
For a few years now, the Maxima condition
if <condition> then <a> else <b>
has simply returned the whole conditional unevaluated if <condition> cannot
be evaluated (= is unknown). This can be handy when manipulating
conditionals as expressions, but is of course problematic (does nothing and
causes no error) if you're executing it for side effect.
In your case, Maxima doesn't know whether a is equal to 0. You can see
this behavior by executing the conditional by itself:
if equal(a,0) then 0 else 1/a => if equal(a,0) then 0 else 1/a
I find conditionals-as-expressions very valuable, but I don't think
conflating them with conditions-as-statements is a great idea.
If you set prederror:true, you will get an error if 'if' conditions can't
be evaluated.
-s
On Tue, Jul 30, 2013 at 1:47 PM, David Ronis
<ronis at ronispc.chem.mcgill.ca>wrote:
> I have a function that manipulates some complicated expressions a maxima
> script generates. In the function, I do several tests. Here's a
> sample code that shows what I do:
>
> fcn(xx) := block
> (
> if equal(xx, 0) then
> print("equal shows that xx is zero")
> else
> print("equal doesn't show that xx is zero", xx),
>
> if xx=0 then
> print("xx=0 test is true." )
> else
> print("xx=0 test is false:", xx)
> )$
>
> fcn(a);
> fcn(a-a);
>
> which gives:
> (%i2) fcn(a);
> xx=0 test is false: a
> (%o2) a
> (%i3) fcn(a-a);
> equal shows that xx is zero
> xx=0 test is true.
> (%o3) xx=0 test is true.
>
>
>
>
>
> Notice that the 1st test doesn't give any answer (it does if I add an
> assume(a>0)). Is this a syntax error on my part or is this a bug?
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>