| Home | Trees | Indices | Help |
|---|
|
|
object --+
|
structure.sage_object.SageObject --+
|
SymbolicEquation
A symbolic equation, which consists of a left hand side, an operator and a right hand side. EXAMPLES:
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from Inherited from |
|||
|
|||
|
Inherited from |
|||
|
|||
Create a symbolic expression.
Internally a symbolic expression is simply a left side
(\code{self._left}), operator (\code{self._op}), and a right
hand side (\code{self._right}), where the left and right hand
sides are symbolic expressions and the operator is a Python
equation or inequality operator, e.g., \code{operator.le}.
EXAMPLES:
One should not call the SymbolicEquation constructor directly,
since it does no type checking. However, we illustrate how to
do so below.
Bad illustrative usage:
sage: eqn = sage.calculus.equations.SymbolicEquation(-x, x^2 + 1, operator.gt); eqn
-x > x^2 + 1
Really bad usage!
sage: eqn.__init__(x, 2*x+pi, operator.lt)
sage: eqn # cripes!
x < 2*x + pi
|
Substitute both sides of this equation
This is very slow currently since we piggy-back off of the
symbolic matrix functionality.
EXAMPLES:
sage: var('theta')
theta
sage: eqn = (x^3 + theta < sin(x*theta))
sage: eqn(x = 5)
theta + 125 < sin(5*theta)
sage: eqn(theta=x, x=0)
x < 0
sage: var('y')
y
sage: eqn = x^3 < sin(y)
sage: eqn(2)
8 < sin(y)
sage: eqn(2,3)
8 < sin(3)
sage: eqn = x^3 < 2
sage: eqn(2)
8 < 2
|
Return the ith part of this equation:
OUTPUT:
self[0] -- left hand side
self[1] -- operator
self[2] -- right hand side
EXAMPLES:
sage: eqn = x^2 + sin(x) < cos(x^2)
sage: eqn[0]
sin(x) + x^2
sage: eqn[1]
<built-in function lt>
sage: eqn[2]
cos(x^2)
sage: eqn[-1]
cos(x^2)
|
INPUT:
scalar -- number
op -- operation to perform
checksign -- (default: True) boolean; if True and op is
multiply or divides, switch direction of
inequality of x is negative; otherwise
direction will not switch.
EXAMPLES:
sage: var('x y')
(x, y)
sage: f = x + 3 < y - 2
sage: f*-1
-x - 3 > 2 - y
sage: f._scalar(-1, operator.mul, checksign=True)
-x - 3 > 2 - y
sage: f._scalar(-1, operator.mul, checksign=False)
-x - 3 < 2 - y
sage: f * 5
5*(x + 3) < 5*(y - 2)
sage: f - 3
x < y - 5
sage: f + 2
x + 5 < y
|
Multiply both sides of this inequality by $x$.
EXAMPLES:
sage: var('x,y'); f = x + 3 < y - 2
(x, y)
sage: f.multiply_both_sides(7)
7*(x + 3) < 7*(y - 2)
sage: f.multiply_both_sides(-1/2)
(-x - 3)/2 > (2 - y)/2
sage: f*(-2/3)
-2*(x + 3)/3 > -2*(y - 2)/3
sage: f*(-pi)
-1*pi*(x + 3) > -1*pi*(y - 2)
sage: f*(1+I)
Traceback (most recent call last):
...
ValueError: unable to multiply or divide both sides of an inequality by a number whose sign can't be determined.
Multiplying by complex numbers works only if it's an equality:
sage: f = sqrt(2) + x == y^3
sage: f.multiply_both_sides(I)
I*(x + sqrt(2)) == I*y^3
sage: f.multiply_both_sides(-1)
-x - sqrt(2) == -y^3
Some further examples:
sage: (x^3 + 1 > 2*sqrt(3)) * (-1)
-x^3 - 1 < -2*sqrt(3)
sage: (x^3 + 1 >= 2*sqrt(3)) * (-1)
-x^3 - 1 <= -2*sqrt(3)
sage: (x^3 + 1 <= 2*sqrt(3)) * (-1)
-x^3 - 1 >= -2*sqrt(3)
|
Divide both sides of the inequality by $x$.
INPUT:
x -- number
checksign -- (default: True) boolean; if True, switch direction of
inequality of x is negative; otherwise direction
will not switch.
EXAMPLES:
sage: var('theta')
theta
sage: eqn = (x^3 + theta < sin(x*theta))
sage: eqn.divide_both_sides(theta, checksign=False)
(x^3 + theta)/theta < sin(theta*x)/theta
sage: assume(theta > 0)
sage: eqn.divide_both_sides(theta)
(x^3 + theta)/theta < sin(theta*x)/theta
sage: eqn/theta
(x^3 + theta)/theta < sin(theta*x)/theta
sage: forget(theta > 0)
sage: eqn.divide_both_sides(theta)
Traceback (most recent call last):
...
ValueError: unable to multiply or divide both sides of an inequality by a number whose sign can't be determined.
As a shorthand you can just use the divides notation:
sage: (x^3 + 1 > x^2 - 1) / (-1)
-x^3 - 1 < 1 - x^2
The quantity $x^2 - 1$ could be either negative or positive depending on $x$, so
dividing by it is not defined.
sage: (x^3 + 1 > x^2 - 1) / (x^2 - 1)
Traceback (most recent call last):
...
ValueError: unable to multiply or divide both sides of an inequality by a number whose sign can't be determined.
If we specify that $x^2 - 1> 0$, then dividing is defined.
sage: assume(x^2 - 1 > 0)
sage: (x^3 + 1 > x^2 - 1) / (x^2 - 1)
(x^3 + 1)/(x^2 - 1) > 1
sage: forget()
We can also specify that $x^2 - 1 < 0$. Note that now the inequality direction changes.
sage: assume(x^2 - 1 < 0)
sage: (x^3 + 1 > x^2 - 1) / (x^2 - 1)
(x^3 + 1)/(x^2 - 1) < 1
sage: forget()
|
Add $x$ to both sides of this symbolic equation.
EXAMPLES:
sage: var('x y z')
(x, y, z)
sage: eqn = x^2 + y^2 + z^2 <= 1
sage: eqn.add_to_both_sides(-z^2)
y^2 + x^2 <= 1 - z^2
sage: eqn.add_to_both_sides(I)
z^2 + y^2 + x^2 + I <= I + 1
|
Subtract $x$ from both sides of this symbolic equation.
EXAMPLES:
sage: eqn = x*sin(x)*sqrt(3) + sqrt(2) > cos(sin(x))
sage: eqn.subtract_from_both_sides(sqrt(2))
sqrt(3)*x*sin(x) > cos(sin(x)) - sqrt(2)
sage: eqn.subtract_from_both_sides(cos(sin(x)))
-cos(sin(x)) + sqrt(3)*x*sin(x) + sqrt(2) > 0
|
This function is called internally to implement arithmetic
operations on symbolic expressions.
INPUT:
self -- a symbolic equation
right -- a symbolic equation
op -- an operation, e.g., operator.add
EXAMPLES:
We create two symbolic equations and add them:
sage: e1 = x^3 + x < sin(2*x)
sage: e2 = x^2 - x < cos(x)
sage: e1._arith(e2, operator.add)
x^3 + x^2 < sin(2*x) + cos(x)
We try to multiply them, which doesn't really make sense:
sage: e1._arith(e2, operator.mul)
Traceback (most recent call last):
...
ValueError: cannot multiply or divide inequalities.
We can multiply equalities though:
sage: e1 = x^3 + x == sin(2*x)
sage: e2 = x^2 - x == cos(x)
sage: f = e1._arith(e2, operator.mul); f
(x^2 - x)*(x^3 + x) == cos(x)*sin(2*x)
By the way, we can expand the above product by calling the
\code{expand} method:
sage: f.expand()
x^5 - x^4 + x^3 - x^2 == cos(x)*sin(2*x)
|
Add two symbolic equations.
EXAMPLES:
sage: var('a,b')
(a, b)
sage: m = 144 == -10 * a + b
sage: n = 136 == 10 * a + b
sage: m + n
280 == 2*b
|
Add two symbolic equations.
EXAMPLES:
sage: var('a,b')
(a, b)
sage: m = 144 == -10 * a + b
sage: n = 136 == 10 * a + b
sage: int(-144) + m
0 == b - 10*a - 144
|
Subtract two symbolic equations.
EXAMPLES:
sage: var('a,b')
(a, b)
sage: m = 144 == 20 * a + b
sage: n = 136 == 10 * a + b
sage: m - n
8 == 10*a
|
Subtract two symbolic equations.
EXAMPLES:
sage: var('a,b')
(a, b)
sage: m = 144 == -10 * a + b
sage: n = 136 == 10 * a + b
sage: int(144) - m
0 == b - 10*a - 144
|
Multiply two symbolic equations.
EXAMPLES:
sage: m = x == 5*x + 1
sage: n = sin(x) == sin(x+2*pi)
sage: m * n
x*sin(x) == (5*x + 1)*sin(x)
|
Multiply two symbolic equations.
sage: m = 2*x == 3*x^2 - 5
sage: int(-1) * m
-2*x == 5 - 3*x^2
|
Divide two symbolic equations.
EXAMPLES:
sage: m = x == 5*x + 1
sage: n = sin(x) == sin(x+2*pi)
sage: m / n
x/sin(x) == (5*x + 1)/sin(x)
sage: m = x != 5*x + 1
sage: n = sin(x) != sin(x+2*pi)
sage: m / n
x/sin(x) != (5*x + 1)/sin(x)
|
Return version of this symbolic expression but in the given
Maxima session.
EXAMPLES:
sage: e1 = x^3 + x == sin(2*x)
sage: z = e1._maxima_()
sage: z.parent() is sage.calculus.calculus.maxima
True
sage: z = e1._maxima_(maxima)
sage: z.parent() is maxima
True
sage: z = maxima(e1)
sage: z.parent() is maxima
True
|
Do the given symbolic substitution to both sides of the equation. The
notation is the same for substitute on a symbolic expression.
EXAMPLES:
sage: var('a')
a
sage: e = (x^3 + a == sin(x/a)); e
x^3 + a == sin(x/a)
sage: e.substitute(x=5*x)
125*x^3 + a == sin(5*x/a)
sage: e.substitute(a=1)
x^3 + 1 == sin(x)
sage: e.substitute(a=x)
x^3 + x == sin(1)
sage: e.substitute(a=x, x=1)
x + 1 == sin(1/x)
sage: e.substitute({a:x, x:1})
x + 1 == sin(1/x)
|
Do the given symbolic substitution to both sides of the equation. The
notation is the same for substitute on a symbolic expression.
EXAMPLES:
sage: var('a')
a
sage: e = (x^3 + a == sin(x/a)); e
x^3 + a == sin(x/a)
sage: e.substitute(x=5*x)
125*x^3 + a == sin(5*x/a)
sage: e.substitute(a=1)
x^3 + 1 == sin(x)
sage: e.substitute(a=x)
x^3 + x == sin(1)
sage: e.substitute(a=x, x=1)
x + 1 == sin(1/x)
sage: e.substitute({a:x, x:1})
x + 1 == sin(1/x)
|
EXAMPLES:
sage: (x>0) == (x>0)
True
sage: (x>0) == (x>1)
False
sage: (x>0) != (x>1)
True
|
Return non-ASCII art string representation of this
symbolic equation. This is called implicitly when
displaying an equation (without using print).
EXAMPLES:
We create an inequality $f$ and called the \code{_repr_}
method on it, and note that this produces the same
string as just displaying $f$:
sage: f = x^3 + 1/3*x - sqrt(2) <= sin(x)
sage: f._repr_()
'x^3 + x/3 - sqrt(2) <= sin(x)'
sage: f
x^3 + x/3 - sqrt(2) <= sin(x)
When using print the \code{__str__} method is called instead,
which results in ASCII art:
sage: print f
3 x
x + - - sqrt(2) <= sin(x)
3
|
Return the variables appearing in this symbolic equation.
OUTPUT:
tuple -- tuple of the variables in this equation (the
result of calling this is cached).
EXAMPLES:
sage: var('x,y,z,w')
(x, y, z, w)
sage: f = (x+y+w) == (x^2 - y^2 - z^3); f
y + x + w == -z^3 - y^2 + x^2
sage: f.variables()
(w, x, y, z)
|
Return the operator in this equation.
EXAMPLES:
sage: eqn = x^3 + 2/3 >= x - pi
sage: eqn.operator()
<built-in function ge>
sage: (x^3 + 2/3 < x - pi).operator()
<built-in function lt>
sage: (x^3 + 2/3 == x - pi).operator()
<built-in function eq>
|
Return the left hand side of this equation.
EXAMPLES:
sage: eqn = x^3 + 2/3 >= x - pi
sage: eqn.lhs()
x^3 + 2/3
sage: eqn.left()
x^3 + 2/3
sage: eqn.left_hand_side()
x^3 + 2/3
SYNONYMS: \code{lhs}, \code{left_hand_side}
|
Return the left hand side of this equation.
EXAMPLES:
sage: eqn = x^3 + 2/3 >= x - pi
sage: eqn.lhs()
x^3 + 2/3
sage: eqn.left()
x^3 + 2/3
sage: eqn.left_hand_side()
x^3 + 2/3
SYNONYMS: \code{lhs}, \code{left_hand_side}
|
Return the left hand side of this equation.
EXAMPLES:
sage: eqn = x^3 + 2/3 >= x - pi
sage: eqn.lhs()
x^3 + 2/3
sage: eqn.left()
x^3 + 2/3
sage: eqn.left_hand_side()
x^3 + 2/3
SYNONYMS: \code{lhs}, \code{left_hand_side}
|
Return the right hand side of this equation.
EXAMPLES:
sage: (x + sqrt(2) >= sqrt(3) + 5/2).right()
sqrt(3) + 5/2
sage: (x + sqrt(2) >= sqrt(3) + 5/2).rhs()
sqrt(3) + 5/2
sage: (x + sqrt(2) >= sqrt(3) + 5/2).right_hand_side()
sqrt(3) + 5/2
SYNONYMS: \code{rhs}, \code{right_hand_side}
|
Return the right hand side of this equation.
EXAMPLES:
sage: (x + sqrt(2) >= sqrt(3) + 5/2).right()
sqrt(3) + 5/2
sage: (x + sqrt(2) >= sqrt(3) + 5/2).rhs()
sqrt(3) + 5/2
sage: (x + sqrt(2) >= sqrt(3) + 5/2).right_hand_side()
sqrt(3) + 5/2
SYNONYMS: \code{rhs}, \code{right_hand_side}
|
Return the right hand side of this equation.
EXAMPLES:
sage: (x + sqrt(2) >= sqrt(3) + 5/2).right()
sqrt(3) + 5/2
sage: (x + sqrt(2) >= sqrt(3) + 5/2).rhs()
sqrt(3) + 5/2
sage: (x + sqrt(2) >= sqrt(3) + 5/2).right_hand_side()
sqrt(3) + 5/2
SYNONYMS: \code{rhs}, \code{right_hand_side}
|
Return the string representation of this equation, in 2-d ASCII art.
OUTPUT:
string
EXAMPLES:
sage: f = (x^2 - x == 0)
sage: f
x^2 - x == 0
sage: print f
2
x - x == 0
Here we call \code{__str__} explicitly:
sage: (x > 2/3).__str__()
' 2\r\n x > -\r\n 3'
|
Return latex representation of this symbolic equation.
This is obtained by calling the \code{_latex_} method
on both the left and right hand sides, and typesetting
the operator symbol correctly.
OUTPUT:
string -- a string
EXAMPLES:
The output is a strig with backslashes, so prints funny:
sage: (x^(3/5) >= pi)._latex_()
'{x}^{\\frac{3}{5}} \\geq \\pi'
Call the latex method to get an object that prints more nicely:
sage: latex(x^(3/5) >= pi)
{x}^{\frac{3}{5}} \geq \pi
|
Return True if this (in)equality is definitely true. Return False
if it is false or the algorithm for testing (in)equality is
inconclusive.
EXAMPLES:
sage: k = var('k')
sage: pol = 1/(k-1) - 1/k -1/k/(k-1);
sage: bool(pol == 0)
True
sage: f = sin(x)^2 + cos(x)^2 - 1
sage: bool(f == 0)
True
sage: bool( x == x )
True
sage: bool( x != x )
False
sage: bool( x > x )
False
sage: bool( x^2 > x )
False
sage: bool( x + 2 > x )
True
sage: bool( x - 2 > x )
False
|
Return string representation for this symbolic equation
in a form suitable for evaluation in Maxima.
EXAMPLES:
sage: (x^(3/5) >= pi^2 + e^i)._maxima_init_()
'((x) ^ (3/5)) >= (((%pi) ^ (2)) + ((%e) ^ (%i)))'
sage: (x == 0)._maxima_init_(assume=True)
'equal(x, 0)'
sage: (x != 0)._maxima_init_(assume=True)
'notequal(x, 0)'
|
Assume that this equation holds. This is relevant for
symbolic integration, among other things.
EXAMPLES:
We call the assume method to assume that $x>2$:
sage: (x > 2).assume()
Bool returns True below if the inequality is \emph{definitely}
known to be True.
sage: bool(x > 0)
True
sage: bool(x < 0)
False
This may or may not be True, so bool returns False:
sage: bool(x > 3)
False
TESTS:
sage: v,c = var('v,c')
sage: assume(c != 0)
sage: integral((1+v^2/c^2)^3/(1-v^2/c^2)^(3/2),v)
-75*sqrt(c^2)*arcsin(sqrt(c^2)*v/c^2)/8 - v^5/(4*c^4*sqrt(1 - v^2/c^2)) - 17*v^3/(8*c^2*sqrt(1 - v^2/c^2)) + 83*v/(8*sqrt(1 - v^2/c^2))
|
If this is a symbolic equality with an equals sign \code{==}
find numerically a single root of this equation in a given
interval. Otherwise raise a \code{ValueError}. See the
documentation for the global \code{find_root} method for more
about the options to this function.
Note that this symbolic expression must involve at most one
variable.
EXAMPLES:
sage: (x == sin(x)).find_root(-2,2)
0.0
sage: (x^5 + 3*x + 2 == 0).find_root(-2,2)
-0.63283452024215225
sage: (cos(x) == sin(x)).find_root(10,20)
19.634954084936208
We illustrate some valid error conditions:
sage: (cos(x) != sin(x)).find_root(10,20)
Traceback (most recent call last):
...
ValueError: Symbolic equation must be an equality.
sage: (SR(3)==SR(2)).find_root(-1,1)
Traceback (most recent call last):
...
RuntimeError: no zero in the interval, since constant expression is not 0.
There must be at most one variable:
sage: x, y = var('x,y')
sage: (x == y).find_root(-2,2)
Traceback (most recent call last):
...
NotImplementedError: root finding currently only implemented in 1 dimension.
|
Forget the given constraint.
EXAMPLES:
sage: var('x,y')
(x, y)
sage: forget()
sage: assume(x>0, y < 2)
sage: assumptions()
[x > 0, y < 2]
sage: forget(y < 2)
sage: assumptions()
[x > 0]
|
Symbolically solve for the given variable.
WARNING: In many cases, only one solution is computed.
INPUT:
x -- a SymbolicVariable object (if not given, the first in
the expression is used)
multiplicities -- (default: False) if True, also returns
the multiplicities of each solution, in order.
solution_dict -- (default: False) if True, return the
solution as a dictionary rather than an equation.
explicit_solution -- (default: False); if True, require
that all solutions returned be explicit (rather than
implicit) OUTPUT: A list of SymbolicEquations with the
variable to solve for on the left hand side.
EXAMPLES:
sage: S = solve(x^3 - 1 == 0, x)
sage: S
[x == (sqrt(3)*I - 1)/2, x == (-sqrt(3)*I - 1)/2, x == 1]
sage: S[0]
x == (sqrt(3)*I - 1)/2
sage: S[0].right()
(sqrt(3)*I - 1)/2
sage: S = solve(x^3 - 1 == 0, x, solution_dict=True)
sage: S
[{x: (sqrt(3)*I - 1)/2}, {x: (-sqrt(3)*I - 1)/2}, {x: 1}]
We illustrate finding multiplicities of solutions:
sage: f = (x-1)^5*(x^2+1)
sage: solve(f == 0, x)
[x == -1*I, x == I, x == 1]
sage: solve(f == 0, x, multiplicities=True)
([x == -1*I, x == I, x == 1], [1, 1, 5])
|
Expands one or both sides of the equation.
If side is not specified, then both sides of the equation
are expanded by calling \code{expand()} on the corresponding
\class{SymbolicExpression}.
If side is `left' (or `right'), then only the left (or right)
side of the equation is expanded.
EXAMPLES:
sage: a = (16*x-13)/6 == (3*x+5)/2 - (4-x)/3
sage: a.expand()
8*x/3 - 13/6 == 11*x/6 + 7/6
sage: a.expand('left')
8*x/3 - 13/6 == (3*x + 5)/2 - (4 - x)/3
sage: a.expand('right')
(16*x - 13)/6 == 11*x/6 + 7/6
|
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0beta1 on Thu Jul 17 04:23:31 2008 | http://epydoc.sourceforge.net |