@@ -98,20 +98,6 @@ let prod_graph : sym -> (sym * sym * sym * bool) list = fun s ->
9898(* * cached version of [prod_graph]. *)
9999let 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. *)
117103let 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
137125let 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 )
0 commit comments