# 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

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 + 6 Sqrt + 7 Sqrt, 4]


3 + Sqrt + 2 Sqrt + 3 Sqrt

surdMod[17 + 21 Sqrt + 18 Sqrt + 7 Sqrt, 13]


4 + 8 Sqrt + 5 Sqrt + 7 Sqrt

surdMod[Sqrt, 3]


Sqrt

• 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