Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb59072

Browse files
committed
Chakaralava example and azimpremjifoundation ref
1 parentb5517a0 commitdb59072

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

‎src/others/pells_equation.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ $x^{2} - d \cdot y^{2} = ( x + \sqrt{d} \cdot y ) ( x - \sqrt{d} \cdot y ) = 1$
2020

2121
The first part $( x + \sqrt{d} \cdot y )$ is always greater than 1. And the second part $( x - \sqrt{d} \cdot y )$ is always less than 1.
2222

23-
We will prove that all solutions to Pell's equation are given by powers of the smallest positive solution. Let's assume it to be $ x_{0} + y_{0} \cdot \sqrt{d}$.
23+
We will prove that all solutions to Pell's equation are given by powers of the smallest positive solution. Let's assume it to be
24+
$ x_{0} + y_{0} \cdot \sqrt{d} $
2425

25-
[//]:#(We claim that every solution to the equation is given by $(x_{0} + y_{0} \cdot \sqrt{d})^{n}$ for some integer $n$. The idea is that any other solution)
26-
[//]:#( $( x + \sqrt{d} \cdot y)$ must be of this form, meaning that all solutions are generated by repeated multiplication of the smallest solution. Here we use Brahmagupta's identity of quadratic decomposition.)
27-
[//]:#( $(a^{2} - n \cdot b^{2}) \cdot(c^{2} - n \cdot d^{2}) =(a \cdot c + n \cdot b \cdot d)^{2} - n \cdot(a \cdot d + b \cdot c)^{2}$)
26+
[//]:#(We claim that every solution to the equation is given by $(x_{0} + y_{0} \cdot \sqrt{d})^{n}$ for some integer $ n$. The idea is that any other solution)
27+
[//]:#($( x + \sqrt{d} \cdot y)$ must be of this form, meaning that all solutions are generated by repeated multiplication of the smallest solution. Here we use Brahmagupta's identity of quadratic decomposition.)
28+
[//]:#( $(a^{2} - n \cdot b^{2}) \cdot(c^{2} - n \cdot d^{2}) =(a \cdot c + n \cdot b \cdot d)^{2} - n \cdot(a \cdot d + b \cdot c)^{2}$)
2829
[//]:#()
2930
[//]:#(Here, $a = x_{1}$, $b = y_{1}$, $c = x_{2}$, $d = y_{2}$)
3031
[//]:#( So if(x_{1}, y_{1}) and(x_{2}, y_{2}) are solutions, then $(x_{1} \cdot x_{2} + n \cdot y_{1} \cdot y_{2}, x_{1} \cdot y_{2} + y_{1} \cdot x_{2})$ is also a solution.)
3132
[//]:#(First, we prove that product of two solutions is also a solution.)
3233

33-
We use method of descent to prove it. suppose there is a solution $u + v \cdot \sqrt{d}$ such that $u^{2} - d \cdot v^{2} = 1$
34-
Therefore, $ ( x_{0} + \sqrt{d} \cdot y_{0} )^{n} < u + v \cdot \sqrt{d} < ( x_{0} + \sqrt{d} \cdot y_{0} )^{n+1}$
34+
We use method of descent to prove it. suppose there is a solution $u + v \cdot \sqrt{d}$ such that $u^{2} - d \cdot v^{2} = 1$
35+
Therefore, $ ( x_{0} + \sqrt{d} \cdot y_{0} )^{n} < u + v \cdot \sqrt{d} < ( x_{0} + \sqrt{d} \cdot y_{0} )^{n+1}$
3536

3637
Multiplying the above inequality by $( x_{0} - \sqrt{d} \cdot y_{0} )^{n}$,(which is > 0 and < 1) we get
3738

@@ -75,19 +76,35 @@ $$\sf=2+\cfrac{1}{1+\cfrac1{1+\cfrac1{1+\cfrac4{\vdots}}}}$$
7576

7677
we get the continued fraction of $\sf$ as $[2; 1, 1, 4, 1, 1, 4, \ldots]$.
7778

79+
It can also be calculated using only[integer based calculation](https://cp-algorithms.com/algebra/continued-fractions.html)
80+
7881
###Finding the solution using Chakravala method
79-
The Chakravala method is an ancient Indian algorithm to solve Pell's equation. It is based on the Brahmagupta's identity of quadratic decomposition.
82+
The Chakravala method is an ancient Indian algorithm to solve Pell's equation. It is based on the Brahmagupta's identity of quadratic decomposition
8083
$(x_{1}^{2} - n \cdot y_{1}^{2}) \cdot (x_{2}^{2} - n \cdot y_{2}^{2}) = (x_{1} \cdot x_{2} + n \cdot y_{1} \cdot y_{2})^{2} - n \cdot (x_{1} \cdot y_{2} + x_{2} \cdot y_{1})^{2}$
8184
$(x_{1}^{2} - n \cdot y_{1}^{2}) \cdot (x_{2}^{2} - n \cdot y_{2}^{2}) = (x_{1} \cdot x_{2} - n \cdot y_{1} \cdot y_{2})^{2} - n \cdot (x_{1} \cdot y_{2} - x_{2} \cdot y_{1})^{2}$
8285

86+
And Bhaskara's Lemma:
87+
If $x^{2} - n \cdot y^{2} = k$, then $ ( \frac{ m \cdot x + n \cdot y }{k})^{2} - n \cdot ( \frac{ x + m \cdot y }{k})^{2} = \frac{m^2 - n}{k}$
88+
8389
Using above Brahmagupta's identity, If $(x_{1}, y_{1}, k_{1})$ and $(x_{2}, y_{2}, k_{2})$ satisfy $(x_{1}^{2} - y_1^{2}) \cdot (x_{2}^{2} - y_2^{2}) = k_{1} \cdot k_{2} $, then $(x_{1} \cdot x_{2} + n \cdot y_{1} \cdot y_{2}, x_{1} \cdot y_{2} + y_{1} \cdot x_{2}, k_{1} \cdot k_{2})$ is also a solution of $(x_{1} \cdot x_{2} + n \cdot y_{1} \cdot y_{2})^{2} - n \cdot (x_{1} \cdot y_{2} + x_{2} \cdot y_{1})^{2} = k_{1} \cdot k_{2}$
8490

85-
[//]:#(First, we choose $y_{1} = 1$ and choose $x_{1} = \lfloor \sqrt n \rfloor$ such that $k_{1}$ is a small integer.)
91+
####Steps
92+
1. Initialization:Choose an initial solution $(p_{0}, q_{0}, m_{0})$ where $p_{0}$ and $q_{0}$ are co-prime such that $p_{0}^{2} - N \cdot q_{0}^{2} = m_{0}$. Typically, start with $p_{0} = \lfloor \sqrt N \rfloor $, $q_{0} = 1$, $m_{0} = p_0^2 - N $.
93+
2. Key step: Find $x_{1}$ such that: $q_{0} \cdot x_{1} \equiv -p_{0} \pmod {\lvert m_{0}\rvert}$ and $\lvert x_{1}^2 - N \rvert$ is minimized.
94+
Update the triple $(p_{1}, q_{1}, m_{1}) = ( \frac{x_{1} \cdot p_{0} + N \cdot q_{0}}{\lvert m_{0} \rvert}, \frac{p_{0} + x_{1} \cdot q_{0}}{\lvert m_{0} \rvert}, \frac{x_1^{2} - N}{m_{0}})$.
95+
3. Termination: When $m_{k}=1$, the values of $p_{k}$ and $q_{k}$ are the smallest positive solution of the Pell's equation.
96+
97+
#####Example
98+
Let's solve the equation $x^{2} - 13 \cdot y^{2} = 1$ using Chakravala method.
99+
1. Start with $(p_{0}, q_{0}, m_{0}) = (3, 1, -4)$ because $3^2 - 13 \cdot1^2 = -4$.
86100

87-
[//]:#()
88-
[//]:#(Then, Iteratively we adjust $x_{1}$ and $y_{1}$ so that $k_{1} = 1$. The solution is given by $&#40;x_{1}, y_{1}&#41;$ to original Pell's equation.)
89-
[//]:#()
90-
[//]:#( Choosing m. At e)
101+
2. Find $x_{1}$ such that $x_{1} \equiv -3 \pmod {4}$ and $\lvert x_{1}^2 - 13 \rvert$ is minimized.
102+
We get $x_{1} = 1$. Update the triple $(p_{1}, q_{1}, m_{1}) = ( \frac{1 \cdot 3 + 13 \cdot 1}{4}, \frac{3 + 1 \cdot 1}{4}, \frac{1^{2} - 13}{-4}) = (4, 1, 3)$.
103+
3. Substituting $(p_{1}, q_{1}, k_{1}) = (4, 1, 3)$ in key step, we get $x_{2} \equiv -4 \pmod 3$ and minimize $\lvert x_{2}^2 - 13 \rvert$ i.e, $x_{2} = 2$. Update the triple $(p_{2}, q_{2}, m_{2}) = ( \frac{2 \cdot 4 + 13 \cdot 1}{3}, \frac{4 + 2 \cdot 1}{3}, \frac{2^{2} - 13}{-3}) = (7, 2, -3)$.
104+
4. Substituting $(p_{2}, q_{2}, m_{2}) = (7, 2, -3)$ in key step, we get $2 \cdot x_{3} \equiv -7 \pmod 3$ and minimize $\lvert x_{3}^2 - 13 \rvert$ i.e, $x_{3} = 4$. Update the triple $(p_{3}, q_{3}, m_{3}) = ( \frac{4 \cdot 7 + 13 \cdot 2}{3}, \frac{7 + 4 \cdot 2}{3}, \frac{4^{2} - 13}{-3}) = (18, 5, -1)$.
105+
5. Substituting $(p_{3}, q_{3}, m_{3}) = (18, 5, -1)$ in key step, we get $5 \cdot x_{4} \equiv -18 \pmod 1$ and minimize $\lvert x_{4}^2 - 13 \rvert$ i.e, $x_{4} = 4$. Update the triple $(p_{4}, q_{4}, m_{4}) = ( \frac{4 \cdot 18 + 13 \cdot 5}{1}, \frac{18 + 4 \cdot 5}{1}, \frac{4^{2} - 13}{-1}) = (137, 38, -3)$.
106+
6. Substituting $(p_{4}, q_{4}, m_{4}) = (137, 38, -3)$ in key step, we get $ 38 \cdot x_{5} \equiv -137 \pmod 3$ and minimize $\lvert x_{5}^2 - 13 \rvert$ i.e, $x_{5} = 2$. Update the triple $(p_{5}, q_{5}, m_{5}) = ( \frac{2 \cdot 137 + 13 \cdot 38}{3}, \frac{137 + 2 \cdot 38}{3}, \frac{2^{2} - 13}{-3}) = (256, 71, 3)$.
107+
7. Substituting $(p_{5}, q_{5}, m_{5}) = (256, 71, 3)$ in key step, we get $ 71 \cdot x_{6} \equiv -256 \pmod 3$ and minimize $\lvert x_{6}^2 - 13 \rvert$ i.e, $x_{6} = 4$. Update the triple $(p_{6}, q_{6}, m_{6}) = ( \frac{4 \cdot 256 + 13 \cdot 71}{3}, \frac{256 + 4 \cdot 71}{3}, \frac{4^{2} - 13}{3}) = (649, 180, 1)$.
91108

92109
##Implementation
93110
```cpp
@@ -97,8 +114,9 @@ Using above Brahmagupta's identity, If $(x_{1}, y_{1}, k_{1})$ and $(x_{2}, y_{2
97114
##References
98115
-[Pell's equation - Wikipedia](https://en.wikipedia.org/wiki/Pell%27s_equation)
99116
-[Periodic Continued Fractions](https://en.wikipedia.org/wiki/Periodic_continued_fraction)
100-
-[Chakralava Method - Wikipedia](https://en.wikipedia.org/wiki/Chakravala_method)
101-
-[Chakralava Method](https://www.isibang.ac.in/~sury/chakravala.pdf)
117+
-[Chakravala Method - Wikipedia](https://en.wikipedia.org/wiki/Chakravala_method)
118+
-[Chakravala Method](http://publications.azimpremjifoundation.org/1630/1/3_The%20Chakravala%20Method.pdf)
119+
-[Chakravala Method](https://www.isibang.ac.in/~sury/chakravala.pdf)
102120
-[Codeforces Pell's Equation](https://codeforces.com/topic/116937/en20)
103121

104122
##Problems

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp