Proof.agda 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. module Proof where
  2. open import Basics hiding (_==_)
  3. open import Proc
  4. open import Path
  5. import Graph
  6. private
  7. open module G = Graph Nat
  8. open module P = Process param hiding (U; T; _!_)
  9. {-
  10. Soundness:
  11. if we get an answer there is a path
  12. Completeness:
  13. if there is a path we get an answer
  14. -}
  15. infix 18 _encodes_
  16. data _encodes_ {G : Graph} :
  17. {x y : Nat} -> List Node -> Path G x y -> Set where
  18. nul-path : {x : Nat} -> stop :: [] encodes nul {x = x}
  19. step-path : {x y z : Nat}{xs : List Node}
  20. {step : Step G x y}{path : Path G y z} ->
  21. xs encodes path ->
  22. node y :: xs encodes step <> path
  23. test : {G : Graph}{a b c : Nat}
  24. {ab : Step G a b}{bc : Step G b c} ->
  25. node b :: node c :: stop :: [] encodes
  26. ab <> bc <> nul
  27. test = step-path (step-path nul-path)
  28. target : {G : Graph}{x y : Nat} -> Step G x y -> Nat
  29. target {y = y} _ = y
  30. encoding : {G : Graph}{x y : Nat} -> Path G x y -> List Node
  31. encoding nul = stop :: []
  32. encoding (step <> path) = node (target step) :: encoding path
  33. lem-encode : {G : Graph}{x y : Nat}(path : Path G x y) ->
  34. encoding path encodes path
  35. lem-encode nul = nul-path
  36. lem-encode (step <> path) = step-path (lem-encode path)
  37. data WellFormed : List Node -> Set where
  38. good-stop : WellFormed (stop :: [])
  39. good-:: : forall {x xs} -> WellFormed xs -> WellFormed (node x :: xs)
  40. data MalFormed : List Node -> Set where
  41. bad-[] : MalFormed []
  42. bad-:: : forall {x xs} -> MalFormed xs -> MalFormed (node x :: xs)
  43. bad-stop : forall {x xs} -> MalFormed (stop :: x :: xs)
  44. module Theorems (G : Graph)(start end : Nat) where
  45. mainp = main G start end
  46. Complete : Set
  47. Complete = (path : Path G start end) ->
  48. ∃ \q -> Silent q /\
  49. mainp -! encoding path !->* q
  50. Sound : Set
  51. Sound = forall q xs -> Silent q -> WellFormed xs ->
  52. mainp -! xs !->* q ->
  53. ∃ \(path : Path G start end) -> xs encodes path
  54. Sound-Fail : Set
  55. Sound-Fail = forall q xs -> Silent q -> MalFormed xs ->
  56. mainp -! xs !->* q -> Path G start end -> False
  57. silent-edges : {a : U} -> Graph -> Proc a
  58. silent-edges [] = o
  59. silent-edges (_ :: G) = o || silent-edges G
  60. silent-silent-edges : {a : U}(G : Graph) -> Silent (silent-edges {a} G)
  61. silent-silent-edges [] = silent-o
  62. silent-silent-edges (_ :: G) = silent-|| silent-o (silent-silent-edges G)
  63. module Proofs (G : Graph) where
  64. private open module T = Theorems G
  65. complete : (start end : Nat) -> Complete start end
  66. complete x .x nul =
  67. ∃-intro q (silent-q , run)
  68. where
  69. edg₁ = {! !}
  70. edg₂ = {! !}
  71. edg₃ = silent-edges G
  72. silent-edg₃ : Silent edg₃
  73. silent-edg₃ = silent-silent-edges G
  74. q = φ /| o || o || edg₃
  75. silent-q : Silent q
  76. silent-q = silent-/| (silent-|| silent-o (silent-|| silent-o silent-edg₃))
  77. rx-edg₁ : edges G -[ lift (forward stop (node x)) ]-> edg₁
  78. rx-edg₁ = {! !}
  79. rx-edg₂ : edg₁ -[ {! !} ]-> edg₂
  80. rx-edg₂ = {! !}
  81. run-edg₃ : φ /| o || o || edg₂ -! [] !->* φ /| o || o || edg₃
  82. run-edg₃ = {! !}
  83. tx-batter : (n : Nat) ->
  84. if node n == node n
  85. then backward stop ! o
  86. else def (start x)
  87. -! lift (backward stop) !-> o
  88. tx-batter zero = tx-!
  89. tx-batter (suc n) = tx-batter n
  90. run : mainp x x -! stop :: [] !->* q
  91. run = (tx-/| (tx-!|
  92. (tx-def tx-!)
  93. (rx-|| (rx-def rx->) rx-edg₁)))
  94. >*>
  95. (tx-/| (tx-|! rx-o (tx-!| (tx-batter x) rx-edg₂)))
  96. >!>
  97. run-edg₃