mathmaker  0.6(alpha)
Public Member Functions | Public Attributes | Properties
core.base_calculus.Item Class Reference

It's the smallest displayable element (sign, value, exponent) The value can be either numeric or literal. More...

Inheritance diagram for core.base_calculus.Item:
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.Function core.base_calculus.SquareRoot

List of all members.

Public Member Functions

def __init__
 Constructor.
def get_is_out_striked
 Gets the raw value of the Item.
def get_force_display_sign_once
 Gets force_display_sign_once field.
def get_raw_value
 Gets the raw value of the Item.
def get_value_inside
 Gets the Value of the Item.
def get_unit
 Returns the unit of the Item.
def get_minus_signs_nb
 Gets the number of '-' signs of the Item.
def get_iteration_list
 Returns the list of elements to iter over.
def get_first_letter
 Returns the letter of the Item, in case it's a literal.
def set_unit
 Set the unit of the Item.
def set_is_out_striked
 Sets a value to the "is_out_striked" field If is_out_striked is set to True, the Item will be displayed out striked.
def set_force_display_sign_once
 Sets a True|False value to the "force_display_sign_once" field.
def set_value_inside
 Sets the Value inside.
def into_str
 Creates a string of the given object in the given ML.
def evaluate
 Returns the value of a numerically evaluable Item.
def calculate_next_step
 Returns None|an Item.
def expand_and_reduce_next_step
 Returns None (an Item can't get expanded nor reduced !)
def dbg_str
 Raw display of the Item (debugging method)
def __eq__
 Compares two Items.
def __lt__
 Compares an Item to something else ; it's a reimplementing of alphabetical_order_cmp(), since we need this comparison.
def __hash__
 Makes Items hashable (so, usable as dictionnary keys)
def __len__
 Returns the Item's length.
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 object requires inner brackets The reason for requiring them is having a negative *value* and if the exponent is either :
def contains_exactly
 Always False for an Item.
def contains_a_rounded_number
 To check if this contains a rounded number...
def round
 Returns the (numeric) Item once rounded to the given precision.
def digits_number
 Returns the number of digits of a numerical Item.
def needs_to_get_rounded
 Returns True/False depending on the need of the value to get rounded (for instance 2.68 doesn't need to get rounded if precision is HUNDREDTH or more, but needs it if it is less) If the Item is not numeric, or if the given precision is incorrect, the matching call to the Value will raise an exception.
def turn_into_fraction
 Turns the Item into the fraction item itself over item 1.
def is_numeric
 True if it's a numeric Item.
def is_literal
 True if it's a literal Item.
def is_null
 True if it's the null Item.
def is_displ_as_a_single_1
 True if it's positive w/ (exponent 0 or numeric w/ value 1)
def is_displ_as_a_single_minus_1
 True if it's negative w/ (exponent 0 or numeric w/ value 1)
def is_displ_as_a_single_0
 True if self.is_null()
def is_displ_as_a_single_numeric_Item
 True if the Item is numeric.
def is_displ_as_a_single_int
 True if the object can be displayed as a single int.
def is_displ_as_a_single_neutral
 True if the object can be considered as a neutral element.
def is_expandable
 False.

Public Attributes

 sign
 exponent

Properties

 is_out_striked
 force_display_sign_once
 raw_value = property(get_raw_value, doc = "Item's raw value")
 value_inside = property(get_value_inside, doc = "Item's Value")
 unit = property(get_unit, doc = "Unit of the Item")

Detailed Description

It's the smallest displayable element (sign, value, exponent) The value can be either numeric or literal.

Definition at line 81 of file base_calculus.py.


Constructor & Destructor Documentation

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

Constructor.

Warning:
Might raise an UncompatibleType exception.
Parameters:
argNone|Number|String|Item|(sign,value,exponent)| (sign,number|letter|Value)|0-degree Monomial|Value Possible arguments can be :
  • a number which will will be the same as (sign_number, number, 1)
  • a letter : for example, passing 'a' is equivalent to ('+', 'a', 1) but passing '-x' is equivalent to ('-', 'x', 1) further characters are ignored ('ax' is equivalent to 'a')
  • another Item which will be copied
  • a tuple ('+'|'-', number|string)
  • a tuple ('+'|'-', number|string, <exponent as number|Exponented>)
  • None which will be the same as giving 1
  • a Monomial of degree zero and coefficient is an Item The is_out_striked field will always be initialized at False but will be copied in the case of an Item given as argument. If the argument is not of one of these kinds, an exception will be raised.
Returns:
One instance of Item

Reimplemented in core.base_calculus.Function.

Definition at line 108 of file base_calculus.py.

References core.base_calculus.Item._exponent, core.base_calculus.Item._force_display_sign_once, core.base_calculus.Item._is_out_striked, core.base_calculus.Item._sign, core.base_calculus.Item._unit, core.base_calculus.Item._value_inside, and core.base.Clonable.clone().

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


Member Function Documentation

def core.base_calculus.Item.__eq__ (   self,
  other_item 
)

Compares two Items.

Returns:
True if they're equal

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 646 of file base_calculus.py.

References core.base_calculus.Item.exponent, core.base_calculus.Item.raw_value, and core.base_calculus.Item.sign.

Returns the Item's length.

Returns:
1

Reimplemented from core.root_calculus.Calculable.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 732 of file base_calculus.py.

def core.base_calculus.Item.__lt__ (   self,
  other_objct 
)

Compares an Item to something else ; it's a reimplementing of alphabetical_order_cmp(), since we need this comparison.

Returns:
True if self is lower than the other_item

Definition at line 692 of file base_calculus.py.

References core.base_calculus.Item.get_first_letter(), core.base_calculus.Item.is_literal(), and core.base_calculus.Item.is_numeric().

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

Returns None|an Item.

Todo:
Manage the case when the exponent is a calculable that should be calculated itself.
Warning:
Relays an exception if the exponent is not Exponented|Value If the Item has an exponent equivalent to a single 1, then nothing can be calculated, so this method returns None In another case, it returns the evaluated Item

Reimplemented from core.root_calculus.Calculable.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 525 of file base_calculus.py.

References core.base_calculus.Item.dbg_str(), core.base_calculus.Item.is_numeric(), core.base_calculus.Item.raw_value, and core.base_calculus.Item.sign.

Referenced by core.base_calculus.Quotient.evaluate(), core.base_calculus.CommutativeOperation.evaluate(), 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(), and core.base_calculus.Sum.expand_and_reduce_next_step().

To check if this contains a rounded number...

Returns:
True or False depending on the Value inside

Reimplemented from core.root_calculus.Evaluable.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 920 of file base_calculus.py.

References core.base_calculus.Item.value_inside.

def core.base_calculus.Item.contains_exactly (   self,
  objct 
)

Always False for an Item.

Parameters:
objctThe object to search for
Returns:
False

Reimplemented from core.root_calculus.Evaluable.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 908 of file base_calculus.py.

def core.base_calculus.Item.dbg_str (   self,
  options 
)

Returns None (an Item can't get expanded nor reduced !)

Returns:
Exponented

Reimplemented from core.root_calculus.Calculable.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 610 of file base_calculus.py.

References core.base_calculus.Item.calculate_next_step(), and core.base_calculus.Item.is_numeric().

Referenced by core.base_calculus.Product.calculate_next_step(), and core.base_calculus.Sum.calculate_next_step().

Gets force_display_sign_once field.

Returns:
Item's force_display_sign_once field

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 216 of file base_calculus.py.

References core.base_calculus.Item._force_display_sign_once.

Gets the raw value of the Item.

Returns:
value_inside.raw_value

Definition at line 205 of file base_calculus.py.

References core.base_calculus.Item._is_out_striked.

Gets the raw value of the Item.

Returns:
value_inside.raw_value

Definition at line 227 of file base_calculus.py.

References core.base_calculus.Item.value_inside.

Gets the Value of the Item.

Returns:
value_inside

Definition at line 238 of file base_calculus.py.

References core.base_calculus.Item._value_inside.

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

False.

Returns:
False

Reimplemented in core.base_calculus.SquareRoot, and core.base_calculus.Function.

Definition at line 1120 of file base_calculus.py.

def core.base_calculus.Item.multiply_symbol_is_required (   self,
  objct,
  position 
)
def core.base_calculus.Item.needs_to_get_rounded (   self,
  precision 
)

Returns True/False depending on the need of the value to get rounded (for instance 2.68 doesn't need to get rounded if precision is HUNDREDTH or more, but needs it if it is less) If the Item is not numeric, or if the given precision is incorrect, the matching call to the Value will raise an exception.

Definition at line 964 of file base_calculus.py.

Referenced by core.root_calculus.Value.round().

def core.base_calculus.Item.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.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 816 of file base_calculus.py.

References core.base_calculus.Item.is_literal(), core.base_calculus.Item.raw_value, and core.base_calculus.Item.sign.

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

True if the object requires inner brackets The reason for requiring them is having a negative *value* and if the exponent is either :

  • (numeric Item | number) and even
  • (numeric Item | number) equivalent to 1 the object has a '-' *sign*
  • litteral Item
  • any Exponented apart from Items.
    Todo:

    Case of non-Item-Exponented exponents probably is to be improved

    Case of numerator-only equivalent Quotients not made so far

    Returns:
    True if the object requires inner brackets

Reimplemented from core.root_calculus.Calculable.

Reimplemented in core.base_calculus.SquareRoot.

Definition at line 849 of file base_calculus.py.

References core.base_calculus.Item.exponent, core.base_calculus.Item.is_literal(), core.root_calculus.Signed.is_negative(), core.base_calculus.Monomial.is_negative(), core.base_calculus.Item.is_numeric(), core.base_calculus.Item.raw_value, and core.base_calculus.Item.sign.

Referenced by core.base_calculus.Item.into_str(), and core.base_calculus.Product.into_str().

def core.base_calculus.Item.set_unit (   self,
  arg 
)

Set the unit of the Item.

Parameters:
argString

Definition at line 328 of file base_calculus.py.

References core.base_calculus.Item._unit.


Property Documentation

core::base_calculus.Item::force_display_sign_once [static]
Initial value:
property(get_force_display_sign_once,
                              doc = "Item's force_display_sign_once field")

Definition at line 312 of file base_calculus.py.

Referenced by core.base_calculus.Item.into_str(), core.base_calculus.SquareRoot.into_str(), and core.base_calculus.SquareRoot.requires_brackets().

core::base_calculus.Item::is_out_striked [static]
Initial value:
property(get_is_out_striked,
                              doc = "Item's is_out_striked field")

Definition at line 309 of file base_calculus.py.

Referenced by core.base_calculus.Item.dbg_str(), and core.base_calculus.Item.into_str().


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