# Thread: Modular arithmetic in Mathematica

1. ## Modular arithmetic in Mathematica

Does anyone know how to code Mathematica to solve modular problems? For example, say I want to solve 4x == 1 mod 5. My best guess was Mod[Solve[4x == 1, x], 5] but that only resulted in the response Mod[1/4, 5].

Thanks!
-Dan

2. ## Re: Modular arithmetic in Mathematica

Did you try:

Solve[Mod[4x,5] == 1,x]

?

3. ## Re: Modular arithmetic in Mathematica Originally Posted by SlipEternal Did you try:

Solve[Mod[4x,5] == 1,x]

?
No good. I get back {{x -> 1/4 InverseFunction[Mod, 1, 2][1, 5]}}, which leads me to believe that it doesn't understand the Mod[ ] in this context. I don't know. WolframAlpha will solve simple ones but even that site doesn't tell me how the problem needs to be coded. Ach!

-Dan

4. ## Re: Modular arithmetic in Mathematica

Ok, I checked a bit, and this might work:

Solve[4x == 1 && Modulus == 5,x]

5. ## Re: Modular arithmetic in Mathematica Originally Posted by SlipEternal Ok, I checked a bit, and this might work:

Solve[4x == 1 && Modulus == 5,x]
Strike that. This does work in Mathematica 9

Reduce[4x == 1,x,Modulus -> 5]

6. ## Re: Modular arithmetic in Mathematica Originally Posted by SlipEternal Strike that. This does work in Mathematica 9
Reduce[4x == 1,x,Modulus -> 5]
Voila! You are my hero for the day!

-Dan

#### Search Tags

arithmetic, mathematica, modular 