passagemath-repl 10.5.28__py3-none-any.whl → 10.5.30__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. passagemath_repl-10.5.30.data/data/share/jupyter/kernels/sagemath/kernel.json +1 -0
  2. passagemath_repl-10.5.30.data/data/share/jupyter/kernels/sagemath/logo-64x64.png +0 -0
  3. passagemath_repl-10.5.30.data/data/share/jupyter/kernels/sagemath/logo.svg +352 -0
  4. {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/METADATA +3 -3
  5. {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/RECORD +95 -24
  6. {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/top_level.txt +1 -0
  7. sage/ext_data/all__sagemath_repl.py +1 -0
  8. sage/interfaces/all__sagemath_repl.py +1 -0
  9. sage/repl/ipython_kernel/install.py +6 -8
  10. sage/tests/books/__init__.py +2 -0
  11. sage/tests/books/computational-mathematics-with-sagemath/__init__.py +1 -0
  12. sage/tests/books/computational-mathematics-with-sagemath/calculus_doctest.py +550 -0
  13. sage/tests/books/computational-mathematics-with-sagemath/combinat_doctest.py +1054 -0
  14. sage/tests/books/computational-mathematics-with-sagemath/domaines_doctest.py +444 -0
  15. sage/tests/books/computational-mathematics-with-sagemath/float_doctest.py +478 -0
  16. sage/tests/books/computational-mathematics-with-sagemath/graphique_doctest.py +255 -0
  17. sage/tests/books/computational-mathematics-with-sagemath/graphtheory_doctest.py +419 -0
  18. sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py +291 -0
  19. sage/tests/books/computational-mathematics-with-sagemath/linalg_doctest.py +455 -0
  20. sage/tests/books/computational-mathematics-with-sagemath/linsolve_doctest.py +422 -0
  21. sage/tests/books/computational-mathematics-with-sagemath/lp_doctest.py +235 -0
  22. sage/tests/books/computational-mathematics-with-sagemath/mpoly_doctest.py +561 -0
  23. sage/tests/books/computational-mathematics-with-sagemath/nonlinear_doctest.py +491 -0
  24. sage/tests/books/computational-mathematics-with-sagemath/numbertheory_doctest.py +156 -0
  25. sage/tests/books/computational-mathematics-with-sagemath/polynomes_doctest.py +406 -0
  26. sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py +181 -0
  27. sage/tests/books/computational-mathematics-with-sagemath/programmation_doctest.py +663 -0
  28. sage/tests/books/computational-mathematics-with-sagemath/recequadiff_doctest.py +393 -0
  29. sage/tests/books/computational-mathematics-with-sagemath/sol/__init__.py +1 -0
  30. sage/tests/books/computational-mathematics-with-sagemath/sol/calculus_doctest.py +265 -0
  31. sage/tests/books/computational-mathematics-with-sagemath/sol/combinat_doctest.py +218 -0
  32. sage/tests/books/computational-mathematics-with-sagemath/sol/domaines_doctest.py +60 -0
  33. sage/tests/books/computational-mathematics-with-sagemath/sol/float_doctest.py +142 -0
  34. sage/tests/books/computational-mathematics-with-sagemath/sol/graphique_doctest.py +106 -0
  35. sage/tests/books/computational-mathematics-with-sagemath/sol/graphtheory_doctest.py +54 -0
  36. sage/tests/books/computational-mathematics-with-sagemath/sol/integration_doctest.py +57 -0
  37. sage/tests/books/computational-mathematics-with-sagemath/sol/linalg_doctest.py +57 -0
  38. sage/tests/books/computational-mathematics-with-sagemath/sol/linsolve_doctest.py +26 -0
  39. sage/tests/books/computational-mathematics-with-sagemath/sol/lp_doctest.py +48 -0
  40. sage/tests/books/computational-mathematics-with-sagemath/sol/mpoly_doctest.py +116 -0
  41. sage/tests/books/computational-mathematics-with-sagemath/sol/nonlinear_doctest.py +112 -0
  42. sage/tests/books/computational-mathematics-with-sagemath/sol/numbertheory_doctest.py +168 -0
  43. sage/tests/books/computational-mathematics-with-sagemath/sol/polynomes_doctest.py +108 -0
  44. sage/tests/books/computational-mathematics-with-sagemath/sol/recequadiff_doctest.py +59 -0
  45. sage/tests/books/judson-abstract-algebra/__init__.py +1 -0
  46. sage/tests/books/judson-abstract-algebra/actions-sage-exercises.py +52 -0
  47. sage/tests/books/judson-abstract-algebra/actions-sage.py +174 -0
  48. sage/tests/books/judson-abstract-algebra/algcodes-sage.py +131 -0
  49. sage/tests/books/judson-abstract-algebra/boolean-sage.py +270 -0
  50. sage/tests/books/judson-abstract-algebra/cosets-sage-exercises.py +88 -0
  51. sage/tests/books/judson-abstract-algebra/cosets-sage.py +171 -0
  52. sage/tests/books/judson-abstract-algebra/crypt-sage.py +152 -0
  53. sage/tests/books/judson-abstract-algebra/cyclic-sage.py +451 -0
  54. sage/tests/books/judson-abstract-algebra/domains-sage.py +164 -0
  55. sage/tests/books/judson-abstract-algebra/fields-sage.py +300 -0
  56. sage/tests/books/judson-abstract-algebra/finite-sage.py +109 -0
  57. sage/tests/books/judson-abstract-algebra/galois-sage.py +485 -0
  58. sage/tests/books/judson-abstract-algebra/groups-sage.py +281 -0
  59. sage/tests/books/judson-abstract-algebra/homomorph-sage-exercises.py +66 -0
  60. sage/tests/books/judson-abstract-algebra/homomorph-sage.py +201 -0
  61. sage/tests/books/judson-abstract-algebra/integers-sage.py +198 -0
  62. sage/tests/books/judson-abstract-algebra/isomorph-sage.py +173 -0
  63. sage/tests/books/judson-abstract-algebra/normal-sage.py +134 -0
  64. sage/tests/books/judson-abstract-algebra/permute-sage.py +320 -0
  65. sage/tests/books/judson-abstract-algebra/poly-sage.py +301 -0
  66. sage/tests/books/judson-abstract-algebra/rings-sage.py +414 -0
  67. sage/tests/books/judson-abstract-algebra/sets-sage.py +164 -0
  68. sage/tests/books/judson-abstract-algebra/struct-sage.py +64 -0
  69. sage/tests/books/judson-abstract-algebra/sylow-sage.py +251 -0
  70. sage/tests/books/judson-abstract-algebra/vect-sage-exercises.py +49 -0
  71. sage/tests/books/judson-abstract-algebra/vect-sage.py +212 -0
  72. sage/tests/memcheck/__init__.py +1 -0
  73. sage/tests/memcheck/run_tests.py +25 -0
  74. sage/tests/memcheck/run_tests_in_valgrind.py +36 -0
  75. sage/tests/memcheck/symbolic_expression.py +12 -0
  76. sage/tests/memcheck/verify_no_leak.py +28 -0
  77. sage/tests/all.py +0 -0
  78. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-cachegrind +0 -0
  79. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-callgrind +0 -0
  80. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-cleaner +0 -0
  81. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-coverage +0 -0
  82. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-eval +0 -0
  83. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-fixdoctests +0 -0
  84. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-inline-fortran +0 -0
  85. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-ipynb2rst +0 -0
  86. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-ipython +0 -0
  87. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-massif +0 -0
  88. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-notebook +0 -0
  89. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-omega +0 -0
  90. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-preparse +0 -0
  91. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-run +0 -0
  92. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-run-cython +0 -0
  93. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-runtests +0 -0
  94. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-startuptime.py +0 -0
  95. {passagemath_repl-10.5.28.data → passagemath_repl-10.5.30.data}/scripts/sage-valgrind +0 -0
  96. {passagemath_repl-10.5.28.dist-info → passagemath_repl-10.5.30.dist-info}/WHEEL +0 -0
@@ -0,0 +1,491 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ # sage.doctest: needs sage.symbolic
3
+ """
4
+ This file (./nonlinear_doctest.sage) was *autogenerated* from ./nonlinear.tex,
5
+ with sagetex.sty version 2011/05/27 v2.3.1.
6
+ It contains the contents of all the sageexample environments from this file.
7
+ You should be able to doctest this file with:
8
+ sage -t ./nonlinear_doctest.sage
9
+ It is always safe to delete this file; it is not used in typesetting your
10
+ document.
11
+
12
+ Sage example in ./nonlinear.tex, line 102::
13
+
14
+ sage: R.<x> = PolynomialRing(RealField(prec=10))
15
+ sage: p = 2*x^7 - 21*x^6 + 64*x^5 - 67*x^4 + 90*x^3 \
16
+ ....: + 265*x^2 - 900*x + 375
17
+ sage: p.roots()
18
+ [(-1.7, 1), (0.50, 1), (1.7, 1), (5.0, 2)]
19
+ sage: p.roots(ring=ComplexField(10), multiplicities=False)
20
+ [-1.7, 0.50, 1.7, 5.0, -2.2*I, 2.2*I]
21
+ sage: p.roots(ring=RationalField())
22
+ [(1/2, 1), (5, 2)]
23
+
24
+ Sage example in ./nonlinear.tex, line 246::
25
+
26
+ sage: R.<x> = PolynomialRing(QQ, 'x')
27
+ sage: p = x^4 + x^3 + x^2 + x + 1
28
+ sage: K.<alpha> = p.root_field()
29
+ sage: p.roots(ring=K, multiplicities=None)
30
+ [alpha, alpha^2, alpha^3, -alpha^3 - alpha^2 - alpha - 1]
31
+ sage: alpha^5
32
+ 1
33
+
34
+ Sage example in ./nonlinear.tex, line 309::
35
+
36
+ sage: R.<x> = PolynomialRing(RR, 'x')
37
+ sage: d = ZZ.random_element(1, 15)
38
+ sage: p = R.random_element(d)
39
+ sage: p.degree() == sum(r[1] for r in p.roots(CC))
40
+ True
41
+
42
+ Sage example in ./nonlinear.tex, line 348::
43
+
44
+ sage: def build_complex_roots(degree):
45
+ ....: R.<x> = PolynomialRing(CDF, 'x')
46
+ ....: v = []
47
+ ....: for c in cartesian_product([[-1, 1]] * (degree + 1)):
48
+ ....: v.extend(R(list(c)).roots(multiplicities=False))
49
+ ....: return v
50
+ sage: data = build_complex_roots(12) # long time
51
+ sage: points(data, pointsize=1, aspect_ratio=1) # long time
52
+ Graphics object consisting of 1 graphics primitive
53
+
54
+ Sage example in ./nonlinear.tex, line 420::
55
+
56
+ sage: a, b, c, x = var('a, b, c, x')
57
+ sage: p = a * x^2 + b * x + c
58
+ sage: type(p)
59
+ <... 'sage.symbolic.expression.Expression'>
60
+ sage: p.parent()
61
+ Symbolic Ring
62
+ sage: p.roots(x)
63
+ [(-1/2*(b + sqrt(b^2 - 4*a*c))/a, 1),
64
+ (-1/2*(b - sqrt(b^2 - 4*a*c))/a, 1)]
65
+
66
+ Sage example in ./nonlinear.tex, line 450::
67
+
68
+ sage: a, b, c, d, e, f, x = var('a, b, c, d, e, f, x')
69
+ sage: p = a*x^5+b*x^4+c*x^3+d*x^2+e*x+f
70
+ sage: p.roots(x)
71
+ Traceback (most recent call last):
72
+ ...
73
+ RuntimeError: no explicit roots found
74
+
75
+ Sage example in ./nonlinear.tex, line 467::
76
+
77
+ sage: x, a, b, c, d = var('x, a, b, c, d')
78
+ sage: P = a * x^3 + b * x^2 + c * x + d
79
+ sage: alpha = var('alpha')
80
+ sage: P.subs(x = x + alpha).expand().coefficient(x, 2)
81
+ 3*a*alpha + b
82
+ sage: P.subs(x = x - b / (3 * a)).expand().collect(x)
83
+ a*x^3 - 1/3*(b^2/a - 3*c)*x + 2/27*b^3/a^2 - 1/3*b*c/a + d
84
+
85
+ Sage example in ./nonlinear.tex, line 482::
86
+
87
+ sage: p, q, u, v = var('p, q, u, v')
88
+ sage: P = x^3 + p * x + q
89
+ sage: P.subs(x = u + v).expand()
90
+ u^3 + 3*u^2*v + 3*u*v^2 + v^3 + p*u + p*v + q
91
+
92
+ Sage example in ./nonlinear.tex, line 498::
93
+
94
+ sage: P.subs({x: u + v, q: -u^3 - v^3}).factor()
95
+ (3*u*v + p)*(u + v)
96
+ sage: P.subs({x: u+v, q: -u^3 - v^3, p: -3 * u * v}).expand()
97
+ 0
98
+ sage: X = var('X')
99
+ sage: solve([X^2 + q*X - p^3 / 27 == 0], X, solution_dict=True)
100
+ [{X: -1/2*q - 1/18*sqrt(12*p^3 + 81*q^2)},
101
+ {X: -1/2*q + 1/18*sqrt(12*p^3 + 81*q^2)}]
102
+
103
+ Sage example in ./nonlinear.tex, line 539::
104
+
105
+ sage: e = sin(x) * (x^3 + 1) * (x^5 + x^4 + 1)
106
+ sage: roots = e.roots(); len(roots)
107
+ 9
108
+ sage: roots
109
+ [(0, 1),
110
+ (-1/2*(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3)*(I*sqrt(3) + 1) - 1/6*(-I*sqrt(3) + 1)/(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3),
111
+ 1),
112
+ (-1/2*(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3)*(-I*sqrt(3) + 1) - 1/6*(I*sqrt(3) + 1)/(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3),
113
+ 1),
114
+ ((1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3) + 1/3/(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3),
115
+ 1),
116
+ (-1/2*I*sqrt(3) - 1/2, 1),
117
+ (1/2*I*sqrt(3) - 1/2, 1),
118
+ (1/2*I*sqrt(3)*(-1)^(1/3) - 1/2*(-1)^(1/3), 1),
119
+ (-1/2*I*sqrt(3)*(-1)^(1/3) - 1/2*(-1)^(1/3), 1),
120
+ ((-1)^(1/3), 1)]
121
+
122
+ Sage example in ./nonlinear.tex, line 620::
123
+
124
+ sage: alpha, m, x = var('alpha, m, x'); q = function('q')(x)
125
+ sage: p = (x - alpha)^m * q
126
+ sage: p.derivative(x)
127
+ (-alpha + x)^(m - 1)*m*q(x) + (-alpha + x)^m*diff(q(x), x)
128
+ sage: simplify(p.derivative(x)(x=alpha))
129
+ 0
130
+
131
+ Sage example in ./nonlinear.tex, line 659::
132
+
133
+ sage: R.<x> = PolynomialRing(QQ, 'x')
134
+ sage: p = 128 * x^13 - 1344 * x^12 + 6048 * x^11 - 15632 * x^10 \
135
+ ....: + 28056 * x^9 - 44604 * x^8 + 71198 * x^7 - 98283 * x^6 \
136
+ ....: + 105840 * x^5 - 101304 * x^4 + 99468 * x^3 - 81648 * x^2 \
137
+ ....: + 40824 * x - 8748
138
+ sage: d = gcd(p, p.derivative())
139
+ sage: (p // d).degree()
140
+ 4
141
+ sage: roots = SR(p // d).roots(multiplicities=False)
142
+ sage: roots
143
+ [1/2*I*sqrt(3)*2^(1/3) - 1/2*2^(1/3),
144
+ -1/2*I*sqrt(3)*2^(1/3) - 1/2*2^(1/3),
145
+ 2^(1/3),
146
+ 3/2]
147
+ sage: [QQbar(p(alpha)).is_zero() for alpha in roots] # long time
148
+ [True, True, True, True]
149
+
150
+ Sage example in ./nonlinear.tex, line 732::
151
+
152
+ sage: R.<x> = PolynomialRing(RR, 'x')
153
+ sage: p = x^7 - 131/3*x^6 + 1070/3*x^5 - 2927/3*x^4 \
154
+ ....: + 2435/3*x^3 - 806/3*x^2 + 3188/3*x - 680
155
+ sage: l = [c for c in p.coefficients(sparse=False) if not c.is_zero()]
156
+ sage: sign_changes = [l[i]*l[i+1] < 0 for i in range(len(l)-1)].count(True)
157
+ sage: real_positive_roots = \
158
+ ....: sum([alpha[1] if alpha[0] > 0 else 0 for alpha in p.roots()])
159
+ sage: sign_changes, real_positive_roots
160
+ (7, 5)
161
+
162
+ Sage example in ./nonlinear.tex, line 831::
163
+
164
+ sage: def count_sign_changes(p):
165
+ ....: l = [c for c in p if not c.is_zero()]
166
+ ....: changes = [l[i]*l[i + 1] < 0 for i in range(len(l) - 1)]
167
+ ....: return changes.count(True)
168
+
169
+ Sage example in ./nonlinear.tex, line 837::
170
+
171
+ sage: def sturm(p, a, b):
172
+ ....: assert p.degree() > 2
173
+ ....: assert not (p(a) == 0)
174
+ ....: assert not (p(b) == 0)
175
+ ....: assert a <= b
176
+ ....: remains = [p, p.derivative()]
177
+ ....: for i in range(p.degree() - 1):
178
+ ....: remains.append(-(remains[i] % remains[i + 1]))
179
+ ....: evals = [[], []]
180
+ ....: for q in remains:
181
+ ....: evals[0].append(q(a))
182
+ ....: evals[1].append(q(b))
183
+ ....: return count_sign_changes(evals[0]) \
184
+ ....: - count_sign_changes(evals[1])
185
+
186
+ Sage example in ./nonlinear.tex, line 857::
187
+
188
+ sage: R.<x> = PolynomialRing(QQ, 'x')
189
+ sage: p = (x - 34) * (x - 5) * (x - 3) * (x - 2) * (x - 2/3)
190
+ sage: sturm(p, 1, 4)
191
+ 2
192
+ sage: sturm(p, 1, 10)
193
+ 3
194
+ sage: sturm(p, 1, 200)
195
+ 4
196
+ sage: p.roots(multiplicities=False)
197
+ [34, 5, 3, 2, 2/3]
198
+ sage: sturm(p, 1/2, 35)
199
+ 5
200
+
201
+ Sage example in ./nonlinear.tex, line 949::
202
+
203
+ sage: f(x) = 4 * sin(x) - exp(x) / 2 + 1
204
+ sage: a, b = RR(-pi), RR(pi)
205
+ sage: bool(f(a) * f(b) < 0)
206
+ True
207
+
208
+ Sage example in ./nonlinear.tex, line 961::
209
+
210
+ sage: solve(f(x) == 0, x)
211
+ [sin(x) == 1/8*e^x - 1/4]
212
+
213
+ Sage example in ./nonlinear.tex, line 966::
214
+
215
+ sage: f.roots()
216
+ Traceback (most recent call last):
217
+ ...
218
+ RuntimeError: no explicit roots found
219
+
220
+ Sage example in ./nonlinear.tex, line 991::
221
+
222
+ sage: a, b = RR(-pi), RR(pi)
223
+ sage: g = plot(f, a, b, rgbcolor='blue')
224
+
225
+ Sage example in ./nonlinear.tex, line 1045::
226
+
227
+ sage: def phi(s, t): return (s + t) / 2
228
+ sage: def intervalgen(f, phi, s, t):
229
+ ....: msg = 'Wrong arguments: f({0})*f({1})>=0)'.format(s, t)
230
+ ....: assert (f(s) * f(t) < 0), msg
231
+ ....: yield s
232
+ ....: yield t
233
+ ....: while True:
234
+ ....: u = phi(s, t)
235
+ ....: yield u
236
+ ....: if f(u) * f(s) < 0:
237
+ ....: t = u
238
+ ....: else:
239
+ ....: s = u
240
+
241
+ Sage example in ./nonlinear.tex, line 1152::
242
+
243
+ sage: a, b
244
+ (-3.14159265358979, 3.14159265358979)
245
+ sage: bisection = intervalgen(f, phi, a, b)
246
+ sage: next(bisection)
247
+ -3.14159265358979
248
+ sage: next(bisection)
249
+ 3.14159265358979
250
+ sage: next(bisection)
251
+ 0.000000000000000
252
+
253
+ Sage example in ./nonlinear.tex, line 1178::
254
+
255
+ sage: from types import GeneratorType, FunctionType
256
+ sage: def checklength(u, v, w, prec):
257
+ ....: return abs(v - u) < 2 * prec
258
+ sage: def iterate(series, check=checklength, prec=10^-5, maxit=100):
259
+ ....: assert isinstance(series, GeneratorType)
260
+ ....: assert isinstance(check, FunctionType)
261
+ ....: niter = 2
262
+ ....: v, w = next(series), next(series)
263
+ ....: while niter <= maxit:
264
+ ....: niter += 1
265
+ ....: u, v, w = v, w, next(series)
266
+ ....: if check(u, v, w, prec):
267
+ ....: print('After {0} iterations: {1}'.format(niter, w))
268
+ ....: return
269
+ ....: print('Failed after {0} iterations'.format(maxit))
270
+
271
+ Sage example in ./nonlinear.tex, line 1221::
272
+
273
+ sage: bisection = intervalgen(f, phi, a, b)
274
+ sage: iterate(bisection)
275
+ After 22 iterations: 2.15847275559132
276
+
277
+ Sage example in ./nonlinear.tex, line 1313::
278
+
279
+ sage: phi(s, t) = s - f(s) * (t - s) / (f(t) - f(s))
280
+ sage: falsepos = intervalgen(f, phi, a, b)
281
+ sage: iterate(falsepos)
282
+ After 8 iterations: -2.89603757331027
283
+
284
+ Sage example in ./nonlinear.tex, line 1320::
285
+
286
+ sage: a, b = RR(-pi), RR(pi)
287
+ sage: g = plot(f, a, b, rgbcolor='blue')
288
+ sage: phi(s, t) = s - f(s) * (t - s) /(f(t) - f(s))
289
+ sage: falsepos = intervalgen(f, phi, a, b)
290
+ sage: u, v, w = next(falsepos), next(falsepos), next(falsepos)
291
+ sage: niter = 3
292
+ sage: while niter < 9:
293
+ ....: g += line([(u, 0), (u, f(u))], rgbcolor='red',
294
+ ....: linestyle=':')
295
+ ....: g += line([(u, f(u)), (v, f(v))], rgbcolor='red')
296
+ ....: g += line([(v, 0), (v, f(v))], rgbcolor='red',
297
+ ....: linestyle=':')
298
+ ....: g += point((w, 0), rgbcolor='red')
299
+ ....: if (f(u) * f(w)) < 0:
300
+ ....: u, v = u, w
301
+ ....: else:
302
+ ....: u, v = w, v
303
+ ....: w = next(falsepos)
304
+ ....: niter += 1
305
+
306
+ Sage example in ./nonlinear.tex, line 1361::
307
+
308
+ sage: a, b = RR(pi/2), RR(pi)
309
+ sage: phi(s, t) = t - f(t) * (s - t) / (f(s) - f(t))
310
+ sage: falsepos = intervalgen(f, phi, a, b)
311
+ sage: phi(s, t) = (s + t) / 2
312
+ sage: bisection = intervalgen(f, phi, a, b)
313
+ sage: iterate(falsepos)
314
+ After 15 iterations: 2.15846441170219
315
+ sage: iterate(bisection)
316
+ After 20 iterations: 2.15847275559132
317
+
318
+ Sage example in ./nonlinear.tex, line 1373::
319
+
320
+ sage: a, b = RR(pi/2), RR(pi)
321
+ sage: g = plot(f, a, b, rgbcolor='blue')
322
+ sage: phi(s, t) = t - f(t) * (s - t) / (f(s) - f(t))
323
+ sage: falsepos = intervalgen(f, phi, a, b)
324
+ sage: u, v, w = next(falsepos), next(falsepos), next(falsepos)
325
+ sage: niter = 3
326
+ sage: while niter < 7:
327
+ ....: g += line([(u, 0), (u, f(u))], rgbcolor='red',
328
+ ....: linestyle=':')
329
+ ....: g += line([(u, f(u)), (v, f(v))], rgbcolor='red')
330
+ ....: g += line([(v, 0), (v, f(v))], rgbcolor='red',
331
+ ....: linestyle=':')
332
+ ....: g += point((w, 0), rgbcolor='red')
333
+ ....: if (f(u) * f(w)) < 0:
334
+ ....: u, v = u, w
335
+ ....: else:
336
+ ....: u, v = w, v
337
+ ....: w = next(falsepos)
338
+ ....: niter += 1
339
+
340
+ Sage example in ./nonlinear.tex, line 1477::
341
+
342
+ sage: f.derivative()
343
+ x |--> 4*cos(x) - 1/2*e^x
344
+ sage: a, b = RR(pi/2), RR(pi)
345
+
346
+ Sage example in ./nonlinear.tex, line 1501::
347
+
348
+ sage: def newtongen(f, u):
349
+ ....: while True:
350
+ ....: yield u
351
+ ....: u -= f(u) / f.derivative()(u)
352
+ sage: def checkconv(u, v, w, prec):
353
+ ....: return abs(w - v) / abs(w) <= prec
354
+
355
+ Sage example in ./nonlinear.tex, line 1513::
356
+
357
+ sage: iterate(newtongen(f, a), check=checkconv)
358
+ After 6 iterations: 2.15846852566756
359
+
360
+ Sage example in ./nonlinear.tex, line 1518::
361
+
362
+ sage: generator = newtongen(f, a)
363
+ sage: g = plot(f, a, b, rgbcolor='blue')
364
+ sage: u, v = next(generator), next(generator)
365
+ sage: niter = 2
366
+ sage: while niter < 6:
367
+ ....: g += point((u, 0), rgbcolor='red')
368
+ ....: g += line([(u, 0), (u, f(u))], rgbcolor='red',
369
+ ....: linestyle=':')
370
+ ....: g += line([(u, f(u)), (v, 0)], rgbcolor='red')
371
+ ....: u, v = v, next(generator)
372
+ ....: niter += 1
373
+
374
+ Sage example in ./nonlinear.tex, line 1583::
375
+
376
+ sage: def secantgen(f, a):
377
+ ....: yield a
378
+ ....: estimate = f.derivative()(a)
379
+ ....: b = a - f(a) / estimate
380
+ ....: yield b
381
+ ....: while True:
382
+ ....: fa, fb = f(a), f(b)
383
+ ....: if fa == fb:
384
+ ....: estimate = f.derivative()(a)
385
+ ....: else:
386
+ ....: estimate = (fb - fa) / (b - a)
387
+ ....: a = b
388
+ ....: b -= fb / estimate
389
+ ....: yield b
390
+
391
+ Sage example in ./nonlinear.tex, line 1609::
392
+
393
+ sage: iterate(secantgen(f, a), check=checkconv)
394
+ After 8 iterations: 2.15846852557553
395
+
396
+ Sage example in ./nonlinear.tex, line 1621::
397
+
398
+ sage: g = plot(f, a, b, rgbcolor='blue')
399
+ sage: sequence = secantgen(f, a)
400
+ sage: u, v = next(sequence), next(sequence)
401
+ sage: niter = 2
402
+ sage: while niter < 6:
403
+ ....: g += point((u, 0), rgbcolor='red')
404
+ ....: g += line([(u, 0), (u, f(u))], rgbcolor='red',
405
+ ....: linestyle=':')
406
+ ....: g += line([(u, f(u)), (v, 0)], rgbcolor='red')
407
+ ....: u, v = v, next(sequence)
408
+ ....: niter += 1
409
+
410
+ Sage example in ./nonlinear.tex, line 1697::
411
+
412
+ sage: from collections import deque
413
+ sage: basering = PolynomialRing(CC, 'x')
414
+ sage: def quadraticgen(f, r, s):
415
+ ....: t = (r + s) / 2
416
+ ....: yield t
417
+ ....: points = deque([(r,f(r)), (s,f(s)), (t,f(t))], maxlen=int(3))
418
+ ....: while True:
419
+ ....: pol = basering.lagrange_polynomial(points)
420
+ ....: roots = pol.roots(ring=CC, multiplicities=False)
421
+ ....: u = min(roots, key=lambda x: abs(x - points[2][0]))
422
+ ....: points.append((u, f(u)))
423
+ ....: yield points[2][0]
424
+
425
+ Sage example in ./nonlinear.tex, line 1742::
426
+
427
+ sage: generator = quadraticgen(f, a, b)
428
+ sage: iterate(generator, check=checkconv)
429
+ After 5 iterations: 2.15846852554764
430
+
431
+ Sage example in ./nonlinear.tex, line 1851::
432
+
433
+ sage: for ring in [ZZ, QQ, QQbar, RDF, RIF, RR, AA, CDF, CIF, CC]:
434
+ ....: print("{0:50} {1}".format(str(ring), ring.is_exact()))
435
+ Integer Ring True
436
+ Rational Field True
437
+ Algebraic Field True
438
+ Real Double Field False
439
+ Real Interval Field with 53 bits of precision False
440
+ Real Field with 53 bits of precision False
441
+ Algebraic Real Field True
442
+ Complex Double Field False
443
+ Complex Interval Field with 53 bits of precision False
444
+ Complex Field with 53 bits of precision False
445
+
446
+ Sage example in ./nonlinear.tex, line 2031::
447
+
448
+ sage: def steffensen(sequence):
449
+ ....: assert isinstance(sequence, GeneratorType)
450
+ ....: values = deque(maxlen=int(3))
451
+ ....: for i in range(3):
452
+ ....: values.append(next(sequence))
453
+ ....: yield values[i]
454
+ ....: while True:
455
+ ....: values.append(next(sequence))
456
+ ....: u, v, w = values
457
+ ....: yield u - (v - u)^2 / (w - 2 * v + u)
458
+
459
+ Sage example in ./nonlinear.tex, line 2047::
460
+
461
+ sage: g(x) = sin(x^2 - 2) * (x^2 - 2)
462
+ sage: sequence = newtongen(g, RR(0.7))
463
+ sage: accelseq = steffensen(newtongen(g, RR(0.7)))
464
+ sage: iterate(sequence, check=checkconv)
465
+ After 17 iterations: 1.41422192763287
466
+ sage: iterate(accelseq, check=checkconv)
467
+ After 10 iterations: 1.41421041980166
468
+
469
+ Sage example in ./nonlinear.tex, line 2062::
470
+
471
+ sage: sequence = newtongen(f, RR(a))
472
+ sage: accelseq = steffensen(newtongen(f, RR(a)))
473
+ sage: iterate(sequence, check=checkconv)
474
+ After 6 iterations: 2.15846852566756
475
+ sage: iterate(accelseq, check=checkconv)
476
+ After 7 iterations: 2.15846852554764
477
+
478
+ Sage example in ./nonlinear.tex, line 2124::
479
+
480
+ sage: result = (f == 0).find_root(a, b, full_output=True)
481
+ sage: result[0], result[1].iterations
482
+ (2.1584685255476415, 9)
483
+
484
+ Sage example in ./nonlinear.tex, line 2183::
485
+
486
+ sage: a, b = pi/2, pi
487
+ sage: generator = newtongen(f, a)
488
+ sage: next(generator); next(generator)
489
+ 1/2*pi
490
+ 1/2*pi - (e^(1/2*pi) - 10)*e^(-1/2*pi)
491
+ """
@@ -0,0 +1,156 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ # sage.doctest: needs sage.libs.pari sage.symbolic
3
+ """
4
+ This file (./numbertheory_doctest.sage) was *autogenerated* from ./numbertheory.tex,
5
+ with sagetex.sty version 2011/05/27 v2.3.1.
6
+ It contains the contents of all the sageexample environments from this file.
7
+ You should be able to doctest this file with:
8
+ sage -t ./numbertheory_doctest.sage
9
+ It is always safe to delete this file; it is not used in typesetting your
10
+ document.
11
+
12
+ Sage example in ./numbertheory.tex, line 107::
13
+
14
+ sage: a = IntegerModRing(15)(3); b = IntegerModRing(17)(3); a, b
15
+ (3, 3)
16
+ sage: a == b
17
+ False
18
+
19
+ Sage example in ./numbertheory.tex, line 135::
20
+
21
+ sage: R = a.parent(); R
22
+ Ring of integers modulo 15
23
+ sage: R.characteristic()
24
+ 15
25
+
26
+ Sage example in ./numbertheory.tex, line 157::
27
+
28
+ sage: a + a, a - 17, a * a + 1, a^3
29
+ (6, 1, 10, 12)
30
+
31
+ Sage example in ./numbertheory.tex, line 199::
32
+
33
+ sage: z = a.lift(); y = ZZ(a); y, type(y), y == z
34
+ (3, <... 'sage.rings.integer.Integer'>, True)
35
+
36
+ Sage example in ./numbertheory.tex, line 228::
37
+
38
+ sage: [Mod(x,15).additive_order() for x in range(0,15)]
39
+ [1, 15, 15, 5, 15, 3, 5, 15, 15, 5, 3, 15, 5, 15, 15]
40
+
41
+ Sage example in ./numbertheory.tex, line 261::
42
+
43
+ sage: [[x, Mod(x,15).multiplicative_order()]
44
+ ....: for x in range(1,15) if gcd(x,15) == 1]
45
+ [[1, 1], [2, 4], [4, 2], [7, 4], [8, 4], [11, 2], [13, 4], [14, 2]]
46
+
47
+ Sage example in ./numbertheory.tex, line 276::
48
+
49
+ sage: p = 10^20 + 39; mod(2,p).multiplicative_order()
50
+ 50000000000000000019
51
+ sage: mod(3,p).multiplicative_order()
52
+ 100000000000000000038
53
+
54
+ Sage example in ./numbertheory.tex, line 367::
55
+
56
+ sage: R = GF(17); [1/R(x) for x in range(1,17)]
57
+ [1, 9, 6, 13, 7, 3, 5, 15, 2, 12, 14, 10, 4, 11, 8, 16]
58
+
59
+ Sage example in ./numbertheory.tex, line 403::
60
+
61
+ sage: R = GF(9,name='x'); R
62
+ Finite Field in x of size 3^2
63
+
64
+ Sage example in ./numbertheory.tex, line 409::
65
+
66
+ sage: R.polynomial()
67
+ x^2 + 2*x + 2
68
+
69
+ Sage example in ./numbertheory.tex, line 423::
70
+
71
+ sage: Set([r for r in R])
72
+ {0, 1, 2, x, x + 1, x + 2, 2*x, 2*x + 1, 2*x + 2}
73
+
74
+ Sage example in ./numbertheory.tex, line 429::
75
+
76
+ sage: Q.<x> = PolynomialRing(GF(3))
77
+ sage: R2 = GF(9, name='x', modulus=x^2+1); R2
78
+ Finite Field in x of size 3^2
79
+
80
+ Sage example in ./numbertheory.tex, line 463::
81
+
82
+ sage: p = R(x+1); R2(p)
83
+ Traceback (most recent call last):
84
+ ...
85
+ TypeError: unable to coerce from a finite field other than the prime subfield
86
+
87
+ Sage example in ./numbertheory.tex, line 548::
88
+
89
+ sage: rational_reconstruction(411,1000)
90
+ -13/17
91
+ sage: rational_reconstruction(409,1000)
92
+ Traceback (most recent call last):
93
+ ...
94
+ ArithmeticError: rational reconstruction of 409 (mod 1000) does not exist
95
+
96
+ Sage example in ./numbertheory.tex, line 571::
97
+
98
+ sage: def harmonic(n):
99
+ ....: return add([1/x for x in range(1,n+1)])
100
+
101
+ Sage example in ./numbertheory.tex, line 593::
102
+
103
+ sage: def harmonic_mod(n, m):
104
+ ....: return add([1/x % m for x in range(1,n+1)])
105
+ sage: def harmonic2(n):
106
+ ....: q = lcm(range(1,n+1))
107
+ ....: pmax = RR(q*(log(n)+1))
108
+ ....: m = ZZ(2*pmax^2)
109
+ ....: m = integer_ceil(m / q) * q + 1
110
+ ....: a = harmonic_mod(n,m)
111
+ ....: return rational_reconstruction(a,m)
112
+
113
+ Sage example in ./numbertheory.tex, line 707::
114
+
115
+ sage: a = 2; b = 3; m = 5; n = 7; lambda0 = (b-a)/m % n; a + lambda0 * m
116
+ 17
117
+ sage: crt(2,3,5,7)
118
+ 17
119
+
120
+ Sage example in ./numbertheory.tex, line 726::
121
+
122
+ sage: def harmonic3(n):
123
+ ....: q = lcm(range(1,n+1))
124
+ ....: pmax = RR(q*(log(n)+1))
125
+ ....: B = ZZ(2*pmax^2)
126
+ ....: a = 0; m = 1; p = 2^63
127
+ ....: while m < B:
128
+ ....: p = next_prime(p)
129
+ ....: b = harmonic_mod(n,p)
130
+ ....: a = crt(a,b,m,p)
131
+ ....: m = m*p
132
+ ....: return rational_reconstruction(a,m)
133
+ sage: harmonic(100) == harmonic3(100)
134
+ True
135
+
136
+ Sage example in ./numbertheory.tex, line 755::
137
+
138
+ sage: crt(15,1,30,4)
139
+ 45
140
+ sage: crt(15,2,30,4)
141
+ Traceback (most recent call last):
142
+ ...
143
+ ValueError: no solution to crt problem since gcd(30,4) does not divide 15-2
144
+
145
+ Sage example in ./numbertheory.tex, line 1008::
146
+
147
+ sage: [560 % (x-1) for x in [3,11,17]]
148
+ [0, 0, 0]
149
+
150
+ Sage example in ./numbertheory.tex, line 1226::
151
+
152
+ sage: p = 10^10+19; a = mod(17,p); a.log(2)
153
+ 6954104378
154
+ sage: mod(2,p)^6954104378
155
+ 17
156
+ """