Arithmetic example

The galactic.algebras.examples.arithmetic module.

It defines several functions:

and one classe:

gcd(*elements)

Compute the greatest common divisor of a collection of integers.

Parameters:

*elements (int | None) – A sequence of integers

Returns:

The greatest common divisor of args

Return type:

int | None

Note

  • The greatest common divisor of 0 and 0 is computed as 0.

  • The greatest common divisor of an empty set is computed as 1.

Raises:

ValueError – If a value cannot be converted to an integer or if the converted value is less than 0.

lcm(*elements)

Compute the least common multiple of a collection of integers.

Parameters:

*elements (int | None) – A sequence of integers

Returns:

The least common multiple of args

Return type:

int | None

Note

The least common multiple of an empty set is computed as 1.

Raises:

ValueError – If a value cannot be converted to an integer or if the converted value is less than 0.

factors(number=None)

Compute the prime factors of an integer.

Parameters:

number (int | None, default: None) – The number for which decomposition is requested

Yields:

int – A prime factor of the number.

Return type:

Iterator[int]

class PrimeFactors(value=None)

Bases: Joinable, Meetable

It represents a partially ordered relation between integers.

\(a \leq b\): is equivalent to \(a\) a divisor of \(b\).

Parameters:

value (SupportsInt | None, default: None) – An integer value.

Raises:

ValueError – If the value is not a positive number.

property value: int | None

Get the value of the integer.

Return type:

The integer value

join(*others)

Return the supremum of this element and the others.

Parameters:

*others (Self) – The others elements

Returns:

The join of this element and the others

Return type:

Self

join_level(generators)

Compute the level of an element considering an iterable of generators.

Parameters:

generators (Iterable[Self]) – An iterable of generators.

Returns:

The level of the element.

Return type:

int

latex()

Get a LateX representation of a number using a prime number decomposition.

Return type:

str

Returns:

A LaTeX representation

meet(*others)

Return the infimum of this element and the others.

Parameters:

*others (Self) – The others elements

Returns:

The meet of this element and the others

Return type:

Self

meet_level(generators)

Compute the level of an element considering an iterable of generators.

Parameters:

generators (Iterable[Self]) – An iterable of generators.

Returns:

The level of the element.

Return type:

int

The galactic.algebras.examples.arithmetic.renderer renders elements.

class PrimeFactorsRenderer(meet_irreducible_color='#fcaf3e', join_irreducible_color='#8ae234', meet_semi_lattice=False, join_semi_lattice=False, meet_irreducible=False, join_irreducible=False)

Bases: NodeRenderer[PrimeFactors, PrimeFactors], CellRenderer[PrimeFactors]

It renders prime factors.

  • graphviz node attributes when rendering a Hasse Diagram

  • header and row title when rendering a reduced context

Parameters:
  • meet_irreducible_color (str, default: '#fcaf3e') – The meet irreducible color.

  • join_irreducible_color (str, default: '#8ae234') – The join irreducible color.

  • meet_semi_lattice (bool, default: False) – Is it displayed in a meet semi-lattice context?

  • join_semi_lattice (bool, default: False) – Is it displayed in a join semi-lattice context?

  • meet_irreducible (bool, default: False) – Is it displayed as a meet irreducible?

  • join_irreducible (bool, default: False) – Is it displayed as a join irreducible?

render(element, index)

Render a prime factors for a cell element.

Parameters:
  • element (PrimeFactors) – The prime factors to render.

  • index (int) – The element index.

Returns:

The markdown representation of a prime factors.

Return type:

str

attributes(element, index=None, current=False, successors=None, predecessors=None)

Produce a dictionary of graphviz attributes for a node.

Parameters:
Returns:

A dictionary of graphviz attributes.

Return type:

dict[str, str]

property meet_irreducible_color: str

Get or set the meet irreducible color.

Returns:

The meet irreducible color.

Return type:

str

property join_irreducible_color: str

Get or set the join irreducible color.

Returns:

The join irreducible color.

Return type:

str

property meet_semi_lattice: bool

Get or set the meet semi-lattice mode.

Returns:

If the display is in meet semi-lattice mode.

Return type:

bool

property join_semi_lattice: bool

Get or set the join semi-lattice mode.

Returns:

If the display is in join semi-lattice mode.

Return type:

bool

property meet_irreducible: bool

Get or set the meet irreducible mode.

Returns:

If the display is in meet irreducible mode.

Return type:

bool

property join_irreducible: bool

Get or set the join irreducible mode.

Returns:

If the display is in join irreducible mode.

Return type:

bool

Color example

The galactic.algebras.examples.color module defines several classes.

  • Color which represents partially comparable colors;

class Color(red=0.0, green=0.0, blue=0.0)

Bases: Element

It implements a partially ordered relation between colors.

\((r_a,g_a,b_a) \leq (r_b,g_b,b_b)\): is equivalent to \(r_a\leq r_b \wedge g_a\leq g_b \wedge b_a\leq b_b\).

Parameters:
Raises:

ValueError – If a color is not between 0 and 1.

property red: float

Get the red value of the color.

Returns:

The red value.

Return type:

float

property green: float

Get the green value of the color.

Returns:

The green value.

Return type:

float

property blue: float

Get the blue value of the color.

Returns:

The blue value.

Return type:

float

hexadecimal()

Convert a color into HTML notation.

Returns:

The HTML color notation.

Return type:

str

join(*others)

Return the supremum of this element and the others.

Parameters:

*others (Self) – The others elements

Returns:

The join of this element and the others

Return type:

Self

join_level(generators)

Compute the level of an element considering an iterable of generators.

Parameters:

generators (Iterable[Self]) – An iterable of generators.

Returns:

The level of the element.

Return type:

int

meet(*others)

Return the infimum of this element and the others.

Parameters:

*others (Self) – The others elements

Returns:

The meet of this element and the others

Return type:

Self

meet_level(generators)

Compute the level of an element considering an iterable of generators.

Parameters:

generators (Iterable[Self]) – An iterable of generators.

Returns:

The level of the element.

Return type:

int

The galactic.algebras.examples.color.renderer renders elements.

class ColorRenderer

Bases: object

It renders graphviz node and edge attributes.

attributes(element, index=None, current=False, successors=None, predecessors=None)

Produce a dictionary of graphviz attributes for a node.

Parameters:
  • element (Color) – The color to render.

  • index (int | None, default: None) – The element index.

  • current (bool, default: False) – Is element the current element?

  • successors (Collection[Color] | None, default: None) – The successors of the element.

  • predecessors (Collection[Color] | None, default: None) – The predecessors of the element.

Returns:

A dictionary of graphviz attributes.

Return type:

dict[str, str]