Beispiel #1
0
lean_univ mk_one() {
    lean_exception ex;
    lean_univ zero, one;
    check(lean_univ_mk_zero(&zero, &ex));
    check(lean_univ_mk_succ(zero, &one, &ex));
    lean_univ_del(zero);
    return one;
}
Beispiel #2
0
void test_id() {
    lean_exception ex;
    lean_univ l          = mk_uparam("l");
    lean_env env         = mk_env();
    lean_expr v0         = mk_var(0);
    lean_expr v1         = mk_var(1);
    lean_expr AA         = mk_pi("a", v0, v1);
    lean_expr Type       = mk_sort(l);
    lean_expr id_type    = mk_pi("A", Type, AA);
    lean_expr f          = mk_lambda("a", v0, v0);
    lean_expr id_val     = mk_lambda("A", Type, f);
    lean_name l_name     = mk_name("l");
    lean_list_name id_ps = mk_unary_name_list(l_name);
    lean_decl id_def     = mk_def("id", id_ps, id_type, id_val);
    lean_name id_name    = mk_name("id");
    lean_cert_decl id_cert_def;
    lean_env new_env;
    lean_univ zero, one;
    lean_bool is_lt;

    check(lean_expr_lt(f, id_val, &is_lt, &ex) && is_lt);
    check(lean_expr_lt(id_val, f, &is_lt, &ex) && !is_lt);

    printf("id type:  ");
    print_expr(id_type);
    printf("id value: ");
    print_expr(id_val);
    printf("-------\n");

    /* type check definition */
    check(lean_decl_check(env, id_def, &id_cert_def, &ex));
    /* add certified definition to environment */
    check(lean_env_add(env, id_cert_def, &new_env, &ex));

    check(!lean_env_contains_decl(env, id_name));
    check(lean_env_contains_decl(new_env, id_name));
    check(lean_env_for_each_decl(new_env, print_decl_and_del, &ex));

    check(lean_univ_mk_zero(&zero, &ex));
    check(lean_univ_mk_succ(zero, &one, &ex));
    check(lean_univ_lt(zero, one, &is_lt, &ex) && is_lt);
    check(lean_univ_lt(one, zero, &is_lt, &ex) && !is_lt);
    {
        lean_type_checker tc;
        lean_expr T0  = mk_sort(zero);
        lean_expr T1  = mk_sort(one);
        lean_expr id1 = mk_const("id", one);
        lean_expr id1T1, id1T1T0;
        lean_expr n1;
        lean_cnstr_seq s1;
        check(lean_expr_mk_app(id1, T1, &id1T1, &ex));
        check(lean_expr_mk_app(id1T1, T0, &id1T1T0, &ex));
        check(lean_type_checker_mk(new_env, &tc, &ex));
        printf("WHNF test\n");
        print_expr(id1T1T0);
        check(lean_type_checker_whnf(tc, id1T1T0, &n1, &s1, &ex));
        printf("=====>\n");
        print_expr(n1);
        lean_expr_del(n1);
        lean_cnstr_seq_del(s1);

        printf("Infer type test\n");
        print_expr(id1T1);
        check(lean_type_checker_infer(tc, id1T1, &n1, &s1, &ex));
        printf("=====>\n");
        print_expr(n1);
        lean_expr_del(n1);
        lean_cnstr_seq_del(s1);

        lean_type_checker_del(tc);
        lean_expr_del(T0);
        lean_expr_del(T1);
        lean_expr_del(id1);
        lean_expr_del(id1T1);
        lean_expr_del(id1T1T0);
    }

    lean_univ_del(l);
    lean_env_del(env);
    lean_expr_del(v0);
    lean_expr_del(v1);
    lean_expr_del(Type);
    lean_expr_del(AA);
    lean_expr_del(id_type);
    lean_expr_del(f);
    lean_expr_del(id_val);
    lean_decl_del(id_def);
    lean_list_name_del(id_ps);
    lean_name_del(l_name);
    lean_cert_decl_del(id_cert_def);
    lean_env_del(new_env);
    lean_name_del(id_name);
    lean_univ_del(zero);
    lean_univ_del(one);
}
Beispiel #3
0
int main() {
    lean_exception ex;
    lean_name a, l, U, pp, pp_unicode, rn;
    lean_options o1, o2;
    lean_univ zero, one, p1, g1, m1, u, n, i, ru;
    lean_list_name ln1, ln2;
    lean_list_univ lu1, lu2;
    char const * s1;
    lean_bool r;

    check(lean_name_mk_anonymous(&a, &ex));
    check(lean_name_mk_str(a, "l_1", &l, &ex));
    check(lean_name_mk_str(a, "U", &U, &ex));
    check(lean_name_mk_str(a, "pp", &pp, &ex));
    check(lean_name_mk_str(pp, "unicode", &pp_unicode, &ex));

    check(lean_options_mk_empty(&o1, &ex));
    check(lean_options_set_bool(o1, pp_unicode, lean_false, &o2, &ex));

    check(lean_univ_mk_zero(&zero, &ex));
    check(lean_univ_mk_succ(zero, &one, &ex));
    check(lean_univ_mk_param(l, &p1, &ex));
    check(lean_univ_mk_global(U, &g1, &ex));
    check(lean_univ_mk_max(p1, one, &m1, &ex));
    check(lean_univ_mk_succ(m1, &u, &ex));

    check(lean_univ_normalize(u, &n, &ex));
    check(lean_univ_to_string(n, &s1, &ex));
    printf("universe: %s\n", s1);

    check(lean_univ_geq(one, zero, &r, &ex) && r);

    /* replace l_1 with one in u */
    check(lean_list_name_mk_nil(&ln1, &ex));
    check(lean_list_name_mk_cons(l, ln1, &ln2, &ex));
    check(lean_list_univ_mk_nil(&lu1, &ex));
    check(lean_list_univ_mk_cons(one, lu1, &lu2, &ex));
    check(lean_univ_instantiate(u, ln2, lu2, &i, &ex));
    lean_list_name_del(ln1);
    lean_list_name_del(ln2);
    lean_list_univ_del(lu1);
    lean_list_univ_del(lu2);
    lean_string_del(s1);
    check(lean_univ_to_string_using(i, o2, &s1, &ex));
    printf("universe: %s\n", s1);

    check(lean_univ_get_kind(zero) == LEAN_UNIV_ZERO);
    check(lean_univ_get_kind(one) == LEAN_UNIV_SUCC);
    check(lean_univ_get_kind(n) == LEAN_UNIV_MAX);

    check(lean_univ_get_name(g1, &rn, &ex) && lean_name_eq(rn, U));

    check(lean_univ_get_max_lhs(m1, &ru, &ex) && lean_univ_eq(ru, p1, &r, &ex) && r);
    lean_univ_del(ru);
    check(lean_univ_get_max_rhs(m1, &ru, &ex) && lean_univ_eq(ru, one, &r, &ex) && r);
    lean_univ_del(ru);
    check(lean_univ_get_pred(one, &ru, &ex) && lean_univ_eq(ru, zero, &r, &ex) && r);
    lean_univ_del(ru);

    lean_name_del(a);
    lean_name_del(l);
    lean_name_del(U);
    lean_name_del(pp);
    lean_name_del(pp_unicode);
    lean_name_del(rn);

    lean_options_del(o1);
    lean_options_del(o2);

    lean_univ_del(zero);
    lean_univ_del(one);
    lean_univ_del(p1);
    lean_univ_del(g1);
    lean_univ_del(m1);
    lean_univ_del(u);
    lean_univ_del(n);
    lean_univ_del(i);

    lean_string_del(s1);
    return 0;
}