mathmaker  0.4(alpha)
Public Member Functions | Public Attributes | Properties
core.base_calculus.Sum Class Reference

Has Exponented terms & an exponent. More...

Inheritance diagram for core.base_calculus.Sum:
core.base_calculus.CommutativeOperation core.base_calculus.Operation core.root_calculus.Exponented core.root_calculus.Signed core.root_calculus.Calculable core.root_calculus.Evaluable core.base.Printable core.base.NamedObject core.base.Clonable core.base_calculus.Polynomial

List of all members.

Public Member Functions

def __init__
 Constructor.
def get_minus_signs_nb
 Returns the number of negative factors of the Sum (i.e.
def get_numeric_terms
 Returns a raw list of the numeric terms of the Sum.
def get_literal_terms
 Returns a raw list of the literal terms of the Sum.
def get_terms_lexicon
 Creates a dict.
def get_force_inner_brackets_display
 Gets the value of the force_inner_brackets_display field.
def set_term
 Sets the n-th term to the given arg.
def set_force_inner_brackets_display
 Sets a value to the force_inner_brackets_display field.
def into_str
 Creates a string of the given object in the given ML.
def calculate_next_step
 Returns the next calculated step of a *numeric* Sum.
def expand_and_reduce_next_step
 Returns the next step of expansion/reduction of the Sum So, either the Sum of its expanded/reduced terms, or the Sum itself reduced, or None.
def __cmp__
 Compares two Sums Returns 0 if all terms are the same in the same order and if the exponents are also the same /!\ a + b will be different from de b + a It's not a mathematical comparison, but a "displayable"'s one.
def operator
 Defines the performed CommutativeOperation as a Sum.
def next_displayable_term_nb
 Returns the rank of next non-equivalent to 0 term...
def multiply_symbol_is_required
 True if the usual writing rules require a × between two factors.
def requires_brackets
 True if the argument requires brackets in a product For instance, a Sum with several terms or a negative Item.
def requires_inner_brackets
 True if the argument requires inner brackets The reason for requiring them is having an exponent different from 1 and several terms or factors (in the case of Products & Sums)
def numeric_terms_require_to_be_reduced
 True if a gathering of numeric terms must be reduced It is True if at least two consecutive numeric Items are in the list and no other numeric term elsewhere.
def intermediate_reduction_line
 Creates the intermediate reduction line.
def reduce_
 Returns the reduced Sum For instance, giving the Sum 5x + 7x³ - 3x + 1, this method would return -2x + 7x³ + 1.
def is_null
 True if the result of the Sum is null.
def is_displ_as_a_single_1
 True if the Sum contains only 0s and one 1.
def is_displ_as_a_single_minus_1
 True if the Sum can be displayed as a single -1 So, if it only contains 0s and a single -1.
def is_displ_as_a_single_0
 True if the object can be displayed as a single 0 For instance, 0 + 0 + 0 but NOT - 1 + 0 + 1 (it's a matter of display)
def is_reducible
 True if the Sum is reducible This is based on the result of the get_term_lexicon method.

Public Attributes

 str_openmark
 str_closemark

Properties

 term
 force_inner_brackets_display

Detailed Description

Has Exponented terms & an exponent.

Iterable. Two display modes.

Definition at line 5971 of file base_calculus.py.


Constructor & Destructor Documentation

def core.base_calculus.Sum.__init__ (   self,
  arg 
)

Constructor.

Warning:
Might raise an UncompatibleType exception.
Parameters:
argNone|Sum|Number|String|Exponented|[Number|String|Exponented] In the case of the list, the Sums having an exponent equal to 1 will be treated before the Exponenteds so that their terms are inserted in the current Sum instead of inserting a term as a Sum. If the exponent is greater than 1, then it will be the case. If the argument isn't of the kinds listed above, an exception will be raised. Giving None or an empty list is equivalent to giving 0
Returns:
One instance of Sum

Reimplemented in core.base_calculus.Polynomial.

Definition at line 5990 of file base_calculus.py.

References core.base_calculus.CommutativeOperation._compact_display, core.base_calculus.Product._compact_display, core.base_calculus.Sum._compact_display, core.base_calculus.Item._exponent, core.base_calculus.Function._exponent, core.base_calculus.Quotient._exponent, core.base_calculus.Fraction._exponent, core.base_calculus.Product._exponent, core.base_calculus.Sum._exponent, core.base_calculus.Sum._force_inner_brackets_display, core.base_calculus.Operation._neutral, core.base_calculus.Product._neutral, core.base_calculus.Sum._neutral, core.base_calculus.Operation._symbol, core.base_calculus.Quotient._symbol, core.base_calculus.Fraction._symbol, core.base_calculus.Product._symbol, core.base_calculus.Sum._symbol, core.base.Clonable.clone(), core.base_calculus.CommutativeOperation.str_closemark, core.base_calculus.Product.str_closemark, core.base_calculus.Sum.str_closemark, core.base_calculus.CommutativeOperation.str_openmark, core.base_calculus.Product.str_openmark, and core.base_calculus.Sum.str_openmark.

Referenced by core.calculus.Equation.__init__(), and core.root_calculus.Value.substitute().


Member Function Documentation

def core.base_calculus.Sum.__cmp__ (   self,
  objct 
)

Compares two Sums Returns 0 if all terms are the same in the same order and if the exponents are also the same /!\ a + b will be different from de b + a It's not a mathematical comparison, but a "displayable"'s one.

Returns:
0 if all terms are the same in the same order & the exponent

Definition at line 7078 of file base_calculus.py.

References core.base_calculus.Item.exponent, core.root_calculus.Exponented.exponent, core.base_calculus.Fraction.exponent, and core.base_calculus.Sum.term.

def core.base_calculus.Sum.calculate_next_step (   self,
  options 
)

Returns the number of negative factors of the Sum (i.e.

0)

Reimplemented from core.root_calculus.Signed.

Definition at line 6073 of file base_calculus.py.

Creates a dict.

of couples (literal object):(numeric coeffs sum) Two objects are in fact created : a dictionary + an index which is a list containing the objects in the order they appear. The dictionary loses this order in general and the Sums created after that would never be in the same order without this index. Numeric Items are labeled NUMERIC in the index. For ex. giving the expression 6 + 2x² + 3x - 9 + x³ - 5x as an argument should return ({NUMERIC:(6-9), x²:2, x:(3-5), x³:1}, [NUMERIC, x², x, x³]). This method is fundamental to reduce Sums correctly, it is most important that it returns an object of the kind mentionned here above.

Parameters:
provided_sumThe Sum to examine...
Returns:
A tuple (dic, index).

Definition at line 6135 of file base_calculus.py.

References core.base_calculus.Operation.element, and core.base_calculus.Operation.is_literal().

Referenced by core.base_calculus.Sum.intermediate_reduction_line(), core.base_calculus.Sum.is_reducible(), and core.base_calculus.Sum.reduce_().

Creates the intermediate reduction line.

For instance, giving the Sum 5x + 7x³ - 3x + 1, this method would return (5 - 3)x + 7x³ + 1. No intermediate expansion will be done, though. For instance, the expression a + b + (a + b) will be reduced in 2a + 2b (provided the (a+b) is given as a Sum and not, for instance, as this Product : 1×(a + b) ; but the expression a + b + 5(a + b) won't be reduced in 6a + 6b. It has to be expanded first (there's a Expandable term there !). This method is the base to process the reduction of a Sum. It is therefore important that it returns the described kind of result.

Returns:
A Products' Sum : (coefficients Sum)×(literal factor)

Definition at line 7286 of file base_calculus.py.

References core.base_calculus.Sum.force_inner_brackets_display, core.base_calculus.Sum.get_terms_lexicon(), core.base_calculus.Sum.is_displ_as_a_single_1(), and core.base_calculus.Sum.numeric_terms_require_to_be_reduced().

def core.base_calculus.Sum.into_str (   self,
  options 
)

True if the Sum can be displayed as a single -1 So, if it only contains 0s and a single -1.

For instance, 0+0+(-1)+0

Reimplemented from core.root_calculus.Calculable.

Definition at line 7457 of file base_calculus.py.

References core.base_calculus.Operation.element.

Referenced by core.base_calculus.Sum.is_reducible().

def core.base_calculus.Sum.multiply_symbol_is_required (   self,
  objct,
  position 
)

True if the usual writing rules require a × between two factors.

Parameters:
objctThe other one
positionThe position (integer) of self in the Product
Returns:
True if the writing rules require × between self & obj

Reimplemented from core.root_calculus.Calculable.

Definition at line 7129 of file base_calculus.py.

References core.base_calculus.Item.multiply_symbol_is_required(), core.base_calculus.SquareRoot.multiply_symbol_is_required(), core.base_calculus.Quotient.multiply_symbol_is_required(), core.base_calculus.Product.multiply_symbol_is_required(), core.base_calculus.Sum.multiply_symbol_is_required(), and core.base_calculus.Sum.term.

Referenced by core.base_calculus.Sum.multiply_symbol_is_required().

def core.base_calculus.Sum.next_displayable_term_nb (   self,
  position 
)

Returns the rank of next non-equivalent to 0 term...

Parameters:
positionThe point where to start from to search
Returns:
The rank of next non-equivalent to 0 term (or None)

Definition at line 7113 of file base_calculus.py.

References core.base_calculus.Sum.is_displ_as_a_single_0(), and core.base_calculus.Sum.term.

Referenced by core.base_calculus.Sum.into_str().

True if a gathering of numeric terms must be reduced It is True if at least two consecutive numeric Items are in the list and no other numeric term elsewhere.

Examples where it's True : 3x - 5 + 2 + 5x -2 + 4 + 9 - 2x + 3x² When it's False : 3 - 5 + 2x + 6 4 + x - 2 -7 + 2×5 + 4 + 2x

Returns:
True if a gathering of numeric terms must be reduced

Definition at line 7248 of file base_calculus.py.

References core.base_calculus.CommutativeOperation.is_displ_as_a_single_numeric_Item(), and core.base_calculus.Sum.term.

Referenced by core.base_calculus.Sum.intermediate_reduction_line().

Returns the reduced Sum For instance, giving the Sum 5x + 7x³ - 3x + 1, this method would return -2x + 7x³ + 1.

No intermediate expandment will be done, though. For instance, the expression a + b + (a + b) will be reduced in 2a + 2b (provided the (a+b) is given as a Sum and not, for instance, as this Product : 1×(a + b) ; but the expression a + b + 5(a + b) won't be reduced in 6a + 6b. It has to be expanded first (there's a Expandable term there !).

Todo:
support for Fractions (evaluation...)
Returns:
One instance of Sum (reduced) [?] or of the only remaining term

Definition at line 7349 of file base_calculus.py.

References core.base_calculus.Item.dbg_str(), core.root_calculus.Value.dbg_str(), core.calculus.Equation.dbg_str(), core.base_calculus.SquareRoot.dbg_str(), core.base_calculus.Quotient.dbg_str(), core.base_calculus.Fraction.dbg_str(), core.base_calculus.CommutativeOperation.dbg_str(), core.base_calculus.Monomial.dbg_str(), core.base_calculus.Polynomial.dbg_str(), core.base_calculus.CommutativeOperation.evaluate(), core.base_calculus.Sum.force_inner_brackets_display, core.base_calculus.Sum.get_terms_lexicon(), core.base_calculus.Sum.is_displ_as_a_single_1(), and core.base_calculus.CommutativeOperation.throw_away_the_neutrals().

Referenced by core.base_calculus.Sum.calculate_next_step().

def core.base_calculus.Sum.requires_brackets (   self,
  position 
)

True if the argument requires brackets in a product For instance, a Sum with several terms or a negative Item.

Parameters:
positionThe position of the object in the Product
Returns:
True if the object requires brackets in a Product

Reimplemented from core.root_calculus.Calculable.

Definition at line 7176 of file base_calculus.py.

References core.base.Clonable.clone(), machine.Structure.Structure.clone(), core.base_calculus.CommutativeOperation.compact_display, and core.base_calculus.CommutativeOperation.throw_away_the_neutrals().

Referenced by core.base_calculus.Sum.into_str().

Sets a value to the force_inner_brackets_display field.

Parameters:
argAssumed to be True or False (not tested)

Definition at line 6326 of file base_calculus.py.

References core.base_calculus.Sum._force_inner_brackets_display.


Property Documentation

core::base_calculus.Sum::force_inner_brackets_display [static]
Initial value:
property(get_force_inner_brackets_display,
                    doc = "force_inner_brackets_display field of a Sum")

Definition at line 6306 of file base_calculus.py.

Referenced by core.base_calculus.Sum.intermediate_reduction_line(), core.base_calculus.Sum.into_str(), and core.base_calculus.Sum.reduce_().

core::base_calculus.Sum::term [static]

The documentation for this class was generated from the following file: