Check (fun x:nat => x = 3).
Check (S O).
Check S.
Print S.

Locate " _ <= _".

Require Export ZArith.

Locate " _ <= _".

Require Export Reals.

Locate " _ <= _".
Locate " _ +  _".

Open Scope R_scope.

Check (1+1).
Check (1+1)%Z.
Check (1+1)%nat.

Locate "_ * _".

(*Check nat*bool.*)

Check (nat*bool)%type.

Open Scope type_scope.

Locate " _ * _ ".
Print prod.

Check Rplus.

Eval compute in (2+2)%Z.
Eval cbv in (2+2)%Z.
Eval lazy in (2+2)%Z.

(*Eval toto in (2+2)%Z.*)

Open Scope nat_scope.

Definition example1 := fun x : nat => x*x+2*x+1.
Definition example2:= fun x : nat => (x+1)*(x+1).

Eval compute in (example1 3).
Eval compute in (example2 3).

Lemma example : forall x, example1 x = example2 x.
Proof.
intros.
unfold example1, example2;
ring.
Qed.

Lemma f : forall n m:nat, n=m -> m=n.
Proof.

intros.
Check eq_ind.
apply (eq_ind) with (x:=n) (y:=m).
Show Proof.
reflexivity.
assumption.
(*
apply (@eq_ind nat n (fun (w:nat) => w=n)
(@refl_equal nat n) m H). *)
Qed.

Print f.

Eval compute in if true then 3 else 5.


Search bool.
SearchPattern ({_}+{_}).

Locate " _ / _ ".
Print Zdiv.
Eval compute in (Zdiv 2 0).

Definition g x y := match (Z_zerop x) with
| (left H) => (* H : x=0*) 0
| (right H') => (* h' : <>0 *) y
end.

Require Export List.

Eval compute in map (fun x => x + 3) (1::2::3::nil).

Fixpoint insert n l {struct l}:= match l with
| nil => n::nil
| x ::xs => if leb n x then n::l else x::insert n xs
end.

Eval compute in insert 1 (2::3::nil).
Eval compute in insert 3 (2::4::5::nil).

Fixpoint sort l :=
match l with
 nil => nil
| x::xs => insert x (sort xs)
end.

Eval compute in sort (2::3::7::1::4::5::5::8::nil). 

Print leb.

Lemma example6 : forall x y, (x+y)*(x+y) = x*x + 2*x*y + y*y.
Proof.
intros.

SearchRewrite (_ * (_ + _)).
SearchRewrite ((_ + _)*_).

rewrite mult_plus_distr_l.
rewrite mult_plus_distr_r.
rewrite mult_plus_distr_r.
Check plus_assoc.
rewrite plus_assoc.
rewrite <- plus_assoc with (n:=x*x).
rewrite (mult_comm y x).
pattern (x*y) at 1; rewrite <- mult_1_l.
Check mult_succ_l.
rewrite <- mult_succ_l.
rewrite <- mult_assoc.
reflexivity.
Qed.

Fixpoint sum (n:nat) {struct n}: nat :=
match n with O => O | (S p) => plus (sum p) (S p)
end.

Print list.

Fixpoint count n l :=
match l with 
 nil => O
| a::tl => let r:= count n tl in if beq_nat n a then 1+r else r
end.

Print insert.

Lemma eq_beq : forall x y, x<>y -> beq_nat x y = false.
Proof.
intros n.
elim n.
intros a.
case a.
simpl.
intros.
assert False.
apply H.
reflexivity.
elim H0.
simpl.
reflexivity.
intros n0 Hn0.
intros a.
case a.

simpl.
reflexivity.

intros.
simpl.
apply Hn0.
intro.
apply H.
subst n0.
reflexivity.
Qed.

Lemma insert_inscr : forall n l, count n (insert n l) = 1 + count n l.
Proof.
intros n l; elim l.
simpl.
(*rewrite <- beq_nat_refl.
reflexivity.*)
Print beq_nat.

elim n.
simpl.
reflexivity.
simpl.
intros; assumption.

intros.
simpl.
case (leb n a).

SearchAbout (beq_nat _ _).
Check eq_nat_dec.

elim (eq_nat_dec n a).
intro Hn0.
subst n.
simpl.
rewrite <- beq_nat_refl.
reflexivity.

intros.
assert (beq_nat n a = false).
apply eq_beq; assumption.
rewrite H0.
simpl.
rewrite <- beq_nat_refl.
rewrite H0.
reflexivity.

elim (eq_nat_dec n a).
intros Hna.
subst n.
rewrite <- beq_nat_refl.
simpl.
rewrite <- beq_nat_refl.
rewrite H.
simpl.
reflexivity.
intros.
assert (beq_nat n a=false).
apply eq_beq; assumption.
rewrite H0.
simpl.
rewrite H0.
rewrite H.
simpl.
reflexivity.
Qed.

Lemma insert_inscr' : forall n l, count n (insert n l) = 1 + count n l.
Proof.
intros n l; induction l.
simpl.
rewrite <- beq_nat_refl.
reflexivity.

simpl.
case (leb n a).
simpl.
rewrite <- beq_nat_refl.
reflexivity.

simpl.
case (beq_nat n a).
rewrite IHl.
simpl; reflexivity.
rewrite IHl.
simpl; reflexivity.
Qed.

Print beq_nat.

elim n.
simpl.
reflexivity.
simpl.
intros; assumption.

intros.
simpl.
case (leb n a).


SearchAbout (beq_nat _ _).
Check eq_nat_dec.

elim (eq_nat_dec n a).
intro Hn0.
subst n.
simpl.
rewrite <- beq_nat_refl.
reflexivity.

intros.
assert (beq_nat n a = false).
apply eq_beq; assumption.
rewrite H0.
simpl.
rewrite <- beq_nat_refl.
rewrite H0.
reflexivity.

elim (eq_nat_dec n a).
intros Hna.
subst n.
rewrite <- beq_nat_refl.
simpl.
rewrite <- beq_nat_refl.
rewrite H.
simpl.
reflexivity.
intros.
assert (beq_nat n a=false).
apply eq_beq; assumption.
rewrite H0.
simpl.
rewrite H0.
rewrite H.
simpl.
reflexivity.
Qed.


