# Modular arithmetic in Mathematica

Printable View

• Oct 31st 2013, 11:27 AM
topsquark
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
• Oct 31st 2013, 12:17 PM
SlipEternal
Re: Modular arithmetic in Mathematica
Did you try:

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

?
• Oct 31st 2013, 04:21 PM
topsquark
Re: Modular arithmetic in Mathematica
Quote:

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
• Oct 31st 2013, 04:28 PM
SlipEternal
Re: Modular arithmetic in Mathematica
Ok, I checked a bit, and this might work:

Solve[4x == 1 && Modulus == 5,x]
• Oct 31st 2013, 04:36 PM
SlipEternal
Re: Modular arithmetic in Mathematica
Quote:

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]
• Oct 31st 2013, 04:48 PM
topsquark
Re: Modular arithmetic in Mathematica
Quote:

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