2013-07-30 03:59:15 +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
|
|
|
|
*/
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "util/name.h"
|
|
|
|
#include "kernel/expr.h"
|
|
|
|
#include "kernel/abstract.h"
|
|
|
|
#include "kernel/instantiate.h"
|
|
|
|
#include "kernel/expr_maps.h"
|
2013-12-03 20:40:52 +00:00
|
|
|
#include "kernel/replace_fn.h"
|
2014-08-22 17:32:01 +00:00
|
|
|
#include "library/print.h"
|
2013-07-30 03:59:15 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
|
|
|
expr mk_big(expr f, unsigned depth, unsigned val) {
|
|
|
|
if (depth == 1)
|
2013-09-24 18:01:30 +00:00
|
|
|
return mk_constant(name(name("foo"), val));
|
2013-07-30 03:59:15 +00:00
|
|
|
else
|
|
|
|
return f(mk_big(f, depth - 1, val << 1), mk_big(f, depth - 1, (val << 1) + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst1() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
2013-07-30 03:59:15 +00:00
|
|
|
expr r = mk_big(f, 16, 0);
|
2013-09-24 18:01:30 +00:00
|
|
|
expr n = Const(name("foo"));
|
2013-07-30 03:59:15 +00:00
|
|
|
for (unsigned i = 0; i < 20; i++) {
|
2013-08-03 19:20:01 +00:00
|
|
|
r = abstract(r, n);
|
2013-07-30 03:59:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-03 18:27:03 +00:00
|
|
|
static void tst2() {
|
2014-02-18 01:04:22 +00:00
|
|
|
expr r = mk_lambda("x", Type, mk_app({Var(0), Var(1), Var(2)}));
|
2014-04-17 20:12:49 +00:00
|
|
|
std::cout << instantiate(r, Const("a")) << std::endl;
|
|
|
|
lean_assert(instantiate(r, Const("a")) == mk_lambda("x", Type, mk_app({Var(0), Const("a"), Var(1)})));
|
|
|
|
lean_assert(instantiate(instantiate(r, Const("a")), Const("b")) ==
|
2014-02-18 01:04:22 +00:00
|
|
|
mk_lambda("x", Type, mk_app({Var(0), Const("a"), Const("b")})));
|
2014-05-16 18:13:50 +00:00
|
|
|
std::cout << instantiate(binding_body(r), Const("a")) << std::endl;
|
|
|
|
lean_assert(instantiate(binding_body(r), Const("a")) == mk_app({Const("a"), Var(0), Var(1)}));
|
2013-08-06 18:27:14 +00:00
|
|
|
std::cout << instantiate(r, Var(10)) << std::endl;
|
2014-02-18 01:04:22 +00:00
|
|
|
lean_assert(instantiate(r, Var(10)) == mk_lambda("x", Type, mk_app({Var(0), Var(11), Var(1)})));
|
2013-08-06 18:27:14 +00:00
|
|
|
std::cout << mk_pi("_", Var(3), Var(4)) << std::endl;
|
|
|
|
std::cout << instantiate(mk_pi("_", Var(3), Var(4)), Var(0)) << std::endl;
|
|
|
|
lean_assert(instantiate(mk_pi("_", Var(3), Var(4)), Var(0)) == mk_pi("_", Var(2), Var(3)));
|
2013-08-03 19:20:01 +00:00
|
|
|
}
|
2013-08-03 18:27:03 +00:00
|
|
|
|
2013-08-28 17:47:19 +00:00
|
|
|
class tracer {
|
|
|
|
expr_map<expr> & m_trace;
|
|
|
|
public:
|
|
|
|
tracer(expr_map<expr> & trace):m_trace(trace) {}
|
|
|
|
|
|
|
|
void operator()(expr const & old_e, expr const & new_e) {
|
|
|
|
if (!is_eqp(new_e, old_e)) {
|
|
|
|
m_trace[new_e] = old_e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-30 03:59:15 +00:00
|
|
|
int main() {
|
2013-12-07 22:59:21 +00:00
|
|
|
save_stack_info();
|
2014-08-22 17:26:45 +00:00
|
|
|
init_default_print_fn();
|
2013-07-30 03:59:15 +00:00
|
|
|
tst1();
|
2013-08-03 18:27:03 +00:00
|
|
|
tst2();
|
2013-07-30 03:59:15 +00:00
|
|
|
std::cout << "done" << "\n";
|
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|