4

I suspect this is a bug. Further, I suspect it is already known, but I have not seen another example.

Solve[{0.7 == ha + a, 1.88 == 3.86 + Log10[a/ha]}, {a, ha}]
(* {{a -> 0.00725394, ha -> 0.692746}} *)
Solve[{0.7 == ha + a, 1.88 == 3.86 + Log10[a/ha]}, {ha, a}]
(* {} *)

Apparently, my students are correct, and buffer calculations are hard.

It seems to be a problem with whatever non-equivalent transformations means since adding either of the options Method->Reduce or VerifySolutions->True appears to resolve the variable-order-dependent solution.

The question: Is this behavior a bug or working as intended?

Tested on WIN 12.0.0 and RPI 12.0.1

Johu
  • 4,918
  • 16
  • 43
bobthechemist
  • 19,693
  • 4
  • 52
  • 138

2 Answers2

4
eqns = {0.7 == ha + a, 1.88 == 3.86 + Log10[a/ha]};

Use exact values

sol1 = Solve[eqns // Rationalize, {a, ha}] // Simplify

(* {{a -> 7/(10 + 100 10^(49/50)), ha -> 70/(100 + 10^(1/50))}} *)

sol1 // N

(* {{a -> 0.00725394, ha -> 0.692746}} *)

sol2 = Solve[eqns // Rationalize, {ha, a}] // Simplify

(* {{ha -> 70/(100 + 10^(1/50)), a -> 7/(10 + 100 10^(49/50))}} *)

sol2 // N

(* {{ha -> 0.692746, a -> 0.00725394}} *)
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • Certainly a workaround. I'm still wondering, though, why the order of variables is in any way related to whether or not exact values are used. – bobthechemist Mar 02 '20 at 17:25
2

In MMA Version 8.0 not Rationalize but Simplify of equations is sufficient to get right results both times.

Solve[{0.7 == ha + a, 1.88 == 3.86 + Log10[a/ha]} // Simplify, {a, ha}]

Solve[{0.7 == ha + a, 1.88 == 3.86 + Log10[a/ha]} // Simplify, {ha, a}]
Akku14
  • 17,287
  • 14
  • 32
  • Generally, though, one should give Solve exact input. It sometimes fails to cope with approximate numbers. – John Doty Mar 01 '20 at 17:07
  • @JohnDoty While in practice this appears to be true, I see no explicit statement in the documentation stating one should give the function exact input. Have I missed something? – bobthechemist Mar 01 '20 at 17:58
  • @bobthechemist The documentation doesn't always cover best practice. For Return it should say "Be sure you understand what this does before using it. Once you understand, you'll be hard pressed to find a sensible use case." – John Doty Mar 01 '20 at 20:20
  • 1
    @JohnDoty Return has its place in my opinion. – Mr.Wizard Mar 02 '20 at 09:35
  • @Mr.Wizard I didn't say it was impossible to find a sensible use case. Your example proves my point: the case you came up with was pretty obscure. – John Doty Mar 02 '20 at 18:28