# Is there a function or a way of getting a remainder or modulus with equations with “surds”?

So I'm working with "surds", or radicals. I have expressions like

$$7 + 5\sqrt{2} + 6\sqrt{3} + 7\sqrt{6}\tag{1}$$

and I want to take the "coefficients", for lack of a better word, and take their remainder when divided by $$p$$.

For example, if $$p=4$$, Equation (1) becomes:

$$3 + \sqrt{2} + 2\sqrt{3} + 3\sqrt{6}$$

...again, by taking each number in front and finding the remainder when dividing by $$4$$.

Also, could someone tell me what this is in mathematical terms?

• I'm essentially looking for a function that takes something like SurdMod[$17+21\sqrt{3}+18\sqrt{5}+7\sqrt{15}$,$13$] and returns $4+8\sqrt{3}+5\sqrt{5}+7\sqrt{15}$ – Matt Groff Nov 7 '19 at 22:13

## 1 Answer

surdMod[expr_, n_]:=expr /. {x_Integer y_Power -> Mod[x, n] y, x_Power :> x,
x_Integer :> Mod[x, n]}


Testing:

surdMod[7 + 5 Sqrt[2] + 6 Sqrt[3] + 7 Sqrt[6], 4]


3 + Sqrt[2] + 2 Sqrt[3] + 3 Sqrt[6]

surdMod[17 + 21 Sqrt[3] + 18 Sqrt[5] + 7 Sqrt[15], 13]


4 + 8 Sqrt[3] + 5 Sqrt[5] + 7 Sqrt[15]

surdMod[Sqrt[14], 3]


Sqrt[14]

• I'm not sure why, but your function sometimes takes the modulus of the surds. For instance, I had a function with $\sqrt{14}$, and it returned a $\sqrt{3}$ instead. – Matt Groff Nov 8 '19 at 5:52
• Oh, I see. Repaired, tested, should be working. – Alx Nov 8 '19 at 7:10