Let#

class discopy.closed.Let(expression, variables, body)[source]#

Bases: Compound

The evaluation of an expression term, binding a tuple of variables to the factors of its result inside a body term, i.e. the statement let (x, ..., z) = expression in body.

Parameters:
  • expression (Term) – The term that is evaluated.

  • variables (tuple[Variable, ...]) – The variables binding the factors of the result.

  • body (Term) – The term in which the variables are bound.

Note

The codomain of expression unpacks either as the factors of its Product type or as the tensor of the variables’ types. Bound variables may be discarded or copied by the body, see let() for the introspection helper that builds the statement from a function.

Example

>>> X, Y = Ty("X"), Ty("Y")
>>> f, x, y = (X >> Y)("f"), Variable("x", X), Variable("y", Y)
>>> term = Let(f(x), (y, ), Tuple(y, y))
>>> print(term)
let(f(x), lambda y: Tuple(y, y))
>>> assert term.cod == Y * Y and not term.is_linear
property name#

The term as printed, computed once from its parts when first read.

property rest: list[Variable]#

The free variables of the body that the statement does not bind.

property constants#

The constants of the term, in order of occurrence.