Skip to content

Commit 4c20b63

Browse files
authored
fix inverse (#1316)
1 parent 5cb774d commit 4c20b63

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/core/inverse.ml

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,6 @@ let prod_graph : sym -> (sym * sym * sym * bool) list = fun s ->
9898
(** cached version of [prod_graph]. *)
9999
let prod_graph : sym -> (sym * sym * sym * bool) list = cache prod_graph
100100

101-
(** [inverse_prod s s'] returns [(s0,s1,s2,b)] if [s] has a rule of the form
102-
[s (s0 _ _) ↪ Π x:s1 _, s2 r] with [b=true] iff [x] occurs in [r], and
103-
either [s1] has a rule of the form [s1 (s3 ...) ↪ s' ...] or [s1 == s'].
104-
@raise [Not_found] otherwise. *)
105-
let inverse_prod : sym -> sym -> sym * sym * sym * bool = fun s s' ->
106-
match prod_graph s with
107-
| [] -> raise Not_found
108-
| [x] -> x
109-
| graph ->
110-
let f (_,s1,_,_) =
111-
try let _ = inverse_const s1 s' in true with Not_found -> false in
112-
try List.find f graph
113-
with Not_found -> List.find (fun (_,s1,_,_) -> s1 == s') graph
114-
115101
(** [inverse s v] tries to compute a term [u] such that [s(u)] reduces to [v].
116102
@raise [Not_found] otherwise. *)
117103
let rec inverse : sym -> term -> term = fun s v ->
@@ -120,22 +106,24 @@ let rec inverse : sym -> term -> term = fun s v ->
120106
| Symb s', [t] when s' == s -> t
121107
| Symb s', ts -> add_args (mk_Symb (inverse_const s s')) ts
122108
| Prod(a,b), _ ->
123-
let s0,s1,s2,occ =
124-
match get_args a with
125-
| Symb s', _ -> inverse_prod s s'
126-
| _ -> raise Not_found
127-
in
128-
let t1 = inverse s1 a in
129-
let t2 =
130-
let x, b = unbind b in
131-
let b = inverse s2 b in
132-
if occ then mk_Abst (a, bind_var x b) else b
109+
let x, b = unbind b in
110+
let f (s0,s1,s2,occ) =
111+
try
112+
let t1 = inverse s1 a in
113+
let t2 = inverse s2 b in
114+
let t2 = if occ then mk_Abst (a, bind_var x t2) else t2 in
115+
Some (add_args (mk_Symb s0) [t1;t2])
116+
with Not_found -> None
133117
in
134-
add_args (mk_Symb s0) [t1;t2]
118+
begin
119+
match List.find_map f (prod_graph s) with
120+
| None -> raise Not_found
121+
| Some t -> t
122+
end
135123
| _ -> raise Not_found
136124

137125
let inverse : sym -> term -> term = fun s v ->
138126
let t = inverse s v in let v' = mk_Appl(mk_Symb s,t) in
139127
if Eval.eq_modulo [] v' v then t
140-
else (if Logger.log_enabled() then log "%a ≢ %a@" term v' term v;
128+
else (if Logger.log_enabled() then log "%a ≢ %a" term v' term v;
141129
raise Not_found)

tests/OK/1313.lp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require open tests.OK.HOL tests.OK.Eq tests.OK.Epsilon tests.OK.Impred;
2+
3+
symbol test_KO : π ((ε) [ι] = (ε) [ι]);

tests/OK/Epsilon.lp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require open tests.OK.FOL tests.OK.HOL tests.OK.Impred;
2+
3+
symbol ε [a:Set] : (τ aProp) → τ a;
4+
symbol εᵢ [a:Set] (paProp) : π (∃ p) → π (pp));

tests/export_raw_dk.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ do
6060
# proofs
6161
why3*|tutorial|try|tautologies|rewrite*|remove|natproofs|have|generalize|foo|comment_in_qid|apply|anonymous|admit|change);;
6262
# "open"
63-
triangular|power-fact|postfix|perf_rw_*|not-eager|nonLeftLinear2|natural|Nat|lpparse2|logic|List|FOL|Eq|doc|Bool|arity_var|arity_diff|922|262_pair_ex_2|215|1141|Tactic|Option|String|HOL|Impred|PropExt|Classic|Comp|Pos|Z|1217|1151|B1|B2|C1|C2|C3);;
63+
triangular|power-fact|postfix|perf_rw_*|not-eager|nonLeftLinear2|natural|Nat|lpparse2|logic|List|FOL|Eq|doc|Bool|arity_var|arity_diff|922|262_pair_ex_2|215|1141|Tactic|Option|String|HOL|Impred|PropExt|Classic|Comp|Pos|Z|1217|1151|B1|B2|C1|C2|C3|Epsilon|1313);;
6464
# "inductive"
6565
strictly_positive_*|inductive|989|904|830|341);;
6666
# underscore in query

0 commit comments

Comments
 (0)