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,254 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ """
3
+ This file (./graphique_doctest.sage) was *autogenerated* from ./graphique.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 ./graphique_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 ./graphique.tex, line 18::
12
+
13
+ sage: reset()
14
+
15
+ Sage example in ./graphique.tex, line 61::
16
+
17
+ sage: plot(x * sin(1/x), x, -2, 2, plot_points=500)
18
+ Graphics object consisting of 1 graphics primitive
19
+
20
+ Sage example in ./graphique.tex, line 156::
21
+
22
+ sage: def p(x, n):
23
+ ....: return(taylor(sin(x), x, 0, n))
24
+ sage: xmax = 15 ; n = 15
25
+ sage: g = plot(sin(x), x, -xmax, xmax)
26
+ sage: for d in range(n): # long time
27
+ ....: g += plot(p(x, 2 * d + 1), x, -xmax, xmax,\
28
+ ....: color=(1.7*d/(2*n), 1.5*d/(2*n), 1-3*d/(4*n)))
29
+ sage: g.show(ymin=-2, ymax=2)
30
+
31
+ Sage example in ./graphique.tex, line 237::
32
+
33
+ sage: f2(x) = 1; f1(x) = -1
34
+ sage: f = piecewise([[(-pi,0),f1],[(0,pi),f2]])
35
+ sage: S = f.fourier_series_partial_sum(20,pi)
36
+ sage: g = plot(S, x, -8, 8, color='blue')
37
+ sage: saw(x) = x - 2 * pi * floor((x + pi) / (2 * pi))
38
+ sage: g += plot(saw(x) / abs(saw(x)), x, -8, 8, color='red')
39
+ sage: g
40
+ Graphics object consisting of 2 graphics primitives
41
+
42
+ Sage example in ./graphique.tex, line 311::
43
+
44
+ sage: t = var('t')
45
+ sage: x = cos(t) + cos(7*t)/2 + sin(17*t)/3
46
+ sage: y = sin(t) + sin(7*t)/2 + cos(17*t)/3
47
+ sage: g = parametric_plot((x, y), (t, 0, 2*pi))
48
+ sage: g.show(aspect_ratio=1)
49
+
50
+ Sage example in ./graphique.tex, line 364::
51
+
52
+ sage: t = var('t'); n = 20/19
53
+ sage: g1 = polar_plot(1+2*cos(n*t),(t,0,n*36*pi),plot_points=5000)
54
+ sage: g2 = polar_plot(1+1/3*cos(n*t),(t,0,n*36*pi),plot_points=5000)
55
+ sage: g1.show(aspect_ratio=1); g2.show(aspect_ratio=1)
56
+
57
+ Sage example in ./graphique.tex, line 500::
58
+
59
+ sage: bar_chart([randrange(15) for i in range(20)])
60
+ Graphics object consisting of 1 graphics primitive
61
+ sage: bar_chart([x^2 for x in range(1,20)], width=0.2)
62
+ Graphics object consisting of 1 graphics primitive
63
+
64
+ Sage example in ./graphique.tex, line 550::
65
+
66
+ sage: liste = [10 + floor(10*sin(i)) for i in range(100)]
67
+ sage: bar_chart(liste)
68
+ Graphics object consisting of 1 graphics primitive
69
+ sage: TimeSeries(liste).plot_histogram(bins=20)
70
+ Graphics object consisting of 20 graphics primitives
71
+
72
+ Sage example in ./graphique.tex, line 714::
73
+
74
+ sage: n, l, x, y = 10000, 1, 0, 0; p = [[0, 0]]
75
+ sage: for k in range(n):
76
+ ....: theta = (2 * pi * random()).n(digits=5)
77
+ ....: x, y = x + l * cos(theta), y + l * sin(theta)
78
+ ....: p.append([x, y])
79
+ sage: g1 = line([p[n], [0, 0]], color='red', thickness=2)
80
+ sage: g1 += line(p, thickness=.4); g1.show(aspect_ratio=1)
81
+
82
+ Sage example in ./graphique.tex, line 777::
83
+
84
+ sage: length = 200; n = var('n')
85
+ sage: u = lambda n: n * sqrt(2)
86
+ sage: z = lambda n: exp(2 * I * pi * u(n)).n()
87
+ sage: vertices = [CC(0, 0)]
88
+ sage: for n in range(1, length):
89
+ ....: vertices.append(vertices[n - 1] + CC(z(n)))
90
+ sage: line(vertices).show(aspect_ratio=1)
91
+
92
+ Sage example in ./graphique.tex, line 968::
93
+
94
+ sage: x = var('x'); y = function('y')
95
+ sage: DE = x*diff(y(x), x) == 2*y(x) + x^3
96
+ sage: desolve(DE, [y(x),x])
97
+ (_C + x)*x^2
98
+ sage: sol = []
99
+ sage: for i in srange(-2, 2, 0.2):
100
+ ....: sol.append(desolve(DE, [y(x), x], ics=[1, i]))
101
+ ....: sol.append(desolve(DE, [y(x), x], ics=[-1, i]))
102
+ sage: g = plot(sol, x, -2, 2)
103
+ sage: y = var('y')
104
+ sage: g += plot_vector_field((x, 2*y+x^3), (x,-2,2), (y,-1,1))
105
+ sage: g.show(ymin=-1, ymax=1)
106
+
107
+ Sage example in ./graphique.tex, line 1029::
108
+
109
+ sage: x = var('x'); y = function('y')
110
+ sage: DE = x*diff(y(x), x) == 2*y(x) + x^3
111
+ sage: g = Graphics() # creates an empty graph
112
+ sage: for i in srange(-2, 2, 0.2): # long time
113
+ ....: g += line(desolve_rk4(DE, y(x), ics=[1, i],\
114
+ ....: step=0.05, end_points=[0,2]))
115
+ ....: g += line(desolve_rk4(DE, y(x), ics=[-1, i],\
116
+ ....: step=0.05, end_points=[-2,0]))
117
+ sage: y = var('y')
118
+ sage: g += plot_vector_field((x, 2*y+x^3), (x,-2,2), (y,-1,1))
119
+ sage: g.show(ymin=-1, ymax=1)
120
+
121
+ Sage example in ./graphique.tex, line 1120::
122
+
123
+ sage: import scipy; from scipy import integrate
124
+ sage: f = lambda y, t: - cos(y * t)
125
+ sage: t = srange(0, 5, 0.1); p = Graphics()
126
+ sage: for k in srange(0, 10, 0.15):
127
+ ....: y = integrate.odeint(f, k, t)
128
+ ....: p += line(zip(t, flatten(y.tolist())))
129
+ sage: t = srange(0, -5, -0.1); q = Graphics()
130
+ sage: for k in srange(0, 10, 0.15):
131
+ ....: y = integrate.odeint(f, k, t)
132
+ ....: q += line(zip(t, flatten(y.tolist())))
133
+ sage: y = var('y')
134
+ sage: v = plot_vector_field((1, -cos(x*y)), (x,-5,5), (y,-2,11))
135
+ sage: g = p + q + v; g.show()
136
+
137
+ Sage example in ./graphique.tex, line 1229::
138
+
139
+ sage: import scipy; from scipy import integrate
140
+ sage: a, b, c, d = 1., 0.1, 1.5, 0.75
141
+ sage: def dX_dt(X, t=0): # returns the population variation
142
+ ....: return [a*X[0] - b*X[0]*X[1], -c*X[1] + d*b*X[0]*X[1]]
143
+ sage: t = srange(0, 15, .01) # time scale
144
+ sage: X0 = [10, 5] # initial conditions: 10 rabbits and 5 foxes
145
+ sage: X = integrate.odeint(dX_dt, X0, t) # numerical solution
146
+ sage: rabbits, foxes = X.T # shortcut for X.transpose()
147
+ sage: p = line(zip(t, rabbits), color='red') # number of rabbits graph
148
+ sage: p += text("Rabbits",(12,37), fontsize=10, color='red')
149
+ sage: p += line(zip(t, foxes), color='blue') # idem for foxes
150
+ sage: p += text("Foxes",(12,7), fontsize=10, color='blue')
151
+ sage: p.axes_labels(["time", "population"]); p.show(gridlines=True)
152
+
153
+ Sage example in ./graphique.tex, line 1266::
154
+
155
+ sage: n = 11; L = srange(6, 18, 12 / n); R = srange(3, 9, 6 / n)
156
+ sage: CI = list(zip(L, R)) # list of initial conditions
157
+ sage: def g(x, y):
158
+ ....: v = vector(dX_dt([x, y])) # for a nicer graph, we
159
+ ....: return v/v.norm() # normalise the vector field
160
+ sage: x, y = var('x, y')
161
+ sage: q = plot_vector_field(g(x, y), (x, 0, 60), (y, 0, 36))
162
+ sage: for j in range(n):
163
+ ....: X = integrate.odeint(dX_dt, CI[j], t) # resolution
164
+ ....: q += line(X, color=hue(.8-float(j)/(1.8*n))) # graph plot
165
+ sage: q.axes_labels(["rabbits","foxes"]); q.show()
166
+
167
+ Sage example in ./graphique.tex, line 1501::
168
+
169
+ sage: x, y, t = var('x, y, t')
170
+ sage: alpha(t) = 1; beta(t) = t / 2; gamma(t) = t + t^3 / 8
171
+ sage: env = solve([alpha(t) * x + beta(t) * y == gamma(t),\
172
+ ....: diff(alpha(t), t) * x + diff(beta(t), t) * y == \
173
+ ....: diff(gamma(t), t)], [x,y])
174
+
175
+ Sage example in ./graphique.tex, line 1541::
176
+
177
+ sage: f(x) = x^2 / 4
178
+ sage: p = plot(f, -8, 8, rgbcolor=(0.2,0.2,0.4)) # the parabola
179
+ sage: for u in srange(0, 8, 0.1): # normals to the parabola
180
+ ....: p += line([[u, f(u)], [-8*u, f(u) + 18]], thickness=.3)
181
+ ....: p += line([[-u, f(u)], [8*u, f(u) + 18]], thickness=.3)
182
+ sage: p += parametric_plot((env[0][0].rhs(),env[0][1].rhs()),\
183
+ ....: (t, -8, 8),color='red') # draws the evolute
184
+ sage: p.show(xmin=-8, xmax=8, ymin=-1, ymax=12, aspect_ratio=1)
185
+
186
+ Sage example in ./graphique.tex, line 1604::
187
+
188
+ sage: t = var('t'); p = 2
189
+ sage: x(t) = t; y(t) = t^2 / (2 * p); f(t) = [x(t), y(t)]
190
+ sage: df(t) = [x(t).diff(t), y(t).diff(t)]
191
+ sage: d2f(t) = [x(t).diff(t, 2), y(t).diff(t, 2)]
192
+ sage: T(t) = [df(t)[0] / df(t).norm(), df[1](t) / df(t).norm()]
193
+ sage: N(t) = [-df(t)[1] / df(t).norm(), df[0](t) / df(t).norm()]
194
+ sage: R(t) = (df(t).norm())^3 / (df(t)[0]*d2f(t)[1]-df(t)[1]*d2f(t)[0])
195
+ sage: Omega(t) = [f(t)[0] + R(t)*N(t)[0], f(t)[1] + R(t)*N(t)[1]]
196
+ sage: g = parametric_plot(f(t), (t,-8,8), color='green',thickness=2)
197
+ sage: for u in srange(.4, 4, .2):
198
+ ....: g += line([f(t=u), Omega(t=u)], color='red', alpha = .5)
199
+ ....: g += circle(Omega(t=u), R(t=u), color='blue')
200
+ sage: g.show(aspect_ratio=1,xmin=-12,xmax=7,ymin=-3,ymax=12)
201
+
202
+ Sage example in ./graphique.tex, line 1781::
203
+
204
+ sage: u, v = var('u, v')
205
+ sage: h = lambda u,v: u^2 + 2*v^2
206
+ sage: plot3d(h, (u,-1,1), (v,-1,1), aspect_ratio=[1,1,1])
207
+ Graphics3d Object
208
+
209
+ Sage example in ./graphique.tex, line 1833. Sometimes the result
210
+ needs to be simplified to obtain a nice short expression::
211
+
212
+ sage: f(x, y) = x^2 * y / (x^4 + y^2)
213
+ sage: t, theta = var('t, theta')
214
+ sage: result = limit(f(t * cos(theta), t * sin(theta)) / t, t=0)
215
+ sage: result.full_simplify()
216
+ cos(theta)^2/sin(theta)
217
+
218
+ Sage example in ./graphique.tex, line 1847::
219
+
220
+ sage: solve(f(x,y) == 1/2, y)
221
+ [y == x^2]
222
+ sage: a = var('a'); h = f(x, a*x^2).simplify_rational(); h
223
+ a/(a^2 + 1)
224
+
225
+ Sage example in ./graphique.tex, line 1861::
226
+
227
+ sage: plot(h, a, -4, 4)
228
+ Graphics object consisting of 1 graphics primitive
229
+
230
+ Sage example in ./graphique.tex, line 1908::
231
+
232
+ sage: p = plot3d(f(x,y),(x,-2,2),(y,-2,2),plot_points=[150,150])
233
+
234
+ Sage example in ./graphique.tex, line 1937::
235
+
236
+ sage: for i in range(1,4):
237
+ ....: p += plot3d(-0.5 + i / 4, (x, -2, 2), (y, -2, 2),\
238
+ ....: color=hue(i / 10), opacity=.1)
239
+
240
+ Sage example in ./graphique.tex, line 1956::
241
+
242
+ sage: x, y, z = var('x, y, z'); a = 1
243
+ sage: h = lambda x, y, z:(a^2 + x^2 + y^2)^2 - 4*a^2*x^2-z^4
244
+ sage: implicit_plot3d(h, (x,-3,3), (y,-3,3), (z,-2,2), # long time
245
+ ....: plot_points=100)
246
+ Graphics3d Object
247
+
248
+ Sage example in ./graphique.tex, line 2004::
249
+
250
+ sage: line3d([(-10*cos(t)-2*cos(5*t)+15*sin(2*t),\
251
+ ....: -15*cos(2*t)+10*sin(t)-2*sin(5*t),\
252
+ ....: 10*cos(3*t)) for t in srange(0,6.4,.1)],radius=.5)
253
+ Graphics3d Object
254
+ """
@@ -0,0 +1,418 @@
1
+ # sage_setup: distribution = sagemath-repl
2
+ """
3
+ This file (./graphtheory_doctest.sage) was *autogenerated* from ./graphtheory.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 ./graphtheory_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 ./graphtheory.tex, line 12::
12
+
13
+ sage: set_random_seed(1588)
14
+ sage: sage.numerical.backends.generic_backend.default_solver = "Glpk"
15
+
16
+ Sage example in ./graphtheory.tex, line 59::
17
+
18
+ sage: g = Graph()
19
+
20
+ Sage example in ./graphtheory.tex, line 87::
21
+
22
+ sage: g.order(), g.size()
23
+ (0, 0)
24
+ sage: g.add_vertex(0)
25
+ sage: g.order(), g.size()
26
+ (1, 0)
27
+ sage: g.add_vertices([1, 2, 5, 9])
28
+ sage: g.order(), g.size()
29
+ (5, 0)
30
+ sage: g.add_edges([(1,5), (9,2), (2,5), (1,9)])
31
+ sage: g.order(), g.size()
32
+ (5, 4)
33
+ sage: g.add_edge("Madrid", "Edinburgh")
34
+ sage: g.order(), g.size()
35
+ (7, 5)
36
+
37
+ Sage example in ./graphtheory.tex, line 128::
38
+
39
+ sage: g.delete_vertex(0)
40
+ sage: g.delete_edges([(1,5), (2,5)])
41
+ sage: g.order(), g.size()
42
+ (6, 3)
43
+ sage: sorted(g.vertices(sort=False), key=str)
44
+ [1, 2, 5, 9, 'Edinburgh', 'Madrid']
45
+ sage: sorted(g.edges(sort=False, labels=False), key=str)
46
+ [('Edinburgh', 'Madrid'), (1, 9), (2, 9)]
47
+
48
+ Sage example in ./graphtheory.tex, line 159::
49
+
50
+ sage: g = Graph({
51
+ ....: 0: [],
52
+ ....: 1: [5, 9],
53
+ ....: 2: [1, 5, 9],
54
+ ....: 'Edinburgh': ['Madrid']})
55
+
56
+ Sage example in ./graphtheory.tex, line 212::
57
+
58
+ sage: P = graphs.PetersenGraph()
59
+ sage: C = graphs.ChvatalGraph()
60
+
61
+ Sage example in ./graphtheory.tex, line 252::
62
+
63
+ sage: P = graphs.PetersenGraph()
64
+ sage: P.is_planar()
65
+ False
66
+ sage: P.minor(graphs.CompleteBipartiteGraph(3,3)) # random
67
+ {0: [1], 1: [8], 2: [4], 3: [6, 7, 9], 4: [2, 3], 5: [0, 5]}
68
+ sage: P.minor(graphs.CompleteGraph(5)) # random
69
+ {0: [1, 6], 1: [0, 5], 2: [2, 7], 3: [4, 9], 4: [3, 8]}
70
+ sage: P.girth()
71
+ 5
72
+ sage: P.is_regular(3)
73
+ True
74
+ sage: P.chromatic_number()
75
+ 3
76
+ sage: P.is_vertex_transitive()
77
+ True
78
+ sage: P.show()
79
+
80
+ Sage example in ./graphtheory.tex, line 332::
81
+
82
+ sage: K = graphs.KneserGraph(5, 2); P = graphs.PetersenGraph()
83
+ sage: K.is_isomorphic(P)
84
+ True
85
+
86
+ Sage example in ./graphtheory.tex, line 340::
87
+
88
+ sage: all( graphs.KneserGraph(n,k).chromatic_number() == n - 2*k + 2
89
+ ....: for n in range(5, 9) for k in range(2, n // 2) )
90
+ True
91
+
92
+ Sage example in ./graphtheory.tex, line 459::
93
+
94
+ sage: H = graphs.ClawGraph()
95
+ sage: def test():
96
+ ....: g = graphs.RandomGNP(20,2/5)
97
+ ....: return not g.subgraph_search(H, induced=True) is None
98
+ sage: sum( test() for i in range(100) ) >= 80
99
+ True
100
+
101
+ Sage example in ./graphtheory.tex, line 485::
102
+
103
+ sage: P = graphs.PetersenGraph()
104
+ sage: H = graphs.HoffmanSingletonGraph()
105
+ sage: U = P + H; U2 = P.disjoint_union(H)
106
+ sage: U.is_isomorphic(U2)
107
+ True
108
+
109
+ Sage example in ./graphtheory.tex, line 496::
110
+
111
+ sage: C = graphs.ChvatalGraph()
112
+ sage: U = 3 * C; U2 = C.disjoint_union(C.disjoint_union(C))
113
+ sage: U2.is_isomorphic(U)
114
+ True
115
+
116
+ Sage example in ./graphtheory.tex, line 506::
117
+
118
+ sage: U = 3*P + 2*C
119
+
120
+ Sage example in ./graphtheory.tex, line 513::
121
+
122
+ sage: all( (CC.is_isomorphic(P) or CC.is_isomorphic(C))
123
+ ....: for CC in U.connected_components_subgraphs() )
124
+ True
125
+
126
+ Sage example in ./graphtheory.tex, line 522::
127
+
128
+ sage: sum( CC.is_isomorphic(P)
129
+ ....: for CC in U.connected_components_subgraphs() )
130
+ 3
131
+ sage: sum( CC.is_isomorphic(C)
132
+ ....: for CC in U.connected_components_subgraphs() )
133
+ 2
134
+
135
+ Sage example in ./graphtheory.tex, line 568::
136
+
137
+ sage: C = graphs.ChvatalGraph(); C.show()
138
+
139
+ Sage example in ./graphtheory.tex, line 583::
140
+
141
+ sage: C.show(partition = [C.independent_set()])
142
+
143
+ Sage example in ./graphtheory.tex, line 597::
144
+
145
+ sage: C.show(vertex_colors = {
146
+ ....: "red" : [0, 1, 2], "blue" : [3, 4, 5],
147
+ ....: "yellow" : [6, 7, 8], "purple" : [9, 10, 11]})
148
+
149
+ Sage example in ./graphtheory.tex, line 608::
150
+
151
+ sage: C.coloring(hex_colors = True)
152
+ {'#00ffff': [3, 8, 5],
153
+ '#7f00ff': [11],
154
+ '#7fff00': [1, 4, 6, 9],
155
+ '#ff0000': [0, 2, 7, 10]}
156
+ sage: C.show(vertex_colors = C.coloring(hex_colors = True))
157
+
158
+ Sage example in ./graphtheory.tex, line 644::
159
+
160
+ sage: L = [graphs.CompleteGraph(i) for i in range(3,3+10)]
161
+ sage: for number, G in enumerate(L):
162
+ ....: G.plot().save(tmp_filename(ext='.png'))
163
+
164
+ Sage example in ./graphtheory.tex, line 782::
165
+
166
+ sage: P5 = graphs.PathGraph(5); House = graphs.HouseGraph()
167
+ sage: P5.complement().is_isomorphic(House)
168
+ True
169
+ sage: P4 = graphs.PathGraph(4); P4.complement().is_isomorphic(P4)
170
+ True
171
+ sage: C5 = graphs.CycleGraph(5); C5.complement().is_isomorphic(C5)
172
+ True
173
+
174
+ Sage example in ./graphtheory.tex, line 852::
175
+
176
+ sage: n = 5; Path = graphs.PathGraph(n)
177
+ sage: Grid = Path.cartesian_product(Path)
178
+ sage: Grid.is_isomorphic(graphs.GridGraph([n,n]))
179
+ True
180
+
181
+ Sage example in ./graphtheory.tex, line 1144::
182
+
183
+ sage: n = 30; p = 0.3; trials = 50
184
+ sage: def equality(G):
185
+ ....: return G.edge_connectivity() == min(G.degree())
186
+ sage: sum(equality(graphs.RandomGNP(n,p)) for i in range(trials))/trials
187
+ 1
188
+
189
+ Sage example in ./graphtheory.tex, line 1319::
190
+
191
+ sage: g = graphs.ChvatalGraph(); cycle = g.hamiltonian_cycle()
192
+ sage: g.show(vertex_labels = False); cycle.show(vertex_labels = False)
193
+
194
+ Sage example in ./graphtheory.tex, line 1586::
195
+
196
+ sage: set_random_seed(3291)
197
+
198
+ Sage example in ./graphtheory.tex, line 1589::
199
+
200
+ sage: n = 100; p = 5/n; g = graphs.RandomGNP(n, p)
201
+
202
+ Sage example in ./graphtheory.tex, line 1597::
203
+
204
+ sage: # Set of available colors.
205
+ sage: # In the worst-case scenario up to n colors suffice
206
+ sage: available_colors = Set(range(n))
207
+
208
+ Sage example in ./graphtheory.tex, line 1611::
209
+
210
+ sage: # This dictionary contains the color associated
211
+ sage: # with each vertex of the graph
212
+ sage: color = {}
213
+ sage: for u in g:
214
+ ....: forbidden = Set([color[v] for v in g.neighbors(u)
215
+ ....: if v in color])
216
+ ....: color[u] = min(available_colors - forbidden)
217
+
218
+ Sage example in ./graphtheory.tex, line 1625::
219
+
220
+ sage: # Number of colors used
221
+ sage: max(color.values()) + 1
222
+ 5
223
+
224
+ Sage example in ./graphtheory.tex, line 1635::
225
+
226
+ sage: P = Permutations([0,1,2,3]); P.random_element()
227
+ [3, 2, 1, 0]
228
+
229
+ Sage example in ./graphtheory.tex, line 1646::
230
+
231
+ sage: available_colors = Set(range(n))
232
+
233
+ Sage example in ./graphtheory.tex, line 1656::
234
+
235
+ sage: n_tests = 30
236
+ sage: vertices = g.vertices(sort=False)
237
+ sage: P = Permutations(range(n))
238
+ sage: best_coloring = {}
239
+ sage: best_chromatic_number = +oo
240
+
241
+ Sage example in ./graphtheory.tex, line 1678::
242
+
243
+ sage: for t in range(n_tests):
244
+ ....: # Random ordering of vertices
245
+ ....: p = P.random_element()
246
+ ....: color = {}
247
+ ....: for i in range(g.order()):
248
+ ....: u = vertices[p[i]]
249
+ ....: forbidden = Set([color[v] for v in g.neighbors(u)
250
+ ....: if v in color])
251
+ ....: color[u] = min(available_colors - forbidden)
252
+ ....: # Update the best coloring
253
+ ....: if max(color.values()) + 1 < best_chromatic_number:
254
+ ....: best_coloring = color
255
+ ....: best_chromatic_number = 1 + max(color.values())
256
+
257
+ Sage example in ./graphtheory.tex, line 1697::
258
+
259
+ sage: best_chromatic_number # Number of colors used
260
+ 5
261
+
262
+ Sage example in ./graphtheory.tex, line 1718::
263
+
264
+ sage: def greedy_coloring(g, permutation):
265
+ ....: n = g.order()
266
+ ....: available_colors = Set(range(n))
267
+ ....: vertices = g.vertices(sort=False)
268
+ ....: color = {}
269
+ ....: for i in range(n):
270
+ ....: u = vertices[permutation[i]]
271
+ ....: forbidden = Set([color[v] for v in g.neighbors(u)
272
+ ....: if v in color])
273
+ ....: color[u] = min(available_colors - forbidden)
274
+ ....: return max(color.values()) + 1, color
275
+
276
+ Sage example in ./graphtheory.tex, line 1736::
277
+
278
+ sage: set_random_seed(0)
279
+
280
+ Sage example in ./graphtheory.tex, line 1746::
281
+
282
+ sage: P = Permutations(range(g.order()))
283
+ sage: n_colors, coloration = min([greedy_coloring(g, P.random_element())
284
+ ....: for i in range(50)], key=lambda c: c[0])
285
+ sage: n_colors
286
+ 5
287
+
288
+ Sage example in ./graphtheory.tex, line 1782::
289
+
290
+ sage: n = 20; k = 4; g = graphs.RandomGNP(n, 0.5)
291
+ sage: g = g.subgraph(edges = g.min_spanning_tree())
292
+
293
+ Sage example in ./graphtheory.tex, line 1786::
294
+
295
+ sage: while True:
296
+ ....: _, edges, [S,Sb] = g.edge_connectivity(vertices = True)
297
+ ....: cardinality = len(edges)
298
+ ....: if cardinality < k:
299
+ ....: CP = cartesian_product([S, Sb])
300
+ ....: g.add_edges([CP.random_element()
301
+ ....: for i in range(k - len(edges))])
302
+ ....: else:
303
+ ....: break
304
+
305
+ Sage example in ./graphtheory.tex, line 1844::
306
+
307
+ sage: g = graphs.RandomGNP(40, 0.4)
308
+ sage: P = Permutations(range(g.order()))
309
+ sage: mean = sum( 1/(g.degree(v)+1) for v in g )
310
+
311
+ Sage example in ./graphtheory.tex, line 1849::
312
+
313
+ sage: while True:
314
+ ....: n = P.random_element()
315
+ ....: S = [v for v in g if all( n[v] < n[u] for u in g.neighbors(v))]
316
+ ....: if len(S) >= mean:
317
+ ....: break
318
+
319
+ Sage example in ./graphtheory.tex, line 1989::
320
+
321
+ sage: def find_induced(H, G):
322
+ ....: # the function from V(H) to V(G) we aim to define:
323
+ ....: f = {}
324
+ ....: # set of vertices of G not yet used by f:
325
+ ....: G_remain = G.vertices(sort=False)
326
+ ....: # set of vertices having no representative yet:
327
+ ....: H_remain = H.vertices(sort=False)
328
+ ....: # while the function is not complete:
329
+ ....: while H_remain:
330
+ ....: v = H_remain.pop(0) # look for the next vertex of H
331
+ ....: # and its potential images in G
332
+ ....: candidates = [u for u in G_remain
333
+ ....: if all(H.has_edge(h,v) == G.has_edge(f_h,u)
334
+ ....: for h, f_h in f.items())]
335
+ ....: # if no candidate is found, we abort immediately
336
+ ....: if not candidates:
337
+ ....: raise ValueError("No copy of H has been found in G")
338
+ ....: # otherwise we select the first candidate
339
+ ....: f[v] = candidates[0]
340
+ ....: G_remain.remove(f[v])
341
+ ....: return f
342
+
343
+ Sage example in ./graphtheory.tex, line 2012::
344
+
345
+ sage: set_random_seed(4)
346
+
347
+ Sage example in ./graphtheory.tex, line 2021::
348
+
349
+ sage: H = graphs.PetersenGraph()
350
+ sage: G = graphs.RandomGNP(500,0.5)
351
+ sage: find_induced(H,G)
352
+ {0: 0, 1: 1, 2: 3, 3: 13, 4: 7, 5: 62, 6: 24, 7: 232, 8: 67, 9: 45}
353
+
354
+ Sage example in ./graphtheory.tex, line 2070::
355
+
356
+ sage: n = 100; V = range(n+1)
357
+ sage: G = Graph()
358
+ sage: G.add_edges([
359
+ ....: (i,j) for i,j in Subsets(V,2) if is_square(abs(i-j)) ])
360
+
361
+ Sage example in ./graphtheory.tex, line 2084::
362
+
363
+ sage: X = G.independent_set(); X # random with python3
364
+ [4, 6, 9, 11, 16, 21, 23, 26, 28, 33, 38, 43, 50,
365
+ 56, 61, 71, 76, 78, 83, 88, 93, 95, 98, 100]
366
+ sage: G.is_independent_set(X)
367
+ True
368
+
369
+ Sage example in ./graphtheory.tex, line 2139::
370
+
371
+ sage: tasks = {0: [2, 5, 3, 7], 1: [0, 1, 4],
372
+ ....: 2: [5, 0, 4], 3: [0, 1],
373
+ ....: 4: [8], 5: [2],
374
+ ....: 6: [8, 9, 7], 7: [5, 8, 7],
375
+ ....: 8: [2, 5, 3, 6, 4], 9: [2, 5, 8, 6, 1]}
376
+ sage: G = Graph()
377
+ sage: for i in tasks:
378
+ ....: G.add_edges(("w" + str(i), "t" + str(j)) for j in tasks[i])
379
+
380
+ Sage example in ./graphtheory.tex, line 2182::
381
+
382
+ sage: M = Graph(G.matching())
383
+ sage: txt = "t{} assigned to {}"
384
+ sage: for i in tasks: # random
385
+ ....: print(txt.format(i, M.neighbors('t' + str(i))[0])) # random
386
+ t0 assigned to w2
387
+ t1 assigned to w3
388
+ t2 assigned to w5
389
+ t3 assigned to w8
390
+ t4 assigned to w1
391
+ t5 assigned to w7
392
+ t6 assigned to w9
393
+ t7 assigned to w0
394
+ t8 assigned to w4
395
+ t9 assigned to w6
396
+
397
+ Sage example in ./graphtheory.tex, line 2232::
398
+
399
+ sage: n = 10
400
+ sage: G = graphs.CompleteGraph(n)
401
+ sage: from sage.graphs.graph_coloring import edge_coloring
402
+ sage: for day, matches in enumerate(edge_coloring(G)):
403
+ ....: print("Matches of day {}: {}".format(day, matches))
404
+ Matches of day 0: [(0, 9), (1, 8), (2, 7), (3, 6), (4, 5)]
405
+ Matches of day 1: [(0, 2), (1, 9), (3, 8), (4, 7), (5, 6)]
406
+ Matches of day 2: [(0, 4), (1, 3), (2, 9), (5, 8), (6, 7)]
407
+ Matches of day 3: [(0, 6), (1, 5), (2, 4), (3, 9), (7, 8)]
408
+ Matches of day 4: [(0, 8), (1, 7), (2, 6), (3, 5), (4, 9)]
409
+ Matches of day 5: [(0, 1), (2, 8), (3, 7), (4, 6), (5, 9)]
410
+ Matches of day 6: [(0, 3), (1, 2), (4, 8), (5, 7), (6, 9)]
411
+ Matches of day 7: [(0, 5), (1, 4), (2, 3), (6, 8), (7, 9)]
412
+ Matches of day 8: [(0, 7), (1, 6), (2, 5), (3, 4), (8, 9)]
413
+
414
+ Sage example in ./graphtheory.tex, line 2260::
415
+
416
+ sage: g = graphs.CompleteGraph(10)
417
+ sage: g.show(edge_colors=edge_coloring(g, hex_colors=True))
418
+ """