Span.agda 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. module Span where
  2. open import Prelude
  3. open import Star
  4. open import Modal
  5. data SpanView {A : Set}{R : Rel A}(p : {a b : A} -> R a b -> Bool) :
  6. EdgePred (Star R) where
  7. oneFalse : {a b c d : A}(xs : Star R a b)(pxs : All (\x -> IsTrue (p x)) xs)
  8. (x : R b c)(¬px : IsFalse (p x))(ys : Star R c d) ->
  9. SpanView p (xs ++ x • ys)
  10. allTrue : {a b : A}{xs : Star R a b}(ts : All (\x -> IsTrue (p x)) xs) ->
  11. SpanView p xs
  12. span : {A : Set}{R : Rel A}(p : {a b : A} -> R a b -> Bool){a b : A}
  13. (xs : Star R a b) -> SpanView p xs
  14. span p ε = allTrue ε
  15. span p (x • xs) with inspect (p x)
  16. span p (x • xs) | itsFalse ¬px = oneFalse ε ε x ¬px xs
  17. span p (x • xs) | itsTrue px with span p xs
  18. span p (x • .(xs ++ y • ys)) | itsTrue px
  19. | oneFalse xs pxs y ¬py ys =
  20. oneFalse (x • xs) (check px • pxs) y ¬py ys
  21. span p (x • xs) | itsTrue px | allTrue pxs =
  22. allTrue (check px • pxs)
  23. _│_ : {A : Set}(R : Rel A)(P : EdgePred R) -> Rel A
  24. (R │ P) a b = Σ (R a b) P
  25. forget : {A : Set}{R : Rel A}{P : EdgePred R} -> Star (R │ P) =[ id ]=> Star R
  26. forget = map id fst
  27. data SpanView' {A : Set}{R : Rel A}(p : {a b : A} -> R a b -> Bool) :
  28. EdgePred (Star R) where
  29. oneFalse' : {a b c d : A}(xs : Star (R │ \{a b} x -> IsTrue (p x)) a b)
  30. (x : R b c)(¬px : IsFalse (p x))(ys : Star R c d) ->
  31. SpanView' p (forget xs ++ x • ys)
  32. allTrue' : {a b : A}(xs : Star (R │ \{a b} x -> IsTrue (p x)) a b) ->
  33. SpanView' p (forget xs)
  34. span' : {A : Set}{R : Rel A}(p : {a b : A} -> R a b -> Bool){a b : A}
  35. (xs : Star R a b) -> SpanView' p xs
  36. span' p ε = allTrue' ε
  37. span' p (x • xs) with inspect (p x)
  38. span' p (x • xs) | itsFalse ¬px = oneFalse' ε x ¬px xs
  39. span' p (x • xs) | itsTrue px with span' p xs
  40. span' p (x • .(forget xs ++ y • ys)) | itsTrue px
  41. | oneFalse' xs y ¬py ys = oneFalse' ((x ,, px) • xs) y ¬py ys
  42. span' p (x • .(forget xs)) | itsTrue px
  43. | allTrue' xs = allTrue' ((x ,, px) • xs)
  44. -- Can't seem to define it as 'map Some.a (\x -> (_ ,, uncheck x))'
  45. all│ : {A : Set}{R : Rel A}{P : EdgePred R}{a b : A}{xs : Star R a b} ->
  46. All P xs -> Star (R │ P) a b
  47. all│ (check p • pxs) = (_ ,, p) • all│ pxs
  48. all│ ε = ε