Built with Alectryon, running Coq+SerAPI v8.19.0+0.19.3. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑Ctrl+↓ to navigate, Ctrl+🖱️ to focus. On Mac, use ⌘ instead of Ctrl.
[Loading ML file number_string_notation_plugin.cmxs (using legacy method) ... done]
Require Import
HoTT.Tactics.Require Import
HoTT.Classes.interfaces.abstract_algebra
HoTT.Classes.interfaces.naturals
HoTT.Classes.interfaces.orders
HoTT.Classes.implementations.peano_naturals
HoTT.Classes.theory.rings
HoTT.Classes.orders.semirings
HoTT.Classes.theory.apartness.Sectionbasics.(* This definition of binary naturals is due to Martín Escardó and Cory Knapp *)Inductivebinnat : Type0 :=
| bzero : binnat (* zero *)
| double1 : binnat -> binnat (* 2n+1 *)
| double2 : binnat -> binnat. (* 2n+2 *)FixpointSucc (n : binnat) : binnat :=
match n with
| bzero => double1 bzero
| double1 n' => double2 n'
| double2 n' => double1 (Succ n')
end.Fixpointdouble (n : binnat) : binnat :=
match n with
| bzero => bzero
| double1 n' => double2 (double n')
| double2 n' => double2 (Succ (double n'))
end.FixpointDouble (n : nat) : nat :=
match n with
| O => O
| S n' => S (S (Double n'))
end.DefinitionDouble1 (n : nat) : nat := S (Double n).DefinitionDouble2 (n : nat) : nat := S (S (Double n)).Fixpointbinary (n : nat) : binnat :=
match n with
| O => bzero
| S n' => Succ (binary n')
end.Endbasics.Sectionbinary_equiv.Local Fixpointunary' (n : binnat) : nat :=
match n with
| bzero => O
| double1 n' => Double1 (unary' n')
| double2 n' => Double2 (unary' n')
end.
m, k, l: binnat E: binary^-1 m + binary^-1 k <
binary^-1 m + binary^-1 l
binary^-1 k < binary^-1 l
m, k, l: binnat E: binary^-1 m + binary^-1 k <
binary^-1 m + binary^-1 l
binary^-1 m + binary^-1 k < binary^-1 m + binary^-1 l
exact E.
m, n: binnat
forallx₂y₂ : binnat,
m * n ≶ x₂ * y₂ -> hor (m ≶ x₂) (n ≶ y₂)
m, n, k, l: binnat E: m * n ≶ k * l
hor (m ≶ k) (n ≶ l)
m, n, k, l: binnat E: m * n ≶ k * l
binary^-1 m * binary^-1 n ≶ binary^-1 k * binary^-1 l
m, n, k, l: binnat E: binary^-1 (m * n) ≶ binary^-1 (k * l)
binary^-1 m * binary^-1 n ≶ binary^-1 k * binary^-1 l
m, n, k, l: binnat E: binary^-1 m * binary^-1 n
≶ binary^-1 k * binary^-1 l
binary^-1 m * binary^-1 n ≶ binary^-1 k * binary^-1 l
exact E.
m, n: binnat
PropHolds (0 < m) ->
PropHolds (0 < n) -> PropHolds (0 < m * n)
m, n: binnat E: PropHolds (0 < m) F: PropHolds (0 < n)
PropHolds (0 < m * n)
m, n: binnat E: PropHolds (0 < m) F: PropHolds (0 < n)
PropHolds (binary^-10 < binary^-1 (m * n))
m, n: binnat E: PropHolds (0 < m) F: PropHolds (0 < n)
PropHolds (binary^-10 < binary^-1 m * binary^-1 n)
apply nat_full; assumption.
forallxy : binnat, x ≤ y <-> ~ (y < x)
m, n: binnat
m ≤ n <-> ~ (n < m)
apply nat_full.Qed.#[export] Instancebinnat_naturals_to_semiring : NaturalsToSemiRing binnat:=
fun______ => fix f (n: binnat) :=
match n with
| bzero => 0
| double1 n' => 2 * (f n') + 1
| double2 n' => 2 * (f n') + 2end.Definitionnat_to_semiring_helper : NaturalsToSemiRing nat :=
fun______ => fix f (n: nat) :=
match n with
| 0%nat => 0
| S n' => 1 + f n'
end.Sectionfor_another_semiring.UniverseU.Context {R:Type} `{IsSemiCRing R}.NotationtoR := (naturals_to_semiring binnat R).NotationtoR_fromnat := (naturals_to_semiring nat R).NotationtoR_vianat := (toR_fromnat ∘ unary).
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat
toR (Succ m) = toR m + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat
toR (Succ m) = toR m + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
toR (Succ bzero) = toR bzero + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ m) = toR m + 1
toR (Succ (double1 m)) = toR (double1 m) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ m) = toR m + 1
toR (Succ (double2 m)) = toR (double2 m) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
toR (Succ bzero) = toR bzero + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
2 * 0 + 1 = 0 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
0 * 2 + 1 = 0 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
0 + 1 = 0 + 1
done.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ m) = toR m + 1
toR (Succ (double1 m)) = toR (double1 m) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ m) = toR m + 1
2 * toR m + 2 = 2 * toR m + 1 + 1
apply plus_assoc.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ m) = toR m + 1
toR (Succ (double2 m)) = toR (double2 m) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHm: toR (Succ bzero) = toR bzero + 1
toR (Succ (double2 bzero)) = toR (double2 bzero) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
toR (Succ (double2 (double1 m))) =
toR (double2 (double1 m)) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double2 m)) = toR (double2 m) + 1
toR (Succ (double2 (double2 m))) =
toR (double2 (double2 m)) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHm: toR (Succ bzero) = toR bzero + 1
toR (Succ (double2 bzero)) = toR (double2 bzero) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHm: toR (Succ bzero) = toR bzero + 1
2 * (2 * 0 + 1) + 1 = 2 * 0 + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHm: toR (Succ bzero) = toR bzero + 1
2 * (2 * 0) + 2 * 1 + 1 = 2 * 0 + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHm: toR (Succ bzero) = toR bzero + 1
2 * (2 * 0) + 2 + 1 = 2 * 0 + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHm: toR (Succ bzero) = toR bzero + 1
0 + 2 + 1 = 0 + 2 + 1
reflexivity.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
toR (Succ (double2 (double1 m))) =
toR (double2 (double1 m)) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
2 * (2 * toR m + 2) + 1 = 2 * (2 * toR m + 1) + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
2 * (2 * toR m + 2) = 2 * (2 * toR m + 1) + 2
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1 L: 2 * toR m + 2 = 2 * toR m + 1 + 1
2 * (2 * toR m + 2) = 2 * (2 * toR m + 1) + 2
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
2 * (2 * toR m + 1 + 1) = 2 * (2 * toR m + 1) + 2
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
2 * (2 * toR m + 1) + 2 * 1 = 2 * (2 * toR m + 1) + 2
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double1 m)) = toR (double1 m) + 1
2 * (2 * toR m + 1) + 2 = 2 * (2 * toR m + 1) + 2
reflexivity.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (Succ (double2 m)) = toR (double2 m) + 1
toR (Succ (double2 (double2 m))) =
toR (double2 (double2 m)) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (double1 (Succ m)) = toR (double2 m) + 1
toR (Succ (double2 (double2 m))) =
toR (double2 (double2 m)) + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat IHm: toR (double1 (Succ m)) = toR (double2 m) + 1
2 * toR (double1 (Succ m)) + 1 =
2 * toR (double2 m) + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat
2 * (toR (double2 m) + 1) + 1 =
2 * toR (double2 m) + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat
2 * toR (double2 m) + 2 * 1 + 1 =
2 * toR (double2 m) + 2 + 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R m: binnat
2 * toR (double2 m) + 2 + 1 =
2 * toR (double2 m) + 2 + 1
reflexivity.Qed.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
forallm : binnat, toR m = (toR_fromnat ∘ binary^-1) m
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
forallm : binnat, toR m = (toR_fromnat ∘ binary^-1) m
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat
toR (binary n) = (toR_fromnat ∘ binary^-1) (binary n)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
toR (binary 0) = (toR_fromnat ∘ binary^-1) (binary 0)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n) =
(toR_fromnat ∘ binary^-1) (binary n)
toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R
toR (binary 0) = (toR_fromnat ∘ binary^-1) (binary 0)
reflexivity.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n) =
(toR_fromnat ∘ binary^-1) (binary n)
toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHn: toR (binary 0) =
(toR_fromnat ∘ binary^-1) (binary 0)
toR (binary 1) = (toR_fromnat ∘ binary^-1) (binary 1)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1)
toR (binary n.+2) =
(toR_fromnat ∘ binary^-1) (binary n.+2)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHn: toR (binary 0) =
(toR_fromnat ∘ binary^-1) (binary 0)
toR (binary 1) = (toR_fromnat ∘ binary^-1) (binary 1)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHn: toR (binary 0) =
(toR_fromnat ∘ binary^-1) (binary 0)
2 * 0 + 1 = 1
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R IHn: toR (binary 0) =
(toR_fromnat ∘ binary^-1) (binary 0)
0 + 1 = 1
apply plus_0_l.
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1)
toR (binary n.+2) =
(toR_fromnat ∘ binary^-1) (binary n.+2)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1)
toR (Succ (nat_iter n Succ bzero)) + 1 =
(toR_fromnat ∘ binary^-1) (binary n.+2)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1)
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1) L: (toR_fromnat ∘ binary^-1) (binary n.+1) + 1 =
toR_fromnat (binary^-1 (binary n.+1)).+1%nat
R: Type Aplus: Plus R Amult: Mult R Azero: Zero R Aone: One R H: IsSemiCRing R n: nat IHn: toR (binary n.+1) =
(toR_fromnat ∘ binary^-1) (binary n.+1) L: (toR_fromnat ∘ binary^-1) (binary n.+1) + 1 =
toR_fromnat (binary^-1 (binary n.+1)).+1%nat
forall (B : Type) (Aplus0 : Plus B) (Amult0 : Mult B)
(Azero0 : Zero B) (Aone0 : One B) (H : IsSemiCRing B),
IsSemiRingPreserving (naturals_to_semiring binnat B)
forall (B : Type) (Aplus0 : Plus B) (Amult0 : Mult B)
(Azero0 : Zero B) (Aone0 : One B) (H : IsSemiCRing B)
(h : binnat -> B),
IsSemiRingPreserving h ->
forallx : binnat,
naturals_to_semiring binnat B x = h x
IsSemiCRing binnat
exact binnat_semiring.
FullPseudoSemiRingOrder binnat_le binnat_lt
exact binnat_full.
forall (B : Type) (Aplus0 : Plus B) (Amult0 : Mult B)
(Azero0 : Zero B) (Aone0 : One B) (H : IsSemiCRing B),
IsSemiRingPreserving (naturals_to_semiring binnat B)
B: Type Aplus0: Plus B Amult0: Mult B Azero0: Zero B Aone0: One B H: IsSemiCRing B
IsSemiRingPreserving (naturals_to_semiring binnat B)
apply binnat_to_sr_morphism.
forall (B : Type) (Aplus0 : Plus B) (Amult0 : Mult B)
(Azero0 : Zero B) (Aone0 : One B) (H : IsSemiCRing B)
(h : binnat -> B),
IsSemiRingPreserving h ->
forallx : binnat,
naturals_to_semiring binnat B x = h x
B: Type Aplus0: Plus B Amult0: Mult B Azero0: Zero B Aone0: One B H: IsSemiCRing B h: binnat -> B IsSemiRingPreserving0: IsSemiRingPreserving h x: binnat
naturals_to_semiring binnat B x = h x
B: Type Aplus0: Plus B Amult0: Mult B Azero0: Zero B Aone0: One B H: IsSemiCRing B h: binnat -> B IsSemiRingPreserving0: IsSemiRingPreserving h x: binnat
IsSemiRingPreserving h
assumption.Qed.Endnaturals.Sectiondecidable.
n: binnat
bzero <> double1 n
n: binnat
bzero <> double1 n
n: binnat p: bzero = double1 n
Empty
n: binnat p: bzero = double1 n
(funx : binnat =>
match x with
| double1 _ => Unit
| _ => Empty
end) bzero
n: binnat p: bzero = double1 n
?Goal = bzero
n: binnat p: bzero = double1 n
match?Goalwith
| double1 _ => Unit
| _ => Empty
end
n: binnat p: bzero = double1 n
?Goal = bzero
exact p^.
n: binnat p: bzero = double1 n
match double1 n with
| double1 _ => Unit
| _ => Empty
end
exact tt.Qed.
n: binnat
bzero <> double2 n
n: binnat
bzero <> double2 n
n: binnat p: bzero = double2 n
Empty
n: binnat p: bzero = double2 n
(funx : binnat =>
match x with
| double2 _ => Unit
| _ => Empty
end) bzero
n: binnat p: bzero = double2 n
?Goal = bzero
n: binnat p: bzero = double2 n
match?Goalwith
| double2 _ => Unit
| _ => Empty
end
n: binnat p: bzero = double2 n
?Goal = bzero
exact p^.
n: binnat p: bzero = double2 n
match double2 n with
| double2 _ => Unit
| _ => Empty
end
exact tt.Qed.
m, n: binnat
double1 m <> double2 n
m, n: binnat
double1 m <> double2 n
m, n: binnat p: double1 m = double2 n
Empty
m, n: binnat p: double1 m = double2 n
(funx : binnat =>
match x with
| double2 _ => Unit
| _ => Empty
end) (double1 m)
m, n: binnat p: double1 m = double2 n
?Goal = double1 m
m, n: binnat p: double1 m = double2 n
match?Goalwith
| double2 _ => Unit
| _ => Empty
end
m, n: binnat p: double1 m = double2 n
?Goal = double1 m
exact p^.
m, n: binnat p: double1 m = double2 n
match double2 n with
| double2 _ => Unit
| _ => Empty
end
exact tt.Qed.Local Definitionundouble (m : binnat) : binnat :=
match m with
| bzero => bzero
| double1 k => k
| double2 k => k
end.Local Instancedouble1_inj : IsInjective double1
:= { injective := funabE => ap undouble E }.Local Instancedouble2_inj : IsInjective double2
:= { injective := funabE => ap undouble E }.
all:
first
[ left ; reflexivity
| right ; (idtac + apply symmetric_neq);
first
[ apply ineq_bzero_double1
| apply ineq_bzero_double2
| apply ineq_double1_double2
]
| destruct (IHm n) as [eq | ineq];
[ left; apply ap; exact eq
| right; intros E;
first
[ apply (injective double1) in E
| apply (injective double2) in E
]; auto
]
].Defined.Enddecidable.Sectionother_laws.
z: binnat
LeftCancellation plus z
z: binnat
LeftCancellation plus z
z, x, y: binnat p: z + x = z + y
x = y
z, x, y: binnat p: z + x = z + y
binary^-1 x = binary^-1 y
z, x, y: binnat p: binary^-1 (z + x) = binary^-1 (z + y)
binary^-1 x = binary^-1 y
z, x, y: binnat p: binary^-1 z + binary^-1 x =
binary^-1 z + binary^-1 y
binary^-1 x = binary^-1 y
exact (left_cancellation _ _ _ _ p).Qed.
z: binnat
PropHolds (z <> 0) -> LeftCancellation mult z
z: binnat
PropHolds (z <> 0) -> LeftCancellation mult z
z: binnat E: PropHolds (z <> 0)
LeftCancellation mult z
z: binnat E: z = 0 -> Empty
LeftCancellation mult z
z: binnat E: z = 0 -> Empty
binary^-1 z <> binary^-10
z: binnat E: z = 0 -> Empty H: binary^-1 z <> binary^-10
LeftCancellation mult z
z: binnat E: z = 0 -> Empty
binary^-1 z <> binary^-10
z: binnat E: z = 0 -> Empty q: binary^-1 z = binary^-10
Empty
z: binnat E: z = 0 -> Empty q: z = 0
Empty
exact (E q).
z: binnat E: z = 0 -> Empty H: binary^-1 z <> binary^-10
LeftCancellation mult z
z: binnat E: z = 0 -> Empty H: binary^-1 z <> binary^-10 x, y: binnat p: z * x = z * y
x = y
z: binnat E: z = 0 -> Empty H: binary^-1 z <> binary^-10 x, y: binnat p: binary^-1 (z * x) = binary^-1 (z * y)
x = y
z: binnat E: z = 0 -> Empty H: binary^-1 z <> binary^-10 x, y: binnat p: binary^-1 z * binary^-1 x =
binary^-1 z * binary^-1 y
x = y
exact (equiv_inj unary (nat_mult_cancel_l (unary z) H _ _ p)).Qed.
TotalRelation (binnat_le : Le binnat)
TotalRelation (binnat_le : Le binnat)
x, y: binnat
(binnat_le x y + binnat_le y x)%type
apply nat_le_total.Qed.
Irreflexive (binnat_lt : Lt binnat)
Irreflexive (binnat_lt : Lt binnat)
x: binnat
complement binnat_lt x x
apply nat_lt_irrefl.Qed.Endother_laws.Sectiontrichotomy.(* TODO this is an inefficient implementation. Instead, write this without going via the unary naturals. *)