# Why will a Log expression with Quantity expressions not get simplified? [closed]

I'm having trouble with numerically evaluating some functions. The problem essentially comes down to

Log[Quantity[3, "Meters"]] - Log[Quantity[2, "Kilometers"]]


The above code doesn't evaluate to a numerical answer even though it should since $$\log(3\ {\rm m}) - \log(2\ {\rm km}) = \log \left(\frac{3\ {\rm m}}{2\ {\rm km}} \right)=\log\left(\frac 3{2000}\right)$$ Is there a way to get mathematica to automatically combine the logs of unitful quantities?

EDIT:

Note the following:

Log[ Quantity[3, "Meters" ] / Quantity[2, "Kilometers"] ]
(* -Log[2000/3] *)

Simplify[ Log[a] - Log[b], b > 0]
(* Log[a/b] *)

Simplify[ Log[ Quantity[3, "Meters"] ] - Log[ Quantity[2, "Kilometers"] ] ]
(* Log[ 3 m ] - Log[ 2 km ] *)

• Log[QuantityMagnitude@Quantity[3, "Meters"]] - Log[QuantityMagnitude@Quantity[2, "Kilometers"]] // N could be a workaround.
– Syed
Commented Nov 23, 2021 at 5:37
• @Syed - You need a UnitConvert, i.e., Log[QuantityMagnitude@Quantity[3, "Meters"]] - Log[QuantityMagnitude@UnitConvert@Quantity[2, "Kilometers"]] // N Commented Nov 23, 2021 at 5:46
• Log[Quantity[3, "Meters"]] - Log[Quantity[2, "Kilometers"]] /. Log[a_] - Log[b_] :> Log[a/b] Commented Nov 23, 2021 at 5:51
• Completely missed that units were different. Thanks @BobHanlon
– Syed
Commented Nov 23, 2021 at 5:53
• Log[ Quantity[3, "Meters"] ] is undefined. The first example is unrelated because Quantity[3, "Meters"]/Quantity[2, "Kilometers"] evaluates to a number. So the question is comparing the logarithm of a number with logarithms of distances. Commented Apr 30, 2022 at 22:02