feat(library/blast/strategies): add strategy for testing congruence closure module
This commit is contained in:
parent
39dbbd687b
commit
67e291ac84
20 changed files with 120 additions and 36 deletions
|
@ -1,2 +1,2 @@
|
|||
add_library(blast_strategies OBJECT simple_strategy.cpp iterative_deepening.cpp
|
||||
preprocess_strategy.cpp portfolio.cpp)
|
||||
preprocess_strategy.cpp debug_action_strategy.cpp portfolio.cpp)
|
||||
|
|
75
src/library/blast/strategies/debug_action_strategy.cpp
Normal file
75
src/library/blast/strategies/debug_action_strategy.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "library/blast/strategy.h"
|
||||
#include "library/blast/actions/simple_actions.h"
|
||||
#include "library/blast/actions/intros_action.h"
|
||||
|
||||
namespace lean {
|
||||
namespace blast {
|
||||
class debug_action_strategy_core_fn : public strategy_fn {
|
||||
virtual action_result pre(hypothesis_idx) { return action_result::failed(); }
|
||||
virtual action_result post(hypothesis_idx) { return action_result::failed(); }
|
||||
virtual action_result next() { return action_result::failed(); }
|
||||
|
||||
virtual action_result hypothesis_pre_activation(hypothesis_idx hidx) override {
|
||||
Try(assumption_contradiction_actions(hidx));
|
||||
Try(discard_action(hidx));
|
||||
Try(pre(hidx));
|
||||
return action_result::new_branch();
|
||||
}
|
||||
|
||||
virtual action_result hypothesis_post_activation(hypothesis_idx hidx) override {
|
||||
Try(post(hidx));
|
||||
return action_result::new_branch();
|
||||
}
|
||||
|
||||
virtual action_result next_action() override {
|
||||
Try(intros_action());
|
||||
Try(assumption_action());
|
||||
Try(activate_hypothesis());
|
||||
Try(trivial_action());
|
||||
Try(next());
|
||||
return action_result::failed();
|
||||
}
|
||||
};
|
||||
|
||||
class debug_pre_action_strategy_fn : public debug_action_strategy_core_fn {
|
||||
std::function<action_result(hypothesis_idx)> m_action;
|
||||
virtual action_result pre(hypothesis_idx hidx) { return m_action(hidx); }
|
||||
public:
|
||||
debug_pre_action_strategy_fn(std::function<action_result(hypothesis_idx)> const & a):
|
||||
m_action(a) {}
|
||||
};
|
||||
|
||||
class debug_post_action_strategy_fn : public debug_action_strategy_core_fn {
|
||||
std::function<action_result(hypothesis_idx)> m_action;
|
||||
virtual action_result post(hypothesis_idx hidx) { return m_action(hidx); }
|
||||
public:
|
||||
debug_post_action_strategy_fn(std::function<action_result(hypothesis_idx)> const & a):
|
||||
m_action(a) {}
|
||||
};
|
||||
|
||||
class debug_action_strategy_fn : public debug_action_strategy_core_fn {
|
||||
std::function<action_result()> m_action;
|
||||
virtual action_result next() { return m_action(); }
|
||||
public:
|
||||
debug_action_strategy_fn(std::function<action_result()> const & a):
|
||||
m_action(a) {}
|
||||
};
|
||||
|
||||
strategy mk_debug_action_strategy(std::function<action_result()> const & a) {
|
||||
return [=]() { return debug_action_strategy_fn(a)(); }; // NOLINT
|
||||
}
|
||||
|
||||
strategy mk_debug_pre_action_strategy(std::function<action_result(hypothesis_idx)> const & a) {
|
||||
return [=]() { return debug_pre_action_strategy_fn(a)(); }; // NOLINT
|
||||
}
|
||||
|
||||
strategy mk_debug_post_action_strategy(std::function<action_result(hypothesis_idx)> const & a) {
|
||||
return [=]() { return debug_post_action_strategy_fn(a)(); }; // NOLINT
|
||||
}
|
||||
}}
|
16
src/library/blast/strategies/debug_action_strategy.h
Normal file
16
src/library/blast/strategies/debug_action_strategy.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#pragma once
|
||||
#include "library/blast/strategy.h"
|
||||
namespace lean {
|
||||
namespace blast {
|
||||
/* \brief Create minimalistic strategies for testing the given action.
|
||||
These strategies apply basic actions (e.g., intros and assumption) and the given action. */
|
||||
strategy mk_debug_action_strategy(std::function<action_result()> const & a);
|
||||
strategy mk_debug_pre_action_strategy(std::function<action_result(hypothesis_idx)> const & a);
|
||||
strategy mk_debug_post_action_strategy(std::function<action_result(hypothesis_idx)> const & a);
|
||||
}}
|
|
@ -5,9 +5,11 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include <string>
|
||||
#include "library/blast/actions/assert_cc_action.h"
|
||||
#include "library/blast/simplifier/simplifier_strategies.h"
|
||||
#include "library/blast/strategies/simple_strategy.h"
|
||||
#include "library/blast/strategies/preprocess_strategy.h"
|
||||
#include "library/blast/strategies/debug_action_strategy.h"
|
||||
|
||||
namespace lean {
|
||||
namespace blast {
|
||||
|
@ -27,6 +29,10 @@ static optional<expr> apply_simple() {
|
|||
return preprocess_and_then(mk_simple_strategy())();
|
||||
}
|
||||
|
||||
static optional<expr> apply_cc() {
|
||||
return mk_debug_pre_action_strategy(assert_cc_action)();
|
||||
}
|
||||
|
||||
optional<expr> apply_strategy() {
|
||||
std::string s_name(get_config().m_strategy);
|
||||
if (s_name == "preprocess") {
|
||||
|
@ -37,6 +43,8 @@ optional<expr> apply_strategy() {
|
|||
return apply_simp_nohyps();
|
||||
} else if (s_name == "simple") {
|
||||
return apply_simple();
|
||||
} else if (s_name == "cc") {
|
||||
return apply_cc();
|
||||
} else {
|
||||
// TODO(Leo): add more builtin strategies
|
||||
return apply_simple();
|
||||
|
|
|
@ -94,12 +94,12 @@ optional<expr> strategy_fn::search() {
|
|||
}
|
||||
}
|
||||
|
||||
strategy operator|(strategy const & s1, strategy const & s2) {
|
||||
return [=]() {
|
||||
strategy operator||(strategy const & s1, strategy const & s2) {
|
||||
return [=]() { // NOLINT
|
||||
if (auto r = s1())
|
||||
return r;
|
||||
else
|
||||
return s2();
|
||||
}
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
|
|
@ -42,5 +42,5 @@ public:
|
|||
|
||||
typedef std::function<optional<expr>()> strategy;
|
||||
|
||||
strategy operator|(strategy const & s1, strategy const & s2);
|
||||
strategy operator||(strategy const & s1, strategy const & s2);
|
||||
}}
|
||||
|
|
|
@ -2,7 +2,7 @@ import data.list
|
|||
|
||||
constant f {A : Type} : A → A → A
|
||||
constant g : nat → nat
|
||||
set_option blast.subst false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
example (a b c : nat) : a = b → g a == g b :=
|
||||
by blast
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
definition t1 (a b : nat) : (a = b ↔ a = b) :=
|
||||
by blast
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import data.list
|
||||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
definition t1 (a b : nat) : (a = b) ↔ (b = a) :=
|
||||
by blast
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
set_option pp.all true
|
||||
set_option blast.strategy "simple"
|
||||
|
||||
definition foo1 (a b : nat) (p : Prop) : a = b → (b = a → p) → p :=
|
||||
by blast
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
set_option blast.init_depth 10
|
||||
set_option blast.inc_depth 100
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
example (p : nat → nat → Prop) (f : nat → nat) (a b c d : nat) :
|
||||
p (f a) (f b) → a = c → b = d → b = c → p (f c) (f c) :=
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
set_option blast.strategy "cc"
|
||||
|
||||
constant R : nat → nat → Prop
|
||||
axiom R_trans : ∀ a b c, R a b → R b c → R a c
|
||||
attribute R_trans [trans]
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
set_option blast.init_depth 10
|
||||
set_option blast.inc_depth 100
|
||||
set_option blast.subst false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
example (a b c d : nat) : a == b → b = c → c == d → a == d :=
|
||||
by blast
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
open nat
|
||||
set_option blast.subst false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
constant f (a b : nat) : a > b → nat
|
||||
constant g : nat → nat
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
open nat
|
||||
set_option blast.subst false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
definition tst
|
||||
(a₁ a₂ b₁ b₂ c d : nat) :
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
set_option blast.simp false
|
||||
set_option blast.subst false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
set_option blast.trace true
|
||||
example (a b c : Prop) : (a ↔ b) → ((a ∧ (c ∨ b)) ↔ (b ∧ (c ∨ a))) :=
|
||||
by blast
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import data.list
|
||||
set_option blast.simp false
|
||||
set_option blast.subst false
|
||||
set_option blast.strategy "cc"
|
||||
open perm list
|
||||
|
||||
definition tst₁
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
set_option blast.init_depth 10
|
||||
set_option blast.inc_depth 1000
|
||||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
example (a b c d : Prop)
|
||||
[d₁ : decidable a] [d₂ : decidable b] [d₃ : decidable c] [d₄ : decidable d]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import data.finset data.set
|
||||
open set finset
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
structure finite_set [class] {T : Type} (xs : set T) :=
|
||||
(to_finset : finset T) (is_equiv : to_set to_finset = xs)
|
||||
|
@ -28,9 +29,6 @@ definition finite_set_set_of [instance] (xs : set A) [fxs : finite_set xs] : fin
|
|||
noncomputable definition mycard {T : Type} (xs : set T) [fxs : finite_set xs] :=
|
||||
finset.card (to_finset xs)
|
||||
|
||||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
|
||||
/- Congruence closure still works :-) -/
|
||||
definition tst
|
||||
(A : Type) (s₁ s₂ s₃ s₄ s₅ s₆ : set A)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import data.list
|
||||
open perm
|
||||
set_option blast.subst false
|
||||
set_option blast.simp false
|
||||
set_option blast.strategy "cc"
|
||||
|
||||
example (a b : nat) : a = b → (b = a ↔ true) :=
|
||||
by blast
|
||||
|
|
Loading…
Reference in a new issue