361 Machine check in Rocq— Verified

The chain from the identity to Gibbs’ inequality was checked in the Rocq prover, version 9.3.0, in a single file Ent.v of 1581 lines, listed below. The file imports nothing except the ring tactic, which proves equations from the semiring laws established in E7; it adds no axiom. Each of the 53 commands Print Assumptions at the end of the file returns Closed under the global context: no axiom is used anywhere in the chain.

step

statement

Rocq name

E1

reading at the identity: both triangles

read_place, place_read

E2

\(\ell \neq r\); a cut is decided; \(p^2=p\)

l_ne_r, em_two, meet_idem

E3

extensionality from sameness by readings

funext_in_kinds, propext_in_kinds

E4

\(0\neq s(n)\); recursion is unique

z_ne_s, rec_unique

E5

order: irreflexive, total

lt_irrefl, lt_total

E6

sum, product, power are sizes

addIso, mulIso, powIso

E7

laws of sum, product, power

mul_assoc, pow_add, mul_pow

E8

\(2^b>b\); Bernoulli

lt_two_pow, bern

E9

fractions form a kind; order decided

sameQ_trans, ltQ_total

E10, E13

the logarithm is a pair of decided cuts

inL_resp, log_located, log_rounded_L

E14

\(\log (nn')=\log n+\log n'\)

log_mul_L, log_mul_U

E12, E19

an additive monotone reading lies on the logarithm

boltzmann_L, boltzmann_U

E20

\(W\,a^ab^b\leq N^N\)

gibbs_count_upper

E22

\(a+b=c+d\Rightarrow c^ad^b\leq a^ab^b\)

gibbs_ineq

Three choices make the check free of axioms.

point how it is handled
sameness of maps read as agreement under every reading (Kind), as in E3
excluded middle held by statements that are cuts, \(A\to \mathbf 2\), as in E2
real numbers statements are checked in exponentiated form

The last row means that E20 is checked as \(W\,a^ab^b\leq N^N\) and E22 as \(c^ad^b\leq a^ab^b\). Since the logarithm is additive and monotone (E13, E14), these are E20 and E22 read through it: \(\ln W\leq N H(p)\) and \(\sum _ip_i\ln q_i\leq \sum _ip_i\ln p_i\). The real exponential and logarithm of E15–E18 are not formalised; nothing in the checked statements depends on them.

The check is reproduced by

coqc Ent.v

whose output is 53 lines, each reading Closed under the global context.

The file Ent.v.

Ent.v

(* ======================================================================
   Ent.v - Entropy from the identity, one chain, in Rocq.

   Sections follow E1-E22 of the paper:
     0  E1-E3    identity, pairs, sums, maps, kinds
     1  E4-E5    numbers, order
     2  E6-E8    sizes, laws
     3  E9       fractions
     4-5 E10, E12-E14, E19   the logarithm as a pair of decided cuts;
                             Boltzmann: an additive reading lies on it
     7   E20                 Gibbs: W * a^a * b^b <= N^N  (W <= e^{N H})
     8   E22                 Gibbs' inequality: a+b = c+d -> c^a d^b <= a^a b^b

   No axioms. The `Print Assumptions` lines at the end must each print
       Closed under the global context
   Only import: Ring (the `ring` tactic; it proves equations from the
   semiring laws registered in E7 and adds no axiom).
   For Coq 8.x (before Rocq 9), write `From Coq` instead of `From Stdlib`.
   ====================================================================== *)

From Stdlib Require Import Ring.



(* ----------------------------------------------------------------------
   E1  identity, copy, pair
   ---------------------------------------------------------------------- *)

Section Yoneda.
  Variable F : Type -> Type.
  Variable fmap : forall X Y : Type, (X -> Y) -> F X -> F Y.
  Hypothesis fmap_id : forall (X : Type) (x : F X), fmap X X (fun a => a) x = x.
  Variable A : Type.

  (* reading a natural family at the identity *)
  Definition readId (eta : forall B : Type, (A -> B) -> F B) : F A :=
    eta A (fun a => a).

  (* placing an element along every arrow *)
  Definition place (x : F A) : forall B : Type, (A -> B) -> F B :=
    fun B f => fmap A B f x.

  (* triangle (i) *)
  Lemma read_place (x : F A) : readId (place x) = x.
  Proof. unfold readId, place. apply fmap_id. Qed.

  (* triangle (ii), for natural families *)
  Lemma place_read (eta : forall B : Type, (A -> B) -> F B)
    (nat : forall (B C : Type) (g : B -> C) (f : A -> B),
             eta C (fun a => g (f a)) = fmap B C g (eta B f))
    (B : Type) (f : A -> B) : place (readId eta) B f = eta B f.
  Proof. unfold place, readId. symmetry. apply (nat A B f (fun a => a)). Qed.
End Yoneda.

(* substitution: an equality is read at refl *)
Definition transport {A : Type} (P : A -> Type) {a b : A} (h : a = b) (pa : P a) : P b :=
  eq_rect a P pa b h.

Definition pairUp {C A B : Type} (f : C -> A) (g : C -> B) : C -> A * B :=
  fun c => (f c, g c).

(* the copy is the pair of two identities *)
Definition copy {A : Type} : A -> A * A := pairUp (fun a => a) (fun a => a).

Lemma fst_pair {C A B : Type} (f : C -> A) (g : C -> B) (c : C) : fst (pairUp f g c) = f c.
Proof. reflexivity. Qed.

Lemma snd_pair {C A B : Type} (f : C -> A) (g : C -> B) (c : C) : snd (pairUp f g c) = g c.
Proof. reflexivity. Qed.

Lemma pair_eta {C A B : Type} (h : C -> A * B) (c : C) :
  pairUp (fun x => fst (h x)) (fun x => snd (h x)) c = h c.
Proof. unfold pairUp. destruct (h c). reflexivity. Qed.

Lemma fst_copy {A : Type} (a : A) : fst (copy a) = a.
Proof. reflexivity. Qed.

Lemma snd_copy {A : Type} (a : A) : snd (copy a) = a.
Proof. reflexivity. Qed.

(* pairs are equal exactly when their components are *)
Lemma pair_ext {A B : Type} (p q : A * B) : fst p = fst q -> snd p = snd q -> p = q.
Proof. destruct p, q. simpl. intros h1 h2. subst. reflexivity. Qed.

Definition swap {A B : Type} (p : A * B) : B * A := (snd p, fst p).

Lemma swap_swap {A B : Type} (p : A * B) : swap (swap p) = p.
Proof. destruct p. reflexivity. Qed.

Lemma swap_copy {A : Type} (a : A) : swap (copy a) = copy a.
Proof. reflexivity. Qed.

Lemma one_unique (x y : unit) : x = y.
Proof. destruct x, y. reflexivity. Qed.

(* ----------------------------------------------------------------------
   E2  the empty kind, sums, two
   ---------------------------------------------------------------------- *)

Inductive Two : Type := l | r.

(* case map into kinds: P l = 1, P r = 0 *)
Definition P (t : Two) : Type :=
  match t with l => unit | r => Empty_set end.

(* l <> r: otherwise the mark of 1 would be an element of 0 *)
Lemma l_ne_r : l <> r.
Proof.
  intro h.
  assert (e : P r) by (rewrite <- h; exact tt).
  simpl in e. destruct e.
Qed.

Lemma two_cases (t : Two) : t = l \/ t = r.
Proof. destruct t; [left | right]; reflexivity. Qed.

(* excluded middle for statements that are cuts: a theorem *)
Lemma em_two (t : Two) : t = l \/ ~ t = l.
Proof.
  destruct t.
  - left. reflexivity.
  - right. intro h. exact (l_ne_r (eq_sym h)).
Qed.

Definition Cut (A : Type) : Type := A -> Two.

Lemma cut_decided {A : Type} (c : Cut A) (a : A) : c a = l \/ c a = r.
Proof. apply two_cases. Qed.

Lemma cut_not_both {A : Type} (c : Cut A) (a : A) : c a = l -> c a = r -> False.
Proof. intros h1 h2. apply l_ne_r. rewrite <- h1, <- h2. reflexivity. Qed.

Definition meet (s t : Two) : Two :=
  match s with l => t | r => r end.

(* p^2 = p *)
Lemma meet_idem (t : Two) : meet t t = t.
Proof. destruct t; reflexivity. Qed.

(* pq = qp *)
Lemma meet_comm (s t : Two) : meet s t = meet t s.
Proof. destruct s, t; reflexivity. Qed.

(* equality in a sum, computed by cases *)
Definition code {A B : Type} (x y : (A + B)%type) : Prop :=
  match x, y with
  | inl a, inl a' => a = a'
  | inr b, inr b' => b = b'
  | _, _ => False
  end.

Lemma code_refl {A B : Type} (x : (A + B)%type) : code x x.
Proof. destruct x; simpl; reflexivity. Qed.

Lemma encode {A B : Type} (x y : (A + B)%type) : x = y -> code x y.
Proof. intro h. rewrite <- h. apply code_refl. Qed.

Lemma inl_inj {A B : Type} (a a' : A) : (inl a : (A + B)%type) = inl a' -> a = a'.
Proof. intro h. exact (encode _ _ h). Qed.

Lemma inr_inj {A B : Type} (b b' : B) : (inr b : (A + B)%type) = inr b' -> b = b'.
Proof. intro h. exact (encode _ _ h). Qed.

Lemma inl_ne_inr {A B : Type} (a : A) (b : B) : (inl a : (A + B)%type) <> inr b.
Proof. intro h. exact (encode _ _ h). Qed.

(* ----------------------------------------------------------------------
   E3  maps form a kind; a kind carries its own sameness
   ---------------------------------------------------------------------- *)

Definition lam {A B C : Type} (h : C * B -> A) : C -> B -> A := fun c b => h (c, b).
Definition ev {A B : Type} (p : (B -> A) * B) : A := (fst p) (snd p).

Lemma ev_lam {A B C : Type} (h : C * B -> A) (p : C * B) :
  ev (lam h (fst p), snd p) = h p.
Proof. destruct p. reflexivity. Qed.

Lemma lam_ev {A B C : Type} (k : C -> B -> A) :
  lam (fun p : C * B => ev (k (fst p), snd p)) = k.
Proof. reflexivity. Qed.

Record Kind : Type := {
  carrier : Type;
  same : carrier -> carrier -> Prop;
  same_refl : forall a, same a a;
  same_symm : forall a b, same a b -> same b a;
  same_trans : forall a b c, same a b -> same b c -> same a c
}.

(* an arrow of kinds: a reading that gives the same on the same *)
Record Arrow (A B : Kind) : Type := {
  fn : carrier A -> carrier B;
  resp : forall a a', same A a a' -> same B (fn a) (fn a')
}.
Arguments fn {A B} _ _.
Arguments resp {A B} _ _ _ _.

(* two arrows are the same when every reading gives the same *)
Definition funKind (A B : Kind) : Kind.
Proof.
  refine {| carrier := Arrow A B;
            same := fun f g => forall a, same B (fn f a) (fn g a);
            same_refl := _; same_symm := _; same_trans := _ |}.
  - intros f a. apply same_refl.
  - intros f g h a. apply same_symm. apply h.
  - intros f g k h1 h2 a. apply (same_trans B _ (fn g a)); [apply h1 | apply h2].
Defined.

(* function extensionality: a theorem *)
Lemma funext_in_kinds (A B : Kind) (f g : Arrow A B) :
  (forall a, same B (fn f a) (fn g a)) -> same (funKind A B) f g.
Proof. intro h. exact h. Qed.

Definition propKind : Kind.
Proof.
  refine {| carrier := Prop;
            same := fun p q => p <-> q;
            same_refl := _; same_symm := _; same_trans := _ |}.
  - intro p. split; intro x; exact x.
  - intros p q [h1 h2]. split; assumption.
  - intros p q s [h1 h2] [k1 k2]. split; intro x; [apply k1, h1 | apply h2, k2]; exact x.
Defined.

(* propositional extensionality: a theorem *)
Lemma propext_in_kinds (p q : Prop) : (p -> q) -> (q -> p) -> same propKind p q.
Proof. intros h1 h2. split; assumption. Qed.

(* ----------------------------------------------------------------------
   E4  numbers
   ---------------------------------------------------------------------- *)

(* the least kind with zero and successor: mu X. 1 + X; its recursor is leastness *)
Inductive N : Type := z | s (n : N).

Definition isZ (n : N) : Type :=
  match n with z => unit | s _ => Empty_set end.

Lemma z_ne_s (n : N) : z <> s n.
Proof.
  intro h.
  assert (e : isZ (s n)) by (rewrite <- h; exact tt).
  simpl in e. destruct e.
Qed.

Definition predN (n : N) : N :=
  match n with z => z | s m => m end.

Lemma s_inj (m n : N) : s m = s n -> m = n.
Proof. intro h. exact (f_equal predN h). Qed.

Lemma z_or_s (n : N) : n = z \/ exists m, n = s m.
Proof. destruct n as [| m]. - left. reflexivity. - right. exists m. reflexivity. Qed.

(* recursion: existence *)
Fixpoint iter {X : Type} (a : X) (g : X -> X) (n : N) : X :=
  match n with z => a | s m => g (iter a g m) end.

Lemma iter_z {X : Type} (a : X) (g : X -> X) : iter a g z = a.
Proof. reflexivity. Qed.

Lemma iter_s {X : Type} (a : X) (g : X -> X) (n : N) : iter a g (s n) = g (iter a g n).
Proof. reflexivity. Qed.

(* recursion: uniqueness *)
Lemma rec_unique {X : Type} (a : X) (g : X -> X) (h k : N -> X)
  (hz : h z = a) (hs : forall n, h (s n) = g (h n))
  (kz : k z = a) (ks : forall n, k (s n) = g (k n)) : forall n, h n = k n.
Proof.
  intro n. induction n as [| n IH].
  - rewrite hz, kz. reflexivity.
  - rewrite hs, ks, IH. reflexivity.
Qed.

(* the row of length n *)
Fixpoint Row (n : N) : Type :=
  match n with z => Empty_set | s m => sum (Row m) unit end.

(* ----------------------------------------------------------------------
   E5  order
   ---------------------------------------------------------------------- *)

(* the least relation with n < s n and m < n -> m < s n *)
Inductive Lt (m : N) : N -> Prop :=
  | base : Lt m (s m)
  | step : forall n, Lt m n -> Lt m (s n).
Arguments base {m}.
Arguments step {m n} _.

Lemma not_lt_z (m : N) : ~ Lt m z.
Proof. intro h. inversion h. Qed.

Lemma lt_inv (n m : N) : Lt n m -> exists k, m = s k /\ (Lt n k \/ n = k).
Proof.
  intro h. destruct h as [| k h'].
  - exists n. split; [reflexivity | right; reflexivity].
  - exists k. split; [reflexivity | left; exact h'].
Qed.

Lemma lt_s_inv (m n : N) : Lt m (s n) -> Lt m n \/ m = n.
Proof.
  intro h. destruct (lt_inv m (s n) h) as [k [hk hor]].
  apply s_inj in hk. subst k. exact hor.
Qed.

Lemma lt_trans (k m n : N) : Lt k m -> Lt m n -> Lt k n.
Proof.
  intros h1 h2. induction h2 as [| n h2 IH].
  - apply step. exact h1.
  - apply step. exact IH.
Qed.

Lemma z_lt_s (n : N) : Lt z (s n).
Proof.
  induction n as [| n IH].
  - apply base.
  - apply step. exact IH.
Qed.

Lemma s_lt_s (m n : N) : Lt m n -> Lt (s m) (s n).
Proof.
  intro h. induction h as [| n h IH].
  - apply base.
  - apply step. exact IH.
Qed.

Lemma lt_irrefl (n : N) : ~ Lt n n.
Proof.
  induction n as [| n IH].
  - apply not_lt_z.
  - intro h. destruct (lt_s_inv (s n) n h) as [h' | e].
    + apply IH. exact (lt_trans n (s n) n base h').
    + apply IH. pose proof (@base n) as hb. rewrite e in hb. exact hb.
Qed.

Lemma lt_total (m n : N) : Lt m n \/ m = n \/ Lt n m.
Proof.
  induction n as [| n IH].
  - destruct m as [| m].
    + right. left. reflexivity.
    + right. right. apply z_lt_s.
  - destruct IH as [h | [e | h]].
    + left. apply step. exact h.
    + left. subst. apply base.
    + destruct (lt_inv n m h) as [k [hm [hk | e]]].
      * right. right. subst m. apply s_lt_s. exact hk.
      * right. left. subst. reflexivity.
Qed.

(* ----------------------------------------------------------------------
   E6  sum, product, power are sizes
   ---------------------------------------------------------------------- *)

Fixpoint add (a b : N) {struct b} : N :=
  match b with z => a | s b' => s (add a b') end.

Fixpoint mul (a b : N) {struct b} : N :=
  match b with z => z | s b' => add (mul a b') a end.

Fixpoint pow (a b : N) {struct b} : N :=
  match b with z => s z | s b' => mul (pow a b') a end.

(* a bijection, with both triangles *)
Record Iso (X Y : Type) : Type := {
  to : X -> Y;
  inv : Y -> X;
  inv_to : forall x, inv (to x) = x;
  to_inv : forall y, to (inv y) = y
}.
Arguments to {X Y} _ _.
Arguments inv {X Y} _ _.
Arguments inv_to {X Y} _ _.
Arguments to_inv {X Y} _ _.

Definition symmIso {X Y : Type} (e : Iso X Y) : Iso Y X :=
  {| to := inv e; inv := to e; inv_to := to_inv e; to_inv := inv_to e |}.

Definition transIso {X Y Z : Type} (f : Iso X Y) (g : Iso Y Z) : Iso X Z.
Proof.
  refine {| to := fun x : X => to g (to f x);
            inv := fun c : Z => inv f (inv g c);
            inv_to := _; to_inv := _ |}.
  - intro x. cbn. rewrite (inv_to g (to f x)). apply (inv_to f).
  - intro c. cbn. rewrite (to_inv f (inv g c)). apply (to_inv g).
Defined.

Definition sumCongrLeft {X Y : Type} (Z : Type) (e : Iso X Y) : Iso (X + Z) (Y + Z).
Proof.
  refine {| to := fun t : X + Z => match t with inl x => inl (to e x) | inr c => inr c end;
            inv := fun t : Y + Z => match t with inl y => inl (inv e y) | inr c => inr c end;
            inv_to := _; to_inv := _ |}.
  - intros [x | c]; cbn; [rewrite (inv_to e x) |]; reflexivity.
  - intros [y | c]; cbn; [rewrite (to_inv e y) |]; reflexivity.
Defined.

Definition prodCongrLeft {X Y : Type} (Z : Type) (e : Iso X Y) : Iso (X * Z) (Y * Z).
Proof.
  refine {| to := fun p : X * Z => (to e (fst p), snd p);
            inv := fun p : Y * Z => (inv e (fst p), snd p);
            inv_to := _; to_inv := _ |}.
  - intros [x c]. cbn. rewrite (inv_to e x). reflexivity.
  - intros [y c]. cbn. rewrite (to_inv e y). reflexivity.
Defined.

Definition sumAssoc (X Y Z : Type) : Iso ((X + Y) + Z) (X + (Y + Z)).
Proof.
  refine {| to := fun t : (X + Y) + Z => match t with
                           | inl (inl x) => inl x
                           | inl (inr y) => inr (inl y)
                           | inr c => inr (inr c)
                           end;
            inv := fun t : X + (Y + Z) => match t with
                            | inl x => inl (inl x)
                            | inr (inl y) => inl (inr y)
                            | inr (inr c) => inr c
                            end;
            inv_to := _; to_inv := _ |}.
  - intros [[x | y] | c]; reflexivity.
  - intros [x | [y | c]]; reflexivity.
Defined.

Definition sumEmpty (X : Type) : Iso (X + Empty_set) X.
Proof.
  refine {| to := fun t : X + Empty_set => match t with inl x => x | inr e => match e with end end;
            inv := fun x => inl x;
            inv_to := _; to_inv := _ |}.
  - intros [x | e]; [reflexivity | destruct e].
  - intro x. reflexivity.
Defined.

Definition prodEmpty (X : Type) : Iso Empty_set (X * Empty_set).
Proof.
  refine {| to := fun e : Empty_set => match e return X * Empty_set with end;
            inv := fun p : X * Empty_set => match snd p return Empty_set with end;
            inv_to := _; to_inv := _ |}.
  - intro e. destruct e.
  - intros [x e]. destruct e.
Defined.

Definition emptySumUnit : Iso (Empty_set + unit) unit.
Proof.
  refine {| to := fun _ : Empty_set + unit => tt;
            inv := fun u : unit => inr u;
            inv_to := _; to_inv := _ |}.
  - intros [e | u]; [destruct e | destruct u; reflexivity].
  - intro u. destruct u. reflexivity.
Defined.

(* (X * Y) + X  =~  X * (Y + 1): one more mark on the right factor *)
Definition prodSumUnit (X Y : Type) : Iso ((X * Y) + X) (X * (Y + unit)).
Proof.
  refine {| to := fun t : (X * Y) + X => match t with
                           | inl (x, y) => (x, inl y)
                           | inr x => (x, inr tt)
                           end;
            inv := fun p : X * (Y + unit) => match p with
                            | (x, inl y) => inl (x, y)
                            | (x, inr _) => inr x
                            end;
            inv_to := _; to_inv := _ |}.
  - intros [[x y] | x]; reflexivity.
  - intros [x [y | u]]; [reflexivity | destruct u; reflexivity].
Defined.

(* a map from the row of length n into X, as a row of length n with marks in X *)
Fixpoint Vec (X : Type) (n : N) : Type :=
  match n with z => unit | s m => prod (Vec X m) X end.

(* |[a] + [b]| = a + b *)
Fixpoint addIso (a b : N) {struct b} : Iso (Row (add a b)) (Row a + Row b) :=
  match b as b0 return Iso (Row (add a b0)) (Row a + Row b0) with
  | z => symmIso (sumEmpty (Row a))
  | s b' => transIso (sumCongrLeft unit (addIso a b')) (sumAssoc (Row a) (Row b') unit)
  end.

(* |[a] * [b]| = a * b *)
Fixpoint mulIso (a b : N) {struct b} : Iso (Row (mul a b)) (Row a * Row b) :=
  match b as b0 return Iso (Row (mul a b0)) (Row a * Row b0) with
  | z => prodEmpty (Row a)
  | s b' => transIso (addIso (mul a b') a)
              (transIso (sumCongrLeft (Row a) (mulIso a b')) (prodSumUnit (Row a) (Row b')))
  end.

(* |[b] -> [a]| = a ^ b, maps out of a row being rows *)
Fixpoint powIso (a b : N) {struct b} : Iso (Row (pow a b)) (Vec (Row a) b) :=
  match b as b0 return Iso (Row (pow a b0)) (Vec (Row a) b0) with
  | z => emptySumUnit
  | s b' => transIso (mulIso (pow a b') a) (prodCongrLeft (Row a) (powIso a b'))
  end.


(* ======================================================================
   Section 2 (continued): E7 laws, E8 first part
   ====================================================================== *)


(* ----------------------------------------------------------------------
   E7  laws of sum
   ---------------------------------------------------------------------- *)

Lemma add_z_l (n : N) : add z n = n.
Proof. induction n as [| n IH]; simpl; [reflexivity | rewrite IH; reflexivity]. Qed.

Lemma add_s_l (m n : N) : add (s m) n = s (add m n).
Proof. induction n as [| n IH]; simpl; [reflexivity | rewrite IH; reflexivity]. Qed.

Lemma add_comm (m n : N) : add m n = add n m.
Proof.
  induction n as [| n IH]; simpl.
  - rewrite add_z_l. reflexivity.
  - rewrite add_s_l, IH. reflexivity.
Qed.

Lemma add_assoc (a b c : N) : add (add a b) c = add a (add b c).
Proof. induction c as [| c IH]; simpl; [reflexivity | rewrite IH; reflexivity]. Qed.

(* ----------------------------------------------------------------------
   E7  laws of product
   ---------------------------------------------------------------------- *)

Lemma mul_z_l (n : N) : mul z n = z.
Proof. induction n as [| n IH]; simpl; [reflexivity | rewrite IH; reflexivity]. Qed.

Lemma mul_one_r (a : N) : mul a (s z) = a.
Proof. simpl. apply add_z_l. Qed.

Lemma mul_s_l (m n : N) : mul (s m) n = add (mul m n) n.
Proof.
  induction n as [| n IH]; simpl.
  - reflexivity.
  - rewrite IH, !add_assoc, (add_comm n m). reflexivity.
Qed.

Lemma mul_comm (m n : N) : mul m n = mul n m.
Proof.
  induction n as [| n IH]; simpl.
  - rewrite mul_z_l. reflexivity.
  - rewrite mul_s_l, IH. reflexivity.
Qed.

Lemma mul_add_distr_l (a b c : N) : mul a (add b c) = add (mul a b) (mul a c).
Proof.
  induction c as [| c IH]; simpl.
  - reflexivity.
  - rewrite IH, add_assoc. reflexivity.
Qed.

Lemma mul_add_distr_r (a b c : N) : mul (add a b) c = add (mul a c) (mul b c).
Proof.
  rewrite (mul_comm (add a b) c), mul_add_distr_l, (mul_comm c a), (mul_comm c b).
  reflexivity.
Qed.

Lemma mul_assoc (a b c : N) : mul (mul a b) c = mul a (mul b c).
Proof.
  induction c as [| c IH]; simpl.
  - reflexivity.
  - rewrite mul_add_distr_l, IH. reflexivity.
Qed.

(* ----------------------------------------------------------------------
   E7  laws of power
   ---------------------------------------------------------------------- *)

Lemma pow_add (a b c : N) : pow a (add b c) = mul (pow a b) (pow a c).
Proof.
  induction c as [| c IH]; simpl.
  - rewrite add_z_l. reflexivity.
  - rewrite IH, mul_assoc. reflexivity.
Qed.

Lemma pow_mul (a b c : N) : pow a (mul b c) = pow (pow a b) c.
Proof.
  induction c as [| c IH]; simpl.
  - reflexivity.
  - rewrite pow_add, IH. reflexivity.
Qed.

Lemma mul_pow (a a' b : N) : pow (mul a a') b = mul (pow a b) (pow a' b).
Proof.
  induction b as [| b IH]; simpl.
  - reflexivity.
  - rewrite IH, !mul_assoc. f_equal.
    rewrite <- (mul_assoc (pow a' b) a a'), <- (mul_assoc a (pow a' b) a'),
            (mul_comm (pow a' b) a).
    reflexivity.
Qed.

(* ----------------------------------------------------------------------
   E7  order and sum
   ---------------------------------------------------------------------- *)

Definition Le (m n : N) : Prop := Lt m n \/ m = n.

Lemma le_add (m d : N) : Le m (add m d).
Proof.
  induction d as [| d IH]; simpl.
  - right. reflexivity.
  - destruct IH as [h | e].
    + left. apply step. exact h.
    + left. rewrite <- e. apply base.
Qed.

Lemma lt_add_s (m d : N) : Lt m (add m (s d)).
Proof.
  simpl. destruct (le_add m d) as [h | e].
  - apply step. exact h.
  - rewrite <- e. apply base.
Qed.

Lemma lt_add_pos (x y : N) : y <> z -> Lt x (add x y).
Proof.
  intro hy. destruct y as [| y].
  - exfalso. apply hy. reflexivity.
  - apply lt_add_s.
Qed.

(* m < n exactly when n = m + (d + 1) *)
Lemma lt_exists (m n : N) : Lt m n -> exists d, n = add m (s d).
Proof.
  intro h. induction h as [| n h IH].
  - exists z. reflexivity.
  - destruct IH as [d e]. exists (s d). simpl. rewrite e. reflexivity.
Qed.

Lemma add_lt_mono_r (a b c : N) : Lt a b -> Lt (add a c) (add b c).
Proof.
  intro h. induction c as [| c IH]; simpl.
  - exact h.
  - apply s_lt_s. exact IH.
Qed.

Lemma lt_le_s (b x : N) : Lt b x -> Le (s b) x.
Proof.
  intro h. destruct (lt_exists b x h) as [d e]. subst x. simpl.
  destruct (le_add b d) as [h' | e'].
  - left. apply s_lt_s. exact h'.
  - right. rewrite <- e'. reflexivity.
Qed.

Lemma le_lt_trans (a b c : N) : Le a b -> Lt b c -> Lt a c.
Proof.
  intros [h | e] h2.
  - exact (lt_trans a b c h h2).
  - subst. exact h2.
Qed.

(* ----------------------------------------------------------------------
   E7  order and product
   ---------------------------------------------------------------------- *)

Lemma mul_s_s_ne_z (a b : N) : mul (s a) (s b) <> z.
Proof.
  simpl. intro h. exact (z_ne_s _ (eq_sym h)).
Qed.

Lemma mul_lt_mono_r (a b c : N) : Lt a b -> c <> z -> Lt (mul a c) (mul b c).
Proof.
  intros h hc. destruct (lt_exists a b h) as [d e]. subst b.
  rewrite mul_add_distr_r. apply lt_add_pos.
  destruct c as [| c].
  - exfalso. apply hc. reflexivity.
  - apply mul_s_s_ne_z.
Qed.

(* ----------------------------------------------------------------------
   E8  powers: positivity and 2^b > b
   ---------------------------------------------------------------------- *)

Lemma pow_ne_z (a b : N) : a <> z -> pow a b <> z.
Proof.
  intro ha. induction b as [| b IH]; simpl.
  - intro h. exact (z_ne_s _ (eq_sym h)).
  - destruct (pow a b) as [| p] eqn:E.
    + exfalso. exact (IH eq_refl).
    + destruct a as [| a]; [exfalso; apply ha; reflexivity |].
      apply mul_s_s_ne_z.
Qed.

Lemma two_ne_z : s (s z) <> z.
Proof. intro h. exact (z_ne_s _ (eq_sym h)). Qed.

Lemma lt_two_pow (b : N) : Lt b (pow (s (s z)) b).
Proof.
  induction b as [| b IH]; simpl.
  - apply base.
  - rewrite add_z_l.
    apply (le_lt_trans (s b) (pow (s (s z)) b)).
    + apply lt_le_s. exact IH.
    + apply lt_add_pos. apply pow_ne_z. exact two_ne_z.
Qed.


(* ----------------------------------------------------------------------
   E7  the laws are those of a commutative semiring.
   Registering them lets `ring` rearrange sums and products of numbers;
   each rearrangement is a chain of the lemmas above.
   ---------------------------------------------------------------------- *)

Lemma N_srt : semi_ring_theory z (s z) add mul (@eq N).
Proof.
  constructor; intros.
  - apply add_z_l.
  - apply add_comm.
  - symmetry. apply add_assoc.
  - rewrite mul_s_l, mul_z_l. apply add_z_l.
  - apply mul_z_l.
  - apply mul_comm.
  - symmetry. apply mul_assoc.
  - apply mul_add_distr_r.
Qed.

Add Ring NRing : N_srt.

(* ----------------------------------------------------------------------
   E7  cancellation; order and sum, order and product
   ---------------------------------------------------------------------- *)

Lemma s_ne_z (n : N) : s n <> z.
Proof. intro h. exact (z_ne_s n (eq_sym h)). Qed.

Lemma lt_s_s_inv (m n : N) : Lt (s m) (s n) -> Lt m n.
Proof.
  intro h. destruct (lt_s_inv _ _ h) as [h' | e].
  - exact (lt_trans _ _ _ base h').
  - rewrite <- e. apply base.
Qed.

Lemma add_cancel_r (a b c : N) : add a c = add b c -> a = b.
Proof.
  induction c as [| c IH]; simpl.
  - intro h. exact h.
  - intro h. apply IH. apply s_inj. exact h.
Qed.

Lemma add_lt_mono_l (a c d : N) : Lt c d -> Lt (add a c) (add a d).
Proof.
  intro h. rewrite (add_comm a c), (add_comm a d). apply add_lt_mono_r. exact h.
Qed.

Lemma add_lt_mono (a b c d : N) : Lt a b -> Lt c d -> Lt (add a c) (add b d).
Proof.
  intros h1 h2.
  exact (lt_trans _ _ _ (add_lt_mono_r a b c h1) (add_lt_mono_l b c d h2)).
Qed.

Lemma add_lt_cancel_r (a b c : N) : Lt (add a c) (add b c) -> Lt a b.
Proof.
  intro h. destruct (lt_total a b) as [h' | [e | h']].
  - exact h'.
  - subst. exfalso. exact (lt_irrefl _ h).
  - exfalso. exact (lt_irrefl _ (lt_trans _ _ _ h (add_lt_mono_r b a c h'))).
Qed.

Lemma mul_cancel_r (a b c : N) : mul a (s c) = mul b (s c) -> a = b.
Proof.
  intro h. destruct (lt_total a b) as [h' | [e | h']].
  - exfalso. pose proof (mul_lt_mono_r a b (s c) h' (s_ne_z c)) as H.
    rewrite h in H. exact (lt_irrefl _ H).
  - exact e.
  - exfalso. pose proof (mul_lt_mono_r b a (s c) h' (s_ne_z c)) as H.
    rewrite h in H. exact (lt_irrefl _ H).
Qed.

Lemma mul_lt_cancel_r (a b c : N) : Lt (mul a (s c)) (mul b (s c)) -> Lt a b.
Proof.
  intro h. destruct (lt_total a b) as [h' | [e | h']].
  - exact h'.
  - subst. exfalso. exact (lt_irrefl _ h).
  - exfalso.
    exact (lt_irrefl _ (lt_trans _ _ _ h (mul_lt_mono_r b a (s c) h' (s_ne_z c)))).
Qed.

(* ----------------------------------------------------------------------
   E5  order is a cut: decided by a map into Two
   ---------------------------------------------------------------------- *)

Fixpoint ltb (m n : N) : Two :=
  match n with
  | z => r
  | s n' => match m with z => l | s m' => ltb m' n' end
  end.

Lemma ltb_spec (m : N) : forall n, ltb m n = l <-> Lt m n.
Proof.
  induction m as [| m IH]; intros [| n]; simpl.
  - split; intro h; exfalso; [exact (l_ne_r (eq_sym h)) | exact (not_lt_z _ h)].
  - split; intro h; [apply z_lt_s | reflexivity].
  - split; intro h; exfalso; [exact (l_ne_r (eq_sym h)) | exact (not_lt_z _ h)].
  - destruct (IH n) as [f g]. split; intro h.
    + apply s_lt_s. apply f. exact h.
    + apply g. apply lt_s_s_inv. exact h.
Qed.

(* ----------------------------------------------------------------------
   E9  fractions.
   A fraction is (p - n) / D with D = s d > 0, built from numbers only.
   Its sameness is cross-multiplication; it is a Kind, so no axiom is needed.
   ---------------------------------------------------------------------- *)

Record Q : Type := mkQ { qp : N; qn : N; qd : N }.

Definition D (q : Q) : N := s (qd q).

(* (p - n)/D  vs  (p' - n')/D' :  compare  p D' + n' D  with  p' D + n D' *)
Definition LQ (q q' : Q) : N := add (mul (qp q) (D q')) (mul (qn q') (D q)).
Definition RQ (q q' : Q) : N := add (mul (qp q') (D q)) (mul (qn q) (D q')).

Definition sameQ (q q' : Q) : Prop := LQ q q' = RQ q q'.
Definition ltQ (q q' : Q) : Prop := Lt (LQ q q') (RQ q q').
Definition ltbQ (q q' : Q) : Two := ltb (LQ q q') (RQ q q').

Lemma sameQ_refl (q : Q) : sameQ q q.
Proof. reflexivity. Qed.

Lemma sameQ_symm (q q' : Q) : sameQ q q' -> sameQ q' q.
Proof. intro h. exact (eq_sym h). Qed.

(* the algebra behind transitivity, with the middle denominator s d' cancelled *)
Lemma cross_eq (p n p' n' p'' n'' D1 d' D3 : N) :
  add (mul p (s d')) (mul n' D1) = add (mul p' D1) (mul n (s d')) ->
  add (mul p' D3) (mul n'' (s d')) = add (mul p'' (s d')) (mul n' D3) ->
  add (mul p D3) (mul n'' D1) = add (mul p'' D1) (mul n D3).
Proof.
  intros h1 h2.
  apply (mul_cancel_r _ _ d').
  apply (add_cancel_r _ _ (add (mul n' (mul D1 D3)) (mul p' (mul D1 D3)))).
  transitivity (add (mul (add (mul p (s d')) (mul n' D1)) D3)
                    (mul (add (mul p' D3) (mul n'' (s d'))) D1)).
  - ring.
  - rewrite h1, h2. ring.
Qed.

Lemma sameQ_trans (q1 q2 q3 : Q) : sameQ q1 q2 -> sameQ q2 q3 -> sameQ q1 q3.
Proof.
  destruct q1 as [p n d], q2 as [p' n' d'], q3 as [p'' n'' d''].
  exact (cross_eq p n p' n' p'' n'' (s d) d' (s d'')).
Qed.

Definition QKind : Kind :=
  {| carrier := Q; same := sameQ;
     same_refl := sameQ_refl; same_symm := sameQ_symm; same_trans := sameQ_trans |}.

(* order of fractions is decided *)
Lemma ltbQ_spec (q q' : Q) : ltbQ q q' = l <-> ltQ q q'.
Proof. apply ltb_spec. Qed.

Lemma ltQ_irrefl (q : Q) : ~ ltQ q q.
Proof. intro h. exact (lt_irrefl _ h). Qed.

(* exactly one of q < q', q = q', q' < q *)
Lemma ltQ_total (q q' : Q) : ltQ q q' \/ sameQ q q' \/ ltQ q' q.
Proof. exact (lt_total (LQ q q') (RQ q q')). Qed.

Lemma cross_lt (p n p' n' p'' n'' D1 d' D3 : N) :
  Lt (add (mul p (s d')) (mul n' D1)) (add (mul p' D1) (mul n (s d'))) ->
  Lt (add (mul p' D3) (mul n'' (s d'))) (add (mul p'' (s d')) (mul n' D3)) ->
  D1 <> z -> D3 <> z ->
  Lt (add (mul p D3) (mul n'' D1)) (add (mul p'' D1) (mul n D3)).
Proof.
  intros h1 h2 hD1 hD3.
  apply (mul_lt_cancel_r _ _ d').
  apply (add_lt_cancel_r _ _ (add (mul n' (mul D1 D3)) (mul p' (mul D1 D3)))).
  pose proof (add_lt_mono _ _ _ _ (mul_lt_mono_r _ _ D3 h1 hD3)
                                  (mul_lt_mono_r _ _ D1 h2 hD1)) as H.
  assert (E1 : add (mul (add (mul p (s d')) (mul n' D1)) D3)
                   (mul (add (mul p' D3) (mul n'' (s d'))) D1)
             = add (mul (add (mul p D3) (mul n'' D1)) (s d'))
                   (add (mul n' (mul D1 D3)) (mul p' (mul D1 D3)))) by ring.
  assert (E2 : add (mul (add (mul p' D1) (mul n (s d'))) D3)
                   (mul (add (mul p'' (s d')) (mul n' D3)) D1)
             = add (mul (add (mul p'' D1) (mul n D3)) (s d'))
                   (add (mul n' (mul D1 D3)) (mul p' (mul D1 D3)))) by ring.
  rewrite E1, E2 in H. exact H.
Qed.

Lemma ltQ_trans (q1 q2 q3 : Q) : ltQ q1 q2 -> ltQ q2 q3 -> ltQ q1 q3.
Proof.
  destruct q1 as [p n d], q2 as [p' n' d'], q3 as [p'' n'' d''].
  intros h1 h2.
  exact (cross_lt p n p' n' p'' n'' (s d) d' (s d'') h1 h2 (s_ne_z d) (s_ne_z d'')).
Qed.

(* sum, negative, product of fractions; the new denominator is D q * D q' *)
Definition addQ (q q' : Q) : Q :=
  mkQ (add (mul (qp q) (D q')) (mul (qp q') (D q)))
      (add (mul (qn q) (D q')) (mul (qn q') (D q)))
      (add (mul (D q) (qd q')) (qd q)).

Definition negQ (q : Q) : Q := mkQ (qn q) (qp q) (qd q).

Definition mulQ (q q' : Q) : Q :=
  mkQ (add (mul (qp q) (qp q')) (mul (qn q) (qn q')))
      (add (mul (qp q) (qn q')) (mul (qn q) (qp q')))
      (add (mul (D q) (qd q')) (qd q)).

Definition ofN (n : N) : Q := mkQ n z z.

Lemma add_resp_N (p1 n1 D1 p2 n2 D2 p n D3 : N) :
  add (mul p1 D2) (mul n2 D1) = add (mul p2 D1) (mul n1 D2) ->
  add (mul (add (mul p1 D3) (mul p D1)) (mul D2 D3))
      (mul (add (mul n2 D3) (mul n D2)) (mul D1 D3))
  = add (mul (add (mul p2 D3) (mul p D2)) (mul D1 D3))
        (mul (add (mul n1 D3) (mul n D1)) (mul D2 D3)).
Proof.
  intro h.
  transitivity (add (mul (add (mul p1 D2) (mul n2 D1)) (mul D3 D3))
                    (add (mul p (mul D1 (mul D2 D3))) (mul n (mul D1 (mul D2 D3))))).
  - ring.
  - rewrite h. ring.
Qed.

(* adding the same fraction to the same fractions gives the same *)
Lemma addQ_resp (q1 q2 q : Q) : sameQ q1 q2 -> sameQ (addQ q1 q) (addQ q2 q).
Proof.
  destruct q1 as [p1 n1 d1], q2 as [p2 n2 d2], q as [p n d].
  exact (add_resp_N p1 n1 (s d1) p2 n2 (s d2) p n (s d)).
Qed.

Lemma negQ_resp (q1 q2 : Q) : sameQ q1 q2 -> sameQ (negQ q1) (negQ q2).
Proof.
  destruct q1 as [p1 n1 d1], q2 as [p2 n2 d2].
  unfold sameQ, LQ, RQ, D, negQ. cbn [qp qn qd].
  intro h. rewrite (add_comm (mul n1 (s d2))), (add_comm (mul n2 (s d1))).
  exact (eq_sym h).
Qed.


(* ======================================================================
   Section 4-5: E8 (rest), E10, E12-E14, E19.
   A real number is a pair of cuts of the fractions (E10). The logarithm
   is such a pair whose cuts are decided (E13): l/K is below log_m n when
   m^l < n^K, above it when n^K < m^l. Fractions l/K (K <> 0) are compared
   by cross-multiplication. Everything here is about numbers only.
   ====================================================================== *)

(* ----------------------------------------------------------------------
   E7-E8  order, product, power
   ---------------------------------------------------------------------- *)

Lemma le_trans (a b c : N) : Le a b -> Le b c -> Le a c.
Proof.
  intros [h | e] [h' | e'].
  - left. exact (lt_trans _ _ _ h h').
  - subst. left. exact h.
  - subst. left. exact h'.
  - subst. right. reflexivity.
Qed.

Lemma lt_le_trans (a b c : N) : Lt a b -> Le b c -> Lt a c.
Proof.
  intros h [h' | e].
  - exact (lt_trans _ _ _ h h').
  - subst. exact h.
Qed.

Lemma lt_ne_z_r (a b : N) : Lt a b -> b <> z.
Proof. intros h e. subst. exact (not_lt_z _ h). Qed.

Lemma mul_ne_z (x y : N) : x <> z -> y <> z -> mul x y <> z.
Proof.
  intros hx hy.
  destruct x as [| x]; [exfalso; apply hx; reflexivity |].
  destruct y as [| y]; [exfalso; apply hy; reflexivity |].
  apply mul_s_s_ne_z.
Qed.

Lemma mul_le_mono_r (a b c : N) : Le a b -> Le (mul a c) (mul b c).
Proof.
  intros [h | e].
  - destruct c as [| c].
    + right. reflexivity.
    + left. apply mul_lt_mono_r; [exact h | apply s_ne_z].
  - subst. right. reflexivity.
Qed.

Lemma mul_le_mono_l (a b c : N) : Le b c -> Le (mul a b) (mul a c).
Proof.
  intro h. rewrite (mul_comm a b), (mul_comm a c). apply mul_le_mono_r. exact h.
Qed.

Lemma mul_lt_mono_l (a b c : N) : Lt b c -> a <> z -> Lt (mul a b) (mul a c).
Proof.
  intros h ha. rewrite (mul_comm a b), (mul_comm a c). apply mul_lt_mono_r; assumption.
Qed.

Lemma mul_lt_cancel_pos (a b c : N) : c <> z -> Lt (mul a c) (mul b c) -> Lt a b.
Proof.
  intros hc h. destruct c as [| c].
  - exfalso. apply hc. reflexivity.
  - exact (mul_lt_cancel_r _ _ _ h).
Qed.

Lemma mul_le_lt (P Q a b : N) : Le P Q -> Lt a b -> Q <> z -> Lt (mul P a) (mul Q b).
Proof.
  intros h1 h2 hQ. apply (le_lt_trans _ (mul Q a)).
  - apply mul_le_mono_r. exact h1.
  - apply mul_lt_mono_l; assumption.
Qed.

Lemma mul_lt_mono2 (a b c d : N) : Lt a b -> Lt c d -> Lt (mul a c) (mul b d).
Proof.
  intros h1 h2. apply (le_lt_trans _ (mul a d)).
  - apply mul_le_mono_l. left. exact h2.
  - apply mul_lt_mono_r; [exact h1 | exact (lt_ne_z_r _ _ h2)].
Qed.

Lemma pow_one (a : N) : pow a (s z) = a.
Proof. cbn [pow]. rewrite mul_s_l, mul_z_l. apply add_z_l. Qed.

Lemma pow_le_mono_base (a b c : N) : Le a b -> Le (pow a c) (pow b c).
Proof.
  intro h. induction c as [| c IH]; cbn [pow].
  - right. reflexivity.
  - apply (le_trans _ (mul (pow b c) a)).
    + apply mul_le_mono_r. exact IH.
    + apply mul_le_mono_l. exact h.
Qed.

Lemma pow_lt_mono_base (a b D : N) : Lt a b -> D <> z -> Lt (pow a D) (pow b D).
Proof.
  intros h hD. destruct D as [| D]; [exfalso; apply hD; reflexivity |].
  cbn [pow]. apply mul_le_lt.
  - apply pow_le_mono_base. left. exact h.
  - exact h.
  - apply pow_ne_z. exact (lt_ne_z_r _ _ h).
Qed.

(* a^D < b^D gives a < b *)
Lemma pow_lt_inv (a b D : N) : D <> z -> Lt (pow a D) (pow b D) -> Lt a b.
Proof.
  intros hD h. destruct (lt_total a b) as [h' | [e | h']].
  - exact h'.
  - subst. exfalso. exact (lt_irrefl _ h).
  - exfalso. exact (lt_irrefl _ (lt_trans _ _ _ h (pow_lt_mono_base _ _ _ h' hD))).
Qed.

Lemma one_lt_pow_s (m d : N) : Lt (s z) m -> Lt (s z) (pow m (s d)).
Proof.
  intro hm. induction d as [| d IH].
  - rewrite pow_one. exact hm.
  - apply (lt_le_trans _ _ _ IH).
    change (pow m (s (s d))) with (mul (pow m (s d)) m).
    pose proof (mul_le_mono_l (pow m (s d)) (s z) m (or_introl hm)) as H.
    rewrite mul_one_r in H. exact H.
Qed.

Lemma pow_lt_exp (m l l' : N) : Lt (s z) m -> Lt l l' -> Lt (pow m l) (pow m l').
Proof.
  intros hm h. destruct (lt_exists _ _ h) as [d e]. subst l'. rewrite pow_add.
  pose proof (mul_lt_mono_l (pow m l) (s z) (pow m (s d))
                (one_lt_pow_s m d hm) (pow_ne_z m l (lt_ne_z_r _ _ hm))) as H.
  rewrite mul_one_r in H. exact H.
Qed.

Lemma lt_pow_self (m x : N) : Lt (s z) m -> Lt x (pow m x).
Proof.
  intro hm. apply (lt_le_trans _ _ _ (lt_two_pow x)).
  apply pow_le_mono_base. exact (lt_le_s _ _ hm).
Qed.

(* Bernoulli for numbers:  a^j (a + j) <= (a + 1)^j a *)
Lemma bern (a j : N) : Le (mul (pow a j) (add a j)) (mul (pow (add a (s z)) j) a).
Proof.
  induction j as [| j IH].
  - right. reflexivity.
  - apply (le_trans _ (mul (mul (pow a j) (add a j)) (add a (s z)))).
    + replace (mul (mul (pow a j) (add a j)) (add a (s z)))
        with (add (mul (pow a (s j)) (add a (s j))) (mul (pow a j) j)).
      * apply le_add.
      * cbn [pow]. change (add a (s j)) with (add (add a j) (s z)). ring.
    + replace (mul (pow (add a (s z)) (s j)) a)
        with (mul (mul (pow (add a (s z)) j) a) (add a (s z))).
      * apply mul_le_mono_r. exact IH.
      * cbn [pow]. ring.
Qed.

(* the step used for roundedness: if a < b then a^J m < b^J for J = m a *)
Lemma round_core (m a b : N) :
  Lt (s z) m -> a <> z -> Lt a b -> Lt (mul (pow a (mul m a)) m) (pow b (mul m a)).
Proof.
  intros hm ha hab.
  destruct a as [| a0]; [exfalso; apply ha; reflexivity |].
  pose proof (bern (s a0) (mul m (s a0))) as hB.
  assert (h1 : Lt (mul (mul (pow (s a0) (mul m (s a0))) m) (s a0))
                  (mul (pow (s a0) (mul m (s a0))) (add (s a0) (mul m (s a0))))).
  { replace (mul (pow (s a0) (mul m (s a0))) (add (s a0) (mul m (s a0))))
      with (add (mul (mul (pow (s a0) (mul m (s a0))) m) (s a0))
                (mul (pow (s a0) (mul m (s a0))) (s a0))) by ring.
    apply lt_add_pos. apply mul_ne_z; [apply pow_ne_z; apply s_ne_z | apply s_ne_z]. }
  assert (h2 : Lt (mul (pow (s a0) (mul m (s a0))) m)
                  (pow (add (s a0) (s z)) (mul m (s a0)))).
  { apply (mul_lt_cancel_r _ _ a0). exact (lt_le_trans _ _ _ h1 hB). }
  apply (lt_le_trans _ _ _ h2). apply pow_le_mono_base. exact (lt_le_s _ _ hab).
Qed.

(* ----------------------------------------------------------------------
   E13  the logarithm is a pair of decided cuts
   ---------------------------------------------------------------------- *)

(* l/K lies below log_m n *)
Definition inL (m n l K : N) : Prop := Lt (pow m l) (pow n K).
(* l/K lies above log_m n *)
Definition inU (m n l K : N) : Prop := Lt (pow n K) (pow m l).

(* both cuts are maps into Two: decided *)
Definition inLb (m n l K : N) : Two := ltb (pow m l) (pow n K).
Definition inUb (m n l K : N) : Two := ltb (pow n K) (pow m l).

Lemma inLb_spec (m n e K : N) : inLb m n e K = l <-> inL m n e K.
Proof. apply ltb_spec. Qed.

Lemma inUb_spec (m n e K : N) : inUb m n e K = l <-> inU m n e K.
Proof. apply ltb_spec. Qed.

(* well defined: equal fractions l/K = l'/K' have the same membership *)
Lemma inL_resp (m n l K l' K' : N) :
  K <> z -> K' <> z -> mul l K' = mul l' K -> inL m n l K -> inL m n l' K'.
Proof.
  unfold inL. intros hK hK' e h.
  apply (pow_lt_inv _ _ K hK).
  rewrite <- (pow_mul m l' K), <- (pow_mul n K' K), <- e, (mul_comm K' K),
          (pow_mul m l K'), (pow_mul n K K').
  apply pow_lt_mono_base; [exact h | exact hK'].
Qed.

Lemma inU_resp (m n l K l' K' : N) :
  K <> z -> K' <> z -> mul l K' = mul l' K -> inU m n l K -> inU m n l' K'.
Proof.
  unfold inU. intros hK hK' e h.
  apply (pow_lt_inv _ _ K hK).
  rewrite <- (pow_mul n K' K), <- (pow_mul m l' K), <- e, (mul_comm K' K),
          (pow_mul n K K'), (pow_mul m l K').
  apply pow_lt_mono_base; [exact h | exact hK'].
Qed.

(* inhabited *)
Lemma inL_zero (m n K : N) : Lt (s z) n -> K <> z -> inL m n z K.
Proof.
  unfold inL. intros hn hK.
  destruct K as [| k]; [exfalso; apply hK; reflexivity |].
  exact (one_lt_pow_s n k hn).
Qed.

Lemma inU_some (m n K : N) : Lt (s z) m -> inU m n (pow n K) K.
Proof. unfold inU. intro hm. exact (lt_pow_self m (pow n K) hm). Qed.

(* disjoint *)
Lemma log_disjoint (m n l K : N) : inL m n l K -> inU m n l K -> False.
Proof. unfold inL, inU. intros h1 h2. exact (lt_irrefl _ (lt_trans _ _ _ h1 h2)). Qed.

(* located: if l/K < l'/K' then l/K is below or l'/K' is above *)
Lemma log_located (m n l K l' K' : N) :
  Lt (s z) m -> K <> z -> K' <> z -> Lt (mul l K') (mul l' K) ->
  inL m n l K \/ inU m n l' K'.
Proof.
  unfold inL, inU. intros hm hK hK' hfr.
  destruct (lt_total (pow m l) (pow n K)) as [h | h'].
  - left. exact h.
  - right.
    assert (H : Le (pow n K) (pow m l)).
    { unfold Le. destruct h' as [e | h''].
      - right. symmetry. exact e.
      - left. exact h''. }
    apply (pow_lt_inv _ _ K hK).
    rewrite <- (pow_mul n K' K), <- (pow_mul m l' K), (mul_comm K' K), (pow_mul n K K').
    apply (le_lt_trans _ (pow (pow m l) K')).
    + apply pow_le_mono_base. exact H.
    + rewrite <- (pow_mul m l K'). apply pow_lt_exp; [exact hm | exact hfr].
Qed.

(* rounded, lower cut: a larger fraction is still below *)
Lemma log_rounded_L (m n l K : N) :
  Lt (s z) m -> K <> z -> inL m n l K ->
  exists l' K', K' <> z /\ Lt (mul l K') (mul l' K) /\ inL m n l' K'.
Proof.
  unfold inL. intros hm hK h.
  assert (hmz : m <> z) by exact (lt_ne_z_r _ _ hm).
  assert (ha : pow m l <> z) by (apply pow_ne_z; exact hmz).
  pose proof (round_core m (pow m l) (pow n K) hm ha h) as C.
  exists (add (mul l (mul m (pow m l))) (s z)), (mul K (mul m (pow m l))).
  split; [apply mul_ne_z; [exact hK | apply mul_ne_z; assumption] |].
  split.
  - replace (mul (add (mul l (mul m (pow m l))) (s z)) K)
      with (add (mul l (mul K (mul m (pow m l)))) K) by ring.
    apply lt_add_pos. exact hK.
  - rewrite (pow_add m (mul l (mul m (pow m l))) (s z)), (pow_mul m l (mul m (pow m l))),
            (pow_mul n K (mul m (pow m l))), (pow_one m).
    exact C.
Qed.

(* rounded, upper cut: a smaller fraction is still above *)
Lemma log_rounded_U (m n l K : N) :
  Lt (s z) m -> Lt (s z) n -> K <> z -> inU m n l K ->
  exists l' K', K' <> z /\ Lt (mul l' K) (mul l K') /\ inU m n l' K'.
Proof.
  unfold inU. intros hm hn hK h.
  assert (hmz : m <> z) by exact (lt_ne_z_r _ _ hm).
  assert (hnz : n <> z) by exact (lt_ne_z_r _ _ hn).
  assert (hb : pow n K <> z) by (apply pow_ne_z; exact hnz).
  pose proof (round_core m (pow n K) (pow m l) hm hb h) as C.
  destruct l as [| l0].
  - exfalso. change (pow m z) with (s z) in h.
    destruct (lt_s_inv _ _ h) as [h0 | e0].
    + exact (not_lt_z _ h0).
    + exact (hb e0).
  - revert C.
    destruct (mul m (pow n K)) as [| j0] eqn:EJ.
    + exfalso. exact (mul_ne_z _ _ hmz hb EJ).
    + intro C.
      exists (add (mul (s l0) j0) l0), (mul K (s j0)).
      split; [apply mul_ne_z; [exact hK | apply s_ne_z] |].
      split.
      * replace (mul (s l0) (mul K (s j0)))
          with (add (mul (add (mul (s l0) j0) l0) K) K)
          by (change (s l0) with (add l0 (s z)); change (s j0) with (add j0 (s z)); ring).
        apply lt_add_pos. exact hK.
      * apply (mul_lt_cancel_pos _ _ m hmz).
        change (mul (pow m (add (mul (s l0) j0) l0)) m)
          with (pow m (mul (s l0) (s j0))).
        rewrite (pow_mul m (s l0) (s j0)), (pow_mul n K (s j0)).
        exact C.
Qed.

(* ----------------------------------------------------------------------
   E14  log (n n') = log n + log n' : sums of cut elements stay in the cut
   ---------------------------------------------------------------------- *)

Lemma log_mul_L (m n n' l l' K : N) :
  inL m n l K -> inL m n' l' K -> inL m (mul n n') (add l l') K.
Proof.
  unfold inL. intros h1 h2. rewrite pow_add, mul_pow. apply mul_lt_mono2; assumption.
Qed.

Lemma log_mul_U (m n n' l l' K : N) :
  inU m n l K -> inU m n' l' K -> inU m (mul n n') (add l l') K.
Proof.
  unfold inU. intros h1 h2. rewrite pow_add, mul_pow. apply mul_lt_mono2; assumption.
Qed.

(* ----------------------------------------------------------------------
   E12, E13, E19  an additive monotone reading of size lies exactly on the
   logarithm: K f(n) is above l f(m) for every l/K in the lower cut and
   below it for every l/K in the upper cut. Values in any ordered kind.
   ---------------------------------------------------------------------- *)

Section Reading.
  Variable G : Type.
  Variable gz : G.
  Variable gadd : G -> G -> G.
  Variable gle : G -> G -> Prop.
  Hypothesis gadd_zero_r : forall x, gadd x gz = x.
  Hypothesis gadd_cancel_l : forall x y w, gadd x y = gadd x w -> y = w.
  Variable f : N -> G.
  Hypothesis f_mul : forall a b, f (mul a b) = gadd (f a) (f b).
  Hypothesis f_mono : forall a b, Le a b -> gle (f a) (f b).

  Fixpoint nsm (k : N) (x : G) : G :=
    match k with z => gz | s k' => gadd (nsm k' x) x end.

  Lemma f_one : f (s z) = gz.
  Proof.
    apply (gadd_cancel_l (f (s z))). rewrite gadd_zero_r, <- f_mul. reflexivity.
  Qed.

  Lemma f_pow (a j : N) : f (pow a j) = nsm j (f a).
  Proof.
    induction j as [| j IH]; cbn [pow nsm].
    - exact f_one.
    - rewrite f_mul, IH. reflexivity.
  Qed.

  (* Boltzmann: l/K below log_m n  gives  l f(m) <= K f(n) *)
  Theorem boltzmann_L (m n l K : N) : inL m n l K -> gle (nsm l (f m)) (nsm K (f n)).
  Proof. intro h. rewrite <- !f_pow. apply f_mono. left. exact h. Qed.

  (* Boltzmann: l/K above log_m n  gives  K f(n) <= l f(m) *)
  Theorem boltzmann_U (m n l K : N) : inU m n l K -> gle (nsm K (f n)) (nsm l (f m)).
  Proof. intro h. rewrite <- !f_pow. apply f_mono. left. exact h. Qed.
End Reading.


(* ======================================================================
   Section 7: E20, Gibbs entropy is Boltzmann entropy per place.
   W a b counts the rows with a places of one mark and b of the other:
   the last place carries one of the two marks (the recursion of E20).
   In exponentiated form, W <= e^{N H(p)} reads
       W a b * a^a * b^b  <=  (a + b)^(a + b).
   ====================================================================== *)

Fixpoint W (a b : N) {struct a} : N :=
  match a with
  | z => s z
  | s a' => (fix Wb (b : N) : N :=
               match b with
               | z => s z
               | s b' => add (W a' (s b')) (Wb b')
               end) b
  end.

Lemma W_z_l (b : N) : W z b = s z.
Proof. reflexivity. Qed.

Lemma W_z_r (a : N) : W a z = s z.
Proof. destruct a; reflexivity. Qed.

(* the last place carries the first mark or the second *)
Lemma W_ss (a b : N) : W (s a) (s b) = add (W a (s b)) (W (s a) b).
Proof. reflexivity. Qed.

Lemma add_le_mono_r (a b c : N) : Le a b -> Le (add a c) (add b c).
Proof.
  intros [h | e].
  - left. apply add_lt_mono_r. exact h.
  - subst. right. reflexivity.
Qed.

Lemma add_le_mono_l (a c d : N) : Le c d -> Le (add a c) (add a d).
Proof.
  intros [h | e].
  - left. apply add_lt_mono_l. exact h.
  - subst. right. reflexivity.
Qed.

Lemma add_le_mono (a b c d : N) : Le a b -> Le c d -> Le (add a c) (add b d).
Proof.
  intros h1 h2. apply (le_trans _ (add b c)).
  - apply add_le_mono_r. exact h1.
  - apply add_le_mono_l. exact h2.
Qed.

Lemma le_add_l (x y : N) : Le y (add x y).
Proof. rewrite add_comm. apply le_add. Qed.

(* one term of the expansion of (x + y)^(a + b) is at most the whole *)
Lemma binom_le (x y : N) :
  forall a b, Le (mul (W a b) (mul (pow x a) (pow y b))) (pow (add x y) (add a b)).
Proof.
  intro a. induction a as [| a IHa]; intro b.
  - rewrite W_z_l, add_z_l.
    replace (mul (s z) (mul (pow x z) (pow y b))) with (pow y b) by (cbn [pow]; ring).
    apply pow_le_mono_base. apply le_add_l.
  - induction b as [| b IHb].
    + rewrite W_z_r.
      replace (mul (s z) (mul (pow x (s a)) (pow y z))) with (pow x (s a))
        by (cbn [pow]; ring).
      change (add (s a) z) with (s a).
      apply pow_le_mono_base. apply le_add.
    + rewrite W_ss.
      apply (le_trans _ (add (mul x (pow (add x y) (add a (s b))))
                             (mul y (pow (add x y) (add (s a) b))))).
      * replace (mul (add (W a (s b)) (W (s a) b)) (mul (pow x (s a)) (pow y (s b))))
          with (add (mul x (mul (W a (s b)) (mul (pow x a) (pow y (s b)))))
                    (mul y (mul (W (s a) b) (mul (pow x (s a)) (pow y b)))))
          by (cbn [pow]; ring).
        apply add_le_mono; apply mul_le_mono_l; [apply IHa | apply IHb].
      * right.
        assert (E1 : add a (s b) = s (add a b)) by reflexivity.
        assert (E2 : add (s a) b = s (add a b)) by apply add_s_l.
        assert (E3 : add (s a) (s b) = s (s (add a b)))
          by (cbn [add]; rewrite add_s_l; reflexivity).
        rewrite E3, E1, E2. cbn [pow]. ring.
Qed.

(* E20, upper bound:  W * a^a * b^b <= N^N,  i.e.  W <= e^{N H(p)} *)
Theorem gibbs_count_upper (a b : N) :
  Le (mul (W a b) (mul (pow a a) (pow b b))) (pow (add a b) (add a b)).
Proof. exact (binom_le a b a b). Qed.


(* ======================================================================
   Section 8: E22, Gibbs' inequality, in exponentiated form:
       a + b = c + d   ->   c^a * d^b  <=  a^a * b^b.
   Taking logarithms (E13, E14) this is  sum p_i ln q_i <= sum p_i ln p_i,
   i.e.  D(p || q) >= 0.  Route, with no subtraction:
     2XY <= X^2 + Y^2  ->  (n+1) X Y^n <= X^(n+1) + n Y^(n+1)
     ->  arithmetic-geometric means  ->  Gibbs.
   ====================================================================== *)

Lemma le_lt_false (a b : N) : Le a b -> Lt b a -> False.
Proof.
  intros [h | e] h'.
  - exact (lt_irrefl _ (lt_trans _ _ _ h h')).
  - subst. exact (lt_irrefl _ h').
Qed.

Lemma add_le_cancel_r (a b c : N) : Le (add a c) (add b c) -> Le a b.
Proof.
  intro h. destruct (lt_total a b) as [h' | [e | h']].
  - left. exact h'.
  - right. exact e.
  - exfalso. exact (le_lt_false _ _ h (add_lt_mono_r b a c h')).
Qed.

Lemma mul_le_cancel_l (c a b : N) : c <> z -> Le (mul c a) (mul c b) -> Le a b.
Proof.
  intros hc h. destruct (lt_total a b) as [h' | [e | h']].
  - left. exact h'.
  - right. exact e.
  - exfalso. exact (le_lt_false _ _ h (mul_lt_mono_l c b a h' hc)).
Qed.

Lemma pow_self_ne_z (k : N) : pow k k <> z.
Proof.
  destruct k as [| k].
  - exact (s_ne_z z).
  - apply pow_ne_z. apply s_ne_z.
Qed.

(* 2XY <= X^2 + Y^2 *)
Lemma amgm2 (X Y : N) : Le (add (mul X Y) (mul X Y)) (add (mul X X) (mul Y Y)).
Proof.
  destruct (lt_total X Y) as [h | [e | h]].
  - destruct (lt_exists _ _ h) as [t et]. subst Y.
    replace (add (mul X X) (mul (add X (s t)) (add X (s t))))
      with (add (add (mul X (add X (s t))) (mul X (add X (s t)))) (mul (s t) (s t)))
      by ring.
    apply le_add.
  - subst. right. reflexivity.
  - destruct (lt_exists _ _ h) as [t et]. subst X.
    replace (add (mul (add Y (s t)) (add Y (s t))) (mul Y Y))
      with (add (add (mul (add Y (s t)) Y) (mul (add Y (s t)) Y)) (mul (s t) (s t)))
      by ring.
    apply le_add.
Qed.

(* (n+1) X Y^n <= X^(n+1) + n Y^(n+1) *)
Lemma ib (n X Y : N) :
  Le (mul (s n) (mul X (pow Y n))) (add (pow X (s n)) (mul n (pow Y (s n)))).
Proof.
  induction n as [| n IH].
  - right. cbn [pow]. ring.
  - cbn [pow] in *.
    apply (add_le_cancel_r _ _ (mul n (mul X (mul (pow Y n) Y)))).
    apply (le_trans _ (mul (s n) (mul (pow Y n) (add (mul X Y) (mul X Y))))).
    { right. change (s (s n)) with (add (add n (s z)) (s z)).
      change (s n) with (add n (s z)). ring. }
    apply (le_trans _ (mul (s n) (mul (pow Y n) (add (mul X X) (mul Y Y))))).
    { apply mul_le_mono_l. apply mul_le_mono_l. apply amgm2. }
    apply (le_trans _ (add (mul X (add (mul (pow X n) X) (mul n (mul (pow Y n) Y))))
                           (mul (s n) (mul (mul (pow Y n) Y) Y)))).
    { apply (le_trans _ (add (mul X (mul (s n) (mul X (pow Y n))))
                             (mul (s n) (mul (mul (pow Y n) Y) Y)))).
      { right. ring. }
      apply add_le_mono_r. apply mul_le_mono_l. exact IH. }
    right. ring.
Qed.

(* k copies of M/k and one y:  (k+1)^(k+1) y M^k <= k^k (M+y)^(k+1) *)
Lemma kpos (k M y : N) :
  k <> z ->
  Le (mul (pow (s k) (s k)) (mul y (pow M k))) (mul (pow k k) (pow (add M y) (s k))).
Proof.
  intro hk.
  pose proof (ib k (mul k (add M y)) (mul (s k) M)) as H.
  rewrite !mul_pow in H.
  cbn [pow] in H. cbn [pow].
  apply (mul_le_cancel_l k _ _ hk).
  apply (add_le_cancel_r _ _ (mul k (mul (mul (pow (s k) k) (s k)) (mul (pow M k) M)))).
  refine (le_trans _ _ _ _ (le_trans _ _ _ H _)); right; ring.
Qed.

Lemma kl (k M y : N) :
  Le (mul (pow (s k) (s k)) (mul y (pow M k))) (mul (pow k k) (pow (add M y) (s k))).
Proof.
  destruct k as [| k].
  - apply (le_trans _ y).
    { right. cbn [pow]. ring. }
    apply (le_trans _ (add M y)).
    { apply le_add_l. }
    right. cbn [pow]. ring.
  - apply kpos. apply s_ne_z.
Qed.

(* weighted arithmetic-geometric means:  (a+b)^(a+b) x^a y^b <= (a x + b y)^(a+b) *)
Lemma wamgm (a x y : N) :
  forall b, Le (mul (pow (add a b) (add a b)) (mul (pow x a) (pow y b)))
               (pow (add (mul a x) (mul b y)) (add a b)).
Proof.
  intro b. induction b as [| b IH].
  - right. change (add a z) with a. rewrite mul_z_l.
    change (add (mul a x) z) with (mul a x). rewrite mul_pow. cbn [pow]. ring.
  - change (add a (s b)) with (s (add a b)).
    rewrite (mul_s_l b y), <- (add_assoc (mul a x) (mul b y) y).
    apply (mul_le_cancel_l (pow (add a b) (add a b)) _ _ (pow_self_ne_z _)).
    apply (le_trans _ (mul (pow (s (add a b)) (s (add a b)))
                           (mul y (pow (add (mul a x) (mul b y)) (add a b))))).
    + replace (mul (pow (add a b) (add a b))
                   (mul (pow (s (add a b)) (s (add a b))) (mul (pow x a) (pow y (s b)))))
        with (mul (mul (pow (s (add a b)) (s (add a b))) y)
                  (mul (pow (add a b) (add a b)) (mul (pow x a) (pow y b))))
        by (cbn [pow]; ring).
      replace (mul (pow (s (add a b)) (s (add a b)))
                   (mul y (pow (add (mul a x) (mul b y)) (add a b))))
        with (mul (mul (pow (s (add a b)) (s (add a b))) y)
                  (pow (add (mul a x) (mul b y)) (add a b)))
        by ring.
      apply mul_le_mono_l. exact IH.
    + exact (kl (add a b) (add (mul a x) (mul b y)) y).
Qed.

(* E22: Gibbs' inequality.  q = (c, d)/N against p = (a, b)/N. *)
Theorem gibbs_ineq (a b c d : N) :
  add a b = add c d -> Le (mul (pow c a) (pow d b)) (mul (pow a a) (pow b b)).
Proof.
  destruct a as [| a].
  - intro e. rewrite add_z_l in e. cbn [pow].
    apply mul_le_mono_l. apply pow_le_mono_base. rewrite e. apply le_add_l.
  - destruct b as [| b].
    + intro e. change (add (s a) z) with (s a) in e.
      change (pow d z) with (s z). change (pow z z) with (s z).
      rewrite !mul_one_r. apply pow_le_mono_base. rewrite e. apply le_add.
    + intro e.
      pose proof (wamgm (s a) (mul c (s b)) (mul d (s a)) (s b)) as H.
      replace (add (mul (s a) (mul c (s b))) (mul (s b) (mul d (s a))))
        with (mul (mul (s a) (s b)) (add (s a) (s b))) in H by (rewrite e; ring).
      rewrite !mul_pow in H.
      rewrite (pow_add (s a) (s a) (s b)), (pow_add (s b) (s a) (s b)) in H.
      apply (mul_le_cancel_l (mul (pow (add (s a) (s b)) (add (s a) (s b)))
                                  (mul (pow (s a) (s b)) (pow (s b) (s a))))).
      { apply mul_ne_z; [apply pow_self_ne_z | apply mul_ne_z; apply pow_ne_z; apply s_ne_z]. }
      refine (le_trans _ _ _ _ (le_trans _ _ _ H _)); right; ring.
Qed.


(* ======================================================================
   Check: each line should print "Closed under the global context".
   ====================================================================== *)

Print Assumptions read_place.
Print Assumptions place_read.
Print Assumptions pair_ext.
Print Assumptions swap_swap.
Print Assumptions l_ne_r.
Print Assumptions em_two.
Print Assumptions meet_idem.
Print Assumptions inl_ne_inr.
Print Assumptions funext_in_kinds.
Print Assumptions propext_in_kinds.
Print Assumptions z_ne_s.
Print Assumptions rec_unique.
Print Assumptions lt_irrefl.
Print Assumptions lt_total.
Print Assumptions addIso.
Print Assumptions mulIso.
Print Assumptions powIso.
Print Assumptions mul_comm.
Print Assumptions mul_assoc.
Print Assumptions pow_add.
Print Assumptions mul_pow.
Print Assumptions lt_two_pow.
Print Assumptions mul_cancel_r.
Print Assumptions ltb_spec.
Print Assumptions sameQ_trans.
Print Assumptions ltQ_total.
Print Assumptions ltQ_trans.
Print Assumptions addQ_resp.
Print Assumptions negQ_resp.
Print Assumptions pow_lt_inv.
Print Assumptions bern.
Print Assumptions round_core.
Print Assumptions inLb_spec.
Print Assumptions inL_resp.
Print Assumptions inU_resp.
Print Assumptions inL_zero.
Print Assumptions inU_some.
Print Assumptions log_disjoint.
Print Assumptions log_located.
Print Assumptions log_rounded_L.
Print Assumptions log_rounded_U.
Print Assumptions log_mul_L.
Print Assumptions log_mul_U.
Print Assumptions boltzmann_L.
Print Assumptions boltzmann_U.
Print Assumptions W_ss.
Print Assumptions binom_le.
Print Assumptions gibbs_count_upper.
Print Assumptions amgm2.
Print Assumptions ib.
Print Assumptions kl.
Print Assumptions wamgm.
Print Assumptions gibbs_ineq.

Output of the check. The first two lines are the output of coqc –version; the remaining lines are the 53 results of Print Assumptions.

ent_check.txt

The Rocq Prover, version 9.3.0
compiled with OCaml 5.5.2
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context

PIC

Figure 298: Compiling Ent.v with Rocq 9.3.0. All 53 checks report that no axiom is used.

Output of the check

The file was compiled with the command coqc Ent.v. The first line below is the output of coqc –version; the remaining lines are the 53 results of Print Assumptions.

ent_check.txt

The Rocq Prover, version 9.3.0
compiled with OCaml 5.5.2
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context
Closed under the global context

The Boltzmann and Gibbs entropy [93, 94] formulas are two expressions of the same partition structure \(A + \neg A = 1\), and both reduce to \(A = A\) at the fixed point \(w = \tfrac {1}{2}\).

1. Standard Forms.

Boltzmann entropy:

\begin{equation} S = k_B \ln \Omega . \tag{21810}\end{equation}
Gibbs entropy (general):
\begin{equation} S = -k_B \sum _i p_i \ln p_i. \tag{21811}\end{equation}

2. Generalised Notation.

Under the substitution \(\Omega \mapsto N\), \(k_B \mapsto K\), \(p_i \mapsto w_i\), \(S \mapsto \Sigma \):

\begin{align} \Sigma &= K \ln N, \tag{21812}\\ \Sigma &= -K \sum _i w_i \ln w_i. \tag{21813}\end{align}

3. Special Cases.

(a) \(N = 1\): single state, no partition.

\begin{equation} N = 1 \;\Longrightarrow \; \Sigma = K \ln 1 = 0 \;\Longleftrightarrow \; T = 1 \;\Longleftrightarrow \; A = A. \tag{21814}\end{equation}

(b) Uniform distribution over \(n\) states.

\begin{equation} w_i = \frac {1}{n} \;\Longrightarrow \; \Sigma = -K \sum _{i=1}^{n} \frac {1}{n}\ln \frac {1}{n} = K \ln n. \tag{21815}\end{equation}

(c) Binary partition: \(w = \tfrac {1}{2}\).

\begin{equation} w = \frac {1}{2} \;\Longrightarrow \; \Sigma = -K\!\left (\frac {1}{2}\ln \frac {1}{2} + \frac {1}{2}\ln \frac {1}{2}\right ) = K \ln 2. \tag{21816}\end{equation}

4. Fixed Point as \(A = A\).

The binary case \(w = \tfrac {1}{2}\) is the fixed point \(A = \neg A = 0.5\):

\begin{equation} w = \frac {1}{2} \;\Longleftrightarrow \; A \wedge \neg A \;\Longleftrightarrow \; V = 0.5 \;\Longleftrightarrow \; A = A. \tag{21817}\end{equation}
At this fixed point, entropy is maximised at \(\Sigma = K \ln 2\):
\begin{equation} \Sigma (A \wedge \neg A) = -K\!\left (\frac {1}{2}\ln \frac {1}{2} + \frac {1}{2}\ln \frac {1}{2}\right ) = K \ln 2 \;\Longleftrightarrow \; A = A. \tag{21818}\end{equation}

5. Complete Structure.




State Entropy Level



\(N = 1\) \(\Sigma = 0\) \(T = 1\) (no partition)
\(w_i = 1/n\) (uniform) \(\Sigma = K\ln n\) \(O < T\)
\(w = 1/2\) (binary) \(\Sigma = K\ln 2\) \(V = 0.5\), \(A = \neg A\)
\(w \to 0\) or \(w \to 1\) \(\Sigma \to 0\) \(\partial T\) (boundary)



All: \(\Sigma \geq 0\), \(\Sigma = 0 \Longleftrightarrow T=1\), \(\Sigma = K\ln 2 \Longleftrightarrow A = \neg A = 0.5\)