# Solutions of a modular equation

I have a modular equation like this:

In[]:= Reduce[(1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2, {x, y}, Modulus -> 3^2]

Out[]= x == 1 + 3 C[1] && y == C[2]


and I want to transform this parametric solution so that I have all the couples {x,y} that satisfy the equation. I tried:

In[]:= Reduce[(1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2, {x, y}, Modulus -> 3^2, GeneratedParameters -> Slot]

Out[]= x == 1 + 3 #1 && y == #2


but while it seems nearly correct, I failed to transform it into a pure function to process the tuples:

{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8},
{2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8},
{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8},
{4, 0}, {4, 1}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {4, 6}, {4, 7}, {4, 8},
{5, 0}, {5, 1}, {5, 2}, {5, 3}, {5, 4}, {5, 5}, {5, 6}, {5, 7}, {5, 8},
{6, 0}, {6, 1}, {6, 2}, {6, 3}, {6, 4}, {6, 5}, {6, 6}, {6, 7}, {6, 8},
{7, 0}, {7, 1}, {7, 2}, {7, 3}, {7, 4}, {7, 5}, {7, 6}, {7, 7}, {7, 8},
{8, 0}, {8, 1}, {8, 2}, {8, 3}, {8, 4}, {8, 5}, {8, 6}, {8, 7}, {8, 8}}


Any suggestion?

• Is this the desired result from processing the tuples: Function[, Evaluate@red] @@@ Tuples[Range[0, 8], 2]? ( where red = Reduce[...])
– kglr
Jun 13, 2023 at 17:34
• Correct. I never mind to use Evaluate.... Jun 13, 2023 at 18:44

red1 = Reduce[(1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2, {x, y},
Modulus -> 3^2, GeneratedParameters -> Slot]

 x == 1 + 3 #1 && y == #2


"to transform it into a pure function to process the tuples":

function = Function[, Evaluate @ red1];

tuples = Tuples[Range[0, 8], 2];

result1 = MapApply[function] @ tuples;


red0 = Reduce[(1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2, {x, y},
Modulus -> 3^2]

 x == 1 + 3 C[1] && y == C[2]

result0 = ReplaceAll[Map[Thread[{C[1], C[2]} -> #] &] @ tuples] @ red0;

result0 == result1

True

Clear["Global*"]

eqn = (1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2;

sol = Solve[(1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2, {x, y},
Modulus -> 3^2][[1]]

(* {x -> 1 + 3 C[1], y -> C[2]} *)

And @@ ((((Mod[#, 3^2] & /@ eqn) /. sol) /.
Thread[{C[1], C[2]} -> #]) & /@ Tuples[Range[0, 8], {2}])

(* True *)


Just another way:

r = Reduce[(1 + 3 x)^2 + (1 + 3 x)^4 + (1 + 3 x)^8 == 9 y^2, {x, y},
Modulus -> 3^2];
g[x_, y_] := (r /. {Equal[a_, b_] :> b, And :> List}) /. {C[1] -> x,
C[2] -> y}
g @@@ Tuples[Range[0, 8], 2]
`

yields:

{{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1,
8}, {4, 0}, {4, 1}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {4, 6}, {4, 7}, {4, 8}, {7, 0}, {7, 1}, {7, 2}, {7, 3}, {7, 4}, {7, 5}, {7, 6}, {7, 7}, {7, 8}, {10, 0}, {10, 1}, {10, 2}, {10, 3}, {10, 4}, {10, 5}, {10, 6}, {10, 7}, {10, 8}, {13, 0}, {13, 1}, {13, 2}, {13, 3}, {13, 4}, {13, 5}, {13, 6}, {13, 7}, {13, 8}, {16, 0}, {16, 1}, {16, 2}, {16, 3}, {16, 4}, {16, 5}, {16, 6}, {16, 7}, {16, 8}, {19, 0}, {19, 1}, {19, 2}, {19, 3}, {19, 4}, {19, 5}, {19, 6}, {19, 7}, {19, 8}, {22, 0}, {22, 1}, {22, 2}, {22, 3}, {22, 4}, {22, 5}, {22, 6}, {22, 7}, {22, 8}, {25, 0}, {25, 1}, {25, 2}, {25, 3}, {25, 4}, {25, 5}, {25, 6}, {25, 7}, {25, 8}}