Skip to content

Instantly share code, notes, and snippets.

@clayrat
Created February 23, 2026 14:38
Show Gist options
  • Select an option

  • Save clayrat/85cc967dccb3c234901136823b0ae139 to your computer and use it in GitHub Desktop.

Select an option

Save clayrat/85cc967dccb3c234901136823b0ae139 to your computer and use it in GitHub Desktop.
GOI-unification
module GOI where
open import Prelude
open import Data.Nat
open import Data.List renaming (_++_ to _++β‚—_)
open import Data.List.Correspondences.Binary.Prefix
open import Data.Fin.Inductive
open import Data.Vec.Inductive
open import Data.Vec.Inductive.Operations as Vec
open import Data.Star
open import Data.Sum
-- from Honsell, Lenisa, Scagnetto, [2024] "Two Views on Unification: Terms as Strategies"
record Signature : 𝒰₁ where
field
Symbol : 𝒰
arity : Symbol β†’ β„•
module Theory (Var : 𝒰) ⦃ d : is-discrete Var ⦄ (Sig : Signature) where
open Signature Sig
-- Definition 1(i): Terms TΞ£
data Term : 𝒰 where
var : Var β†’ Term
con : (f : Symbol)
β†’ Vec Term (arity f)
β†’ Term
-- Definition 1(iii-iv): Paths and Occurrences OΞ£
-- A Step is a constructor and the index of the subtree
record Step : 𝒰 where
constructor step
field
f : Symbol
k : Fin (arity f)
OPath : 𝒰
OPath = List Step
record Occurrence : 𝒰 where
constructor _o[_]
field
opath : OPath
ovar : Var
open Occurrence public
-- Helper: Checking if an occurrence is in a term
data _βˆˆβ‚œ_ : Occurrence β†’ Term β†’ 𝒰 where
here : {Ξ± : Var}
β†’ ([] o[ Ξ± ]) βˆˆβ‚œ var Ξ±
there : {f : Symbol} {args : Vec Term (arity f)} {p : OPath} {Ξ± : Var} {i : Fin (arity f)}
β†’ ((p o[ Ξ± ]) βˆˆβ‚œ Vec.lookup args i)
β†’ ((step f i ∷ p) o[ Ξ± ]) βˆˆβ‚œ con f args
-- Definition 4: From Terms to Strategies R(Οƒ)
-- R(Οƒ) is the set of pairs of different occurrences of the same variable
Strategy : 𝒰₁
Strategy = Occurrence β†’ Occurrence β†’ 𝒰
R : Term β†’ Strategy
R Οƒ o₁ oβ‚‚ = (o₁ βˆˆβ‚œ Οƒ) Γ— (oβ‚‚ βˆˆβ‚œ Οƒ) Γ— (Occurrence.ovar o₁ = Occurrence.ovar oβ‚‚) Γ— (o₁ β‰  oβ‚‚)
-- Definition 12: Occ-substitution M
-- An occ-substitution M is induced by M_Var : Variable β†’ Occurrence
-- It maps u[Ξ±] to (u ++ path(M_Var Ξ±))[variable(M_Var Ξ±)]
OccSubst : 𝒰
OccSubst = Var β†’ Occurrence
-- TODO sketchy
ap-subst : OccSubst β†’ Occurrence β†’ Occurrence
ap-subst M (u o[ Ξ± ]) with M Ξ±
... | (w o[ Ξ² ]) = (u ++β‚— w) o[ Ξ² ]
OccUnifier : OccSubst β†’ Occurrence β†’ Occurrence β†’ 𝒰
OccUnifier M u v = ap-subst M u = ap-subst M v
{-
lemma13-to : {M : OccSubst} {u v : Occurrence}
β†’ OccUnifier M u v
β†’ Prefix (u .opath) (v .opath) ⊎ Prefix (v .opath) (u .opath)
lemma13-to {u = u o[ Ξ± ]} {v = v o[ Ξ² ]} e =
{!!}
-}
-- Definition 14(ii): Inclusion up to substitution (βŠ†Μ‚)
-- S₁ βŠ†Μ‚ Sβ‚‚ if every pair in S₁ is an instance of a pair in Sβ‚‚
_βŠ†Μ‚_ : Strategy β†’ Strategy β†’ 𝒰
S₁ βŠ†Μ‚ Sβ‚‚ =
βˆ€ {u₁ v₁}
β†’ S₁ u₁ v₁
β†’ Ξ£[ uβ‚‚ κž‰ Occurrence ]
Ξ£[ vβ‚‚ κž‰ Occurrence ]
Ξ£[ M κž‰ OccSubst ]
(Sβ‚‚ uβ‚‚ vβ‚‚ Γ— OccUnifier M u₁ uβ‚‚ Γ— OccUnifier M v₁ vβ‚‚)
-- Definition 14(i): Composition up to substitution (β¨ΎΜ‚)
_β¨ΎΜ‚_ : Strategy β†’ Strategy β†’ Strategy
(S₁ β¨ΎΜ‚ Sβ‚‚) u'' v'' =
Ξ£[ u₁ κž‰ Occurrence ]
Ξ£[ v₁ κž‰ Occurrence ]
Ξ£[ uβ‚‚ κž‰ Occurrence ]
Ξ£[ vβ‚‚ κž‰ Occurrence ]
Ξ£[ M κž‰ OccSubst ]
(S₁ u₁ v₁ Γ— Sβ‚‚ uβ‚‚ vβ‚‚ Γ— OccUnifier M v₁ uβ‚‚ Γ— OccUnifier M u'' u₁ Γ— OccUnifier M v'' vβ‚‚)
-- Definition 16: GoI-unification
-- Οƒ and Ο„ GoI-unify if their variable strategies satisfy the execution formula
GoI-unify : Term β†’ Term β†’ 𝒰
GoI-unify Οƒ Ο„ =
(R Οƒ βŠ†Μ‚ (R Ο„ β¨ΎΜ‚ (Star (R Οƒ β¨ΎΜ‚ R Ο„))))
Γ— (R Ο„ βŠ†Μ‚ (R Οƒ β¨ΎΜ‚ (Star (R Ο„ β¨ΎΜ‚ R Οƒ))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment