Re: ezunits fundamental_units quite slow
Michael Soegtrop via Maxima-discuss <[email protected]> Sun, 17 May 2026 10:59:28 +0200
| Newsgroups | gmane.comp.mathematics.maxima.general |
|---|---|
| Message-ID | <[email protected]> |
Dear Robert, > I'm pretty happy with ezunits as a whole at this point, and I feel > like some substantial speed-ups might be pretty easy to implement, so > I will try to take a look at that in the near future. Indeed I am also quite happy with ezunits. I recently ported a largish computation (~150 pages as PDF export) from Mathematica to Maxima and it is faster in Maxima. I can't as yet how much because I am not yet finished with the port and also I did some things slightly different. But it is definitely not so that ezunits is painfully slow in general. The computation has complicated antiderivatives (for some I use FriCAS* via a simple export/syscall/import method) which leads to huge terms and ezunits works just fine with this. What I can say is that the unit system in Mathematica is were verbose on input and very hard to use. The interface of ezunits is very nice. > I suspect a lot of the slow operations have to do with processing the > same expressions over and over and over. I am not sure the slowness of fundamental_units can be fully explained this way. As far as I understand after a quick look it uses a combination of rules, substitutions, recursion and infinite evaluation with a large list of unit conversions. The tricky thing is that units can be defined based on other units. What I had in my patched version was computing the fundamental units right away on definition of a unit and hashing them. This has the effect than one cannot change units later any more - or that derived units would not change with them - but this is not a sensible use case IMHO. Let me also have a look and let's discuss optimization opportunities. > You may be interested to hear I have pushed commit 6da388 which > implements a new function, all_fundamental_units, which converts all > explicit dimensional expressions (i.e., stuff like a ` b) to > fundamental units. This is a function which can be applied explicitly; > it isn't applied automatically, since in a lot of cases one would want > to work with non-fundamental units. In the case I mentioned I convert all inputs to fundamental units and convert the output. If I would compute with standard units I would anyway end up with stuff worse than J^9/(Pa^8*mm^8*m^16) for J - the (automatically) reduced fundamental units are more readable in such cases - and this also makes addition work without rules. But for simpler cases all_fundamental_units is definitely nice. The caching works fine for me as a work around. I even dump the cache contents in the end and initialize it with the dump, so I have no fundamental_units calls any more unless I add new stuff. Best regards, Michael * I will start a separate thread on this topic.