Compare commits

..

8 Commits

Author SHA1 Message Date
69a4e8eb5c Add some helpers and rewrite code
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 17:43:16 -07:00
4fee16413a Define end-to-end path concatenation and prove one more case
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 17:34:50 -07:00
316e56f2bc Dip toes into creating end-to-end traces
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 15:27:46 -07:00
ab40a27e78 Formulate correctness of buildCfg using end-to-end traces
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 14:56:19 -07:00
f555947184 Promote traces through loop
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 14:38:07 -07:00
660f6594fd Allow promoting traces through graph composition
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 14:28:00 -07:00
fb32315f58 Allow traces to be promoted through graph overlaying
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-04-27 14:18:16 -07:00
037358308f Fix up Graph construction 2024-04-27 13:50:06 -07:00
3 changed files with 130 additions and 17 deletions

View File

@ -79,13 +79,19 @@ _↦_ g₁ g₂ = record
} }
loop : Graph Graph loop : Graph Graph
loop g = record loop g = record g
{ size = Graph.size g { edges = Graph.edges g List.++
; nodes = Graph.nodes g
; edges = Graph.edges g List.++
List.cartesianProduct (Graph.outputs g) (Graph.inputs g) List.cartesianProduct (Graph.outputs g) (Graph.inputs g)
; inputs = Graph.inputs g }
; outputs = Graph.outputs g
infixl 5 _skipto_
_skipto_ : Graph Graph Graph
_skipto_ g₁ g₂ = record (g₁ g₂)
{ edges = Graph.edges (g₁ g₂) List.++
(List.cartesianProduct (Graph.inputs g₁ ↑ˡⁱ Graph.size g₂)
(Graph.size g₁ ↑ʳⁱ Graph.inputs g₂))
; inputs = Graph.inputs g₁ ↑ˡⁱ Graph.size g₂
; outputs = Graph.size g₁ ↑ʳⁱ Graph.inputs g₂
} }
_[_] : (g : Graph) Graph.Index g List BasicStmt _[_] : (g : Graph) Graph.Index g List BasicStmt
@ -104,4 +110,4 @@ buildCfg : Stmt → Graph
buildCfg bs₁ = singleton (bs₁ []) buildCfg bs₁ = singleton (bs₁ [])
buildCfg (s₁ then s₂) = buildCfg s₁ buildCfg s₂ buildCfg (s₁ then s₂) = buildCfg s₁ buildCfg s₂
buildCfg (if _ then s₁ else s₂) = singleton [] (buildCfg s₁ buildCfg s₂) singleton [] buildCfg (if _ then s₁ else s₂) = singleton [] (buildCfg s₁ buildCfg s₂) singleton []
buildCfg (while _ repeat s) = loop (buildCfg s singleton []) buildCfg (while _ repeat s) = (loop (singleton [] buildCfg s)) skipto (singleton [])

View File

@ -6,10 +6,15 @@ open import Language.Graphs
open import Language.Traces open import Language.Traces
open import Data.Fin as Fin using (zero) open import Data.Fin as Fin using (zero)
open import Data.List using (_∷_; []) open import Data.List using (List; _∷_; [])
open import Data.Product using (Σ; _,_) open import Data.List.Relation.Unary.Any using (here)
open import Data.List.Membership.Propositional.Properties as ListMemProp using ()
open import Data.Product using (Σ; _,_; _×_)
open import Data.Vec.Properties using (lookup-++ˡ; ++-identityʳ; lookup-++ʳ)
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; sym)
open import Utils using (x∈xs⇒fx∈fxs; ∈-cartesianProduct)
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl)
buildCfg-input : (s : Stmt) let g = buildCfg s in Σ (Graph.Index g) (λ idx Graph.inputs g idx []) buildCfg-input : (s : Stmt) let g = buildCfg s in Σ (Graph.Index g) (λ idx Graph.inputs g idx [])
buildCfg-input bs₁ = (zero , refl) buildCfg-input bs₁ = (zero , refl)
@ -26,3 +31,95 @@ buildCfg-output (s₁ then s₂)
buildCfg-output (if _ then s₁ else s₂) = (_ , refl) buildCfg-output (if _ then s₁ else s₂) = (_ , refl)
buildCfg-output (while _ repeat s) buildCfg-output (while _ repeat s)
with (idx , p) buildCfg-output s rewrite p = (_ , refl) with (idx , p) buildCfg-output s rewrite p = (_ , refl)
Trace-∙ˡ : (g₁ g₂ : Graph) {idx₁ idx₂ : Graph.Index g₁} {ρ₁ ρ₂ : Env}
Trace {g₁} idx₁ idx₂ ρ₁ ρ₂
Trace {g₁ g₂} (idx₁ Fin.↑ˡ Graph.size g₂) (idx₂ Fin.↑ˡ Graph.size g₂) ρ₁ ρ₂
Trace-∙ˡ g₁ g₂ {idx₁} {idx₁} (Trace-single ρ₁⇒ρ₂)
rewrite sym (lookup-++ˡ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-single ρ₁⇒ρ₂
Trace-∙ˡ g₁ g₂ {idx₁} (Trace-edge ρ₁⇒ρ idx₁→idx tr')
rewrite sym (lookup-++ˡ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-edge ρ₁⇒ρ (ListMemProp.∈-++⁺ˡ (x∈xs⇒fx∈fxs (_↑ˡ Graph.size g₂) idx₁→idx))
(Trace-∙ˡ g₁ g₂ tr')
Trace-∙ʳ : (g₁ g₂ : Graph) {idx₁ idx₂ : Graph.Index g₂} {ρ₁ ρ₂ : Env}
Trace {g₂} idx₁ idx₂ ρ₁ ρ₂
Trace {g₁ g₂} (Graph.size g₁ Fin.↑ʳ idx₁) (Graph.size g₁ Fin.↑ʳ idx₂) ρ₁ ρ₂
Trace-∙ʳ g₁ g₂ {idx₁} {idx₁} (Trace-single ρ₁⇒ρ₂)
rewrite sym (lookup-++ʳ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-single ρ₁⇒ρ₂
Trace-∙ʳ g₁ g₂ {idx₁} (Trace-edge ρ₁⇒ρ idx₁→idx tr')
rewrite sym (lookup-++ʳ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-edge ρ₁⇒ρ (ListMemProp.∈-++⁺ʳ _ (x∈xs⇒fx∈fxs (Graph.size g₁ ↑ʳ_) idx₁→idx))
(Trace-∙ʳ g₁ g₂ tr')
Trace-↦ˡ : (g₁ g₂ : Graph) {idx₁ idx₂ : Graph.Index g₁} {ρ₁ ρ₂ : Env}
Trace {g₁} idx₁ idx₂ ρ₁ ρ₂
Trace {g₁ g₂} (idx₁ Fin.↑ˡ Graph.size g₂) (idx₂ Fin.↑ˡ Graph.size g₂) ρ₁ ρ₂
Trace-↦ˡ g₁ g₂ {idx₁} {idx₁} (Trace-single ρ₁⇒ρ₂)
rewrite sym (lookup-++ˡ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-single ρ₁⇒ρ₂
Trace-↦ˡ g₁ g₂ {idx₁} (Trace-edge ρ₁⇒ρ idx₁→idx tr')
rewrite sym (lookup-++ˡ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-edge ρ₁⇒ρ (ListMemProp.∈-++⁺ˡ (x∈xs⇒fx∈fxs (_↑ˡ Graph.size g₂) idx₁→idx))
(Trace-↦ˡ g₁ g₂ tr')
Trace-↦ʳ : (g₁ g₂ : Graph) {idx₁ idx₂ : Graph.Index g₂} {ρ₁ ρ₂ : Env}
Trace {g₂} idx₁ idx₂ ρ₁ ρ₂
Trace {g₁ g₂} (Graph.size g₁ Fin.↑ʳ idx₁) (Graph.size g₁ Fin.↑ʳ idx₂) ρ₁ ρ₂
Trace-↦ʳ g₁ g₂ {idx₁} {idx₁} (Trace-single ρ₁⇒ρ₂)
rewrite sym (lookup-++ʳ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-single ρ₁⇒ρ₂
Trace-↦ʳ g₁ g₂ {idx₁} (Trace-edge ρ₁⇒ρ idx₁→idx tr')
rewrite sym (lookup-++ʳ (Graph.nodes g₁) (Graph.nodes g₂) idx₁) =
Trace-edge ρ₁⇒ρ (ListMemProp.∈-++⁺ʳ (Graph.edges g₁ ↑ˡᵉ Graph.size g₂)
(ListMemProp.∈-++⁺ˡ (x∈xs⇒fx∈fxs (Graph.size g₁ ↑ʳ_) idx₁→idx)))
(Trace-↦ʳ g₁ g₂ tr')
Trace-loop : (g₁ : Graph) {idx₁ idx₂ : Graph.Index g₁} {ρ₁ ρ₂ : Env}
Trace {g₁} idx₁ idx₂ ρ₁ ρ₂ Trace {loop g₁} idx₁ idx₂ ρ₁ ρ₂
Trace-loop g₁ {idx₁} {idx₁} (Trace-single ρ₁⇒ρ₂) = Trace-single ρ₁⇒ρ₂
Trace-loop g₁ {idx₁} (Trace-edge ρ₁⇒ρ idx₁→idx tr') =
Trace-edge ρ₁⇒ρ (ListMemProp.∈-++⁺ˡ idx₁→idx) (Trace-loop g₁ tr')
_++_ : {g₁ g₂ : Graph} {ρ₁ ρ₂ ρ₃ : Env}
EndToEndTrace {g₁} ρ₁ ρ₂ EndToEndTrace {g₂} ρ₂ ρ₃
EndToEndTrace {g₁ g₂} ρ₁ ρ₃
_++_ {g₁} {g₂} etr₁ etr₂
= record
{ idx₁ = EndToEndTrace.idx₁ etr₁ Fin.↑ˡ Graph.size g₂
; idx₁∈inputs = x∈xs⇒fx∈fxs (Fin._↑ˡ Graph.size g₂) (EndToEndTrace.idx₁∈inputs etr₁)
; idx₂ = Graph.size g₁ Fin.↑ʳ EndToEndTrace.idx₂ etr₂
; idx₂∈outputs = x∈xs⇒fx∈fxs (Graph.size g₁ Fin.↑ʳ_) (EndToEndTrace.idx₂∈outputs etr₂)
; trace =
let
o∈tr₁ = x∈xs⇒fx∈fxs (Fin._↑ˡ Graph.size g₂) (EndToEndTrace.idx₂∈outputs etr₁)
i∈tr₂ = x∈xs⇒fx∈fxs (Graph.size g₁ Fin.↑ʳ_) (EndToEndTrace.idx₁∈inputs etr₂)
oi∈es = ListMemProp.∈-++⁺ʳ (Graph.edges g₁ ↑ˡᵉ Graph.size g₂)
(ListMemProp.∈-++⁺ʳ (Graph.size g₁ ↑ʳᵉ Graph.edges g₂)
(∈-cartesianProduct o∈tr₁ i∈tr₂))
in
(Trace-↦ˡ g₁ g₂ (EndToEndTrace.trace etr₁)) ++⟨ oi∈es
(Trace-↦ʳ g₁ g₂ (EndToEndTrace.trace etr₂))
}
Trace-singleton : {bss : List BasicStmt} {ρ₁ ρ₂ : Env}
ρ₁ , bss ⇒ᵇˢ ρ₂ EndToEndTrace {singleton bss} ρ₁ ρ₂
Trace-singleton ρ₁⇒ρ₂ = record
{ idx₁ = zero
; idx₁∈inputs = here refl
; idx₂ = zero
; idx₂∈outputs = here refl
; trace = Trace-single ρ₁⇒ρ₂
}
Trace-singleton[] : (ρ : Env) EndToEndTrace {singleton []} ρ ρ
Trace-singleton[] env = Trace-singleton []
buildCfg-sufficient : {s : Stmt} {ρ₁ ρ₂ : Env} ρ₁ , s ⇒ˢ ρ₂
EndToEndTrace {buildCfg s} ρ₁ ρ₂
buildCfg-sufficient (⇒ˢ-⟨⟩ ρ₁ ρ₂ bs ρ₁,bs⇒ρ) =
Trace-singleton (ρ₁,bs⇒ρ [])
buildCfg-sufficient (⇒ˢ-then ρ₁ ρ₂ ρ₃ s₁ s₂ ρ₁,s₁⇒ρ ρ₂,s₂⇒ρ) =
buildCfg-sufficient ρ₁,s₁⇒ρ ++ buildCfg-sufficient ρ₂,s₂⇒ρ

View File

@ -1,24 +1,34 @@
module Language.Traces where module Language.Traces where
open import Language.Base public open import Language.Base
open import Language.Semantics public open import Language.Semantics using (Env; _,_⇒ᵇˢ_)
open import Language.Graphs public open import Language.Graphs
open import Data.Product using (_,_) open import Data.Product using (_,_)
open import Data.List.Membership.Propositional as MemProp using () open import Data.List.Membership.Propositional using (_∈_)
module _ {g : Graph} where module _ {g : Graph} where
open Graph g using (Index; edges) open Graph g using (Index; edges; inputs; outputs)
data Trace : Index Index Env Env Set where data Trace : Index Index Env Env Set where
Trace-single : {ρ₁ ρ₂ : Env} {idx : Index} Trace-single : {ρ₁ ρ₂ : Env} {idx : Index}
ρ₁ , (g [ idx ]) ⇒ᵇˢ ρ₂ Trace idx idx ρ₁ ρ₂ ρ₁ , (g [ idx ]) ⇒ᵇˢ ρ₂ Trace idx idx ρ₁ ρ₂
Trace-edge : {ρ₁ ρ₂ ρ₃ : Env} {idx₁ idx₂ idx₃ : Index} Trace-edge : {ρ₁ ρ₂ ρ₃ : Env} {idx₁ idx₂ idx₃ : Index}
ρ₁ , (g [ idx₁ ]) ⇒ᵇˢ ρ₂ (idx₁ , idx₂) MemProp. edges ρ₁ , (g [ idx₁ ]) ⇒ᵇˢ ρ₂ (idx₁ , idx₂) edges
Trace idx₂ idx₃ ρ₂ ρ₃ Trace idx₁ idx₃ ρ₁ ρ₃ Trace idx₂ idx₃ ρ₂ ρ₃ Trace idx₁ idx₃ ρ₁ ρ₃
_++⟨_⟩_ : {idx₁ idx₂ idx₃ idx₄ : Index} {ρ₁ ρ₂ ρ₃ : Env} _++⟨_⟩_ : {idx₁ idx₂ idx₃ idx₄ : Index} {ρ₁ ρ₂ ρ₃ : Env}
Trace idx₁ idx₂ ρ₁ ρ₂ (idx₂ , idx₃) MemProp. edges Trace idx₁ idx₂ ρ₁ ρ₂ (idx₂ , idx₃) edges
Trace idx₃ idx₄ ρ₂ ρ₃ Trace idx₁ idx₄ ρ₁ ρ₃ Trace idx₃ idx₄ ρ₂ ρ₃ Trace idx₁ idx₄ ρ₁ ρ₃
_++⟨_⟩_ (Trace-single ρ₁⇒ρ₂) idx₂→idx₃ tr = Trace-edge ρ₁⇒ρ₂ idx₂→idx₃ tr _++⟨_⟩_ (Trace-single ρ₁⇒ρ₂) idx₂→idx₃ tr = Trace-edge ρ₁⇒ρ₂ idx₂→idx₃ tr
_++⟨_⟩_ (Trace-edge ρ₁⇒ρ₂ idx₁→idx' tr') idx₂→idx₃ tr = Trace-edge ρ₁⇒ρ₂ idx₁→idx' (tr' ++⟨ idx₂→idx₃ tr) _++⟨_⟩_ (Trace-edge ρ₁⇒ρ₂ idx₁→idx' tr') idx₂→idx₃ tr = Trace-edge ρ₁⇒ρ₂ idx₁→idx' (tr' ++⟨ idx₂→idx₃ tr)
record EndToEndTrace (ρ₁ ρ₂ : Env) : Set where
field
idx₁ : Index
idx₁∈inputs : idx₁ inputs
idx₂ : Index
idx₂∈outputs : idx₂ outputs
trace : Trace idx₁ idx₂ ρ₁ ρ₂