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