mathmaker
0.4(alpha)
|
Has Exponented terms & an exponent. More...
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 |
Has Exponented terms & an exponent.
Iterable. Two display modes.
Definition at line 5971 of file base_calculus.py.
def core.base_calculus.Sum.__init__ | ( | self, | |
arg | |||
) |
Constructor.
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 |
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().
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.
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 next calculated step of a *numeric* Sum.
This method may be only partially implemented (see source)
the inner '-' signs (±(-2)) are not handled by this method so far
Reimplemented from core.root_calculus.Calculable.
Definition at line 6540 of file base_calculus.py.
References core.base.Clonable.clone(), machine.Structure.Structure.clone(), core.base_calculus.CommutativeOperation.dbg_str(), core.base_calculus.Item.expand_and_reduce_next_step(), core.base_calculus.SquareRoot.expand_and_reduce_next_step(), core.base_calculus.Fraction.expand_and_reduce_next_step(), core.base_calculus.Product.expand_and_reduce_next_step(), core.base_calculus.Sum.expand_and_reduce_next_step(), core.base_calculus.CommutativeOperation.get_sign(), core.root_calculus.Evaluable.is_numeric(), core.base_calculus.Item.is_numeric(), core.root_calculus.Value.is_numeric(), core.base_calculus.SquareRoot.is_numeric(), core.base_calculus.Operation.is_numeric(), core.calculus.Table.is_numeric(), core.base_calculus.Monomial.is_numeric(), core.base_calculus.Sum.reduce_(), and core.base_calculus.CommutativeOperation.set_sign().
Referenced by core.base_calculus.CommutativeOperation.evaluate(), and core.base_calculus.Sum.expand_and_reduce_next_step().
def core.base_calculus.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.
Reimplemented from core.root_calculus.Calculable.
Definition at line 6885 of file base_calculus.py.
References core.base_calculus.Item.calculate_next_step(), core.base_calculus.SquareRoot.calculate_next_step(), core.base_calculus.Quotient.calculate_next_step(), core.base_calculus.Fraction.calculate_next_step(), core.base_calculus.Product.calculate_next_step(), core.base_calculus.Sum.calculate_next_step(), 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.CommutativeOperation.info, core.root_calculus.Evaluable.is_numeric(), core.base_calculus.Item.is_numeric(), core.root_calculus.Value.is_numeric(), core.base_calculus.SquareRoot.is_numeric(), core.base_calculus.Operation.is_numeric(), core.calculus.Table.is_numeric(), core.base_calculus.Monomial.is_numeric(), and core.base_calculus.CommutativeOperation.throw_away_the_neutrals().
Referenced by core.base_calculus.Sum.calculate_next_step().
def core.base_calculus.Sum.get_minus_signs_nb | ( | self | ) |
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.
def core.base_calculus.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.
provided_sum | The Sum to examine... |
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.
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 | |||
) |
Creates a string of the given object in the given ML.
options | Any options |
Reimplemented from core.base.Printable.
Definition at line 6338 of file base_calculus.py.
References core.base_calculus.CommutativeOperation.compact_display, core.base_calculus.CommutativeOperation.dbg_str(), core.root_calculus.Exponented.exponent_must_be_displayed(), core.base_calculus.Sum.force_inner_brackets_display, core.base_calculus.CommutativeOperation.get_sign(), core.base_calculus.CommutativeOperation.info, core.base_calculus.Sum.is_displ_as_a_single_0(), core.base_calculus.Sum.next_displayable_term_nb(), core.base_calculus.Sum.requires_brackets(), core.base_calculus.Sum.requires_inner_brackets(), core.base_calculus.Sum.term, and core.base_calculus.CommutativeOperation.throw_away_the_neutrals().
def core.base_calculus.Sum.is_displ_as_a_single_1 | ( | self | ) |
True if the Sum contains only 0s and one 1.
For instance, 1+0+0
Reimplemented from core.root_calculus.Calculable.
Definition at line 7428 of file base_calculus.py.
References core.base_calculus.Operation.element, and core.base_calculus.Sum.term.
Referenced by core.base_calculus.Sum.intermediate_reduction_line(), core.base_calculus.Sum.is_reducible(), core.base_calculus.Sum.reduce_(), and core.base_calculus.Sum.requires_inner_brackets().
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.is_reducible | ( | self | ) |
True if the Sum is reducible This is based on the result of the get_term_lexicon method.
Definition at line 7494 of file base_calculus.py.
References core.base_calculus.Sum.get_terms_lexicon(), core.base_calculus.Item.is_displ_as_a_single_0(), core.base_calculus.Function.is_displ_as_a_single_0(), core.base_calculus.SquareRoot.is_displ_as_a_single_0(), core.base_calculus.Quotient.is_displ_as_a_single_0(), core.base_calculus.Product.is_displ_as_a_single_0(), core.base_calculus.Sum.is_displ_as_a_single_0(), core.base_calculus.Item.is_displ_as_a_single_1(), core.base_calculus.Function.is_displ_as_a_single_1(), core.base_calculus.SquareRoot.is_displ_as_a_single_1(), core.base_calculus.Quotient.is_displ_as_a_single_1(), core.base_calculus.Product.is_displ_as_a_single_1(), core.base_calculus.Sum.is_displ_as_a_single_1(), core.base_calculus.Item.is_displ_as_a_single_minus_1(), core.base_calculus.Function.is_displ_as_a_single_minus_1(), core.base_calculus.SquareRoot.is_displ_as_a_single_minus_1(), core.base_calculus.Quotient.is_displ_as_a_single_minus_1(), core.base_calculus.Product.is_displ_as_a_single_minus_1(), and core.base_calculus.Sum.is_displ_as_a_single_minus_1().
def core.base_calculus.Sum.multiply_symbol_is_required | ( | self, | |
objct, | |||
position | |||
) |
True if the usual writing rules require a × between two factors.
objct | The other one |
position | The position (integer) of self in the Product |
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...
position | The point where to start from to search |
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
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().
def core.base_calculus.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 !).
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.
position | The position of the object in the 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().
def core.base_calculus.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)
Reimplemented from core.root_calculus.Calculable.
Definition at line 7217 of file base_calculus.py.
References core.root_calculus.Exponented.exponent_must_be_displayed(), core.root_calculus.Signed.get_sign(), core.root_calculus.Value.get_sign(), core.base_calculus.Quotient.get_sign(), core.base_calculus.CommutativeOperation.get_sign(), core.base_calculus.Monomial.get_sign(), core.base_calculus.Item.is_displ_as_a_single_1(), core.base_calculus.Function.is_displ_as_a_single_1(), core.base_calculus.SquareRoot.is_displ_as_a_single_1(), core.base_calculus.Quotient.is_displ_as_a_single_1(), core.base_calculus.Product.is_displ_as_a_single_1(), core.base_calculus.Sum.is_displ_as_a_single_1(), core.base_calculus.Operation.is_numeric(), and core.base_calculus.Sum.term.
Referenced by core.base_calculus.Sum.into_str().
def core.base_calculus.Sum.set_force_inner_brackets_display | ( | self, | |
arg | |||
) |
Sets a value to the force_inner_brackets_display field.
arg | Assumed 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.
core::base_calculus.Sum::force_inner_brackets_display [static] |
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] |
property(CommutativeOperation.get_element,
doc = "To access the terms of the Sum.")
Definition at line 6303 of file base_calculus.py.
Referenced by core.base_calculus.Sum.__cmp__(), core.base_calculus.Polynomial.dbg_str(), core.base_calculus.Polynomial.get_degree(), core.base_calculus.Polynomial.get_max_degree(), core.base_calculus.Sum.into_str(), core.base_calculus.Sum.is_displ_as_a_single_1(), core.base_calculus.Sum.multiply_symbol_is_required(), core.base_calculus.Sum.next_displayable_term_nb(), core.base_calculus.Sum.numeric_terms_require_to_be_reduced(), and core.base_calculus.Sum.requires_inner_brackets().