Download The computational-Type Problems 1 Solving Linear Diophantine

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

BKL singularity wikipedia , lookup

Fermat's Last Theorem wikipedia , lookup

Schrödinger equation wikipedia , lookup

Equations of motion wikipedia , lookup

Two-body problem in general relativity wikipedia , lookup

Debye–Hückel equation wikipedia , lookup

Van der Waals equation wikipedia , lookup

Perturbation theory wikipedia , lookup

Derivation of the Navier–Stokes equations wikipedia , lookup

Computational electromagnetics wikipedia , lookup

Equation of state wikipedia , lookup

Itô diffusion wikipedia , lookup

Calculus of variations wikipedia , lookup

Differential equation wikipedia , lookup

Schwarzschild geodesics wikipedia , lookup

Exact solutions in general relativity wikipedia , lookup

Partial differential equation wikipedia , lookup

Transcript
The computational-Type Problems
Dr. Min Ru, University of Houston
These are concrete problems with numerical answers that test your knowledge
of basic techniques and algorithms, such as congruence arithmetic, the Euclidean
algorithm, or the Chinese Remainder Theorem algorithm. The following contains the
types of problems (may be not complete).
1
Solving Linear Diophantine Equations ax+by = c
(Note: this may be the most important one, since other types of problems will eventually be reduced to solving the Linear Diophantine Equations)
The method is based on the following theorem
Theorem(structure of solutions): If (x̃0 , ỹ0 ) is an integer solution to the linear
Diophantine equation ax + by = c. Then any other (integer) solutions (x, y) has the
form x = x̃0 + m(b/d), y = ỹ0 − m(a/d), where d =gcd(a, b), m is any integer.
So it gets down to to find ONE solution (i.e, (x̃0 , ỹ0 ), by using whatever the
method.
Here are some proposed methods:
Method I: By guessing or inspection. This method may be the most naive and
simplest. It usually saves you A LOT of time. For example, to solve 3x − 2y = 1,
you immediately (by guessing or inspection) realize that x=1, y=1 is an integer
solution, so by the Theorem(structure of solutions) above, we get ALL solutions
x = 1 − 2m, y = 1 − 3m m is any integer. Even in some ”seems more complicated”
equation like 7x + 9y = 5, you can see that x = 2, y = −1. If you go back to look at
the equations you have solved (either in hws or in practice), you may find that may
be more than half of them can be solve by guessing or inspection). This really saves
you time!!!
Method II: Use using the reverse Euclidean Algorithm. Note that, while the Euclidean
Algorithm allows you to find gcd(a, b) (as I explained in my notes), the reverse Euclidean Algorithm allows you find x, y such that ax + by =gcd(a, b), i.e. allows you
to a particular solution (x0 , y0 ) to the equation ax + by = d where d =gcd(a, b). It is
VERY important to note that it only gives you a solution to the equation ax+by = d,
NOT the equation ax + by = c. To get a solution to the equation ax + by = c, you
1
need to let k = (c/d) and multiply k to x0 and y0 to get a solution, i.e. (kx0 , ky0 ) is
a solution to the equation ax + by = c. This is the part where most students made
the mistake. DO’NT FORGET TO MULTIPLY k.
Example: Solve 154x + 91y = 42.
Solution: As we have discussed above, we (only) need to find a particular solution
(x̃0 , ỹ0 ) to the equation 154x + 91y = 42. We use Method II. We do the Euclidean
Algorithm: 154 = 91 + 63, 91 = 6391 = 63 + 28, 63 = 2 · 28 + 7, 28 = 4 · 7. Hence
gcd(154, 91) = 7. We then do the reverse:
7 = 63 − 2 · 28 = 63 − 2 · (91 − 63) = (154 − 91) − 2 · (91 − (154 − 91)) = 3 · 154 − 5 · 91.
Hence x0 = 3, y0 = −5 is a solution to the equation 154x+91y = 7 ( Note this is NOT
our equation yet!). Let k = 42/7 = 6 and multiply it to x0 , y0 , we get x̃0 = 18, ỹ0 =
−30. Hence (18, −30) is a particular solution to the equation 154x + 91y = 42. From
the Theorem(structure of solutions) above, we have the general solutions (i.e. ALL
solutions) x = 18 + 13m, y = −30 − 22m, where m is any integer, to the equation
154x + 91y = 42.
2
Solving Linear Congruence Equation ax ≡ b (mod
n)
Assuming gcd(a, n)|b (otherwise there’ll be no solutions). From the theorem that The
linear congruence ax ≡ b (mod n) with gcd(a, n)|b has exactly d =gcd(a, n) solutions
modulo n. So PLEASE DO NOT LOSS any solutions (you need to find ALL!).
If gcd(a, n) = 1. Then the naive way is to ”divide a” on both sides of ax ≡ b (mod n)
(by the ”cancellation law” in chapter 3 (see ” Modular arithmetic” section)), i.e find
the ”Multiplicative Inverse of a” and multiply it to the both sides. This provides a
way to solve ax ≡ b (mod n) when gcd(a, n) = 1. This method seems most natural
and naive. For example, to solve 3x ≡ 4 (mod 5), first we find multiplicative inverse of
3 modulo 5 (we denote it by 3−1 ), in this case is 2 (see notes on chapter 5 ”How to find
a multiplicative inverse!). So we multiply 2 to both sides (using the ”multiplication
law” (see ” Modular arithmetic” section in chapter 3)) to get x ≡ 2 · 4 = 8 ≡ 3 (mod
5).
Note that ax ≡ b (mod n) can always be reduced to the case above i.e. gcd(a, n) =
1. Indeed, let gcd(a, n) = d, by dividing d on both sides (including the modulo), we
get, by letting a = dã, b = db̃, m = dm̃, ãx ≡ b̃ (mod m̃), and now gcd(ã, m̃)=1. For
2
example, to solve 6x ≡ 8 (mod 10), notice that gcd(6, 10) = 2, then by dividing 2
on both sides, we get 3x ≡ 4 (mod 5). In other words, to solve 6x ≡ 8 (mod 10),
we can instead to solve 3x ≡ 4 (mod 5). Note that now gcd(3, 5)=1, so we can
used the above ”naive” method above. Note that the solution you obtained is indeed
textcolorredmod 5, i.e. the solution is x ≡ 3 (mod 5). This is fine. Of course, if
you want to write the solution in textcolorredmod 10 (because your original equation
is (mod 10)), you can also do it: From the theorem that The linear congruence
ax ≡ b (mod n) with gcd(a, n)|b has exactly d =gcd(a, n) solutions modulo n, so the
equation 6x ≡ 8 (mod 10) has textcolorredexactly T W O solutions modulo 10. Form
the solution x ≡ 3 (mod 5) you obtained, i.e. x = 3 + 5m where m is any integer.
You take m = 0 to get x = 3, and take m = 1 to get x = 8. So the general solution
to the equation 6x ≡ 8 (mod 10) are: x ≡ 3 (mod 10) and x ≡ 8 (mod 10).
The second method of solving ax ≡ b (mod n) is to reduce it to solve the
linear Diophantine equation ax + ny = b. See section 1 on how to solve linear
Diophantine equations. For example, to solve 35x ≡ 14 (mod 84), we solve, instead,
the linear Diophantine equation 35x + 84y = 14 to get x = −2 + m × 12, where m
is any integer (you can ignore y). Note that, from the theorem above, we’ll need 7
solutions since gcd(35, 84)=7. So m = 1, . . . , 6, 7 we get general solutions to 35x ≡ 14
(mod 84) are: x ≡ 10 (mod 84), x ≡ 22 (mod 84), x ≡ 34 (mod 84), x ≡ 46 (mod
84), x ≡ 58 (mod 84), x ≡ 70 (mod 84), x ≡ 82 (mod 84).
Warning: DO NOT LOSS any solutions!!!.
3
Solving A SYSTEM of Linear Congruence Equations x ≡ a1 (mod m1) and x ≡ a2 (mod m2)
The solution is based on the following theorem: The pair of congruences x ≡ a1 (mod
m1 ) and x ≡ a2 has solution if and only if a1 ≡ a2 (mod gcd(m1 , m2 )). In the cases
where a solution x0 exists, all solutions are of the form x = x0 +nlcm(m1 , m2 ) for some
n (in other words, the solution is unique modulo lcm(m1 , m2 )), where lcm(m1 , m2 ) is
the least common multiple.
Assuming a1 ≡ a2 (mod gcd(m1 , m2 )). The most naive way or idea is to multiply
some numbers to the first AND second equation (in modulus as well) to get a common
modulo. To do so, write lcm(m1 , m2 ) = m1 d1 , lcm(m1 , m2 ) = m2 d2 , and then multiply d1 to the first equation x ≡ a1 (mod m1 ) to get d1 x ≡ a1 d1 (mod lcm(m1 , m2 ))
and multiply d2 to the first equation x ≡ a2 (mod m2 ) to get d2 x ≡ a2 d2 (mod
lcm(m1 , m2 )). Thus we get the common modulo which is lcm(m1 , m2 ). We then
3
subtract the second new equation from the first new equation to get
(d1 − d2 )x ≡ (a1 d1 − a2 d2 ) mod (lcm(m1 , m2 ).
Then it is reduced to the case of solving (single) congruence equation whose method
has been discussed in section 2. For example, to solve x ≡ 59 (mod 60), x ≡ 35 (mod
42). Note that lcm(60, 42)=420, so we need to multiply 7 to the first equation x ≡ 59
(mod 60) and multiply 10 to on the second equation x ≡ 35 (mod 42). Hence we
get 7x ≡ 413 (mod 420) and 10x ≡ 350 (mod 420) (note the purpose of doing so is
to get a common modulo). We then subtract the first new equation from the second
new equation to get 3x ≡ −63 ≡ 357 (mod 420). By using the method discussed in
section 2, we solve 3x ≡ 357 (mod 420) to get our solution x ≡ 119 (mod 420) and
x ≡ 259 (mod 420) (warning: since gcd(3, 420)=2, you NEED TWO solutions. DO
NOT LOSS ANY SOLUTIONS!).
Other methods in solving the SYSTEM of Linear Congruence Equations x ≡ a1
(mod m1 ) and x ≡ a2 (mod m2 ) include reducing it to solving linear Diophantine
equation and By using the explicit formula(warning: if you want to use the explicit
formula, you need to MAKE SURE that gcd(m1 , m2 ) = 1).
4
Other cases
SEE MY PREVIOUS NOTES.
4