Re: ezunits tellsimpafter rules in user code

Robert Dodier <[email protected]> Wed, 17 Jun 2026 22:31:00 -0700
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <CAAsY_sT-mWEOLOfbvZZwFRb9_dbeUy1ayLRwga=9YA1Ufxt46g@mail.gmail.com>
On Wed, Jun 17, 2026 at 1:26 PM Michael Soegtrop via Maxima-discuss
<[email protected]> wrote:

> of course I want:
>
> tellsimpafter (signum (aa% ` bb%), signum (aa%));
>
> (with bb% removed).

The problem you've encountered is that aa% is declared with different
matchdeclare properties in different places in the ezunits code, and
so you are essentially wanting a previous declaration (namely that aa%
and bb% match anything).

I think you can get the behavior you want by declaring aa% and bb%
with the properties you want, e.g.

  matchdeclare ([aa%, bb%], all);
  tellsimpafter (signum (aa% ` bb%), signum (aa%));

matchdeclare properties are global, and persist until removed or
redeclared, but as a matter of good practice I think it's a good idea
to always declare the pattern variables just before they're used;
reusing pattern variables is convenient, but leads to just the problem
you've encountered.

In some ways it would be more comprehensible and predictable to tie
the matchdeclare properties to the rule definition more closely,
something like (this is just a would-be speculative construct)

  with (all (aa%), all (bb%), integerp (nn%)) define ((aa% ` bb%)^nn%
--> (aa%^nn%) ` (bb%^nn%));

so that the pattern variables can't be used outside of a limited
lexical context. I have experimented with similar constructs but so
far haven't come to any conclusions.

Another possibility to consider is

  matchdeclare (uu%, unitp);
  tellsimpafter (signum (uu%), signum (qty (uu%)));

That has the same behavior as the preceding example with explicit "`"
expressions, and it also recognizes expressions declared dimensional,
e.g.

  declare (z, dimensional);
  signum (z);
    => signum(qty(z));

If you are working with variables declared dimensional, maybe that's useful.

> and if I add it to the nondimensional functions as well:
>
> (map (nounify, [qty, sin, cos, tan, asin, acos, atan, atan2, log, exp,
> sinh, cosh, tanh, asinh, acosh,
> atanh, signum]),
>    apply (declare, [%%, 'nondimensional]));
>
> signum plays nicely with ezunits. I think it would be worth to add this.

Thanks for the hints. Can you give a few examples of how you are using
signum with dimensional quantities?

All the best

Robert


_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss