> (%i1) batch("C:/Program Files/Maxima-5.11.0/share/maxima/5.11.0/share/physics
> /physconst.mac")$
>
> and from some equation we have arrived at our engineering result:
> (%i359) %%c;
> (%o359) %%c
>
> So we evaluate it
> (%i360) ev(%%c);
> (%o360) %%c
>
> no not yet, say then
> (%i361) ev(%%c,bfloat);
> (%o361) %%c
>
> not yet, say then
> (%i362) ev(%%c,numer : true);
> (%o362) (299792458*m)/s
>
> ok.
Well the correct usage is documented in physconst.usg. I agree with
you, that the current behavior is somewhat unintuitive, but I'm not
yet sure what would be the best way out of this. But see below ...
> There may be room for discussion here but for me the word float
> disambiguates to produce numerical values or numer.
While it is clear what you want you have to remember, that you are
not talking to some intelligent being but to some programm. By
just mentioning something, you wont get much ...
But leaving aside physconst.mac for a moment the semantics of
numer, float and bfloat seem somewhat mixed up to me. No wonder
Edward got confused if he didn't read the maxima manual from
end to end several times:
First we have to distinguish between flags (numer, float)
(%i3) numer;
(%o3) false
(%i4) float;
(%o4) false
(%i5) bfloat;
(%o5) bfloat
and functions (float(), bfloat())
(%i6) float(1);
(%o6) 1.0
(%i7) bfloat(1);
(%o7) 1.0b0
(%i8) numer(1);
numer evaluates to false
Improper name or value in functional position.
-- an error. To debug this try debugmode(true);
While I see the difference between numer on one side and float and
bfloat on the other. I think the difference between float and bfloat
is less obvious.
The documentation says the following:
The flags:
* `float' causes non-integral rational numbers to be
converted to floating point.
* `numer' causes some mathematical functions (including
exponentiation) with numerical arguments to be evaluated
in floating point. It causes variables in <expr> which
have been given numervals to be replaced by their
values. It also sets the `float' switch on.
This is actually quite clear and unambiguous, but not necessarily
the behavior I'd expect naively.
-- Function: float (<expr>)
Converts integers, rational numbers and bigfloats in <expr> to
floating point numbers. It is also an `evflag', `float' causes
non-integral rational numbers and bigfloat numbers to be converted
to floating point.
Which somewhat contradicts the above statement about the "float" flag,
as there isn't mentioned the behavior regarding bigfloats ...
-- Function: bfloat (<expr>)
Converts all numbers and functions of numbers in <expr> to
bigfloat numbers.
(%i10) 1,numer;
(%o10) 1
Ok, 1 already is a number. But wait, didn't the documentation say
to evaluate things in floating point? Perhaps "1" is not a
mathematical function ...
(%i11) 1,float;
(%o11) 1
The documentation said to only convert non-integral rational numbers.
But why?
(%i18) float(1);
(%o18) 1.0
(%i12) 1,bfloat;
(%o12) 1.0b0
Since bfloat is no flag, ev() applies bfloat() ... which actually
yields the most expected result.
(%i14) sin(1),numer;
(%o14) .8414709848078965
(%i15) sin(1),float;
(%o15) sin(1)
(%i16) sin(1),bfloat;
(%o16) 8.414709848078965b-1
(%i19) %e, numer;
(%o19) 2.718281828459045
(%i20) %e, float;
(%o20) %e
(%i21) float(%e);
(%o21) 2.718281828459045
Hm, one more difference between evflag and float(). But why? Also this
is not documented!
(%i22) bfloat(%e);
(%o22) 2.718281828459045b0
Let's investigate the issue with %e a bit further:
(%i23) numerval(a, 1);
(%o23) [a]
(%i24) a,numer;
(%o24) 1
(%i25) a,float;
(%o25) a
(%i26) float(a);
(%o26) 1
WTF? I'd expect 'a', but if for some reason we decide to evaluate numervals
in float(), then I'd at least expect the result to be converted to float!
(%i27) bfloat(a);
(%o27) a
The next example speaks for itself:
(%i32) numerval(a, 1/2);
(%o32) [a]
(%i33) a,numer;
(%o33) 0.5
(%i34) a,float;
(%o34) a
(%i35) float(a);
(%o35) 1/2
(%i42) float(a),float;
(%o42) 0.5
The last behavior is caused by the fact that numer implies float, which
is also mentioned in the documentation of numer.
(%i44) numer,float;
(%o44) false
(%i45) float,numer;
(%o45) true
While I can understand this from a convenience point of view, I'm not
convinced that mixing quite different things in such a way is a good
idea. At least it would seem to me more logical the other way around.
Also the current behavior can be really wierd:
(%i47) numerval(a, 1b0);
(%o47) [a]
(%i48) a;
(%o48) a
(%i49) a,numer;
(%o49) 1.0
(%i50) a,float;
(%o50) a
(%i51) a,bfloat;
(%o51) a
(%i52) float(a);
(%o52) 1.0b0
(%i53) bfloat(a);
(%o53) a
The above examples probably show severaly bugs in the code as well as in the
documentation. But I think we first should discuss, which behavior actually
is desireable before I file any bug reports.
I think the behavior I'd expect from maxima is, that float() and bfloat()
work as symmetrical as possible and that numer is mostly independent from
the others only causing the substitution of numervals. Perhaps with some
numer:auto setting which is interpreted as true in the case of
float or bfloat evaluation and false otherwise to make things like
"%e,float;" work.
Also I fail to see any advantage of the evflag "float".
Regards,
Harald