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
|
|
|
|
*/
|
|
|
|
#include "expr.h"
|
|
|
|
#include "abstract.h"
|
2013-08-03 18:27:03 +00:00
|
|
|
#include "instantiate.h"
|
2013-07-30 03:59:15 +00:00
|
|
|
#include "deep_copy.h"
|
|
|
|
#include "name.h"
|
|
|
|
#include "test.h"
|
|
|
|
using namespace lean;
|
|
|
|
|
|
|
|
expr mk_big(expr f, unsigned depth, unsigned val) {
|
|
|
|
if (depth == 1)
|
2013-08-06 18:27:14 +00:00
|
|
|
return mk_constant(name(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-08-06 18:27:14 +00:00
|
|
|
expr n = Const(name(0u));
|
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() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr r = mk_lambda("x", Type(), mk_app({Var(0), Var(1), Var(2)}));
|
|
|
|
std::cout << instantiate_with_closed(r, Const("a")) << std::endl;
|
|
|
|
lean_assert(instantiate_with_closed(r, Const("a")) == mk_lambda("x", Type(), mk_app({Var(0), Const("a"), Var(1)})));
|
|
|
|
lean_assert(instantiate_with_closed(instantiate_with_closed(r, Const("a")), Const("b")) ==
|
|
|
|
mk_lambda("x", Type(), mk_app({Var(0), Const("a"), Const("b")})));
|
|
|
|
std::cout << instantiate_with_closed(abst_body(r), Const("a")) << std::endl;
|
|
|
|
lean_assert(instantiate_with_closed(abst_body(r), Const("a")) == mk_app({Const("a"), Var(0), Var(1)}));
|
|
|
|
std::cout << instantiate(r, Var(10)) << std::endl;
|
|
|
|
lean_assert(instantiate(r, Var(10)) == mk_lambda("x", Type(), mk_app({Var(0), Var(11), Var(1)})));
|
|
|
|
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-07-30 03:59:15 +00:00
|
|
|
int main() {
|
|
|
|
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;
|
|
|
|
}
|