Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download
Views: 554
Image: ubuntu2004-dev
Kernel: SageMath 9.2
version()
'SageMath version 9.2, Release Date: 2020-10-24'
pretty_print_default(True)
x,n = var('x,n') taylor((1+x)^n, n, 1)
(n1)(x+1)log(x+1)+x+1\renewcommand{\Bold}[1]{\mathbf{#1}}{\left(n - 1\right)} {\left(x + 1\right)} \log\left(x + 1\right) + x + 1
ex1 = taylor((1+x)^n, n, 1) - (1+n*x) ex1
2xlog(x+1)2x+2log(x+1)\renewcommand{\Bold}[1]{\mathbf{#1}}2 \, x \log\left(x + 1\right) - 2 \, x + 2 \, \log\left(x + 1\right)
ex1.subs({log(x+1) : x})
2x2\renewcommand{\Bold}[1]{\mathbf{#1}}2 \, x^{2}
simplify(taylor((1+x)^n, n, 2))
12x2log(x+1)2+x2log(x+1)+xlog(x+1)2+x2+2xlog(x+1)+12log(x+1)2+2x+log(x+1)+1\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, x^{2} \log\left(x + 1\right)^{2} + x^{2} \log\left(x + 1\right) + x \log\left(x + 1\right)^{2} + x^{2} + 2 \, x \log\left(x + 1\right) + \frac{1}{2} \, \log\left(x + 1\right)^{2} + 2 \, x + \log\left(x + 1\right) + 1
upper = taylor((1+x)^n, n, 1) simplify(upper - 1 + n*x)
(n - 1)*(x + 1)*log(x + 1) + n*x + x
n = 2 p0 = plot(lambda x : (1+x) ^ n, (x,-1,2) , color='green') p1 = plot(lambda x : f(x=x, n=n), (x, -1, 2)) p2 = plot(lambda x : 1+n*x, (x, -1, 2), color='red') show(p0 + p1 + p2)
Image in a Jupyter notebook
#%%python import sys print(sys.executable) print([1..10])
/ext/sage/sage-9.2/local/bin/python3 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var('x y') ex1 = 2*x+1 print(ex1) print(ex1.subs(x = 3)) print(ex1.subs(x = pi)) ex2 = ex1.subs(x = (x + y - 1) / 2) print(ex2)
2*x + 1 7 2*pi + 1 x + y
@interact def f(x=[1,3,4,5,4,2,3,1], y = (-10, 10, .1)): print(f"x={x:} y={y:}")

NEW: 3D Animations!

x, y = var('x, y') def build_frame(t): """Build a single frame of animation at time t.""" e = parametric_plot3d([sin(2*x - t), sin(x + t), x], (x, 0, 2*pi), color='red') b = parametric_plot3d([cos(x + t), -sin(x - t), x], (x, 0, 2*pi), color='green') return e + b frames = [build_frame(t) for t in (0, pi/32, pi/16, .., 2*pi)] animate(frames, delay=5).interactive(projection='orthographic')

eigenvalues with errors using Arb

from sage.matrix.benchmark import hilbert_matrix mat = hilbert_matrix(5).change_ring(CBF) mat.eigenvalues()
<ipython-input-5-175dab4ddc5a>:3: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See https://trac.sagemath.org/30393 for details. mat.eigenvalues()
[[1.56705069109823 +/- 8.92e-15] + [+/- 5.27e-15]*I, [0.2085342186110 +/- 2.01e-14] + [+/- 5.27e-15]*I, [3.28792877e-6 +/- 7.64e-15] + [+/- 5.27e-15]*I, [0.00030589804015 +/- 6.67e-15] + [+/- 5.27e-15]*I, [0.01140749162342 +/- 5.68e-15] + [+/- 5.27e-15]*I]

Polyomino tilings

from sage.combinat.tiling import Polyomino H = Polyomino([ (-1, 1), (-1, 4), (-1, 7), (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (2, 0), (2, 2), (2, 3), (2, 5), (2, 6), (2, 8)]) H.show2d()
Image in a Jupyter notebook
%time solution = H.self_surrounding(10, ncpus=2)
CPU times: user 1.35 s, sys: 248 ms, total: 1.6 s Wall time: 5.09 s
G = sum([p.show2d() for p in solution], Graphics()) G
Image in a Jupyter notebook

Manifolds: diff function for exterior derivatives

M = Manifold(2, 'M') X.<x,y> = M.chart() f = M.scalar_field(x^2*y, name='f') diff(f)
diff(f).display()
a = M.one_form(-2*x*y, x, name='a'); a.display() diff(a).display()
da = (2*x + 1) dx/\dy

Differential Weyl algebra

W.<x,y> = DifferentialWeylAlgebra(QQ) dx, dy = W.differentials() dx.diff(x^3)
3*x^2
(x*dx + dy + 1).diff(x^4*y^4 + 1)
5*x^4*y^4 + 4*x^4*y^3 + 1

Temperley-Lieb diagrams now have unicode

from sage.combinat.diagram_algebras import TL_diagram_ascii_art TL = [(-15,-12), (-14,-13), (-11,15), (-10,14), (-9,-6), (-8,-7), (-5,-4), (-3,1), (-2,-1), (2,3), (4,5), (6,11), (7, 8), (9,10), (12,13)] TL_diagram_ascii_art(TL, use_unicode=True)
⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ │ ╰─╯ ╰─╯ │ ╰─╯ ╰─╯ │ ╰─╯ │ │ │ ╰─────────╯ │ │ │ ╭───────╯ │ ╰───╮ │ ╭───────╯ │ ╭─────╮ │ │ ╭─────╮ ╭─╮ │ ╭─╮ │ ╭─╮ │ │ │ │ ╭─╮ │ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬ ⚬

some calculus

x = var('x') eq = 6*x^6 - 7*x^5 - 7*x^4 + 7*x^2 + 7*x - 6 sol = solve(eq, x) sol
[x == (2/3), x == -1, x == (3/2), x == 1]
show(sol)
[x=(23),x=(1),x=(32),x=1]\renewcommand{\Bold}[1]{\mathbf{#1}}\left[x = \left(\frac{2}{3}\right), x = \left(-1\right), x = \left(\frac{3}{2}\right), x = 1\right]
plot(eq, (x, -1.1, 1.6))
Image in a Jupyter notebook
eq = 6*x^6 - 7*x^5 - 7*x^4 + 7*x^2 + 7*x - 6 complex_plot(eq, (-1.5, 2.1), (-1.5, 1.5))
Image in a Jupyter notebook
sage: P = polytopes.cube(intervals='zero_one') # obtain others than the standard cube sage: P = matrix([[0,1,0],[0,1,1],[1,0,0]])*P # linear transformations sage: it = P.face_generator() # a (fast and efficient) face generator sage: next(it)
A 3-dimensional face of a Polyhedron in ZZ^3 defined as the convex hull of 8 vertices

Generator for cube-connected cycles

graphs.CubeConnectedCycle(3).plot()
Image in a Jupyter notebook

Manifolds

More functionalities in index notation for tensors

E.<x,y> = EuclideanSpace() v = E.vector_field(-y, x) t = E.tensor_field(0, 2, [[1, x], [-2*y, x^2]]) v['j']*(t['_ij'] + t['_ji']) == v.contract(2*t.symmetrize())
v
t
v['j'], t['_ij'], t['_ji']
t.symmetrize()
@interact def func(k = slider(0, 10, .1), j = (-10, 10), l = range_slider(-5, 5)): print("k: %s" % k) print("j: %s" % j) print("l: [%s, %s]" % l)
var('t y') plot_slope_field(y - t, (t,0,10), (y,0,6), plot_points=25)
G = cellular_automata.GraftalLace([2,0,3,3,6,0,2,7]) G
G.evolve(42) G.plot()
init = 200*[1] init[100] = 0 init[101] = 0 ECA = cellular_automata.Elementary(151, width=200, initial_state=init) ECA
ECA.evolve(200) ECA.plot()
print("Scatter plot and line") # http://www.packtpub.com/article/plotting-data-sage # python function def noisy_line(m, b, x): ret = m * x + b + 0.5 * (random() - 0.5) return ret slope = 1.0 intercept = -0.5 x_coords = [random() for t in range(50)] y_coords = [noisy_line(slope, intercept, x) for x in x_coords] sp = scatter_plot(list(zip(x_coords, y_coords))) sp += line([(0.0, intercept), (1.0, slope+intercept)], color='red') sp.show( figsize=[6,2])

Torus

from sage.plot.plot3d.shapes import Torus inner_radius = .3; outer_radius = 1 show(Torus(outer_radius, inner_radius, color='orange'), aspect_ratio=1, spin=3)