obj::calc::Sum Class Reference

Has Exponented terms & an exponent. More...

Inheritance diagram for obj::calc::Sum:
obj::calc::Operation obj::calc::Exponented obj::calc::Calculable obj::Printable obj::calc::Polynomial

List of all members.

Public Member Functions

def __init__
 Constructor.
def get_elements
 Allow the subclasses to access to their elements.
def get_info
 Allow the subclasses to access this field.
def operator
 Defines the performed Operation as a Sum.
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 is_null
 True if the result of the Sum is null.
def is_equivalent_to_a_single_1
 True if the Sum contains only 0s and one 1.
def is_equivalent_to_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_equivalent_to_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.
def get_minus_signs_nb
 Returns the number of negative factors of the Sum (i.e.
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 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 set_force_inner_brackets_display
 Sets a value to the force_inner_brackets_display field.
def set_term
 Sets the n-th term to the given arg.
def calculate_next_step
 Returns the next calculated step of a *numeric* Sum.
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 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 make_string
 Creates a string of the given object in the given ML.

Detailed Description

Has Exponented terms & an exponent.

Iterable. Two display modes.

Definition at line 4588 of file __init__.py.


Member Function Documentation

def obj::calc::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 4737 of file __init__.py.

def obj::calc::Sum::__init__ (   self,
  arg 
)

Constructor.

Warning:
Might raise an UncompatibleType exception.
Parameters:
arg None|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 obj::calc::Polynomial.

Definition at line 4607 of file __init__.py.

def obj::calc::Sum::calculate_next_step (   self,
  options 
)

Returns the next calculated step of a *numeric* Sum.

Todo:

This method may be only partially implemented (see source)

the inner '-' signs (±(-2)) are not handled by this method so far

Reimplemented from obj::calc::Exponented.

Definition at line 5272 of file __init__.py.

def obj::calc::Sum::expand_and_reduce_next_step (   self,
  options 
)

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.

Returns:
Exponented

Reimplemented from obj::calc::Exponented.

Definition at line 5757 of file __init__.py.

def obj::calc::Sum::get_minus_signs_nb (   self  ) 

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

0)

Reimplemented from obj::calc::Exponented.

Definition at line 4863 of file __init__.py.

def obj::calc::Sum::get_terms_lexicon (   self  ) 

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_sum The Sum to examine...
Returns:
A tuple (dic, index).

Definition at line 5089 of file __init__.py.

def obj::calc::Sum::intermediate_reduction_line (   self  ) 

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 5626 of file __init__.py.

def obj::calc::Sum::is_equivalent_to_a_single_1 (   self  ) 

True if the Sum contains only 0s and one 1.

For instance, 1+0+0

Reimplemented from obj::calc::Calculable.

Definition at line 4773 of file __init__.py.

def obj::calc::Sum::is_equivalent_to_a_single_minus_1 (   self  ) 

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 obj::calc::Calculable.

Definition at line 4802 of file __init__.py.

def obj::calc::Sum::is_reducible (   self  ) 

True if the Sum is reducible This is based on the result of the get_term_lexicon method.

Returns:
True|False

Definition at line 4839 of file __init__.py.

def obj::calc::Sum::make_string (   self,
  markup,
  options 
)

Creates a string of the given object in the given ML.

Parameters:
markup The markup dictionary to use
options Any options
Returns:
The formated string

Reimplemented from obj::Printable.

Definition at line 5950 of file __init__.py.

def obj::calc::Sum::multiply_symbol_is_required (   self,
  objct,
  position 
)

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

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

Reimplemented from obj::calc::Exponented.

Definition at line 4891 of file __init__.py.

def obj::calc::Sum::next_displayable_term_nb (   self,
  position 
)

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

..

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

Definition at line 4875 of file __init__.py.

def obj::calc::Sum::numeric_terms_require_to_be_reduced (   self  ) 

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 5010 of file __init__.py.

def obj::calc::Sum::reduce_ (   self  ) 

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 5689 of file __init__.py.

def obj::calc::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:
position The position of the object in the Product
Returns:
True if the object requires brackets in a Product

Reimplemented from obj::calc::Exponented.

Definition at line 4938 of file __init__.py.

def obj::calc::Sum::requires_inner_brackets (   self  ) 

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).

Returns:
True if the object requires inner brackets

Reimplemented from obj::calc::Exponented.

Definition at line 4979 of file __init__.py.

def obj::calc::Sum::set_force_inner_brackets_display (   self,
  arg 
)

Sets a value to the force_inner_brackets_display field.

Parameters:
arg Assumed to be True or False (not tested)

Definition at line 5251 of file __init__.py.


The documentation for this class was generated from the following file:
Generated on Fri Dec 30 19:26:37 2011 for mathmaker by  doxygen 1.6.3