let rec apply_choice_std vi (xor_vars : int list) (std_ls : t_equal) : t_equal =
let rec remove_bindings tas to_add = function
| (n,PInv(Var(m)) as b)::tail ->
let nn = try rep vi n with Not_found -> n in
if List.mem nn xor_vars then
match valeur_elem m std_ls with
| Var(mm) ->
remove_bindings tas ((mm,PInv(Var(n)))::to_add) tail
| _ -> failwith "apply_choice_std: assumptions do not hold"
else
remove_bindings (b::tas) to_add tail
| (n,Var(m) as b)::tail ->
let nn = try rep vi n with Not_found -> n in
if List.mem nn xor_vars then
remove_bindings tas ((m,Var(n))::to_add) tail
else
remove_bindings (b::tas) to_add tail
| b::tail -> remove_bindings (b::tas) to_add tail
| [] -> (tas, to_add)
in
let rec add_bindings (std_ls : t_equal) : t_equal -> t_equal = function
| (n,t)::tail ->
(try
let (std_ls,_,_) =
add_elem true n t (std_ls,FreeVar(0),[])
in
add_bindings std_ls tail
with
| No_Solution -> failwith ("apply_choice_std: "^
"add_elem raised No_Solution, which must not happen\n"^
"Add var "^(Debugprinting.str_term_dbg !localtab (Var n))^
" with value "^(Debugprinting.str_term_dbg !localtab t)^" to subst \n"^
(Debugprinting.str_sub_dbg !localtab (std_ls,FreeVar(0),[]))
)
| NeedXorUnification(_,_,_) -> failwith ("apply_choice_std: "^
"add_elem raised NeedXorUnification, which must not happen")
| _ -> failwith ("apply_choice_std: "^
"add_elem raised an exception, which must not happen")
)
| [] -> std_ls
in
let (std_ls, to_add) = remove_bindings [] [] std_ls in
add_bindings std_ls to_add