# Solving a consistent overdetermined linear system

Not a duplicate question. I already tried all the Answers offered for this Question and they failed, so I believe this is a different problem with Solve[].

I have a solveable, consistent system of linear equations. The complete system is zAll, and {z1,z2,z3} are subsets of it.

zAll = {};
y[x] := Sum[c[i]*x^i, {i, 1, 4}];
Do[
poly = Expand[D[(x^j)*Exp[y[x]], {x, i}]/Exp[y[x]]];
If[Exponent[poly, x] <= 8,
zAll = Append[zAll, (poly /. x^q_ -> m[q] /. x -> m[1])]],
{j, 0, 5}, {i, 1, 3}];
z1 = zAll[[{1, 3}]];
z2 = zAll[[{5, 7, 8, 9}]];
z3 = zAll[[{2, 4, 6}]];


I need to solve for {m[5],m[6],m[7],m[8]} in terms of {m[1],m[2],m[3],m[4],c[1],c[2],c[3],c[4]}

This can be done with just the subset z2:

m5678=Solve[z2 == 0, {m[5], m[6], m[7], m[8]}]


That the system zAll is consistent can be proven by showing that the solutions to z1 and z2 reduce z3 to zeroes:

m34 = Solve[z1 == 0, {m[3], m[4]}];
z3 /. m5678 /. m34 // Expand // Together

(*   {{{0, 0, 0}}}   *)


My problem is that in related linear system problems, it's not really possible to hand-pick the subset that does the trick. So how can I make MMa solve this solveable problem starting with the entire system zAll?

This fails, returning an empty set solution:

Solve[zAll == 0, {m[5], m[6], m[7], m[8]}]


This hack sort of works, but it returns ugly, ugly solution because of the undesired elimination of m[3] and m[4] as variables:

Solve[zAll == 0, {m[3], m[4], m[5], m[6], m[7], m[8]}]


I don't want to Eliminate m[3] and m[4], I want them in a tidy solution like the m5678 above, but without having to hand-pick a subset.

ADDENDUM TO QUESTION

@bbgodfrey gave a very helpful Answer below that partly fixed my problem but raised a new mystery. He suggested using this instruction:

s = Solve[zAll == 0, {m[5], m[6], m[7], m[8]}, MaxExtraConditions -> Automatic]


This returns exactly the result I want, but as a ConditionalExpression, with conditions on the values of m[1] and m[2]. But those "conditional" values of m[1] and m[2] are verifiably true in this linear system. In fact, the hack with ugly results (that I complained about in my Question) returns values of m[1] and m[2] equivalent to these "conditional" values.

So, why is MMa correctly solving for those values in my hack, but lists them as conditions when you apply @bbgodfrey's method?

And how can I fix this. I am cautious about just accepting that conditions are true, because some similar problem might return additional conditions that aren't true.

• The "Details and Options"documentation section for Solve contains this important bullet item: "Solve gives generic solutions only. Solutions that are valid only when continuous parameters satisfy equations are removed. Other solutions that are only conditionally valid are expressed as ConditionalExpression objects." This may address your question regarding SOlve behavior. – Daniel Lichtblau Sep 9 '15 at 6:58

## 1 Answer

Actually, the third approach in the question referenced by this queston does solve the problem, although it is much more complex.

s = Solve[zAll == 0, {m[5], m[6], m[7], m[8]}, MaxExtraConditions -> Automatic]


Because the answer is quite lengthy, we present only the expression for m[5].

s[[1, 1]]
(* m[5] -> ConditionalExpression[(-2 m[1] - c[1] m[2] - 2 c[2] m[3] -
3 c[3] m[4])/(4 c[4]),
m[2] == (c[1]^2 - 2 c[2] - 6 c[2] c[3] m[3] + 4 c[1] c[4] m[3] -
8 c[2] c[4] m[4])/(4 c[2]^2 - 3 c[1] c[3]) &&
m[1] == (-c[1] - 3 c[3] m[2] - 4 c[4] m[3])/(2 c[2])] *)


If the author is convinced that the conditions are met, then they can be discarded.

s[[1]] // Normal // Simplify
(* {m[5] -> -((2 m[1] + c[1] m[2] + 2 c[2] m[3] + 3 c[3] m[4])/(4 c[4])),
m[6] -> (3 c[3] (2 m[1] + c[1] m[2] + 2 c[2] m[3]) + 9 c[3]^2 m[4] -
4 c[4] (3 m[2] + c[1] m[3] + 2 c[2] m[4]))/(16 c[4]^2),
m[7] -> (1/(64 c[4]^3))(-9 c[3]^2 (2 m[1] + c[1] m[2] + 2 c[2] m[3]) -
27 c[3]^3 m[4] + 12 c[3] c[4] (3 m[2] + c[1] m[3] + 4 c[2] m[4]) +
8 c[4] (c[2] (2 m[1] + c[1] m[2]) + 2 c[2]^2 m[3] - 2 c[4] (4 m[3] +
c[1] m[4]))),
m[8] -> (1/(256 c[4]^4))(27 c[3]^3 (2 m[1] + c[1] m[2] + 2 c[2] m[3]) +
81 c[3]^4 m[4] - 36 c[3]^2 c[4] (3 m[2] + c[1] m[3] + 6 c[2] m[4]) +
16 c[4]^2 (c[1]^2 m[2] + 6 c[2] m[2] +
2 c[1] (m[1] + 2 c[2] m[3]) + 4 c[2]^2 m[4] - 20 c[4] m[4]) -
48 c[3] c[4] (c[2] (2 m[1] + c[1] m[2]) + 2 c[2]^2 m[3] -
2 c[4] (2 m[3] + c[1] m[4])))} *)


This is equivalent to the solution presented in the question.

Simplify[m5678[[1]]] == %
(* True *)


Addendum

This addition responds to the addendum in the question. The system of equations can be solved completely by

sAll = Solve[zAll == 0, Table[m[i], {i, 8}], MaxExtraConditions -> Automatic][[1]]
// Simplify


giving {m[1], m[2], m[5], m[6], m[7], m[8]} in terms of {m[3], m[4]} with no conditions. This is consistent with the observation in the question that only six of the nine equations are independent. With a LeafCount of 981, sAll is too long to be reproduced here. We can, however, profitably construct

Simplify[s[[1, All, 2, 2]] /. sAll]


which picks out the required conditions in s, which are all the same,

(* m[2] == (c[1]^2 - 2 c[2] - 6 c[2] c[3] m[3] + 4 c[1] c[4] m[3] -
8 c[2] c[4] m[4])/(4 c[2]^2 - 3 c[1] c[3]) &&
m[1] == (-c[1] - 3 c[3] m[2] - 4 c[4] m[3])/(2 c[2]) *)


and evaluates them with the general solution sAll, yielding

(* {True, True, True, True} *)


This validates that the conditions can be dropped from s, as desired.

• Thank you, that was helpful. But it's doing something odd. I've added an Addendum to the Question. Also, what is that cool "== %" trick you did at the end of your Answer? I haven't seen that before and it's not easy to Search on. – Jerry Guern Sep 5 '15 at 7:59
• @JerryGuern Here, % refers to the immediately preceding Output. I could just as well written, Simplify[m5678[[1]]] == s[[1]] // Normal // Simplify. I shall think later today about why Mathematica felt it necessary to use conditions you believe are true. Sometimes, Mathematica just does not simplify results as much as possible. – bbgodfrey Sep 5 '15 at 13:41
• @JerryGuern My addendum to the answer shows that the conditions in s indeed are satisfied and be dropped. Perhaps, Mathematica did not recognize this, because to obtain s it solved only for {m[5], m[6], m[7], m[8]}` rather than for the complete set of variables. By the way, I believe it would be more accurate to describe in the title your set of equations as underdetermined rather than overdetermined. – bbgodfrey Sep 5 '15 at 15:30
• I'm thinking hard about your Addendum. But this system is overdertermined because it contains more relations then are necessary to solve it for the variables I want. If I were solving for all the m[]'s, it would indeed be underdetermined. – Jerry Guern Sep 6 '15 at 2:28