Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

M2142 - zápisník pro první přednášku

Project: M2142
Views: 426
Image: ubuntu2204
%typeset_mode True
Komentář.
1+1
2
fctor(x^2-9)
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python3.11/site-packages/smc_sagews/sage_server.py", line 1244, in execute exec( File "", line 1, in <module> NameError: name 'fctor' is not defined
plot(x * sin(x), (x, -2, 10))
plot(x^3, (x,-3,3))
%html <h1>Komentar</h1>

Komentar

1+1
2\displaystyle 2
%typeset_mode True
1+1 #Příkaz provedeme klávesou Enter, odřádkování kombinací kláves Shift+Enter, nutno nastavit "Sage Worksheet evaluate key" na Enter
2\displaystyle 2
Komentář.
help(factor)
Help on function factor in module sage.arith.misc: factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds) Return the factorization of ``n``. The result depends on the type of ``n``. If ``n`` is an integer, returns the factorization as an object of type :class:`Factorization`. If ``n`` is not an integer, ``n.factor(proof=proof, **kwds)`` gets called. See ``n.factor??`` for more documentation in this case. .. warning:: This means that applying :func:`factor` to an integer result of a symbolic computation will not factor the integer, because it is considered as an element of a larger symbolic ring. EXAMPLES:: sage: f(n) = n^2 # needs sage.symbolic sage: is_prime(f(3)) # needs sage.symbolic False sage: factor(f(3)) # needs sage.symbolic 9 INPUT: - ``n`` -- a nonzero integer - ``proof`` -- bool or ``None`` (default: ``None``) - ``int_`` -- bool (default: ``False``) whether to return answers as Python ints - ``algorithm`` -- string - ``'pari'`` -- (default) use the PARI c library - ``'kash'`` -- use KASH computer algebra system (requires that kash be installed) - ``'magma'`` -- use Magma (requires magma be installed) - ``verbose`` -- integer (default: 0); PARI's debug variable is set to this; e.g., set to 4 or 8 to see lots of output during factorization. OUTPUT: - factorization of `n` The qsieve and ecm commands give access to highly optimized implementations of algorithms for doing certain integer factorization problems. These implementations are not used by the generic :func:`factor` command, which currently just calls PARI (note that PARI also implements sieve and ecm algorithms, but they are not as optimized). Thus you might consider using them instead for certain numbers. The factorization returned is an element of the class :class:`~sage.structure.factorization.Factorization`; use ``Factorization??`` to see more details, and examples below for usage. A :class:`~sage.structure.factorization.Factorization` contains both the unit factor (`+1` or `-1`) and a sorted list of ``(prime, exponent)`` pairs. The factorization displays in pretty-print format but it is easy to obtain access to the ``(prime, exponent)`` pairs and the unit, to recover the number from its factorization, and even to multiply two factorizations. See examples below. EXAMPLES:: sage: factor(500) 2^2 * 5^3 sage: factor(-20) -1 * 2^2 * 5 sage: f=factor(-20) sage: list(f) [(2, 2), (5, 1)] sage: f.unit() -1 sage: f.value() -20 sage: factor(-next_prime(10^2) * next_prime(10^7)) # needs sage.libs.pari -1 * 101 * 10000019 :: sage: factor(293292629867846432923017396246429, algorithm='flint') # needs sage.libs.flint 3 * 4852301647696687 * 20148007492971089 :: sage: factor(-500, algorithm='kash') -1 * 2^2 * 5^3 :: sage: factor(-500, algorithm='magma') # optional - magma -1 * 2^2 * 5^3 :: sage: factor(0) Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined sage: factor(1) 1 sage: factor(-1) -1 sage: factor(2^(2^7) + 1) # needs sage.libs.pari 59649589127497217 * 5704689200685129054721 Sage calls PARI's :pari:`factor`, which has ``proof=False`` by default. Sage has a global proof flag, set to ``True`` by default (see :mod:`sage.structure.proof.proof`, or use ``proof.[tab]``). To override the default, call this function with ``proof=False``. :: sage: factor(3^89 - 1, proof=False) # needs sage.libs.pari 2 * 179 * 1611479891519807 * 5042939439565996049162197 :: sage: factor(2^197 + 1) # long time (2s) # needs sage.libs.pari 3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843 Any object which has a factor method can be factored like this:: sage: K.<i> = QuadraticField(-1) # needs sage.rings.number_field sage: factor(122 - 454*i) # needs sage.rings.number_field (-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4) To access the data in a factorization:: sage: # needs sage.libs.pari sage: f = factor(420); f 2^2 * 3 * 5 * 7 sage: [x for x in f] [(2, 2), (3, 1), (5, 1), (7, 1)] sage: [p for p,e in f] [2, 3, 5, 7] sage: [e for p,e in f] [2, 1, 1, 1] sage: [p^e for p,e in f] [4, 3, 5, 7] We can factor Python, numpy and gmpy2 numbers:: sage: factor(math.pi) 3.141592653589793 sage: import numpy # needs numpy sage: factor(numpy.int8(30)) # needs numpy sage.libs.pari 2 * 3 * 5 sage: import gmpy2 sage: factor(gmpy2.mpz(30)) 2 * 3 * 5 TESTS:: sage: factor(Mod(4, 100)) Traceback (most recent call last): ... TypeError: unable to factor 4 sage: factor("xyz") Traceback (most recent call last): ... TypeError: unable to factor 'xyz' Test that :issue:`35219` is fixed:: sage: len(factor(2^2203-1,proof=false)) 1
%latex \textbf{Komentář}.
1+1;2+2 #Více příkazů na jednom řádku oddělujeme středníkem (;)
2 4
var('y')
y\displaystyle y
((3*x^2+5*x*y-2*y^2)*(x-y)^3)^2
(3x2+5xy2y2)2(xy)6\displaystyle {\left(3 \, x^{2} + 5 \, x y - 2 \, y^{2}\right)}^{2} {\left(x - y\right)}^{6}
expand(_)
9x1024x9y32x8y2+172x7y3146x6y4188x5y5+484x4y6428x3y7+193x2y844xy9+4y10\displaystyle 9 \, x^{10} - 24 \, x^{9} y - 32 \, x^{8} y^{2} + 172 \, x^{7} y^{3} - 146 \, x^{6} y^{4} - 188 \, x^{5} y^{5} + 484 \, x^{4} y^{6} - 428 \, x^{3} y^{7} + 193 \, x^{2} y^{8} - 44 \, x y^{9} + 4 \, y^{10}
factor(_)
(3xy)2(x+2y)2(xy)6\displaystyle {\left(3 \, x - y\right)}^{2} {\left(x + 2 \, y\right)}^{2} {\left(x - y\right)}^{6}
((x^2-1)/(3*x^3-11*x^2+13*x-5)).partial_fraction()
43x51x1\displaystyle \frac{4}{3 \, x - 5} - \frac{1}{x - 1}
integrate(x^2*sin(x),x)
(x22)cos(x)+2xsin(x)\displaystyle -{\left(x^{2} - 2\right)} \cos\left(x\right) + 2 \, x \sin\left(x\right)
Komentář
%latex Komentář v \TeX{}u
plot(x * sin(x), (x, -2, 10))
plot(sin(x), (x,-pi,pi))
32*12^4
663552\displaystyle 663552
factorial(20)-factorial(12)
2432902007697638400\displaystyle 2432902007697638400
factor(_) #_ je odkaz na předcházející výstup
2103552711341976119\displaystyle 2^{10} \cdot 3^{5} \cdot 5^{2} \cdot 7 \cdot 11^{3} \cdot 41976119
expand(_)
2432902007697638400\displaystyle 2432902007697638400
%typeset_mode True (2^30/3^20)*sqrt(2) #Sage pracuje v přesné aritmetice.
107374182434867844012\displaystyle \frac{1073741824}{3486784401} \, \sqrt{2}
n(_) #Aproximaci získáme příkazem n().
0.435501618497698\displaystyle 0.435501618497698
var('i') #Narozdíl od Maplu a Maximy je třeba proměnné (kromě proměnné x) předem deklarovat.
i\displaystyle i
sum((1+i)/(1+i^4), i,1,20)
2753108915513951266418473494479966526667515770634998143458420014321653762264974190884124027285387789492160976952723410943046016049\displaystyle \frac{27531089155139512664184734944799665266675157706349981434584200143}{21653762264974190884124027285387789492160976952723410943046016049}
n(_,digits=30)
1.27142289724276359903349287003\displaystyle 1.27142289724276359903349287003
Aproximace π\pi.
n(pi)
3.14159265358979\displaystyle 3.14159265358979
pi.n() #Druhý způsob zadání.
3.14159265358979\displaystyle 3.14159265358979
pi.n(digits=30)
3.14159265358979323846264338328\displaystyle 3.14159265358979323846264338328
((3+5*I)*(7+4*I)); #Komplexní jednotku zadáváme pomocí I.
47i+1\displaystyle 47 i + 1
%typeset_mode True
var('y')
y\displaystyle y
(x+y)^3*(x-y)^2;
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
expand(_)
x5+x4y2x3y22x2y3+xy4+y5\displaystyle x^{5} + x^{4} y - 2 \, x^{3} y^{2} - 2 \, x^{2} y^{3} + x y^{4} + y^{5}
factor(_)
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
_.show() #Pomocí show formátujeme výstup v LaTeXu.
(x+y)3(xy)2\displaystyle {\left(x + y\right)}^{3} {\left(x - y\right)}^{2}
(x^2-9).partial_fraction()
x29\displaystyle x^{2} - 9
abs?
File: Docstring : Return the absolute value of the argument.
help(integrate)
Help on function integral in module sage.misc.functional: integral(x, *args, **kwds) Return an indefinite or definite integral of an object ``x``. First call ``x.integral()`` and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm. For symbolic expression calls :func:`sage.calculus.calculus.integral` - see this function for available options. EXAMPLES:: sage: f = cyclotomic_polynomial(10) sage: integral(f) 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x :: sage: integral(sin(x), x) # needs sage.symbolic -cos(x) :: sage: y = var('y') # needs sage.symbolic sage: integral(sin(x), y) # needs sage.symbolic y*sin(x) :: sage: integral(sin(x), x, 0, pi/2) # needs sage.symbolic 1 sage: sin(x).integral(x, 0, pi/2) # needs sage.symbolic 1 sage: integral(exp(-x), (x, 1, oo)) # needs sage.symbolic e^(-1) Numerical approximation:: sage: h = integral(tan(x)/x, (x, 1, pi/3)) # needs sage.symbolic ... sage: h # needs sage.symbolic integrate(tan(x)/x, x, 1, 1/3*pi) sage: h.n() # needs sage.symbolic 0.07571599101... Specific algorithm can be used for integration:: sage: integral(sin(x)^2, x, algorithm='maxima') # needs sage.symbolic 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') # needs sage.symbolic -1/2*cos(x)*sin(x) + 1/2*x TESTS: A symbolic integral from :trac:`11445` that was incorrect in earlier versions of Maxima:: sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) # needs sage.symbolic sage: integrate(f, (x, -Infinity, Infinity)) # needs sage.symbolic 2 Another symbolic integral, from :trac:`11238`, that used to return zero incorrectly; with Maxima 5.26.0 one gets ``1/2*sqrt(pi)*e^(1/4)``, whereas with 5.29.1, and even more so with 5.33.0, the expression is less pleasant, but still has the same value. Unfortunately, the computation takes a very long time with the default settings, so we temporarily use the Maxima setting ``domain: real``:: sage: # needs sage.symbolic sage: sage.calculus.calculus.maxima('domain: real') real sage: f = exp(-x) * sinh(sqrt(x)) sage: t = integrate(f, x, 0, Infinity); t # long time 1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4) - 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4) + 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4) sage: t.canonicalize_radical() # long time 1/2*sqrt(pi)*e^(1/4) sage: sage.calculus.calculus.maxima('domain: complex') complex An integral which used to return -1 before maxima 5.28. See :trac:`12842`:: sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) # needs sage.symbolic sage: integrate(f, x, 0, infinity) # needs sage.symbolic 1 This integral would cause a stack overflow in earlier versions of Maxima, crashing sage. See :trac:`12377`. We don't care about the result here, just that the computation completes successfully:: sage: y = (x^2)*exp(x) / (1 + exp(x))^2 # needs sage.symbolic sage: _ = integrate(y, x, -1000, 1000) # needs sage.symbolic When SymPy cannot solve an integral it gives it back, so we must be able to convert SymPy's ``Integral`` (:trac:`14723`):: sage: # needs sage.symbolic sage: x, y, z = var('x,y,z') sage: f = function('f') sage: integrate(f(x), x, algorithm='sympy') integrate(f(x), x) sage: integrate(f(x), x, 0, 1, algorithm='sympy') integrate(f(x), x, 0, 1) sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'), ....: y, algorithm='sympy'), ....: z, algorithm='sympy') integrate(integrate(integrate(f(x, y, z), x), y), z) sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x) sage: _ = var('a,b,x') sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b) sage: # needs sympy sage: import sympy sage: x, y, z = sympy.symbols('x y z') sage: f = sympy.Function('f') sage: SR(sympy.Integral(f(x,y,z), x, y, z)) # needs sage.symbolic integrate(integrate(integrate(f(x, y, z), x), y), z) Ensure that the following integral containing a signum term from :trac:`11590` can be integrated:: sage: x = SR.symbol('x', domain='real') # needs sage.symbolic sage: result = integrate(x * sgn(x^2 - 1/4), x, -1, 0) # needs sage.symbolic ... sage: result # needs sage.symbolic -1/4
integrate?
File: /ext/sage/sage-9.2/local/lib/python3.8/site-packages/sage/misc/functional.py Signature : integrate(x, *args, **kwds) Docstring : Return an indefinite or definite integral of an object "x". First call "x.integral()" and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm. For symbolic expression calls "sage.calculus.calculus.integral()" - see this function for available options. EXAMPLES: sage: f = cyclotomic_polynomial(10) sage: integral(f) 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x sage: integral(sin(x),x) -cos(x) sage: y = var('y') sage: integral(sin(x),y) y*sin(x) sage: integral(sin(x), x, 0, pi/2) 1 sage: sin(x).integral(x, 0,pi/2) 1 sage: integral(exp(-x), (x, 1, oo)) e^(-1) Numerical approximation: sage: h = integral(tan(x)/x, (x, 1, pi/3)); h integrate(tan(x)/x, x, 1, 1/3*pi) sage: h.n() 0.07571599101... Specific algorithm can be used for integration: sage: integral(sin(x)^2, x, algorithm='maxima') 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') -1/2*cos(x)*sin(x) + 1/2*x
integrate??
File: /ext/sage/10.2/src/sage/misc/functional.py Source: def integral(x, *args, **kwds): """ Return an indefinite or definite integral of an object ``x``. First call ``x.integral()`` and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm. For symbolic expression calls :func:`sage.calculus.calculus.integral` - see this function for available options. EXAMPLES:: sage: f = cyclotomic_polynomial(10) sage: integral(f) 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x :: sage: integral(sin(x), x) # needs sage.symbolic -cos(x) :: sage: y = var('y') # needs sage.symbolic sage: integral(sin(x), y) # needs sage.symbolic y*sin(x) :: sage: integral(sin(x), x, 0, pi/2) # needs sage.symbolic 1 sage: sin(x).integral(x, 0, pi/2) # needs sage.symbolic 1 sage: integral(exp(-x), (x, 1, oo)) # needs sage.symbolic e^(-1) Numerical approximation:: sage: h = integral(tan(x)/x, (x, 1, pi/3)) # needs sage.symbolic ... sage: h # needs sage.symbolic integrate(tan(x)/x, x, 1, 1/3*pi) sage: h.n() # needs sage.symbolic 0.07571599101... Specific algorithm can be used for integration:: sage: integral(sin(x)^2, x, algorithm='maxima') # needs sage.symbolic 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') # needs sage.symbolic -1/2*cos(x)*sin(x) + 1/2*x TESTS: A symbolic integral from :trac:`11445` that was incorrect in earlier versions of Maxima:: sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) # needs sage.symbolic sage: integrate(f, (x, -Infinity, Infinity)) # needs sage.symbolic 2 Another symbolic integral, from :trac:`11238`, that used to return zero incorrectly; with Maxima 5.26.0 one gets ``1/2*sqrt(pi)*e^(1/4)``, whereas with 5.29.1, and even more so with 5.33.0, the expression is less pleasant, but still has the same value. Unfortunately, the computation takes a very long time with the default settings, so we temporarily use the Maxima setting ``domain: real``:: sage: # needs sage.symbolic sage: sage.calculus.calculus.maxima('domain: real') real sage: f = exp(-x) * sinh(sqrt(x)) sage: t = integrate(f, x, 0, Infinity); t # long time 1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4) - 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4) + 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4) sage: t.canonicalize_radical() # long time 1/2*sqrt(pi)*e^(1/4) sage: sage.calculus.calculus.maxima('domain: complex') complex An integral which used to return -1 before maxima 5.28. See :trac:`12842`:: sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) # needs sage.symbolic sage: integrate(f, x, 0, infinity) # needs sage.symbolic 1 This integral would cause a stack overflow in earlier versions of Maxima, crashing sage. See :trac:`12377`. We don't care about the result here, just that the computation completes successfully:: sage: y = (x^2)*exp(x) / (1 + exp(x))^2 # needs sage.symbolic sage: _ = integrate(y, x, -1000, 1000) # needs sage.symbolic When SymPy cannot solve an integral it gives it back, so we must be able to convert SymPy's ``Integral`` (:trac:`14723`):: sage: # needs sage.symbolic sage: x, y, z = var('x,y,z') sage: f = function('f') sage: integrate(f(x), x, algorithm='sympy') integrate(f(x), x) sage: integrate(f(x), x, 0, 1, algorithm='sympy') integrate(f(x), x, 0, 1) sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'), ....: y, algorithm='sympy'), ....: z, algorithm='sympy') integrate(integrate(integrate(f(x, y, z), x), y), z) sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x) sage: _ = var('a,b,x') sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy') -integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b) sage: # needs sympy sage: import sympy sage: x, y, z = sympy.symbols('x y z') sage: f = sympy.Function('f') sage: SR(sympy.Integral(f(x,y,z), x, y, z)) # needs sage.symbolic integrate(integrate(integrate(f(x, y, z), x), y), z) Ensure that the following integral containing a signum term from :trac:`11590` can be integrated:: sage: x = SR.symbol('x', domain='real') # needs sage.symbolic sage: result = integrate(x * sgn(x^2 - 1/4), x, -1, 0) # needs sage.symbolic ... sage: result # needs sage.symbolic -1/4 """ if hasattr(x, 'integral'): return x.integral(*args, **kwds) else: from sage.symbolic.ring import SR return SR(x).integral(*args, **kwds)

Doplňování jmen

Začněte psát příkaz a stiskněte Klávesu Tab
%var x, theta
%typeset_mode True
diff(1 + x + x^2, x)
2x+1\displaystyle 2 \, x + 1
(1+x+x^2).diff()
2x+1\displaystyle 2 \, x + 1
matrix(3, 3, [1,pi,3, e,5,6, 1,2,3]).
6π3(π2)e12\displaystyle 6 \, \pi - 3 \, {\left(\pi - 2\right)} e - 12
%var x, theta
plot(x * sin(x), (x, -2, 10))
%var x, theta, y
solve(cos(y-x), y, to_poly_solve=True)
[y == 1/2*pi + x]
solve?
File: /ext/sage/9.7/src/sage/symbolic/relation.py Signature : solve(f, *args, **kwds) Docstring : Algebraically solve an equation or system of equations (over the complex numbers) for given variables. Inequalities and systems of inequalities are also supported. INPUT: * "f" - equation or system of equations (given by a list or tuple) * "*args" - variables to solve for. * "solution_dict" - bool (default: False); if True or non-zero, return a list of dictionaries containing the solutions. If there are no solutions, return an empty list (rather than a list containing an empty dictionary). Likewise, if there's only a single solution, return a list containing one dictionary with that solution. There are a few optional keywords if you are trying to solve a single equation. They may only be used in that context. * "multiplicities" - bool (default: False); if True, return corresponding multiplicities. This keyword is incompatible with "to_poly_solve=True" and does not make any sense when solving inequalities. * "explicit_solutions" - bool (default: False); require that all roots be explicit rather than implicit. Not used when solving inequalities. * "to_poly_solve" - bool (default: False) or string; use Maxima's "to_poly_solver" package to search for more possible solutions, but possibly encounter approximate solutions. This keyword is incompatible with "multiplicities=True" and is not used when solving inequalities. Setting "to_poly_solve" to 'force' (string) omits Maxima's solve command (useful when some solutions of trigonometric equations are lost). * "algorithm" - string (default: 'maxima'); to use SymPy's solvers set this to 'sympy'. Note that SymPy is always used for diophantine equations. Another choice is 'giac'. * "domain" - string (default: 'complex'); setting this to 'real' changes the way SymPy solves single equations; inequalities are always solved in the real domain. EXAMPLES: sage: x, y = var('x, y') sage: solve([x+y==6, x-y==4], x, y) [[x == 5, y == 1]] sage: solve([x^2+y^2 == 1, y^2 == x^3 + x + 1], x, y) [[x == -1/2*I*sqrt(3) - 1/2, y == -sqrt(-1/2*I*sqrt(3) + 3/2)], [x == -1/2*I*sqrt(3) - 1/2, y == sqrt(-1/2*I*sqrt(3) + 3/2)], [x == 1/2*I*sqrt(3) - 1/2, y == -sqrt(1/2*I*sqrt(3) + 3/2)], [x == 1/2*I*sqrt(3) - 1/2, y == sqrt(1/2*I*sqrt(3) + 3/2)], [x == 0, y == -1], [x == 0, y == 1]] sage: solve([sqrt(x) + sqrt(y) == 5, x + y == 10], x, y) [[x == -5/2*I*sqrt(5) + 5, y == 5/2*I*sqrt(5) + 5], [x == 5/2*I*sqrt(5) + 5, y == -5/2*I*sqrt(5) + 5]] sage: solutions = solve([x^2+y^2 == 1, y^2 == x^3 + x + 1], x, y, solution_dict=True) sage: for solution in solutions: print("{} , {}".format(solution[x].n(digits=3), solution[y].n(digits=3))) -0.500 - 0.866*I , -1.27 + 0.341*I -0.500 - 0.866*I , 1.27 - 0.341*I -0.500 + 0.866*I , -1.27 - 0.341*I -0.500 + 0.866*I , 1.27 + 0.341*I 0.000 , -1.00 0.000 , 1.00 Whenever possible, answers will be symbolic, but with systems of equations, at times approximations will be given by Maxima, due to the underlying algorithm: sage: sols = solve([x^3==y,y^2==x], [x,y]); sols[-1], sols[0] ([x == 0, y == 0], [x == (0.3090169943749475 + 0.9510565162951535*I), y == (-0.8090169943749475 - 0.5877852522924731*I)]) sage: sols[0][0].rhs().pyobject().parent() Complex Double Field sage: solve([y^6==y],y) [y == 1/4*sqrt(5) + 1/4*I*sqrt(2*sqrt(5) + 10) - 1/4, y == -1/4*sqrt(5) + 1/4*I*sqrt(-2*sqrt(5) + 10) - 1/4, y == -1/4*sqrt(5) - 1/4*I*sqrt(-2*sqrt(5) + 10) - 1/4, y == 1/4*sqrt(5) - 1/4*I*sqrt(2*sqrt(5) + 10) - 1/4, y == 1, y == 0] sage: solve( [y^6 == y], y)==solve( y^6 == y, y) True Here we demonstrate very basic use of the optional keywords: sage: ((x^2-1)^2).solve(x) [x == -1, x == 1] sage: ((x^2-1)^2).solve(x,multiplicities=True) ([x == -1, x == 1], [2, 2]) sage: solve(sin(x)==x,x) [x == sin(x)] sage: solve(sin(x)==x,x,explicit_solutions=True) [] sage: solve(abs(1-abs(1-x)) == 10, x) [abs(abs(x - 1) - 1) == 10] sage: solve(abs(1-abs(1-x)) == 10, x, to_poly_solve=True) [x == -10, x == 12] sage: from sage.symbolic.expression import Expression sage: Expression.solve(x^2==1,x) [x == -1, x == 1] We must solve with respect to actual variables: sage: z = 5 sage: solve([8*z + y == 3, -z +7*y == 0],y,z) Traceback (most recent call last): ... TypeError: 5 is not a valid variable. If we ask for dictionaries containing the solutions, we get them: sage: solve([x^2-1],x,solution_dict=True) [{x: -1}, {x: 1}] sage: solve([x^2-4*x+4],x,solution_dict=True) [{x: 2}] sage: res = solve([x^2 == y, y == 4],x,y,solution_dict=True) sage: for soln in res: print("x: %s, y: %s" % (soln[x], soln[y])) x: 2, y: 4 x: -2, y: 4 If there is a parameter in the answer, that will show up as a new variable. In the following example, "r1" is an arbitrary constant (because of the "r"): sage: forget() sage: x, y = var('x,y') sage: solve([x+y == 3, 2*x+2*y == 6],x,y) [[x == -r1 + 3, y == r1]] sage: var('b, c') (b, c) sage: solve((b-1)*(c-1), [b,c]) [[b == 1, c == r...], [b == r..., c == 1]] Especially with trigonometric functions, the dummy variable may be implicitly an integer (hence the "z"): sage: solve( sin(x)==cos(x), x, to_poly_solve=True) [x == 1/4*pi + pi*z...] sage: solve([cos(x)*sin(x) == 1/2, x+y == 0],x,y) [[x == 1/4*pi + pi*z..., y == -1/4*pi - pi*z...]] Expressions which are not equations are assumed to be set equal to zero, as with x in the following example: sage: solve([x, y == 2],x,y) [[x == 0, y == 2]] If "True" appears in the list of equations it is ignored, and if "False" appears in the list then no solutions are returned. E.g., note that the first "3==3" evaluates to "True", not to a symbolic equation. sage: solve([3==3, 1.00000000000000*x^3 == 0], x) [x == 0] sage: solve([1.00000000000000*x^3 == 0], x) [x == 0] Here, the first equation evaluates to "False", so there are no solutions: sage: solve([1==3, 1.00000000000000*x^3 == 0], x) [] Completely symbolic solutions are supported: sage: var('s,j,b,m,g') (s, j, b, m, g) sage: sys = [ m*(1-s) - b*s*j, b*s*j-g*j ] sage: solve(sys,s,j) [[s == 1, j == 0], [s == g/b, j == (b - g)*m/(b*g)]] sage: solve(sys,(s,j)) [[s == 1, j == 0], [s == g/b, j == (b - g)*m/(b*g)]] sage: solve(sys,[s,j]) [[s == 1, j == 0], [s == g/b, j == (b - g)*m/(b*g)]] sage: z = var('z') sage: solve((x-z)^2==2, x) [x == z - sqrt(2), x == z + sqrt(2)] Inequalities can be also solved: sage: solve(x^2>8,x) [[x < -2*sqrt(2)], [x > 2*sqrt(2)]] sage: x,y = var('x,y'); (ln(x)-ln(y)>0).solve(x) [[log(x) - log(y) > 0]] sage: x,y = var('x,y'); (ln(x)>ln(y)).solve(x) # random [[0 < y, y < x, 0 < x]] [[y < x, 0 < y]] A simple example to show the use of the keyword "multiplicities": sage: ((x^2-1)^2).solve(x) [x == -1, x == 1] sage: ((x^2-1)^2).solve(x,multiplicities=True) ([x == -1, x == 1], [2, 2]) sage: ((x^2-1)^2).solve(x,multiplicities=True,to_poly_solve=True) Traceback (most recent call last): ... NotImplementedError: to_poly_solve does not return multiplicities Here is how the "explicit_solutions" keyword functions: sage: solve(sin(x)==x,x) [x == sin(x)] sage: solve(sin(x)==x,x,explicit_solutions=True) [] sage: solve(x*sin(x)==x^2,x) [x == 0, x == sin(x)] sage: solve(x*sin(x)==x^2,x,explicit_solutions=True) [x == 0] The following examples show the use of the keyword "to_poly_solve": sage: solve(abs(1-abs(1-x)) == 10, x) [abs(abs(x - 1) - 1) == 10] sage: solve(abs(1-abs(1-x)) == 10, x, to_poly_solve=True) [x == -10, x == 12] sage: var('Q') Q sage: solve(Q*sqrt(Q^2 + 2) - 1, Q) [Q == 1/sqrt(Q^2 + 2)] The following example is a regression in Maxima 5.39.0. It used to be possible to get one more solution here, namely "1/sqrt(sqrt(2) + 1)", see https://sourceforge.net/p/maxima/bugs/3276/: sage: solve(Q*sqrt(Q^2 + 2) - 1, Q, to_poly_solve=True) [Q == -sqrt(-sqrt(2) - 1), Q == sqrt(sqrt(2) + 1)*(sqrt(2) - 1)] An effort is made to only return solutions that satisfy the current assumptions: sage: solve(x^2==4, x) [x == -2, x == 2] sage: assume(x<0) sage: solve(x^2==4, x) [x == -2] sage: solve((x^2-4)^2 == 0, x, multiplicities=True) ([x == -2], [2]) sage: solve(x^2==2, x) [x == -sqrt(2)] sage: z = var('z') sage: solve(x^2==2-z, x) [x == -sqrt(-z + 2)] sage: assume(x, 'rational') sage: solve(x^2 == 2, x) [] In some cases it may be worthwhile to directly use "to_poly_solve" if one suspects some answers are being missed: sage: forget() sage: solve(cos(x)==0, x) [x == 1/2*pi] sage: solve(cos(x)==0, x, to_poly_solve=True) [x == 1/2*pi] sage: solve(cos(x)==0, x, to_poly_solve='force') [x == 1/2*pi + pi*z...] The same may also apply if a returned unsolved expression has a denominator, but the original one did not: sage: solve(cos(x) * sin(x) == 1/2, x, to_poly_solve=True) [sin(x) == 1/2/cos(x)] sage: solve(cos(x) * sin(x) == 1/2, x, to_poly_solve=True, explicit_solutions=True) [x == 1/4*pi + pi*z...] sage: solve(cos(x) * sin(x) == 1/2, x, to_poly_solve='force') [x == 1/4*pi + pi*z...] We use "use_grobner" in Maxima if no solution is obtained from Maxima's "to_poly_solve": sage: x,y = var('x y') sage: c1(x,y) = (x-5)^2+y^2-16 sage: c2(x,y) = (y-3)^2+x^2-9 sage: solve([c1(x,y),c2(x,y)],[x,y]) [[x == -9/68*sqrt(55) + 135/68, y == -15/68*sqrt(55) + 123/68], [x == 9/68*sqrt(55) + 135/68, y == 15/68*sqrt(55) + 123/68]] We use SymPy for Diophantine equations, see "Expression.solve_diophantine": sage: assume(x, 'integer') sage: assume(z, 'integer') sage: solve((x-z)^2==2, x) [] sage: forget() The following shows some more of SymPy's capabilities that cannot be handled by Maxima: sage: _ = var('t') sage: r = solve([x^2 - y^2/exp(x), y-1], x, y, algorithm='sympy') sage: (r[0][x], r[0][y]) (2*lambert_w(-1/2), 1) sage: solve(-2*x**3 + 4*x**2 - 2*x + 6 > 0, x, algorithm='sympy') [x < 1/3*(1/2)^(1/3)*(9*sqrt(77) + 79)^(1/3) + 2/3*(1/2)^(2/3)/(9*sqrt(77) + 79)^(1/3) + 2/3] sage: solve(sqrt(2*x^2 - 7) - (3 - x),x,algorithm='sympy') [x == -8, x == 2] sage: solve(sqrt(2*x + 9) - sqrt(x + 1) - sqrt(x + 4),x,algorithm='sympy') [x == 0] sage: r = solve([x + y + z + t, -z - t], x, y, z, t, algorithm='sympy') sage: (r[0][x], r[0][z]) (-y, -t) sage: r = solve([x^2+y+z, y+x^2+z, x+y+z^2], x, y,z, algorithm='sympy') sage: (r[0][x], r[0][y]) (z, -(z + 1)*z) sage: (r[1][x], r[1][y]) (-z + 1, -z^2 + z - 1) sage: solve(abs(x + 3) - 2*abs(x - 3),x,algorithm='sympy',domain='real') [x == 1, x == 9] We cannot translate all results from SymPy but we can at least print them: sage: solve(sinh(x) - 2*cosh(x),x,algorithm='sympy') [ImageSet(Lambda(_n, I*(2*_n*pi + pi/2) + log(sqrt(3))), Integers), ImageSet(Lambda(_n, I*(2*_n*pi - pi/2) + log(sqrt(3))), Integers)] sage: solve(2*sin(x) - 2*sin(2*x), x,algorithm='sympy') [ImageSet(Lambda(_n, 2*_n*pi), Integers), ImageSet(Lambda(_n, 2*_n*pi + pi), Integers), ImageSet(Lambda(_n, 2*_n*pi + 5*pi/3), Integers), ImageSet(Lambda(_n, 2*_n*pi + pi/3), Integers)] sage: solve(x^5 + 3*x^3 + 7, x, algorithm='sympy')[0] # known bug complex_root_of(x^5 + 3*x^3 + 7, 0) A basic interface to Giac is provided: sage: solve([(2/3)^x-2], [x], algorithm='giac') ... [[-log(2)/(log(3) - log(2))]] sage: f = (sin(x) - 8*cos(x)*sin(x))*(sin(x)^2 + cos(x)) - (2*cos(x)*sin(x) - sin(x))*(-2*sin(x)^2 + 2*cos(x)^2 - cos(x)) sage: solve(f, x, algorithm='giac') ... [-2*arctan(sqrt(2)), 0, 2*arctan(sqrt(2)), pi] sage: x, y = SR.var('x,y') sage: solve([x+y-4,x*y-3],[x,y],algorithm='giac') [[1, 3], [3, 1]]