Arithmetic example
The galactic.algebras.examples.arithmetic
module.
It defines several functions:
gcd()
See https://en.wikipedia.org/wiki/Greatest_common_divisor;lcm()
See https://en.wikipedia.org/wiki/Least_common_multiple;factors()
to get the prime factors of a number.
and one classe:
- gcd(*elements)
Compute the greatest common divisor of a collection of integers.
- Parameters:
- 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:
- 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.
- class PrimeFactors(value=None)
-
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.
- 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.
- latex()
Get a LateX representation of a number using a prime number decomposition.
- Return type:
- 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
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:
- attributes(element, index=None, current=False, successors=None, predecessors=None)
Produce a dictionary of graphviz attributes for a node.
- Parameters:
element (
PrimeFactors
) – The prime factors to render.current (
bool
, default:False
) – Is element the current element?successors (
Collection
[PrimeFactors
] |None
, default:None
) – The successors of element.predecessors (
Collection
[PrimeFactors
] |None
, default:None
) – The predecessors of element.
- Returns:
A dictionary of graphviz attributes.
- Return type:
- property meet_irreducible_color: str
Get or set the meet irreducible color.
- Returns:
The meet irreducible color.
- Return type:
- property join_irreducible_color: str
Get or set the join irreducible color.
- Returns:
The join irreducible color.
- Return type:
- 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:
- 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:
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:
red (
SupportsFloat
, default:0.0
) – The red color.green (
SupportsFloat
, default:0.0
) – The green color.blue (
SupportsFloat
, default:0.0
) – The blue color.
- Raises:
ValueError – If a color is not between 0 and 1.
- hexadecimal()
Convert a color into HTML notation.
- Returns:
The HTML color notation.
- Return type:
- 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.
- 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
The galactic.algebras.examples.color.renderer
renders elements.
ColorRenderer
for rendering colors into jupyter notebooks.
- 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.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: