<commit_before>/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "free_vars.h"
#include "test.h"
using namespace lean;

static void tst1() {
    expr f = Const("f");
    expr a = Const("a");
    expr b = Const("b");
    expr x = Var(0);
    expr y = Var(1);
    expr t = Const("t");
    expr F = mk_lambda("_", t, f(x));
    lean_assert(has_free_var(mk_lambda("_", t, f(Var(1))), 0));
    lean_assert(!has_free_var(mk_lambda("_", t, f(Var(0))), 1));
    lean_assert(!has_free_var(mk_pi("_", t, mk_lambda("_", t, f(Var(1)))), 0));
    lean_assert(has_free_var(f(Var(0)), 0));
    lean_assert(has_free_var(f(Var(1)), 1));
    lean_assert(!has_free_var(f(Var(1)), 0));
    lean_assert(has_free_var(f(Var(1)), 0, 2));
    lean_assert(!has_free_var(f(Var(1)), 0, 1));
    lean_assert(lower_free_vars(f(Var(1)), 1) == f(Var(0)));
    lean_assert(lower_free_vars(mk_lambda("_", t, f(Var(2))), 1) == mk_lambda("_", t, f(Var(1))));
    lean_assert(lower_free_vars(mk_lambda("_", t, f(Var(0))), 1) == mk_lambda("_", t, f(Var(0))));
}

int main() {
    continue_on_violation(true);
    tst1();
    return has_violations() ? 1 : 0;
}
<commit_msg>Add regression test to expose bug fixed in previous commit.<commit_after>/*
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.

Author: <NAME>
*/
#include "free_vars.h"
#include "abstract.h"
#include "test.h"
using namespace lean;

static void tst1() {
    expr f = Const("f");
    expr a = Const("a");
    expr b = Const("b");
    expr x = Var(0);
    expr y = Var(1);
    expr t = Const("t");
    expr F = mk_lambda("_", t, f(x));
    lean_assert(has_free_var(mk_lambda("_", t, f(Var(1))), 0));
    lean_assert(!has_free_var(mk_lambda("_", t, f(Var(0))), 1));
    lean_assert(!has_free_var(mk_pi("_", t, mk_lambda("_", t, f(Var(1)))), 0));
    lean_assert(has_free_var(f(Var(0)), 0));
    lean_assert(has_free_var(f(Var(1)), 1));
    lean_assert(!has_free_var(f(Var(1)), 0));
    lean_assert(has_free_var(f(Var(1)), 0, 2));
    lean_assert(!has_free_var(f(Var(1)), 0, 1));
    lean_assert(lower_free_vars(f(Var(1)), 1) == f(Var(0)));
    lean_assert(lower_free_vars(mk_lambda("_", t, f(Var(2))), 1) == mk_lambda("_", t, f(Var(1))));
    lean_assert(lower_free_vars(mk_lambda("_", t, f(Var(0))), 1) == mk_lambda("_", t, f(Var(0))));
}

static void tst2() {
    expr f = Const("f");
    expr x = Const("x");
    expr y = Const("y");
    expr B = Const("Bool");
    expr t = Fun({x, B}, Fun({y, B}, x));
    lean_assert(closed(t));
    lean_assert(!closed(abst_body(t)));
}

int main() {
    continue_on_violation(true);
    tst1();
    tst2();
    return has_violations() ? 1 : 0;
}

{'fraction_non_alphanumeric': 0.2132431470274119, 'fraction_numerical': 0.02847988608045568, 'mean_word_length': 4.456310679611651, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5605173', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1152, 'n_words': 248}