galactic.algebras.convex.descriptions.examples.arithmetic.core#

galactic.algebras.convex.descriptions.examples.arithmetic.core module

Defines arithmetic descriptions.

class DivisorDescription(**data)#

Bases: Description

Describes an iterable of integers.

Inherits from Description and implements the _call method to describe a collection of values by yielding Divisor instances. The characteristic parameter must be an instance of Integer, defining the nature of the divisors described. It is typically used to specify the integer characteristic in arithmetic contexts.

Parameters:

space (tuple[Integer]) – A tuple containing a single Integer characteristic that defines the nature of the divisors described by this description.

ALIAS#

The alias of the type in the resource registry.

Type:

ClassVar[str] = “examples.core.description.Divisor”

Examples

>>> from galactic.algebras.concept.core import ItemUniverse
>>> from galactic.algebras.convex.characteristics.core import Component, Integer
>>> from galactic.algebras.convex.descriptions.core import (
...     Context,
...     PredicateUniverse,
... )
>>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
...     DivisorDescription,
... )
>>> from galactic.algebras.convex.predicates.examples.arithmetic.core import (
...     Divisor,
... )
>>> description = DivisorDescription(space=(Integer(components=(Component(),)),))
>>> dataset = [12, 18, 24]
>>> context = Context(ItemUniverse(dataset), PredicateUniverse(descriptions=(description,)))
>>> [str(divisor) for divisor in description(context.domain)]
['D(int(@),72)']
>>> dataset = [None, 18, 24]
>>> context = Context(ItemUniverse(dataset), PredicateUniverse(descriptions=(description,)))
>>> [str(divisor) for divisor in description(context.domain)]
[]
>>> divisor_18 = Divisor(space=description.space, number=18)
>>> [item.value for item in context.predecessors(divisor_18)]
[None, 18]
>>> [
...     str(divisor)
...     for divisor in description(context.predecessors(divisor_18))
... ]
[]
>>> divisor_5 = Divisor(space=description.space, number=5)
>>> [item.value for item in context.predecessors(divisor_5)]
[None]
>>> [str(divisor) for divisor in description(context.predecessors(divisor_5))]
[]
Raises:
  • TypeError – If the characteristic is not an instance of Integer

  • ValueError – If the space does not have the required number of elements

Note

This description computes the least common multiple (LCM) of the first elements of the tuples in values, and then yields Divisor instances for each factor of the LCM. The factors are computed using the factors function, which returns the prime factors of the LCM. Each Divisor instance is created with the characteristic and the factor value.

Hint

This description is useful for generating predicates that represent divisors of integers based on the LCM of a collection of values. It can be used in contexts where you need to analyze or describe relationships between integers, such as in number theory or arithmetic operations.

Warning

This description is not a convex description space; in consequence, the NaiveStrategy could not produce sub-concepts.

property characteristic: Integer#

Get the underlying characteristic.

Returns:

The underlying characteristic

Return type:

Integer

Notes

This property returns the inner characteristic of the description, which is an instance of Integer. The characteristic is used to define the nature of the divisors described by this instance. It is typically an integer characteristic that defines the divisors in the context of arithmetic operations.

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class MultipleDescription(**data)#

Bases: Description

Describes an iterable of integers.

Inherits from Description and implements the _call method to describe a collection of values by yielding Multiple instances. The characteristic parameter must be an instance of Integer, defining the nature of the multiples described. It is typically used to specify the integer characteristic in arithmetic contexts.

Parameters:

space (tuple[Integer]) – A tuple containing a single Integer characteristic that defines the nature of the multiples described by this description.

ALIAS#

The alias of the type in the resource registry.

Type:

ClassVar[str] = “examples.core.description.Multiple”

Examples

>>> from galactic.algebras.concept.core import ItemUniverse
>>> from galactic.algebras.convex.characteristics.core import Component, Integer
>>> from galactic.algebras.convex.descriptions.core import (
...     Context,
...     PredicateUniverse,
... )
>>> from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
...     MultipleDescription,
... )
>>> description = MultipleDescription(space=(Integer(components=(Component(),)),))
>>> dataset = [12, 18, 24]
>>> context = Context(ItemUniverse(dataset), PredicateUniverse(descriptions=(description,)))
>>> [str(multiple) for multiple in description(context.domain)]
['M(int(@),2)', 'M(int(@),3)']
>>> dataset = [None, 18, 24]
>>> context = Context(ItemUniverse(dataset), PredicateUniverse(descriptions=(description,)))
>>> [str(multiple) for multiple in description(context.domain)]
[]
>>> multiple_4 = Multiple(space=description.space, number=4)
>>> [item.value for item in context.predecessors(multiple_4)]
[None, 24]
>>> [
...     str(multiple)
...     for multiple in description(context.predecessors(multiple_4))
... ]
[]
>>> multiple_5 = Multiple(space=description.space, number=5)
>>> [item.value for item in context.predecessors(multiple_5)]
[None]
>>> [str(multiple) for multiple in description(context.predecessors(multiple_5))]
[]
Raises:
  • TypeError – If the characteristic is not an instance of Integer

  • ValueError – If the space does not have the required number of elements

Notes

This description computes the greatest common divisor (GCD) of the first elements of the tuples in values, and then yields Multiple instances for each factor of the GCD. The factors are computed using the factors function, which returns the prime factors of the GCD. Each Multiple instance is created with the characteristic and the factor value.

Hint

This description is useful for generating predicates that represent multiples of integers based on the GCD of a collection of values. It can be used in contexts where you need to analyze or describe relationships between integers, such as in number theory or arithmetic operations.

property characteristic: Integer#

Get the underlying characteristic.

This property returns the inner characteristic of the description, which is an instance of Integer.

Returns:

The underlying characteristic

Return type:

Integer

Notes

The characteristic is used to define the nature of the multiples described by this instance. It is typically an integer characteristic that defines the multiples in the context of arithmetic operations.

model_config: ClassVar[ConfigDict] = {'validate_assignment': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].