Package sage :: Package calculus :: Module calculus :: Class SymbolicArithmetic
[hide private]
[frames] | no frames]

Class SymbolicArithmetic

source code

                      object --+                        
                               |                        
structure.sage_object.SageObject --+                    
                                   |                    
           structure.element.Element --+                
                                       |                
         structure.element.ModuleElement --+            
                                           |            
               structure.element.RingElement --+        
                                               |        
                              SymbolicExpression --+    
                                                   |    
                                   SymbolicOperation --+
                                                       |
                                                      SymbolicArithmetic


Represents the result of an arithmetic operation on
$f$ and $g$.



Instance Methods [hide private]
 
__init__(self, operands, op) source code
 
__call__(self, *args, **kwargs)
Method for handling a function call.
source code
 
_recursive_sub(self, kwds)
EXAMPLES:...
source code
 
_recursive_sub_over_ring(self, kwds, ring) source code
 
_fast_float_(self, *vars)
EXAMPLES: ...
source code
 
_convert(self, typ)
Convert self to the given type by converting each of the operands to that type and doing the arithmetic.
source code
 
__float__(self)
TESTS:...
source code
 
__complex__(self)
EXAMPLES:...
source code
 
_mpfr_(self, field)
EXAMPLES:...
source code
 
_complex_mpfr_field_(self, field)
EXAMPLES:...
source code
 
_complex_double_(self, field)
EXAMPLES: sage: CDF((-1)^(1/3)) 0.5 + 0.866025403784*I Watch out -- right now Maxima algebraically simplifies the above to -1: sage: (-1)^(1/3) (-1)^(1/3) So when doing this conversion it is the non-simplified form that is converted, for efficiency purposes, which can result in a different answer in some cases.
source code
 
_real_double_(self, field)
EXAMPLES:...
source code
 
_real_rqdf_(self, field)
EXAMPLES:...
source code
 
_algebraic_(self, field)
Convert a symbolic expression to an algebraic number.
source code
 
_is_atomic(self)
File: sage/structure/element.pyx (starting at line 497) Return True if and only if parenthesis are not required when *printing* out any of $x - s$, $x + s$, $x^s$ and $x/s$.
source code
 
_repr_(self, simplify=True)
TESTS:...
source code
 
_latex_(self, simplify=True)
EXAMPLES:...
source code
 
_maxima_init_(self) source code
 
_sympy_(self)
Converts any expression to SymPy.
source code
 
_sys_init_(self, system) source code

Inherited from SymbolicOperation: number_of_arguments, variables

Inherited from SymbolicExpression: __abs__, __cmp__, __eq__, __ge__, __gt__, __hash__, __int__, __le__, __long__, __lt__, __ne__, __nonzero__, __pow__, __str__, _add_, _axiom_init_, _div_, _gap_init_, _gp_init_, _integer_, _kash_init_, _macaulay2_init_, _magma_init_, _maple_init_, _mathematica_init_, _maxima_, _mul_, _neg_, _octave_init_, _pari_init_, _polynomial_, _rational_, _richcmp_, _singular_init_, _sub_, arguments, coeff, coefficient, coefficients, coeffs, combine, conjugate, default_variable, denominator, derivative, diff, differentiate, display2d, exp_simplify, expand, expand_rational, expand_trig, factor, factor_list, find_maximum_on_interval, find_minimum_on_interval, find_root, full_simplify, function, gradient, hessian, imag, integral, integrate, inverse_laplace, laplace, limit, log_simplify, minpoly, n, nintegral, nintegrate, norm, numerator, numerical_approx, partial_fraction, plot, poly, polynomial, power_series, radical_simplify, rational_expand, rational_simplify, real, roots, show, simplify, simplify_exp, simplify_full, simplify_log, simplify_radical, simplify_rational, simplify_trig, solve, subs, subs_expr, substitute, substitute_over_ring, taylor, trig_expand, trig_simplify

Inherited from structure.element.RingElement: __div__, __idiv__, __imul__, __invert__, __mul__, __new__, __pos__, __rdiv__, __rmul__, __rpow__, __rtruediv__, __truediv__, _idiv_, _imul_, abs, additive_order, is_nilpotent, is_one, is_unit, multiplicative_order, order

Inherited from structure.element.ModuleElement: __add__, __iadd__, __isub__, __neg__, __radd__, __rsub__, __sub__, _iadd_, _ilmul_, _isub_, _lmul_, _rmul_

Inherited from structure.element.Element: __reduce__, __rxor__, __xor__, _cmp_, _im_gens_, base_base_extend, base_base_extend_canonical_sym, base_extend, base_extend_canonical, base_extend_canonical_sym, base_extend_recursive, base_ring, category, is_zero, parent

Inherited from structure.sage_object.SageObject: __repr__, _axiom_, _gap_, _gp_, _interface_, _interface_init_, _interface_is_cached_, _kash_, _macaulay2_, _magma_, _maple_, _mathematica_, _octave_, _pari_, _r_init_, _sage_, _singular_, db, dump, dumps, rename, reset_name, save, version

Inherited from object: __delattr__, __getattribute__, __reduce_ex__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, operands, op)
(Constructor)

source code 
Overrides: SymbolicOperation.__init__

__call__(self, *args, **kwargs)
(Call operator)

source code 

Method for handling a function call.

EXAMPLES:
    sage: x,y,z=var('x,y,z')
    
    sage: h = sin + cos
    sage: h(1)
    sin(1) + cos(1)
    sage: h(x)
    sin(x) + cos(x)
    sage: h = 3*sin
    sage: h(1)
    3*sin(1)
    sage: h(x)
    3*sin(x)

    sage: (sin+cos)(1)
    sin(1) + cos(1)
    sage: (sin+1)(1)
    sin(1) + 1
    sage: (x+sin)(5)
    sin(5) + 5
    sage: (y+sin)(5)
    sin(5) + 5
    sage: (x+y+sin)(5)
    y + sin(5) + 5


    sage: f = x + 2*y + 3*z
    sage: f(1)
    3*z + 2*y + 1
    sage: f(0,1)
    3*z + 2
    sage: f(0,0,1)
    3
    
    sage: (sqrt(2) + 17)(x+2)
    Traceback (most recent call last):
    ...
    ValueError: the number of arguments must be less than or equal to 0
    sage: (I*17+3*5)(x+2)
    Traceback (most recent call last):
    ...
    ValueError: the number of arguments must be less than or equal to 0

Overrides: SymbolicExpression.__call__

_recursive_sub(self, kwds)

source code 

EXAMPLES:
    sage: var('x, y, z, w')
    (x, y, z, w)
    sage: f = (x - x) + y^2 - z/z + (w^2-1)/(w+1); f
    y^2 + (w^2 - 1)/(w + 1) - 1
    sage: f(y=10)
    (w^2 - 1)/(w + 1) + 99
    sage: f(w=1,y=10)
    99
    sage: f(y=w,w=y)
    (y^2 - 1)/(y + 1) + w^2 - 1

    sage: f = y^5 - sqrt(2)
    sage: f(10)
    100000 - sqrt(2)

    sage: a = x^2; b = a(2); b
    4
    sage: type(b)
    <class 'sage.calculus.calculus.SymbolicConstant'>

Overrides: SymbolicExpression._recursive_sub

_recursive_sub_over_ring(self, kwds, ring)

source code 
Overrides: SymbolicExpression._recursive_sub_over_ring

_fast_float_(self, *vars)

source code 

EXAMPLES: 
    sage: x,y = var('x,y')
    sage: f = x*x-y
    sage: ff = f._fast_float_('x','y')
    sage: ff(2,3)
    1.0

Overrides: SymbolicExpression._fast_float_

_convert(self, typ)

source code 

Convert self to the given type by converting each of the
operands to that type and doing the arithmetic.

EXAMPLES:
    sage: f = sqrt(2) * cos(3); f
    sqrt(2)*cos(3)
    sage: f._convert(RDF)
    -1.40006081534
    sage: f._convert(float)
    -1.4000608153399503

Converting to an int can have surprising consequences, since
Python int is ``floor'' and one individual factor can floor to 0
but the product doesn't:
    sage: int(f)
    -1
    sage: f._convert(int)
    0
    sage: int(sqrt(2))
    1
    sage: int(cos(3))
    0

TESTS:
This illustrates how the conversion works even when a type
exception is raised, since here one operand is still x (in the
unsimplified form):
    sage: f = sin(0)*x
    sage: f._convert(CDF)
    0

__float__(self)

source code 

TESTS:
    sage: f=x*sin(0)
    sage: float(f(x=1))
    0.0
    sage: w = I - I
    sage: float(w)
    0.0

__complex__(self)

source code 

EXAMPLES:
    sage: complex((-2)^(1/4))
    (0.840896415253714...+0.840896415253714...j)

TESTS:
    sage: complex(I - I)
    0j
    sage: w = I-I; complex(w)
    0j
    sage: complex(w * x)
    0j

_mpfr_(self, field)

source code 

EXAMPLES:
    sage: RealField(200)(sqrt(2))
    1.4142135623730950488016887242096980785696718753769480731767

TESTS:
    sage: w = I-I; RR(w)
    0.000000000000000
    sage: w = I-I; RealField(200)(w)
    0.00000000000000000000000000000000000000000000000000000000000
    sage: RealField(200)(x*sin(0))
    0.00000000000000000000000000000000000000000000000000000000000

Overrides: SymbolicExpression._mpfr_

_complex_mpfr_field_(self, field)

source code 

EXAMPLES:
    sage: CC(sqrt(2))
    1.41421356237310
    sage: a = sqrt(-2); a
    sqrt(2)*I
    sage: CC(a)
    1.41421356237310*I
    sage: ComplexField(200)(a)
    1.4142135623730950488016887242096980785696718753769480731767*I
    sage: ComplexField(100)((-1)^(1/10))
    0.95105651629515357211643933338 + 0.30901699437494742410229341718*I

TESTS:
    sage: CC(x*sin(0))
    0

Overrides: SymbolicExpression._complex_mpfr_field_

_complex_double_(self, field)

source code 

EXAMPLES:
    sage: CDF((-1)^(1/3))
    0.5 + 0.866025403784*I

Watch out -- right now Maxima algebraically simplifies the above to -1:
    sage: (-1)^(1/3)
    (-1)^(1/3)

So when doing this conversion it is the non-simplified form
that is converted, for efficiency purposes, which can result
in a different answer in some cases.  You can always force
using the simplified form:

    sage: a = (-1)^(1/3)
    sage: CDF(a.simplify())
    0.5 + 0.866025403784*I

TESTS:
    sage: CDF(x*sin(0))
    0        

Overrides: SymbolicExpression._complex_double_

_real_double_(self, field)

source code 

EXAMPLES:
    sage: RDF(sqrt(2))
    1.41421356237


TESTS:
    sage: RDF(x*sin(0))
    0.0

Overrides: SymbolicExpression._real_double_

_real_rqdf_(self, field)

source code 

EXAMPLES:
    sage: RQDF(sqrt(2))
    1.414213562373095048801688724209698078569671875376948073176679738

TESTS:
    sage: RQDF(x*sin(0))
    0.000000000000000000000000000000000000000000000000000000000000000

Overrides: SymbolicExpression._real_rqdf_

_algebraic_(self, field)

source code 

Convert a symbolic expression to an algebraic number.

EXAMPLES:
    sage: QQbar(sqrt(2) + sqrt(8))
    [4.2426406871192847 .. 4.2426406871192857]
    sage: AA(sqrt(2) ^ 4) == 4
    True
    sage: AA(-golden_ratio)
    [-1.6180339887498950 .. -1.6180339887498946]
    sage: QQbar((2*I)^(1/2))
    [1.0000000000000000 .. 1.0000000000000000] + [1.0000000000000000 .. 1.0000000000000000]*I

TESTS:
    sage: AA(x*sin(0))
    0
    sage: QQbar(x*sin(0))
    0

_is_atomic(self)

source code 
File: sage/structure/element.pyx (starting at line 497)

Return True if and only if parenthesis are not required when
*printing* out any of $x - s$, $x + s$, $x^s$ and $x/s$.

EXAMPLES:
    sage: n = 5; n._is_atomic()
    True
    sage: n = x+1; n._is_atomic()
    False

Overrides: structure.element.Element._is_atomic
(inherited documentation)

_repr_(self, simplify=True)

source code 

TESTS:
    sage: var('r')
    r
    sage: a = (1-1/r)^(-1); a
    1/(1 - 1/r)
    sage: a.derivative(r)
    -1/((1 - 1/r)^2*r^2)

    sage: var('a,b')
    (a, b)
    sage: s = 0*(1/a) + -b*(1/a)*(1 + -1*0*(1/a))*(1/(a*b + -1*b*(1/a)))
    sage: s
    -b/(a*(a*b - b/a))
    sage: s(a=2,b=3)
    -1/3
    sage: -3/(2*(2*3-(3/2)))
    -1/3
    sage: (-1)^(1/4)
    (-1)^(1/4)

    sage: (-(x-1)/2)._latex_(simplify=False)
    '\frac{-\left( x - 1 \right)}{2}'

Overrides: structure.element.Element._repr_

_latex_(self, simplify=True)

source code 

EXAMPLES:
    sage: var('x,y')
    (x, y)
    sage: f=(x+y)*(x-y)*(x^2-2)*(y^2-3)
    sage: latex(f)
    {{{\left( {x}^{2}  - 2 
ight) \left( x - y 
ight)} \left( y + x 
ight)} \left( {y}^{2}  - 3 
ight)}
    sage: latex(cos*(x+1))
    {\left( x + 1 
ight) \cos}

_maxima_init_(self)

source code 
Overrides: SymbolicExpression._maxima_init_

_sys_init_(self, system)

source code 
Overrides: SymbolicExpression._sys_init_