-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make IsTrunc an inductive type #1806
Conversation
Global Instance contr_contr `{Funext} (A : Type) `{contrA : Contr A} | ||
: Contr (Contr A) | 100. | ||
Proof. | ||
exists contrA; intros [a2 c2]. | ||
destruct (contr a2). | ||
apply (ap (Build_Contr _ (center A))). | ||
apply path_forall; intros x. | ||
apply path2_contr. | ||
Defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was moved to Trunc.v and generalized to contr_istrunc
.
Definition isequiv_istrunc_unfold (n : trunc_index) (A : Type) | ||
: IsEquiv (istrunc_unfold n A). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be moved to Trunc.v, since that's the only place it is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(It's now also used in ReflectiveSubuniverse. It could still move to Trunc.v, but maybe it's best in Overture.v.)
Definition issig_contr (A : Type) | ||
: {x : A & forall y, x = y} <~> Contr A. | ||
Proof. | ||
issig. | ||
Defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example no longer works, and since it was never used, I removed it.
57cf712
to
4cbf7ef
Compare
I added a coercion from I had to do something with [n = -2], so I produce the contracting homotopy. This coercion doesn't satisfy the uniform inheritance property, but it does work in practice. Question: before this PR, given |
The second new commit finishes off Modalities/, Truncations/ and HIT/*, getting us more than half-way. |
Corollary equiv_contr_hprop (A : Type) `{Funext} `{IsHProp A} | ||
: Contr A <~> A. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to end of file.
Definition contr_forall `{Funext} `{P : A -> Type} `{forall a, Contr (P a)} | ||
: Contr (forall a, P a). | ||
Proof. | ||
exact (equiv_iff_hprop_uncurried (iff_contr_hprop A)). | ||
apply (Build_Contr _ (fun a => center (P a))). | ||
intro f. apply path_forall. intro a. apply contr. | ||
Defined. | ||
|
||
Global Instance istrunc_forall `{Funext} `{P : A -> Type} `{forall a, IsTrunc n (P a)} | ||
: IsTrunc n (forall a, P a) | 100. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two moved from Types/Forall, since they are useful here. Also, the first one contr_forall
is no longer an instance, since it was redundant.
@@ -4,6 +4,8 @@ | |||
Require Import Basics.Overture Basics.Equivalences. | |||
Local Open Scope path_scope. | |||
|
|||
Local Set Universe Minimization ToSet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done because otherwise the universe variable in contr_unit
was free (since IsTrunc
is now cumulative), which caused a problem in another file (Nullification.v, I think).
I did something similar with the definition of leq for nat and looking back I don't know if it was a good idea. Using inductive types can make the proofs more rigid to reduction, but also means we lose out on a lot of easy simplificiations. However I suppose that a lesson to be learnt is that proof by reduction can be expensive, in that sense it is cheaper for the proof assistant to have an explicit sequence of terms. It also saves us from having to recompute the same kinds of things repeatedly. The benefit of this approach is cumulativity and I think that is a good gain, since unnecessary universes cause a lot of performance issues for us. Also, since being truncated is a hprop, we really shouldn't concern ourselves too much with how the proofs look. If we ever for some reason need to reason about a proof, we can always equate it to a nicer one. For this reason, having something that gains us efficiency is desirable. Another benefit of this approach is that it will work better with the typeclasses mechanism. It is a huge burden to have to do reduction when resolving typeclasses. These are my thoughts on this issue, I am therefore happy to proceed with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for giving this a try! I guess I'm on the fence too.
I feel like a smarter exists
tactic ought to be able to notice that Contr A
can only be built by one constructor, and if we could "coerce from Funclass to something else" then intros
ought to work for proving other IsTrunc
s, but that's just wishing.
Do we have any sense for how much mileage we get out of cumulativity?
With the latest commit, the library builds. I did have to use "Admitted" for two results where universe variables are causing issues, and I didn't have time to investigate. One is |
I'm not sure yet. So far, it has caused problems in two places, but there's a chance that if we now tighten up some universe variables in earlier proofs, those problems would go away. I do like that Overture.v has gotten simpler, without those various typeclass hints. And most of the changes to the rest of the library were just adding constructors, which isn't a big deal. I just tried setting minimization to set globally, and around 300 files build, with just 6 failures, which is a bit better than before this PR. I haven't looked into how hard it would be to fix the errors. |
I did some timing tests, and this PR speeds things up by about 6% for both -j1 and -j8 builds. And that's without any tuning for the new definition of This PR improved a few proofs while repairing them, and I checked that those files didn't contribute significantly to the speedup. In fact, the files that improved the most were generally files that were not changed at all, or which had very minor changes. For example, the build time of Analysis/Locator.v is 49% of what it was before, even though it was not changed by this PR. |
That seems like a good argument! |
Also, no longer make contr_forall an instance, since it is redundant.
f972c08
to
2af8511
Compare
Rebased. All that is left is the universe issue in Hartogs. |
Ok, just a single universe annotation was needed to fix the last issue. @dominik-kirst , if you have a chance, could you confirm that when defining Definition hartogs_number' : Ordinal.
Proof.
set (carrier := {B : Ordinal@{A _} & card B <= card A}). |
With the inductive definition of Definition test {A : Type} (H : Contr A) (P : Contr A -> Type) : P H.
destruct H. Coq generates two goals, one for each constructor of P (Build_Contr A center contr)
P (istrunc_S A i) This causes problems for both the Note that when there is a goal of the form |
Could we just write a replacement for |
Also, when we are trying to prove something of the form I feel like there must be a standard solution to this, since it also comes up with things like vectors. |
@jdchristensen Vectors are unfortunately very poorly behaved and hardly used in Coq. Mainly for these reasons. FTR induction is capable of using different induction principles. |
cc @SkySkimmer @JasonGross Any ideas how to fix pattern matching on indexed inductives with destruct? |
Well, one thing that could in principle be done is to convert the index to a non-uniform parameter. That would also fix the ordering issue without an extra notation. Inductive IsTrunc (n : trunc_index) (A : Type@{u}) : Type@{u} :=
| Build_Contr : forall (center : A) (contr : forall y, center = y), (minus_two = n) -> IsTrunc n A
| istrunc_S : forall {k:trunc_index}, (forall x y:A, IsTrunc k (x = y)) -> (trunc_S k = n) -> IsTrunc n A. Then |
You could use inversion instead of destruct if you don't care about the term it generates. If you do care I'm not sure what you expect destruct to do. |
I tried the version of I tried I also tried replacing For now, I've pushed a change that at least makes |
@jdchristensen You might need dependent inversion. Mike's idea is basically inversion but the tactic goes a step further and tries to eliminate the index equalities. |
I had tried As an aside, I just replaced the I'm happy to merge this as is, unless anyone wants to look at it further. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, feel free to merge.
Sure, that seems fine to me for now. |
This is based on discussion in PR #1805 . With the changes shown here, around 225 of the 550 files in the library build. Every file changed in this PR builds, including all of Basics, Types, HProp.v, HSet.v, TruncType.v, etc. I haven't got to Truncations/* or Modalities/* yet, but I feel like at this point all of the non-trivial changes are done and it will just be a matter of inserting the constructors of
IsTrunc
and their inverses (viaequiv_istrunc_unfold
and/oristrunc_paths
) in many places. It's a little annoying having to do this, so that's why I stopped at this point to see what people think. Also, there might be things I should change in the foundations, and it would be good to hear such suggestions before doing the rest of the work.Two benefits I see:
IsTrunc
is now cumulative, and several things involving typeclasses that cluttered up Overture.v can simply be deleted.The downsides: having to convert frequently.
I'm on the fence about whether this is a win, so I'd be particularly interested in feedback on this.