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.
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?
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)
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.
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.