# How to Solve[] for rational constants?

I am trying to solve a system equations for rational, constant coefficients:

ord = 3;
vars = {a, b, c, d, e};
Do[tt[nn] = Total[vars^nn], {nn, 1, ord}];
mm = (Expand[tt^ord] /. mm_^nn_ -> 0)/ord! // Expand; (*Sum of products of all unique sets of 3*)
expr = cc*tt^3 + cc*tt*tt + cc*tt - mm;
aa = Solve[{expr == 0}, {cc, cc, cc}]

(*{{cc -> -((-a b c - a b d - a c d - b c d - a b e - a c e - b c e - a d e - b d e - c d e)/(a^3 + b^3 + c^3 + d^3 + e^3)) - ((a + b + c + d + e)^3 cc)/(a^3 + b^3 + c^3 + d^3 + e^3) - ((a + b + c + d + e) (a^2 + b^2 + c^2 + d^2 + e^2) cc)/(a^3 + b^3 + c^3 + d^3 + e^3)}} *)


This is the correct result for an under-determined system like this one, with 1 eqn and 3 unknowns. However, if we require that the cc[]'s be rational constants, i.e. independent of {a, b, c, d, e}, then the only solution (which I calculated by hand) is:

bb = {cc -> 1/6, cc -> -1/2, cc -> 1/3};
expr /. bb // Expand

(* 0 *)


How can I get such solns from MMa? How does one impose the condition that the soln coefficients must be rational constants?

Ultimately, I need to do this with arbitrarily large vars lists and larger values of ord where ord < Length[vars].

Take a look at SolveAlways (documentation page). In this case:

SolveAlways[expr == 0, vars]
(* Out: {{cc -> 1/6, cc -> -(1/2), cc -> 1/3}} *)


It may be, however, that in a more complicated expression you might obtain multiple sets of values for the parameters, and you may have to refine the results to pick those in which all cc[] parameters are rational.

SolveAlways is actually just a "shortcut" for the following Solve expression (see the "Details and Options" section of its documentation):

SolveAlways[expr == 0, vars]
(* is equivalent to *)
Solve[!Eliminate[!expr == 0, vars], Array[cc, 3]]


so you could use the version written with Solve and explicitly request that solutions be rational by specifying a domain:

Solve[!Eliminate[!expr == 0, vars], Array[cc, 3], Rationals]

• Why can't all Answers be this simple? Thanks! Jun 15, 2015 at 3:26
• @JerryGuern glad it helped, and thank you for the accept! Jun 15, 2015 at 3:31
• I have never seen exclamation points used the way you've used them in the code you added. Is "!expr==0" the same a "expr!=0"? What do the two !'s in that code do? Very intriguing. Jun 15, 2015 at 6:46