Theory IsaSAT_Setup0_LLVM

theory IsaSAT_Setup0_LLVM
  imports IsaSAT_Watch_List_LLVM IsaSAT_Lookup_Conflict_LLVM
    More_Sepref.WB_More_Refinement IsaSAT_Clauses_LLVM LBD_LLVM
    IsaSAT_Options_LLVM IsaSAT_VMTF_Setup_LLVM
    IsaSAT_Arena_Sorting_LLVM
    IsaSAT_Rephase_LLVM
    IsaSAT_EMA_LLVM
    IsaSAT_Stats_LLVM
    IsaSAT_VDom_LLVM
    IsaSAT_Bump_Heuristics_State_LLVM
    Isabelle_LLVM.LLVM_DS_Block_Alloc
    Tuple17_LLVM
begin

hide_const (open) NEMonad.ASSERT NEMonad.RETURN

text 
This is the setup for accessing and modifying the state. The construction is kept generic 
(even if still targetting only our state). There is a lot of copy-paste that would be nice to automate
at some point.


We define 3 sort of operations:

   extracting an element, replacing it by an default element. Modifies the state. The name starts 
with text‹exctr›

   reinserting an element, freeing the current one. Modifies the state. The name starts with
 text‹update›

   in-place reading a value, possibly with pure parameters. Does not modify the state. The name
starts with text‹read›



type_synonym occs_assn = (64,(64 word),64)array_array_list

abbreviation occs_assn  aal_assn' TYPE(64) TYPE(64) sint64_nat_assn

type_synonym twl_st_wll_trail_fast2 =
  (trail_pol_fast_assn, arena_assn, option_lookup_clause_assn,
    64 word, watched_wl_uint32, bump_heuristics_assn,
    32 word, cach_refinement_l_assn, lbd_assn, out_learned_assn,
    isasat_stats_assn, heur_assn,
   aivdom_assn, (64 word × 64 word × 64 word × 64 word × 64 word),
  opts_assn, arena_assn, occs_assn) tuple17

definition isasat_bounded_assn :: isasat  twl_st_wll_trail_fast2  assn where
isasat_bounded_assn = tuple17_assn
  trail_pol_fast_assn arena_fast_assn
  conflict_option_rel_assn
  sint64_nat_assn
  watchlist_fast_assn
  heuristic_bump_assn
  uint32_nat_assn
  cach_refinement_l_assn
  lbd_assn
  out_learned_assn
  isasat_stats_assn
  heuristic_assn
  aivdom_assn
  lcount_assn
  opts_assn
  arena_fast_assn
  occs_assn

sepref_register mop_arena_length

type_synonym twl_st_wll_trail_fast =
  trail_pol_fast_assn × arena_assn × option_lookup_clause_assn ×
    64 word × watched_wl_uint32 × bump_heuristics_assn ×
    32 word × cach_refinement_l_assn × lbd_assn × out_learned_assn × isasat_stats ×
    heur_assn ×
   aivdom_assn × (64 word × 64 word × 64 word × 64 word × 64 word) ×
  opts_assn × arena_assn × occs_assn


text The following constants are not useful for the initialisation for the solver, but only as temporary replacement
  for values in state.
definition bottom_trail :: trail_pol where
  bottom_trail = do {
     let M0 = [] in
     let cs = [] in
     let M = replicate 0 UNSET in
     let M' = replicate 0 0 in
     let M'' = replicate 0 1 in
    ((M0, M, M', M'', 0, cs, 0))
}

definition extract_trail_wl_heur where
  extract_trail_wl_heur = isasat_state_ops.remove_a bottom_trail

sepref_def bottom_trail_code
  is uncurry0 (RETURN bottom_trail)
  :: unit_assnk a trail_pol_fast_assn
  unfolding bottom_trail_def trail_pol_fast_assn_def
  apply (rewrite in let _ =  in _ annotate_assn[where A=arl64_assn unat_lit_assn])
  apply (rewrite in let _ =  in _ al_fold_custom_empty[where 'l=64])
  apply (rewrite in let _ = _; _ =  in _ al_fold_custom_empty[where 'l=64])
  apply (rewrite in let _ = _; _ =  in _ annotate_assn[where A=arl64_assn uint32_nat_assn])

  apply (rewrite in let _ = _;_ =  in _ annotate_assn[where A=larray64_assn (tri_bool_assn)])
  apply (rewrite in let _ = _;_ = _;_ =  in _ annotate_assn[where A=larray64_assn uint32_nat_assn])
  apply (rewrite in let _ = _ in _ larray_fold_custom_replicate)
  apply (rewrite in let _ = _ in _ larray_fold_custom_replicate)
  apply (rewrite in let _ = _ in _ larray_fold_custom_replicate)
  apply (rewrite at (_, , _) unat_const_fold[where 'a=32])
  apply (rewrite at (_, _, _, _ , ) snat_const_fold[where 'a=64])
  apply (rewrite at (op_larray_custom_replicate _ ) unat_const_fold[where 'a=32])
  apply (annot_snat_const TYPE(64))
  supply [[goals_limit = 1]]
  by sepref

definition bottom_arena :: arena where
  bottom_arena = []

definition extract_arena_wl_heur where
  extract_arena_wl_heur = isasat_state_ops.remove_b bottom_arena

sepref_def bottom_arena_code
  is uncurry0 (RETURN bottom_arena)
  :: unit_assnk a arena_fast_assn
  unfolding bottom_arena_def al_fold_custom_empty[where 'l=64]
  by sepref

definition bottom_conflict :: conflict_option_rel where
  bottom_conflict = (True, 0, replicate 0 NOTIN)

definition extract_conflict_wl_heur where
  extract_conflict_wl_heur = isasat_state_ops.remove_c bottom_conflict

sepref_def bottom_conflict_code
  is uncurry0 (RETURN bottom_conflict)
  :: unit_assnk a conflict_option_rel_assn
  unfolding bottom_conflict_def
    conflict_option_rel_assn_def lookup_clause_rel_assn_def array_fold_custom_replicate
  apply (rewrite at (_, , _) unat_const_fold[where 'a=32])
  apply (annot_snat_const TYPE(32))
  by sepref

definition bottom_decision_level :: nat where
  bottom_decision_level = 0

definition extract_literals_to_update_wl_heur :: _  _ where
  extract_literals_to_update_wl_heur = isasat_state_ops.remove_d bottom_decision_level

sepref_def bottom_decision_level_code
  is uncurry0 (RETURN bottom_decision_level)
  :: unit_assnk a sint64_nat_assn
  unfolding bottom_decision_level_def
  apply (annot_snat_const TYPE(64))
  by sepref

definition bottom_watchlist :: (nat) watcher list list where
  bottom_watchlist = replicate 0 []

definition extract_watchlist_wl_heur where
  extract_watchlist_wl_heur = isasat_state_ops.remove_e bottom_watchlist

sepref_def bottom_watchlist_code
  is uncurry0 (RETURN bottom_watchlist)
  :: unit_assnk a watchlist_fast_assn
  unfolding bottom_watchlist_def aal_fold_custom_empty[where 'l=64 and 'll=64]
  apply (annot_snat_const TYPE(64))
  by sepref

definition bottom_atom where
  bottom_atom = 0
lemma [sepref_fr_rules]: (uncurry0 (Mreturn 0), uncurry0 (RETURN bottom_atom))  unit_assnk a atom_assn
  unfolding bottom_atom_def
  apply sepref_to_hoare
  apply vcg
  apply (auto simp: atom_rel_def unat_rel_def unat.rel_def br_def entails_def ENTAILS_def)
  by (smt (verit, best) pure_true_conv rel_simps(51) sep.add_0)

definition bottom_bump :: bump_heuristics where
  bottom_bump = Tuple4 empty_acids bottom_vmtf False bottom_atms_hash

definition extract_vmtf_wl_heur where
  extract_vmtf_wl_heur = isasat_state_ops.remove_f bottom_bump

sepref_def bottom_bump_code
  is uncurry0 (RETURN bottom_bump)
  :: unit_assnk a heuristic_bump_assn
  unfolding bottom_bump_def
  by sepref

definition bottom_clvls :: nat where
  bottom_clvls = 0

definition extract_clvls_wl_heur where
  extract_clvls_wl_heur = isasat_state_ops.remove_g bottom_clvls

sepref_def bottom_clvls_code
  is uncurry0 (RETURN bottom_clvls)
  :: unit_assnk a uint32_nat_assn
  unfolding bottom_clvls_def
  apply (annot_unat_const TYPE(32))
  by sepref

definition bottom_ccach :: minimize_status list × nat list where
  bottom_ccach = (replicate 0 SEEN_UNKNOWN, [])

definition extract_ccach_wl_heur where
  extract_ccach_wl_heur = isasat_state_ops.remove_h bottom_ccach

sepref_def bottom_ccach_code
  is uncurry0 (RETURN bottom_ccach)
  :: unit_assnk a cach_refinement_l_assn
  unfolding bottom_ccach_def cach_refinement_l_assn_def array_fold_custom_replicate
  apply (rewrite at (_, ) al_fold_custom_empty[where 'l=64])
  apply (rewrite at (, _) annotate_assn[where A = IICF_Array.array_assn minimize_status_assn])
  apply (annot_snat_const TYPE(32))
  by sepref

definition extract_lbd_wl_heur where
  extract_lbd_wl_heur = isasat_state_ops.remove_i empty_lbd

definition bottom_outl :: out_learned where
  bottom_outl = []

definition extract_outl_wl_heur where
  extract_outl_wl_heur = isasat_state_ops.remove_j bottom_outl

sepref_def bottom_outl_code
  is uncurry0 (RETURN bottom_outl)
  :: unit_assnk a out_learned_assn
  unfolding bottom_outl_def cach_refinement_l_assn_def array_fold_custom_replicate
  apply (rewrite at () al_fold_custom_empty[where 'l=64])
  by sepref

definition bottom_stats :: isasat_stats where
  bottom_stats = empty_stats

definition extract_stats_wl_heur where
  extract_stats_wl_heur = isasat_state_ops.remove_k bottom_stats

sepref_def bottom_stats_code
  is uncurry0 (RETURN bottom_stats)
  :: unit_assnk a isasat_stats_assn
  unfolding bottom_stats_def
  by sepref

definition bottom_heur_int :: restart_heuristics where
  bottom_heur_int = (
  let φ = replicate 0 False in
  let fema = ema_init (0) in
  let sema = ema_init (0) in
  let other_fema = ema_init (0) in
  let other_sema = ema_init (0) in
  let ccount = restart_info_init in
  let n = 0  in
  (fema, sema, ccount, 0, (φ, 0, replicate n False, 0, replicate n False, 10000, 1000, 1), reluctant_init, False, replicate 0 False, (0, 0, 0), other_fema, other_sema))

sepref_def bottom_heur_int_code
  is uncurry0 (RETURN bottom_heur_int)
  :: unit_assnk a heuristic_int_assn
  supply [[goals_limit=1]]
  unfolding bottom_heur_int_def heuristic_int_assn_def phase_heur_assn_def
  apply (rewrite in (replicate _ False, _) annotate_assn[where A=phase_saver'_assn])
  apply (rewrite in (replicate _ False, _) array_fold_custom_replicate)
  apply (rewrite in (_, _, , _) array_fold_custom_replicate)
  apply (rewrite in let _ = in _ annotate_assn[where A=phase_saver_assn])
  unfolding larray_fold_custom_replicate
  apply (annot_snat_const TYPE(64))
  by sepref

definition bottom_heur :: _ where
  bottom_heur = Restart_Heuristics (bottom_heur_int)

definition extract_heur_wl_heur where
  extract_heur_wl_heur = isasat_state_ops.remove_l bottom_heur

sepref_def bottom_heur_code
  is uncurry0 (RETURN bottom_heur)
  :: unit_assnk a heuristic_assn
  supply [[goals_limit=1]]
  unfolding bottom_heur_def
  by sepref

definition bottom_vdom :: _ where
  bottom_vdom = AIvdom_init [] [] []

definition extract_vdom_wl_heur where
  extract_vdom_wl_heur = isasat_state_ops.remove_m bottom_vdom

sepref_def bottom_vdom_code
  is uncurry0 (RETURN bottom_vdom)
  :: unit_assnk a aivdom_assn
  supply [[goals_limit=1]]
  unfolding bottom_vdom_def
  unfolding al_fold_custom_empty[where 'l=64]
  by sepref

definition bottom_lcount :: clss_size where
  bottom_lcount = (0, 0, 0, 0, 0)

definition extract_lcount_wl_heur where
  extract_lcount_wl_heur = isasat_state_ops.remove_n bottom_lcount

sepref_def bottom_lcount_code
  is uncurry0 (RETURN bottom_lcount)
  :: unit_assnk a lcount_assn
  supply [[goals_limit=1]]
  unfolding bottom_lcount_def lcount_assn_def
  unfolding al_fold_custom_empty[where 'l=64]
  apply (annot_unat_const TYPE(64))
  by sepref

definition bottom_opts :: opts where
  bottom_opts = IsaOptions False False False 0 0 0 0 0 0 0 True

definition extract_opts_wl_heur where
  extract_opts_wl_heur = isasat_state_ops.remove_o bottom_opts

sepref_def bottom_opts_code
  is uncurry0 (RETURN bottom_opts)
  :: unit_assnk a opts_assn
  supply [[goals_limit=1]]
  unfolding bottom_opts_def
  apply (annot_snat_const TYPE(64))
  by sepref

definition bottom_old_arena :: arena where
  bottom_old_arena = []

definition extract_old_arena_wl_heur where
  extract_old_arena_wl_heur = isasat_state_ops.remove_p bottom_old_arena

sepref_def bottom_old_arena_code
  is uncurry0 (RETURN bottom_old_arena)
  :: unit_assnk a arena_fast_assn
  supply [[goals_limit=1]]
  unfolding bottom_old_arena_def  al_fold_custom_empty[where 'l=64]
  by sepref

schematic_goal free_trail_pol_fast_assn[sepref_frame_free_rules]: MK_FREE trail_pol_fast_assn ?a
    unfolding trail_pol_fast_assn_def
    by synthesize_free

sepref_def free_trail_pol_fast
  is mop_free
  :: trail_pol_fast_assnd a unit_assn
  by sepref

lemma free_trail_pol_fast_assn2: MK_FREE trail_pol_fast_assn free_trail_pol_fast
  unfolding free_trail_pol_fast_def
  by (rule back_subst[of MK_FREE trail_pol_fast_assn, OF free_trail_pol_fast_assn])
    (auto intro!: ext)
 
schematic_goal free_arena_fast_assn[sepref_frame_free_rules]: MK_FREE arena_fast_assn ?a
    by synthesize_free

sepref_def free_arena_fast
  is mop_free
  :: arena_fast_assnd a unit_assn
  by sepref

lemma free_arena_fast_assn2: MK_FREE arena_fast_assn free_arena_fast
  unfolding free_arena_fast_def
  by (rule back_subst[of MK_FREE arena_fast_assn, OF free_arena_fast_assn])
    (auto intro!: ext)

schematic_goal free_conflict_option_rel_assn[sepref_frame_free_rules]: MK_FREE conflict_option_rel_assn ?a
    by synthesize_free

sepref_def free_conflict_option_rel
  is mop_free
  :: conflict_option_rel_assnd a unit_assn
  by sepref

lemma free_conflict_option_rel_assn2: MK_FREE conflict_option_rel_assn free_conflict_option_rel
  unfolding free_conflict_option_rel_def
  by (rule back_subst[of MK_FREE conflict_option_rel_assn, OF free_conflict_option_rel_assn])
    (auto intro!: ext)

schematic_goal free_sint64_nat_assn[sepref_frame_free_rules]: MK_FREE sint64_nat_assn ?a
    by synthesize_free

sepref_def free_sint64_nat
  is mop_free
  :: sint64_nat_assnd a unit_assn
  by sepref

lemma free_sint64_nat_assn_assn2: MK_FREE sint64_nat_assn free_sint64_nat
  unfolding free_sint64_nat_def
  by (rule back_subst[of MK_FREE sint64_nat_assn, OF free_sint64_nat_assn])
    (auto intro!: ext)

schematic_goal free_watchlist_fast_assn[sepref_frame_free_rules]: MK_FREE watchlist_fast_assn ?a
    by synthesize_free

sepref_def free_watchlist_fast
  is mop_free
  :: watchlist_fast_assnd a unit_assn
  by sepref

lemma free_watchlist_fast_assn2: MK_FREE watchlist_fast_assn free_watchlist_fast
  unfolding free_watchlist_fast_def
  by (rule back_subst[of MK_FREE watchlist_fast_assn, OF free_watchlist_fast_assn])
    (auto intro!: ext)

schematic_goal free_heuristic_bump_assn[sepref_frame_free_rules]: MK_FREE heuristic_bump_assn ?a
    unfolding heuristic_bump_assn_def
    by synthesize_free

sepref_def free_vmtf_remove
  is mop_free
  :: heuristic_bump_assnd a unit_assn
  by sepref

lemma free_heuristic_bump_assn2: MK_FREE heuristic_bump_assn free_vmtf_remove
  unfolding free_vmtf_remove_def
  apply (rule back_subst[of MK_FREE heuristic_bump_assn, OF free_heuristic_bump_assn])
  apply (auto intro!: ext simp: M_monad_laws)
  by (metis M_monad_laws(1))


schematic_goal free_uint32_nat_assn[sepref_frame_free_rules]: MK_FREE uint32_nat_assn ?a
    by synthesize_free

sepref_def free_uint32_nat
  is mop_free
  :: uint32_nat_assnd a unit_assn
  by sepref

lemma free_uint32_nat_assn2: MK_FREE uint32_nat_assn free_uint32_nat
  unfolding free_uint32_nat_def
  by (rule back_subst[of MK_FREE uint32_nat_assn, OF free_uint32_nat_assn])
    (auto intro!: ext)
 
schematic_goal free_cach_refinement_l_assn[sepref_frame_free_rules]: MK_FREE cach_refinement_l_assn ?a
    by synthesize_free

sepref_def free_cach_refinement_l
  is mop_free
  :: cach_refinement_l_assnd a unit_assn
  by sepref

lemma free_cach_refinement_l_assn2: MK_FREE cach_refinement_l_assn free_cach_refinement_l
  unfolding free_cach_refinement_l_def
  by (rule back_subst[of MK_FREE cach_refinement_l_assn, OF free_cach_refinement_l_assn])
    (auto intro!: ext)
 
schematic_goal free_lbd_assn[sepref_frame_free_rules]: MK_FREE lbd_assn ?a
    by synthesize_free

sepref_def free_lbd
  is mop_free
  :: lbd_assnd a unit_assn
  by sepref

lemma free_lbd_assn2: MK_FREE lbd_assn free_lbd
  unfolding free_lbd_def
  by (rule back_subst[of MK_FREE lbd_assn, OF free_lbd_assn])
    (auto intro!: ext)
 
schematic_goal free_outl_assn[sepref_frame_free_rules]: MK_FREE out_learned_assn ?a
    by synthesize_free

sepref_def free_outl
  is mop_free
  :: out_learned_assnd a unit_assn
  by sepref

lemma free_outl_assn2: MK_FREE out_learned_assn free_outl
  unfolding free_outl_def
  by (rule back_subst[of MK_FREE out_learned_assn, OF free_outl_assn])
    (auto intro!: ext)

schematic_goal free_heur_assn[sepref_frame_free_rules]: MK_FREE heuristic_assn ?a
    unfolding heuristic_assn_def code_hider_assn_def
    by synthesize_free

sepref_def free_heur
  is mop_free
  :: heuristic_assnd a unit_assn
  by sepref

lemma free_heur_assn2: MK_FREE heuristic_assn free_heur
  unfolding free_heur_def
  by (rule back_subst[of MK_FREE heuristic_assn, OF free_heur_assn])
    (auto intro!: ext)

schematic_goal free_isasat_stats_assn[sepref_frame_free_rules]: MK_FREE isasat_stats_assn ?a
  unfolding isasat_stats_assn_def code_hider_assn_def
  by synthesize_free

sepref_def free_stats
  is mop_free
  :: isasat_stats_assnd a unit_assn
  by sepref

lemma free_isasat_stats_assn2: MK_FREE isasat_stats_assn free_stats
  unfolding free_stats_def
  by (rule back_subst[of MK_FREE isasat_stats_assn, OF free_isasat_stats_assn])
    (auto intro!: ext)

schematic_goal free_vdom_assn[sepref_frame_free_rules]: MK_FREE aivdom_assn ?a
    unfolding aivdom_assn_def code_hider_assn_def
    by synthesize_free

sepref_def free_vdom
  is mop_free
  :: aivdom_assnd a unit_assn
  by sepref

lemma free_vdom_assn2: MK_FREE aivdom_assn free_vdom
  unfolding free_vdom_def
  by (rule back_subst[of MK_FREE aivdom_assn, OF free_vdom_assn])
    (auto intro!: ext)

schematic_goal free_lcount_assn[sepref_frame_free_rules]: MK_FREE lcount_assn ?a
    unfolding lcount_assn_def code_hider_assn_def
    by synthesize_free

sepref_def free_lcount
  is mop_free
  :: lcount_assnd a unit_assn
  by sepref

lemma free_lcount_assn2: MK_FREE lcount_assn free_lcount
  unfolding free_lcount_def
  by (rule back_subst[of MK_FREE lcount_assn, OF free_lcount_assn])
    (auto intro!: ext)

schematic_goal free_opts_assn[sepref_frame_free_rules]: MK_FREE opts_assn ?a
    unfolding opts_assn_def code_hider_assn_def opts_rel_assn_def
    by synthesize_free

sepref_def free_opts
  is mop_free
  :: opts_assnd a unit_assn
  by sepref

lemma free_opts_assn2: MK_FREE opts_assn free_opts
  unfolding free_opts_def
  by (rule back_subst[of MK_FREE opts_assn, OF free_opts_assn])
    (auto intro!: ext)

schematic_goal free_old_arena_fast_assn[sepref_frame_free_rules]: MK_FREE arena_fast_assn ?a
    by synthesize_free

sepref_def free_old_arena_fast
  is mop_free
  :: arena_fast_assnd a unit_assn
  by sepref

lemma free_old_arena_fast_assn2: MK_FREE arena_fast_assn free_old_arena_fast
  unfolding free_old_arena_fast_def free_arena_fast_def
  by (rule back_subst[of MK_FREE arena_fast_assn, OF free_old_arena_fast_assn])
    (auto intro!: ext)

sepref_def free_occs_fast
  is mop_free
  :: occs_assnd a unit_assn
  by sepref


definition bottom_occs :: nat list list where
  bottom_occs = op_aal_lempty TYPE(64) TYPE(64) 0

definition extract_occs_wl_heur where
  extract_occs_wl_heur = isasat_state_ops.remove_q bottom_occs

sepref_def bottom_occs_code
  is uncurry0 (RETURN bottom_occs)
  :: unit_assnk a occs_assn
  supply [[goals_limit=1]]
  unfolding bottom_occs_def aal_fold_custom_empty[where 'l=64 and 'll=64]
  apply (annot_snat_const TYPE(64))
  by sepref

schematic_goal free_occs_fast_assn[sepref_frame_free_rules]: MK_FREE occs_assn ?a
  by synthesize_free

lemma free_occs_fast_assn2: MK_FREE occs_assn free_occs_fast
  unfolding free_occs_fast_def
  by (rule back_subst[of MK_FREE occs_assn, OF free_occs_fast_assn])
    (auto intro!: ext)

global_interpretation isasat_state where
  a_assn = trail_pol_fast_assn and
  b_assn = arena_fast_assn and
  c_assn = conflict_option_rel_assn and
  d_assn = sint64_nat_assn and
  e_assn = watchlist_fast_assn and
  f_assn = heuristic_bump_assn and
  g_assn = uint32_nat_assn and
  h_assn = cach_refinement_l_assn and
  i_assn = lbd_assn and
  j_assn = out_learned_assn and
  k_assn = isasat_stats_assn and
  l_assn = heuristic_assn and
  m_assn = aivdom_assn and
  n_assn = lcount_assn and
  o_assn = opts_assn and
  p_assn = arena_fast_assn and
  q_assn = occs_assn and
  a_default = bottom_trail and
  a = bottom_trail_code and
  a_free = free_trail_pol_fast and
  b_default = bottom_arena and
  b = bottom_arena_code and
  b_free = free_arena_fast and
  c_default = bottom_conflict and
  c = bottom_conflict_code and
  c_free = free_conflict_option_rel and
  d_default = bottom_decision_level and
  d = (bottom_decision_level_code) and
  d_free = free_sint64_nat and
  e_default = bottom_watchlist and
  e = bottom_watchlist_code and
  e_free = free_watchlist_fast and
  f_default = bottom_bump and
  f = bottom_bump_code and
  f_free = free_vmtf_remove and
  g_default = bottom_clvls and
  g = bottom_clvls_codeand
  g_free = free_uint32_nat and
  h_default = bottom_ccach and
  h = bottom_ccach_code and
  h_free = free_cach_refinement_l and
  i_default = empty_lbd and
  i = empty_lbd_code and
  i_free = free_lbd and
  j_default = bottom_outl and
  j = bottom_outl_code and
  j_free = free_outl and
  k_default = bottom_stats and
  k = bottom_stats_code and
  k_free = free_stats and
  l_default = bottom_heur and
  l = bottom_heur_code and
  l_free = free_heur and
  m_default = bottom_vdom and
  m = bottom_vdom_code and
  m_free = free_vdom and
  n_default = bottom_lcount and
  n = bottom_lcount_code and
  n_free = free_lcount and
  ko_default = bottom_opts and
  ko = bottom_opts_code and
  o_free = free_opts and
  p_default = bottom_old_arena and
  p = bottom_old_arena_code and
  p_free = free_old_arena_fast and
  q_default = bottom_occs and
  q = bottom_occs_code and
  q_free = free_occs_fast
  rewrites
    isasat_assn  isasat_bounded_assn and
    remove_a  extract_trail_wl_heur and
    remove_b  extract_arena_wl_heur and
    remove_c  extract_conflict_wl_heur and
    remove_d  extract_literals_to_update_wl_heur and
    remove_e  extract_watchlist_wl_heur and
    remove_f  extract_vmtf_wl_heur and
    remove_g  extract_clvls_wl_heur and
    remove_h  extract_ccach_wl_heur and
    remove_i  extract_lbd_wl_heur and
    remove_j   extract_outl_wl_heur and
    remove_k  extract_stats_wl_heur and
    remove_l  extract_heur_wl_heur and
    remove_m  extract_vdom_wl_heur and
    remove_n  extract_lcount_wl_heur and
    remove_o  extract_opts_wl_heur and
    remove_p  extract_old_arena_wl_heurand
    remove_q  extract_occs_wl_heur
  apply unfold_locales
  subgoal by (rule bottom_trail_code.refine)
  subgoal by (rule bottom_arena_code.refine)
  subgoal by (rule bottom_conflict_code.refine)
  subgoal by (rule bottom_decision_level_code.refine)
  subgoal by (rule bottom_watchlist_code.refine)
  subgoal by (rule bottom_bump_code.refine)
  subgoal by (rule bottom_clvls_code.refine)
  subgoal by (rule bottom_ccach_code.refine)
  subgoal by (rule empty_lbd_hnr)
  subgoal by (rule bottom_outl_code.refine)
  subgoal by (rule bottom_stats_code.refine)
  subgoal by (rule bottom_heur_code.refine)
  subgoal by (rule bottom_vdom_code.refine)
  subgoal by (rule bottom_lcount_code.refine)
  subgoal by (rule bottom_opts_code.refine)
  subgoal by (rule bottom_old_arena_code.refine)
  subgoal by (rule bottom_occs_code.refine)
  subgoal by (rule free_trail_pol_fast_assn2)
  subgoal by (rule free_arena_fast_assn2)
  subgoal by (rule free_conflict_option_rel_assn2)
  subgoal by (rule free_sint64_nat_assn_assn2)
  subgoal by (rule free_watchlist_fast_assn2)
  subgoal by (rule free_heuristic_bump_assn2)
  subgoal by (rule free_uint32_nat_assn2)
  subgoal by (rule free_cach_refinement_l_assn2)
  subgoal by (rule free_lbd_assn2)
  subgoal by (rule free_outl_assn2)
  subgoal by (rule free_isasat_stats_assn2)
  subgoal by (rule free_heur_assn2)
  subgoal by (rule free_vdom_assn2)
  subgoal by (rule free_lcount_assn2)
  subgoal by (rule free_opts_assn2)
  subgoal by (rule free_old_arena_fast_assn2)
  subgoal by (rule free_occs_fast_assn2)
  subgoal unfolding isasat_bounded_assn_def isasat_state_ops.isasat_assn_def .
  subgoal unfolding extract_trail_wl_heur_def .
  subgoal unfolding extract_arena_wl_heur_def .
  subgoal unfolding extract_conflict_wl_heur_def .
  subgoal unfolding extract_literals_to_update_wl_heur_def .
  subgoal unfolding extract_watchlist_wl_heur_def .
  subgoal unfolding extract_vmtf_wl_heur_def .
  subgoal unfolding extract_clvls_wl_heur_def .
  subgoal unfolding extract_ccach_wl_heur_def .
  subgoal unfolding extract_lbd_wl_heur_def .
  subgoal unfolding extract_outl_wl_heur_def .
  subgoal unfolding extract_stats_wl_heur_def .
  subgoal unfolding extract_heur_wl_heur_def .
  subgoal unfolding extract_vdom_wl_heur_def .
  subgoal unfolding extract_lcount_wl_heur_def .
  subgoal unfolding extract_opts_wl_heur_def .
  subgoal unfolding extract_old_arena_wl_heur_def .
  subgoal unfolding extract_occs_wl_heur_def .
  done


(*There must some setup missing for Sepref to do that automatically*)
lemma [llvm_pre_simp]:
  (Mreturn 17 IsaSAT_int) a1 a2 a3 x a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 =
  Mreturn (IsaSAT_int a1 a2 a3 x a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17)
  by auto

lemmas [llvm_code del] =
  update_a_code_def
  update_b_code_def
  update_c_code_def
  update_d_code_def
  update_e_code_def
  update_f_code_def
  update_h_code_def
  update_i_code_def
  update_j_code_def
  update_k_code_def
  update_l_code_def
  update_m_code_def
  update_n_code_def
  update_o_code_def
  update_p_code_def
  update_q_code_def

lemmas [unfolded comp_def inline_node_case, llvm_code] =
  remove_d_code_alt_def
  remove_b_code_alt_def
  remove_a_code_alt_def
  bottom_decision_level_code_def
  bottom_arena_code_def
  bottom_trail_code_def
  update_a_code_alt_def
  update_b_code_alt_def
  update_c_code_alt_def
  update_d_code_alt_def
  update_e_code_alt_def
  update_f_code_alt_def
  update_h_code_alt_def
  update_i_code_alt_def
  update_j_code_alt_def
  update_k_code_alt_def
  update_l_code_alt_def
  update_m_code_alt_def
  update_n_code_alt_def
  update_o_code_alt_def
  update_p_code_alt_def
  update_q_code_alt_def

lemma add_pure_parameter:
  assumes C C'. (C, C')  R  (f C, f' C')  [P C']a A  b
  shows (uncurry f, uncurry f')  [uncurry P]a (pure R)k *a A  b
  apply sepref_to_hoare
  apply vcg
  apply auto
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (rule assms[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format])
  apply auto
  done

lemma remove_pure_parameter:
  assumes  (uncurry f, uncurry f')  [uncurry P]a (pure R)k *a A  b (C, C')  R
  shows (f C, f' C')  [P C']a A  b
  using assms(2) assms(1)[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format]
  apply sepref_to_hoare
  apply vcg
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  by (auto simp: pure_true_conv)

lemma add_pure_parameter2:
  assumes C C'. (C, C')  R  (λS. f S C, λS. f' S C')  [λS. P S C']a A  b
  shows (uncurry f, uncurry f')  [uncurry P]a A *a (pure R)k  b
  apply sepref_to_hoare
  apply vcg
  apply auto
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (rule assms[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format])
  apply auto
  done

lemma remove_pure_parameter2:
  assumes  (uncurry f, uncurry f')  [uncurry P]a A *a (pure R)k  b (C, C')  R
  shows (λS. f S C, λS. f' S C')  [λS. P  S C']a A  b
  using assms(2) assms(1)[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format]
  apply sepref_to_hoare
  apply vcg
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (auto simp: pure_true_conv)
  done

lemma remove_pure_parameter2':
  assumes  (uncurry (λS C. f C S), uncurry (λS C. f' C S))  [uncurry P]a A *a (pure R)k  b (C, C')  R
  shows (f C, f' C')  [λS. P S C']a A  b
  by (rule remove_pure_parameter2)
    (rule assms)+

lemma remove_pure_parameter2_twoargs:
  assumes  (uncurry2 f, uncurry2 f')  [uncurry2 P]a A *a (pure R)k *a (pure R')k  b (C, C')  R (D,D')R'
  shows (λS. f S C D, λS. f' S C' D')  [λS. P  S C' D']a A  b
  using assms(2-) assms(1)[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format]
  apply sepref_to_hoare
  apply vcg
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (auto simp: pure_true_conv)
  done


locale read_trail_param_adder0_ops =
  fixes P :: trail_pol  bool and f' :: trail_pol  'r nres
begin

definition mop where
  mop N = do {
    ASSERT (P (get_trail_wl_heur N));
    read_all_st (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' M) N
   }

end

lemma remove_component_right:
  assumes (f, f')  [P]a A  B
  shows (uncurry (λM _. f M), uncurry (λM _. f' M))  [uncurry (λM _. P M)]a A *a Xk  B
  using assms
  unfolding hfref_def
  apply clarsimp
  apply (rule hn_refine_frame')
  apply auto
  done
lemma hn_refine_frame'': "hn_refine Γ c Γ' R CP m  hn_refine (F**Γ) c (F**Γ') R CP m"
  by (metis hn_refine_frame' sep_conj_c(1))

lemma hn_refine_frame_mid'': "hn_refine (F**G) c (F'**G') R CP m  hn_refine (F**Γ**G) c (F'**Γ**G') R CP m"
  by (smt (verit) hn_refine_frame' sep_conj_aci(2) sep_conj_c(1))

lemma remove_component_left:
  assumes (f, f')  [P]a A  B
  shows (uncurry (λ_ M. f M), uncurry (λ_ M. f' M))  [uncurry (λ_ M. P M)]a  Xk *a A  B
  using assms
  unfolding hfref_def
  apply clarsimp
  apply (rule hn_refine_frame'')
  apply auto
  done

lemma remove_component_middle:
  assumes (f, f')  [P]a A *a B  C
  shows (uncurry2 (λM _ N. f (M, N)), uncurry2 (λM _ N. f' (M, N)))  [uncurry2 (λM _ N. P (M, N))]a  A *a Xk *a B C
  using assms
  unfolding hfref_def
  apply clarsimp
  apply (rule hn_refine_frame_mid'')
  apply auto
  done


lemma (in -)hfref_cong: (a, b)  [P]a A  B  a = a'  b = b'  P = P'  (a',b') [P']a A  B
  by auto

lemma split_snd_pure_arg:
  assumes (uncurry (λN C. f C N), uncurry (λN C'.  f' C' N))
     [uncurry (λS C. P S C)]a Kk *a (pure (R ×f R'))k  x_assn
  shows (uncurry2 (λN C D. f (C,D) N), uncurry2 (λN C' D'.  f' (C',D') N))
     [uncurry2 (λS C D. P S (C, D))]a Kk *a (pure(R))k *a (pure R')k  x_assn
  using assms unfolding hfref_def
  by (auto simp flip: prod_assn_pure_conv)

lemma add_pure_parameter2_twoargs:
  assumes C C' D D'. (C, C')  R   (D, D')  R'  (λS. f S C D, λS. f' S C' D')  [λS. P S C' D']a A  b
  shows (uncurry2 f, uncurry2 f')  [uncurry2 P]a A *a (pure R)k*a (pure R')k  b
  apply sepref_to_hoare
  apply vcg
  apply auto
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (rule assms[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def EXTRACT_def
    sep_conj_empty' pure_true_conv, rule_format])
  apply auto
  done

lemma remove_unused_unit_parameter:
  assumes (uncurry (λS _. f S), uncurry (λS _. f' S))  [uncurry (λS _. P S)]a A *a (pure unit_rel)k  b
  shows (f, f')  [P]a A  b
  apply sepref_to_hoare
  apply vcg
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (rule assms[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format])
  apply auto
  done

lemma add_pure_parameter_unit:
  assumes (λS. f S (), λS. f' S ())  [λS. P S]a A  b
  shows (f (), f' ())  [P]a A  b
  apply sepref_to_hoare
  apply vcg
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (rule assms[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv, rule_format])
  apply auto
  done


abbreviation read_trail_wl_heur_code :: _  _  _ where
  read_trail_wl_heur_code f  read_all_st_code  (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_trail_wl_heur :: _  isasat  _ where
  read_trail_wl_heur f  read_all_st  (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M)

locale read_trail_param_adder0 = read_trail_param_adder0_ops P f'
  for P ::  trail_pol  bool and f' :: trail_pol  'r nres +
  fixes f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine: (f, f')  [P]a trail_pol_fast_assnk  x_assn
begin

text I tried to automate the generation of the theorem but I failed (although generating the sequence
  is actually very easy...)
lemma not_deleted_code_refine':
  (uncurry16 (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M), uncurry16 (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' M)) 
   [uncurry16 (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. P M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk  x_assn
  apply (insert not_deleted_code_refine)
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = conflict_option_rel_assn])
  apply (drule remove_component_right[where X = sint64_nat_assn])
  apply (drule remove_component_right[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  apply (rule hfref_cong, assumption)
  apply (auto simp add: uncurry_def)
  done

lemmas refine = read_all_code_refine[OF not_deleted_code_refine']

lemma mop_refine:
  (read_trail_wl_heur_code f, mop)  isasat_bounded_assnka x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre0)
  apply (rule hfref_cong[OF refine])
  apply (auto intro!: ext split: isasat_int_splits)
  done

end

locale read_all_param_adder_ops =
  fixes f' :: 'a  trail_pol  arena 
      conflict_option_rel  nat  (nat watcher) list list  bump_heuristics 
      nat  conflict_min_cach_l  lbd  out_learned  isasat_stats  isasat_restart_heuristics  
    isasat_aivdom  clss_size  opts  arena  occurences_ref  'e nres and
    P :: 'a  trail_pol  arena 
      conflict_option_rel  nat  (nat watcher) list list  bump_heuristics 
      nat  conflict_min_cach_l  lbd  out_learned  isasat_stats  isasat_restart_heuristics  
    isasat_aivdom  clss_size  opts  arena  occurences_ref  bool 
begin
definition mop where
  mop S C = do {
  ASSERT (P C (get_trail_wl_heur S) 
  (get_clauses_wl_heur S)
  (get_conflict_wl_heur S)
  (literals_to_update_wl_heur S)
  (get_watched_wl_heur S)
  (get_vmtf_heur S)
  (get_count_max_lvls_heur S)
  (get_conflict_cach S)
  (get_lbd S)
  (get_outlearned_heur S)
  (get_stats_heur S)
  (get_heur S)
  (get_aivdom S)
  (get_learned_count S)
  (get_opts S)
  (get_old_arena S)
  (get_occs S));
   read_all_st (f' C) S
  }
 end

locale read_all_param_adder = read_all_param_adder_ops f' P
  for f' :: 'a  trail_pol  arena 
      conflict_option_rel  nat  (nat watcher) list list  bump_heuristics 
      nat  conflict_min_cach_l  lbd  out_learned  isasat_stats  isasat_restart_heuristics  
    isasat_aivdom  clss_size  opts  arena  occurences_ref  'r nres and
    P :: 'a  trail_pol  arena 
      conflict_option_rel  nat  (nat watcher) list list  bump_heuristics 
      nat  conflict_min_cach_l  lbd  out_learned  isasat_stats  isasat_restart_heuristics  
    isasat_aivdom  clss_size  opts  arena  occurences_ref  bool  +
  fixes R and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine:
    (uncurry17 (λa b c d e kf g h i j k l m n ko p q C. f C a b c d e kf g h i j k l m n ko p q),
    uncurry17 (λa b c d e kf g h i j k l m n ko p q C. f' C a b c d e kf g h i j k l m n ko p q))
     [uncurry17  (λa b c d e kf g h i j k l m n ko p q C. P C a b c d e kf g h i j k l m n ko p q)]a
    trail_pol_fast_assnk *a
    arena_fast_assnk *a
  conflict_option_rel_assnk *a
  sint64_nat_assnk *a
  watchlist_fast_assnk *a
  heuristic_bump_assnk *a
  uint32_nat_assnk *a
  cach_refinement_l_assnk *a
  lbd_assnk *a
  out_learned_assnk *a
  isasat_stats_assnk *a
  heuristic_assnk *a
  aivdom_assnk *a
  lcount_assnk *a
  opts_assnk *a
  arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
begin

context
begin
lemma not_deleted_code_refine_tmp:
  C C'. (C, C')  R  (uncurry16 (f C), uncurry16 (f' C'))  [uncurry16 (P C')]a
    trail_pol_fast_assnk *a
    arena_fast_assnk *a
  conflict_option_rel_assnk *a
  sint64_nat_assnk *a
  watchlist_fast_assnk *a
  heuristic_bump_assnk *a
  uint32_nat_assnk *a
  cach_refinement_l_assnk *a
  lbd_assnk *a
  out_learned_assnk *a
  isasat_stats_assnk *a
  heuristic_assnk *a
  aivdom_assnk *a
  lcount_assnk *a
  opts_assnk *a
  arena_fast_assnk *a occs_assnk  x_assn
  apply (rule remove_pure_parameter2'[where R=R])
  apply (rule hfref_cong[OF not_deleted_code_refine])
  apply (auto simp add: uncurry_def)
  done
end

lemma (in -) case_isasat_int_split_getter: P (get_trail_wl_heur S) 
  (get_clauses_wl_heur S)
  (get_conflict_wl_heur S)
  (literals_to_update_wl_heur S)
  (get_watched_wl_heur S)
  (get_vmtf_heur S)
  (get_count_max_lvls_heur S)
  (get_conflict_cach S)
  (get_lbd S)
  (get_outlearned_heur S)
  (get_stats_heur S)
  (get_heur S)
  (get_aivdom S)
  (get_learned_count S)
  (get_opts S)
  (get_old_arena S) (get_occs S) = case_isasat_int P S
  by (auto split: isasat_int_splits)

lemma refine:
  (uncurry (λN C. read_all_st_code (f C) N),
    uncurry (λN C'. read_all_st (f' C') N))
   [uncurry (λS C. P C (get_trail_wl_heur S) 
  (get_clauses_wl_heur S)
  (get_conflict_wl_heur S)
  (literals_to_update_wl_heur S)
  (get_watched_wl_heur S)
  (get_vmtf_heur S)
  (get_count_max_lvls_heur S)
  (get_conflict_cach S)
  (get_lbd S)
  (get_outlearned_heur S)
  (get_stats_heur S)
  (get_heur S)
  (get_aivdom S)
  (get_learned_count S)
  (get_opts S)
  (get_old_arena S) (get_occs S))]a isasat_bounded_assnk  *a (pure R)k x_assn
  apply (rule add_pure_parameter2)
  unfolding tuple17.case_distrib case_isasat_int_split_getter
  apply (rule read_all_code_refine)
  apply (rule not_deleted_code_refine_tmp)
  apply assumption
  done

lemma mop_refine:
  (uncurry (λN C. read_all_st_code (f C) N),
    uncurry mop)
   isasat_bounded_assnk  *a (pure R)ka x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre)
  apply (rule refine)
  done
end
 
locale read_trail_param_adder =
  fixes R and f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C. f' C S))  [uncurry (λS C. P C S)]a trail_pol_fast_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  (uncurry17 (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = conflict_option_rel_assn])
  apply (drule remove_component_right[where X = sint64_nat_assn])
  apply (drule remove_component_right[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C M) and
  P = (λC M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
lemmas mop_refine = XX.mop_refine
end



locale read_arena_param_adder_ops =
  fixes P :: 'b  arena  bool and f' :: 'b  arena_el list  'r nres
begin
definition mop where
  mop N C = do {
    ASSERT (P C (get_clauses_wl_heur N));
    read_all_st (λ_ N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C N) N   }

end

locale read_arena_param_adder = read_arena_param_adder_ops P f'
  for P :: 'b  arena  bool and f' :: 'b  arena_el list  'r nres +
  fixes R :: ('a × 'b) set and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a arena_fast_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  (uncurry17 (λ_ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_right[where X = conflict_option_rel_assn])
  apply (drule remove_component_right[where X = sint64_nat_assn])
  apply (drule remove_component_right[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX: read_all_param_adder where
  f = (λC _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C M) and
  P = (λC _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')
lemmas refine = XX.refine

lemma mop_refine:
  (uncurry (λN C. read_all_st_code (λ_ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C M) N),
    uncurry mop)
   isasat_bounded_assnk  *a (pure R)ka x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre)
  apply (rule refine)
  done

end

locale read_arena_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a arena_fast_assnk  x_assn
begin

sublocale XX: read_arena_param_adder where
  f = λ_ N. f N and
  f' = λ_ N. f' N and
  P = λ_. P and
  R = unit_rel
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
lemmas mop_refine = XX.mop_refine
end

lemma merge_second_pure_argument_generalized:
  (uncurry2 f, uncurry2 f')
   [uncurry2 P]a A *a (pure R)k *a (pure R')k  x_assn 
  (uncurry (λS C. (case C of (C, D)  f S C D)),
  uncurry (λS C'. (case C' of (C, D)  f' S C D)))
     [uncurry
     (λS C. (case C of (C, D)  P S C D))]a A *a (pure (R ×f R'))k  x_assn
  unfolding hfref_def 
  by (auto simp flip: prod_assn_pure_conv)

 lemma merge_second_pure_argument:
  (uncurry2 (λS C D. f C D S), uncurry2 (λS C' D'. f' C' D' S))
   [uncurry2
   (λS C' D'.
    P C' D' S)]a A *a (pure R)k *a (pure R')k  x_assn 
  (uncurry (λS C. (case C of (C, D)  f C D) S),
  uncurry (λS C'. (case C' of (C, D)  f' C D) S))
    [uncurry (λS C. (case C of (C, D)  P C D) S)]a A *a (pure (R ×f R'))k  x_assn
  unfolding hfref_def 
  by (auto simp flip: prod_assn_pure_conv)


lemma merge_third_pure_argument':
  (uncurry3 (λS C D E. f C D E S), uncurry3 (λS C' D' E'. f' C' D' E' S))
   [uncurry3
   (λS C' D' E'.
    P C' D' E' S)]a A *a (pure R)k *a (pure R')k  *a (pure R'')k  x_assn 
  (uncurry2 (λS E C. (case C of (C, D)  f E C D) S),
  uncurry2 (λS E' C'. (case C' of (C, D)  f' E' C D) S))
     [uncurry2
     (λS E C. (case C of (C, D)  P E C D)
  S)]a A *a (pure R)k *a  (pure (R' ×f R''))k  x_assn
  unfolding hfref_def 
  by (auto simp flip: prod_assn_pure_conv)
 
abbreviation read_arena_wl_heur_code :: _ where
  read_arena_wl_heur_code f  read_all_st_code  (λ_ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_arena_wl_heur :: _ where
  read_arena_wl_heur f  read_all_st  (λ_ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M)

locale read_arena_param_adder2_twoargs_ops =
  fixes
    f' :: 'b  'd  arena  'r nres and
    P :: 'b  'd  arena  bool
begin
definition mop where
  mop N C C' = do {
     ASSERT (P C C' (get_clauses_wl_heur N));
     read_arena_wl_heur (λN. f' C C' N) N
  }
end


locale read_arena_param_adder2_twoargs =
  read_arena_param_adder2_twoargs_ops f' P
  for f' :: 'b  'd  arena  'r nres and P +
  fixes R and R' and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine:
    (uncurry2 (λS C D. f C D S), uncurry2 (λS C' D'. f' C' D' S)) 
    [uncurry2 (λS C' D'. P C' D' S)]a arena_fast_assnk *a (pure R)k *a (pure R')k  x_assn
begin

sublocale XX: read_arena_param_adder where
  f = λ(C,D) N. f C D N and
  f' = λ(C,D) N. f' C D N and
  P = λ(C,D) N. P C D N and
  R = R ×f R'
  apply unfold_locales
  using not_deleted_code_refine[THEN merge_second_pure_argument] .

lemma refine:
  (uncurry2 (λN C D. read_arena_wl_heur_code (f C D) N),
    uncurry2 (λN C' D. read_arena_wl_heur (f' C' D) N))
   [uncurry2 (λS C D. P C D (get_clauses_wl_heur S))]a isasat_bounded_assnk  *a (pure R)k *a (pure R')k  x_assn
  by (rule XX.refine[THEN split_snd_pure_arg, unfolded prod.case])

lemma mop_refine:
  (uncurry2 (λN C D. read_arena_wl_heur_code (λN. f C D N) N), uncurry2 mop)  isasat_bounded_assnk *a (pure R)k *a (pure R')k a x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre2)
  apply (rule refine[unfolded comp_def])
  done

end

abbreviation read_conflict_wl_heur_code :: _ where
  read_conflict_wl_heur_code f  read_all_st_code  (λ_ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_conflict_wl_heur :: _ where
  read_conflict_wl_heur f  read_all_st  (λ_ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _. f M)


locale read_conflict_param_adder =
  fixes R and f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a conflict_option_rel_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = sint64_nat_assn])
  apply (drule remove_component_right[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C M) and
  P = (λC _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_conflict_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a conflict_option_rel_assnk  x_assn
begin
sublocale XX: read_conflict_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P and
  R = unit_rel
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end


abbreviation read_literals_to_update_wl_heur_code :: _ where
  read_literals_to_update_wl_heur_code f  read_all_st_code  (λ_ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_literals_to_update_wl_heur :: _ where
  read_literals_to_update_wl_heur f  read_all_st  (λ_ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _. f M)

locale read_literals_to_update_param_adder =
  fixes R and f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a sint64_nat_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_right[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _. f' C M) and
  P = (λC _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end


locale read_literals_to_update_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a sint64_nat_assnk  x_assn
begin
sublocale XX: read_literals_to_update_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end

abbreviation read_watchlist_wl_heur_code :: _ where
  read_watchlist_wl_heur_code f  read_all_st_code  (λ_ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_watchlist_wl_heur :: _ where
  read_watchlist_wl_heur f  read_all_st  (λ_ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _. f M)


locale read_watchlist_param_adder =
  fixes R and f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine:
    (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a watchlist_fast_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _. f' C M) and
  P = (λC _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
lemmas mop_refine = XX.mop_refine
end


locale read_watchlist_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a watchlist_fast_assnk  x_assn
begin

sublocale XX: read_watchlist_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]

end


locale read_watchlist_param_adder_twoargs =
  fixes R and R' and f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine:
    (uncurry2 (λS C D. f C D S), uncurry2 (λS C' D'. f' C' D' S)) 
    [uncurry2 (λS C' D'. P C' D' S)]a watchlist_fast_assnk  *a (pure R)k *a (pure R')k  x_assn
begin

sublocale XX: read_watchlist_param_adder where
  f = λ(C,D). f C D and
  f' = λ(C,D). f' C D and
  P = λ(C,D). P C D and
  R = R ×f R'
  apply unfold_locales
  using not_deleted_code_refine[THEN merge_second_pure_argument] .


lemma refine:
  (uncurry2 (λN C D. read_watchlist_wl_heur_code (f C D) N),
    uncurry2 (λN C' D'. read_watchlist_wl_heur (f' C' D') N))
   [uncurry2 (λS C D. P C D (get_watched_wl_heur S))]a
    isasat_bounded_assnk  *a (pure R)k  *a (pure R')k x_assn
  by (rule XX.refine[THEN split_snd_pure_arg, unfolded prod.case])

lemmas mop_refine = XX.XX.mop_refine
end



abbreviation read_vmtf_wl_heur_code :: _ where
  read_vmtf_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_vmtf_wl_heur :: _ where
  read_vmtf_wl_heur f  read_all_st  (λ_ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _. f M)

locale read_vmtf_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a heuristic_bump_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k   x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _. f' C M) and
  P = (λC _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end


locale read_vmtf_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a heuristic_bump_assnk  x_assn
begin

sublocale XX: read_vmtf_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]

end



abbreviation read_ccount_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_ccount_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _. f M)
abbreviation read_ccount_wl_heur :: _  isasat  _ where
  read_ccount_wl_heur f  read_all_st  (λ_ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _. f M)

locale read_ccount_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a uint32_nat_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k   x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption)
    (auto intro!: ext)

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_ccount_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a uint32_nat_assnk  x_assn
begin

sublocale XX: read_ccount_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end


abbreviation read_ccach_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_ccach_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _. f M)
abbreviation read_ccach_wl_heur :: _  isasat  _ where
  read_ccach_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _. f M)

locale read_ccach_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a cach_refinement_l_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end


abbreviation read_lbd_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_lbd_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _. f M)
abbreviation read_lbd_wl_heur :: _  isasat  _ where
  read_lbd_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _. f M)

locale read_lbd_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a lbd_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_lbd_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a lbd_assnk  x_assn
begin
sublocale XX: read_lbd_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end

abbreviation read_outl_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_outl_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _. f M)
abbreviation read_outl_wl_heur :: _  isasat  _ where
  read_outl_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _. f M)

locale read_outl_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a out_learned_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine

end

locale read_outl_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a out_learned_assnk  x_assn
begin

sublocale XX: read_outl_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end


abbreviation read_stats_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_stats_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _. f M)
abbreviation read_stats_wl_heur :: _  isasat  _ where
  read_stats_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _. f M)

locale read_stats_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a isasat_stats_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_stats_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a isasat_stats_assnk  x_assn
begin
sublocale XX: read_stats_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end


abbreviation read_heur_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_heur_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _. f M)
abbreviation read_heur_wl_heur :: _  isasat  _ where
  read_heur_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _. f M)

locale read_heur_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a heuristic_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_middle[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_heur_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a heuristic_assnk  x_assn
begin
sublocale XX: read_heur_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end


locale read_heur_param_adder2 =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R and R'
  assumes not_deleted_code_refine: (uncurry2 (λS C D. f C D S), uncurry2 (λS C' D'. f' C' D' S))  [uncurry2 (λS C D. P C D S)]a heuristic_assnk *a (pure R)k*a (pure R')k  x_assn
begin
sublocale XX: read_heur_param_adder where
  f = λ(C,D) N. f C D N and
  f' = λ(C,D) N. f' C D N and
  P = λ(C,D) N. P C D N and
  R = R ×f R'
  apply unfold_locales
  using not_deleted_code_refine[THEN merge_second_pure_argument] .

lemma refine:
  (uncurry2 (λN C D. read_heur_wl_heur_code (f C D) N),
    uncurry2 (λN C' D. read_heur_wl_heur (f' C' D) N))
   [uncurry2 (λS C D. P C D (get_heur S))]a isasat_bounded_assnk  *a (pure R)k *a (pure R')k  x_assn
  by (rule XX.refine[THEN split_snd_pure_arg, unfolded prod.case])

end

abbreviation read_vdom_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_vdom_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _. f M)
abbreviation read_vdom_wl_heur :: _  isasat  _ where
  read_vdom_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _. f M)

locale read_vdom_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a aivdom_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_middle[where X = isasat_stats_assn])
  apply (drule remove_component_middle[where X = heuristic_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_vdom_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a aivdom_assnk  x_assn
begin

sublocale XX: read_vdom_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end



abbreviation read_lcount_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_lcount_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _. f M)
abbreviation read_lcount_wl_heur :: _  isasat  _ where
  read_lcount_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _. f M)


locale read_lcount_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a lcount_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_middle[where X = isasat_stats_assn])
  apply (drule remove_component_middle[where X = heuristic_assn])
  apply (drule remove_component_middle[where X = aivdom_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_lcount_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a lcount_assnk  x_assn
begin
sublocale XX: read_lcount_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end



abbreviation read_opts_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_opts_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _. f M)
abbreviation read_opts_wl_heur :: _  isasat  _ where
  read_opts_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _. f M)

locale read_opts_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a opts_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_middle[where X = isasat_stats_assn])
  apply (drule remove_component_middle[where X = heuristic_assn])
  apply (drule remove_component_middle[where X = aivdom_assn])
  apply (drule remove_component_middle[where X = lcount_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

locale read_opts_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a opts_assnk  x_assn
begin

sublocale XX: read_opts_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end



abbreviation read_old_arena_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_old_arena_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. f M)
abbreviation read_old_arena_wl_heur :: _  isasat  _ where
  read_old_arena_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. f M)

locale read_old_arena_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a arena_fast_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _ C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_middle[where X = isasat_stats_assn])
  apply (drule remove_component_middle[where X = heuristic_assn])
  apply (drule remove_component_middle[where X = aivdom_assn])
  apply (drule remove_component_middle[where X = lcount_assn])
  apply (drule remove_component_middle[where X = opts_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M _. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end


locale read_old_arena_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a arena_fast_assnk  x_assn
begin

sublocale XX: read_old_arena_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end


abbreviation read_occs_wl_heur_code :: _  twl_st_wll_trail_fast2  _ where
  read_occs_wl_heur_code f  read_all_st_code  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. f M)
abbreviation read_occs_wl_heur :: _  isasat  _ where
  read_occs_wl_heur f  read_all_st  (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. f M)

locale read_occs_param_adder =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R
  assumes not_deleted_code_refine: (uncurry (λS C. f C S), uncurry (λS C'. f' C' S))  [uncurry (λS C. P C S)]a occs_assnk  *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  shows 
  (uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M C. f C M), uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M C'. f' C' M)) 
  [uncurry17 (λ_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M C'. P C' M)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[where f =f and f'=f', OF not_deleted_code_refine])
  apply (drule remove_component_left[where X = trail_pol_fast_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_middle[where X = heuristic_bump_assn])
  apply (drule remove_component_middle[where X = uint32_nat_assn])
  apply (drule remove_component_middle[where X = cach_refinement_l_assn])
  apply (drule remove_component_middle[where X = lbd_assn])
  apply (drule remove_component_middle[where X = out_learned_assn])
  apply (drule remove_component_middle[where X = isasat_stats_assn])
  apply (drule remove_component_middle[where X = heuristic_assn])
  apply (drule remove_component_middle[where X = aivdom_assn])
  apply (drule remove_component_middle[where X = lcount_assn])
  apply (drule remove_component_middle[where X = opts_assn])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. f C M) and
  f' = (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. f' C M) and
  P =  (λC _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ M. P C M)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end


locale read_occs_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (f, f')  [P]a occs_assnk  x_assn
begin

sublocale XX: read_occs_param_adder where
  f = λ_. f and
  f' = λ_. f' and
  P = λ_. P
  apply unfold_locales
  using not_deleted_code_refine[THEN remove_component_right] .

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end

locale read_occs_param_adder2 =
  fixes f and f' and x_assn :: 'r  'q  assn and P and R and R'
  assumes not_deleted_code_refine: (uncurry2 (λS C D. f C D S), uncurry2 (λS C' D'. f' C' D' S))  [uncurry2 (λS C D. P C D S)]a occs_assnk *a (pure R)k*a (pure R')k  x_assn
begin

sublocale XX: read_occs_param_adder where
  f = λ(C,D) N. f C D N and
  f' = λ(C,D) N. f' C D N and
  P = λ(C,D) N. P C D N and
  R = R ×f R'
  apply unfold_locales
  using not_deleted_code_refine[THEN merge_second_pure_argument] .

lemma refine:
  (uncurry2 (λN C D. read_occs_wl_heur_code (f C D) N),
    uncurry2 (λN C' D. read_occs_wl_heur (f' C' D) N))
   [uncurry2 (λS C D. P C D (get_occs S))]a isasat_bounded_assnk  *a (pure R)k *a (pure R')k  x_assn
  by (rule XX.refine[THEN split_snd_pure_arg, unfolded prod.case])

lemma mop_refine:
  (uncurry2 (λN C D. read_occs_wl_heur_code (f C D) N), uncurry2 (λN C D. XX.XX.mop N (C,D))) 
  isasat_bounded_assnk *a (pure R)k *a (pure R')k a x_assn
  unfolding mop_def XX.XX.mop_def
  apply (rule refine_ASSERT_move_to_pre2)
  unfolding prod.simps
  apply (rule refine[unfolded comp_def])
  done

end


locale read_trail_arena_param_adder_ops =
  fixes P :: 'b  trail_pol  arena  bool and f' :: 'b  trail_pol  arena_el list  'r nres
begin

definition mop where
  mop N C = do {
    ASSERT (P C (get_trail_wl_heur N) (get_clauses_wl_heur N));
    read_all_st (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C M N) N
   }

end

locale read_trail_arena_param_adder = read_trail_arena_param_adder_ops P f'
  for P :: 'b  trail_pol  arena  bool and f' :: 'b  trail_pol  arena_el list  'r nres +
  fixes R :: ('a × 'b) set and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine: (uncurry2 (λS T C. f C S T), uncurry2 (λS T C'. f' C' S T))  [uncurry2 (λS T C. P C S T)]a trail_pol_fast_assnk *a arena_fast_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  (uncurry17 (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C. f C M N), uncurry17 (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M N)) 
  [uncurry17 (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C'. P C' M N)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[OF not_deleted_code_refine])
  apply (drule remove_component_right[where X = conflict_option_rel_assn])
  apply (drule remove_component_right[where X = sint64_nat_assn])
  apply (drule remove_component_right[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = heuristic_bump_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC M N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C M N) and
  f' = (λC M N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C M N) and
  P = (λC M N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. P C M N)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine

lemma mop_refine:
  (uncurry (λN C. read_all_st_code (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C M N) N),
    uncurry mop)
   isasat_bounded_assnk  *a (pure R)ka x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre)
  apply (rule refine)
  done
end


locale read_trail_arena_param_adder2_twoargs_ops =
  fixes
    f' :: 'b  'd  trail_pol  arena  'r nres and
    P :: 'b  'd  trail_pol  arena  bool
begin
definition mop where
  mop N C C' = do {
     ASSERT (P C C' (get_trail_wl_heur N) (get_clauses_wl_heur N));
     read_all_st (λM N  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C C' M N) N
  }
end

locale read_trail_arena_param_adder2_twoargs =
  read_trail_arena_param_adder2_twoargs_ops f' P
  for f' :: 'b  'd  trail_pol  arena  'r nres and P +
  fixes R and R' and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine:
    (uncurry3 (λS T C D. f C D S T), uncurry3 (λS T C' D'. f' C' D' S T)) 
    [uncurry3 (λS T C' D'. P C' D' S T)]a trail_pol_fast_assnk *a arena_fast_assnk *a (pure R)k *a (pure R')k  x_assn
begin

sublocale XX: read_trail_arena_param_adder where
  f = λ(C,D) N. f C D N and
  f' = λ(C,D) N. f' C D N and
  P = λ(C,D) N. P C D N and
  R = R ×f R'
  apply unfold_locales
  by (rule hfref_cong[OF not_deleted_code_refine[THEN merge_second_pure_argument]]) auto

lemmas refine = XX.refine[unfolded case_isasat_int_split_getter]

lemma mop_refine:
  (uncurry2 (λN C D. read_all_st_code
        (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C D M N) N), uncurry2 mop)  isasat_bounded_assnk *a (pure R)k *a (pure R')k a x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre2)
  apply (rule refine[THEN split_snd_pure_arg, unfolded prod.case])
  done
end

locale read_trail_arena_param_adder2_threeargs_ops =
  fixes
    f' :: 'b  'd  'e  trail_pol  arena  'r nres and
    P :: 'b  'd  'e  trail_pol  arena  bool
begin
definition mop where
  mop N C D E = do {
     ASSERT (P C D E (get_trail_wl_heur N) (get_clauses_wl_heur N));
     read_all_st (λM N  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C D E M N) N
  }
end


lemma refine_ASSERT_move_to_pre3:
  assumes (uncurry3 g, uncurry3 h)  [uncurry3 P]a A *a B *a C *a D  x_assn
  shows
  (uncurry3 g, uncurry3 (λN C D E. do {ASSERT (P N C D E); h N C D E}))
     A *a B *a C *a D a x_assn
  apply sepref_to_hoare
  apply vcg
  apply (subst POSTCOND_def hn_ctxt_def sep_conj_empty' pure_true_conv EXTRACT_def)+
  apply (auto simp: nofail_ASSERT_bind)
  apply (rule assms[to_hnr, simplified, unfolded hn_ctxt_def hn_refine_def htriple_def
    sep_conj_empty' pure_true_conv sep.add_assoc, rule_format])
  apply auto
  done
 
locale read_trail_arena_param_adder2_threeargs =
  read_trail_arena_param_adder2_threeargs_ops f' P
  for f' :: 'b  'd  'e  trail_pol  arena  'r nres and P +
  fixes R and R' and R'' and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine:
    (uncurry4 (λS T C D E. f C D E S T), uncurry4 (λS T C' D' E'. f' C' D' E' S T)) 
    [uncurry4 (λS T C' D' E'. P C' D' E' S T)]a trail_pol_fast_assnk *a arena_fast_assnk *a (pure R)k *a (pure R')k*a (pure R'')k  x_assn
begin
sublocale XX: read_trail_arena_param_adder where
  f = λ(C,D,E) N. f C D E N and
  f' = λ(C,D,E) N. f' C D E N and
  P = λ(C,D,E) N. P C D E N and
  R = R ×r R' ×r R''
  apply unfold_locales
  subgoal
    using not_deleted_code_refine[THEN merge_second_pure_argument]
    by (auto simp flip: prod_assn_pure_conv simp: hfref_def)
  done


text It would be better to this without calling auto, but fighting uncurry is just too hard
  and not really useful.
lemma refine:
  (uncurry3 (λN C D E. read_all_st_code (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C D E M N) N),
  uncurry3 (λN C D E. read_all_st (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f' C D E M N) N))
   [uncurry3 (λS C' D' E'. P C' D' E' (get_trail_wl_heur S) (get_clauses_wl_heur S))]a
  isasat_bounded_assnk *a (pure R)k *a (pure R')k *a (pure R'')k  x_assn
  using XX.refine[THEN split_snd_pure_arg, unfolded prod.case] unfolding hfref_def
  by (auto simp flip: prod_assn_pure_conv)
lemma mop_refine:
  (uncurry3 (λN C D E. read_all_st_code
        (λM N _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. f C D E M N) N), uncurry3 mop)  isasat_bounded_assnk *a (pure R)k *a (pure R')k *a (pure R'')k a x_assn
  unfolding mop_def
  apply (rule refine_ASSERT_move_to_pre3)
  apply (rule refine)
  done

end


locale read_trail_vmtf_param_adder =
  fixes P :: 'b  _  bump_heuristics  bool and f' :: 'b  trail_pol  _  'r nres and
     R :: ('a × 'b) set and f and x_assn :: 'r  'q  assn
  assumes not_deleted_code_refine: (uncurry2 (λS T C. f C S T), uncurry2 (λS T C'. f' C' S T))  [uncurry2 (λS T C. P C S T)]a trail_pol_fast_assnk *a heuristic_bump_assnk *a (pure R)k  x_assn
begin

lemma not_deleted_code_refine':
  (uncurry17 (λM _ _ _ _ N _ _ _ _ _ _ _ _ _ _ _ C. f C M N), uncurry17 (λM _ _ _ _ N _ _ _ _ _ _ _ _ _ _ _ C'. f' C' M N)) 
  [uncurry17 (λM _ _ _ _ N _ _ _ _ _ _ _ _ _ _ _ C'. P C' M N)]a
   trail_pol_fast_assnk *a arena_fast_assnk *a conflict_option_rel_assnk *a sint64_nat_assnk *a
  watchlist_fast_assnk *a heuristic_bump_assnk *a uint32_nat_assnk *a cach_refinement_l_assnk *a
  lbd_assnk *a out_learned_assnk *a isasat_stats_assnk *a heuristic_assnk *a
  aivdom_assnk *a lcount_assnk *a opts_assnk *a arena_fast_assnk  *a occs_assnk *a (pure R)k  x_assn
  apply (rule add_pure_parameter2)
  apply (drule remove_pure_parameter2'[OF not_deleted_code_refine])
  apply (drule remove_component_middle[where X = arena_fast_assn])
  apply (drule remove_component_middle[where X = conflict_option_rel_assn])
  apply (drule remove_component_middle[where X = sint64_nat_assn])
  apply (drule remove_component_middle[where X = watchlist_fast_assn])
  apply (drule remove_component_right[where X = uint32_nat_assn])
  apply (drule remove_component_right[where X = cach_refinement_l_assn])
  apply (drule remove_component_right[where X = lbd_assn])
  apply (drule remove_component_right[where X = out_learned_assn])
  apply (drule remove_component_right[where X = isasat_stats_assn])
  apply (drule remove_component_right[where X = heuristic_assn])
  apply (drule remove_component_right[where X = aivdom_assn])
  apply (drule remove_component_right[where X = lcount_assn])
  apply (drule remove_component_right[where X = opts_assn])
  apply (drule remove_component_right[where X = arena_fast_assn])
  apply (drule remove_component_right[where X = occs_assn])
  by (rule hfref_cong, assumption) auto

sublocale XX : read_all_param_adder where
  f = (λC M _ _ _ _ N _ _ _ _ _ _ _ _ _ _ _. f C M N) and
  f' = (λC M _ _ _ _ N _ _ _ _ _ _ _ _ _ _ _. f' C M N) and
  P = (λC M _ _ _ _ N _ _ _ _ _ _ _ _ _ _ _. P C M N)
  by unfold_locales
   (rule not_deleted_code_refine')

lemmas refine = XX.refine
end

lemma hn_refine_frame''': "hn_refine (F**G) c (F'**G') R CP m  hn_refine (F**G**H) c (F'**G'**H) R CP m"
  by (metis hn_refine_frame_mid'' sep.mult_commute)

locale read_trail_vmtf_param_adder0 =
  fixes f and f' and x_assn :: 'r  'q  assn and P
  assumes not_deleted_code_refine: (uncurry (λS T. f S T), uncurry (λS T. f' S T))  [uncurry (λS T. P S T)]a trail_pol_fast_assnk *a heuristic_bump_assnk  x_assn
begin

sublocale XX: read_trail_vmtf_param_adder where
  f = λ_::unit. f and
  f' = λ_::unit. f' and
  P = λ_::unit. P and 
  R = unit_rel
  apply unfold_locales
  using not_deleted_code_refine apply -
  unfolding hfref_def
  apply clarsimp
  apply (rule hn_refine_frame''')
  apply auto
  done

lemmas refine = XX.refine[THEN remove_unused_unit_parameter]
end



lemma Mreturn_comp_IsaSAT_int:
  (Mreturn o17 IsaSAT_int) a b c d e f g h i j k l m n ko p q =
  Mreturn (IsaSAT_int a b c d e f g h i j k l m n ko p q)
  by auto

sepref_register
  remove_a remove_b remove_c remove_d
  remove_e remove_f remove_g remove_h
  remove_i remove_j remove_k remove_l
  remove_m remove_n remove_o remove_p remove_q

lemmas [sepref_fr_rules] =
  remove_a_code.refine
  remove_b_code.refine
  remove_c_code.refine
  remove_d_code.refine
  remove_e_code.refine
  remove_f_code.refine
  remove_g_code.refine
  remove_h_code.refine
  remove_i_code.refine
  remove_j_code.refine
  remove_k_code.refine
  remove_l_code.refine
  remove_m_code.refine
  remove_n_code.refine
  remove_o_code.refine
  remove_p_code.refine
  remove_q_code.refine


lemma lambda_comp_true: (λS. True)  f = (λ_. True) uncurry (λa b. True) = (λ_. True)  uncurry2 (λa b c. True) = (λ_. True)
  case_isasat_int (λM _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. True) = (λ_. True)
  by (auto intro!: ext split: isasat_int_splits)

named_theorems state_extractors Definition of all functions modifying the state
lemmas [state_extractors] =
  extract_trail_wl_heur_def
  extract_arena_wl_heur_def
  extract_conflict_wl_heur_def
  extract_watchlist_wl_heur_def
  extract_vmtf_wl_heur_def
  extract_ccach_wl_heur_def
  extract_clvls_wl_heur_def
  extract_lbd_wl_heur_def
  extract_outl_wl_heur_def
  extract_stats_wl_heur_def
  extract_heur_wl_heur_def
  extract_vdom_wl_heur_def
  extract_lcount_wl_heur_def
  extract_opts_wl_heur_def
  extract_literals_to_update_wl_heur_def
  extract_occs_wl_heur_def
  tuple17_getters_setters



lemmas [llvm_inline] =
  DEFAULT_INIT_PHASE_def
  FOCUSED_MODE_def

lemma from_bool1: "from_bool True = 1"
  by auto
lemmas [llvm_pre_simp] = from_bool1

lemmas [unfolded inline_direct_return_node_case, llvm_code] =
  remove_a_code_alt_def[unfolded isasat_state.remove_a_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_b_code_alt_def[unfolded isasat_state.remove_b_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_c_code_alt_def[unfolded isasat_state.remove_c_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_d_code_alt_def[unfolded isasat_state.remove_d_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_e_code_alt_def[unfolded isasat_state.remove_e_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_f_code_alt_def[unfolded isasat_state.remove_f_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_g_code_alt_def[unfolded isasat_state.remove_g_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_h_code_alt_def[unfolded isasat_state.remove_h_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_i_code_alt_def[unfolded isasat_state.remove_i_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_j_code_alt_def[unfolded isasat_state.remove_j_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_k_code_alt_def[unfolded isasat_state.remove_k_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_l_code_alt_def[unfolded isasat_state.remove_l_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_m_code_alt_def[unfolded isasat_state.remove_m_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_n_code_alt_def[unfolded isasat_state.remove_n_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_o_code_alt_def[unfolded isasat_state.remove_o_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_p_code_alt_def[unfolded isasat_state.remove_p_code_alt_def Mreturn_comp_IsaSAT_int]
  remove_q_code_alt_def[unfolded isasat_state.remove_q_code_alt_def Mreturn_comp_IsaSAT_int]

abbreviation update_trail_wl_heur :: trail_pol  isasat  _ where
  update_trail_wl_heur  update_a

abbreviation update_arena_wl_heur :: arena isasat  _ where
  update_arena_wl_heur  update_b

abbreviation update_conflict_wl_heur :: conflict_option_rel isasat  _ where
  update_conflict_wl_heur  update_c

abbreviation update_literals_to_update_wl_heur :: nat isasat  _ where
  update_literals_to_update_wl_heur  update_d

abbreviation update_watchlist_wl_heur :: nat watcher list list isasat  _ where
  update_watchlist_wl_heur  update_e

abbreviation update_vmtf_wl_heur :: bump_heuristics isasat  _ where
  update_vmtf_wl_heur  update_f

abbreviation update_clvls_wl_heur :: nat isasat  _ where
  update_clvls_wl_heur  update_g

abbreviation update_ccach_wl_heur :: conflict_min_cach_l isasat  _ where
  update_ccach_wl_heur  update_h

abbreviation update_lbd_wl_heur :: lbd isasat  _ where
  update_lbd_wl_heur  update_i

abbreviation update_outl_wl_heur :: out_learned isasat  _ where
  update_outl_wl_heur  update_j

abbreviation update_stats_wl_heur :: isasat_stats  isasat  isasat where
  update_stats_wl_heur  update_k

abbreviation update_heur_wl_heur :: isasat_restart_heuristics isasat  isasat where
  update_heur_wl_heur  update_l

abbreviation update_vdom_wl_heur :: isasat_aivdom isasat  _ where
  update_vdom_wl_heur  update_m

abbreviation update_lcount_wl_heur :: clss_size isasat  _ where
  update_lcount_wl_heur  update_n

abbreviation update_opts_wl_heur :: opts isasat  _ where
  update_opts_wl_heur  update_o

abbreviation update_old_arena_wl_heur :: arena isasat  _ where
  update_old_arena_wl_heur  update_p

abbreviation update_occs_wl_heur :: occurences_ref isasat  _ where
  update_occs_wl_heur  update_q
end