Skip to content

Fresh PR: Integers as Higher Inductive Type implementation in Coq#41

Open
maxipetro wants to merge 25 commits into
jdchristensen:masterfrom
maxipetro:integers_hit_fresh
Open

Fresh PR: Integers as Higher Inductive Type implementation in Coq#41
maxipetro wants to merge 25 commits into
jdchristensen:masterfrom
maxipetro:integers_hit_fresh

Conversation

@maxipetro

Copy link
Copy Markdown

This is a fresh PR for the implementation of Integers as Higher Inductive Type implementation in Coq following [Altenkirch and Scoccola 2020].

@jdchristensen

Copy link
Copy Markdown
Owner

Now that we've merged the BiInv.v part, can you rebase on master and force push, so there is just one commit without that material?

@maxipetro maxipetro force-pushed the integers_hit_fresh branch from 06cf313 to f7607e4 Compare April 29, 2026 14:40
@jdchristensen

Copy link
Copy Markdown
Owner

You rebased on the previous version of master, I think. You probably need to pull in the latest master.

@maxipetro maxipetro force-pushed the integers_hit_fresh branch from f7607e4 to 5f0e4e3 Compare April 29, 2026 19:33
@maxipetro

Copy link
Copy Markdown
Author

You rebased on the previous version of master, I think. You probably need to pull in the latest master.

I rebased on the updated master, the problem was the commit that I made in the other PR before it got merged. The changes of that commit were not made in this branch and so the rebasing caused a conflict. My merge editor then messed things up when I had to manually resolve the conflict. It should be fine now

Comment thread theories/Spaces/HITInt.v Outdated
@jdchristensen

Copy link
Copy Markdown
Owner

For the record, the previous PR is #32 .

@jdchristensen

jdchristensen commented Apr 30, 2026

Copy link
Copy Markdown
Owner

I've copied over the tasks list and updated it:

  • Decide on directions of pf, pf1, pf2.
  • There are still many style issues to be fixed, e.g. indentation, spacing, line breaks, etc.
  • Proof read all comments in the code and think about naming conventions for definitions/theorems. When it makes sense to do so, results should be named like those in Int.v, so this material can replace Int.v with users not needing to change much. Note that we usually use only lower case in identifiers.
  • Can any of the proofs be simplified, e.g. by using the uniqueness principle more? Or the new IntHIT_ind_equiv?
  • What is missing from Int.v that we still need to add to HITInt.v? E.g. a coercion from nat is one thing, but I suspect there is more.
  • Can SInt.v (formerly IntShort.v) be simplified further? If it becomes simple enough, we could inline it into HITInt.v.
  • Remove Int.v and rename HITInt.v to Int.v. Rename everything inside HITInt.v to the old names, so that the rest of the library can use the new approach with minimal changes. Even better, maybe some other parts of the library will simplify slightly.

Edit: minor updates 2026/6/17.

Comment thread theories/Spaces/HITInt.v
Comment thread theories/Equiv/BiInv.v Outdated
@jdchristensen

Copy link
Copy Markdown
Owner

I made a few cleanups. I think similar proof simplifications could be made in other places, so look around for similar things.

Comment thread theories/Spaces/HITInt.v Outdated
Comment thread theories/Spaces/HITInt.v Outdated
@jdchristensen

Copy link
Copy Markdown
Owner

@maxipetro Just checking on the status of this.

jdchristensen and others added 4 commits June 15, 2026 11:19
- Remove the unused imports Categories.Additive.Biproducts and
  Classes.theory.groups.  Nothing in the file refers to either: the
  monoid-morphism helpers (IsMonoidPreserving, id_monoid_morphism,
  compose_monoid_morphism, preserves_sg_op, ...) all come from
  abstract_algebra, which is already imported, and biproducts are reached
  transitively through SemiAdditive.

- Rename inverse_morphism_unique to hom_moveL_1V, paralleling the group
  movement lemma grp_moveL_1V, and update its two uses.

- Name the AdditiveFunctor fields consistently: the coercion is addfunctor
  and the monoid-preservation instance is ismonoidpreserving_addfunctor.

- Remove the AdditiveFunctorLaws section; its three lemmas were direct
  applications of preserves_sg_op, preserves_mon_unit and preserves_inverse,
  which apply to an additive functor's action without a wrapper.
Add additive categories infrastructure
@maxipetro

maxipetro commented Jun 16, 2026

Copy link
Copy Markdown
Author

@jdchristensen I think now all the open issues are resolved. Regarding the bullet points in your list:

The directions of pf, pf1 and pf2 are changed so I think we can tick this off.

Some comments exceed the 80 character limit per line. Should I break them into two lines?

I think we should rename uniquenessZ* to something that fits the naming conventions of the library, maybe "IntHIT_uniqueness" which will be then renamed later to "Int_uniqueness"? The same for IntITtoIntHIT and similar lemmas.

I can start replacing the old Int with the new HITInt and rename the latter. If further simplifications or style fixes are found in the future they should not affect this.

@jdchristensen

jdchristensen commented Jun 17, 2026

Copy link
Copy Markdown
Owner

The directions of pf, pf1 and pf2 are changed so I think we can tick this off.

Sounds good.

Some comments exceed the 80 character limit per line. Should I break them into two lines?

No, the style for comments is to have no line breaks at all.

I think we should rename uniquenessZ* to something that fits the naming conventions of the library, maybe "IntHIT_uniqueness" which will be then renamed later to "Int_uniqueness"? The same for IntITtoIntHIT and similar lemmas.

I reworked this material (I'll push in a minute) but didn't adjust naming. I'm not exactly sure what is best. Maybe IntHIT_homotopic for now? Later, int_homotopic. (We don't capitalize the names of types in most identifiers, except for the type name itself.)

I can start replacing the old Int with the new HITInt and rename the latter. If further simplifications or style fixes are found in the future they should not affect this.

Let's wait on this, as there are too many issues right now. I'll provide feedback in a minute.

@jdchristensen

Copy link
Copy Markdown
Owner

I just pushed eight commits. Please read them separately, as I was careful to only put related changes together, and some of the changes overlap so won't be understandable if you just look at the overall diff. Here's a summary from oldest to newest:

BiInv, HITInt: fix spacing, indentation; remove unneeded parentheses

I only looked at a small portion of the file, but found tons of style errors. Please go through the file carefully checking the spacing, indentation, parenthesization, etc.

HITInt: use == notation, slightly simplify proof, fix comments

The == notation is good to use when it makes sense. The simplifications to the proof are also worth noting, although this proof disappears in a later commit.

BiInv: clean-ups to EquivalenceCompatibility

Various style things. In particular, notice that every definition in this section had a common argument pe, so it's natural to make this a Section variable.

HITInt: clarify/correct comments

I removed an incorrect comment that said: "Since it is an Instance that biinvertible maps are equivalent to half-adjoint equivalences using type class search one could also use IntHIT_rec_biinv instead." Only one direction is an instance, and it's not the one that would allow us to use IntHIT_rec_biinv instead. But this raises the question of why we need the other one. I'll make a comment in the appropriate spot.

HITInt: clarify two proofs

Minor.

BiInv: move prod_isbiinv and issig_biinv earlier in file

They were separating related functions, so I moved them out of the way.

BiInv: adjust retr_is_sect_isbiinv so that adjoint law holds, and dually

This is an important change. As originally defined, retr_is_sect_isbiinv and sect_is_retr_isbiinv probably don't satisfy the adjoint laws. So I inlined their proofs into the proofs of isequiv_isbiinv and isequiv_isbiinv'. Since those use adjointification, the resulting proofs that these composites are the identities will then satisfy the adjoint law.

HITInv: prove IntHIT_ind_equiv, greatly simplifying uniqueness principles

Using the adjoint law, I was able to prove a simple induction principle IntHIT_ind_equiv. This makes the proofs of the uniqueness principles very short. I suspect it can also be used in other places, but I didn't look around. Can you see if there is anywhere else that can benefit?

Comment thread theories/Equiv/BiInv.v
Let es' := eisretr_biinv e' : e' o s' == idmap.

Definition helper_r (pe : e' o f == g o e) : r' o g o e == f o r o e.
Definition helper_r : r' o g o e == f o r o e.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these helpers needed? Since they are one-liners and are used just once, couldn't they be inlined to where they are needed? If they are kept, they should be renamed to something less generic, or made Local.

Comment thread theories/Equiv/BiInv.v
Definition helper_r (pe : e' o f == g o e) : r' o g o e == f o r o e.
Definition helper_r : r' o g o e == f o r o e.
Proof.
intro x.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a or b, to help the reader know the type of this variable. (Not just here, everywhere that you use intro.)

Comment thread theories/Spaces/HITInt.v
Comment on lines +85 to +89
Definition IntHIT_ind_hprop {P : IntHIT -> Type} `{forall x, IsHProp (P x)}
(t0 : P zero_i)
(f : forall z : IntHIT, P z -> P (succ z))
(g : forall z : IntHIT, P z -> P (pred z))
: forall x, P x.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent variable names: x in two places and z in two places. I think using z as a variable of type IntHIT is good. Again, not just here, but everywhere.

Comment thread theories/Spaces/HITInt.v
Comment on lines +112 to +116
Definition IntHIT_rec {P : Type} (t0 : P)
(f : P -> P) (g1 : P -> P) (g2 : P -> P)
(s : forall (t : P), g1 (f t) = t)
(r : forall (t : P), f (g2 t) = t)
: IntHIT -> P.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the corresponding beta laws should go in a Section, since they use the same variables.

Comment thread theories/Spaces/HITInt.v
Comment on lines +199 to +207
Definition uniquenessZ_two_fun_equiv
{P : Type}
(f : P -> P)
{e' : IsEquiv f}
(k1 : IntHIT -> P)
(k2 : IntHIT -> P)
(p0 : k1 zero_i = k2 zero_i)
(pf1 : forall (z : IntHIT), (k1 o succ) z = (f o k1) z)
(pf2 : forall (z : IntHIT), (k2 o succ) z = (f o k2) z)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make argument lists more compact, like I did for the two results before this one. (Again, not just here, but in general.)

Comment thread theories/Spaces/HITInt.v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants