How to Solve Modular Equations in Mathematica?

In summary: In the equation 11x=1 (mod 360), the number x is the result of multiplying 11 and 360 together. To get x, we have to find the modular inverse of 11, which is 131.If Mathematica doesn't have a modular inverse function, the extended Euclidean algorithm can be used. This algorithm works by solving for u and v such that 11u + 360v = 1. Once u is found, v can be seen to be the inverse of 11 mod 360.If Mathematica doesn't have the extended Euclidean algorithm, another solution is to write a function that implements the algorithm.
  • #1
heartless
220
2
Hello,
I'm not very experienced with mathematica, and I have some problems in making an equation like this,
Find x such that 11x = 1 (mod 360) and x < 360.
Any ideas on how to input this into mathematica?
Thanks,
 
Physics news on Phys.org
  • #2
or at least tell me how to find x?
 
  • #3
actually x equals 131. It took me quite a few minutes to brute force it though (trial and error). I'm working out a formula now.
 
  • #4
AFAIK, you have to do the solving yourself. :frown: But at least you can still get Mathematica to do the computation...

The whole problem boils down to finding the modular inverse of 11, modulo 360. That is, the number a such that 11a = 1 (mod 360).

Mathematica might have a modular inverse function.

If not, the normal way to compute modular inverses is through the extended Euclidean algorithm for GCD's... Mathematica ought to have that!

This algorithm gives you the numbers u and v such that 11u + 360v = 1, so u is easily seen to be the inverse of 11 modulo 360. (Of course, this only works because GCD(11, 360) = 1)

If Mathematica doesn't have that, I think the easiest solution is to write a function that implements the extended Eucllidean algorithm. :smile:

But if you really don't want to, you could still manage something with modular exponentiation, since:

11^EulerPhi[360] = 1 (mod 360)

so you can spend a little bit of time figuring out the possibilities for things which 11a = 1 (mod 360).

(the Carmichael lambda function is better to use than the EulerPhi function, but I don't know if Mathematica has that)
 
  • #5
There is a neat way to do this relying on the Chinese Remainder Theorem. We look at M, the total product and we divided by each Mi , the result we call individually Mi*. We must have all the M*s relatively prime to each other. So, while that may not be clear, we have 5x8x9=360, and the three factors 5,8,9 are relatively prime.

Then we solve X/Mi Modulo, 5, 8, and 9, giving us a series of Qi.

We have the equation X = Sum of Mi*(Qi). This gives the answer, which we reduce to lowest terms.

This requires good nomenclature to put it down right. But the proof is rather simple, since we have Mi*(Qi)==X Modulo Mi.

For instance in the case of 8x9(X/8x9 Mod 5) gives 8x9(11/72 Mod 5)=72(1/2 Mod 5)=72x3=216.

If you want to use a computer program, Pari has no problem with such things. Just use the Mod function: Mod(1/11,360) =Mod(131,360) in an augenblick!

In fact, it has no trouble with 13X==1 Mod 11!, Mod(1/13,11!)= Mod(36846277, 39916800)
 
Last edited:
  • #6
im sorry for my ignorance, but i havnt learned anything in Number Theory yet.

here goes...

What exactly is mod?
 
  • #7
You can have a look at this page: Modulo to get some ideas about what modulo is.
We write:
[tex]a \equiv b (\mbox{mod } c)[/tex], that means when divided by c, a and b have the same remainder. :)
 

FAQ: How to Solve Modular Equations in Mathematica?

What is modular arithmetic?

Modular arithmetic is a branch of mathematics that deals with operations on integers, where the numbers "wrap around" upon reaching a certain value. This value is known as the modulus. It is often used when dealing with cyclic phenomena, such as time or repeating patterns.

How is modular arithmetic used in Mathematica?

Mathematica has built-in functions for performing modular arithmetic operations, such as Mod, ModInverse, and PowerMod. These functions allow users to easily manipulate numbers in a modular fashion, making it a useful tool for solving various mathematical problems.

What are some applications of modular arithmetic in real life?

Modular arithmetic has many practical applications in fields such as computer science, cryptography, and physics. It is used in computer algorithms, data encryption, and even in the design of musical scales. It also has applications in various engineering and scientific calculations.

Can modular arithmetic be used with non-integer numbers?

No, modular arithmetic is only defined for integer numbers. However, Mathematica has functions like FractionalPart and IntegerPart that can be used to work with non-integer numbers in a modular fashion.

How does Mathematica handle negative numbers in modular arithmetic?

Mathematica follows the convention of most mathematical systems and uses the remainder when dividing by the modulus to handle negative numbers. For example, -5 mod 7 is equivalent to 2, since -5 is 2 units away from the nearest multiple of 7 in the negative direction.

Similar threads

Replies
9
Views
739
Replies
5
Views
2K
Replies
2
Views
475
Replies
1
Views
2K
Replies
1
Views
2K
Replies
4
Views
657
Back
Top