2013-07-22 20:04:27 +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-08-01 22:42:06 +00:00
|
|
|
Soonho Kong
|
2013-07-22 20:04:27 +00:00
|
|
|
*/
|
2013-07-23 18:31:31 +00:00
|
|
|
#include <algorithm>
|
2013-09-13 23:14:24 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "kernel/expr.h"
|
|
|
|
#include "kernel/expr_sets.h"
|
|
|
|
#include "kernel/free_vars.h"
|
|
|
|
#include "kernel/abstract.h"
|
|
|
|
#include "kernel/instantiate.h"
|
2014-01-03 04:03:42 +00:00
|
|
|
#include "kernel/max_sharing.h"
|
2013-07-22 20:04:27 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
2013-12-28 09:16:50 +00:00
|
|
|
static void check_serializer(expr const & e) {
|
|
|
|
std::ostringstream out;
|
|
|
|
serializer s(out);
|
|
|
|
s << e << e;
|
|
|
|
std::cout << "OUT size: " << out.str().size() << "\n";
|
|
|
|
std::istringstream in(out.str());
|
|
|
|
deserializer d(in);
|
|
|
|
expr n1, n2;
|
|
|
|
d >> n1 >> n2;
|
|
|
|
lean_assert(e == n1);
|
|
|
|
lean_assert(e == n2);
|
|
|
|
lean_assert(is_eqp(n1, n2));
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst1() {
|
2013-07-22 20:04:27 +00:00
|
|
|
expr a;
|
2013-08-06 18:27:14 +00:00
|
|
|
a = Const("a");
|
2013-07-22 20:04:27 +00:00
|
|
|
expr f;
|
2013-08-06 18:27:14 +00:00
|
|
|
f = Var(0);
|
2013-07-23 18:56:15 +00:00
|
|
|
expr fa = f(a);
|
2014-02-18 05:47:04 +00:00
|
|
|
expr ty = Type;
|
2013-07-22 20:04:27 +00:00
|
|
|
std::cout << fa << "\n";
|
2013-07-23 18:56:15 +00:00
|
|
|
std::cout << fa(a) << "\n";
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(is_eqp(app_fn(fa), f));
|
|
|
|
lean_assert(is_eqp(app_arg(fa), a));
|
2013-08-04 16:41:49 +00:00
|
|
|
lean_assert(!is_eqp(fa, f(a)));
|
2013-08-06 18:27:14 +00:00
|
|
|
lean_assert(fa(a) == f(a, a));
|
2013-07-23 18:56:15 +00:00
|
|
|
std::cout << fa(fa, fa) << "\n";
|
2013-08-06 18:27:14 +00:00
|
|
|
std::cout << mk_lambda("x", ty, Var(0)) << "\n";
|
2013-07-23 18:56:15 +00:00
|
|
|
lean_assert(f(a)(a) == f(a, a));
|
|
|
|
lean_assert(f(a(a)) != f(a, a));
|
2013-08-06 18:27:14 +00:00
|
|
|
lean_assert(mk_lambda("x", ty, Var(0)) == mk_lambda("y", ty, Var(0)));
|
|
|
|
std::cout << mk_pi("x", ty, Var(0)) << "\n";
|
2013-07-22 20:04:27 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static expr mk_dag(unsigned depth, bool _closed = false) {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr a = _closed ? Const("a") : Var(0);
|
2013-07-22 20:04:27 +00:00
|
|
|
while (depth > 0) {
|
|
|
|
depth--;
|
2013-07-23 18:56:15 +00:00
|
|
|
a = f(a, a);
|
2013-07-22 20:04:27 +00:00
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst2() {
|
2013-07-22 23:40:17 +00:00
|
|
|
expr r1 = mk_dag(20);
|
|
|
|
expr r2 = mk_dag(20);
|
2013-07-24 21:53:45 +00:00
|
|
|
lean_assert(r1 == r2);
|
2014-02-18 05:47:04 +00:00
|
|
|
std::cout << get_depth(r1) << "\n";
|
|
|
|
lean_assert_eq(get_depth(r1), 41);
|
2013-07-22 23:40:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static expr mk_big(expr f, unsigned depth, unsigned val) {
|
2013-07-22 23:40:17 +00:00
|
|
|
if (depth == 1)
|
2013-09-24 18:01:30 +00:00
|
|
|
return Const(name(name("foo"), val));
|
2013-07-22 23:40:17 +00:00
|
|
|
else
|
2013-07-23 18:56:15 +00:00
|
|
|
return f(mk_big(f, depth - 1, val << 1), mk_big(f, depth - 1, (val << 1) + 1));
|
2013-07-22 23:40:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst3() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
2013-12-28 09:16:50 +00:00
|
|
|
expr r1 = mk_big(f, 16, 0);
|
|
|
|
expr r2 = mk_big(f, 16, 0);
|
2013-07-24 21:53:45 +00:00
|
|
|
lean_assert(r1 == r2);
|
2013-12-28 09:16:50 +00:00
|
|
|
check_serializer(r1);
|
2013-07-22 20:04:27 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst4() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr a = Var(0);
|
2013-07-23 00:58:28 +00:00
|
|
|
for (unsigned i = 0; i < 10000; i++) {
|
2013-07-23 18:56:15 +00:00
|
|
|
a = f(a);
|
2013-07-23 00:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static expr mk_redundant_dag(expr f, unsigned depth) {
|
2013-07-23 02:02:11 +00:00
|
|
|
if (depth == 0)
|
2013-08-06 18:27:14 +00:00
|
|
|
return Var(0);
|
2013-07-23 02:02:11 +00:00
|
|
|
else
|
2013-07-23 18:56:15 +00:00
|
|
|
return f(mk_redundant_dag(f, depth - 1), mk_redundant_dag(f, depth - 1));
|
2013-07-23 02:02:11 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static unsigned count_core(expr const & a, expr_set & s) {
|
2013-07-23 02:02:11 +00:00
|
|
|
if (s.find(a) != s.end())
|
|
|
|
return 0;
|
|
|
|
s.insert(a);
|
|
|
|
switch (a.kind()) {
|
2014-02-18 05:47:04 +00:00
|
|
|
case expr_kind::Var: case expr_kind::Constant: case expr_kind::Sort:
|
|
|
|
case expr_kind::Macro: case expr_kind::Meta: case expr_kind::Local:
|
2013-07-23 02:02:11 +00:00
|
|
|
return 1;
|
|
|
|
case expr_kind::App:
|
2014-02-18 05:47:04 +00:00
|
|
|
return count_core(app_fn(a), s) + count_core(app_arg(a), s) + 1;
|
2014-02-04 00:52:49 +00:00
|
|
|
case expr_kind::Lambda: case expr_kind::Pi: case expr_kind::Sigma:
|
2014-02-18 05:47:04 +00:00
|
|
|
return count_core(binder_domain(a), s) + count_core(binder_body(a), s) + 1;
|
2013-08-04 16:37:52 +00:00
|
|
|
case expr_kind::Let:
|
|
|
|
return count_core(let_value(a), s) + count_core(let_body(a), s) + 1;
|
2014-02-18 05:47:04 +00:00
|
|
|
case expr_kind::Fst: case expr_kind::Snd:
|
2014-02-04 00:52:49 +00:00
|
|
|
return count_core(proj_arg(a), s) + 1;
|
|
|
|
case expr_kind::Pair:
|
|
|
|
return count_core(pair_first(a), s) + count_core(pair_second(a), s) + count_core(pair_type(a), s) + 1;
|
2013-07-23 02:02:11 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static unsigned count(expr const & a) {
|
2013-07-23 02:02:11 +00:00
|
|
|
expr_set s;
|
|
|
|
return count_core(a, s);
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst5() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
2013-07-23 02:31:27 +00:00
|
|
|
{
|
|
|
|
expr r1 = mk_redundant_dag(f, 5);
|
2013-07-23 15:59:39 +00:00
|
|
|
expr r2 = max_sharing(r1);
|
2013-07-23 02:31:27 +00:00
|
|
|
std::cout << "count(r1): " << count(r1) << "\n";
|
|
|
|
std::cout << "count(r2): " << count(r2) << "\n";
|
2013-08-02 01:54:06 +00:00
|
|
|
std::cout << "r1 = " << std::endl;
|
2013-08-16 01:54:01 +00:00
|
|
|
std::cout << r1 << std::endl;
|
2013-08-02 01:54:06 +00:00
|
|
|
std::cout << "r2 = " << std::endl;
|
2013-08-16 01:54:01 +00:00
|
|
|
std::cout << r2 << std::endl;
|
2013-07-23 02:31:27 +00:00
|
|
|
lean_assert(r1 == r2);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
expr r1 = mk_redundant_dag(f, 16);
|
2013-07-23 15:59:39 +00:00
|
|
|
expr r2 = max_sharing(r1);
|
2013-07-23 02:31:27 +00:00
|
|
|
lean_assert(r1 == r2);
|
|
|
|
}
|
2013-07-23 02:02:11 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst6() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
2013-07-23 15:59:39 +00:00
|
|
|
expr r = mk_redundant_dag(f, 12);
|
|
|
|
for (unsigned i = 0; i < 1000; i++) {
|
|
|
|
r = max_sharing(r);
|
|
|
|
}
|
|
|
|
r = mk_big(f, 16, 0);
|
|
|
|
for (unsigned i = 0; i < 1000000; i++) {
|
|
|
|
r = max_sharing(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst7() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr v = Var(0);
|
2013-09-13 19:49:03 +00:00
|
|
|
expr a1 = max_sharing(f(v, v));
|
|
|
|
expr a2 = max_sharing(f(v, v));
|
2013-08-04 16:41:49 +00:00
|
|
|
lean_assert(!is_eqp(a1, a2));
|
2013-07-23 18:56:15 +00:00
|
|
|
expr b = max_sharing(f(a1, a2));
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(is_eqp(app_arg(app_fn(b)), app_arg(b)));
|
2013-07-23 16:18:18 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst8() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr x = Var(0);
|
|
|
|
expr a = Const("a");
|
|
|
|
expr n = Const("n");
|
2014-02-18 05:47:04 +00:00
|
|
|
expr p = Type;
|
2013-08-06 18:27:14 +00:00
|
|
|
expr y = Var(1);
|
2013-07-23 18:31:31 +00:00
|
|
|
lean_assert(closed(a));
|
|
|
|
lean_assert(!closed(x));
|
|
|
|
lean_assert(closed(f));
|
2013-07-23 18:56:15 +00:00
|
|
|
lean_assert(!closed(f(x)));
|
2013-08-06 18:27:14 +00:00
|
|
|
lean_assert(closed(mk_lambda("x", p, x)));
|
|
|
|
lean_assert(!closed(mk_lambda("x", x, x)));
|
|
|
|
lean_assert(!closed(mk_lambda("x", p, y)));
|
2013-07-23 18:56:15 +00:00
|
|
|
lean_assert(closed(f(f(f(a)))));
|
2013-08-06 18:27:14 +00:00
|
|
|
lean_assert(closed(mk_lambda("x", p, f(f(f(a))))));
|
|
|
|
lean_assert(closed(mk_pi("x", p, x)));
|
|
|
|
lean_assert(!closed(mk_pi("x", x, x)));
|
|
|
|
lean_assert(!closed(mk_pi("x", p, y)));
|
|
|
|
lean_assert(closed(mk_pi("x", p, f(f(f(a))))));
|
|
|
|
lean_assert(closed(mk_lambda("y", p, mk_lambda("x", p, y))));
|
|
|
|
lean_assert(closed(mk_lambda("y", p, mk_app({mk_lambda("x", p, y), Var(0)}))));
|
|
|
|
expr r = mk_lambda("y", p, mk_app({mk_lambda("x", p, y), Var(0)}));
|
2013-07-23 18:31:31 +00:00
|
|
|
lean_assert(closed(r));
|
|
|
|
lean_assert(closed(r));
|
2013-08-06 18:27:14 +00:00
|
|
|
r = mk_lambda("y", p, mk_app({mk_lambda("x", p, y), Var(1)}));
|
2013-07-23 18:31:31 +00:00
|
|
|
lean_assert(!closed(r));
|
2013-08-06 18:27:14 +00:00
|
|
|
r = mk_lambda("y", p, mk_app({mk_lambda("x", p, Var(0)), Var(1)}));
|
2013-07-23 18:31:31 +00:00
|
|
|
lean_assert(!closed(r));
|
2013-08-06 18:27:14 +00:00
|
|
|
lean_assert(closed(mk_lambda("z", p, r)));
|
2013-07-23 18:31:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst9() {
|
2013-07-23 18:31:31 +00:00
|
|
|
expr r = mk_dag(20, true);
|
|
|
|
lean_assert(closed(r));
|
|
|
|
r = mk_dag(20, false);
|
|
|
|
lean_assert(!closed(r));
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst10() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
2013-07-23 18:31:31 +00:00
|
|
|
expr r = mk_big(f, 16, 0);
|
|
|
|
for (unsigned i = 0; i < 1000; i++) {
|
|
|
|
lean_assert(closed(r));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 07:32:01 +00:00
|
|
|
/**
|
|
|
|
\brief Substitute s with t in e.
|
|
|
|
|
|
|
|
\pre s and t must be closed expressions (i.e., no free variables)
|
|
|
|
*/
|
2013-11-18 17:13:34 +00:00
|
|
|
static expr substitute(expr const & e, expr const & s, expr const & t) {
|
2013-12-28 09:16:50 +00:00
|
|
|
check_serializer(e);
|
2013-08-03 19:20:01 +00:00
|
|
|
return instantiate(abstract(e, s), t);
|
2013-07-24 07:32:01 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst11() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr a = Const("a");
|
|
|
|
expr b = Const("b");
|
|
|
|
expr x = Var(0);
|
|
|
|
expr y = Var(1);
|
2014-02-18 05:47:04 +00:00
|
|
|
expr t = Type;
|
2013-08-06 18:27:14 +00:00
|
|
|
std::cout << instantiate(mk_lambda("x", t, f(f(y, b), f(x, y))), f(a)) << "\n";
|
|
|
|
lean_assert(instantiate(mk_lambda("x", t, f(f(y, b), f(x, y))), f(a)) ==
|
|
|
|
mk_lambda("x", t, f(f(f(a), b), f(x, f(a)))));
|
|
|
|
std::cout << abstract(mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))), Const("a")) << "\n";
|
|
|
|
lean_assert(abstract(mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))), Const("a")) ==
|
|
|
|
mk_lambda("x", t, f(Var(1), mk_lambda("y", t, f(b, Var(2))))));
|
|
|
|
std::cout << abstract_p(mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))), Const("a")) << "\n";
|
|
|
|
lean_assert(abstract_p(mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))), Const("a")) ==
|
|
|
|
mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))));
|
|
|
|
std::cout << abstract_p(mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))), a) << "\n";
|
|
|
|
lean_assert(abstract_p(mk_lambda("x", t, f(a, mk_lambda("y", t, f(b, a)))), a) ==
|
|
|
|
mk_lambda("x", t, f(Var(1), mk_lambda("y", t, f(b, Var(2))))));
|
2013-07-24 02:27:13 +00:00
|
|
|
|
2013-08-03 19:20:01 +00:00
|
|
|
lean_assert(substitute(f(f(f(a))), f(a), b) == f(f(b)));
|
2013-07-24 07:04:05 +00:00
|
|
|
}
|
2013-07-24 02:27:13 +00:00
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst12() {
|
2013-08-06 18:27:14 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr v = Var(0);
|
2013-09-13 19:49:03 +00:00
|
|
|
expr a1 = max_sharing(f(v, v));
|
|
|
|
expr a2 = max_sharing(f(v, v));
|
2013-08-04 16:41:49 +00:00
|
|
|
lean_assert(!is_eqp(a1, a2));
|
2013-07-24 19:24:49 +00:00
|
|
|
lean_assert(a1 == a2);
|
|
|
|
max_sharing_fn M;
|
2013-09-13 19:49:03 +00:00
|
|
|
lean_assert(is_eqp(M(f(v, v)), M(f(v, v))));
|
2013-08-04 16:41:49 +00:00
|
|
|
lean_assert(is_eqp(M(a1), M(a2)));
|
2013-07-24 19:24:49 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst13() {
|
2014-02-18 05:47:04 +00:00
|
|
|
expr t0 = Type;
|
|
|
|
expr t1 = mk_sort(mk_succ(mk_succ(level())));
|
2013-12-28 09:16:50 +00:00
|
|
|
check_serializer(t0);
|
|
|
|
check_serializer(t1);
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(sort_level(t1) == mk_succ(mk_succ(level())));
|
2013-07-30 02:44:26 +00:00
|
|
|
lean_assert(t0 != t1);
|
|
|
|
std::cout << t0 << " " << t1 << "\n";
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst14() {
|
2014-02-19 17:48:28 +00:00
|
|
|
expr l = mk_let("a", Bool, Const("b"), Var(0));
|
2013-12-28 09:16:50 +00:00
|
|
|
check_serializer(l);
|
2013-08-04 16:37:52 +00:00
|
|
|
std::cout << l << "\n";
|
|
|
|
lean_assert(closed(l));
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void tst15() {
|
2013-09-13 01:25:38 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr x = Var(0);
|
|
|
|
expr a = Const("a");
|
2014-02-18 05:47:04 +00:00
|
|
|
expr m = mk_metavar("m", Bool);
|
2013-12-28 09:16:50 +00:00
|
|
|
check_serializer(m);
|
2013-09-13 01:25:38 +00:00
|
|
|
lean_assert(has_metavar(m));
|
|
|
|
lean_assert(has_metavar(f(m)));
|
|
|
|
lean_assert(!has_metavar(f(a)));
|
|
|
|
lean_assert(!has_metavar(f(x)));
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(!has_metavar(Pi({a, Type}, a)));
|
|
|
|
lean_assert(!has_metavar(Type));
|
|
|
|
lean_assert(!has_metavar(Fun({a, Type}, a)));
|
|
|
|
lean_assert(has_metavar(Pi({a, Type}, m)));
|
2013-09-13 01:25:38 +00:00
|
|
|
lean_assert(has_metavar(Pi({a, m}, a)));
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(has_metavar(Fun({a, Type}, m)));
|
2013-09-13 01:25:38 +00:00
|
|
|
lean_assert(has_metavar(Fun({a, m}, a)));
|
2014-02-19 17:48:28 +00:00
|
|
|
lean_assert(!has_metavar(Let(a, Type, Bool, a)));
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(!has_metavar(mk_let(name("a"), Type, f(x), f(f(x)))));
|
2013-09-13 01:25:38 +00:00
|
|
|
lean_assert(has_metavar(mk_let(name("a"), m, f(x), f(f(x)))));
|
2014-02-18 05:47:04 +00:00
|
|
|
lean_assert(has_metavar(mk_let(name("a"), Type, f(m), f(f(x)))));
|
|
|
|
lean_assert(has_metavar(mk_let(name("a"), Type, f(x), f(f(m)))));
|
2013-09-13 01:25:38 +00:00
|
|
|
lean_assert(has_metavar(f(a, a, m)));
|
|
|
|
lean_assert(has_metavar(f(a, m, a, a)));
|
|
|
|
lean_assert(!has_metavar(f(a, a, a, a)));
|
2014-02-20 18:07:38 +00:00
|
|
|
lean_assert(!has_metavar(mk_fst(a)));
|
|
|
|
lean_assert(!has_metavar(mk_snd(a)));
|
|
|
|
lean_assert(has_metavar(mk_fst(m)));
|
|
|
|
lean_assert(has_metavar(mk_snd(m)));
|
|
|
|
lean_assert(!has_metavar(mk_pair(a, x, x)));
|
|
|
|
lean_assert(has_metavar(mk_pair(f(m), x, x)));
|
|
|
|
lean_assert(has_metavar(mk_pair(f(a), m, x)));
|
|
|
|
lean_assert(has_metavar(mk_pair(f(a), a, m)));
|
|
|
|
lean_assert(has_metavar(mk_pair(f(a), a, f(m))));
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 17:13:34 +00:00
|
|
|
static void check_copy(expr const & e) {
|
|
|
|
expr c = copy(e);
|
|
|
|
lean_assert(!is_eqp(e, c));
|
|
|
|
lean_assert(e == c);
|
2013-12-28 09:16:50 +00:00
|
|
|
check_serializer(e);
|
2013-11-18 17:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tst16() {
|
|
|
|
expr f = Const("f");
|
|
|
|
expr a = Const("a");
|
|
|
|
check_copy(f(a));
|
2014-02-18 05:47:04 +00:00
|
|
|
check_copy(mk_metavar("M", Bool));
|
2013-11-18 17:13:34 +00:00
|
|
|
check_copy(mk_lambda("x", a, Var(0)));
|
|
|
|
check_copy(mk_pi("x", a, Var(0)));
|
2014-02-19 17:48:28 +00:00
|
|
|
check_copy(mk_let("x", Bool, a, Var(0)));
|
2013-11-18 17:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tst17() {
|
2014-01-16 01:09:46 +00:00
|
|
|
expr f = Const("f");
|
|
|
|
expr a = Const("a");
|
|
|
|
expr b = Const("b");
|
|
|
|
expr c = Const("c");
|
|
|
|
buffer<expr> args;
|
|
|
|
args.push_back(f);
|
|
|
|
for (unsigned i = 0; i < 200; i++) {
|
|
|
|
args.push_back(a);
|
|
|
|
args.push_back(b);
|
|
|
|
}
|
|
|
|
args.push_back(c);
|
|
|
|
expr t = mk_app(args);
|
|
|
|
check_serializer(t);
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:07:38 +00:00
|
|
|
static void tst18() {
|
|
|
|
expr f = Const("f");
|
|
|
|
expr x = Var(0);
|
|
|
|
expr a = Const("a");
|
|
|
|
expr l = mk_local("m", Bool);
|
|
|
|
expr m = mk_metavar("m", Bool);
|
|
|
|
check_serializer(l);
|
|
|
|
lean_assert(!has_local(m));
|
|
|
|
lean_assert(has_local(l));
|
|
|
|
lean_assert(!has_local(f(m)));
|
|
|
|
lean_assert(has_local(f(l)));
|
|
|
|
lean_assert(!has_local(f(a)));
|
|
|
|
lean_assert(!has_local(f(x)));
|
|
|
|
lean_assert(!has_local(Pi({a, Type}, a)));
|
|
|
|
lean_assert(!has_local(Pi({a, m}, a)));
|
|
|
|
lean_assert(!has_local(Type));
|
|
|
|
lean_assert(!has_local(Pi({a, Type}, a)));
|
|
|
|
lean_assert(has_local(Pi({a, Type}, l)));
|
|
|
|
lean_assert(!has_metavar(Pi({a, Type}, l)));
|
|
|
|
lean_assert(has_local(Pi({a, l}, a)));
|
|
|
|
lean_assert(has_local(Fun({a, Type}, l)));
|
|
|
|
lean_assert(has_local(Fun({a, l}, a)));
|
|
|
|
lean_assert(!has_local(Let(a, Type, Bool, a)));
|
|
|
|
lean_assert(has_local(mk_let(name("a"), l, f(x), f(f(x)))));
|
|
|
|
lean_assert(has_local(mk_let(name("a"), Type, f(l), f(f(x)))));
|
|
|
|
lean_assert(has_local(mk_let(name("a"), Type, f(x), f(f(l)))));
|
|
|
|
lean_assert(has_local(f(a, a, l)));
|
|
|
|
lean_assert(has_local(f(a, l, a, a)));
|
|
|
|
lean_assert(!has_local(f(a, a, a, a)));
|
|
|
|
lean_assert(!has_local(mk_fst(a)));
|
|
|
|
lean_assert(!has_local(mk_snd(a)));
|
|
|
|
lean_assert(has_local(mk_fst(l)));
|
|
|
|
lean_assert(has_local(mk_snd(l)));
|
|
|
|
lean_assert(!has_local(mk_fst(m)));
|
|
|
|
lean_assert(!has_local(mk_snd(m)));
|
|
|
|
lean_assert(!has_local(mk_pair(a, x, x)));
|
|
|
|
lean_assert(has_local(mk_pair(f(l), x, x)));
|
|
|
|
lean_assert(has_local(mk_pair(f(a), l, x)));
|
|
|
|
lean_assert(has_local(mk_pair(f(a), a, l)));
|
|
|
|
lean_assert(has_local(mk_pair(f(a), a, f(l))));
|
|
|
|
lean_assert(!has_local(mk_pair(f(m), x, x)));
|
|
|
|
lean_assert(!has_local(mk_pair(f(a), m, x)));
|
|
|
|
lean_assert(!has_local(mk_pair(f(a), a, m)));
|
|
|
|
lean_assert(!has_local(mk_pair(f(a), a, f(m))));
|
|
|
|
}
|
|
|
|
|
2013-07-22 20:04:27 +00:00
|
|
|
int main() {
|
2013-12-07 22:59:21 +00:00
|
|
|
save_stack_info();
|
2013-12-08 18:17:29 +00:00
|
|
|
lean_assert(sizeof(expr) == sizeof(optional<expr>));
|
2013-07-23 02:31:27 +00:00
|
|
|
tst1();
|
|
|
|
tst2();
|
|
|
|
tst3();
|
|
|
|
tst4();
|
2013-07-23 02:02:11 +00:00
|
|
|
tst5();
|
2013-07-23 15:59:39 +00:00
|
|
|
tst6();
|
2013-07-23 16:18:18 +00:00
|
|
|
tst7();
|
2013-07-23 18:47:36 +00:00
|
|
|
tst8();
|
|
|
|
tst9();
|
|
|
|
tst10();
|
2013-07-24 02:27:13 +00:00
|
|
|
tst11();
|
2013-07-24 17:14:22 +00:00
|
|
|
tst12();
|
2013-07-24 19:24:49 +00:00
|
|
|
tst13();
|
2013-07-30 02:44:26 +00:00
|
|
|
tst14();
|
2013-08-04 16:37:52 +00:00
|
|
|
tst15();
|
2013-11-18 17:13:34 +00:00
|
|
|
tst16();
|
|
|
|
tst17();
|
2014-02-20 18:07:38 +00:00
|
|
|
tst18();
|
2013-12-08 18:17:29 +00:00
|
|
|
std::cout << "sizeof(expr): " << sizeof(expr) << "\n";
|
|
|
|
std::cout << "sizeof(expr_app): " << sizeof(expr_app) << "\n";
|
|
|
|
std::cout << "sizeof(expr_cell): " << sizeof(expr_cell) << "\n";
|
|
|
|
std::cout << "sizeof(optional<expr>): " << sizeof(optional<expr>) << "\n";
|
|
|
|
std::cout << "sizeof(optional<sexpr>): " << sizeof(optional<sexpr>) << "\n";
|
2014-02-21 01:19:03 +00:00
|
|
|
std::cout << "sizeof(std::function): " << sizeof(std::function<expr(expr const &, optional<expr> const &)>) << "\n";
|
2013-07-23 00:58:28 +00:00
|
|
|
std::cout << "done" << "\n";
|
2013-07-22 20:04:27 +00:00
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|