Skip to content

Automatic cancelation of derived units #1972

@dkirkby

Description

@dkirkby

When I multiply two quantities, I would expect that any unambiguous cancellations of derived units would be applied automatically, however this example using mathjs@7.2.0 returns "(J m) / (m s)" instead of the expected "J / s":

{
  let a=math.unit(1, 'J/m');
  let b=math.unit(1, 'm/s');
  return math.multiply(a,b).toJSON().unit;
}

If there are performance reasons to defer this type of automatic simplification, perhaps a method to manually trigger would be useful (and apologies if it already exists and I missed it). The toSI method is not what I am looking for since it returns "(kg m^2) / s^3" which is less useful than "J / s" in many contexts.

I noticed the skipAutomaticSimplification attribute, but setting this false on a and b before multiplying does not change the result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions