cubical icon indicating copy to clipboard operation
cubical copied to clipboard

Added Unordered Pair

Open guilhermehas opened this issue 2 years ago • 11 comments

I created Unordered Pair, which means that a , b = b , a.

guilhermehas avatar Aug 16 '22 00:08 guilhermehas

Did you see the finite multisets: https://github.com/agda/cubical/blob/master/Cubical/HITs/FiniteMultiset/Base.agda ? ~~Unordered pairs are a special case and I think it would be better to define them as such, if you really have a use case specifically for pairs.~~ Do you know the relation to that and https://github.com/agda/cubical/blob/master/Cubical/HITs/ListedFiniteSet/Base.agda ?

felixwellen avatar Aug 16 '22 07:08 felixwellen

Yes, I know the relation. I will try to put in the properties. For example, in Agda Stdlib (https://github.com/agda/agda-stdlib/blob/master/src/Data/Vec/Recursive.agda), they defined Vec using Product. So maybe it is possible to define a FiniteMultiset using this Unordered Pair with the same idea.

guilhermehas avatar Aug 16 '22 18:08 guilhermehas

Yes, I know the relation. I will try to put in the properties. For example, in Agda Stdlib (https://github.com/agda/agda-stdlib/blob/master/src/Data/Vec/Recursive.agda), they defined Vec using Product. So maybe it is possible to define a FiniteMultiset using this Unordered Pair with the same idea.

Maybe you can add a comment? Something like "the relation to ... should be ...".

felixwellen avatar Aug 16 '22 19:08 felixwellen

I was trying to define the recursive definition:

FMSet : (A : Type ℓ) (n : ℕ) → Type ℓ
FMSet A 0 = Unit*
FMSet A 1 = A
FMSet A (suc (suc n)) = {!!}

And I figured out that it is not possible to do, because both elements need to be of the same type.

Yes, I know the relation. I will try to put in the properties. For example, in Agda Stdlib (https://github.com/agda/agda-stdlib/blob/master/src/Data/Vec/Recursive.agda), they defined Vec using Product. So maybe it is possible to define a FiniteMultiset using this Unordered Pair with the same idea.

Maybe you can add a comment? Something like "the relation to ... should be ...".

Because of that, what I commented before was wrong.

guilhermehas avatar Aug 16 '22 19:08 guilhermehas

I figured out how to do:

addN : UnorderedPair (A × ℕ) → ℕ
addN = rec isSetℕ (λ x y → proj₂ x + proj₂ y) λ x y → +-comm (proj₂ x) (proj₂ y)

data FMSet (A : Type ℓ) : ℕ → Type ℓ where
  one : A → FMSet A 1
  join : (xs : UnorderedPair (A × ℕ)) → FMSet A (addN xs)

guilhermehas avatar Aug 16 '22 19:08 guilhermehas

Since this construction is limited to the sets, wouldn't it be cleaner to implement it by a set-coequalizer? Consider the coequalizer of swap, id : A × A -> A × A, for example

plt-amy avatar Aug 16 '22 20:08 plt-amy

Since this construction is limited to the sets, wouldn't it be cleaner to implement it by a set-coequalizer? Consider the coequalizer of swap, id : A × A -> A × A, for example

Thanks for your suggestion. I proved that both are isomorphic.

guilhermehas avatar Aug 16 '22 22:08 guilhermehas

As I just learned in the hallway, there is also an untruncated unordered pair notion, defined as maps from a set merely equivalent to Fin 2 to A. I guess for A a Set the Set-truncation of that notion should agree with your notion?

felixwellen avatar Aug 17 '22 10:08 felixwellen

As I just learned in the hallway, there is also an untruncated unordered pair notion, defined as maps from a set merely equivalent to Fin 2 to A. I guess for A a Set the Set-truncation of that notion should agree with your notion?

I didn't understand. Can you give a code example?

guilhermehas avatar Aug 19 '22 13:08 guilhermehas

Let A be a type (of arbitrary h-level). We define the type of unordered pairs with coordinates in A as the type

Σ[ X ∈ Type ] (∥ X ≃ Bool ∥ × X → A)

This construction is at least a groupoid, but for A of h-level ≥ 3, it preserves h-levels. The idea is that, in the same way that a pair in A is the same as a function Bool→A, we can take away the ordering by allowing pairs to choose their own index types up to a mere equivalence; consumers of unordered pairs can't inspect the underlying type, and all they know is that it has two elements.

The pairing {x,y} is defined to be

Bool , inc id , λ { true → x; false → y }

This is equal to the pairing {y,x} because the type of identifications between unordered pairs is given by equivalences of their underlying types which commute with the projection function.

plt-amy avatar Aug 19 '22 14:08 plt-amy

Bool , inc id , λ { true → x; false → y }

This is equal to the pairing {y,x} because the type of identifications between unordered pairs is given by equivalences of their underlying types which commute with the projection function.

I am trying to do your implementation, but I am in trouble. What am I doing wrong?

UPairBool : Type ℓ → Type _
UPairBool A = Σ[ X ∈ Type ] (∥ X ≃ Bool ∥₁ × (X → A))

private
  uP₁ : UPairBool Bool
  uP₁ = Bool , ∣ idEquiv Bool ∣₁ , λ where false → false ; true → true

  uP₂ : UPairBool Bool
  uP₂ = Bool , ∣ notEquiv ∣₁ , λ where false → true ; true → false

  uP₁≡uP₂ : uP₁ ≡ uP₂
  uP₁≡uP₂ i = Bool , squash₁ ∣ idEquiv Bool ∣₁ ∣ notEquiv ∣₁ i  , {!!}

guilhermehas avatar Aug 19 '22 20:08 guilhermehas

I am trying to do your implementation, but I am in trouble. What am I doing wrong?

What you are trying to prove is true. The first part of your term uP₁≡uP₂ should not be constantly Bool, but come from the not equivalence.

felixwellen avatar Aug 22 '22 12:08 felixwellen

Also, isn't that the set-truncation? The equivalence has to be propositionally-truncated.

plt-amy avatar Aug 22 '22 13:08 plt-amy

∥_∥₁ is propositional truncation.

felixwellen avatar Aug 22 '22 13:08 felixwellen

I am in trouble trying to prove this thing:

uP₁≡uP₂ : uP₁ ≡ uP₂
uP₁≡uP₂ = ΣPathP (notEq , ΣPathP (helper₁ , helper₂)) where
  helper₁ : PathP (λ z → ∥ notEq z ≃ Bool ∥₁) ∣ idEquiv Bool ∣₁ ∣ notEquiv ∣₁
  helper₁ i = {!squash₁ ∣ idEquiv Bool ∣₁ ∣ notEquiv ∣₁ i!}

  helper₂ : PathP (λ i → notEq i → Bool) (idfun Bool) not
  helper₂ i b = {!!}

guilhermehas avatar Aug 24 '22 00:08 guilhermehas

You can, of course, also postpone the proof and wrap up the current PR...

felixwellen avatar Aug 29 '22 08:08 felixwellen

Sorry for the long wait and thanks for the updates. I am a bit puzzled about the recursive FMSets - maybe it is better to save those for a PR where you prove something about them? All the other files look good to me.

felixwellen avatar Oct 06 '22 14:10 felixwellen

I deleted the recursive file.

guilhermehas avatar Oct 06 '22 18:10 guilhermehas