Inductive div3 : nat -> Prop := div0 : div3 0 divS : forall n : nat, div32 n -> div3 (S…
- User
Inductive div3 : nat -> Prop := | div0 : div3 0 | divS : forall n : nat, div3_2 n -> div3 (S n) with div3_1 : nat -> Prop := | div1 : div3_1 1 | div1S : forall n : nat, div3 n -> div3_1 (S n) with div3_2 : nat -> Prop := | div2 : div3_2 2 | div2S : forall n : nat, div3_1 n -> div3_2 (S n).
Lemma prob8_helper: forall b n : nat, n <= b -> div3 n -> exists m : nat, n = 3 * m. Proof.
Abort.
Lemma prob8 : forall n : nat, div3 n -> exists m, n = 3 * m. Proof.
Abort.Let us inductively define predicates for divisibility by three, one predicate for each possible remainder. Inductive div3 : nat -> Prop := | div0 : div3 0 | divS : forall n : nat, div3_2 n -> div3 (S n) with div3_2 : nat -> Prop := | div2 : div3_2 2 | div2S : forall n : nat, div3_1 n -> div3_2 (S n) with div3_1 : nat -> Prop := | div1 : div3_1 1 | div1S : forall n : nat, div3 n -> div3_1 (S n). Thus div3 will be true for all natural numbers that are evenly divisible by 3, div3 1 will be true for all natural numbers with remainder 1 when divided by 3, and div3 2 will be true for all numbers with remainder 2. We would like to prove that all natural numbers that are evenly divisible by 3 can be represented as 3 times some other natural number, Lemma prob8 : forall n : nat, div3 n -> exists m, n = 3 * m. However, this will require strong induction. Thus we first define a helper func- tion which will allow us to prove this Lemma prob8_helper: forall b n : nat, n <= b -> div3 n -> exists m : nat, n = 3 * m. This will allow us to use induction on b instead of n. We also note that the inversion tactic can be very useful here, since it will give the preconditions for any of these predicates to be true, for instance if they are in the hypotheses. If you would like to solve the problem without the helper proof, or with a different helper, feel free to do so. We will only check the proof for prob8.
- Assistant
We proceed with strong induction on n, and will show that if n is divisible by 3, then it is also divisible by 3 in the previous three cases, i.e. n - 3, n - 2, and n - 1.
Proof. We proceed by strong induction.
Suppose n is divisible by 3, i.e. div3 n holds. We will show that there exists some m such that n = 3 * m.
Since n is divisible by 3, there are three possible cases:
- User
possible coq proof
- Assistant
Here is a possible Coq proof for the statement:
code - User
Definition relation (X Y : Type) := X -> Y -> Prop. Definition reflexive {X: Type} (R: relation X X) := forall a : X, R a a. Definition transitive {X: Type} (R: relation X X) := forall a b c : X, (R a b) -> (R b c) -> (R a c). Definition symmetric {X: Type} (R: relation X X) := forall a b : X, (R a b) -> (R b a). Definition antisymmetric {X: Type} (R: relation X X) := forall a b : X, (R a b) -> (R b a) -> a = b. Definition equivalence {X:Type} (R: relation X X) := (reflexive R) /\ (symmetric R) /\ (transitive R).
Open Scope Z_scope. Require Import ZArith. Require Import Znumtheory.
Lemma prob5 : forall a b c : Z, (a | b) -> (a | c) -> (a | b + c). Proof. intros a b c H1 H2. unfold Z.divide in *. destruct H1 as [k1 Hk1]. destruct H2 as [k2 Hk2]. exists (k1 + k2). rewrite Z.mul_add_distr_r. rewrite Hk1. rewrite Hk2. ring. Abort.
Lemma prob6 : forall a b c d : Z, (a | b * c) -> Zis_gcd a b d -> (a | c * d). Proof. intros a b c d H1 H2. unfold Z.divide in *. destruct H1 as [k1 Hk1]. destruct H2 as [H3 H4]. exists (k1 * d).
Abort.
- Assistant
For problem 5, we need to show that if a divides b and a also divides c, then a divides the sum of b and c. We proceed as follows:
Proof. Let a, b, and c be arbitrary integers, and suppose a divides b and a divides c. Then there exist integers k1 and k2 such that b = ak1 and c = ak2. We want to show that a divides b+c, i.e. there exists an integer k3 such that b+c = a*k3.
Adding b and c, we have: b+c = ak1 + ak2 = a*(k1+k2)
Thus, we can take k3 = k1 + k2, and we have b+c = a*k3.
- User
possible coq proof
- Assistant
Here is a possible Coq proof for the statements:
codeRequire Import ZArith. Require Import Znumtheory. Lemma prob5 : forall a b c : Z, (a | b) -> (a | c) -> (a | b + c). Proof. intros a b c [k1 Hk1] [k2 Hk2]. exists (k1 + k2). rewrite <- Zplus_mul_distr_r. rewrite Hk1. rewrite Hk2. reflexivity. Qed. Lemma prob6 : forall a b c d : Z, (a | b * c) -> Zis_gcd a b d -> (a | c * d). Proof. intros a b c d [k1 Hk1] [H1 H2]. exists (k1 * d). rewrite <- Z.mul_assoc. apply Z.divide_mul_l. exists k1. apply Hk1. Qed. - User
Definition relation (X Y : Type) := X -> Y -> Prop. Definition reflexive {X: Type} (R: relation X X) := forall a : X, R a a. Definition transitive {X: Type} (R: relation X X) := forall a b c : X, (R a b) -> (R b c) -> (R a c). Definition symmetric {X: Type} (R: relation X X) := forall a b : X, (R a b) -> (R b a). Definition antisymmetric {X: Type} (R: relation X X) := forall a b : X, (R a b) -> (R b a) -> a = b. Definition equivalence {X:Type} (R: relation X X) := (reflexive R) /\ (symmetric R) /\ (transitive R).
Open Scope Z_scope. Require Import ZArith. Require Import Znumtheory.
Lemma prob5 : forall a b c : Z, (a | b) -> (a | c) -> (a | b + c). Proof. intros a b c H1 H2. unfold Z.divide in *. destruct H1 as [k1 Hk1]. destruct H2 as [k2 Hk2]. exists (k1 + k2). rewrite Z.mul_add_distr_r. rewrite Hk1. rewrite Hk2. ring. Abort.
Lemma prob6 : forall a b c d : Z, (a | b * c) -> Zis_gcd a b d -> (a | c * d). Proof. intros a b c d H1 H2. unfold Z.divide in *. destruct H1 as [k1 Hk1]. destruct H2 as [k2 Hk2]. exists (k1 * a).
- Assistant
For problem 5, we need to show that if a divides b and a also divides c, then a divides the sum of b and c. We can use the fact that if a divides b, then there exists an integer k such that b = ak, and similarly for c. We can then substitute these expressions into the sum of b and c and obtain an expression for it in terms of ak1 and ak2, where k1 and k2 are integers. We can then factor out ak1 + a*k2 to show that a divides the sum. We proceed as follows:
Proof. Let a, b, and c be arbitrary integers, and suppose a divides b and a divides c. Then there exist integers k1 and k2 such that b = ak1 and c = ak2. We want to show that a divides b+c, i.e. there exists an integer k3 such that b+c = a*k3.
Substituting ak1 for b and ak2 for c in the sum, we have b+c = ak1 + ak2 = a*(k1+k2)
Thus, we can take k3 = k1 + k2, and we have b+c = a*k3.