galactic.algebras.convex.predicates.examples.arithmetic.core

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

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

Defines arithmetic predicates.

class Divisor(**data)#

Bases: BasicPredicate

Represents the predicate Is it a divisor of a specific integer?.

Parameters:
  • space – The inner characteristic

  • number – The value to check for divisibility

Raises:
  • TypeError – If the number is not an int

  • TypeError – If the space is not a tuple

  • TypeError – If the space does not contain an Integer instance

  • ValueError – If the space does not contain exactly one Integer

Examples

>>> from galactic.algebras.concept.core import Item
>>> from galactic.algebras.convex.characteristics.core import Component, Integer
>>> from galactic.algebras.convex.predicates.examples.arithmetic.core import (
...     Divisor,
... )
>>> characteristic = Integer(components=(Component(),))
>>> predicate = Divisor(space=(characteristic,), number=18)
>>> print(predicate)
D(int(@),18)
>>> print(predicate(Item(value=6)))
True
>>> print(predicate(Item(value=7)))
False
>>> print(predicate(Item(value=9)))
True

Notes

  • The Divisor predicate checks if a value is a divisor of a specific integer.

  • It is typically used in conjunction with an Integer characteristic to determine if the integer value of the characteristic is a divisor of the specified number.

  • The number parameter specifies the integer to check against.

  • The characteristic parameter is the inner characteristic that provides the integer value to be checked.

Hint

The Divisor predicate can be used to filter or select items based on whether their integer characteristic is a divisor of a given number.

property template: str#

Get the template.

Returns:

The template string for the predicate

Return type:

str

model_config: ClassVar[ConfigDict] = {}#

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

class Multiple(**data)#

Bases: BasicPredicate

Represents the predicate Is it a multiple of a specific integer?.

Parameters:
  • space – The inner characteristic

  • number – The value to check for multiplicity

Raises:
  • TypeError – If the number is not an int

  • TypeError – If the space is not a tuple

  • TypeError – If the space does not contain an Integer instance

  • ValueError – If the space does not contain exactly one Integer

Examples

>>> from galactic.algebras.concept.core import Item
>>> from galactic.algebras.convex.characteristics.core import Component, Integer
>>> from galactic.algebras.convex.predicates.examples.arithmetic.core import (
...     Multiple,
... )
>>> characteristic = Integer(components=(Component(),))
>>> predicate = Multiple(space=(characteristic,), number=3)
>>> print(predicate)
M(int(@),3)
>>> print(predicate(Item(value=6)))
True
>>> print(predicate(Item(value=7)))
False
>>> print(predicate(Item(value=9)))
True

Notes

  • The Multiple predicate checks if a value is a multiple of a specific integer.

  • It is typically used in conjunction with an Integer characteristic to determine if the integer value of the characteristic is a multiple of the specified number.

  • The number parameter specifies the integer to check against.

  • The characteristic parameter is the inner characteristic that provides the integer value to be checked.

Hint

The Multiple predicate can be used to filter or select items based on whether their integer characteristic is a multiple of a given number.

property template: str#

Get the template.

Returns:

The template string for the predicate

Return type:

str

model_config: ClassVar[ConfigDict] = {}#

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