Skip to content

_≤ᵇ_ for Natural numbers #781

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

Closed
HuStmpHrrr opened this issue May 17, 2019 · 15 comments
Closed

_≤ᵇ_ for Natural numbers #781

HuStmpHrrr opened this issue May 17, 2019 · 15 comments

Comments

@HuStmpHrrr
Copy link
Member

I realized that now in stdlib, _<ᵇ_ is defined and _≤?_ depends on it. Does that make sense to define _≤ᵇ_ in terms of _<ᵇ_ and have _≤?_ derive proofs from _≤ᵇ_? Namely, two additional lemmas, ≤ᵇ⇒≤ and ≤⇒≤ᵇ. I am asking this, because for me _≤_ is a more frequent relation than _<_.

@MatthewDaggitt
Copy link
Contributor

Hmm, well the idea is that _<ᵇ_ should only be used very rarely. We've only added it in order to give _≤?_ a performance boost behind the scenes.

I'm struggling to think of a use case for where using m ≤ᵇ n wouldn't be able to be replaced by ⌊ m ≤? n ⌋. Maybe there's a small constant factor in difference in performance, but that's probably eliminated by the necessity of having to define m ≤ᵇ n as m <ᵇ n ∨ m =ᵇ n.

Basically if we can come up with a use for it then yes. Otherwise I think best to try and keep the boolean versions as unobtrusive as possible and encourage everyone to use the proper dependent types. I know as an Agda beginner I would have gone straight for the boolean versions if they were prominently available.

@HuStmpHrrr
Copy link
Member Author

one trouble I have with the current definition of _≤?_ is that it builds the proof by depending on _<_ relation. my use case is the following two lemmas.

≤?-yes :  {m n} (m≤n : m ≤ n)  (m ≤? n) ≡ yes m≤n

≤?-no :  {m n} (m>n : ¬ m ≤ n) λ ¬p  (m ≤? n) ≡ no ¬p

the idea is that if _≤ᵇ_ exists, then probably _≤?_ can depend on it and make use of T and derive this conclusion. that's where these two lemmas are coming from: ≤ᵇ⇒≤ and ≤⇒≤ᵇ.

@gallais
Copy link
Member

gallais commented May 19, 2019

We should probably provide a pair of general lemmas:

(p? : Decidable P) -> Irrelevant P -> (p : P) -> p? ≡ yes p
(p? : Decidable P) -> ¬ P ->λ ¬p  p? ≡ no ¬p

Which could then be used to reimplement ≡-≟-identity and ≢-≟-identity in
Relation.Binary.PropositionalEquality as well as the result you
are interested in.

@HuStmpHrrr
Copy link
Member Author

yes that's true. probably the first lemma can have a relevant variant.

@jespercockx
Copy link
Member

Why does ≤?-no need the extra ∃ λ ¬p → ...? Any two proofs of a negative proposition are equal, so we should be able to strengthen it to ≤?-no : ∀ {m n} (m>n : ¬ m ≤ n) → (m ≤? n) ≡ no m>n (which also makes it more symmetric to ≤?-yes).

@HuStmpHrrr
Copy link
Member Author

sorry I might not react fast enough today. could you please explain why that's true?

for example,

module _ {m n : ℕ}
         (m>n : ¬ m ≤ n) where

  m>n′ : ¬ m ≤ n
  m>n′ z≤n       = m>n z≤n
  m>n′ (s≤s m≤n) = m>n (s≤s m≤n)

  irrelevant : m>n ≡ m>n′
  irrelevant = {!!}

how can this be proved?

@jespercockx
Copy link
Member

Hm, I was a bit too fast: you can prove that they are pointwise equal (because any two elements of the empty type are equal) but to prove that m>n and m>n′ are equal you need functional extensionality. Maybe it's not worth making that extra assumption (though it's quite common).

@WolframKahl
Copy link
Member

WolframKahl commented May 19, 2019 via email

@jespercockx
Copy link
Member

They are propositionally equal, not definitionally equal (if you want them to be, you can use irrelevance or Prop).

@gallais
Copy link
Member

gallais commented May 20, 2019

Yep. That's why I opened #645 but then we decided that the change would be too
invasive, effectively forcing all the users of the standard library to accept
working in Agda with --prop enabled.

@jespercockx
Copy link
Member

I always argued in favour of making --prop enabled by default, you can blame @andreasabel for that :P

@MatthewDaggitt
Copy link
Contributor

We should probably provide a pair of general lemmas:

(p? : Decidable P) -> Irrelevant P -> (p : P) -> p? ≡ yes p
(p? : Decidable P) -> ¬ P ->λ ¬p  p? ≡ no ¬p

Which could then be used to reimplement ≡-≟-identity and ≢-≟-identity in
Relation.Binary.PropositionalEquality as well as the result you
are interested in.

Yup, we'd need to add the definition Irrelevant to Relation.Nullary as well.

@HuStmpHrrr
Copy link
Member Author

It's OK to always have --prop open, isn't it? what can it hurt?

@jespercockx
Copy link
Member

Without --prop, you can write the following:

data D A : Set where
  c : A -> D A

and Agda will figure out that A : Set. With --prop it could be either A : Set or A : Prop, so Agda refuses the type.

@MatthewDaggitt
Copy link
Contributor

The original problem has been solved so I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants