︠50718857-b826-4e73-b645-e3c27a221fa1︠ 12+13

25

120+4940

5060

#yes solve(2^x == 5, x)

[x == log(5)/log(2)]

f = sqrt(x) == x bool(f(x=1)) bool(f(x=0))

True
True

solve(sin(x)==0,x)

[x == 0]

solve?

File: /usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/symbolic/relation.py Signature : solve(*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). 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 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, due to the underlying algorithm in Maxima: 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 If "f" is only one equation or expression, we use the solve method for symbolic expressions, which defaults to exact answers only: sage: solve([y^6==y],y) [y == e^(2/5*I*pi), y == e^(4/5*I*pi), y == e^(-4/5*I*pi), y == e^(-2/5*I*pi), 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 for a single expression to be solved: 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] Note: For more details about solving a single equation, see the documentation for the single-expression "solve()". 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 a real free variable (because of the "r"): sage: solve([x+y == 3, 2*x+2*y == 6],x,y) [[x == -r1 + 3, y == r1]] Especially with trigonometric functions, the dummy variable may be implicitly an integer (hence the "z"): sage: solve([cos(x)*sin(x) == 1/2, x+y == 0],x,y) [[x == 1/4*pi + pi*z79, y == -1/4*pi - pi*z79]] 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)]] Inequalities can be also solved: sage: solve(x^2>8,x) [[x < -2*sqrt(2)], [x > 2*sqrt(2)]] We use "use_grobner" in Maxima if no solution is obtained from Maxima's "to_poly_solve": sage: x,y=var('x y'); c1(x,y)=(x-5)^2+y^2-16; 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(11)*sqrt(5) + 123/68], [x == 9/68*sqrt(55) + 135/68, y == 15/68*sqrt(11)*sqrt(5) + 123/68]] TESTS: sage: solve([sin(x)==x,y^2==x],x,y) [sin(x) == x, y^2 == x] sage: solve(0==1,x) Traceback (most recent call last): ... TypeError: The first argument must be a symbolic expression or a list of symbolic expressions. Test if the empty list is returned, too, when (a list of) dictionaries (is) are requested (#8553): sage: solve([SR(0)==1],x) [] sage: solve([SR(0)==1],x,solution_dict=True) [] sage: solve([x==1,x==-1],x) [] sage: solve([x==1,x==-1],x,solution_dict=True) [] sage: solve((x==1,x==-1),x,solution_dict=0) [] Relaxed form, suggested by Mike Hansen (#8553): sage: solve([x^2-1],x,solution_dict=-1) [{x: -1}, {x: 1}] sage: solve([x^2-1],x,solution_dict=1) [{x: -1}, {x: 1}] sage: solve((x==1,x==-1),x,solution_dict=-1) [] sage: solve((x==1,x==-1),x,solution_dict=1) [] This inequality holds for any real "x" (trac #8078): sage: solve(x^4+2>0,x) [x < +Infinity] Test for user friendly input handling http://trac.sagemath.org/13645: sage: poly.<a,b> = PolynomialRing(RR) sage: solve([a+b+a*b == 1], a) Traceback (most recent call last): ... TypeError: The first argument to solve() should be a symbolic expression or a list of symbolic expressions, cannot handle <type 'bool'> sage: solve([a, b], (1, a)) Traceback (most recent call last): ... TypeError: 1 is not a valid variable. sage: solve([x == 1], (1, a)) Traceback (most recent call last): ... TypeError: (1, a) are not valid variables. Test that the original version of a system in the French Sage book now works (http://trac.sagemath.org/14306): sage: var('y,z') (y, z) sage: solve([x^2 * y * z == 18, x * y^3 * z == 24, x * y * z^4 == 6], x, y, z) [[x == 3, y == 2, z == 1], [x == (1.337215067... - 2.685489874...*I), y == (-1.700434271... + 1.052864325...*I), z == (0.9324722294... - 0.3612416661...*I)], ...]

maxima.solve?

File: /usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/interfaces/maxima.py Signature : maxima.solve(*args, **kwds) Docstring : -- Function: solve (<expr>, <x>) -- Function: solve (<expr>) -- Function: solve ([<eqn_1>, ..., <eqn_n>], [<x_1>, ..., <x_n>]) Solves the algebraic equation <expr> for the variable <x> and returns a list of solution equations in <x>. If <expr> is not an equation, the equation >>`<<<expr> = 0' is assumed in its place. <x> may be a function (e.g. >>`<<f(x)'), or other non-atomic expression except a sum or product. <x> may be omitted if <expr> contains only one variable. <expr> may be a rational expression, and may contain trigonometric functions, exponentials, etc. The following method is used: Let <E> be the expression and <X> be the variable. If <E> is linear in <X> then it is trivially solved for <X>. Otherwise if <E> is of the form >>`<<A*X^N + B' then the result is >>`<<(-B/A)^1/N)' times the >>`<<N''th roots of unity. If <E> is not linear in <X> then the gcd of the exponents of <X> in <E> (say <N>) is divided into the exponents and the multiplicity of the roots is multiplied by <N>. Then >>`<<solve' is called again on the result. If <E> factors then >>`<<solve' is called on each of the factors. Finally >>`<<solve' will use the quadratic, cubic, or quartic formulas where necessary. In the case where <E> is a polynomial in some function of the variable to be solved for, say >>`<<F(X)', then it is first solved for >>`<<F(X)' (call the result <C>), then the equation >>`<<F(X)=C' can be solved for <X> provided the inverse of the function <F> is known. >>`<<breakup' if >>`<<false' will cause >>`<<solve' to express the solutions of cubic or quartic equations as single expressions rather than as made up of several common subexpressions which is the default. >>`<<multiplicities' - will be set to a list of the multiplicities of the individual solutions returned by >>`<<solve', >>`<<realroots', or >>`<<allroots'. Try >>`<<apropos (solve)' for the switches which affect >>`<<solve'. >>`<<describe' may then by used on the individual switch names if their purpose is not clear. >>`<<solve ([<eqn_1>, ..., <eqn_n>], [<x_1>, ..., <x_n>])' solves a system of simultaneous (linear or non-linear) polynomial equations by calling >>`<<linsolve' or >>`<<algsys' and returns a list of the solution lists in the variables. In the case of >>`<<linsolve' this list would contain a single list of solutions. It takes two lists as arguments. The first list represents the equations to be solved; the second list is a list of the unknowns to be determined. If the total number of variables in the equations is equal to the number of equations, the second argument-list may be omitted. When >>`<<programmode' is >>`<<false', >>`<<solve' displays solutions with intermediate expression (>>`<<%t') labels, and returns the list of labels. When >>`<<globalsolve' is >>`<<true' and the problem is to solve two or more linear equations, each solved-for variable is bound to its value in the solution of the equations. Examples: (%i1) solve (asin (cos (3*x))*(f(x) - 1), x); solve: using arc-trig functions to get a solution. Some solutions will be lost. %pi (%o1) [x = ---, f(x) = 1] 6 (%i2) ev (solve (5^f(x) = 125, f(x)), solveradcan); log(125) (%o2) [f(x) = --------] log(5) (%i3) [4*x^2 - y^2 = 12, x*y - x = 2]; 2 2 (%o3) [4 x - y = 12, x y - x = 2] (%i4) solve (%, [x, y]); (%o4) [[x = 2, y = 2], [x = .5202594388652008 %i * .1331240357358706, y = .07678378523787788 * 3.608003221870287 %i], [x = - .5202594388652008 %i * .1331240357358706, y = 3.608003221870287 %i * .07678378523787788], [x = - 1.733751846381093, y = - .1535675710019696]] (%i5) solve (1 + a*x + x^3, x); 3 sqrt(3) %i 1 sqrt(4 a + 27) 1 1/3 (%o5) [x = (- ---------- - -) (--------------- - -) 2 2 6 sqrt(3) 2 sqrt(3) %i 1 (---------- - -) a 2 2 * --------------------------, x = 3 sqrt(4 a + 27) 1 1/3 3 (--------------- - -) 6 sqrt(3) 2 3 sqrt(3) %i 1 sqrt(4 a + 27) 1 1/3 (---------- - -) (--------------- - -) 2 2 6 sqrt(3) 2 sqrt(3) %i 1 (- ---------- - -) a 2 2 * --------------------------, x = 3 sqrt(4 a + 27) 1 1/3 3 (--------------- - -) 6 sqrt(3) 2 3 sqrt(4 a + 27) 1 1/3 a (--------------- - -) - --------------------------] 6 sqrt(3) 2 3 sqrt(4 a + 27) 1 1/3 3 (--------------- - -) 6 sqrt(3) 2 (%i6) solve (x^3 - 1); sqrt(3) %i - 1 sqrt(3) %i + 1 (%o6) [x = --------------, x = - --------------, x = 1] 2 2 (%i7) solve (x^6 - 1); sqrt(3) %i + 1 sqrt(3) %i - 1 (%o7) [x = --------------, x = --------------, x = - 1, 2 2 sqrt(3) %i + 1 sqrt(3) %i - 1 x = - --------------, x = - --------------, x = 1] 2 2 (%i8) ev (x^6 - 1, %[1]); 6 (sqrt(3) %i + 1) (%o8) ----------------- - 1 64 (%i9) expand (%); (%o9) 0 (%i10) x^2 - 1; 2 (%o10) x - 1 (%i11) solve (%, x); (%o11) [x = - 1, x = 1] (%i12) ev (%th(2), %[1]); (%o12) 0 The symbols >>`<<%r' are used to denote arbitrary constants in a solution. (%i1) solve([x+y=1,2*x+2*y=2],[x,y]); solve: dependent equations eliminated: (2) (%o1) [[x = 1 - %r1, y = %r1]] See >>`<<algsys' and >>`<<%rnum_list' for more information. There are also some inexact matches for >>`<<solve'. Try >>`<<?? solve' to see them. true