Replies: 2 comments
-
That's a funny idea Adam, thanks for sharing. It feels quite specialistic to me though, I'm not sure if this is something useful to many people in many situations. I think it's great to share as a separate npm library, as an extension of mathjs, and not integrate it with mathjs itself because it's quite a niche. Thinking aloud: something like this could really shine in a "recipe calculator assistant app" instead of just as an abstarct mathematical expression. Such an app could use mathjs under the hood. Something visual appealing to enthusiastic cooks who like to do some calculations but are no pros with maths ;) what do you think? |
Beta Was this translation helpful? Give feedback.
-
This is more of an open-ended idea. Moving to Discussions. |
Beta Was this translation helpful? Give feedback.
-
There are a number of scenarios where you would like to aggregate units of different types together in a "sum".
A simple example might be ingredients for a recipe. Native support for a unit sum makes it easy to do things like combine the ingredients for any number of recipes together with simple addition.
Beyond addition, there are other operations that make sense in the context of a UnitSum. For example there are two definitions of "inner product" that are valuable.
One is defined as the sum-product of "exact" unit matches, so (2 egg + 2 tomato + 2 egg / day) • (3 egg) == 6 egg
The other is the sum-product of "fuzzy" unit matches,
so (1 egg / day + 1 croissant / mile) • (2 day + 4 mile) = (2 egg + 4 croissant)
All of the above is implemented in https://observablehq.com/@ajbouh/math-js-with-unitsum
I'd love to contribute this upstream!
I should add that there are a few open questions, like what the names for these operations should be and how to avoid needing to override so many internal mathjs operations.
This was originally filed over at ericman314/UnitMath#13 but it appears that math.js is really the right home for it, considering that it needs to define a number of mathjs-specific operations.
I have fully integrated UnitSum into math.js in a way that is compatible with existing syntax and semantics. It's closed under both addition and scalar multiplication. It's also closed under both inner products I defined previously.
Beta Was this translation helpful? Give feedback.
All reactions