Skip to content
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

Algebra operations #1428

Merged
merged 4 commits into from
Apr 5, 2021
Merged

Conversation

andreaslyn
Copy link
Collaborator

@andreaslyn andreaslyn commented Mar 25, 2021

Started work on algebra operations

Added Finite/FinSeq.v

Make some definitions monomorphic to fix universe blowup in Finite/FinNat.v

(** Functions [head_dom'] and [head_dom] are used to get the first
element of a nonempty operation domain [a : forall i, A (ss i)]. *)

Monomorphic Definition head_dom' {σ} (A : Carriers σ) (n : nat)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am making certain definitions monomorphic to avoid unverse blowup.

@@ -112,14 +112,14 @@ Proof.
+ rewrite path_fin_fsucc_incl, path_nat_fin_incl.
apply IHn.
+ reflexivity.
Qed.
Defined.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need the computation for operation_curry.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's curious, since it's a path in nat. Is it not possible to just use the fact that nat is a set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -79,7 +79,8 @@ Proof.
(hset_path2 1 (@path_succ_finnat n u u.2)) idpath).
Defined.

Definition is_bounded_fin_to_nat {n} (k : Fin n) : fin_to_nat k < n.
Monomorphic Definition is_bounded_fin_to_nat {n} (k : Fin n)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Monomorphic to avoid universe blowup

(** Finite-dimensional vector. Note that the induction principle
[vect_ind] uses funext and does not compute. *)

Definition Vect (n : nat) (A : Type) : Type := Fin n -> A.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure whether vector is a good name for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, it's at least a traditional name in dependent type theory, right? Although I guess it's more common to define as an indexed family than as a function type. But yeah, it might be confusing if we start also doing linear algebra. (-: Any other suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why you decided to define them this way rather than as an inductive family? It seems like the latter would use less funext, for one thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that Vect is a traditional name in dependent type theory, but perhaps not suitable here. An alternative is FinSeq for finite sequence.

In the multi-sorted universal algebra that I am developing, this type occurs as the of sorts for the domain of finitary operations: https://github.com/HoTT/HoTT/blob/9e8e09146747077eb81c6f152bc5f04b4d7cd5f5/theories/Algebra/Universal/Operation.v#L77

In my initial approach I defined the inductive family and proved the two equivalent, but I do not need the inductive family, so I decided to leave it out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I use funext to derive the induction principle for the type, which I just included for completeness. I do not expect to need that for universal algebra.

Copy link
Contributor

Choose a reason for hiding this comment

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

FinSeq could be good. Why is this definition preferable to the inductive one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the inductive family is often preferable, but in my particular case I need this one to instantiate the SymbolTypeOf record: https://github.com/HoTT/HoTT/blob/bce95e43fe3407706ac0eae1bd9ddaf7d42fb2b9/theories/Algebra/Universal/Algebra.v#L23 when Arity is Fin n.

I am fine with having both notions of FinSeq. The "default" inductive definition in HoTT.Spaces.FinSeq and this one in HoTT.Spaces.Finite.FinSeq. What do you think?

(** A non-empty vector is the [vcons] of its head and tail,
[path_expand_vcons'] and [path_expand_vcons]. *)

Lemma path_expand_vcons' {A : Type} (n : nat)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The remaining lemmas are here to prove vect_ind. I do not think that I will need it, but I formalised vect_ind for completeness.

@mikeshulman
Copy link
Contributor

mikeshulman commented Mar 26, 2021 via email

@andreaslyn andreaslyn force-pushed the infinitary-universal-algebra branch 2 times, most recently from 3fae52a to e7d9b94 Compare March 31, 2021 22:22
@andreaslyn
Copy link
Collaborator Author

I have rebased and changed Vect to FinSeq.

@Alizter
Copy link
Collaborator

Alizter commented Apr 2, 2021

The universe issues here are interesting. We can fix some issues by changing Fin in Finite/Fin.v to the following:

Fixpoint Fin (n : nat) : Type0
  := match n with
       | 0 => Empty
       | S n => Fin n + Unit
     end.

It makes sense to stick it in the lowest universe, just like we do with nat. So Fin doesn't depend on universes.

This let's us reduce the universes in FinSeq as a result. In general I would opt for:

Definition FinSeq@{u} (n : nat) (A : Type@{u}) : Type@{u} := Fin n -> A.

This means that FinSeq only has one universe.

This should reduce some of the blowup I observed.

@andreaslyn
Copy link
Collaborator Author

Good idea. I have added those changes.

@andreaslyn andreaslyn force-pushed the infinitary-universal-algebra branch from c6cac28 to da0c0a6 Compare April 2, 2021 18:11
Started work on algebra operations

Added Finite.Vect

Make some definitions monomorphic to fix universe blowup in Finite.FinNat
Put Fin in lowest universe and 1 universe for FinSeq.
@andreaslyn andreaslyn force-pushed the infinitary-universal-algebra branch from da0c0a6 to 7137029 Compare April 5, 2021 20:21
@andreaslyn
Copy link
Collaborator Author

Are we OK with merging this?

@mikeshulman
Copy link
Contributor

Looks fine to me.

@Alizter Alizter merged commit dd3c399 into HoTT:master Apr 5, 2021
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