1
$\begingroup$

need to resolve this Diophantine equation, but with the condition that a, b, c belong to the set of odd numbers from 1-51, as I write this condition in the code

Reduce[a + b + c == 91 && 0 <= a <= 51 && 0 <= b <= 51 && 
0 <= c <= 51, {a, b, c}, Integers] /. Or -> List /. And -> List

Edit : sorry, I wrote wrong number ( 92 ),is 91 ,a, b, and c must be odd,the range 1-51

$\endgroup$
3
  • $\begingroup$ Can't you rewrite a=2 aa + 1 and so on ? $\endgroup$ Apr 11, 2015 at 14:14
  • $\begingroup$ I'm voting to close this question as off-topic because Three odd numbers can't add up 92 $\endgroup$ Apr 11, 2015 at 15:58
  • $\begingroup$ One standard approach is to replace e.g. a by 2*a+1. $\endgroup$ Apr 11, 2015 at 20:34

4 Answers 4

7
$\begingroup$

For the given problem it will be far more efficient to use IntegerPartitions:

IntegerPartitions[91, {3}, Range[1, 51, 2]]
{{51, 39, 1}, {51, 37, 3}, {51, 35, 5}, {51, 33, 7}, . . .}

If you only need one solution:

IntegerPartitions[91, {3}, Range[1, 51, 2], 1]
{{51, 39, 1}}
$\endgroup$
1
  • $\begingroup$ Sure - you´re right... Sometimes one does not see the obvious :-) $\endgroup$
    – mgamer
    Apr 11, 2015 at 16:42
0
$\begingroup$

So the range is not to large you can make a "brute-force" attack ;-)

data = Tuples[Range[0,51], 3];

and

Select[data, Plus @@ # == 92 &] 

you´ll get 1788 solutions. This is regarding to the complete Range (0..51). The sum of three odd numbers is odd, so never equal to 92.

For the edited questions solution is possible in the same way and delivers 465 solutions (84 different). But it is more efficient to use IntegerPartitions - see the answer of Mr. Wizard.

$\endgroup$
0
$\begingroup$

Not efficient, just showing that Mathemtica can do it from "first principles"

Reduce[a + b + c == 91 && And @@ Thread[0 <= {a, b, c} <= 51] && 
       Exists[Element[{aa, bb, cc}, Integers],  2 aa + 1 == a && 
                                                2 bb + 1 == b && 
                                                2 cc + 1 == c], 
       {a, b, c}, Integers]

(* (aa == 0 && bb == 19 && cc == 25 && a == 1 && b == 39 && c == 51) || ...*)
$\endgroup$
0
$\begingroup$

Here are a two more ways.

A linear diophantine equation with constraints or not is easily solved using generating functions which only require polynomial multiplication.

Coefficient[Sum[x^k, {k, 1, 51, 2}]^3, x^91]

(*465*)

To check:

FindInstance[a + b + c == 91 && 1 <= a <= 51 && 1 <= b <= 51 && 1 <= c <= 51 && 
Mod[a, 2] == Mod[b, 2] == Mod[c, 2] == 1, {a, b, c}, Integers, 2000] // Length

(*465*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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