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

WellFounded for lexicographic ordering on Vector. #1738

Closed
mechvel opened this issue Mar 12, 2022 · 2 comments
Closed

WellFounded for lexicographic ordering on Vector. #1738

mechvel opened this issue Mar 12, 2022 · 2 comments

Comments

@mechvel
Copy link
Contributor

mechvel commented Mar 12, 2022

Probably WellFounded does not hold for <-lex on lists.
Right?
But for each n, it holds for the vectors of length ≤ n.
So far I have implemented it for vectors of length ≡ n.
But
a) my library uses a different representation for Vector (shown below),
b) I expect, the Agda team can implement this itself.
c) I can send the code as a sample, it is clear enough. One can rewrite it to the standard Vector representation.

The approach is as follows.
The vector representation:

module Vector.Base {α} (A : Set α)                                                
  where                                                                           
  data Vector (n : ℕ) : Set α
    where                                              
    vec : (xs : List A) → length xs ≡ n → Vector n      

 _<_ : Rel A α

A general simple lemma suggested in another issue and used here:

subrelation-WellFounded :  ∀ {r} {~ ~' : Rel A r} → (~' ⇒ ~) → WellFounded ~ → WellFounded ~'

Lexicographic ordering on lists:

  _<llex_ = Lex-< _≡_ _<_

Lexicographic ordering on Vector n:

  <lex :  ∀ n → Rel (Vector n) _
  <lex n =  _<llex_ on toList

Theorem:

  wellFounded-<lex :  WellFounded _<_ → (n : ℕ) → WellFounded (<lex n) 

The proof is by induction on n and by using <lex-1+n ⇒ (×-lex _<_ <lexₙ) on f,
where f : Vector 1+n → A × Vector n is a certain evident map.
This is using that a) <lex-1+n on Vector 1+n equals to a certain composition ×-lex on Product with
<lexₙ on Vector n,
b) WellFounded for ×-lex for Product is in lib-1.7.

@MatthewDaggitt MatthewDaggitt changed the title Proposal WellFounded for lexicorgaphic ordering on Vector n. WellFounded for lexicographic ordering on Vector. Mar 12, 2022
@MatthewDaggitt
Copy link
Contributor

MatthewDaggitt commented Mar 12, 2022

I don't think we would want to add your representation of Vector to the standard library. But if you would like to make a PR with a proof that the lexicographic order over the current version of Vector is a well-founded relation if the original relation is well-founded, that would be welcome.

@jamesmckinna
Copy link
Contributor

Closed by #1924 . Cf. #2075 / #2077 .

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

3 participants