-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathdiophantine.tex
55 lines (45 loc) · 2.32 KB
/
diophantine.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Diophantine equations play a central role in number theory. A
Diophantine equation has the form, $f(x_1, x_2, \dotsc, x_n) = 0$ where $n \geq
2$ and $x_1, x_2, \dotsc, x_n$ are integer variables. If there are $n$
integers $a_1, a_2, \dotsc, a_n$ such that $x_1 = a_1, x_2 = a_2, \dotsc, x_n =
a_n$ satisfies the above equation, the equation is said to be solvable.
Currently, the following five types of Diophantine equations can be solved using
SymPy's Diophantine submodule ($a_1, \ldots, a_{n+1}$, $a$, $b$, $c$, $d$, $e$,
$f$, and $k$ are explicitly given rational constants, $x_1, \ldots, x_{n+1}$,
$x$, $y$, and $z$ are unknown variables):
\begin{itemize}
\item Linear Diophantine equations: $a_1x_1 + a_2x_2 + \dotsb{} + a_{n}x_{n} = b$
\item General binary quadratic equation: $ax^2 + bxy + cy^2 + dx + ey + f = 0$
\item Homogeneous ternary quadratic equation: $ax^2 + by^2 + cz^2 + dxy + eyz + fzx = 0$
\item Extended Pythagorean equation: $a_{1}x_{1}^2 + a_{2}x_{2}^2 + \dotsb{} + a_{n}x_{n}^2 = a_{n+1}x_{n+1}^2$
\item General sum of squares: $x_{1}^2 + x_{2}^2 + \dotsb{} + x_{n}^2 = k$
\end{itemize}
The \verb|diophantine| function factors the equation it is given (if
possible), solves each factor separately, and combines the results to give
a final solution set. Solutions may include parametrized variables (over the
integers).
The following examples illustrate some of the
basic functionalities of the Diophantine submodule.
\begin{verbatim}
>>> from sympy.solvers.diophantine import *
>>> diophantine(2*x + 3*y - 5)
set([(3*t_0 - 5, -2*t_0 + 5)])
>>> diophantine(2*x + 4*y - 3)
set()
>>> diophantine(x**2 - 4*x*y + 8*y**2 - 3*x + 7*y - 5)
set([(2, 1), (5, 1)])
>>> diophantine(x**2 - 4*x*y + 4*y**2 - 3*x + 7*y - 5)
set([(-2*t**2 - 7*t + 10, -t**2 - 3*t + 5)])
>>> diophantine(3*x**2 + 4*y**2 - 5*z**2 + 4*x*y - 7*y*z + 7*z*x)
set([(-16*p**2 + 28*p*q + 20*q**2,
3*p**2 + 38*p*q - 25*q**2,
4*p**2 - 24*p*q + 68*q**2)])
>>> x1, x2, x3, x4, x5, x6 = symbols('x1 x2 x3 x4 x5 x6')
>>> diophantine(9*x1**2 + 16*x2**2 + x3**2 + 49*x4**2 + 4*x5**2 - 25*x6**2)
set([(70*t1**2 + 70*t2**2 + 70*t3**2 + 70*t4**2 - 70*t5**2, 105*t1*t5,
420*t2*t5, 60*t3*t5, 210*t4*t5, 42*t1**2 + 42*t2**2 + 42*t3**2 + 42*t4**2 +
42*t5**2)])
>>> a, b, c, d = symbols('a b c d')
>>> diophantine(a**2 + b**2 + c**2 + d**2 - 23)
set([(2, 3, 3, 1)])
\end{verbatim}