induction

Induction on predicates with product type arguments

倾然丶 夕夏残阳落幕 提交于 2020-01-04 13:26:13
问题 If I have a predicate like this: Inductive foo : nat -> nat -> Prop := | Foo : forall n, foo n n. then I can trivially use induction to prove some dummy lemmas: Lemma foo_refl : forall n n', foo n n' -> n = n'. Proof. intros. induction H. reflexivity. Qed. However, for a predicate with product type arguments: Inductive bar : (nat * nat) -> (nat * nat) -> Prop := | Bar : forall n m, bar (n, m) (n, m). a similar proof for nearly identical lemma gets stuck because all assumptions about variables

Proof that a binary tree with n leaves has a height of at least log n

≡放荡痞女 提交于 2020-01-01 03:34:08
问题 I've been able to create a proof that shows the maximum total nodes in a tree is equal to n = 2^(h+1) - 1 and logically I know that the height of a binary tree is log n (can draw it out to see) but I'm having trouble constructing a formal proof to show that a tree with n leaves has "at least" log n. Every proof I've come across or been able to put together always deals with perfect binary trees, but I need something for any situation. Any tips to lead me in the right direction? 回答1: Lemma :

Induction principle for `le`

我怕爱的太早我们不能终老 提交于 2019-12-25 02:24:06
问题 For the inductive type nat , the generated induction principle uses the constructors O and S in its statement: Inductive nat : Set := O : nat | S : nat -> nat nat_ind : forall P : nat -> Prop, P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n But for le , the generated statement does not uses the constructors le_n and le_S : Inductive le (n : nat) : nat -> Prop := le_n : n <= n | le_S : forall m : nat, n <= m -> n <= S m le_ind : forall (n : nat) (P : nat -> Prop), P n -> (forall

Number of binary tree shapes of N nodes are there with height N-1?

笑着哭i 提交于 2019-12-13 22:02:32
问题 How many binary tree shapes of N nodes are there with height N-1? Also, how would you go about proofing by induction? So binary tree of height n-1 with node n means all node will have only 1 child, sort of chain like structure? So number of binary tree will be different permutation of n numbers which is n. Am I thinking in the right direction? 回答1: You are thinking in the right direction and you have correctly transformed the original problem to a simple one. However what is strange is that

An algorithm to determine a subset sequence in O(n)?

烈酒焚心 提交于 2019-12-13 09:28:40
问题 How can i aproach this problem by induction? Suppose that you are given an algorithm as a black box you cannot see how it is designed it has the following properties: if you input any sequence of real numbers and an integer k, the algorithm will answer YES or NO indicating whether there is a subset of numbers whose sum is exactly k. Show how to use this black box to find the subset of a given sequence {X1, …., Xn} whose sum is k. You can use the black box O(n) times. Any idea? 回答1: I'm not

Coq induction hypothesis is wrong

强颜欢笑 提交于 2019-12-13 04:12:35
问题 I'm trying to prove a simple induction on two lists, and for some reason Coq writes the induction hypothesis wrong. Here is my proof: Lemma eqb_list_true_iff_left_to_right : forall A (eqb : A -> A -> bool), (forall a1 a2, eqb a1 a2 = true <-> a1 = a2) -> forall l1 l2, eqb_list eqb l1 l2 = true -> l1 = l2. Proof. intros A eqb H1. induction l1 as [|a1 l1' IHl1'] eqn:E1. - induction l2 as [|a2 l2' IHl2'] eqn:E2. + reflexivity. + intros H2. simpl in H2. discriminate H2. - (* where did l1 = l1'