renamed match_result variants to be less confusing
This commit is contained in:
parent
2dc7624ede
commit
e996e578a8
4 changed files with 32 additions and 32 deletions
|
|
@ -15,11 +15,11 @@ let rec match_term t phi psi =
|
|||
| Relation (r1, ts1), Relation (r2, ts2) ->
|
||||
if r1 = r2 && List.length ts1 = List.length ts2 then
|
||||
List.map2 (Term.match_term t) ts1 ts2
|
||||
|> List.fold_left Term.merge_result None
|
||||
|> List.fold_left Term.merge_result NoneSubst
|
||||
else MatchErr
|
||||
| Equal (t1, s1), Equal (t2, s2) ->
|
||||
Term.(merge_result (match_term t t1 t2) (match_term t s1 s2))
|
||||
| Bottom, Bottom -> None
|
||||
| Bottom, Bottom -> NoneSubst
|
||||
| Neg phi, Neg psi -> match_term t phi psi
|
||||
| Conj (phi1, psi1), Conj (phi2, psi2) ->
|
||||
Term.merge_result (match_term t phi1 phi2) (match_term t psi1 psi2)
|
||||
|
|
|
|||
|
|
@ -58,38 +58,38 @@ let rec valid res a { children; label; formula } =
|
|||
valid res a left && valid res a right
|
||||
&&
|
||||
match Formula.match_term t right.formula phi with
|
||||
| All s' -> s = s'
|
||||
| Some s' -> s = s'
|
||||
| None -> true
|
||||
| AllSubst s' -> s = s'
|
||||
| SomeSubst s' -> s = s'
|
||||
| NoneSubst -> true
|
||||
| MatchErr -> false)
|
||||
| [ kid ], ForallI, Forall phi -> (
|
||||
valid res a kid
|
||||
&&
|
||||
match Formula.match_term (Var 0) phi kid.formula with
|
||||
| All (Free x) -> List.exists (Formula.occurs (Free x)) a |> not
|
||||
| All _ -> false
|
||||
| None -> true
|
||||
| Some _ | MatchErr -> false)
|
||||
| AllSubst (Free x) -> List.exists (Formula.occurs (Free x)) a |> not
|
||||
| AllSubst _ -> false
|
||||
| NoneSubst -> true
|
||||
| SomeSubst _ | MatchErr -> false)
|
||||
| [ ({ formula = Forall phi; _ } as kid) ], ForallE, psi -> (
|
||||
valid res a kid
|
||||
&&
|
||||
match Formula.match_term (Var 0) phi psi with
|
||||
| All _ -> true
|
||||
| None -> Formula.occurs (Var 0) phi |> not
|
||||
| Some _ | MatchErr -> false)
|
||||
| AllSubst _ -> true
|
||||
| NoneSubst -> Formula.occurs (Var 0) phi |> not
|
||||
| SomeSubst _ | MatchErr -> false)
|
||||
| [ kid ], ExistsI, Exists phi -> (
|
||||
valid res a kid
|
||||
&&
|
||||
match Formula.match_term (Var 0) phi kid.formula with
|
||||
| All _ -> true
|
||||
| None -> Formula.occurs (Var 0) phi |> not
|
||||
| Some _ | MatchErr -> false)
|
||||
| AllSubst _ -> true
|
||||
| NoneSubst -> Formula.occurs (Var 0) phi |> not
|
||||
| SomeSubst _ | MatchErr -> false)
|
||||
| [ ({ formula = Exists phi; _ } as kid) ], ExistsE, psi -> (
|
||||
valid res a kid
|
||||
&&
|
||||
match Formula.match_term (Var 0) phi psi with
|
||||
| All (Free x) -> List.exists (Formula.occurs (Free x)) a |> not
|
||||
| All _ -> false
|
||||
| None -> true
|
||||
| Some _ | MatchErr -> false)
|
||||
| AllSubst (Free x) -> List.exists (Formula.occurs (Free x)) a |> not
|
||||
| AllSubst _ -> false
|
||||
| NoneSubst -> true
|
||||
| SomeSubst _ | MatchErr -> false)
|
||||
| _ -> false
|
||||
|
|
|
|||
|
|
@ -6,28 +6,28 @@ type t =
|
|||
| Free of string
|
||||
| Function of string * t list
|
||||
|
||||
type match_result = All of t | Some of t | None | MatchErr
|
||||
type match_result = AllSubst of t | SomeSubst of t | NoneSubst | MatchErr
|
||||
|
||||
let merge_result m1 m2 =
|
||||
match (m1, m2) with
|
||||
| All t1, All t2 -> if t1 = t2 then All t1 else MatchErr
|
||||
| All t1, Some _ -> Some t1
|
||||
| Some _, All t2 -> Some t2
|
||||
| Some t1, Some t2 -> if t1 = t2 then Some t1 else MatchErr
|
||||
| None, _ -> m2
|
||||
| _, None -> m1
|
||||
| AllSubst t1, AllSubst t2 -> if t1 = t2 then AllSubst t1 else MatchErr
|
||||
| AllSubst t1, SomeSubst _ -> SomeSubst t1
|
||||
| SomeSubst _, AllSubst t2 -> SomeSubst t2
|
||||
| SomeSubst t1, SomeSubst t2 -> if t1 = t2 then SomeSubst t1 else MatchErr
|
||||
| NoneSubst, _ -> m2
|
||||
| _, NoneSubst -> m1
|
||||
| _ -> MatchErr
|
||||
|
||||
let rec match_term x t1 t2 =
|
||||
if x = t1 then if t1 = t2 then Some t2 else All t2
|
||||
if x = t1 then if t1 = t2 then SomeSubst t2 else AllSubst t2
|
||||
else
|
||||
match (t1, t2) with
|
||||
| Var v1, Var v2 -> if v1 = v2 then None else MatchErr
|
||||
| Const s1, Const s2 -> if s1 = s2 then None else MatchErr
|
||||
| Free s1, Free s2 -> if s1 = s2 then None else MatchErr
|
||||
| Var v1, Var v2 -> if v1 = v2 then NoneSubst else MatchErr
|
||||
| Const s1, Const s2 -> if s1 = s2 then NoneSubst else MatchErr
|
||||
| Free s1, Free s2 -> if s1 = s2 then NoneSubst else MatchErr
|
||||
| Function (f1, ts1), Function (f2, ts2) ->
|
||||
if f1 = f2 && List.(length ts1 = length ts2) then
|
||||
List.(map2 (match_term x) ts1 ts2 |> fold_left merge_result None)
|
||||
List.(map2 (match_term x) ts1 ts2 |> fold_left merge_result NoneSubst)
|
||||
else MatchErr
|
||||
| _ -> MatchErr
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ type t =
|
|||
| Free of string
|
||||
| Function of string * t list
|
||||
|
||||
type match_result = All of t | Some of t | None | MatchErr
|
||||
type match_result = AllSubst of t | SomeSubst of t | NoneSubst | MatchErr
|
||||
|
||||
val merge_result : match_result -> match_result -> match_result
|
||||
val match_term : t -> t -> t -> match_result
|
||||
|
|
|
|||
Loading…
Reference in a new issue