Library zoo.common.math

Require Export Stdlib.micromega.ZifyNat.

Require Export stdpp.numbers.

Require Import zoo.prelude.
Require Import zoo.common.relations.
Require Import zoo.options.

Section nat.
  #[global] Instance b2ninj :
    Inj (=) (=) Nat.b2n.

  Definition nat۰elim {A} (x : A) f n :=
    match n with
    | 0 ⇒
        x
    | ˖n
        f n
    end.
  #[global] Arguments nat۰elim _ _ _ !_ / : assert.

  #[global] Instance gepartialorder :
    PartialOrder ge.

  #[global] Instance leinitial : Initial (≤) :=
    {|initial := 0
    ; initiallb := Nat.le_0_l
    |}.

  Lemma minusmod₁ a b n :
    b a
    b `mod` n a `mod` n
    (a `mod` n - b `mod` n) `mod` n = (a - b) `mod` n.
  Lemma minusmod₁' a b n :
    n 0
    b a
    b `mod` n a `mod` n
    a `mod` n - b `mod` n = (a - b) `mod` n.
  Lemma minusmod₁'' a b n :
    n 0
    a `mod` n (a + b) `mod` n
    (a + b) `mod` n - a `mod` n = b `mod` n.
  Lemma minusmod₂ a b n :
    n 0
    a b
    b `mod` n a `mod` n
    a `mod` n - b `mod` n = (n - (b - a) `mod` n) `mod` n.
End nat.

Notation "(≥)" :=
  Z.ge
( only parsing
) : Z_scope.

Section Z.
  #[local] Open Scope Z_scope.

  Lemma Zremmod x y :
    0 x
    0 y
    x `rem` y = x `mod` y.
End Z.

Section Qp۰of_nat.
  Implicit Type n : nat.

  Definition Qp۰of_nat :=
    pos_to_Qp Pos.of_nat.

  Lemma Qp۰of_natー1 :
    Qp۰of_nat 1 = 1%Qp.
  Lemma Qp۰of_natS n :
    n 0
    Qp۰of_nat ˖n = (1 + Qp۰of_nat n)%Qp.
End Qp۰of_nat.