15
$\begingroup$

Bug introduced in 9.0 and fixed in 10.0.0


Here is a trivial system of equations in three unknowns for which FindInstance obtains a solution:

FindInstance[
 c3 + c2 == 1 && c1 == 0 && -c2 == 0, {c1, c2, c3}]

(* ==> {{c1 -> 0, c2 -> 0, c3 -> 1}} *)

But in my application, I have a linear system where I want to rule out the trivial solution c1==c2==c3 with an inequality:

FindInstance[
 (c3 != 0 || c2 != 0) && c1 == 0 && -c2 == 0, {c1, c2, c3}]

(* ==> {{c1 -> 0, c2 -> Indeterminate, c3 -> 1}} *)

This incorrectly returns Indeterminate for c2 only in Mathematica version 9, whereas it gives a correct result c2 -> 0 in version 8. In general, my variables are complex so that I can't restrict the domain to Reals (which solves the problem in this simple example).

My current solution to this issue is to replace the inequality by an equation, e.g., Norm[{c1, c2, c3}] ==1. But I would like to understand (if at all possible) what change between versions is causing the Indeterminate result. I have a version-8 notebook that suddenly produced Indeterminate in over half its calculations, and there is no documented change in FindInstance that I'm aware of. So I'd like to hear what the safest and/or most efficient way would be to rule out the trivial solution in FindInstance for a system of linear equations.

$\endgroup$
5
  • 1
    $\begingroup$ Here's a workaround: For some reason, Mathematica only returns the Indeterminate if you ask for 1 result. Ask for 2 and take the first one. $\endgroup$
    – Xerxes
    Commented Mar 7, 2013 at 22:36
  • $\begingroup$ @Xerxes That's funny. But then my workaround with Norm still gives a simpler result. $\endgroup$
    – Jens
    Commented Mar 7, 2013 at 23:38
  • 3
    $\begingroup$ I will second Adam's "thanks for pointing it out". $\endgroup$ Commented Mar 8, 2013 at 0:21
  • $\begingroup$ Sorry for taking the version-9 off, but I thought that was the policy adopted in this meta discussion. $\endgroup$
    – Michael E2
    Commented Aug 14, 2015 at 19:50
  • $\begingroup$ @MichaelE2 Oh, I wasn't aware of that, or maybe forgot. It's OK - I'll remove the tag again. Too bad we don't have a real bug tracker. $\endgroup$
    – Jens
    Commented Aug 14, 2015 at 20:31

2 Answers 2

20
$\begingroup$

This problem can be fixed with the following patch (you can put it in your init.m file).

Unprotect[Internal`FromCoefficientList];
Internal`FromCoefficientList[cfs_List, 0] := If[cfs==={}, 0, cfs[[1]]];
Protect[Internal`FromCoefficientList];

Resolving the problem:

FindInstance[(c3 != 0 || c2 != 0) && c1 == 0 && -c2 == 0, {c1, c2, c3}]
(* {{c1 -> 0, c2 -> 0, c3 -> 1}} *)

Thanks for pointing it out.

$\endgroup$
3
  • $\begingroup$ I tried it on about twenty different systems of equations, and everything is back to what it looked like in version 8. So the problem seems to be solved. Thanks for the quick response! $\endgroup$
    – Jens
    Commented Mar 7, 2013 at 23:45
  • $\begingroup$ Welcome to Mathematica.StackExchange, Adam. $\endgroup$
    – Mr.Wizard
    Commented Mar 8, 2013 at 4:42
  • $\begingroup$ Maybe it would be better to surround this with If[$Version == 9, ...] to avoid trouble after any future upgrades (since users will likely keep their init.m but might forget about modifications). $\endgroup$
    – Szabolcs
    Commented Dec 6, 2013 at 18:51
3
$\begingroup$

On v10.0.0,

In[1]:= FindInstance[(c3 != 0 || c2 != 0) && c1 == 0 && -c2 == 0, {c1, c2, c3}]

Out[1]= {{c1 -> 0, c2 -> 0, c3 -> 1}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.