Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
feat(library/tactic/simplify): add single_pass simplifier option (def…
Browse files Browse the repository at this point in the history
…ault is false)
  • Loading branch information
leodemoura committed Jun 21, 2017
1 parent 9fcb3ae commit b9dee04
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ master branch (aka work in progress branch)

* In addition to user-defined notation parsers introduced in Lean 3.2.0, users may now also define top-level commands in Lean. For an example, see the [`coinductive` command](https://github.com/leanprover/lean/blob/814a5edaf172c3835c000e3f631bddd85bd879ab/library/init/meta/coinductive_predicates.lean#L551-L552) that has been ported to the new model.

* Add new simplifier configuration option `simp_config.single_pass`. It is useful for simplification rules that may produce non-termination.
Example: `simp {single_pass := tt}`

*Changes*

* We now have two type classes for converting to string: `has_to_string` and `has_repr`.
Expand Down
1 change: 1 addition & 0 deletions library/init/meta/simp_tactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ structure simp_config :=
(beta : bool := tt)
(eta : bool := tt)
(proj : bool := tt) -- reduce projections
(single_pass : bool := ff)

meta constant simplify_core
(c : simp_config)
Expand Down
8 changes: 6 additions & 2 deletions src/library/tactic/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ simp_config::simp_config():
m_zeta(false),
m_beta(false),
m_eta(true),
m_proj(true) {
m_proj(true),
m_single_pass(false) {
}

simp_config::simp_config(vm_obj const & obj) {
Expand All @@ -85,6 +86,7 @@ simp_config::simp_config(vm_obj const & obj) {
m_beta = to_bool(cfield(obj, 7));
m_eta = to_bool(cfield(obj, 8));
m_proj = to_bool(cfield(obj, 9));
m_single_pass = to_bool(cfield(obj, 10));
}

/* -----------------------------------
Expand Down Expand Up @@ -696,8 +698,10 @@ simp_result simplify_core_fn::visit(expr const & e, optional<expr> const & paren
} else if (r2->first.get_new() == curr_result.get_new()) {
break;
} else {
/* continue simplifying */
curr_result = join(new_result, r2->first);
if (m_cfg.m_single_pass)
break;
/* continue simplifying */
}
} else {
curr_result = new_result;
Expand Down
2 changes: 2 additions & 0 deletions src/library/tactic/simplify.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ structure simp_config :=
(beta : bool)
(eta : bool)
(proj : bool)
(single_pass : bool)
*/
struct simp_config {
unsigned m_max_steps;
Expand All @@ -37,6 +38,7 @@ struct simp_config {
bool m_beta;
bool m_eta;
bool m_proj;
bool m_single_pass;
simp_config();
simp_config(vm_obj const & o);
};
Expand Down
14 changes: 14 additions & 0 deletions tests/lean/run/simp_single_pass.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open nat well_founded

def gcd : ℕ → ℕ → ℕ | y := λ x,
if h : y = 0 then
x
else
have x % y < y, by { apply mod_lt, cases y, contradiction, apply succ_pos },
gcd (x % y) y

lemma gcd_zero_right (x : nat) : gcd 0 x = x :=
begin
simp [gcd] {single_pass := tt},
simp
end

0 comments on commit b9dee04

Please sign in to comment.