2015-01-29 02:40:21 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
2015-11-01 20:02:49 +00:00
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "library/io_state.h"
|
|
|
|
#include "library/reducible.h"
|
2015-11-01 20:07:21 +00:00
|
|
|
#include "library/tmp_type_context.h"
|
2015-01-29 02:40:21 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2015-11-08 21:05:41 +00:00
|
|
|
class app_builder_exception : public exception {
|
|
|
|
public:
|
|
|
|
// We may provide more information in the future.
|
|
|
|
app_builder_exception():exception("app_builder_exception") {}
|
|
|
|
};
|
|
|
|
|
2015-01-29 02:40:21 +00:00
|
|
|
/** \brief Helper for creating simple applications where some arguments are inferred using
|
|
|
|
type inference.
|
|
|
|
|
|
|
|
Example, given
|
|
|
|
rel.{l_1 l_2} : Pi (A : Type.{l_1}) (B : A -> Type.{l_2}), (Pi x : A, B x) -> (Pi x : A, B x) -> , Prop
|
|
|
|
nat : Type.{1}
|
|
|
|
real : Type.{1}
|
|
|
|
vec.{l} : Pi (A : Type.{l}) (n : nat), Type.{l1}
|
|
|
|
f g : Pi (n : nat), vec real n
|
|
|
|
then
|
|
|
|
builder.mk_app(rel, f, g)
|
|
|
|
returns the application
|
|
|
|
rel.{1 2} nat (fun n : nat, vec real n) f g
|
|
|
|
*/
|
|
|
|
class app_builder {
|
|
|
|
struct imp;
|
|
|
|
std::unique_ptr<imp> m_ptr;
|
|
|
|
public:
|
2015-11-01 20:02:49 +00:00
|
|
|
app_builder(environment const & env, io_state const & ios, reducible_behavior b = UnfoldReducible);
|
|
|
|
app_builder(environment const & env, reducible_behavior b = UnfoldReducible);
|
2015-11-05 00:33:24 +00:00
|
|
|
app_builder(tmp_type_context & ctx);
|
2015-07-27 21:47:41 +00:00
|
|
|
~app_builder();
|
2015-11-05 00:33:24 +00:00
|
|
|
|
2015-01-29 02:40:21 +00:00
|
|
|
/** \brief Create an application (d.{_ ... _} _ ... _ args[0] ... args[nargs-1]).
|
|
|
|
The missing arguments and universes levels are inferred using type inference.
|
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
\remark The method throwns an app_builder_exception if: not all arguments can be inferred;
|
2015-01-29 02:40:21 +00:00
|
|
|
or constraints are created during type inference; or an exception is thrown
|
|
|
|
during type inference.
|
|
|
|
|
|
|
|
\remark This methods uses just higher-order pattern matching.
|
|
|
|
*/
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_app(name const & c, unsigned nargs, expr const * args);
|
2015-01-29 02:40:21 +00:00
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_app(name const & c, std::initializer_list<expr> const & args) {
|
2015-11-01 20:02:49 +00:00
|
|
|
return mk_app(c, args.size(), args.begin());
|
|
|
|
}
|
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_app(name const & c, expr const & a1) {
|
2015-11-01 20:02:49 +00:00
|
|
|
return mk_app(c, {a1});
|
|
|
|
}
|
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_app(name const & c, expr const & a1, expr const & a2) {
|
2015-11-01 20:02:49 +00:00
|
|
|
return mk_app(c, {a1, a2});
|
|
|
|
}
|
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_app(name const & c, expr const & a1, expr const & a2, expr const & a3) {
|
2015-11-01 20:02:49 +00:00
|
|
|
return mk_app(c, {a1, a2, a3});
|
|
|
|
}
|
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_app(name const & c, unsigned mask_sz, bool const * mask, expr const * args);
|
2015-11-01 20:12:41 +00:00
|
|
|
|
2015-11-02 00:25:14 +00:00
|
|
|
/** \brief Similar to mk_app(n, lhs, rhs), but handles eq and iff more efficiently. */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_rel(name const & n, expr const & lhs, expr const & rhs);
|
|
|
|
expr mk_eq(expr const & lhs, expr const & rhs);
|
|
|
|
expr mk_iff(expr const & lhs, expr const & rhs);
|
2015-11-02 00:25:14 +00:00
|
|
|
|
|
|
|
/** \brief Similar a reflexivity proof for the given relation */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_refl(name const & relname, expr const & a);
|
|
|
|
expr mk_eq_refl(expr const & a);
|
|
|
|
expr mk_iff_refl(expr const & a);
|
2015-11-02 00:25:14 +00:00
|
|
|
|
|
|
|
/** \brief Similar a symmetry proof for the given relation */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_symm(name const & relname, expr const & H);
|
|
|
|
expr mk_eq_symm(expr const & H);
|
|
|
|
expr mk_iff_symm(expr const & H);
|
2015-11-02 00:25:14 +00:00
|
|
|
|
|
|
|
/** \brief Similar a transitivity proof for the given relation */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_trans(name const & relname, expr const & H1, expr const & H2);
|
|
|
|
expr mk_eq_trans(expr const & H1, expr const & H2);
|
|
|
|
expr mk_iff_trans(expr const & H1, expr const & H2);
|
2015-11-02 00:25:14 +00:00
|
|
|
|
2015-11-03 20:20:42 +00:00
|
|
|
/** \brief Create a (non-dependent) eq.rec application.
|
|
|
|
C is the motive. The expected types for C, H1 and H2 are
|
|
|
|
C : A -> Type
|
|
|
|
H1 : C a
|
|
|
|
H2 : a = b
|
|
|
|
The resultant application is
|
|
|
|
@eq.rec A a C H1 b H2
|
|
|
|
In the HoTT library, we actually create an eq.nrec application
|
|
|
|
since eq.rec is a dependent eliminator in HoTT. */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_eq_rec(expr const & C, expr const & H1, expr const & H2);
|
2015-11-03 20:20:42 +00:00
|
|
|
|
|
|
|
/** \brief Create a (dependent) eq.drec application.
|
|
|
|
C is the motive. The expected types for C, H1 and H2 are
|
|
|
|
C : Pi (x : A), a = x -> Type
|
|
|
|
H1 : C a (eq.refl a)
|
|
|
|
H2 : a = b
|
|
|
|
The resultant application is
|
|
|
|
@eq.drec A a C H1 b H2
|
|
|
|
In the HoTT library, we actually create an eq.rec application
|
|
|
|
because eq.rec is a dependent eliminator in HoTT. */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_eq_drec(expr const & C, expr const & H1, expr const & H2);
|
2015-11-03 20:20:42 +00:00
|
|
|
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_congr_arg(expr const & f, expr const & H);
|
|
|
|
expr mk_congr_fun(expr const & H, expr const & a);
|
|
|
|
expr mk_congr(expr const & H1, expr const & H2);
|
2015-11-07 23:00:18 +00:00
|
|
|
|
2015-11-07 19:41:24 +00:00
|
|
|
/** \brief Create (@sorry type) */
|
2015-11-08 21:05:41 +00:00
|
|
|
expr mk_sorry(expr const & type);
|
2015-11-07 19:41:24 +00:00
|
|
|
|
2015-11-11 08:02:47 +00:00
|
|
|
/** \brief False elimination */
|
|
|
|
expr mk_false_rec(expr const & c, expr const & H);
|
|
|
|
|
2015-11-04 19:29:34 +00:00
|
|
|
/** \brief Set the local instances. This method is relevant when we want to expose local class instances
|
2015-11-01 20:12:41 +00:00
|
|
|
to the app_builder.
|
|
|
|
|
2015-11-05 00:33:24 +00:00
|
|
|
\remark When the constructor app_builder(tmp_type_context & ctx) is used
|
2015-11-01 20:12:41 +00:00
|
|
|
the initialization can be performed outside. */
|
2015-11-04 19:29:34 +00:00
|
|
|
void set_local_instances(list<expr> const & insts);
|
2015-01-29 02:40:21 +00:00
|
|
|
};
|
|
|
|
}
|