253 lines
4.1 KiB
Coq
253 lines
4.1 KiB
Coq
Require Import ZArith.
|
|
Require Import Arith.
|
|
Require Import Lia.
|
|
|
|
Definition Zeven_even : forall n m:Z,
|
|
((Z.Even n) /\ (Z.Even m))
|
|
-> Z.Even (n+m) /\ Z.Even (n-m).
|
|
intros n m [[p Hp] [q Hq]].
|
|
unfold Z.Even.
|
|
rewrite Hp.
|
|
rewrite Hq.
|
|
split.
|
|
- exists (p+q)%Z.
|
|
lia.
|
|
- exists (p-q)%Z.
|
|
lia.
|
|
Qed.
|
|
|
|
|
|
Definition Zodd_odd : forall n m:Z,
|
|
((Z.Odd n) /\ (Z.Odd m))
|
|
-> Z.Even (n+m) /\ Z.Even (n-m).
|
|
Proof.
|
|
intros n m [[p Hp] [q Hq]].
|
|
unfold Z.Even.
|
|
rewrite Hp.
|
|
rewrite Hq.
|
|
split.
|
|
- exists (p+q+1)%Z.
|
|
lia.
|
|
- exists (p-q)%Z.
|
|
lia.
|
|
Qed.
|
|
|
|
Definition Zeven_odd : forall n m:Z,
|
|
(Z.Even n) /\ (Z.Odd m)
|
|
-> Z.Odd (n+m) /\ Z.Odd (n-m).
|
|
Proof.
|
|
intros n m [[p Hp] [q Hq]].
|
|
unfold Z.Odd.
|
|
rewrite Hp.
|
|
rewrite Hq.
|
|
split.
|
|
- exists (p+q)%Z.
|
|
lia.
|
|
- exists (p-q-1)%Z.
|
|
lia.
|
|
Qed.
|
|
|
|
Fixpoint sum_i_n (start:Z) (n:nat):Z :=
|
|
match n with
|
|
| O => 0%Z
|
|
| S n' => start + (sum_i_n (start+1) n')
|
|
end.
|
|
Compute sum_i_n 1 10.
|
|
|
|
Search (nat -> Z).
|
|
|
|
Lemma Even_0: Nat.Even 0.
|
|
Proof.
|
|
unfold Nat.Even.
|
|
exists 0.
|
|
reflexivity.
|
|
Qed.
|
|
|
|
|
|
Require Import Arith ZArith.
|
|
|
|
Lemma Odd_Nat_Z : forall n:nat,
|
|
Nat.Odd n -> Z.Odd (Z.of_nat n).
|
|
Proof.
|
|
intros n H.
|
|
destruct n.
|
|
- destruct H.
|
|
lia.
|
|
- destruct H.
|
|
unfold Z.Odd.
|
|
rewrite H.
|
|
Search (Nat.Odd _ -> Z.Odd _).
|
|
unfold Z.of_nat.
|
|
lia.
|
|
unfold Z.Odd.
|
|
|
|
unfold Z.Odd.
|
|
unfold Z.of_nat.
|
|
Theorem foo: forall n:nat,
|
|
Nat.Odd n ->
|
|
Z.Odd (sum_i_n 1 n).
|
|
Proof.
|
|
intros n H.
|
|
induction n.
|
|
- simpl.
|
|
Search (Z.Odd).
|
|
Search (Nat.Even).
|
|
|
|
Print Z.
|
|
Search (N -> Z).
|
|
Compute Z.of_N 2.
|
|
|
|
(*
|
|
Fixpoint sumn_aux (n acc:nat) : nat :=
|
|
match n with
|
|
| O => acc
|
|
| S n' => n + (sumn_aux n' acc)
|
|
end.
|
|
Definition sumn (n:nat) : nat := sumn_aux n 0.
|
|
|
|
Lemma nat_sum_n (n:nat): sumn n = (n*(n+1)/2).
|
|
Proof.
|
|
unfold sumn.
|
|
induction n.
|
|
- trivial.
|
|
- simpl.
|
|
rewrite IHn.
|
|
simpl.
|
|
unfold sumn_aux.
|
|
|
|
Lemma foo: forall n:nat,
|
|
Nat.Odd n -> Z.Odd (Z.of_nat (sumn n)).
|
|
Proof.
|
|
intros n H.
|
|
unfold sumn.
|
|
unfold Z.Odd.
|
|
unfold sumn_aux.
|
|
*)
|
|
|
|
(*************************************************************)
|
|
(* nat *)
|
|
(*************************************************************)
|
|
Require Import Arith.
|
|
Require Import Lia.
|
|
|
|
Definition even_even : forall n m:nat,
|
|
((Nat.Even n) /\ (Nat.Even m))
|
|
-> Nat.Even (n+m) /\ Nat.Even (n-m).
|
|
intros n m [[p Hp] [q Hq]].
|
|
split.
|
|
- unfold Nat.Even.
|
|
rewrite Hp.
|
|
rewrite Hq.
|
|
exists (p+q).
|
|
lia.
|
|
- unfold Nat.Even.
|
|
rewrite Hp.
|
|
rewrite Hq.
|
|
exists (p-q).
|
|
lia.
|
|
Qed.
|
|
|
|
Definition odd_odd : forall n m:nat,
|
|
((Nat.Odd n) /\ (Nat.Odd m))
|
|
-> Nat.Even (n+m) /\ Nat.Even (n-m).
|
|
Proof.
|
|
intros n m [[p Hp] [q Hq]].
|
|
unfold Nat.Even.
|
|
rewrite Hp.
|
|
rewrite Hq.
|
|
split.
|
|
- exists (p+q+1).
|
|
lia.
|
|
- exists (p-q).
|
|
lia.
|
|
Qed.
|
|
|
|
|
|
|
|
|
|
Definition even_odd : forall n m:nat,
|
|
n < m
|
|
-> (Nat.Even n) /\ (Nat.Odd m)
|
|
-> Nat.Odd (n+m) /\ Nat.Odd (n-m).
|
|
Proof.
|
|
intros n m H [[p Hp] [q Hq]].
|
|
unfold Nat.Odd.
|
|
subst.
|
|
split.
|
|
- exists (p+q).
|
|
lia.
|
|
- exists (p-q-1).
|
|
(* --output DPI-1 --mode 1960x1080 *)
|
|
lia.
|
|
simpl.
|
|
rewrite (Nat.add_0_r p).
|
|
rewrite (Nat.add_0_r q).
|
|
simpl.
|
|
Search (_ + 0 = _).
|
|
lia.
|
|
Qed.
|
|
|
|
Definition odd_even : forall n m:nat,
|
|
(Nat.Odd m) /\ (Nat.Even n)
|
|
-> Nat.Odd (n+m).
|
|
Proof.
|
|
intros n m [[p Hp] [q Hq]].
|
|
exists (p+q).
|
|
lia.
|
|
Qed.
|
|
|
|
|
|
|
|
Lemma odd7: Nat.Odd 7.
|
|
Proof.
|
|
unfold Nat.Odd.
|
|
exists 3.
|
|
lia.
|
|
Qed.
|
|
|
|
|
|
Lemma even4: Nat.Even 4.
|
|
Proof.
|
|
unfold Nat.Even.
|
|
exists 2.
|
|
lia.
|
|
Qed.
|
|
|
|
(*
|
|
Definition even_even_b : forall n m:nat,
|
|
andb (Nat.even n) (Nat.even m) = true
|
|
-> Nat.even (n+m) = true.
|
|
Proof.
|
|
intros n m H.
|
|
induction n.
|
|
- trivial.
|
|
- Abort.
|
|
|
|
Definition even_even : forall n m:nat,
|
|
((Nat.Even n) /\ (Nat.Even m))
|
|
-> Nat.Even (n+m).
|
|
intros n m H.
|
|
destruct H.
|
|
Search (Nat.Even).
|
|
induction n.
|
|
- trivial.
|
|
- simpl.
|
|
|
|
|
|
destruct IHn.
|
|
trivial.
|
|
+ simpl.
|
|
destruct H.
|
|
rewrite Nat.Even_succ.
|
|
Search (Nat.Even).
|
|
destruct IHn.
|
|
* split.
|
|
simpl.
|
|
rewrite Nat.Even_succ in H.
|
|
try contradiction.
|
|
|
|
(*
|
|
|
|
*)
|
|
*)
|