Results 1 to 6 of 6
Like Tree2Thanks
  • 1 Post By SlipEternal
  • 1 Post By SlipEternal

Math Help - Modular arithmetic in Mathematica

  1. #1
    Forum Admin topsquark's Avatar
    Joined
    Jan 2006
    From
    Wellsville, NY
    Posts
    9,668
    Thanks
    298
    Awards
    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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Nov 2010
    Posts
    1,395
    Thanks
    517

    Re: Modular arithmetic in Mathematica

    Did you try:

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

    ?
    Thanks from topsquark
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Forum Admin topsquark's Avatar
    Joined
    Jan 2006
    From
    Wellsville, NY
    Posts
    9,668
    Thanks
    298
    Awards
    1

    Re: Modular arithmetic in Mathematica

    Quote Originally Posted by SlipEternal View Post
    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
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Nov 2010
    Posts
    1,395
    Thanks
    517

    Re: Modular arithmetic in Mathematica

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

    Solve[4x == 1 && Modulus == 5,x]
    Follow Math Help Forum on Facebook and Google+

  5. #5
    MHF Contributor
    Joined
    Nov 2010
    Posts
    1,395
    Thanks
    517

    Re: Modular arithmetic in Mathematica

    Quote Originally Posted by SlipEternal View Post
    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]
    Thanks from topsquark
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Forum Admin topsquark's Avatar
    Joined
    Jan 2006
    From
    Wellsville, NY
    Posts
    9,668
    Thanks
    298
    Awards
    1

    Re: Modular arithmetic in Mathematica

    Quote Originally Posted by SlipEternal View Post
    Strike that. This does work in Mathematica 9
    Reduce[4x == 1,x,Modulus -> 5]
    Voila! You are my hero for the day!

    -Dan
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Help with modular arithmetic
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: July 12th 2012, 08:41 PM
  2. modular arithmetic
    Posted in the Number Theory Forum
    Replies: 6
    Last Post: October 8th 2011, 10:45 AM
  3. Modular Arithmetic
    Posted in the Number Theory Forum
    Replies: 6
    Last Post: December 12th 2010, 08:53 PM
  4. Modular Arithmetic
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: April 28th 2010, 03:54 AM
  5. modular arithmetic
    Posted in the Number Theory Forum
    Replies: 3
    Last Post: March 2nd 2009, 12:17 PM

Search Tags


/mathhelpforum @mathhelpforum