Skip to content

Lattice

BoundedLattice

Bases: Lattice[BoundedLatticeType]

ABC for bounded lattices as Python class.

BoundedLattice is an abstract class that can be inherited from. It requires the implementation of the bottom and top methods.

Lattice

Bases: ABC, Generic[LatticeType]

ABC for lattices as Python class.

While Lattice is only an interface, LatticeABC is an abstract class that can be inherited from. This provides a few default implementations for the lattice operations.

is_equal

is_equal(other: LatticeType) -> bool

Check if two lattices are equal.

Source code in src/kirin/lattice/abc.py
52
53
54
55
56
57
def is_equal(self, other: LatticeType) -> bool:
    """Check if two lattices are equal."""
    if self is other:
        return True
    else:
        return self.is_subseteq(other) and other.is_subseteq(self)

is_subseteq abstractmethod

is_subseteq(other: LatticeType) -> bool

Subseteq operation.

Source code in src/kirin/lattice/abc.py
47
48
49
50
@abstractmethod
def is_subseteq(self, other: LatticeType) -> bool:
    """Subseteq operation."""
    ...

join abstractmethod

join(other: LatticeType) -> LatticeType

Join operation.

Source code in src/kirin/lattice/abc.py
37
38
39
40
@abstractmethod
def join(self, other: LatticeType) -> LatticeType:
    """Join operation."""
    ...

meet abstractmethod

meet(other: LatticeType) -> LatticeType

Meet operation.

Source code in src/kirin/lattice/abc.py
42
43
44
45
@abstractmethod
def meet(self, other: LatticeType) -> LatticeType:
    """Meet operation."""
    ...

SingletonMeta

SingletonMeta(name, bases, attrs)

Bases: LatticeMeta

Singleton metaclass for lattices. It ensures that only one instance of a lattice is created.

See https://stackoverflow.com/questions/674304/why-is-init-always-called-after-new/8665179#8665179

Source code in src/kirin/lattice/abc.py
16
17
18
def __init__(cls, name, bases, attrs):
    super().__init__(name, bases, attrs)
    cls._instance = None

UnionMeta

UnionMeta(name, bases, attrs)

Bases: LatticeMeta

Meta class for union types. It simplifies the union if possible.

Source code in src/kirin/lattice/abc.py
93
94
95
96
97
def __init__(self, name, bases, attrs):
    super().__init__(name, bases, attrs)
    if not issubclass(base := bases[0], BoundedLattice):
        raise TypeError(f"Union must inherit from Lattice, got {bases[0]}")
    self._bottom = base.bottom()