package lambdapi

  1. Overview
  2. Docs

Module Core.LibTermSource

Basic operations on terms.

Sourceval is_kind : Term.term -> bool

is_kind t tells whether t is of the form Π x1, .., Π xn, TYPE.

Sourceval to_var : Term.term -> Term.var

to_var t returns x if t is of the form Vari x and fails otherwise.

NOTE the Array.map to_var function is useful when working with multiple binders. For example, this is the case when manipulating pattern variables (Patt constructor) or metatavariables (Meta constructor). Remark that it is important for these constructors to hold an array of terms, rather than an array of variables: a variable can only be substituted when if it is injected in a term (using the Vari constructor).

NOTE the result of to_var can generally NOT be precomputed. A first reason is that we cannot know in advance what variable identifier is going to arise when working under binders, for which fresh variables will often be generated. A second reason is that free variables should never be “marshaled” (e.g., by the Sign module), as this would break the freshness invariant of new variables.

Sourceval remove_impl_args : Term.sym -> Term.term list -> Term.term list

Given a symbol s, remove_impl_args s ts returns the non-implicit arguments of s among ts.

Sourceval iter : (Term.term -> unit) -> Term.term -> unit

iter f t applies the function f to every node of the term t with bound variables replaced by Kind. Note: f is called on already unfolded terms only.

Sourceval distinct_vars : Term.ctxt -> Term.term array -> Term.var array option

distinct_vars ctx ts checks that the terms ts are distinct variables. If so, the variables are returned.

Sourceval sym_meta_prefix : char

Symbol name prefix used in sr.ml to replace metavariables that must not be instantiated when type checking the right hand-side of a rule. /!\ This prefix must not be a valid first character of an identifier to not clash with user-defined symbols.

Sourceval nl_distinct_vars : Term.term array -> (Term.var array * Term.var Lplib.Extra.StrMap.t) option

If ts is not made of variables or function symbols prefixed by sym_meta_prefix only, then nl_distinct_vars ts returns None. Otherwise, it returns a pair (vs, map) where vs is an array of variables (of the same size of ts) made of the linear variables of ts and fresh variables for the non-linear variables and the symbols prefixed by sym_meta_prefix, and map records by which variable each linear symbol prefixed by sym_meta_prefix is replaced.

sym_to_var m t replaces in t every symbol f by a variable according to the map map.

Sourceval eq_alpha : Term.term -> Term.term -> bool

eq_alpha a b tests the equality modulo alpha of a and b.

fold id t a returns term binder b with binder name id such that subst b t ≡ a.

Sourceval free_vars : Term.term -> Term.VarSet.t

Free variables of a term.

Sourceval count_products : ?impl:??? -> (Term.ctxt -> Term.term -> Term.term) -> Term.ctxt -> Term.term -> int

count_products impl norm a returns the product arity of the term a, not counting implicit arguments, reducing codomains with norm if needed.