playground/coq/unfinished/2irrat.v

197 lines
3.7 KiB
Coq

(*
https://www.cs.ru.nl/~freek/comparison/comparison.pdf (page 36)
https://github.com/coq-community/gaia/blob/61303be0805404b916098dc40f4e946d3df6ac7c/theories/numbers/ssetr.v#L295
https://github.com/coq-community/coqtail-math/blob/5c22c3d7dcd8cf4c47cf84a281780f5915488e9e/Reals/Reirr.v#L465
*)
(* Attempt to duplicate coq example from '17 provers of the world' *)
Require Import Coq.Reals.Reals.
Require Import ArithRing.
Require Import Wf_nat.
Require Import Peano_dec.
Require Import Div2.
Require Import Even.
(*
(*Compute double 3.2.*)
Compute div2 3.
Theorem double_div2 : forall (n : nat),
div2 (double n) = n.
Proof.
intros.
induction n.
- reflexivity.
-
Qed.
*)
(* Old
Definition irrational (x : R) : Prop :=
forall (p : Z) (q : nat), q <> 0 -> x <> (IZR p / NZR q)%R.
(* The term "p" has type "Z" while it is expected to have type "R".
*)
*)
(* Set of real numbers *)
Print R.
Definition irrational (x:R) : Prop :=
forall (p:Z) (q:nat),
q <> 0 ->
x <> (IZR p/INR q)%R.
Check IZR. (* IZR : Z -> R *)
Check INR. (* INR : nat -> R *)
Check even. (* Say that a nat is an even number *)
Compute (div2 4). (* Divide a nat by 2 *)
Compute double 4. (* Multiply a nat by 2 *)
Check double_S.
(*
double_S
: forall n : nat, Nat.double (S n) = S (S (Nat.double n))
*)
Theorem double_div2 : forall n:nat,
div2 (double n) = n.
Proof.
intros.
induction n.
- reflexivity.
- rewrite double_S.
simpl.
rewrite IHn.
reflexivity.
Qed.
Compute (double_div2 4).
(*
= double_div2 4
: Nat.div2 (Nat.double 4) = 4
*)
Theorem double_inv : forall (n m:nat),
(double n = double m)
-> (n = m).
Proof.
intros.
rewrite <- (double_div2 n).
rewrite <- (double_div2 m).
rewrite H.
reflexivity.
Qed.
Theorem double_mult_left : forall (n m:nat),
double (n*m) = (double n) * m.
Proof.
intros.
unfold double.
auto with arith. (* TODO *)
Qed.
Theorem double_mult_right : forall (n m:nat),
double (n*m) = n * (double m).
Proof.
intros.
unfold double.
ring. (* TODO *)
Qed.
Print even.
(*
Inductive even : nat -> Prop :=
| even_O : even 0
| even_S : forall n : nat, odd n -> even (S n)
with odd : nat -> Prop :=
| odd_S : forall n : nat, even n -> odd (S n)
Arguments even _%nat_scope
Arguments even_S _%nat_scope
Arguments odd _%nat_scope
Arguments odd_S _%nat_scope
*)
Theorem even_times_even_is_even: forall n:nat,
even (n*n) -> even n.
Proof.
intros.
case (even_or_odd n).
- auto.
- apply (even_mult_inv_r _ _ H).
Qed.
(*
#+BEGIN_OUTPUT (Info)
even_mult_inv_r
: forall n m : nat, even (n * m) -> odd n -> even m
#+END_OUTPUT (Info) *)
(*
intros.
induction n.
- constructor.
-
Search (even _).
pose proof (even_mult_r n n).
apply (even_mult_r) with (n:=n;m:=n).
-
rewrite <- (even_mult_r n n).
apply n in (even_mult_r n n).
induction n.
- constructor.
- apply even_S.
Search (even (S _)).
- apply (S n) in IHn.
Search (even (_*_)).
Search (even _).
even_mult_r: forall n m : nat, even m -> even (n * m)
even_mult_l: forall n m : nat, even n -> even (n * m)
Search (even _).
*)
(*
1 subgoal
n : nat
H : even (S n * S n)
IHn : even (n * n) -> even n
========================= (1 / 1)
even (S n)
*)
Theorem main_th_aux : forall (n:nat),
(even n)
-> (double (double ((div2 n) * (div2 n)))) = (n * n).
Proof.
intros.
rewrite double_mult_left.
rewrite double_mult_right.
repeat (rewrite <- even_double; auto).
Qed.
Theorem main_th: forall (n p:nat),
n*n = double p*p
-> p = 0.
Proof.
intros n.
pattern n.
induction n.
- unfold Nat.double.
-
Search (double _).
Admitted.
Check sqrt. (* sqrt : R -> R *)
Print sqrt.
Theorem sqrt2_is_irrational : irrational (sqrt 2%R).
Proof.
Admitted.