feat(library): numeral normalization skeleton
This commit is contained in:
parent
5f967f40b2
commit
e4f0f6a9b4
10 changed files with 151 additions and 2 deletions
23
library/algebra/numeral.lean
Normal file
23
library/algebra/numeral.lean
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import algebra.ring -- has_add, has_one, ... will be moved to init in the future
|
||||||
|
open algebra
|
||||||
|
|
||||||
|
variable {A : Type}
|
||||||
|
|
||||||
|
definition zero [s : has_zero A] : A :=
|
||||||
|
has_zero.zero A
|
||||||
|
|
||||||
|
definition one [s : has_one A] : A :=
|
||||||
|
has_one.one A
|
||||||
|
|
||||||
|
definition add [s : has_add A] : A → A → A :=
|
||||||
|
has_add.add
|
||||||
|
|
||||||
|
definition bit0 [s : has_add A] (a : A) : A :=
|
||||||
|
add a a
|
||||||
|
|
||||||
|
definition bit1 [s₁ : has_add A] [s₂ : has_one A] (a : A) : A :=
|
||||||
|
add (add a a) one
|
||||||
|
|
||||||
|
-- variables [s : ring A]
|
||||||
|
-- set_option pp.all true
|
||||||
|
-- check bit1 (bit0 (one : A))
|
|
@ -46,6 +46,7 @@ definition congruence : tactic := builtin
|
||||||
definition rotate_left (k : num) := builtin
|
definition rotate_left (k : num) := builtin
|
||||||
definition rotate_right (k : num) := builtin
|
definition rotate_right (k : num) := builtin
|
||||||
definition rotate (k : num) := rotate_left k
|
definition rotate (k : num) := rotate_left k
|
||||||
|
definition norm_num : tactic := builtin
|
||||||
|
|
||||||
-- This is just a trick to embed expressions into tactics.
|
-- This is just a trick to embed expressions into tactics.
|
||||||
-- The nested expressions are "raw". They tactic should
|
-- The nested expressions are "raw". They tactic should
|
||||||
|
|
|
@ -15,4 +15,4 @@ add_library(library OBJECT deep_copy.cpp expr_lt.cpp io_state.cpp occurs.cpp
|
||||||
unfold_macros.cpp app_builder.cpp projection.cpp abbreviation.cpp
|
unfold_macros.cpp app_builder.cpp projection.cpp abbreviation.cpp
|
||||||
relation_manager.cpp export.cpp user_recursors.cpp
|
relation_manager.cpp export.cpp user_recursors.cpp
|
||||||
class_instance_synth.cpp idx_metavar.cpp composition_manager.cpp
|
class_instance_synth.cpp idx_metavar.cpp composition_manager.cpp
|
||||||
tc_multigraph.cpp noncomputable.cpp aux_recursors.cpp)
|
tc_multigraph.cpp noncomputable.cpp aux_recursors.cpp norm_num.cpp)
|
||||||
|
|
18
src/library/norm_num.cpp
Normal file
18
src/library/norm_num.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
|
Author: Rob Lewis
|
||||||
|
*/
|
||||||
|
#include "library/norm_num.h"
|
||||||
|
namespace lean {
|
||||||
|
bool norm_num_context::is_numeral(expr const &) const {
|
||||||
|
// TODO(Rob)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pair<expr, expr> norm_num_context::mk_norm(expr const &) {
|
||||||
|
// TODO(Rob)
|
||||||
|
throw exception("not implemented yet - norm_num`");
|
||||||
|
}
|
||||||
|
}
|
27
src/library/norm_num.h
Normal file
27
src/library/norm_num.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
|
Author: Rob Lewis
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "kernel/environment.h"
|
||||||
|
|
||||||
|
namespace lean {
|
||||||
|
class norm_num_context {
|
||||||
|
environment m_env;
|
||||||
|
public:
|
||||||
|
norm_num_context(environment const & env):m_env(env) {}
|
||||||
|
|
||||||
|
bool is_numeral(expr const & e) const;
|
||||||
|
pair<expr, expr> mk_norm(expr const & e);
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool is_numeral(environment const & env, expr const & e) {
|
||||||
|
return norm_num_context(env).is_numeral(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline pair<expr, expr> mk_norm_num(environment const & env, expr const & e) {
|
||||||
|
return norm_num_context(env).mk_norm(e);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,4 +6,5 @@ expr_to_tactic.cpp location.cpp rewrite_tactic.cpp util.cpp
|
||||||
init_module.cpp change_tactic.cpp check_expr_tactic.cpp let_tactic.cpp
|
init_module.cpp change_tactic.cpp check_expr_tactic.cpp let_tactic.cpp
|
||||||
contradiction_tactic.cpp exfalso_tactic.cpp constructor_tactic.cpp
|
contradiction_tactic.cpp exfalso_tactic.cpp constructor_tactic.cpp
|
||||||
injection_tactic.cpp congruence_tactic.cpp relation_tactics.cpp
|
injection_tactic.cpp congruence_tactic.cpp relation_tactics.cpp
|
||||||
induction_tactic.cpp subst_tactic.cpp unfold_rec.cpp with_options_tactic.cpp)
|
induction_tactic.cpp subst_tactic.cpp unfold_rec.cpp with_options_tactic.cpp
|
||||||
|
norm_num_tactic.cpp)
|
||||||
|
|
|
@ -32,6 +32,7 @@ Author: Leonardo de Moura
|
||||||
#include "library/tactic/subst_tactic.h"
|
#include "library/tactic/subst_tactic.h"
|
||||||
#include "library/tactic/location.h"
|
#include "library/tactic/location.h"
|
||||||
#include "library/tactic/with_options_tactic.h"
|
#include "library/tactic/with_options_tactic.h"
|
||||||
|
#include "library/tactic/norm_num_tactic.h"
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
void initialize_tactic_module() {
|
void initialize_tactic_module() {
|
||||||
|
@ -62,9 +63,11 @@ void initialize_tactic_module() {
|
||||||
initialize_subst_tactic();
|
initialize_subst_tactic();
|
||||||
initialize_location();
|
initialize_location();
|
||||||
initialize_with_options_tactic();
|
initialize_with_options_tactic();
|
||||||
|
initialize_norm_num_tactic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalize_tactic_module() {
|
void finalize_tactic_module() {
|
||||||
|
finalize_norm_num_tactic();
|
||||||
finalize_with_options_tactic();
|
finalize_with_options_tactic();
|
||||||
finalize_location();
|
finalize_location();
|
||||||
finalize_subst_tactic();
|
finalize_subst_tactic();
|
||||||
|
|
53
src/library/tactic/norm_num_tactic.cpp
Normal file
53
src/library/tactic/norm_num_tactic.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
|
Author: Rob Lewis
|
||||||
|
*/
|
||||||
|
#include "library/util.h"
|
||||||
|
#include "library/norm_num.h"
|
||||||
|
#include "library/tactic/expr_to_tactic.h"
|
||||||
|
|
||||||
|
namespace lean {
|
||||||
|
tactic norm_num_tactic() {
|
||||||
|
return tactic01([=](environment const & env, io_state const &, proof_state const & s) {
|
||||||
|
goals const & gs = s.get_goals();
|
||||||
|
if (empty(gs)) {
|
||||||
|
throw_no_goal_if_enabled(s);
|
||||||
|
return none_proof_state();
|
||||||
|
}
|
||||||
|
goal const & g = head(gs);
|
||||||
|
expr const & c = g.get_type();
|
||||||
|
expr lhs, rhs;
|
||||||
|
if (!is_eq(c, lhs, rhs)) {
|
||||||
|
throw_tactic_exception_if_enabled(s, "norm_num tactic failed, conclusion is not an equality");
|
||||||
|
return none_proof_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
pair<expr, expr> p = mk_norm_num(env, lhs);
|
||||||
|
expr new_lhs = p.first;
|
||||||
|
expr new_pr = p.second;
|
||||||
|
if (new_lhs != rhs) {
|
||||||
|
throw_tactic_exception_if_enabled(s, "norm_num tactic failed, lhs normal form doesn't match rhs");
|
||||||
|
return none_proof_state();
|
||||||
|
}
|
||||||
|
substitution new_subst = s.get_subst();
|
||||||
|
assign(new_subst, g, new_pr);
|
||||||
|
return some_proof_state(proof_state(s, tail(gs), new_subst));
|
||||||
|
} catch (exception & ex) {
|
||||||
|
throw_tactic_exception_if_enabled(s, ex.what());
|
||||||
|
return none_proof_state();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize_norm_num_tactic() {
|
||||||
|
register_tac(name{"tactic", "norm_num"},
|
||||||
|
[](type_checker &, elaborate_fn const &, expr const &, pos_info_provider const *) {
|
||||||
|
return norm_num_tactic();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
void finalize_norm_num_tactic() {
|
||||||
|
}
|
||||||
|
}
|
12
src/library/tactic/norm_num_tactic.h
Normal file
12
src/library/tactic/norm_num_tactic.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
|
Author: Rob Lewis
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace lean {
|
||||||
|
void initialize_norm_num_tactic();
|
||||||
|
void finalize_norm_num_tactic();
|
||||||
|
}
|
11
tests/lean/extra/num_norm1.lean
Normal file
11
tests/lean/extra/num_norm1.lean
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import algebra.numeral algebra.ring
|
||||||
|
open algebra
|
||||||
|
|
||||||
|
variable {A : Type}
|
||||||
|
variable [s : ring A]
|
||||||
|
include s
|
||||||
|
|
||||||
|
example : add (bit0 (one:A)) one = bit1 one :=
|
||||||
|
begin
|
||||||
|
norm_num
|
||||||
|
end
|
Loading…
Reference in a new issue