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)
|
|
|
|
return constant(name(val));
|
|
|
|
else
|
|
|
|
return f(mk_big(f, depth - 1, val << 1), mk_big(f, depth - 1, (val << 1) + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst1() {
|
|
|
|
expr f = constant("f");
|
|
|
|
expr r = mk_big(f, 16, 0);
|
|
|
|
expr n = constant(name(0u));
|
|
|
|
for (unsigned i = 0; i < 20; i++) {
|
|
|
|
r = abstract(n, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-03 18:27:03 +00:00
|
|
|
static void tst2() {
|
|
|
|
expr r = lambda("x", type(level()), app(var(0), var(1), var(2)));
|
2013-08-03 18:45:51 +00:00
|
|
|
std::cout << instantiate_with_closed(constant("a"), r) << std::endl;
|
|
|
|
lean_assert(instantiate_with_closed(constant("a"), r) == lambda("x", type(level()), app(var(0), constant("a"), var(1))));
|
|
|
|
lean_assert(instantiate_with_closed(constant("b"), instantiate_with_closed(constant("a"), r)) ==
|
2013-08-03 18:27:03 +00:00
|
|
|
lambda("x", type(level()), app(var(0), constant("a"), constant("b"))));
|
2013-08-03 18:45:51 +00:00
|
|
|
std::cout << instantiate_with_closed(constant("a"), abst_body(r)) << std::endl;
|
|
|
|
lean_assert(instantiate_with_closed(constant("a"), abst_body(r)) == app(constant("a"), var(0), var(1)));
|
|
|
|
std::cout << instantiate(var(10), r) << std::endl;
|
|
|
|
lean_assert(instantiate(var(10), r) == lambda("x", type(level()), app(var(0), var(11), var(1))));
|
|
|
|
}
|
2013-08-03 18:27:03 +00:00
|
|
|
|
2013-07-30 03:59:15 +00:00
|
|
|
int main() {
|
|
|
|
continue_on_violation(true);
|
|
|
|
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;
|
|
|
|
}
|