2013-07-24 07:32:01 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2013-09-13 10:35:29 +00:00
|
|
|
#include <utility>
|
|
|
|
#include "kernel/expr.h"
|
2013-07-24 07:32:01 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
|
|
|
\brief Replace the expressions s[0], ..., s[n-1] in e with var(n-1), ..., var(0).
|
|
|
|
|
|
|
|
Structural equality is used to compare subexpressions of e with the s[i]'s.
|
|
|
|
|
|
|
|
\pre s[0], ..., s[n-1] must be closed expressions (i.e., no free variables).
|
|
|
|
*/
|
2013-08-03 19:20:01 +00:00
|
|
|
expr abstract(expr const & e, unsigned n, expr const * s);
|
|
|
|
inline expr abstract(expr const & e, expr const & s) { return abstract(e, 1, &s); }
|
2014-01-26 00:54:42 +00:00
|
|
|
inline expr abstract(expr const & e, std::initializer_list<expr> const & l) { return abstract(e, l.size(), l.begin()); }
|
2014-05-17 17:51:40 +00:00
|
|
|
/** \brief Replace s with variable #i in the given expression. \pre s is closed */
|
2014-05-17 00:47:04 +00:00
|
|
|
expr abstract(expr const & e, expr const & s, unsigned i);
|
2013-07-24 07:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Replace the expressions s[0], ..., s[n-1] in e with var(n-1), ..., var(0).
|
|
|
|
|
|
|
|
Pointer comparison is used to compare subexpressions of e with the s[i]'s.
|
|
|
|
|
|
|
|
\pre s[0], ..., s[n-1] must be closed expressions (i.e., no free variables).
|
|
|
|
*/
|
2013-08-03 19:20:01 +00:00
|
|
|
expr abstract_p(expr const & e, unsigned n, expr const * s);
|
|
|
|
inline expr abstract_p(expr const & e, expr const & s) { return abstract_p(e, 1, &s); }
|
2013-08-02 04:28:26 +00:00
|
|
|
|
|
|
|
/**
|
2013-08-03 19:20:01 +00:00
|
|
|
\brief Create a lambda expression (lambda (x : t) b), the term b is abstracted using abstract(b, constant(x)).
|
2013-08-02 04:28:26 +00:00
|
|
|
*/
|
2014-05-16 21:09:00 +00:00
|
|
|
inline expr Fun(name const & n, expr const & t, expr const & b, binder_info const & bi = binder_info()) {
|
|
|
|
return mk_lambda(n, t, abstract(b, mk_constant(n)), bi);
|
|
|
|
}
|
|
|
|
inline expr Fun(expr const & n, expr const & t, expr const & b, binder_info const & bi = binder_info()) {
|
2014-05-20 00:03:48 +00:00
|
|
|
return mk_lambda(named_expr_name(n), t, abstract(b, n), bi);
|
2014-05-16 21:09:00 +00:00
|
|
|
}
|
2013-08-06 18:27:14 +00:00
|
|
|
inline expr Fun(std::pair<expr const &, expr const &> const & p, expr const & b) { return Fun(p.first, p.second, b); }
|
2014-05-16 21:09:00 +00:00
|
|
|
expr Fun(std::initializer_list<std::pair<expr const &, expr const &>> const & l, expr const & b);
|
2014-05-19 16:01:20 +00:00
|
|
|
/** \brief Create a lambda-expression by abstracting the given local constants over b */
|
|
|
|
expr Fun(unsigned num, expr const * locals, expr const & b);
|
|
|
|
template<typename T> expr Fun(T const & locals, expr const & b) { return Fun(locals.size(), locals.data(), b); }
|
2014-05-31 04:05:47 +00:00
|
|
|
inline expr Fun(expr const & local, expr const & b, binder_info const & bi = binder_info()) {
|
|
|
|
return Fun(local_pp_name(local), mlocal_type(local), abstract(b, local), bi);
|
|
|
|
}
|
2013-08-06 18:27:14 +00:00
|
|
|
|
2013-08-02 04:28:26 +00:00
|
|
|
/**
|
2013-08-03 19:20:01 +00:00
|
|
|
\brief Create a Pi expression (pi (x : t) b), the term b is abstracted using abstract(b, constant(x)).
|
2013-08-02 04:28:26 +00:00
|
|
|
*/
|
2014-05-16 21:09:00 +00:00
|
|
|
inline expr Pi(name const & n, expr const & t, expr const & b, binder_info const & bi = binder_info()) {
|
|
|
|
return mk_pi(n, t, abstract(b, mk_constant(n)), bi);
|
|
|
|
}
|
|
|
|
inline expr Pi(expr const & n, expr const & t, expr const & b, binder_info const & bi = binder_info()) {
|
2014-05-20 00:03:48 +00:00
|
|
|
return mk_pi(named_expr_name(n), t, abstract(b, n), bi);
|
2014-05-16 21:09:00 +00:00
|
|
|
}
|
2013-08-06 18:27:14 +00:00
|
|
|
inline expr Pi(std::pair<expr const &, expr const &> const & p, expr const & b) { return Pi(p.first, p.second, b); }
|
2014-05-16 21:09:00 +00:00
|
|
|
expr Pi(std::initializer_list<std::pair<expr const &, expr const &>> const & l, expr const & b);
|
2014-05-18 20:15:00 +00:00
|
|
|
/** \brief Create a Pi-expression by abstracting the given local constants over b */
|
|
|
|
expr Pi(unsigned num, expr const * locals, expr const & b);
|
|
|
|
template<typename T> expr Pi(T const & locals, expr const & b) { return Pi(locals.size(), locals.data(), b); }
|
2014-06-12 03:56:10 +00:00
|
|
|
inline expr Pi(expr const & local, expr const & b, binder_info const & bi = binder_info()) {
|
|
|
|
return Pi(local_pp_name(local), mlocal_type(local), abstract(b, local), bi);
|
|
|
|
}
|
2013-09-06 17:06:26 +00:00
|
|
|
/**
|
2014-02-19 17:48:28 +00:00
|
|
|
- \brief Create a Let expression (Let x := v in b), the term b is abstracted using abstract(b, x).
|
|
|
|
-*/
|
2013-09-06 17:06:26 +00:00
|
|
|
inline expr Let(name const & x, expr const & t, expr const & v, expr const & b) { return mk_let(x, t, v, abstract(b, mk_constant(x))); }
|
2014-05-20 00:03:48 +00:00
|
|
|
inline expr Let(expr const & x, expr const & t, expr const & v, expr const & b) { return mk_let(named_expr_name(x), t, v, abstract(b, x)); }
|
2013-07-24 07:32:01 +00:00
|
|
|
}
|