1

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

zeros
  • 2,263
  • 1
  • 14
  • 18

4 Answers4

7

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}}
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
0

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*)
bobbym
  • 2,628
  • 2
  • 15
  • 20
0

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.

mgamer
  • 5,593
  • 18
  • 26
0

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) || ...*)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453