galactic.algebras.convex.predicates.examples.arithmetic.core#
galactic.algebras.convex.predicates.examples.arithmetic.core module
Defines arithmetic predicates.
- class Divisor(**data)#
Bases:
BasicPredicateRepresents 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.
- class Multiple(**data)#
Bases:
BasicPredicateRepresents 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.