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

Commit982d59e

Browse files
committed
PR review comments
1 parentc54b9f1 commit982d59e

File tree

3 files changed

+50
-40
lines changed

3 files changed

+50
-40
lines changed

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ converted.pdf
88
/public
99
.firebase/
1010
firebase-debug.log
11-
.idea/
1211
__pycache__/
1312

1413
authors.json

‎scripts/install-mkdocs.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ pip install \
99
mkdocs-git-revision-date-localized-plugin \
1010
mkdocs-simple-hooks \
1111
mkdocs-rss-plugin \
12-
mkdocs-git-committers-plugin-2
12+
plugins/mkdocs-git-committers-plugin-2

‎src/others/pells_equation.md‎

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,73 @@ Alternative formulation: We want to find all the possible solutions of the equat
1414
Here we will consider the case when $d$ is not a perfect square and $d>1$. The case when $d$ is a perfect square is trivial.
1515
We can even assume that $d$ is square-free (i.e. it is not divisible by the square of any prime number) as we can absorb the factors of $d$ into $y$.
1616

17-
$x^{2} - d \cdot y^{2} = ( x + \sqrt{d} \cdot y ) ( x - \sqrt{d} \cdot y ) = 1$
17+
We can rewrite the equation as:
1818

19-
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, since the product is 1.
19+
$$x^{2} - d y^{2} = (x +y\sqrt{d})(x -y\sqrt{d}) = 1$$
2020

21-
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
22-
$x_{0} + y_{0} \cdot \sqrt{d}$
21+
This factorization is important because it shows the connection to quadratic irrationals. The first part $(x + y \sqrt{d})$ is always greater than 1, and the second part $(x - y \sqrt{d})$ is always less than 1, since their product is 1.
2322

24-
We use method of descent to prove it.
23+
The norm of an expression $u + v \sqrt{d}$ is defined as $N(u + v \sqrt{d}) = (u + v \sqrt{d})(u - v \sqrt{d}) = u^2 - d v^2$. The norm is multiplicative: $N(ab) = N(a)N(b)$. This property is crucial in the descent argument below.
24+
25+
We will prove that all solutions to Pell's equation are given by powers of the smallest non-trivial solution. Let's assume it to be the minimum possible $x_0 + y_0 \sqrt{d} > 1$. For such a solution, it also holds that $y_0 > 0$, and its $x_0 > 1$ is the smallest possible value for $x$.
26+
27+
##Method of Descent
2528
Suppose there is a solution $u + v \cdot \sqrt{d}$ such that $u^{2} - d \cdot v^{2} = 1$ and is not a power of $( x_{0} + \sqrt{d} \cdot y_{0} )$
2629
Then it must lie between two powers of $( x_{0} + \sqrt{d} \cdot y_{0} )$.
27-
i.e, For some n, $( x_{0} + \sqrt{d} \cdot y_{0} )^{n} < u + v \cdot \sqrt{d} < ( x_{0} + \sqrt{d} \cdot y_{0} )^{n+1}$
30+
i.e, For some $n$,
31+
$$
32+
( x_{0} + \sqrt{d} \cdot y_{0} )^{n} < u + v \cdot \sqrt{d} < ( x_{0} + \sqrt{d} \cdot y_{0} )^{n+1}
33+
$$
2834

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

31-
$1 < (u + v \cdot \sqrt{d})( x_{0} - \sqrt{d} \cdot y_{0} )^{n} < ( x_{0} + \sqrt{d} \cdot y_{0} )$
32-
Because both $(u + v \cdot \sqrt{d})$ and $( x_{0} - \sqrt{d} \cdot y_{0} )^{n}$ have norm 1, their product is also a solution.
37+
$$
38+
1 < (u + v \cdot \sqrt{d})( x_{0} - \sqrt{d} \cdot y_{0} )^{n} < ( x_{0} + \sqrt{d} \cdot y_{0} )
39+
$$
40+
Because both $(u + v \cdot \sqrt{d})$ and $( x_{0} - \sqrt{d} \cdot y_{0} )^{n}$ have norm $1$, their product is also a solution.
3341
But this contradicts our assumption that $( x_{0} + \sqrt{d} \cdot y_{0} )$ is the smallest solution. Therefore, there is no solution between $( x_{0} + \sqrt{d} \cdot y_{0} )^{n}$ and $( x_{0} + \sqrt{d} \cdot y_{0} )^{n+1}$.
3442

3543
Hence, we conclude that all solutions are given by $( x_{0} + \sqrt{d} \cdot y_{0} )^{n}$ for some integer $n$.
3644

3745
##Finding the smallest positive solution
3846
###Expressing the solution in terms of continued fractions
39-
We can express the solution in terms of continued fractions. The continued fraction of $\sqrt{d}$ is periodic. Let's assume the continued fraction of $\sqrt{d}$ is $[a_{0}; \overline{a_{1}, a_{2}, \ldots,a_{r}}]$. The smallest positive solution is given by the convergent $[a_{0}; a_{1}, a_{2}, \ldots,a_{r}]$ where $r$ is the period of the continued fraction.
47+
We can express the solution in terms of continued fractions. The continued fraction of $\sqrt{d}$ is periodic. Let's assume the continued fraction of $\sqrt{d}$ is $[a_0; \overline{a_1, a_2, \ldots,a_r}]$. The smallest positive solution is given by the convergent $[a_0; a_1, a_2, \ldots,a_r]$ where $r$ is the period of the continued fraction.
4048

41-
The convergents $p_{n}/q_{n}$ are the rational approximations to $\sqrt{d}$ obtained by truncating the continued fraction expansion at each stage. These convergents can be computed recursively.
49+
The convergents $p_n/q_n$ are the rational approximations to $\sqrt{d}$ obtained by truncating the continued fraction expansion at each stage. These convergents can be computed recursively. For Pell's equation, the convergent $(p_n, q_n)$ at the end of the period solves $p_n^2 - d q_n^2 = \pm 1$.
4250

43-
Check whether the convergent satisfiesthePell's equation. If it does, then the convergent is the smallest positive solution.
51+
Check whether the convergent satisfies Pell's equation. If it does, then the convergent is the smallest positive solution.
4452

45-
Let's take an example to understand this by solving the equation $x^{2} - 2\cdot y^{2} = 1$.
53+
Let's take an example to understand this by solving the equation $x^2 - 2y^2 = 1$.
4654
$\sqrt{2} =[1; \overline{2}] = 1 + 1/(2 + 1/(2 + 1/(2+ ...)))$. The convergents are $1/1, 3/2, 7/5, 17/12, 41/29, 99/70, \ldots$.
47-
Now check for each convergent whether it satisfies the Pell's equation. The smallest positive solution is $3/2$.
48-
49-
###How to calculate the continued fraction of $\sqrt{d}$?
50-
Let's find the continued fraction of $\sqrt{7}$.
51-
52-
$\sqrt{7} \approx 2.6457 = 2 + 0.6457$
53-
54-
$a_{0} = 2$
55-
56-
Subtract $a_{0}$ from the number and take the reciprocal of the remaining number.
57-
58-
That is, we calculate ${1\over \sqrt{7} - 2} \approx 1.5486$. The integer part $a_{1}$ is $1$.
59-
So:
60-
$\sqrt{7}=2+\cfrac{1}{1+\cfrac1{\vdots}}$
61-
Where we haven't calculated the $( \vdots )$ part yet.
62-
To get that, we subtract $a_{1}$ from the number and take the reciprocal of the remaining number. That is, we calculate ${1\over 1.5486 - 1} \approx 1.8228$. The integer part $a_{2}$ is $1$.
63-
So:
64-
$\sqrt{7}=2+\cfrac{1}{1+\cfrac1{1+\cfrac1{\vdots}}}$
65-
Now ${1\over 1.8228 - 1} \approx 1.2153$. So $a_{3} = 1$.
66-
Continuing this process, ${1\over 1.2153 - 1} \approx 4.645$. So $a_{4} = 4$.
67-
68-
$$\sqrt{7}=2+\cfrac{1}{1+\cfrac1{1+\cfrac1{1+\cfrac4{\vdots}}}}$$
69-
70-
we get the continued fraction of $\sqrt{7}$ as $[2; 1, 1, 4, 1, 1, 4, \ldots]$.
55+
Now check for each convergent whether it satisfies Pell's equation. The smallest positive solution is $3/2$.
56+
57+
####Integer-based continued fraction calculation
58+
For integer-based calculation, see the[Quadratic irrationality section of the continued fractions article](https://cp-algorithms.com/algebra/continued-fractions.html). Here is a sample algorithm in Python:
59+
60+
```python
61+
# Compute the continued fraction expansion of sqrt(n) using integer arithmetic
62+
import math
63+
64+
defcontinued_fraction_sqrt(n):
65+
m0=0
66+
d0=1
67+
a0=int(math.isqrt(n))
68+
period= []
69+
m, d, a= m0, d0, a0
70+
seen=set()
71+
while (m, d, a)notin seen:
72+
seen.add((m, d, a))
73+
m= d* a- m
74+
d= (n- m* m)// d
75+
a= (a0+ m)// d
76+
period.append(a)
77+
return [a0]+ period
78+
79+
# Example: sqrt(7)
80+
print(continued_fraction_sqrt(7))# Output: [2, 1, 1, 1, 4]
81+
```
7182

72-
Thiscan also be calculated using[integer based calculation(continued fractions)](https://cp-algorithms.com/algebra/continued-fractions.html)
83+
Thismethod avoids floating-point errors and is suitable for large $d$.
7384

7485
###Finding the solution using Chakravala method
7586
The Chakravala method is an ancient Indian algorithm to solve Pell's equation. It is based on the Brahmagupta's identity of quadratic decomposition

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp