clesto.module: Free modules

Module

class clesto.module.module.Module_element(data=None, torsion=None)[source]

Elements in a free module over \(\mathbb{Z}\) or \(\mathbb{Z}/n \mathbb{Z}\).

Parameters
  • data (dict or None, default: None) – Dictionary representing a linear cobination of basis elements. Items in the dict correspond with pairs (basis element: coefficient).

  • torsion (int or 'free', default 'free') – The torsion of the underlying ring \(\mathbb{Z}\) or \(\mathbb{Z}/n \mathbb{Z}\)

torsion

The torsion of the underlying ring \(\mathbb{Z}\) or \(\mathbb{Z}/n \mathbb{Z}\)

Type

int or ‘free’, default ‘free’

Example

>>> print(Module_element())
0
>>> print(Module_element({'a': 1, 'b': -1, 'c': 0}))
a - b
default_torsion = 'free'
__add__(other)[source]

Addition: self + other.

Parameters

other (clesto.basics.module.Module_element object) – The element to add to self.

Returns

The sum of self and other.

Return type

clesto.basics.module.Module_element object

Example

>>> Module_element({'a': 1, 'b': 2}) + Module_element({'a': 1})
Module_element({'a': 2, 'b': 2})
__sub__(other)[source]

Diference: self - other.

Parameters

other (clesto.basics.module.Module_element object) – The element to substract from self.

Returns

The difference of self and other.

Return type

clesto.basics.module.Module_element object

Example

>>> Module_element({'a': 1, 'b': 2}) - Module_element({'a': 1})
Module_element({'b': 2})
__rmul__(c)[source]

Scaling: c * self.

Parameters

other (int) – The element to scale self. by.

Returns

The scaling of self by other.

Return type

clesto.basics.module.Module_element object

Example

>>> 3 * Module_element({'a':1, 'b':2})
Module_element({'b': 6, 'a': 3})
__neg__()[source]

Additive inverse: - self.

Returns

the additive inverse of self.

Return type

clesto.basics.module.Module_element object

Example

>>> - Module_element({'a': 1, 'b': 2})
Module_element({'a': -1, 'b': -2})
__iadd__(other)[source]

In place addition: self += other.

Parameters

other (clesto.basics.module.Module_element object) – The element to add to self.

Example

>>> x = Module_element({'a': 1, 'b': 2})
>>> x += Module_element({'a': 3, 'b': 6})
>>> x
Module_element({'b': 8, 'a': 4})
__isub__(other)[source]

In place difference: self -= other.

Parameters

other (clesto.basics.module.Module_element object) – The element to substract from self.

Example

>>> x = Module_element({'a': 1, 'b': 2})
>>> x -= Module_element({'a': 3, 'b': 6})
>>> x
Module_element({'a': -2, 'b': -4})
set_torsion(torsion)[source]

Sets the torsion of self.

Parameters

torsion (int or 'free') – The new torsion of self

Example

>>> Module_element({'a': 1, 'b': 2}).set_torsion(2)
Module_element({'a': 1})
create(other=None)[source]

Instantiates data with same type and attribute values as self.

Parameters

other (dict or None, default: None) – Data to be initialized.

Returns

The initialized object with the given data

Return type

type(self) object

Example

>>> x =  Module_element({'a': 1})
>>> x + x.create({'b': 1})
Module_element({'a': 1, 'b': 1})
zero()[source]

Instantiates 0 with same type and attribute values as self.

Returns

The initialized empty object

Return type

type(self) object

Example

>>> x = Module_element({'a': 1})
>>> x + x.zero() == x
True