HOL.Data (hol v1.0.1)

View Source

This module defines the datastructures used in the application

Summary

Types

Represents a bound variable.

Represents a constant.

Combination type representing free variables, bound variables and constants.

Represents a free variable.

Represents a term in the simply typed lambda calculus.

Represents a substitution of a free variable with a term

This type encodes the type information for a HOL term or declaration.

Declaration

Creates a new declaration. This function should not need be called under normal usage of this Package

Accessor function for type of declaration.

Accessor function for the identifier

Accessor function for the type

Creates a bound variable with the given id and type.

Creates a constant with the given name and type.

Creates a free variable with the given name and type.

Creates a free variable with a unique name and type.

Substitution

Accessor function for the free variable of the substitution

Accessor function for the term of the substitution

Creates a new substitution

Creates a new substitution.

Term

Accessor function for the arguments of the term

Accessor function for the bound variables of the term

Accessor function for the free variables in the term

Accessor function for head of the term

Accessor function for the max_num of the term

Accessor function for the type of the term

Creates a new term.

Type

Accessor function for argument types

Accessor function for goal type

Creates a base type without arguments.

Creates a type with the given arguments.

Creates a new type. This function should not need be called under normal usage of this Package

Types

bound_var_decl()

@type bound_var_decl() :: {:decl, :bv, pos_integer(), type()}

Represents a bound variable.

The name must be a positive integer.

const_decl()

@type const_decl() :: {:decl, :co, String.t(), type()}

Represents a constant.

The name must be a string.

declaration()

@type declaration() :: free_var_decl() | const_decl() | bound_var_decl()

Combination type representing free variables, bound variables and constants.

Key Data storedAccessor Function
:kindWhether it is a free or bound variable or constantget_kind/1
:nameNameget_name/1
:typeTypeget_type/1

free_var_decl()

@type free_var_decl() :: {:decl, :fv, String.t() | reference(), type()}

Represents a free variable.

The name can be either a string or a reference.

hol_term()

@type hol_term() ::
  {:term, bvars :: [bound_var_decl()], head :: declaration(),
   args :: [hol_term()], type :: type(), fvars :: [free_var_decl()],
   max_num :: non_neg_integer()}

Represents a term in the simply typed lambda calculus.

Terms are always automatically beta-reduced and eta-expanded.

Key Data storedAccessor Function
:bvarsA list of bound variables that are bound hereget_bvars/1
:headThe head of the termget_head/1
:argsA list of terms that are applied to the headget_args/1
:typeThe type of the termget_term_type/1
:fvarsA list of all free variables in the termget_fvars/1
:max_numThe highest bound variable that is bound here or in one of the argsget_max_num/1

substitution()

@type substitution() :: {:subst, fvar :: free_var_decl(), term :: hol_term()}

Represents a substitution of a free variable with a term

KeyData storedAccessor Function
:fvarFree Variable to Replaceget_fvar/1
:termReplacement Termget_term/1

type()

@type type() :: {:type, goal :: atom(), args :: [type()]}

This type encodes the type information for a HOL term or declaration.

It has its goal type stored as an atom, with all input types in a list.

Key Data storedAccessor Function
:goalGoal Typeget_goal_type/1
:argsList of argument typesget_arg_types/1

Examples

# base type i is encoded as
  iex> mk_type(:i)
  {:type, :i, []}

  # function type i->o is encoded as
  iex> mk_type(:o, [mk_type(:i)])
  {:type, :o, [{:type, :i, []}]}

Functions

declaration(record, args)

(macro)

hol_term(record, args)

(macro)

substitution(record, args)

(macro)

type(record, args)

(macro)

Declaration

declaration(args \\ [])

(macro)

Creates a new declaration. This function should not need be called under normal usage of this Package

This Dataformat uses a Record.

get_kind(arg)

@spec get_kind(declaration()) :: :fv | :bv | :co

Accessor function for type of declaration.

Returns

  • :fv when given a free variable
  • :bv when given a bound variable
  • :co when given a constant

get_name(arg)

@spec get_name(declaration()) :: String.t() | pos_integer() | reference()

Accessor function for the identifier

get_type(arg)

@spec get_type(declaration()) :: type()

Accessor function for the type

mk_bound_var(nat, type)

@spec mk_bound_var(non_neg_integer(), type()) :: bound_var_decl()

Creates a bound variable with the given id and type.

This function should not need be called under normal usage of this Package

Example

iex> mk_bound_var(1, mk_type(:i))
{:decl, :bv, 1, {:type, :i, []}}

mk_const(id, type)

@spec mk_const(String.t(), type()) :: const_decl()

Creates a constant with the given name and type.

Example

iex> mk_const("x", mk_type(:i))
{:decl, :co, "x", {:type, :i, []}}

mk_free_var(name, type)

@spec mk_free_var(String.t(), type()) :: free_var_decl()

Creates a free variable with the given name and type.

Also see function mk_uniqe_var/1 for creating a uniqe variable

Example

iex> mk_free_var("x", mk_type(:i))
{:decl, :fv, "x", {:type, :i, []}}

mk_uniqe_var(type)

@spec mk_uniqe_var(type()) :: free_var_decl()

Creates a free variable with a unique name and type.

The name is created via the function Kernel.make_ref/0. See the corresponding documentation for the limitations of this function.

Also see function mk_free_var/2 for creating a named free variable

Substitution

get_fvar(arg)

@spec get_fvar(substitution()) :: free_var_decl()

Accessor function for the free variable of the substitution

get_term(arg)

@spec get_term(substitution()) :: hol_term()

Accessor function for the term of the substitution

mk_substitution(fvar, term)

@spec mk_substitution(free_var_decl(), hol_term()) :: substitution()

Creates a new substitution

substitution(args \\ [])

(macro)

Creates a new substitution.

This Dataformat uses a Record.

Term

get_args(arg)

@spec get_args(hol_term()) :: [hol_term()]

Accessor function for the arguments of the term

get_bvars(arg)

@spec get_bvars(hol_term()) :: [bound_var_decl()]

Accessor function for the bound variables of the term

get_fvars(arg)

@spec get_fvars(hol_term()) :: [free_var_decl()]

Accessor function for the free variables in the term

get_head(arg)

@spec get_head(hol_term()) :: declaration()

Accessor function for head of the term

get_max_num(arg)

@spec get_max_num(hol_term()) :: non_neg_integer()

Accessor function for the max_num of the term

get_term_type(arg)

@spec get_term_type(hol_term()) :: type()

Accessor function for the type of the term

hol_term(args \\ [])

(macro)

Creates a new term.

For creating new terms see HOL.Terms.mk_term/1

This function should not need be called under normal usage of this Package.

This Dataformat uses a Record.

Type

get_arg_types(t)

@spec get_arg_types(type()) :: [type()]

Accessor function for argument types

get_goal_type(t)

@spec get_goal_type(type()) :: atom()

Accessor function for goal type

mk_type(goal_type)

@spec mk_type(atom()) :: type()

Creates a base type without arguments.

Examples

# Creates base type i
iex> mk_type(:i)
{:type, :i, []}

# Creates base type o
iex> mk_type(:o)
{:type, :o, []}

mk_type(goal_type, arg_types)

@spec mk_type(atom(), [type()]) :: type()
@spec mk_type(type(), [type()]) :: type()

Creates a type with the given arguments.

The goal type is always stored as an atom, but it doesn't have to be given as such

Parameters

  • goal_type: Atom or type() that represents the goal type
  • arg_types: List of type() that represents the argument types

Examples

# Creates type i->i
iex> mk_type(:i, [mk_type(:i)])
{:type, :i, [{:type, :i, []}]}

# Creates type i->i->i
iex> mk_type(mk_type(:o, [mk_type(:i)]), [mk_type(:i)])
{:type, :o, [{:type, :i, []}, {:type, :i, []}]}

# Creates type i->i->i (identical to previous)
iex> mk_type(:o, [mk_type(:i), mk_type(:i)])
{:type, :o, [{:type, :i, []}, {:type, :i, []}]}

# Creates type (i->i)->i->i
iex> mk_type(:i, [mk_type(:i, [mk_type(:i)]), mk_type(:i)])
{:type, :i, [{:type, :i, [{:type, :i, []}]}, {:type, :i, []}]}

type(args \\ [])

(macro)

Creates a new type. This function should not need be called under normal usage of this Package

This Dataformat uses a Record.