# Grouping units more sanely

Would it be possible to get Mathematica to group units more sanely. For example the calculation:

m = Quantity["Meters"];
D[
D[
Sin[p] (m),
Quantity[p, "Seconds"]] ,
Quantity[p, "Seconds"]] // Expand


This gives an visual output:

(-1 m/s^2) Sin[p]


however it would be more natural to show:

 -Sin[p](m/s^2)


I there a way to make this happen.

Notes:

• Expand is strictly not necessary in this case but can nice be in more complex cases.

These seem to work

m = Quantity[#, "Meters"] &;
D[D[Sin[p] // m, Quantity[p, "Seconds"]],
Quantity[p, "Seconds"]] // Expand


Or you transform by hand

nonQuantitiesAsMagnitudes[expr_] :=
expr /. x_ Quantity[y_, unit_] :> Quantity[x y, unit]

m = Quantity["Meters"];
D[
D[
Sin[p] (m),
Quantity[p, "Seconds"]] ,
Quantity[p, "Seconds"]] // Expand //nonQuantitiesAsMagnitudes

• Yeah that's it. Still think that Mathematicas syntax for units is atrocious. My engineering students seem to come up with hives about this. But i think they can live with this. What does the &; do? – joojaa Jan 13 '14 at 19:25
• Terribly late reply, but & makes the preceding term into a pure function, while the ; ends the statement and suppresses output. This means you can use m as a function, where # represents the first argument: m[1] would evaluate to Quantity[1,"Meters"]. The // in the second line is a postfix function application, so the m is used as m[Sin[p]]. – Widjet Mar 9 '15 at 6:03