Load loadpath.
Coq.ZArith.ZArith.
Set Implicit Arguments.
Unset Strict Implicit.
Section option.
Variables (A B : Type) (h : A -> B) (f : A -> option B) (o : option A).
Definition omap := match o with Some a => Some (h a) | None => None end.
Definition obnd := match o with Some a => f a | None => None end.
End option.
Implicit Arguments omap [A B].
Implicit Arguments obnd [A B].
Definition isSome {A : Type} (o : option A) :=
match o with Some _ => true | _ => false end.
Section comp.
Variables (A B C : Type) (g : B -> C) (f : A -> B) (a : A).
Definition compose := g (f a).
End comp.
Implicit Arguments compose [A B C].
(*new notation*)
(*Notation "f \o g" := (compose f g) (at level 54, right associativity).*)
(*for backwards compatibility*)
Infix "oo" := compose (at level 54, right associativity).
(*why does List appear to not export this notation?*)
Notation "[ ]" := nil.
Notation "[ x , .. , y ]" := (cons x .. (cons y []) ..).
Fixpoint zip_with_acc {A B : Type} acc (l1 : list A) (l2 : list B) :=
match l1, l2 with
| a :: l1', b :: l2' => (a, b) :: zip_with_acc acc l1' l2'
| _, _ => acc
end.
Definition zip {A B : Type} := @zip_with_acc A B [].
Section iter.
Variables (A : Type) (f : nat -> A -> A).
Fixpoint iter (n : nat) (a : A) :=
match n with
| O => a
| S n' => iter n' (f n' a)
end.
End iter.
Implicit Arguments iter [A].
Section tryfind.
Variables (A E B : Type) (f : A -> E + B).
Fixpoint tryfind (err : E) (l : list A) :=
match l with
| nil => inl _ err
| a :: l' => match f a with
| inl err' => tryfind err' l'
| inr success as r => r
end
end.
End tryfind.
Definition max (n m : nat) := if leb n m then m else n.
Definition maxs (l : list nat) := fold_left (fun m n => max m n) l 0.
Definition elemb (n : nat) := existsb (fun m => beq_nat n m).
(*positive lemmas*)

Lemma Ppred_decrease n : (n<>1)%positive -> (nat_of_P (Ppred n)<nat_of_P n)%nat.
Definition Nleb (x y : N) :=
match Ncompare x y with
| Lt => true
| Eq => true
| Gt => false
end.