Is there a way to apply the rule to a specific assumption in Isabelle? - verification

Here is my goal
...
∀a b. P1 a b ⟹
∀a b. P2 a b ⟹
...
⟹ some goal
I want to apply the lemma to the second assumption
lemma K: ⟦ ∀a b. P a b⟧ ⟹ ∀b. P a b"
by using
apply (drule_tac a = "x" in K)
but Isabelle always firstly applies the tactic to the first assumption, how can I only apply the tactic to the second assumption?
Actually, my goal is
...
∀b. Γ b ≠ Γ' b ⟶
b ∉ set (llocked C1) ∧ (Γ b, Γ' b) ∈ RGUnion R G2 b ∧ disjoint (dom h1) (dom (Γ' b)) ⟶
rgsep_safe n C1 s h1 Γ' (RGUnion R G2) G1 Q1 ⟹
∀b. Γ b ≠ Γ' b ⟶
b ∉ set (llocked C2) ∧ (Γ b, Γ' b) ∈ RGUnion R G1 b ∧ disjoint (dom h2) (dom (Γ' b)) ⟶
rgsep_safe n C2 s h2 Γ' (RGUnion R G1) G2 Q2 ⟹
rgsep_safe n C2 s h2 Γ' (RGUnion R G1) G2 Q2
and I want to use the lemma on the second assumtion
theorem K1: ∀b. ?P b ⟶ ?Q ⟹ ∀b. ?P b ⟹ ?Q
to make the goal become
...
∀b. Γ b ≠ Γ' b ⟶
b ∉ set (llocked C1) ∧ (Γ b, Γ' b) ∈ RGUnion R G2 b ∧ disjoint (dom h1) (dom (Γ' b)) ⟶
rgsep_safe n C1 s h1 Γ' (RGUnion R G2) G1 Q1 ⟹
∀b. Γ b ≠ Γ' b ⟶
b ∉ set (llocked C2) ∧ (Γ b, Γ' b) ∈ RGUnion R G1 b ∧ disjoint (dom h2) (dom (Γ' b))

There are a lot of ugly hacks that can allow you to bypass the first assumption (e.g. by deleting it or reordering them). Already drule_tac is heading in that direction. Better by far is to use a structured proof, if it's practical for your problem. Then it's easy to name your assumptions and join them to "K" using the OF attribute.
Your theorem K1 is useless: it doesn't do what you think it does because of how the scope of quantifiers works. I tried an experiment with a simpler version of your goal and made quite a bit of progress by typing
apply (simp flip: imp_conjL)
This admittedly obscure step converts your implications into conjunctions; the simplifier notices that the quantified variable doesn't appear on the right-hand side, so all you need to do now is exhibit a b satisfying the three conditions
Γ b ≠ Γ' b
b ∉ set (llocked C2)
(Γ b, Γ' b) ∈ RGUnion R G1 b ∧ disjoint (dom h2) (dom (Γ' b))
You will get a much nicer looking proof if you prove these facts first. If they are available then you may find that the automation proves the goal you wanted automatically.

Related

Why doesn't this proof require extensionality? (Agda)

The following proves the equality of two functions:
η-→ : ∀ {A B : Set} (f : A → B) → (λ (x : A) → f x) ≡ f
η-→ f = refl
Why doesn't it need extensionality? How does Agda know that the function to the left of the ≡ simplifies to f?
(λ x → f x) ≡ f is a basic rule of definitional equality for functions, called the eta rule. It's built into the type checker. Implementations of type theory commonly support it.

Can Idris try multiple hints for auto proofs?

In this example
%hint
lemma1: S a `LTE` S b -> a `LTE` b
lemma1 = ?todo1
myMinus: (a, b: Nat) -> {auto prf: b `LTE` a} -> Nat
myMinus (S a') (S b') = a' `myMinus` b' -- automatically uses lemma1
myMinus a b = ?todo2
Idris is able to automatically use lemma1 where it's needed. Now I add a second lemma
%hint
lemma2: S a `LTE` b -> a `LTE` b
lemma2 = ?todo3
between lemma1 and myMinus. Now Idris doesn't find lemma1 anymore, probably because it only tries lemma2, and I have to specify it manually.
Is there a way, that I can have both lemma1 and lemma2 with %hint in context and let Idris automatically choose the correct one?

Big-Theta: multiplying Theta(n) and Theta(n^2) = Theta(n^3)?

If f(n) = Θ(n) and
g(n) = Θ(n^2),
then f(n) * g(n) = Θ(n^3)?
Problem
Technically, Θ(n) is a set of functions, so we say that f is in Θ(n), rather than f(n) being equal to Θ(n).
Hence, the problem we want to investigate is:
Let
h(n) = g(n) · f(n) (*)
Does f ∈ ϴ(n) and g ∈ ϴ(n^2) imply that h ∈ ϴ(n^3)?
Preparations
Let's start by loosely stating the definition of Big-ϴ notation
f ∈ ϴ(g(n))
⇨ For some positive constants k1, k2, and n0, the following holds:
k1 · |g(n)| ≤ |f(n)| ≤ k2 · |g(n)|, for all n ≥ n0 (+)
We will make use of this definition below but assume, without loss of generality, that both f(n) and g(n) above are non-negative for all n.
Solution
From the above we can state, for some positive set of constants (c1, c2, n0) and (d1, d2, m0), that the following holds
f ∈ ϴ(n): c1 · n ≤ f(n) ≤ c2 · n, for all n ≥ n0 (i)
g ∈ ϴ(n^2): d1 · n^2 ≤ g(n) ≤ d2 · n^2, for all n ≥ m0 (ii)
Now, the set of constants (c1, c2, n0) (as well as (d1, d2, m0)) is not unique; if such a set exists, an infinite number of such sets exist. Since f ∈ ϴ(n) and g ∈ ϴ(n^2) holds, such sets do exist, and we can, without loss of generality, assume that we can find a set of constants (c1, c2, n0) and (d1, d2, m0) such that c1=d1, c2=d2 and n0=m0 all hold. Hence, we can re-state (i-ii) as:
f ∈ ϴ(n): c1 · n ≤ f(n) ≤ c2 · n, for all n ≥ n0 (I)
g ∈ ϴ(n^2): c1 · n^2 ≤ g(n) ≤ c2 · n^2, for all n ≥ n0 (II)
for some set of positive constants (c1, c2, n0).
Now, since n > n0 > 0, all terms in the inequalities (I-II) above are positive, and we can apply (*) directly:
(I) * (II):
c1^2 · n^3 ≤ f(n) · g(n) ≤ c2^2 · n^3, for all n ≥ n0 (iii)
Now, let k1 = c1^2 and k2=c2^2, and insert---among with h(n) = f(n) · g(n)---into (iii), yielding
k1 · n^3 ≤ h(n) ≤ k2 · n^3, for all n ≥ n0 (III)
This is, by (+), the very definition of h ∈ ϴ(n^3), and we have hence solved our problem by showing that:
For h(n) as in (*): f ∈ ϴ(n) and g ∈ ϴ(n^2) implies that h ∈ ϴ(n^3)

vector reflexivity under setoid equality using CoRN MathClasses

I have a simple lemma:
Lemma map2_comm: forall A (f:A->A->B) n (a b:t A n),
(forall x y, (f x y) = (f y x)) -> map2 f a b = map2 f b a.
which I was able to prove using standard equality (≡). Now I am need to prove the similar lemma using setoid equality (using CoRN MathClasses). I am new to this library and type classes in general and having difficulty doing so. My first attempt is:
Lemma map2_setoid_comm `{Equiv B} `{Equiv (t B n)} `{Commutative B A}:
forall (a b: t A n),
map2 f a b = map2 f b a.
Proof.
intros.
induction n.
dep_destruct a.
dep_destruct b.
simpl.
(here '=' is 'equiv'). After 'simpl' the goal is "(nil B)=(nil B)" or "[]=[]" using VectorNotations. Normally I would finish it using 'reflexivity' tactics but it gives me:
Tactic failure: The relation equiv is not a declared reflexive relation. Maybe you need to require the Setoid library.
I guess I need somehow to define reflexivity for vector types, but I am not sure how to do that. Please advise.
First of all the lemma definition needs to be adjusted to:
Lemma map2_setoid_comm : forall `{CO:Commutative B A f} `{SB: !Setoid B} ,
forall n:nat, Commutative (map2 f (n:=n)).
To be able to use reflexivity:
Definition vec_equiv `{Equiv A} {n}: relation (vector A n) := Vforall2 (n:=n) equiv.
Instance vec_Equiv `{Equiv A} {n}: Equiv (vector A n) := vec_equiv.

Turning a <= b to suc a <= suc b

This is an extension of the question posted here:
Agda and Binary Search Trees
I have
trans₁ : ∀ {a b c} → suc a ≤ suc b → suc b ≤ c → suc a ≤ c
for the definition of trans₁, but this would require me to change the definition of widen below to:
widen : ∀{min max newMin newMax}
→ BST min max
→ suc newMin ≤ suc min
→ max ≤ newMax
→ BST newMin newMax
How would i change a <= b to suc a <= suc b? This would then allow me to change the definition of trans₁ to:
trans₁ : ∀ {a b c} → a ≤ b → suc b ≤ c → suc a ≤ c
Any help is greatly appreciated.
Look at the s<=s constructor for the less than or equal to relation. Please ask on the course forums, not on stack overflow.