HOL.Terms (hol v1.0.1)
View SourceThis module gives functions for creating terms, applications and abstractions.
Examples
iex> var_x = HOL.Data.mk_free_var("x", mk_type(:i))
iex> const_f = HOL.Data.mk_const("f", mk_type(:i, [mk_type(:i)]))
iex> application = mk_appl_term(mk_term(const_f), mk_term(var_x))
iex> PrettyPrint.pp_term(application)
"(f x)"
iex> abstraction = mk_abstr_term(application, var_x)
iex> PrettyPrint.pp_term(abstraction)
"(1. f 1)"
iex> mk_appl_term(abstraction, mk_const_term("c", mk_type(:i))) |> PrettyPrint.pp_term()
"(f c)"
Summary
Functions
Adjusts all bound variables so that the innermost terms have the lowest bound variables.
Adjusts the outer layer of bound variables so that those bound variables are as small as possible without overlapping with bound variables defined in the arguments
Abstracts a free variable from a term by replacing it with a bound variable.
Applies one term to another.
Creates a term with a free variable as head, that has the given name and type.
Creates a term with a free variable as head, that has the given name and type.
Creates a term from a declaration with this declaration as the head. Terms are always eta-expanded.
Functions
@spec adjust_all_bound_vars(HOL.Data.hol_term()) :: HOL.Data.hol_term()
Adjusts all bound variables so that the innermost terms have the lowest bound variables.
Warning
This function can break if it is applied to terms with bound variables that are not bound anywhere!
This function is only needed when interacting with terms in unusual ways.
Using mk_abstr_term/2
or mk_appl_term/2
applies this function automatically.
@spec adjust_outer_bound_vars(HOL.Data.hol_term()) :: HOL.Data.hol_term()
Adjusts the outer layer of bound variables so that those bound variables are as small as possible without overlapping with bound variables defined in the arguments
Warning
This function can break if it is applied to terms with bound variables that are not bound anywhere!
This function is only needed when interacting with terms in unusual ways.
Using mk_abstr_term/2
or mk_appl_term/2
applies this function automatically.
@spec mk_abstr_term( HOL.Data.hol_term(), HOL.Data.free_var_decl() | HOL.Data.bound_var_decl() ) :: HOL.Data.hol_term()
Abstracts a free variable from a term by replacing it with a bound variable.
Only free variables can be abstracted.
Parameters
- term: Term in which to abstract a variable
- var: Free Variable to abstract
Examples
iex> var_x = mk_free_var("x", mk_type(:i))
iex> term_f = mk_const_term("f", mk_type(:i, [mk_type(:i)]))
iex> application = mk_appl_term(term_f, mk_term(var_x))
iex> PrettyPrint.pp_term(application)
"(f x)"
iex> abstraction = mk_abstr_term(application, var_x)
iex> PrettyPrint.pp_term(abstraction)
"(1. f 1)"
@spec mk_appl_term(HOL.Data.hol_term(), HOL.Data.hol_term()) :: HOL.Data.hol_term()
Applies one term to another.
Example
iex> var_x = mk_free_var("x", mk_type(:i))
iex> term_f = mk_const_term("f", mk_type(:i, [mk_type(:i)]))
iex> application = mk_appl_term(term_f, mk_term(var_x))
iex> PrettyPrint.pp_term(application)
"(f x)"
iex> abstraction = mk_abstr_term(application, var_x)
iex> PrettyPrint.pp_term(abstraction)
"(1. f 1)"
iex> mk_appl_term(abstraction, mk_const_term("c", mk_type(:i))) |> PrettyPrint.pp_term()
"(f c)"
@spec mk_const_term(String.t(), HOL.Data.type()) :: HOL.Data.hol_term()
Creates a term with a free variable as head, that has the given name and type.
@spec mk_free_var_term(String.t() | reference(), HOL.Data.type()) :: HOL.Data.hol_term()
Creates a term with a free variable as head, that has the given name and type.
@spec mk_term(HOL.Data.declaration()) :: HOL.Data.hol_term()
Creates a term from a declaration with this declaration as the head. Terms are always eta-expanded.
Also see mk_free_var_term/2
and mk_const_term/2
to create a term, without first creating a declaration.
Example
iex> mk_term(HOL.Data.mk_const("x", mk_type(:i)))
{:term, [], {:decl, :co, "x", {:type, :i, []}}, [], mk_type(:i), [], 0}