This ports the `.below` and `.brecOn` constructions to lean. I kept them in the same file, as they were in the C code, because they are highly coupled and the constructions are very analogous. For validation I developed this in a separate repository at https://github.com/nomeata/lean-constructions/tree/fad715e and checked that all declarations found in Lean and Mathlib are equivalent, up to def canon (e : Expr) : CoreM Expr := do Core.transform (← Core.betaReduce e) (pre := fun | .const n ls => return .done (.const n (ls.map (·.normalize))) | .sort l => return .done (.sort l.normalize) | _ => return .continue) It was not feasible to make them completely equal, because the kernel's type inference code seem to optimize level expressions a bit less aggressively, and beta-reduces less in inference. The private helper functions about `PProd` can later move into their own file, used by these constructions as well as the structural recursion module.
28 lines
740 B
C++
28 lines
740 B
C++
/*
|
|
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Author: Leonardo de Moura
|
|
*/
|
|
#include "util/name_generator.h"
|
|
#include "kernel/type_checker.h"
|
|
#include "library/util.h"
|
|
#include "library/constants.h"
|
|
|
|
namespace lean {
|
|
static name * g_constructions_fresh = nullptr;
|
|
|
|
name_generator mk_constructions_name_generator() {
|
|
return name_generator(*g_constructions_fresh);
|
|
}
|
|
|
|
void initialize_constructions_util() {
|
|
g_constructions_fresh = new name("_cnstr_fresh");
|
|
mark_persistent(g_constructions_fresh->raw());
|
|
register_name_generator_prefix(*g_constructions_fresh);
|
|
}
|
|
|
|
void finalize_constructions_util() {
|
|
delete g_constructions_fresh;
|
|
}
|
|
}
|