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