2

I am doing some exercises with the subsequence order,

record _⊑₀_ {X : Set} (xs ys : List X) : Set where
 field
  indices : Fin (length xs) → Fin (length ys)
  embed   : ∀ {a b : Fin (length xs)} → a < b → indices a < indices b
  eq      : ∀ {i : Fin (length xs)} → xs ‼ i ≡ ys ‼ (indices i)

where

_‼_ : ∀ {X : Set} → (xs : List X) → Fin (length xs) → X
[] ‼ ()
(x ∷ xs) ‼ fzero = x
(x ∷ xs) ‼ fsuc i = xs ‼ i

is the usual safe lookup.

Now while the record version is nice, I'd like to use inference rules instead as that's probably easier than constructing embeddings and proving properties about them each time.

So I try the following,

infix 3 _⊑₁_
data _⊑₁_ {X : Set} : (xs ys : List X) → Set where
 nil   : ∀ {ys} → [] ⊑₁ ys
 embed : ∀ {x y} → x ≡ y → x ∷ [] ⊑₁ y ∷ []
 cons  : ∀ {xs₁ ys₁ xs₂ ys₂} → xs₁ ⊑₁ ys₁ → xs₂ ⊑₁ ys₂ → xs₁ ++ xs₂ ⊑₁ ys₁ ++ ys₂  

Which looks promising. Though I have had trouble proving it to be a sound and complete reflection of the record version.

Anyhow, the subsequence order is transitive, and this is a bit of trouble:

⊑₁-trans : ∀ {X : Set} (xs ys zs : List X) → xs ⊑₁ ys → ys ⊑₁ zs → xs ⊑₁ zs
⊑₁-trans .[] ys zs nil q = nil
⊑₁-trans ._ ._ [] (embed x₁) q = {! q is absurd !}
⊑₁-trans ._ ._ (x ∷ zs) (embed x₂) q = {!!}
⊑₁-trans ._ ._ zs (cons p p₁) q = {!!}

We get unification errors when pattern matching on a seemingly impossible pattern q. So I have tried other data versions of the order that avoid this unification error but then other proofs have seemingly-absurd patterns lying around.

I'd like some help with a data version of the subsequence order (with soundness and completeness proofs, that'd be nice).

Are there any general heuristics to try when transforming a proposition in formula form into an inference/data form?

Thank-you!

Musa Al-hassy
  • 982
  • 1
  • 7
  • 12

1 Answers1

4

We get unification errors when pattern matching on a seemingly impossible pattern q.

That's the usual "green slime" problem. In the words of Conor McBride:

The presence of ‘green slime’ — defined functions in the return types of constructors — is a danger sign.

See here for some techniques to beat the green slime.

For _⊑_ use order preserving embeddings:

infix 3 _⊑_

data _⊑_ {α} {A : Set α} : List A -> List A -> Set α where
  stop : [] ⊑ []
  skip : ∀ {xs ys y} -> xs ⊑ ys -> xs     ⊑ y ∷ ys
  keep : ∀ {xs ys x} -> xs ⊑ ys -> x ∷ xs ⊑ x ∷ ys

⊑-trans : ∀ {α} {A : Set α} {xs ys zs : List A} -> xs ⊑ ys -> ys ⊑ zs -> xs ⊑ zs
⊑-trans  p        stop    = p
⊑-trans  p       (skip q) = skip (⊑-trans p q)
⊑-trans (skip p) (keep q) = skip (⊑-trans p q)
⊑-trans (keep p) (keep q) = keep (⊑-trans p q)
effectfully
  • 12,325
  • 2
  • 17
  • 40