let rec apply_choice_std vi (xor_vars : int list) (std_ls : t_equal) : t_equal =

  (* remove bindings like n -> PInv(Var(m)) from std_ls if n is an xor variable
   *)

  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
          (* n is xor, so remove b and add m -> PInv(Var(n)) to to_add *)
          match valeur_elem m std_ls with
          | Var(mm) ->
              (* do not replace n by nn, nn is only used to test, if n is in
               * xor_vars *)

              remove_bindings tas ((mm,PInv(Var(n)))::to_add) tail
          | _       -> failwith "apply_choice_std: assumptions do not hold"
        else
          (* do not remove b *)
          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
          (* do not replace n by nn, nn is only used to test, if n is in
           * xor_vars *)

          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

  (* adds (n,t) to std_ls using add_elem for every (n,t) in the input
   *)

  let rec add_bindings (std_ls : t_equal) : t_equal -> t_equal = function
    | (n,t)::tail ->
        (try
          let (std_ls,_,_) =
            add_elem true(*false*) 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

  (* first remove the bindings that have to be changed *)
  let (std_ls, to_add) = remove_bindings [] [] std_ls in
  (* then add the changed bindings again *)
  add_bindings std_ls to_add