Skip to content

term

CallTerm dataclass

Bases: TermTree, ABC

A tree term which applies the operator computed by the expression op to args.

Source code in src/finch/symbolic/term.py
 98
 99
100
101
102
103
104
class CallTerm(TermTree, ABC):
    """
    A tree term which applies the operator computed by the expression `op` to `args`.
    """

    op: ExpressionTerm
    args: tuple[Term, ...]

LiteralTerm dataclass

Bases: Term, Generic[T]

A leaf term which wraps the constant val.

Source code in src/finch/symbolic/term.py
89
90
91
92
93
94
95
@dataclass(eq=True, frozen=True)
class LiteralTerm(Term, Generic[T]):
    """
    A leaf term which wraps the constant `val`.
    """

    val: T

Term

Source code in src/finch/symbolic/term.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Term:
    @abstractmethod
    def head(self) -> Callable[..., Self]:
        """Return the head type of the S-expression."""
        ...

    @classmethod
    @abstractmethod
    def make_term(cls, head: Callable[..., Self], *children: Term) -> Self:
        """
        Construct a new term in the same family of terms with the given head type and
        children. This function should satisfy
        `x == x.make_term(x.head(), *x.children)`
        """
        ...

head() abstractmethod

Return the head type of the S-expression.

Source code in src/finch/symbolic/term.py
54
55
56
57
@abstractmethod
def head(self) -> Callable[..., Self]:
    """Return the head type of the S-expression."""
    ...

make_term(head, *children) abstractmethod classmethod

Construct a new term in the same family of terms with the given head type and children. This function should satisfy x == x.make_term(x.head(), *x.children)

Source code in src/finch/symbolic/term.py
59
60
61
62
63
64
65
66
67
@classmethod
@abstractmethod
def make_term(cls, head: Callable[..., Self], *children: Term) -> Self:
    """
    Construct a new term in the same family of terms with the given head type and
    children. This function should satisfy
    `x == x.make_term(x.head(), *x.children)`
    """
    ...

TermTree dataclass

Bases: Term, ABC

Source code in src/finch/symbolic/term.py
80
81
82
83
84
85
86
@dataclass(frozen=True, eq=True)
class TermTree(Term, ABC):
    @property
    @abstractmethod
    def children(self) -> list[Term]:
        """Return the children (AKA tail) of the S-expression."""
        ...

children abstractmethod property

Return the children (AKA tail) of the S-expression.