Define a constant that mimics the behavior of internal constants



On 2013-09-25, Luj Omu <lujomu at gmail.com> wrote:

> I'd like to replicate the behavior of built-in constants like %pi or %e 
> for custom constants. I.e. the constant should be displayed as a symbol 
> by default and only be substituted by its numeric value upon request.
>
> E.g. for the custom constant %2pi = 2*%pi:
> The line "3 * %2pi;" should result in "3 %2pi;" and not in "6 %pi;".
> The line "3 * %2pi, numer;" should result in "18.84955592153876".

For this much, try this:

  declare (%2pi, constant);
  numerval (%2pi, 6.28);

> The line "sin( %2pi);" should result in "0".

Well, this is more trouble -- it can be done, but, from what I can tell,
only one simplification rule at a time. There isn't a way to tell Maxima
to always treat %2pi the same as 2*%pi, except by actually substituting
that value, which you don't want to do, I gather.

That said, you can do it like this:

  tellsimp (sin (%2pi), 0);
  tellsimp (cos (%2pi), 1);
  tellsimp (tan (%2pi), 0);

etc.

> I guess another way to frame this question would be: Where and how are 
> the internal constants defined?

Unfortunately, Maxima is mostly not implemented in Maxima -- probably
(I didn't check) built-in constants are defined in Lisp code by
manipulating some symbol properties, instead of using the Maxima
functions mentioned above.

HTH

Robert Dodier