Re: Simplifying Units in Ezunits Package

Michael Soegtrop via Maxima-discuss <[email protected]> Thu, 14 May 2026 22:54:07 +0200
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <[email protected]>
Dear Robert, Mateusz,

> defrule (rfoo, aa + uu%, add_with_units_try_harder (aa, uu%));
> add_with_units_try_harder (x%, u%) :=
>      if op(u%) = "+"
>          then (if length (unique (map (second, u%))) = 1 then
> add_with_units (x%, u%) else add_with_units (x%,u% ``
> fundamental_units (first (u%))))
>          else x% + u%;

I am using an equivalent rule for this purpose - just I have 
"fundamental_units" replaced with "units". The rationale is that the 
unit of the first summand is usually closer to what one wants than 
"fundamental_units". Another important simplification rule when working 
with definite integrals is:

defrule(rlog_units, log(aa%), log(qty(aa%)) + log(units(aa%)))

This says "if you have a log of an expression with units (ezunits adds 
the % as marker for this as far as I understand) then split it into 
log(value)+log(unit). Definite integrals very frequently have 
differences of logarithms of arguments with units. If one would convert 
log(a)-log(b) to log(a/b), the units would factor out. Pulling them out 
this way is mathematically equivalent but easier to handle in 
complicated situations - radcan then eliminates the log(unit) terms. 
This only works if the units are the same - which is the case if the 
upper and lower bound of the definite integral have the same units. Of 
course, one could convert to fundamental units instead - then it would 
always work.

Best regards,

Michael