/*  Generated by CHR bootstrap compiler
    From: /pbulk/work/lang/yap/work/yap-6.3.3/packages/chr/chr_translate.chr
    Date: "Thu Jul 16 21:32:21 2026"

    DO NOT EDIT.  EDIT THE CHR FILE INSTEAD
*/

:-module(chr_translate,[chr_translate/2,chr_translate_line_info/3]).
:-use_module(chr_runtime).
:-style_check(- (discontiguous)).
:-use_module(library(lists),[member/2,append/3,reverse/2,permutation/2,last/2]).
:-use_module(library(ordsets)).
:-use_module(library(aggregate)).
:-use_module(library(apply_macros)).
:-use_module(library(occurs)).
:-use_module(library(assoc)).
:-use_module(library(dialect/hprolog)).
:-use_module(pairlist).
:-use_module(a_star).
:-use_module(listmap).
:-use_module(clean_code).
:-use_module(builtins).
:-use_module(find).
:-use_module(binomialheap).
:-use_module(guard_entailment).
:-use_module(chr_compiler_options).
:-use_module(chr_compiler_utility).
:-use_module(chr_compiler_errors).
:-include(chr_op).
:-op(1150,fx,chr_type).
:-op(1150,fx,chr_declaration).
:-op(1130,xfx,--->).
:-op(980,fx,+).
:-op(980,fx,-).
:-op(980,fx,?).
:-op(1150,fx,constraints).
:-op(1150,fx,chr_constraint).
format_storetype(multi_store(A)) :-
   !,
   maplist(format_storetype,A).
format_storetype(atomic_constants(A,B,_)) :-
   format('\t* a trie index on the argument(s) ~w for the ground terms ~w\n',[A,B]).
format_storetype(ground_constants(A,B,_)) :-
   format('\t* a trie index on the argument(s) ~w for the ground terms ~w\n',[A,B]).
format_storetype(A) :-
   format('\t* ~w\n',[A]).
get_constraint_arg_type(A,B,C) :-
   get_constraint_type(A,D),
   nth1(B,D,E),
   unalias_type(E,C).
partial_store(ground_constants(_,_,incomplete)).
partial_store(atomic_constants(_,_,incomplete)).
late_allocation_analysis(A) :-
   ( chr_pp_flag(late_allocation,on) ->
     maplist(late_allocation,A)
   ;
     true
   ).
late_allocation(A) :-
   late_allocation(A,0).
late_allocation(A,B) :-
   allocation_occurrence(A,B),
   !.
late_allocation(A,B) :-
   C is B+1,
   late_allocation(A,C).
stored_in_guard_before_next_kept_occurrence(A,B) :-
   chr_pp_flag(store_in_guards,on),
   C is B+1,
   stored_in_guard_lookahead(A,C).
set_constraint_indices(A) :-
   set_constraint_indices(A,1).
set_constraint_indices([],A) :-
   B is A-1,
   max_constraint_index(B).
set_constraint_indices([B|C],A) :-
   (
     (
       chr_pp_flag(debugable,on)
     ;
       \+only_ground_indexed_arguments(B),
       is_stored(B)
     ;
       is_stored(B),
       get_store_type(B,default)
     ;
       get_store_type(B,var_assoc_store(_,_))
     ) ->
     constraint_index(B,A),
     D is A+1,
     set_constraint_indices(C,D)
   ;
     set_constraint_indices(C,A)
   ).
type_indexed_identifier_structure(A,B) :-
   type_indexed_identifier_name(A,type_indexed_identifier_struct,C),
   get_type_indexed_identifier_size(A,D),
   functor(B,C,D).
type_indexed_identifier_name(A,B,C) :-
   ( atom(A) ->
     D=A
   ;
     term_to_atom(A,D)
   ),
   atom_concat_list([B,'_',D],C).
chr_translate(A,B) :-
   chr_translate_line_info(A,bootstrap,B).
chr_translate_line_info(A,B,C) :-
   chr_banner,
   restart_after_flattening(A,D),
   init_chr_pp_flags,
   chr_source_file(B),
   partition_clauses(D,E,F,G),
   chr_compiler_options:sanity_check,
   dump_code(D),
   check_declared_constraints(E),
   generate_show_constraint(E,H,F,I),
   add_constraints(H),
   add_rules(I),
   generate_never_stored_rules(H,J),
   add_rules(J),
   append(I,J,K),
   chr_analysis(K,H,D),
   time('constraint code generation',chr_translate:constraints_code(H,L)),
   time('validate store assumptions',chr_translate:validate_store_type_assumptions(H)),
   phase_end(validate_store_type_assumptions),
   used_states_known,
   time('store code generation',chr_translate:store_management_preds(H,M)),
   insert_declarations(G,N),
   chr_module_declaration(O),
   append([M,L,O,[end_of_file]],P),
   clean_clauses(P,Q),
   append([N,Q],C),
   dump_code(C),
   !.
chr_analysis(A,B,C) :-
   maplist(pragma_rule_to_ast_rule,A,D),
   check_rules(A,D,B),
   time('type checking',chr_translate:static_type_check(A,D)),
   collect_constants(A,D,B,C),
   add_occurrences(A,D),
   time('functional dependency',chr_translate:functional_dependency_analysis(A)),
   time('set semantics',chr_translate:set_semantics_rules(A)),
   time('symmetry analysis',chr_translate:symmetry_analysis(A)),
   time('guard simplification',chr_translate:guard_simplification),
   time('late storage',chr_translate:storage_analysis(B)),
   time(observation,chr_translate:observation_analysis(B)),
   time('ai observation',chr_translate:ai_observation_analysis(B)),
   time('late allocation',chr_translate:late_allocation_analysis(B)),
   partial_wake_analysis,
   time('assume constraint stores',chr_translate:assume_constraint_stores(B)),
   time('default constraint indices',chr_translate:set_constraint_indices(B)),
   time('check storedness assertions',chr_translate:check_storedness_assertions(B)),
   time('continuation analysis',chr_translate:continuation_analysis(B)).
store_management_preds(A,B) :-
   generate_attach_detach_a_constraint_all(A,C),
   generate_attr_unify_hook(D),
   generate_attach_increment(E),
   generate_extra_clauses(A,F),
   generate_insert_delete_constraints(A,G),
   generate_attach_code(A,H),
   generate_counter_code(I),
   generate_dynamic_type_check_clauses(J),
   append([C,E,D,F,G,H,I,J],B).
insert_declarations(A,B) :-
   findall((:-use_module(chr(D))),(auxiliary_module(D),is_used_auxiliary_module(D)),C),
   append(A,[(:-use_module(chr(chr_runtime)))|C],B).
auxiliary_module(chr_hashtable_store).
auxiliary_module(chr_integertable_store).
auxiliary_module(chr_assoc_store).
generate_counter_code(A) :-
   ( chr_pp_flag(store_counter,on) ->
     A=[('$counter_init'(B):-nb_setval(B,0)),('$counter'(C,D):-nb_getval(C,D)),('$counter_inc'(E):-nb_getval(E,F),G is F+1,nb_setval(E,G)),(:-'$counter_init'('$insert_counter')),(:-'$counter_init'('$delete_counter')),('$insert_counter_inc':-'$counter_inc'('$insert_counter')),('$delete_counter_inc':-'$counter_inc'('$delete_counter')),(counter_stats(H,I):-'$counter'('$insert_counter',H),'$counter'('$delete_counter',I))]
   ;
     A=[]
   ).
chr_module_declaration(A) :-
   get_target_module(B),
   ( B\==chr_translate,
     chr_pp_flag(toplevel_show_store,on) ->
     A=[(:-multifile chr:'$chr_module'/1),chr:'$chr_module'(B)]
   ;
     A=[]
   ).
partition_clauses([],[],[],[]).
partition_clauses([D|E],A,B,C) :-
   ( parse_rule(D,F) ->
     A=G,
     B=[F|H],
     C=I
   ;
     ( is_declaration(D,J) ->
       append(J,G,A),
       B=H,
       C=I
     )
   ;
     ( is_module_declaration(D,K) ->
       target_module(K),
       A=G,
       B=H,
       C=[D|I]
     )
   ;
     ( is_type_definition(D) ->
       A=G,
       B=H,
       C=I
     )
   ;
     ( is_chr_declaration(D) ->
       A=G,
       B=H,
       C=I
     )
   ;
     ( D=handler(_) ->
       chr_warning(deprecated(D),'Backward compatibility: ignoring handler/1 declaration.\n',[]),
       A=G,
       B=H,
       C=I
     )
   ;
     ( D=rules(_) ->
       chr_warning(deprecated(D),'Backward compatibility: ignoring rules/1 declaration.\n',[]),
       A=G,
       B=H,
       C=I
     )
   ;
     ( D=option(L,M) ->
       chr_warning(deprecated(D),'Instead use `:-chr_option(~w,~w).\'\n',[L,M]),
       handle_option(L,M),
       A=G,
       B=H,
       C=I
     )
   ;
     ( D= (:-chr_option(L,M)) ->
       handle_option(L,M),
       A=G,
       B=H,
       C=I
     )
   ;
     ( D='$chr_compiled_with_version'(_) ->
       A=G,
       B=H,
       C=['$chr_compiled_with_version'(3)|I]
     )
   ;
     A=G,
     B=H,
     C=[D|I]
   ),
   partition_clauses(E,G,H,I).
'$chr_compiled_with_version'(3).
is_declaration(A,B) :-
   ( A= (:-C),
     C=..[D,E],
     D== (chr_constraint) ->
     conj2list(E,F)
   ;
     ( A= (:-C) ->
       C=..[constraints,E]
     ;
       A=..[constraints,E]
     ),
     conj2list(E,F),
     chr_warning(deprecated(A),'Instead use :- chr_constraint ~w.\n',[E])
   ),
   extract_type_mode(F,B).
extract_type_mode([],[]).
extract_type_mode([B/C|A],[B/C|D]) :-
   !,
   extract_type_mode(A,D).
extract_type_mode([A|B],[C|D]) :-
   ( A=E#F ->
     functor(E,G,H),
     extract_annotation(F,G/H)
   ;
     A=E,
     functor(E,G,H)
   ),
   C=G/H,
   E=..[_|I],
   extract_types_and_modes(I,J,K),
   assert_constraint_type(C,J),
   constraint_mode(C,K),
   extract_type_mode(B,D).
extract_annotation(stored,A) :-
   stored_assertion(A).
extract_annotation(default(B),A) :-
   never_stored_default(A,B).
extract_types_and_modes([],[],[]).
extract_types_and_modes([A|B],[C|D],[E|F]) :-
   extract_type_and_mode(A,C,E),
   extract_types_and_modes(B,D,F).
extract_type_and_mode(+A,A,+) :-
   !.
extract_type_and_mode(?A,A,?) :-
   !.
extract_type_and_mode(-A,A,-) :-
   !.
extract_type_and_mode(+,any,+) :-
   !.
extract_type_and_mode(?,any,?) :-
   !.
extract_type_and_mode(-,any,-) :-
   !.
extract_type_and_mode(A,_,_) :-
   chr_error(syntax(A),'Illegal mode/type declaration.\n\tCorrect syntax is +type, -type or ?type\n\tor +, - or ?.\n',[]).
is_chr_declaration(A) :-
   A= (:-chr_declaration B),
   ( B= (C--->D) ->
     background_info(C,D)
   ;
     ( B=D ->
       background_info([D])
     )
   ).
is_type_definition(A) :-
   is_type_definition(A,B),
   assert_type_definition(B).
assert_type_definition(typedef(A,B)) :-
   type_definition(A,B).
assert_type_definition(alias(A,B)) :-
   type_alias(A,B).
is_type_definition(A,B) :-
   ( A= (:-C) ->
     true
   ;
     A=C
   ),
   C=..[chr_type,D],
   ( D= (E--->F) ->
     tdisj2list(F,G),
     B=typedef(E,G)
   ;
     ( D= (H==E) ->
       B=alias(H,E)
     )
   ;
     B=typedef(D,[]),
     chr_warning(syntax,'Empty type definition `~w\'.\nAre you sure you want to declare a phantom type?\n',[A])
   ).
tdisj2list(A,B) :-
   tdisj2list(A,B,[]).
tdisj2list(A,B,C) :-
   A= (D;E),
   !,
   tdisj2list(D,B,F),
   tdisj2list(E,F,C).
tdisj2list(A,[A|B],B).
parse_rule(A,B) :-
   A= @(C,D),
   !,
   rule(D,yes(C),B).
parse_rule(A,B) :-
   rule(A,no,B).
rule(A,B,C) :-
   A=pragma(D,E),
   !,
   ( var(E) ->
     F=[_]
   ;
     conj2list(E,F)
   ),
   inc_rule_count(G),
   C=pragma(H,I,F,B,G),
   is_rule(D,H,I,C).
rule(A,B,C) :-
   inc_rule_count(D),
   C=pragma(E,F,[],B,D),
   is_rule(A,E,F,C).
is_rule(A,B,C,D) :-
   A= ==>(E,F),
   !,
   conj2list(E,G),
   get_ids(G,H,I,D),
   C=ids([],H),
   ( F= (J|K) ->
     B=rule([],I,J,K)
   ;
     B=rule([],I,true,F)
   ).
is_rule(A,B,C,D) :-
   A= <=>(E,F),
   !,
   ( F= (G|H) ->
     I=G,
     J=H
   ;
     I=true,
     J=F
   ),
   ( E= \(K,L) ->
     conj2list(K,M),
     conj2list(L,N),
     get_ids(M,O,P,0,Q,D),
     get_ids(N,R,S,Q,_,D),
     C=ids(R,O)
   ;
     conj2list(E,N),
     P=[],
     get_ids(N,R,S,D),
     C=ids(R,[])
   ),
   B=rule(S,P,I,J).
get_ids(A,B,C,D) :-
   get_ids(A,B,C,0,_,D).
get_ids([],[],[],A,A,_).
get_ids([C|D],[E|F],[G|H],E,A,B) :-
   ( C=G#I ->
     ( var(I) ->
       I=E
     ;
       check_direct_pragma(I,E,B)
     )
   ;
     G=C
   ),
   J is E+1,
   get_ids(D,F,H,J,A,B).
check_direct_pragma(passive,A,B) :-
   !,
   B=pragma(_,_,_,_,C),
   passive(C,A).
check_direct_pragma(A,_,B) :-
   ( direct_pragma(C),
     atom_concat(A,_,C) ->
     chr_warning(problem_pragma(A,B),'completed `~w\' to `~w\'\n',[A,C])
   ;
     chr_warning(unsupported_pragma(A,B),'',[])
   ).
direct_pragma(passive).
is_module_declaration((:-module(A)),A).
is_module_declaration((:-module(A,_)),A).
add_constraints([]).
add_constraints([A|B]) :-
   max_occurrence(A,0),
   A=_/C,
   length(D,C),
   set_elems(D,?),
   constraint_mode(A,D),
   add_constraints(B).
add_rules([]).
add_rules([A|B]) :-
   A=pragma(_,_,_,_,C),
   rule(C,A),
   add_rules(B).
check_declared_constraints(A) :-
   tree_set_empty(B),
   check_declared_constraints(A,B).
check_declared_constraints([],_).
check_declared_constraints([B|C],A) :-
   ( tree_set_memberchk(B,A) ->
     chr_error(syntax(B),'Constraint multiply defined: ~w.\n\tRemove redundant declaration!\n',[B])
   ;
     true
   ),
   tree_set_add(A,B,D),
   check_declared_constraints(C,D).
check_rules(A,B,C) :-
   maplist(check_rule(C),A,B).
check_rule(A,B,C) :-
   B=pragma(_,_,D,_,_),
   check_ast_rule_indexing(C,B),
   check_ast_trivial_propagation_rule(C,B),
   check_ast_head_constraints(C,A,B),
   check_pragmas(D,B).
check_ast_trivial_propagation_rule(A,B) :-
   A=ast_rule(C,_,_,D,_),
   ( C=propagation(_),
     D==[] ->
     chr_warning(weird_program,'Ignoring propagation rule with empty body: ~@.\n\t\n',[format_rule(B)]),
     set_rule_passive(B)
   ;
     true
   ).
set_rule_passive(A) :-
   A=pragma(_,_,_,_,B),
   set_all_passive(B).
check_trivial_propagation_rule(A) :-
   A=pragma(B,_,_,_,C),
   ( B=rule([],_,_,true) ->
     chr_warning(weird_program,'Ignoring propagation rule with empty body: ~@.\n\t\n',[format_rule(A)]),
     set_all_passive(C)
   ;
     true
   ).
check_ast_head_constraints(ast_rule(C,_,_,_,_),A,B) :-
   check_ast_head_constraints_(C,A,B).
check_ast_head_constraints_(simplification(C),A,B) :-
   maplist(check_ast_head_constraint(A,B),C).
check_ast_head_constraints_(propagation(C),A,B) :-
   maplist(check_ast_head_constraint(A,B),C).
check_ast_head_constraints_(simpagation(C,D),A,B) :-
   maplist(check_ast_head_constraint(A,B),C),
   maplist(check_ast_head_constraint(A,B),D).
check_ast_head_constraint(A,B,chr_constraint(C,_,D)) :-
   ( memberchk(C,A) ->
     true
   ;
     chr_error(syntax(D),'Undeclared constraint ~w in head of ~@.\n\tConstraint should be one of ~w.\n',[_/_,format_rule(B),A])
   ).
check_head_constraints([],_,_).
check_head_constraints([C|D],A,B) :-
   functor(C,E,F),
   ( memberchk(E/F,A) ->
     check_head_constraints(D,A,B)
   ;
     chr_error(syntax(C),'Undeclared constraint ~w in head of ~@.\n\tConstraint should be one of ~w.\n',[E/F,format_rule(B),A])
   ).
check_pragmas([],_).
check_pragmas([B|C],A) :-
   check_pragma(B,A),
   check_pragmas(C,A).
check_pragma(A,B) :-
   var(A),
   !,
   chr_error(syntax(A),'Invalid pragma ~w in ~@.\n\tPragma should not be a variable!\n',[A,format_rule(B)]).
check_pragma(passive(B),A) :-
   !,
   A=pragma(_,ids(D,E),_,_,C),
   ( memberchk_eq(B,D) ->
     true
   ;
     ( memberchk_eq(B,E) ->
       true
     )
   ;
     chr_error(syntax(B),'Invalid identifier ~w in pragma passive in ~@.\n',[B,format_rule(A)])
   ),
   passive(C,B).
check_pragma(mpassive(B),A) :-
   !,
   A=pragma(_,_,_,_,C),
   chr_warning(experimental,'Experimental pragma ~w. Use with care!\n',[mpassive(B)]),
   maplist(passive(C),B).
check_pragma(A,B) :-
   A=already_in_heads,
   !,
   chr_warning(unsupported_pragma(A,B),'Termination and correctness may be affected.\n',[]).
check_pragma(A,B) :-
   A=already_in_head(_),
   !,
   chr_warning(unsupported_pragma(A,B),'Termination and correctness may be affected.\n',[]).
check_pragma(A,B) :-
   A=no_history,
   !,
   chr_warning(experimental,'Experimental pragma no_history. Use with care!\n',[]),
   B=pragma(_,_,_,_,C),
   no_history(C).
check_pragma(A,B) :-
   A=history(C,D),
   !,
   B=pragma(_,ids(F,G),_,_,E),
   chr_warning(experimental,'Experimental pragma ~w. Use with care!\n',[A]),
   ( F\==[] ->
     chr_error(syntax(A),'Pragma history only implemented for propagation rules.\n',[])
   ;
     ( \+atom(C) ->
       chr_error(syntax(A),'Illegal argument for pragma history: ~w is not an atom (rule number ~w).\n',[C,E])
     )
   ;
     ( \+is_set(D) ->
       chr_error(syntax(A),'Illegal argument for pragma history: ~w is not a set (rule number ~w).\n',[D,E])
     )
   ;
     ( check_history_pragma_ids(D,F,G) ->
       history(E,C,D)
     )
   ;
     chr_error(syntax(A),'Invalid identifier(s) in pragma ~w of rule number ~w.\n',[A,E])
   ).
check_pragma(A,B) :-
   A=line_number(C),
   !,
   B=pragma(_,_,_,_,D),
   line_number(D,C).
check_history_pragma_ids([],_,_).
check_history_pragma_ids([C|D],A,B) :-
   (
     memberchk_eq(C,B)
   ;
     memberchk_eq(C,A)
   ),
   check_history_pragma_ids(D,A,B).
check_pragma(A,B) :-
   chr_error(syntax(A),'Unknown pragma ~w in ~@.\n',[A,format_rule(B)]).
test_named_history_id_pairs(_,[],_,[]).
test_named_history_id_pairs(A,[C|D],B,[E|F]) :-
   test_named_history_id_pair(A,C,B,E),
   test_named_history_id_pairs(A,D,B,F).
format_rule(A) :-
   A=pragma(_,_,_,B,C),
   ( B=yes(D) ->
     write('rule '),
     write(D)
   ;
     write('rule number '),
     write(C)
   ),
   get_line_number(C,E),
   write(' (line '),
   write(E),
   write(')').
check_ast_rule_indexing(A,B) :-
   A=ast_rule(C,D,_,_,_),
   tree_set_empty(E),
   ast_head_variables(C,E,F),
   ast_remove_anti_monotonic_guards(D,F,G),
   ast_term_list_variables(G,E,H),
   check_ast_head_indexing(C,H),
   ( chr_pp_flag(term_indexing,on) ->
     B=pragma(I,_,_,_,_),
     I=rule(J,K,L,_),
     term_variables(J-K,M),
     remove_anti_monotonic_guards(L,M,N),
     term_variables(N,O),
     append(J,K,P),
     check_specs_indexing(P,O,_)
   ;
     true
   ).
check_ast_head_indexing(simplification(B),A) :-
   check_ast_indexing(B,A).
check_ast_head_indexing(propagation(B),A) :-
   check_ast_indexing(B,A).
check_ast_head_indexing(simpagation(B,C),A) :-
   ast_constraint_list_variables(C,A,D),
   check_ast_indexing(B,D),
   ast_constraint_list_variables(B,A,E),
   check_ast_indexing(C,E).
check_rule_indexing(A) :-
   A=pragma(B,_,_,_,_),
   B=rule(C,D,E,_),
   term_variables(C-D,F),
   remove_anti_monotonic_guards(E,F,G),
   check_indexing(C,G-D),
   check_indexing(D,G-C),
   ( chr_pp_flag(term_indexing,on) ->
     term_variables(G,H),
     append(C,D,I),
     check_specs_indexing(I,H,_)
   ;
     true
   ).
remove_anti_monotonic_guards(A,B,C) :-
   conj2list(A,D),
   remove_anti_monotonic_guard_list(D,B,E),
   list2conj(E,C).
remove_anti_monotonic_guard_list([],_,[]).
remove_anti_monotonic_guard_list([C|D],A,B) :-
   ( C=var(E),
     memberchk_eq(E,A) ->
     B=F
   ;
     B=[C|F]
   ),
   remove_anti_monotonic_guard_list(D,A,F).
ast_remove_anti_monotonic_guards([],_,[]).
ast_remove_anti_monotonic_guards([C|D],A,B) :-
   ( C=compound(var,1,[E],_),
     ast_var_memberchk(E,A) ->
     B=F
   ;
     B=[C|F]
   ),
   ast_remove_anti_monotonic_guards(D,A,F).
check_ast_indexing([],_).
check_ast_indexing([B|C],A) :-
   B=chr_constraint(D,E,_),
   ast_constraint_list_variables(C,A,F),
   check_ast_indexing(E,1,D,F),
   ast_constraint_variables(B,A,G),
   check_ast_indexing(C,G).
check_ast_indexing([],_,_,_).
check_ast_indexing([D|E],A,B,C) :-
   ( is_indexed_argument(B,A) ->
     true
   ;
     ( ast_nonvar(D) ->
       indexed_argument(B,A)
     )
   ;
     ast_term_list_variables(E,C,F),
     ( ast_var_memberchk(D,F) ->
       indexed_argument(B,A)
     ;
       true
     )
   ),
   G is A+1,
   ast_term_variables(D,C,H),
   check_ast_indexing(E,G,B,H).
check_indexing([],_).
check_indexing([B|C],A) :-
   functor(B,D,E),
   B=..[_|F],
   term_variables(C-A,G),
   check_indexing(F,1,D/E,G),
   check_indexing(C,[B|A]).
check_indexing([],_,_,_).
check_indexing([D|E],A,B,C) :-
   ( is_indexed_argument(B,A) ->
     true
   ;
     ( nonvar(D) ->
       indexed_argument(B,A)
     )
   ;
     term_variables(E,F),
     append(F,C,G),
     ( memberchk_eq(D,G) ->
       indexed_argument(B,A)
     ;
       true
     )
   ),
   H is A+1,
   term_variables(D,I),
   append(I,C,J),
   check_indexing(E,H,B,J).
check_specs_indexing([],_,[]).
check_specs_indexing([C|D],A,B) :-
   B=[E|F],
   term_variables(D,G,A),
   check_spec_indexing(C,G,E),
   term_variables(C,H,A),
   check_specs_indexing(D,H,F).
check_spec_indexing(A,B,C) :-
   functor(A,D,E),
   C=spec(D,E,F),
   A=..[_|G],
   check_args_spec_indexing(G,1,B,F),
   indexing_spec(D/E,[F]).
check_args_spec_indexing([],_,_,[]).
check_args_spec_indexing([D|E],A,B,C) :-
   term_variables(E,F,B),
   ( check_arg_spec_indexing(D,A,F,G) ->
     C=[G|H]
   ;
     C=H
   ),
   I is A+1,
   term_variables(D,J,B),
   check_args_spec_indexing(E,I,J,H).
check_arg_spec_indexing(A,B,C,D) :-
   ( var(A) ->
     memberchk_eq(A,C),
     D=specinfo(B,any,[])
   ;
     functor(A,E,F),
     D=specinfo(B,E/F,[G]),
     A=..[_|H],
     check_args_spec_indexing(H,1,C,G)
   ).
add_occurrences(A,B) :-
   maplist(add_rule_occurrences,A,B).
add_rule_occurrences(A,B) :-
   A=pragma(_,C,_,_,D),
   B=ast_rule(E,_,_,_,_),
   add_head_occurrences(E,C,D).
add_head_occurrences(simplification(B),ids(C,_),A) :-
   maplist(add_constraint_occurrence(A,simplification),B,C).
add_head_occurrences(propagation(B),ids(_,C),A) :-
   maplist(add_constraint_occurrence(A,propagation),B,C).
add_head_occurrences(simpagation(B,C),ids(D,E),A) :-
   maplist(add_constraint_occurrence(A,simplification),B,D),
   maplist(add_constraint_occurrence(A,propagation),C,E).
add_constraint_occurrence(A,B,C,D) :-
   C=chr_constraint(E,_,_),
   new_occurrence(E,A,D,B).
observation_analysis(A,B,C,D) :-
   ( all_spawned(A,C) ->
     true
   ;
     ( var(B) ->
       spawns_all(A,C)
     )
   ;
     ( B=true ->
       true
     )
   ;
     ( B=fail ->
       true
     )
   ;
     ( B=! ->
       true
     )
   ;
     ( B= (E,F) ->
       observation_analysis(A,E,C,D),
       observation_analysis(A,F,C,D)
     )
   ;
     ( B= (E;F) ->
       observation_analysis(A,E,C,D),
       observation_analysis(A,F,C,D)
     )
   ;
     ( B= (E->F) ->
       observation_analysis(A,E,C,D),
       observation_analysis(A,F,C,D)
     )
   ;
     ( B= (\+G) ->
       observation_analysis(A,G,C,D)
     )
   ;
     ( functor(B,H,I),
       memberchk(H/I,D) ->
       spawns(A,C,H/I)
     )
   ;
     ( B= (_=_) ->
       spawns_all_triggers(A,C)
     )
   ;
     ( B= (_ is _) ->
       spawns_all_triggers(A,C)
     )
   ;
     ( builtin_binds_b(B,J) ->
       ( J==[] ->
         true
       ;
         spawns_all_triggers(A,C)
       )
     )
   ;
     spawns_all(A,C)
   ).
is_observed(A,B) :-
   is_observed(A,B,_),
   ai_is_observed(A,B).
is_stored_in_guard(A,B) :-
   chr_pp_flag(store_in_guards,on),
   do_is_observed(A,B,guard).
generate_attach_detach_a_constraint_all([],[]).
generate_attach_detach_a_constraint_all([B|C],A) :-
   (
     (
       chr_pp_flag(debugable,on)
     ;
       is_stored(B),
       \+only_ground_indexed_arguments(B),
       \+get_store_type(B,var_assoc_store(_,_))
     ) ->
     generate_attach_a_constraint(B,D),
     generate_detach_a_constraint(B,E)
   ;
     D=[],
     E=[]
   ),
   generate_attach_detach_a_constraint_all(C,F),
   append([D,E,F],A).
generate_attach_a_constraint(A,[B,C]) :-
   generate_attach_a_constraint_nil(A,B),
   generate_attach_a_constraint_cons(A,C).
attach_constraint_atom(A,B,C,D) :-
   make_name(attach_,A,E),
   D=..[E,B,C].
generate_attach_a_constraint_nil(A,B) :-
   B= (C:-true),
   attach_constraint_atom(A,[],_,C).
generate_attach_a_constraint_cons(A,B) :-
   B= (C:-D),
   attach_constraint_atom(A,[F|G],E,C),
   attach_constraint_atom(A,G,E,H),
   D= (I,J,H),
   get_max_constraint_index(K),
   ( K==1 ->
     generate_attach_body_1(A,F,E,I)
   ;
     generate_attach_body_n(A,F,E,I)
   ),
   chr_pp_flag(solver_events,L),
   ( L\==none ->
     _=[[F|_],E],
     get_target_module(M),
     use_auxiliary_predicate(run_suspensions),
     J=clp_events:subscribe(F,L,M,M:'$run_suspensions'([E]))
   ;
     J=true
   ).
generate_attach_body_1(_,A,B,C) :-
   get_target_module(D),
   C= (get_attr(A,D,E)->put_attr(A,D,[B|E]);put_attr(A,D,[B])).
generate_attach_body_n(D/E,A,B,C) :-
   chr_pp_flag(experiment,off),
   !,
   get_constraint_index(D/E,F),
   get_max_constraint_index(G),
   get_target_module(H),
   add_attr(G,B,F,I,J,K),
   singleton_attr(G,B,F,L),
   C= (get_attr(A,H,I)->J,put_attr(A,H,K);put_attr(A,H,L)),
   !.
generate_attach_body_n(D/E,A,B,C) :-
   chr_pp_flag(experiment,on),
   !,
   get_constraint_index(D/E,F),
   or_pattern(F,G),
   H is F+1,
   get_max_constraint_index(I),
   get_target_module(J),
   singleton_attr(I,B,F,K),
   C= (get_attr(A,J,L)->arg(1,L,M),arg(H,L,N),O is M\/G,setarg(1,L,O),setarg(H,L,[B|N]);put_attr(A,J,K)),
   !.
generate_detach_a_constraint(A,[B,C]) :-
   generate_detach_a_constraint_nil(A,B),
   generate_detach_a_constraint_cons(A,C).
detach_constraint_atom(A,B,C,D) :-
   make_name(detach_,A,E),
   D=..[E,B,C].
generate_detach_a_constraint_nil(A,B) :-
   B= (C:-true),
   detach_constraint_atom(A,[],_,C).
generate_detach_a_constraint_cons(A,B) :-
   B= (C:-D),
   detach_constraint_atom(A,[F|G],E,C),
   detach_constraint_atom(A,G,E,H),
   D= (I,H),
   get_max_constraint_index(J),
   ( J==1 ->
     generate_detach_body_1(A,F,E,I)
   ;
     generate_detach_body_n(A,F,E,I)
   ).
generate_detach_body_1(_,A,B,C) :-
   get_target_module(D),
   C= (get_attr(A,D,E)->'chr sbag_del_element'(E,B,F),(F==[]->del_attr(A,D);put_attr(A,D,F));true).
generate_detach_body_n(D/E,A,B,C) :-
   get_constraint_index(D/E,F),
   get_max_constraint_index(G),
   rem_attr(G,A,B,F,H,I),
   get_target_module(J),
   C= (get_attr(A,J,H)->I;true),
   !.
create_indexed_variables_body([],[],[],_,_,_,empty,0).
create_indexed_variables_body([F|G],[H|I],[J|K],A,B,C,D,E) :-
   L is B+1,
   create_indexed_variables_body(G,I,K,M,L,C,N,O),
   ( H== (?),
     is_indexed_argument(C,B) ->
     ( atomic_type(J) ->
       D= ((var(F)->A=[F|M];A=M),P),
       ( N==empty ->
         P=true,
         M=[]
       ;
         P=N
       )
     ;
       ( N==empty ->
         D=term_variables(F,A)
       )
     ;
       D= (term_variables(F,A,M),N)
     ),
     E=O
   ;
     ( H== (-),
       is_indexed_argument(C,B) ->
       ( N==empty ->
         D= (A=[F])
       ;
         D= (A=[F|M],N)
       ),
       E is O+1
     )
   ;
     A=M,
     D=N,
     E is O+1
   ).
spectermvars(A,B,C,D,E,F) :-
   spectermvars(B,1,A,C,D,F,[],E).
spectermvars([],A,_,_,B,C,C,true) :-
   A>B,
   !.
spectermvars([H|I],A,B,C,D,E,F,G) :-
   G= (J,K),
   argspecs(B,A,L,M),
   merge_argspecs(L,N),
   arggoal(N,H,J,E,O),
   P is A+1,
   spectermvars(I,P,M,C,D,O,F,K).
argspecs([],_,[],[]).
argspecs([[]|D],A,B,C) :-
   argspecs(D,A,B,C).
argspecs([[specinfo(F,G,H)|E]|D],A,B,C) :-
   ( A==F ->
     B=[specinfo(F,G,H)|I],
     ( E=[] ->
       J=C
     ;
       C=[E|J]
     )
   ;
     B=I,
     C=[[specinfo(F,G,H)|E]|J]
   ),
   argspecs(D,A,I,J).
merge_argspecs(A,B) :-
   sort(A,C),
   merge_argspecs_(C,B).
merge_argspecs_([],[]).
merge_argspecs_([B],A) :-
   !,
   A=[B].
merge_argspecs_([specinfo(B,C,D),specinfo(B,F,G)|E],A) :-
   (
     (
       C==any
     ;
       F==any
     ) ->
     merge_argspecs_([specinfo(B,any,[])|E],A)
   ;
     ( C==F ->
       append(D,G,H),
       merge_argspecs_([specinfo(B,C,H)|E],A)
     )
   ;
     A=[specinfo(B,C,D)|I],
     merge_argspecs_([specinfo(B,F,G)|E],I)
   ).
arggoal(A,B,C,D,E) :-
   ( A==[] ->
     D=E,
     C=true
   ;
     ( A=[specinfo(_,any,_)] ->
       C=term_variables(B,D,E)
     )
   ;
     C= (var(B)->D=[B|E];F),
     arggoal_cases(A,B,D,E,F)
   ).
arggoal_cases([],_,A,B,A=B).
arggoal_cases([specinfo(_,F,G)|E],A,B,C,D) :-
   ( G==[] ->
     D=H
   ;
     ( G==[[]] ->
       D=H
     )
   ;
     ( F=I/J ->
       D= (K;H),
       functor(L,I,J),
       L=..[_|M],
       K= (A=L->N),
       spectermvars(M,1,G,I,J,B,C,N)
     )
   ),
   arggoal_cases(E,A,B,C,H).
generate_extra_clauses(A,B) :-
   generate_activate_clauses(A,B,C),
   generate_remove_clauses(A,C,D),
   generate_allocate_clauses(A,D,E),
   generate_insert_constraint_internal_clauses(A,E,F),
   generate_novel_production(F,G),
   generate_extend_history(G,H),
   generate_run_suspensions_clauses(A,H,I),
   generate_empty_named_history_initialisations(I,J),
   J=[].
generate_remove_clauses([],A,A).
generate_remove_clauses([C|D],A,B) :-
   generate_remove_clause(C,A,E),
   generate_remove_clauses(D,E,B).
remove_constraint_goal(A,B,C,D,E,F,G) :-
   uses_state(A,removed),
   ( chr_pp_flag(inline_insertremove,off) ->
     use_auxiliary_predicate(remove_constraint_internal,A),
     G= (H,(I==yes->E;D)),
     remove_constraint_atom(A,B,C,I,H)
   ;
     delay_phase_end(validate_store_type_assumptions,generate_remove_body(A,B,C,D,E,F,G))
   ).
remove_constraint_atom(A,B,C,D,E) :-
   make_name('$remove_constraint_internal_',A,F),
   ( chr_pp_flag(debugable,off),
     (
       only_ground_indexed_arguments(A)
     ;
       get_store_type(A,var_assoc_store(_,_))
     ) ->
     E=..[F,B,D]
   ;
     E=..[F,B,C,D]
   ).
generate_remove_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(remove_constraint_internal,A) ->
     B=[D|C],
     D= (E:-F),
     remove_constraint_atom(A,G,H,I,E),
     generate_remove_body(A,G,H,I=no,I=yes,active,F)
   ;
     B=C
   ).
generate_remove_body(A,B,C,D,E,F,G) :-
   ( chr_pp_flag(debugable,off),
     (
       only_ground_indexed_arguments(A)
     ;
       get_store_type(A,var_assoc_store(_,_))
     ) ->
     ( F==active ->
       get_update_suspension_field(A,B,state,H,removed,I,J,K),
       if_used_state(A,not_stored_yet,J,true,L),
       if_used_state(A,not_stored_yet,(H==not_stored_yet->D;E),E,M)
     ;
       ( F==partner ->
         get_update_suspension_field(A,B,state,H,removed,I,_,K),
         L=true,
         M=E
       )
     ),
     G= (I,L,K,M)
   ;
     static_suspension_term(A,N),
     get_static_suspension_term_field(arguments,A,N,O),
     generate_indexed_variables_body(A,O,P,C),
     ( chr_pp_flag(debugable,on) ->
       A=Q/_,
       get_static_suspension_term_field(functor,A,N,Q)
     ;
       true
     ),
     ( F==active ->
       get_update_static_suspension_field(A,B,N,state,H,removed,J,K),
       if_used_state(A,not_stored_yet,J,true,L),
       if_used_state(A,not_stored_yet,(H==not_stored_yet->C=[],D;P,E),(P,E),M)
     ;
       ( F==partner ->
         get_update_static_suspension_field(A,B,N,state,H,removed,_,K),
         L=true,
         M= (P,E)
       )
     ),
     G= (B=N,L,K,M)
   ).
generate_activate_clauses([],A,A).
generate_activate_clauses([C|D],A,B) :-
   generate_activate_clause(C,A,E),
   generate_activate_clauses(D,E,B).
activate_constraint_goal(A,B,C,D,E,F) :-
   ( chr_pp_flag(inline_insertremove,off) ->
     use_auxiliary_predicate(activate_constraint,A),
     F= (G,(H==yes->B;true)),
     activate_constraint_atom(A,H,C,D,E,G)
   ;
     delay_phase_end(validate_store_type_assumptions,activate_constraint_body(A,B,true,C,D,E,F))
   ).
activate_constraint_atom(A,B,C,D,E,F) :-
   make_name('$activate_constraint_',A,G),
   ( chr_pp_flag(debugable,off),
     only_ground_indexed_arguments(A) ->
     F=..[G,B,D]
   ;
     ( chr_pp_flag(debugable,off),
       may_trigger(A),
       get_store_type(A,var_assoc_store(_,_)) ->
       F=..[G,B,D,E]
     )
   ;
     ( chr_pp_flag(debugable,off),
       may_trigger(A),
       get_store_type(A,var_assoc_store(_,_)) ->
       F=..[G,B,C,D,E]
     )
   ;
     F=..[G,B,C,D]
   ).
generate_activate_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(activate_constraint,A) ->
     B=[D|C],
     D= (E:-F),
     activate_constraint_atom(A,G,H,I,J,E),
     activate_constraint_body(A,G=yes,G=no,H,I,J,F)
   ;
     B=C
   ).
activate_constraint_body(A,B,C,D,E,F,G) :-
   ( chr_pp_flag(debugable,off),
     may_trigger(A),
     uses_field(A,generation) ->
     get_update_suspension_field(A,E,generation,H,F,I,J,K),
     L= (I,J,F is H+1,K)
   ;
     L=true
   ),
   get_update_suspension_field(A,E,state,M,active,N,O,P),
   if_used_state(A,not_stored_yet,O,true,Q),
   ( chr_pp_flag(debugable,off),
     (
       only_ground_indexed_arguments(A)
     ;
       get_store_type(A,var_assoc_store(_,_))
     ) ->
     if_used_state(A,not_stored_yet,(M==not_stored_yet->B;C),C,R)
   ;
     get_dynamic_suspension_term_field(arguments,A,E,S,T),
     generate_indexed_variables_body(A,S,U,D),
     chr_none_locked(D,V),
     if_used_state(A,not_stored_yet,(M==not_stored_yet->T,U,V,B;C),C,R)
   ),
   G= (N,Q,P,L,R).
generate_allocate_clauses([],A,A).
generate_allocate_clauses([C|D],A,B) :-
   generate_allocate_clause(C,A,E),
   generate_allocate_clauses(D,E,B).
allocate_constraint_goal(A,B,C,D) :-
   uses_state(A,not_stored_yet),
   ( chr_pp_flag(inline_insertremove,off) ->
     use_auxiliary_predicate(allocate_constraint,A),
     allocate_constraint_atom(A,B,C,D)
   ;
     D= (B=F,E),
     delay_phase_end(validate_store_type_assumptions,allocate_constraint_body(A,F,C,E))
   ).
allocate_constraint_atom(A,B,C,D) :-
   make_name('$allocate_constraint_',A,E),
   D=..[E,B|C].
generate_allocate_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(allocate_constraint,A) ->
     B=[D|C],
     D= (E:-F),
     A=_/G,
     length(H,G),
     allocate_constraint_atom(A,I,H,E),
     allocate_constraint_body(A,I,H,F)
   ;
     B=C
   ).
allocate_constraint_body(A,B,C,D) :-
   static_suspension_term(A,E),
   get_static_suspension_term_field(arguments,A,E,C),
   ( chr_pp_flag(debugable,on) ->
     A=F/_,
     get_static_suspension_term_field(functor,A,E,F)
   ;
     true
   ),
   ( chr_pp_flag(debugable,on) ->
     ( may_trigger(A) ->
       append(C,[B],G),
       build_head(_,_,[0],G,H),
       get_target_module(I),
       J=I:H
     ;
       J=true
     ),
     K= (B=E),
     create_static_suspension_field(A,E,continuation,J,L),
     create_static_suspension_field(A,E,generation,0,M)
   ;
     ( may_trigger(A),
       uses_field(A,generation) ->
       create_static_suspension_field(A,E,generation,0,M),
       B=E,
       K=true,
       L=true
     )
   ;
     M=true,
     B=E,
     K=true,
     L=true
   ),
   ( uses_history(A) ->
     create_static_suspension_field(A,E,history,t,N)
   ;
     N=true
   ),
   create_static_suspension_field(A,E,state,not_stored_yet,O),
   ( has_suspension_field(A,id) ->
     get_static_suspension_term_field(id,A,E,P),
     gen_id(P,Q)
   ;
     Q=true
   ),
   D= (K,L,M,N,O,Q).
gen_id(A,'chr gen_id'(A)).
generate_insert_constraint_internal_clauses([],A,A).
generate_insert_constraint_internal_clauses([C|D],A,B) :-
   generate_insert_constraint_internal_clause(C,A,E),
   generate_insert_constraint_internal_clauses(D,E,B).
insert_constraint_internal_constraint_goal(A,B,C,D,E,F) :-
   ( chr_pp_flag(inline_insertremove,off) ->
     use_auxiliary_predicate(remove_constraint_internal,A),
     insert_constraint_internal_constraint_atom(A,B,C,D,E,F)
   ;
     delay_phase_end(validate_store_type_assumptions,generate_insert_constraint_internal_body(A,C,D,E,B,F))
   ).
insert_constraint_internal_constraint_atom(A,B,C,D,E,F) :-
   insert_constraint_internal_constraint_name(A,G),
   ( chr_pp_flag(debugable,on) ->
     F=..[G,B,C,D|E]
   ;
     (
       (
         only_ground_indexed_arguments(A)
       ;
         get_store_type(A,var_assoc_store(_,_))
       ) ->
       F=..[G,C|E]
     )
   ;
     F=..[G,B,C|E]
   ).
insert_constraint_internal_constraint_name(A,B) :-
   make_name('$insert_constraint_internal_',A,B).
generate_insert_constraint_internal_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(insert_constraint_internal,A) ->
     B=[D|C],
     D= (E:-F),
     A=_/G,
     length(H,G),
     insert_constraint_internal_constraint_atom(A,I,J,K,H,E),
     generate_insert_constraint_internal_body(A,J,K,H,I,F)
   ;
     B=C
   ).
generate_insert_constraint_internal_body(A,B,C,D,E,F) :-
   static_suspension_term(A,G),
   create_static_suspension_field(A,G,state,active,H),
   ( chr_pp_flag(debugable,on) ->
     get_static_suspension_term_field(continuation,A,G,C),
     create_static_suspension_field(A,G,generation,0,I)
   ;
     ( may_trigger(A),
       uses_field(A,generation) ->
       create_static_suspension_field(A,G,generation,0,I)
     )
   ;
     I=true
   ),
   ( chr_pp_flag(debugable,on) ->
     A=J/_,
     get_static_suspension_term_field(functor,A,G,J)
   ;
     true
   ),
   ( uses_history(A) ->
     create_static_suspension_field(A,G,history,t,K)
   ;
     K=true
   ),
   get_static_suspension_term_field(arguments,A,G,D),
   _=[_|_],
   ( chr_pp_flag(debugable,off),
     (
       only_ground_indexed_arguments(A)
     ;
       get_store_type(A,var_assoc_store(_,_))
     ) ->
     suspension_term_base_fields(A,_),
     ( has_suspension_field(A,id) ->
       get_static_suspension_term_field(id,A,G,L),
       gen_id(L,M)
     ;
       M=true
     ),
     F= (B=G,H,I,K,M)
   ;
     ( has_suspension_field(A,id) ->
       get_static_suspension_term_field(id,A,G,L),
       gen_id(L,M)
     ;
       M=true
     ),
     generate_indexed_variables_body(A,D,N,E),
     chr_none_locked(E,O),
     F= (B=G,N,O,H,I,K,M)
   ).
generate_novel_production(A,B) :-
   ( is_used_auxiliary_predicate(novel_production) ->
     A=[C|B],
     C= ('$novel_production'(D,E):-arg(3,D,F),(hprolog:get_ds(E,F,_)->fail;true))
   ;
     A=B
   ).
generate_extend_history(A,B) :-
   ( is_used_auxiliary_predicate(extend_history) ->
     A=[C|B],
     C= ('$extend_history'(D,E):-arg(3,D,F),hprolog:put_ds(E,F,x,G),setarg(3,D,G))
   ;
     A=B
   ).
generate_empty_named_history_initialisations(A,B) :-
   empty_named_history_initialisations(A,B),
   find_empty_named_histories.
empty_named_history_global_variable(A,B) :-
   atom_concat('chr empty named history ',A,B).
empty_named_history_novel_production(A,nb_getval(B,0)) :-
   empty_named_history_global_variable(A,B).
empty_named_history_extend_history(A,b_setval(B,1)) :-
   empty_named_history_global_variable(A,B).
generate_run_suspensions_clauses([],A,A).
generate_run_suspensions_clauses([C|D],A,B) :-
   generate_run_suspensions_clause(C,A,E),
   generate_run_suspensions_clauses(D,E,B).
run_suspensions_goal(A,B,C) :-
   make_name('$run_suspensions_',A,D),
   C=..[D,B].
generate_run_suspensions_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(run_suspensions,A) ->
     B=[D,E|C],
     run_suspensions_goal(A,[],D),
     ( chr_pp_flag(debugable,on) ->
       run_suspensions_goal(A,[G|H],F),
       get_update_suspension_field(A,G,state,I,triggered,J,K,L),
       get_update_suspension_field(A,G,state,M,active,N,O,P),
       get_update_suspension_field(A,G,generation,Q,R,S,T,U),
       get_dynamic_suspension_term_field(continuation,A,G,V,W),
       run_suspensions_goal(A,H,X),
       E= (F:-J,K,(I==active->L,S,T,R is Q+1,U,W,('chr debug_event'(wake(G)),call(V);'chr debug_event'(fail(G)),!,fail),('chr debug_event'(exit(G));'chr debug_event'(redo(G)),fail),N,O,(M==triggered->P;true);true),X)
     ;
       run_suspensions_goal(A,[G|H],F),
       static_suspension_term(A,Y),
       get_static_suspension_term_field(arguments,A,Y,Z),
       append(Z,[G],A1),
       make_suspension_continuation_goal(A,A1,V),
       run_suspensions_goal(A,H,X),
       ( uses_field(A,generation) ->
         get_update_static_suspension_field(A,G,Y,generation,Q,R,S,U),
         B1= (S,R is Q+1,U)
       ;
         B1=true
       ),
       get_update_static_suspension_field(A,G,Y,state,I,triggered,J,L),
       get_update_static_suspension_field(A,G,Y,state,M,active,C1,D1),
       if_used_state(A,removed,(J,(I==active->F1;true)),F1,E1),
       F1= (L,B1,V,C1,(M==triggered->D1;true)),
       E= (F:-G=Y,E1,X)
     )
   ;
     B=C
   ).
generate_attach_increment(A) :-
   get_max_constraint_index(B),
   ( is_used_auxiliary_predicate(attach_increment),
     B>0 ->
     A=[C,D],
     generate_attach_increment_empty(C),
     ( B==1 ->
       generate_attach_increment_one(D)
     ;
       generate_attach_increment_many(B,D)
     )
   ;
     A=[]
   ).
generate_attach_increment_empty((attach_increment([],_):-true)).
generate_attach_increment_one(A) :-
   B=attach_increment([D|E],C),
   get_target_module(F),
   chr_not_locked(D,G),
   H= (G,(get_attr(D,F,I)->sort(I,J),'chr merge_attributes'(C,J,K),put_attr(D,F,K);put_attr(D,F,C)),attach_increment(E,C)),
   A= (B:-H).
generate_attach_increment_many(A,B) :-
   C=attach_increment([E|F],D),
   merge_attributes(A,D,G,H,I),
   get_target_module(J),
   chr_not_locked(E,K),
   L= (K,(get_attr(E,J,G)->H,put_attr(E,J,I);put_attr(E,J,D)),attach_increment(F,D)),
   B= (C:-L).
generate_attr_unify_hook(A) :-
   get_max_constraint_index(B),
   ( B==0 ->
     A=[]
   ;
     A=[C|D],
     C=attribute_goals(_,E,E),
     ( B==1 ->
       generate_attr_unify_hook_one(D)
     ;
       generate_attr_unify_hook_many(B,D)
     )
   ).
generate_attr_unify_hook_one([A]) :-
   B=attr_unify_hook(C,D),
   get_target_module(E),
   get_indexed_constraint(1,F),
   ( get_store_type(F,G),
     (
       G=default
     ;
       G=multi_store(H),
       memberchk(default,H)
     ) ->
     make_run_suspensions(I,J,K),
     make_run_suspensions(J,J,L),
     ( atomic_types_suspended_constraint(F) ->
       M=true,
       J=C,
       N=true,
       O=P,
       Q= (append(C,P,R),sort(R,I)),
       S=true
     ;
       M=sort(C,J),
       N=sort(P,O),
       Q='chr merge_attributes'(J,O,I),
       use_auxiliary_predicate(attach_increment),
       S= (compound(D)->term_variables(D,T),attach_increment(T,J);true)
     ),
     U= (M,(var(D)-> (get_attr(D,E,P)->N,Q,put_attr(D,E,I),K;put_attr(D,E,J),L);S,L)),
     A= (B:-U)
   ;
     ( get_store_type(F,var_assoc_store(_,_)) ->
       make_run_suspensions(R,R,K),
       Q=merge_into_assoc_store(C,P,R),
       U= (get_attr(D,E,P)->Q,K;put_attr(D,E,C)),
       A= (B:-U)
     )
   ).
generate_attr_unify_hook_many(A,[B]) :-
   chr_pp_flag(dynattr,off),
   !,
   C=attr_unify_hook(D,E),
   get_target_module(F),
   make_attr(A,G,H,D),
   bagof(I,K^L^ (member(K,H),I=sort(K,L)),J),
   list2conj(J,M),
   bagof(L,K^member(sort(K,L),J),N),
   merge_attributes2(A,G,N,O,P,Q),
   get_all_suspensions2(A,Q,R),
   make_attr(A,G,N,S),
   make_run_suspensions_loop(R,N,T),
   make_run_suspensions_loop(N,N,U),
   ( forall((between(1,A,V),get_indexed_constraint(V,W)),atomic_types_suspended_constraint(W)) ->
     X=true
   ;
     use_auxiliary_predicate(attach_increment),
     X= (compound(E)->term_variables(E,Y),attach_increment(Y,S);true)
   ),
   Z= (M,(var(E)-> (get_attr(E,F,O)->P,put_attr(E,F,Q),T;put_attr(E,F,S),U);X,U)),
   B= (C:-Z).
generate_attr_unify_hook_many(A,B) :-
   C=attr_unify_hook(D,E),
   get_target_module(F),
   normalize_attr(D,G,H),
   normalize_attr(I,J,K),
   merge_attributes(A,H,K,L,M),
   make_run_suspensions(A),
   ( forall((between(1,A,N),get_indexed_constraint(N,O)),atomic_types_suspended_constraint(O)) ->
     P=true
   ;
     use_auxiliary_predicate(attach_increment),
     P= (compound(E)->term_variables(E,Q),attach_increment(Q,H);true)
   ),
   R= (G,(var(E)-> (get_attr(E,F,I)->J,L,put_attr(E,F,M),'$dispatch_run_suspensions'(M);put_attr(E,F,H),'$dispatch_run_suspensions'(H));P,'$dispatch_run_suspensions'(H))),
   S= (C:-R),
   B=[S,T,U|V],
   T='$dispatch_run_suspensions'([]),
   U= ('$dispatch_run_suspensions'([X-Y|W]):-'$dispatch_run_suspensions'(X,Y),'$dispatch_run_suspensions'(W)),
   run_suspensions_dispatchers(A,[],V).
run_suspensions_dispatchers(A,B,C) :-
   ( A>0 ->
     get_indexed_constraint(A,D),
     E=[('$dispatch_run_suspensions'(A,G):-F)|B],
     ( may_trigger(D) ->
       run_suspensions_goal(D,G,F)
     ;
       F=true
     ),
     H is A-1,
     run_suspensions_dispatchers(H,E,C)
   ;
     C=B
   ).
make_run_suspensions(A) :-
   ( A>0 ->
     ( get_indexed_constraint(A,B),
       may_trigger(B) ->
       use_auxiliary_predicate(run_suspensions,B)
     ;
       true
     ),
     C is A-1,
     make_run_suspensions(C)
   ;
     true
   ).
make_run_suspensions(A,B,C) :-
   make_run_suspensions(1,A,B,C).
make_run_suspensions(A,B,C,D) :-
   ( get_indexed_constraint(A,E),
     may_trigger(E) ->
     use_auxiliary_predicate(run_suspensions,E),
     ( wakes_partially(E) ->
       run_suspensions_goal(E,C,D)
     ;
       run_suspensions_goal(E,B,D)
     )
   ;
     D=true
   ).
make_run_suspensions_loop(A,B,C) :-
   make_run_suspensions_loop(A,B,1,C).
make_run_suspensions_loop([],[],_,true).
make_run_suspensions_loop([B|C],[D|E],A,(F,G)) :-
   make_run_suspensions(A,B,D,F),
   H is A+1,
   make_run_suspensions_loop(C,E,H,G).
generate_insert_delete_constraints([],[]).
generate_insert_delete_constraints([B|C],A) :-
   ( is_stored(B) ->
     generate_insert_delete_constraint(B,A,D)
   ;
     A=D
   ),
   generate_insert_delete_constraints(C,D).
generate_insert_delete_constraint(A,B,C) :-
   insert_constraint_clause(A,B,D),
   delete_constraint_clause(A,D,C).
insert_constraint_goal(A,B,C,D) :-
   ( chr_pp_flag(inline_insertremove,off) ->
     use_auxiliary_predicate(insert_in_store,A),
     insert_constraint_atom(A,B,D)
   ;
     delay_phase_end(validate_store_type_assumptions,(insert_constraint_body(A,B,E,D),insert_constraint_direct_used_vars(E,C)))
   ).
insert_constraint_direct_used_vars([],_).
insert_constraint_direct_used_vars([C-D|B],A) :-
   nth1(C,A,D),
   insert_constraint_direct_used_vars(B,A).
insert_constraint_atom(A,B,C) :-
   make_name('$insert_in_store_',A,D),
   C=..[D,B].
insert_constraint_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(insert_in_store,A) ->
     B=[D|C],
     D= (E:-F,G,H),
     insert_constraint_atom(A,I,E),
     insert_constraint_body(A,I,J,H),
     insert_constraint_used_vars(J,A,I,G),
     ( chr_pp_flag(store_counter,on) ->
       F='$insert_counter_inc'
     ;
       F=true
     )
   ;
     B=C
   ).
insert_constraint_used_vars([],_,_,true).
insert_constraint_used_vars([D-E|C],A,B,(F,G)) :-
   get_dynamic_suspension_term_field(argument(D),A,B,E,F),
   insert_constraint_used_vars(C,A,B,G).
insert_constraint_body(A,B,C,D) :-
   get_store_type(A,E),
   insert_constraint_body(E,A,B,C,D).
insert_constraint_body(default,A,B,[],C) :-
   global_list_store_name(A,D),
   make_get_store_goal(D,E,F),
   make_update_store_goal(D,G,H),
   ( chr_pp_flag(debugable,on) ->
     G=[B|E],
     C= (F,H)
   ;
     set_dynamic_suspension_term_field(global_list_prev,A,I,G,J),
     C= (F,G=[B|E],H,(E=[I|_]->J;true))
   ).
insert_constraint_body(multi_inthash(D),A,B,[],C) :-
   generate_multi_inthash_insert_constraint_bodies(D,A,B,C).
insert_constraint_body(multi_hash(E),A,B,C,D) :-
   generate_multi_hash_insert_constraint_bodies(E,A,B,D,C),
   sort_out_used_vars(C,_).
insert_constraint_body(atomic_constants(E,_,_),A,B,C,D) :-
   multi_hash_key_direct(A,E,B,F,C),
   constants_store_index_name(A,E,G),
   H=..[G,F,I],
   D= (H->nb_getval(I,J),b_setval(I,[B|J]);true).
insert_constraint_body(ground_constants(E,_,_),A,B,C,D) :-
   multi_hash_key_direct(A,E,B,F,C),
   constants_store_index_name(A,E,G),
   H=..[G,F,I],
   D= (H->nb_getval(I,J),b_setval(I,[B|J]);true).
insert_constraint_body(global_ground,A,B,[],C) :-
   global_ground_store_name(A,D),
   make_get_store_goal(D,E,F),
   make_update_store_goal(D,G,H),
   ( chr_pp_flag(debugable,on) ->
     G=[B|E],
     C= (F,H)
   ;
     set_dynamic_suspension_term_field(global_list_prev,A,I,G,J),
     C= (F,G=[B|E],H,(E=[I|_]->J;true))
   ).
insert_constraint_body(var_assoc_store(C,D),_,A,[C-E,D-F],B) :-
   get_target_module(G),
   B= (get_attr(E,G,H)->insert_assoc_store(H,F,A);new_assoc_store(H),put_attr(E,G,H),insert_assoc_store(H,F,A)).
insert_constraint_body(global_singleton,A,B,[],C) :-
   global_singleton_store_name(A,D),
   make_update_store_goal(D,B,E),
   C=E.
insert_constraint_body(multi_store(E),A,B,C,D) :-
   maplist(insert_constraint_body1(A,B),E,F,G),
   list2conj(G,D),
   sort_out_used_vars(F,C).
insert_constraint_body1(A,B,C,D,E) :-
   insert_constraint_body(C,A,B,D,E).
insert_constraint_body(identifier_store(E),A,B,C,D) :-
   C=[E-F],
   get_identifier_size(G),
   functor(H,struct,G),
   get_identifier_index(A,E,I),
   arg(I,H,J),
   D= (F=H,setarg(I,F,[B|J])).
insert_constraint_body(type_indexed_identifier_store(E,F),A,B,C,D) :-
   C=[E-G],
   type_indexed_identifier_structure(F,H),
   get_type_indexed_identifier_index(F,A,E,I),
   arg(I,H,J),
   D= (G=H,setarg(I,G,[B|J])).
sort_out_used_vars(A,B) :-
   flatten(A,C),
   sort(C,D),
   sort_out_used_vars1(D,B).
sort_out_used_vars1([],[]).
sort_out_used_vars1([B-C],A) :-
   !,
   A=[B-C].
sort_out_used_vars1([B-C,E-F|D],A) :-
   ( B==E ->
     C=F,
     sort_out_used_vars1([B-C|D],A)
   ;
     A=[B-C|G],
     sort_out_used_vars1([E-F|D],G)
   ).
generate_multi_inthash_insert_constraint_bodies([],_,_,true).
generate_multi_inthash_insert_constraint_bodies([C|D],A,B,(E,F)) :-
   multi_hash_store_name(A,C,G),
   multi_hash_key(A,C,B,H,I),
   E= (H,nb_getval(G,J),insert_iht(J,I,B)),
   generate_multi_inthash_insert_constraint_bodies(D,A,B,F).
generate_multi_hash_insert_constraint_bodies([],_,_,true,[]).
generate_multi_hash_insert_constraint_bodies([C|D],A,B,(E,F),[G|H]) :-
   multi_hash_store_name(A,C,I),
   multi_hash_key_direct(A,C,B,J,G),
   make_get_store_goal(I,K,L),
   ( chr_pp_flag(ht_removal,on) ->
     ht_prev_field(C,M),
     set_dynamic_suspension_term_field(M,A,N,O,P),
     E= (L,insert_ht(K,J,B,O),(O=[_,N|_]->P;true))
   ;
     E= (L,insert_ht(K,J,B))
   ),
   generate_multi_hash_insert_constraint_bodies(D,A,B,F,H).
delete_constraint_clause(A,B,C) :-
   ( is_used_auxiliary_predicate(delete_from_store,A) ->
     B=[D|C],
     D= (E:-F),
     delete_constraint_atom(A,G,E),
     A=H/I,
     functor(E,H,I),
     delete_constraint_body(A,E,G,[],F)
   ;
     B=C
   ).
delete_constraint_goal(A,B,C,D) :-
   functor(A,E,F),
   G=E/F,
   ( chr_pp_flag(inline_insertremove,off) ->
     use_auxiliary_predicate(delete_from_store,G),
     delete_constraint_atom(G,B,D)
   ;
     delay_phase_end(validate_store_type_assumptions,delete_constraint_body(G,A,B,C,D))
   ).
delete_constraint_atom(A,B,C) :-
   make_name('$delete_from_store_',A,D),
   C=..[D,B].
delete_constraint_body(A,B,C,D,E) :-
   E= (F,G),
   ( chr_pp_flag(store_counter,on) ->
     F='$delete_counter_inc'
   ;
     F=true
   ),
   get_store_type(A,H),
   delete_constraint_body(H,A,B,C,D,G).
delete_constraint_body(default,A,_,B,_,C) :-
   ( chr_pp_flag(debugable,on) ->
     global_list_store_name(A,D),
     make_get_store_goal(D,E,F),
     make_update_store_goal(D,G,H),
     C= (F,'chr sbag_del_element'(E,B,G),H)
   ;
     get_dynamic_suspension_term_field(global_list_prev,A,B,I,J),
     global_list_store_name(A,D),
     make_get_store_goal(D,E,F),
     make_update_store_goal(D,K,H),
     set_dynamic_suspension_term_field(global_list_prev,A,L,_,M),
     set_dynamic_suspension_term_field(global_list_prev,A,L,I,N),
     C= (J,(var(I)->F,E=[_|K],H,(K=[L|_]->M;true);I=[_,_|K],setarg(2,I,K),(K=[L|_]->N;true)))
   ).
delete_constraint_body(multi_inthash(D),A,_,B,_,C) :-
   generate_multi_inthash_delete_constraint_bodies(D,A,B,C).
delete_constraint_body(multi_hash(F),A,B,C,D,E) :-
   generate_multi_hash_delete_constraint_bodies(F,A,B,C,D,E).
delete_constraint_body(atomic_constants(F,_,_),A,B,C,D,E) :-
   multi_hash_key(A,B,F,C,D,G,H),
   constants_store_index_name(A,F,I),
   J=..[I,H,K],
   E= (G,(J->nb_getval(K,L),'chr sbag_del_element'(L,C,M),b_setval(K,M);true)).
delete_constraint_body(ground_constants(F,_,_),A,B,C,D,E) :-
   multi_hash_key(A,B,F,C,D,G,H),
   constants_store_index_name(A,F,I),
   J=..[I,H,K],
   E= (G,(J->nb_getval(K,L),'chr sbag_del_element'(L,C,M),b_setval(K,M);true)).
delete_constraint_body(global_ground,A,_,B,_,C) :-
   ( chr_pp_flag(debugable,on) ->
     global_ground_store_name(A,D),
     make_get_store_goal(D,E,F),
     make_update_store_goal(D,G,H),
     C= (F,'chr sbag_del_element'(E,B,G),H)
   ;
     get_dynamic_suspension_term_field(global_list_prev,A,B,I,J),
     global_ground_store_name(A,D),
     make_get_store_goal(D,E,F),
     make_update_store_goal(D,K,H),
     set_dynamic_suspension_term_field(global_list_prev,A,L,_,M),
     set_dynamic_suspension_term_field(global_list_prev,A,L,I,N),
     C= (J,(var(I)->F,E=[_|K],H,(K=[L|_]->M;true);I=[_,_|K],setarg(2,I,K),(K=[L|_]->N;true)))
   ).
delete_constraint_body(var_assoc_store(D,E),A,_,B,_,C) :-
   get_target_module(F),
   get_dynamic_suspension_term_field(argument(D),A,B,G,H),
   get_dynamic_suspension_term_field(argument(E),A,B,I,J),
   C= (H,get_attr(G,F,K),J,delete_assoc_store(K,I,B)).
delete_constraint_body(global_singleton,A,_,_,_,B) :-
   global_singleton_store_name(A,C),
   make_update_store_goal(C,[],D),
   B=D.
delete_constraint_body(multi_store(F),A,B,C,D,E) :-
   maplist(delete_constraint_body1(A,B,C,D),F,G),
   list2conj(G,E).
delete_constraint_body1(A,B,C,D,E,F) :-
   delete_constraint_body(E,A,B,C,D,F).
delete_constraint_body(identifier_store(F),A,B,C,D,E) :-
   get_suspension_argument_possibly_in_scope(B,D,C,F,G,H),
   get_identifier_size(I),
   functor(J,struct,I),
   get_identifier_index(A,F,K),
   arg(K,J,L),
   E= (H,G=J,'chr sbag_del_element'(L,C,M),setarg(K,G,M)).
delete_constraint_body(type_indexed_identifier_store(F,G),A,B,C,D,E) :-
   get_suspension_argument_possibly_in_scope(B,D,C,F,H,I),
   type_indexed_identifier_structure(G,J),
   get_type_indexed_identifier_index(G,A,F,K),
   arg(K,J,L),
   E= (I,H=J,'chr sbag_del_element'(L,C,M),setarg(K,H,M)).
generate_multi_inthash_delete_constraint_bodies([],_,_,true).
generate_multi_inthash_delete_constraint_bodies([C|D],A,B,(E,F)) :-
   multi_hash_store_name(A,C,G),
   multi_hash_key(A,C,B,H,I),
   E= (H,nb_getval(G,J),delete_iht(J,I,B)),
   generate_multi_inthash_delete_constraint_bodies(D,A,B,F).
generate_multi_hash_delete_constraint_bodies([],_,_,_,_,true).
generate_multi_hash_delete_constraint_bodies([E|F],A,B,C,D,(G,H)) :-
   multi_hash_store_name(A,E,I),
   multi_hash_key(A,B,E,C,D,J,K),
   make_get_store_goal(I,L,M),
   ( chr_pp_flag(ht_removal,on) ->
     ht_prev_field(E,N),
     get_dynamic_suspension_term_field(N,A,C,O,P),
     set_dynamic_suspension_term_field(N,A,Q,_,R),
     set_dynamic_suspension_term_field(N,A,Q,O,S),
     G= (P,(var(O)->M,J,delete_first_ht(L,K,T),(T=[Q|_]->R;true);O=[_,_|T],setarg(2,O,T),(T=[Q|_]->S;true)))
   ;
     G= (J,M,delete_ht(L,K,C))
   ),
   generate_multi_hash_delete_constraint_bodies(F,_,B,C,D,H).
generate_attach_code(A,B) :-
   enumerate_stores_code(A,C),
   append(C,D,B),
   generate_attach_code(A,D,E),
   module_initializers(F),
   prolog_global_variables_code(G),
   E=[('$chr_initialization':-F),(:-initialization '$chr_initialization')|G].
generate_attach_code([],A,A).
generate_attach_code([C|D],A,B) :-
   get_store_type(C,E),
   generate_attach_code(E,C,A,F),
   generate_attach_code(D,F,B).
generate_attach_code(default,A,B,C) :-
   global_list_store_initialisation(A,B,C).
generate_attach_code(multi_inthash(D),A,B,C) :-
   multi_inthash_store_initialisations(D,A,B,E),
   multi_inthash_via_lookups(D,A,E,C).
generate_attach_code(multi_hash(D),A,B,C) :-
   multi_hash_store_initialisations(D,A,B,E),
   multi_hash_lookups(D,A,E,C).
generate_attach_code(atomic_constants(D,E,_),A,B,C) :-
   constants_initializers(A,D,E),
   atomic_constants_code(A,D,E,B,C).
generate_attach_code(ground_constants(D,E,_),A,B,C) :-
   constants_initializers(A,D,E),
   ground_constants_code(A,D,E,B,C).
generate_attach_code(global_ground,A,B,C) :-
   global_ground_store_initialisation(A,B,C).
generate_attach_code(var_assoc_store(_,_),_,A,A) :-
   use_auxiliary_module(chr_assoc_store).
generate_attach_code(global_singleton,A,B,C) :-
   global_singleton_store_initialisation(A,B,C).
generate_attach_code(multi_store(D),A,B,C) :-
   multi_store_generate_attach_code(D,A,B,C).
generate_attach_code(identifier_store(D),A,B,C) :-
   get_identifier_index(A,D,E),
   ( E==2 ->
     get_identifier_size(F),
     functor(G,struct,F),
     G=..[_,H|I],
     set_elems(I,[]),
     J=new_identifier(H,G),
     functor(K,struct,F),
     arg(1,K,L),
     M= (user:portray(K):-write('<id:'),print(L),write(>)),
     functor(N,struct,F),
     arg(1,N,O),
     P=identifier_label(N,O),
     B=[J,M,P|C]
   ;
     B=C
   ).
generate_attach_code(type_indexed_identifier_store(D,E),A,B,C) :-
   get_type_indexed_identifier_index(E,A,D,F),
   ( F==2 ->
     identifier_store_initialization(E,B,G),
     get_type_indexed_identifier_size(E,_),
     type_indexed_identifier_structure(E,H),
     H=..[_,I|J],
     set_elems(J,[]),
     type_indexed_identifier_name(E,new_identifier,K),
     L=..[K,I,H],
     M=..[K,N,O],
     type_indexed_identifier_structure(E,P),
     P=..[_,N|Q],
     set_elems(Q,[]),
     R= (O=P),
     S=user:goal_expansion(M,R),
     type_indexed_identifier_structure(E,T),
     arg(1,T,U),
     V= (user:portray(T):-write('<id:'),print(U),write(>)),
     type_indexed_identifier_structure(E,W),
     arg(1,W,X),
     type_indexed_identifier_name(E,identifier_label,Y),
     Z=..[Y,W,X],
     A1=..[Y,B1,C1],
     type_indexed_identifier_structure(E,D1),
     arg(1,D1,C1),
     E1= (B1=D1),
     F1= (user:goal_expansion(A1,E1):-writeln(expanding)),
     identifier_store_name(E,G1),
     lookup_identifier_atom(E,H1,I1,J1),
     type_indexed_identifier_name(E,new_identifier,K1),
     L1=..[K1,H1,I1],
     M1= (J1:-nb_getval(G1,N1),(lookup_ht(N1,H1,[I1])->true;L1,insert_ht(N1,H1,I1))),
     lookup_only_identifier_atom(E,O1,P1,Q1),
     R1= (Q1:-nb_getval(G1,S1),lookup_ht(S1,O1,[P1])),
     G=[(:-multifile goal_expansion/2),(:-dynamic goal_expansion/2),L,S,V,Z,F1,M1,R1|C]
   ;
     B=C
   ).
constants_initializers(A,B,C) :-
   maplist(constant_initializer(A,B),C).
constant_initializer(A,B,C) :-
   constants_store_name(A,B,C,D),
   prolog_global_variable(D),
   module_initializer(nb_setval(D,[])).
lookup_identifier_atom(A,B,C,D) :-
   atom_concat(lookup_identifier_,A,E),
   D=..[E,B,C].
lookup_only_identifier_atom(A,B,C,D) :-
   atom_concat(lookup_only_identifier_,A,E),
   D=..[E,B,C].
identifier_label_atom(A,B,C,D) :-
   type_indexed_identifier_name(A,identifier_label,E),
   D=..[E,B,C].
multi_store_generate_attach_code([],_,A,A).
multi_store_generate_attach_code([D|E],A,B,C) :-
   generate_attach_code(D,A,B,F),
   multi_store_generate_attach_code(E,A,F,C).
multi_inthash_store_initialisations([],_,A,A).
multi_inthash_store_initialisations([D|E],A,B,C) :-
   use_auxiliary_module(chr_integertable_store),
   multi_hash_store_name(A,D,F),
   module_initializer((new_iht(G),nb_setval(F,G))),
   H=B,
   multi_inthash_store_initialisations(E,A,H,C).
multi_hash_store_initialisations([],_,A,A).
multi_hash_store_initialisations([D|E],A,B,C) :-
   use_auxiliary_module(chr_hashtable_store),
   multi_hash_store_name(A,D,F),
   prolog_global_variable(F),
   make_init_store_goal(F,G,H),
   module_initializer((new_ht(G),H)),
   I=B,
   multi_hash_store_initialisations(E,A,I,C).
global_list_store_initialisation(A,B,C) :-
   ( is_stored(A) ->
     global_list_store_name(A,D),
     prolog_global_variable(D),
     make_init_store_goal(D,[],E),
     module_initializer(E)
   ;
     true
   ),
   B=C.
global_ground_store_initialisation(A,B,C) :-
   global_ground_store_name(A,D),
   prolog_global_variable(D),
   make_init_store_goal(D,[],E),
   module_initializer(E),
   B=C.
global_singleton_store_initialisation(A,B,C) :-
   global_singleton_store_name(A,D),
   prolog_global_variable(D),
   make_init_store_goal(D,[],E),
   module_initializer(E),
   B=C.
identifier_store_initialization(A,B,C) :-
   use_auxiliary_module(chr_hashtable_store),
   identifier_store_name(A,D),
   prolog_global_variable(D),
   make_init_store_goal(D,E,F),
   module_initializer((new_ht(E),F)),
   B=C.
multi_inthash_via_lookups([],_,A,A).
multi_inthash_via_lookups([D|E],A,B,C) :-
   multi_hash_lookup_head(A,D,F,G,H),
   multi_hash_lookup_body(A,inthash,D,F,G,I),
   B=[(H:-I)|J],
   multi_inthash_via_lookups(E,A,J,C).
multi_hash_lookups([],_,A,A).
multi_hash_lookups([D|E],A,B,C) :-
   multi_hash_lookup_head(A,D,F,G,H),
   multi_hash_lookup_body(A,hash,D,F,G,I),
   B=[(H:-I)|J],
   multi_hash_lookups(E,A,J,C).
multi_hash_lookup_head(A,B,C,D,E) :-
   multi_hash_lookup_name(A,B,F),
   E=..[F,C,D].
multi_hash_lookup_body(A,B,C,D,E,F) :-
   get_store_type(A,multi_store(G)),
   ( memberchk(atomic_constants(C,H,_),G) ->
     ( ground(D) ->
       constants_store_name(A,C,D,I),
       F=nb_getval(I,E)
     ;
       constants_store_index_name(A,C,J),
       K=..[J,D,I],
       F= (K,nb_getval(I,E))
     )
   ;
     ( memberchk(ground_constants(C,H,_),G) ->
       ( ground(D) ->
         constants_store_name(A,C,D,I),
         F=nb_getval(I,E)
       ;
         constants_store_index_name(A,C,J),
         K=..[J,D,I],
         F= (K,nb_getval(I,E))
       )
     )
   ;
     ( memberchk(multi_hash([C]),G) ->
       multi_hash_store_name(A,C,I),
       make_get_store_goal(I,L,M),
       ( B==hash,
         specialized_hash_term_call(A,C,D,N,O) ->
         F= (M,O,lookup_ht1(L,N,D,E))
       ;
         lookup_hash_call(B,L,D,E,K),
         F= (M,K)
       )
     )
   ;
     ( B==inthash ->
       multi_hash_store_name(A,C,I),
       make_get_store_goal(I,L,M),
       lookup_hash_call(B,L,D,E,K),
       F= (M,K)
     )
   ).
lookup_hash_call(hash,A,B,C,lookup_ht(A,B,C)).
lookup_hash_call(inthash,A,B,C,lookup_iht(A,B,C)).
specialized_hash_term_call(_,_,A,B,C) :-
   ( ground(A) ->
     hash_term(A,B),
     C=true
   ).
multi_hash_lookup_goal(A,B,C,D,E,F) :-
   ( atomic(D) ->
     actual_atomic_multi_hash_keys(A,C,[D])
   ;
     ( ground(D) ->
       actual_ground_multi_hash_keys(A,C,[D])
     )
   ;
     ( C=[G],
       get_constraint_arg_type(A,G,H),
       is_chr_constants_type(H,_,_) ->
       true
     )
   ;
     actual_non_ground_multi_hash_key(A,C)
   ),
   delay_phase_end(validate_store_type_assumptions,multi_hash_lookup_body(A,B,C,D,E,F)).
multi_hash_lookup_name(C/D,A,B) :-
   atom_concat_list(A,E),
   atom_concat_list(['$via1_multi_hash_',C,'___',D,-,E],B).
multi_hash_store_name(C/D,A,B) :-
   get_target_module(E),
   atom_concat_list(A,F),
   atom_concat_list(['$chr_store_multi_hash_',E,'____',C,'___',D,-,F],B).
multi_hash_key(A,B,C,D,E) :-
   ( B=[F] ->
     get_dynamic_suspension_term_field(argument(F),A,C,E,D)
   ;
     maplist(get_dynamic_suspension_term_field1(A,C),B,G,H),
     E=..[k|G],
     list2conj(H,D)
   ).
get_dynamic_suspension_term_field1(A,B,C,D,E) :-
   get_dynamic_suspension_term_field(argument(C),A,B,D,E).
multi_hash_key(_,A,B,C,D,E,F) :-
   ( B=[G] ->
     get_suspension_argument_possibly_in_scope(A,D,C,G,F,E)
   ;
     maplist(get_suspension_argument_possibly_in_scope(A,D,C),B,H,I),
     F=..[k|H],
     list2conj(I,E)
   ).
get_suspension_argument_possibly_in_scope(A,B,C,D,E,F) :-
   arg(D,A,G),
   ( ground(G),
     G='$chr_identifier_match'(H,I) ->
     functor(A,J,K),
     lookup_identifier_atom(I,H,E,F)
   ;
     ( term_variables(G,L),
       copy_term_nat(G-L,E-M),
       translate(L,B,M) ->
       F=true
     )
   ;
     functor(A,J,K),
     N=J/K,
     get_dynamic_suspension_term_field(argument(D),N,C,E,F)
   ).
multi_hash_key_direct(_,A,_,B,C) :-
   ( A=[D] ->
     C=[D-B]
   ;
     pairup(A,E,C),
     B=..[k|E]
   ).
args(A,B,C) :-
   maplist(arg1(B),A,C).
split_args(A,B,C,D) :-
   split_args(A,B,1,C,D).
split_args([],A,_,[],A).
split_args([D|E],[F|G],A,B,C) :-
   H is A+1,
   ( D==A ->
     B=[F|I],
     split_args(E,G,H,I,C)
   ;
     C=[F|I],
     split_args([D|E],G,H,B,I)
   ).
atomic_constants_code(A,B,C,D,E) :-
   constants_store_index_name(A,B,F),
   maplist(atomic_constant_code(A,B,F),C,G),
   append(G,E,D).
atomic_constant_code(A,B,C,D,E) :-
   constants_store_name(A,B,D,F),
   E=..[C,D,F].
ground_constants_code(A,B,C,D,E) :-
   constants_store_index_name(A,B,F),
   maplist(constants_store_name(A,B),C,G),
   length(C,H),
   replicate(H,[],I),
   trie_index([C|I],G,F,D,E).
constants_store_name(D/E,A,B,C) :-
   get_target_module(F),
   term_to_atom(B,G),
   term_to_atom(A,H),
   atom_concat_list(['$chr_store_constants_',F,'____',D,'___',E,'___',H,'___',G],C).
constants_store_index_name(C/D,A,B) :-
   get_target_module(E),
   term_to_atom(A,F),
   atom_concat_list(['$chr_store_constants_',E,'____',C,'___',D,'___',F],B).
trie_index([E|F],A,B,C,D) :-
   trie_step(E,B,B,F,A,C,D).
trie_step([],_,_,[],[],A,A) :-
   !.
trie_step(A,B,C,D,E,F,G) :-
   D=[H|_],
   length(H,I),
   aggregate_all(set(K/L),(member(M,A),functor(M,K,L)),J),
   N is I+1,
   trie_step_cases(J,N,A,D,E,B,C,F,G).
trie_step_cases([],_,_,_,_,_,_,A,A).
trie_step_cases([I|J],A,B,C,D,E,F,G,H) :-
   trie_step_case(I,A,B,C,D,E,F,G,K),
   trie_step_cases(J,A,B,C,D,E,F,K,H).
trie_step_case(H/I,A,B,C,D,E,F,[J|K],G) :-
   J= (L:-M),
   N is A+1,
   functor(L,E,N),
   arg(1,L,O),
   L=..[_,_|P],
   once(append(Q,[R],P)),
   functor(O,H,I),
   O=..[_|S],
   append(S,P,T),
   ( T==[R] ->
     K=G,
     M=true,
     rec_cases(B,_,D,H/I,_,_,U),
     U=[R]
   ;
     rec_cases(B,C,D,H/I,V,W,U),
     ( W=[X] ->
       K=G,
       M=true,
       append([V,X,U],T)
     ;
       pairup(V,W,Y),
       common_pattern(Y,Z,A1,B1),
       append(S,Q,[C1|D1]),
       C1-D1=Z,
       fresh_symbol(F,E1),
       append(A1,[R],F1),
       M=..[E1|F1],
       maplist(head_tail,B1,G1,H1),
       trie_step(G1,E1,F,H1,U,K,G)
     )
   ).
head_tail([A|B],A,B).
rec_cases([],[],[],_,[],[],[]).
rec_cases([D|E],[F|G],[H|I],J/K,A,B,C) :-
   ( functor(D,J,K),
     D=..[_|L],
     append(L,F,[M|N]) ->
     A=[M|O],
     B=[N|P],
     C=[H|Q],
     rec_cases(E,G,I,J/K,O,P,Q)
   ;
     rec_cases(E,G,I,J/K,A,B,C)
   ).
common_pattern(A,B,C,D) :-
   fold1(chr_translate:gct,A,B),
   term_variables(B,C),
   findall(C,member(B,A),D).
gct(A,B,C) :-
   gct_(A,B,C,[],_).
gct_(A,B,C,D,E) :-
   ( nonvar(A),
     nonvar(B),
     functor(A,F,G),
     functor(B,H,I),
     F==H,
     G==I ->
     functor(C,F,G),
     A=..[_|J],
     B=..[_|K],
     C=..[_|L],
     maplist_dcg(chr_translate:gct_,J,K,L,D,E)
   ;
     ( lookup_eq(D,A+B,C) ->
       E=D
     )
   ;
     E=[A+B-C|D]
   ).
global_list_store_name(B/C,A) :-
   get_target_module(D),
   atom_concat_list(['$chr_store_global_list_',D,'____',B,'___',C],A).
global_ground_store_name(B/C,A) :-
   get_target_module(D),
   atom_concat_list(['$chr_store_global_ground_',D,'____',B,'___',C],A).
global_singleton_store_name(B/C,A) :-
   get_target_module(D),
   atom_concat_list(['$chr_store_global_singleton_',D,'____',B,'___',C],A).
identifier_store_name(A,B) :-
   get_target_module(C),
   atom_concat_list(['$chr_identifier_lookup_',C,'____',A],B).
prolog_global_variables_code(A) :-
   prolog_global_variables(B),
   ( B==[] ->
     A=[]
   ;
     maplist(wrap_in_functor('$chr_prolog_global_variable'),B,C),
     A=[(:-dynamic user:exception/3),(:-multifile user:exception/3),(user:exception(undefined_global_variable,D,retry):-'$chr_prolog_global_variable'(D),'$chr_initialization')|C]
   ).
sbag_member_call(A,B,'chr sbag_member'(A,B)).
update_mutable_call(A,B,'chr update_mutable'(A,B)).
create_mutable_call(A,B,true) :-
   B=mutable(A).
get_suspension_field(A,B,C,D,E) :-
   get_dynamic_suspension_term_field(C,A,B,D,E).
update_suspension_field(A,B,C,D,E) :-
   set_dynamic_suspension_term_field(C,A,B,D,E).
get_update_suspension_field(A,B,C,D,E,true,F,G) :-
   get_dynamic_suspension_term_field(C,A,B,D,F),
   set_dynamic_suspension_term_field(C,A,B,E,G).
create_static_suspension_field(A,B,C,D,true) :-
   get_static_suspension_term_field(C,A,B,D).
get_static_suspension_field(A,B,C,D,true) :-
   get_static_suspension_term_field(C,A,B,D).
get_update_static_suspension_field(A,B,C,D,E,F,true,G) :-
   get_static_suspension_term_field(D,A,C,E),
   set_dynamic_suspension_term_field(D,A,B,F,G).
enumerate_stores_code(A,[B|C]) :-
   D='$enumerate_constraints'(E),
   B= (D:-F),
   enumerate_store_bodies(A,E,C),
   ( C=[] ->
     F=fail
   ;
     F= (nonvar(E)->functor(E,G,_),'$enumerate_constraints'(G,E);'$enumerate_constraints'(_,E))
   ).
enumerate_store_bodies([],_,[]).
enumerate_store_bodies([C|D],A,B) :-
   ( is_stored(C) ->
     get_store_type(C,E),
     ( enumerate_store_body(E,C,F,G) ->
       true
     ;
       chr_error(internal,'Could not generate enumeration code for constraint ~w.\n',[C])
     ),
     get_dynamic_suspension_term_field(arguments,C,F,H,I),
     C=J/_,
     K=..[J|H],
     L='$enumerate_constraints'(J,A),
     M= (G,I,A=K),
     B=[(L:-M)|N]
   ;
     B=N
   ),
   enumerate_store_bodies(D,A,N).
enumerate_store_body(default,A,B,C) :-
   global_list_store_name(A,D),
   sbag_member_call(B,E,F),
   make_get_store_goal(D,E,G),
   C= (G,F).
enumerate_store_body(multi_inthash([D|_]),A,B,C) :-
   multi_inthash_enumerate_store_body(D,A,B,C).
enumerate_store_body(multi_hash([D|_]),A,B,C) :-
   multi_hash_enumerate_store_body(D,A,B,C).
enumerate_store_body(atomic_constants(D,E,F),A,B,C) :-
   F==complete,
   maplist(enumerate_constant_store_body(A,D,H),E,G),
   list2disj(G,I),
   C= (I,member(B,H)).
enumerate_constant_store_body(A,B,C,D,nb_getval(E,C)) :-
   constants_store_name(A,B,D,E).
enumerate_store_body(ground_constants(D,E,F),A,B,C) :-
   enumerate_store_body(atomic_constants(D,E,F),A,B,C).
enumerate_store_body(global_ground,A,B,C) :-
   global_ground_store_name(A,D),
   sbag_member_call(B,E,F),
   make_get_store_goal(D,E,G),
   C= (G,F).
enumerate_store_body(var_assoc_store(_,_),_,_,A) :-
   A=fail.
enumerate_store_body(global_singleton,A,B,C) :-
   global_singleton_store_name(A,D),
   make_get_store_goal(D,B,E),
   C= (E,B\==[]).
enumerate_store_body(multi_store(D),A,B,C) :-
   ( memberchk(global_ground,D) ->
     enumerate_store_body(global_ground,A,B,C)
   ;
     once((member(E,D),enumerate_store_body(E,A,B,C)))
   ).
enumerate_store_body(identifier_store(_),_,_,A) :-
   A=fail.
enumerate_store_body(type_indexed_identifier_store(_,_),_,_,A) :-
   A=fail.
multi_inthash_enumerate_store_body(A,B,C,D) :-
   multi_hash_store_name(B,A,E),
   D= (nb_getval(E,F),value_iht(F,C)).
multi_hash_enumerate_store_body(A,B,C,D) :-
   multi_hash_store_name(B,A,E),
   make_get_store_goal(E,F,G),
   D= (G,value_ht(F,C)).
guard_simplification :-
   ( chr_pp_flag(guard_simplification,on) ->
     precompute_head_matchings,
     simplify_guards(1)
   ;
     true
   ).
next_prev_rule(A,B,C) :-
   ( find_min_q(A,_-D) ->
     D= (-B),
     normalize_heap(A,D,C)
   ;
     B=0,
     C=A
   ).
normalize_heap(A,B,C) :-
   ( find_min_q(A,_-B) ->
     delete_min_q(A,D,tuple(E,F,_)-_),
     ( F>1 ->
       G is F-1,
       get_occurrence(E,G,H,_),
       insert_q(D,tuple(E,G,H)- (-H),I)
     ;
       I=D
     ),
     normalize_heap(I,B,C)
   ;
     C=A
   ).
head_types_modes_condition([],_,true).
head_types_modes_condition([B|C],A,(D,E)) :-
   types_modes_condition(A,B,D),
   head_types_modes_condition(C,A,E).
add_background_info(A,B) :-
   get_bg_info(C),
   add_background_info2(A,D),
   append(C,D,B).
add_background_info2(A,[]) :-
   var(A),
   !.
add_background_info2([],[]) :-
   !.
add_background_info2([B|C],A) :-
   !,
   add_background_info2(B,D),
   add_background_info2(C,E),
   append(D,E,A).
add_background_info2(A,B) :-
   ( functor(A,_,C),
     C>0 ->
     A=..[_|D],
     add_background_info2(D,E)
   ;
     E=[]
   ),
   get_bg_info(A,F),
   append(F,E,B).
normalize_conj_list(A,B) :-
   list2conj(A,C),
   conj2list(C,B).
compute_derived_info([],_,_,_,_,_,_,_,[],[]).
compute_derived_info([H|I],A,B,C,D,E,F,G,[J|K],[L|M]) :-
   copy_term(A-D,N),
   variable_replacement(A-D,N,O),
   append(H,O,P),
   list2conj(A,Q),
   negate_b(Q,R),
   make_head_matchings_explicit_not_negated2(C,B,S),
   list2conj(S,T),
   term_variables(P,U),
   term_variables(A-D-S,V),
   new_vars(V,U,W),
   append(P,W,X),
   ( D==true ->
     Y=R
   ;
     negate_b(D,Z),
     Y= (R;T,Z)
   ),
   copy_with_variable_replacement(Y,J,X),
   copy_with_variable_replacement(D,A1,X),
   copy_with_variable_replacement(A,B1,X),
   list2conj(B1,C1),
   apply_guard_wrt_term(F,A1,D1),
   apply_guard_wrt_term(D1,C1,L),
   compute_derived_info(I,A,B,C,D,E,F,G,K,M).
simplify_guard(A,B,C,D,E) :-
   conj2list(A,F),
   guard_entailment:simplify_guards(C,B,F,G,E),
   list2conj(G,D).
new_vars([],_,[]).
new_vars([C|D],A,B) :-
   ( memberchk_eq(C,A) ->
     new_vars(D,A,B)
   ;
     B=[C-E,E-C|F],
     new_vars(D,A,F)
   ).
head_subset(A,B,C) :-
   head_subset(A,B,C,[],_).
head_subset([],A,B,B,A).
head_subset([E|F],A,B,C,D) :-
   head_member(A,E,G,C,H),
   head_subset(F,H,B,G,D).
head_member([E|F],A,B,C,D) :-
   (
     variable_replacement(A,E,C,B),
     D=F
   ;
     D=[E|G],
     head_member(F,A,B,C,G)
   ).
make_head_matchings_explicit(A,B,C) :-
   make_head_matchings_explicit_memo_lookup(A,D,E),
   copy_term_nat(D-E,B-C).
make_head_matchings_explicit_(A,B,C) :-
   extract_arguments(A,D),
   make_matchings_explicit(D,E,[],[],_,C),
   substitute_arguments(A,E,B).
make_head_matchings_explicit_not_negated(A,B,C) :-
   extract_arguments(A,D),
   make_matchings_explicit_not_negated(D,E,C),
   substitute_arguments(A,E,B).
make_head_matchings_explicit_not_negated2(A,B,C) :-
   extract_arguments(A,D),
   extract_arguments(B,E),
   make_matchings_explicit_not_negated(D,E,C).
extract_arguments([],[]).
extract_arguments([B|C],A) :-
   B=..[_|D],
   append(D,E,A),
   extract_arguments(C,E).
substitute_arguments([],[],[]).
substitute_arguments([B|C],A,[D|E]) :-
   functor(B,F,G),
   split_at(G,A,H,I),
   D=..[F|H],
   substitute_arguments(C,I,E).
make_matchings_explicit([],[],_,A,A,[]).
make_matchings_explicit([E|F],[G|H],A,B,C,D) :-
   ( var(E) ->
     ( memberchk_eq(E,A) ->
       list2disj(B,I),
       D=[(I;G==E)|J],
       K=A
     ;
       D=J,
       G=E,
       K=[E|A]
     ),
     L=B
   ;
     functor(E,M,N),
     E=..[M|O],
     make_matchings_explicit(O,P,A,B,Q,R),
     S=..[M|P],
     ( R==[] ->
       D=[functor(G,M,N)|J]
     ;
       list2conj(R,T),
       list2disj(B,I),
       U= (G\=S;I;T),
       D=[functor(G,M,N),U|J]
     ),
     L=[G\=S|Q],
     term_variables(F,V),
     append(V,A,K)
   ),
   make_matchings_explicit(F,H,K,L,C,J).
make_matchings_explicit_not_negated([],[],[]).
make_matchings_explicit_not_negated([B|C],[D|E],A) :-
   A=[D=B|F],
   make_matchings_explicit_not_negated(C,E,F).
apply_guard_wrt_term([],_,[]).
apply_guard_wrt_term([B|C],A,[D|E]) :-
   ( var(B) ->
     apply_guard_wrt_variable(A,B,D)
   ;
     B=..[F|G],
     apply_guard_wrt_term(G,A,H),
     D=..[F|H]
   ),
   apply_guard_wrt_term(C,A,E).
apply_guard_wrt_variable((C,D),A,B) :-
   !,
   apply_guard_wrt_variable(C,A,E),
   apply_guard_wrt_variable(D,E,B).
apply_guard_wrt_variable(A,B,C) :-
   ( A= (D=E),
     B==D ->
     C=E
   ;
     ( A=functor(F,G,H),
       B==F,
       ground(G),
       ground(H) ->
       functor(C,G,H)
     )
   ;
     C=B
   ).
replace_some_heads(A,B,_,[],A,B,_,_,[]) :-
   !.
replace_some_heads([],[D|E],[F|G],[H|I],[],[J|K],A,B,C) :-
   !,
   ( F==H ->
     J=H,
     replace_some_heads([],E,G,I,[],K,A,B,C)
   ;
     ( H=functor(L,M,N),
       F==L ->
       length(O,N),
       ( var(D) ->
         P=[],
         J=..[M|O]
       ;
         D=..[M|Q],
         use_same_args(Q,O,R,A,B,P),
         J=..[M|R]
       ),
       replace_some_heads([],E,G,I,[],K,A,B,S),
       append(P,S,C)
     )
   ;
     J=D,
     replace_some_heads([],E,G,[H|I],[],K,A,B,C)
   ).
replace_some_heads([F|G],A,[H|I],[J|K],[L|M],B,C,D,E) :-
   !,
   ( H==J ->
     L=J,
     replace_some_heads(G,A,I,K,M,B,C,D,E)
   ;
     ( J=functor(N,O,P),
       H==N ->
       length(Q,P),
       ( var(F) ->
         R=[],
         L=..[O|Q]
       ;
         F=..[O|S],
         use_same_args(S,Q,T,C,D,R),
         L=..[O|T]
       ),
       replace_some_heads(G,A,I,K,M,B,C,D,U),
       append(R,U,E)
     )
   ;
     L=F,
     replace_some_heads(G,A,I,[J|K],M,B,C,D,E)
   ).
use_same_args([],[],[],_,_,[]).
use_same_args([D|E],[_|F],[G|H],A,B,C) :-
   var(D),
   !,
   G=D,
   use_same_args(E,F,H,A,B,C).
use_same_args([D|E],[F|G],[H|I],A,B,C) :-
   nonvar(D),
   !,
   ( common_variables(D,B) ->
     C=[F=D|J]
   ;
     C=J
   ),
   H=F,
   use_same_args(E,G,I,A,B,J).
simplify_heads([],_,_,_,[],[]).
simplify_heads([F|G],A,B,C,D,E) :-
   F= (H=I),
   (
     (
       nonvar(I)
     ;
       common_variables(I,G-A)
     ),
     guard_entailment:entails_guard(A,H=I) ->
     ( common_variables(I,B-G-A) ->
       E=J,
       D=K
     ;
       ( common_variables(I,C) ->
         E=[H=I|J]
       ;
         E=J
       ),
       D=[H|K]
     )
   ;
     ( nonvar(I),
       functor(I,L,M),
       guard_entailment:entails_guard([functor(H,L,M)|A],H=I) ->
       E=J,
       ( common_variables(I,B-G-A) ->
         D=K
       ;
         D=[functor(H,L,M)|K]
       )
     )
   ;
     D=K,
     E=J
   ),
   simplify_heads(G,[F|A],B,C,K,J).
common_variables(A,B) :-
   term_variables(A,C),
   term_variables(B,D),
   intersect_eq(C,D,E),
   E\==[].
add_failing_occ(A,B,C,D,E,F,_,G,H) :-
   A=pragma(rule(_,_,I,_),ids(J,K),_,_,_),
   append(K,J,L),
   missing_partner_cond(B,C,L,D,M,N,G),
   copy_term((N,B,C),(O,P,Q)),
   variable_replacement((N,B,C),(O,P,Q),H),
   copy_with_variable_replacement(I,R,H),
   extract_explicit_matchings(R,S),
   negate_b(S,T),
   copy_with_variable_replacement(M,U,H),
   ( subsumes(F,O) ->
     E=[(T;U)]
   ;
     E=[chr_pp_void_info]
   ).
missing_partner_cond([],[],[],_,fail,_,_).
missing_partner_cond([C|D],[_|E],[F|G],F,A,C,B) :-
   !,
   missing_partner_cond(D,E,G,F,A,C,B).
missing_partner_cond([D|E],[_|F],[_|G],A,B,C,H/I) :-
   B= (chr_pp_not_in_store(D);J),
   missing_partner_cond(E,F,G,A,J,C,H/I).
extract_explicit_matchings((B,C),A) :-
   !,
   ( extract_explicit_matchings(B) ->
     extract_explicit_matchings(C,A)
   ;
     A= (B,D),
     extract_explicit_matchings(C,D)
   ).
extract_explicit_matchings(A,B) :-
   !,
   ( extract_explicit_matchings(A) ->
     B=true
   ;
     B=A
   ).
extract_explicit_matchings(A=B) :-
   var(A),
   var(B),
   !,
   A=B.
extract_explicit_matchings(A==B) :-
   var(A),
   var(B),
   !,
   A=B.
assert_constraint_type(A,B) :-
   ( ground(B) ->
     constraint_type(A,B)
   ;
     chr_error(type_error,'Declared argument types "~w" for constraint "~w" must be ground!\n',[B,A])
   ).
get_type_definition_det(A,B) :-
   ( get_type_definition(A,B) ->
     true
   ;
     chr_error(type,'Could not find type definition for type `~w\'.\n',[A])
   ).
get_constraint_type_det(A,B) :-
   ( get_constraint_type(A,B) ->
     true
   ;
     A=_/C,
     replicate(C,any,B)
   ).
modes_condition([],[],true).
modes_condition([B|C],[D|E],A) :-
   ( B== (+) ->
     A= (ground(D),F)
   ;
     ( B== (-) ->
       A= (var(D),F)
     )
   ;
     A=F
   ),
   modes_condition(C,E,F).
types_condition([],[],[],[],true).
types_condition([A|B],[C|D],[E|F],[G|H],(I,J)) :-
   ( G== (-) ->
     K=[true]
   ;
     get_type_definition_det(A,L),
     type_condition(L,C,E,G,M),
     ( G== (+) ->
       K=M
     ;
       K=[\+ground(C)|M]
     )
   ),
   list2disj(K,I),
   types_condition(B,D,F,H,J).
type_condition([],_,_,_,[]).
type_condition([D|E],A,B,C,[F|G]) :-
   ( var(D) ->
     chr_error(type,'Unexpected variable type in type definition!\n',[])
   ;
     ( atomic_builtin_type(D,A,F) ->
       true
     )
   ;
     ( compound_builtin_type(D,A,F,_) ->
       true
     )
   ;
     type_def_case_condition(D,A,B,C,F)
   ),
   type_condition(E,A,B,C,G).
ast_atomic_builtin_type(A,B,C) :-
   ast_term_to_term(B,D),
   atomic_builtin_type(A,D,C).
ast_compound_builtin_type(A,B,C) :-
   ast_term_to_term(B,D),
   compound_builtin_type(A,D,_,C).
atomic_builtin_type(any,_,true).
atomic_builtin_type(dense_int,A,(integer(A),A>=0)).
atomic_builtin_type(int,A,integer(A)).
atomic_builtin_type(number,A,number(A)).
atomic_builtin_type(float,A,float(A)).
atomic_builtin_type(natural,A,(integer(A),A>=0)).
atomic_builtin_type(chr_identifier,_,true).
compound_builtin_type(chr_constants(_),_,true,true).
compound_builtin_type(chr_constants(_,_),_,true,true).
compound_builtin_type(chr_identifier(_),_,true,true).
compound_builtin_type(chr_enum(B),A,(ground(A),memberchk(A,B)),once((member(C,B),unifiable(A,C,_)))).
compound_builtin_type(chr_enum(_,_),_,true,true).
is_chr_constants_type(chr_constants(A),A,no).
is_chr_constants_type(chr_constants(A,B),A,yes(B)).
is_chr_enum_type(chr_enum(A),A,no).
is_chr_enum_type(chr_enum(A,B),A,yes(B)).
type_def_case_condition(A,B,C,D,E) :-
   ( nonvar(A) ->
     functor(A,F,G),
     ( G==0 ->
       E= (B=A)
     ;
       ( var(C) ->
         E=functor(B,F,G)
       )
     ;
       ( functor(C,F,G) ->
         E= (functor(B,F,G),B=I,H),
         A=..[_|J],
         C=..[_|K],
         functor(I,F,G),
         I=..[_|L],
         replicate(G,D,M),
         types_condition(J,L,K,M,H)
       )
     ;
       E=functor(B,F,G)
     )
   ;
     chr_error(internal,'Illegal type definition (must be nonvar).\n',[])
   ).
static_type_check_rule(A,B) :-
   B=ast_rule(C,_,_,D,_),
   (
     catch((ast_static_type_check_head(C),ast_static_type_check_body(D)),type_error(E),(E=invalid_functor(F,G,H)->chr_error(type_error,'Invalid functor in ~@ of ~@:\n\t\tfound `~w\',\n\t\texpected type `~w\'!\n',[chr_translate:format_src(F),format_rule(A),G,H]);E=type_clash(I,J,K,L,M)->chr_error(type_error,'Type clash for variable ~w in ~@:\n\t\texpected type ~w in ~@\n\t\texpected type ~w in ~@\n',[I,format_rule(A),L,chr_translate:format_src(J),M,chr_translate:format_src(K)]))),
     fail
   ;
     true
   ).
ast_static_type_check_head(simplification(A)) :-
   maplist(ast_static_type_check_head_constraint,A).
ast_static_type_check_head(propagation(A)) :-
   maplist(ast_static_type_check_head_constraint,A).
ast_static_type_check_head(simpagation(A,B)) :-
   maplist(ast_static_type_check_head_constraint,A),
   maplist(ast_static_type_check_head_constraint,B).
ast_static_type_check_head_constraint(A) :-
   A=chr_constraint(B,C,_),
   get_constraint_type_det(B,D),
   maplist(ast_static_type_check_term(head(_)),C,D).
ast_static_type_check_body([]).
ast_static_type_check_body([A|B]) :-
   ast_symbol(A,C),
   get_constraint_type_det(C,D),
   ast_args(A,E),
   maplist(ast_static_type_check_term(body(A)),E,D),
   ast_static_type_check_body(B).
format_src(head(A)) :-
   format('head ~w',[A]).
format_src(body(A)) :-
   format('body goal ~w',[A]).
generate_dynamic_type_check_clauses(A) :-
   ( chr_pp_flag(debugable,on) ->
     dynamic_type_check,
     get_dynamic_type_check_clauses(B),
     append(B,[('$dynamic_type_check'(C,D):-throw(error(type_error(C,D),context(_,'CHR Runtime Type Error'))))],A)
   ;
     A=[]
   ).
dynamic_type_check_clause(A,B,C) :-
   copy_term(A-B,D-E),
   functor(E,F,G),
   functor(H,F,G),
   E=..[_|I],
   H=..[_|J],
   maplist(dynamic_type_check_call,I,J,K),
   list2conj(K,L),
   C= ('$dynamic_type_check'(D,H):-L).
dynamic_type_check_alias_clause(A,B,C) :-
   C= ('$dynamic_type_check'(A,D):-'$dynamic_type_check'(B,D)).
dynamic_type_check_call(A,B,C) :-
   ( A==any ->
     C=true
   ;
     C=when(nonvar(B),once('$dynamic_type_check'(A,B)))
   ).
atomic_types_suspended_constraint(A) :-
   A=_/B,
   get_constraint_type(A,C),
   get_constraint_mode(A,D),
   numlist(1,B,E),
   maplist(atomic_types_suspended_constraint(A),C,D,E).
atomic_types_suspended_constraint(A,B,C,D) :-
   ( is_indexed_argument(A,D) ->
     ( C== (?) ->
       atomic_type(B)
     ;
       true
     )
   ;
     true
   ).
storage_analysis(A) :-
   ( chr_pp_flag(storage_analysis,on) ->
     check_constraint_storages(A)
   ;
     true
   ).
check_constraint_storages(A) :-
   maplist(check_constraint_storage,A).
check_constraint_storage(A) :-
   get_max_occurrence(A,B),
   check_occurrences_storage(A,1,B).
check_occurrences_storage(A,B,C) :-
   ( B>C ->
     stored_completing(A,1,0)
   ;
     check_occurrence_storage(A,B),
     D is B+1,
     check_occurrences_storage(A,D,C)
   ).
check_occurrence_storage(A,B) :-
   get_occurrence(A,B,C,D,E),
   ( is_passive(C,D) ->
     stored(A,B,maybe)
   ;
     get_rule(C,F),
     F=pragma(rule(G,H,I,J),ids(K,L),_,_,_),
     ( E==simplification,
       select2(D,M,K,G,_,_) ->
       check_storage_head1(M,B,G,H,I)
     ;
       ( E==propagation,
         select2(D,N,L,H,_,_) ->
         check_storage_head2(N,B,G,J)
       )
     )
   ).
check_storage_head1(A,B,C,D,E) :-
   functor(A,F,G),
   H=F/G,
   ( C==[A],
     D==[],
     guard_entailment:entails_guard([chr_pp_headvariables(A)],E),
     A=..[_|I],
     no_matching(I,[]) ->
     stored(H,B,no)
   ;
     stored(H,B,maybe)
   ).
no_matching([],_).
no_matching([B|C],A) :-
   var(B),
   \+memberchk_eq(B,A),
   no_matching(C,[B|A]).
check_storage_head2(A,B,C,D) :-
   functor(A,E,F),
   G=E/F,
   ( C\==[],
     D==true ->
     stored(G,B,maybe)
   ;
     stored(G,B,yes)
   ).
constraints_code(A,B) :-
   ( chr_pp_flag(reduced_indexing,on),
     forall(C,A,chr_translate:only_ground_indexed_arguments(C)) ->
     none_suspended_on_variables
   ;
     true
   ),
   constraints_code1(A,B,[]).
constraint_prelude(B/C,A) :-
   vars_susp(C,D,E,F),
   G=..[B|D],
   make_suspension_continuation_goal(B/C,F,H),
   build_head(B,C,[0],F,I),
   ( chr_pp_flag(debugable,on) ->
     insert_constraint_goal(B/C,E,D,J),
     attach_constraint_atom(B/C,K,E,L),
     delay_phase_end(validate_store_type_assumptions,chr_translate:update_suspension_field(B/C,E,state,inactive,M)),
     insert_constraint_internal_constraint_goal(B/C,K,E,H,D,N),
     ( get_constraint_type(B/C,O) ->
       maplist(dynamic_type_check_call,O,D,P),
       list2conj(P,Q)
     ;
       Q=true
     ),
     A= (G:-Q,N,J,L,M,'chr debug_event'(insert(G#E)),('chr debug_event'(call(E)),I;'chr debug_event'(fail(E)),!,fail),('chr debug_event'(exit(E));'chr debug_event'(redo(E)),fail))
   ;
     ( get_allocation_occurrence(B/C,0) ->
       gen_insert_constraint_internal_goal(B/C,R,F,D,E),
       delay_phase_end(validate_store_type_assumptions,chr_translate:update_suspension_field(B/C,E,state,inactive,M)),
       A= (G:-R,M,I)
     )
   ;
     A= (G:-I)
   ).
make_suspension_continuation_goal(C/D,A,B) :-
   ( may_trigger(C/D) ->
     build_head(C,D,[0],A,E),
     ( chr_pp_flag(debugable,off) ->
       B=E
     ;
       get_target_module(F),
       B=F:E
     )
   ;
     B=true
   ).
gen_cond_attach_clause(D/E,A,B,C) :-
   ( is_finally_stored(D/E) ->
     get_allocation_occurrence(D/E,F),
     get_max_occurrence(D/E,G),
     ( chr_pp_flag(debugable,off),
       G<F ->
       ( only_ground_indexed_arguments(D/E) ->
         gen_insert_constraint_internal_goal(D/E,H,I,J,K)
       ;
         gen_cond_attach_goal(D/E,H,I,J,K)
       )
     ;
       vars_susp(E,J,K,I),
       gen_uncond_attach_goal(D/E,K,J,H,_)
     ),
     build_head(D,E,A,I,L),
     M= (L:-H),
     add_dummy_location(M,N),
     B=[N|C]
   ;
     B=C
   ).
gen_cond_attach_goal(E/F,A,B,C,D) :-
   vars_susp(F,C,D,B),
   make_suspension_continuation_goal(E/F,B,G),
   ( get_store_type(E/F,var_assoc_store(_,_)) ->
     H=true
   ;
     attach_constraint_atom(E/F,I,D,H)
   ),
   _=..[E|C],
   insert_constraint_goal(E/F,D,C,J),
   insert_constraint_internal_constraint_goal(E/F,I,D,G,C,K),
   ( may_trigger(E/F) ->
     activate_constraint_goal(E/F,(J,H),I,D,_,L),
     A= (var(D)->K,J,H;L)
   ;
     A= (K,J,H)
   ).
gen_insert_constraint_internal_goal(E/F,A,B,C,D) :-
   vars_susp(F,C,D,B),
   make_suspension_continuation_goal(E/F,B,G),
   ( \+only_ground_indexed_arguments(E/F),
     \+get_store_type(E/F,var_assoc_store(_,_)) ->
     attach_constraint_atom(E/F,H,D,I)
   ;
     I=true
   ),
   _=..[E|C],
   insert_constraint_goal(E/F,D,C,J),
   insert_constraint_internal_constraint_goal(E/F,H,D,G,C,K),
   ( only_ground_indexed_arguments(E/F),
     chr_pp_flag(debugable,off) ->
     A= (K,J)
   ;
     A= (K,J,I)
   ).
gen_uncond_attach_goal(A,B,C,D,E) :-
   ( \+only_ground_indexed_arguments(A),
     \+get_store_type(A,var_assoc_store(_,_)) ->
     attach_constraint_atom(A,F,B,G)
   ;
     G=true
   ),
   insert_constraint_goal(A,B,C,H),
   ( chr_pp_flag(late_allocation,on) ->
     activate_constraint_goal(A,(H,G),F,B,E,D)
   ;
     activate_constraint_goal(A,true,F,B,E,D)
   ).
head1_code(A,B,C,D,E,F,G,H,I,J) :-
   E=pragma(K,_,_,_,L),
   K=rule(_,M,_,_),
   ( M==[] ->
     reorder_heads(L,A,C,D,N,O),
     simplification_code(A,B,N,O,E,F,G,H,I,J)
   ;
     simpagation_head1_code(A,B,C,D,E,F,G,H,I,J)
   ).
head2_code(A,B,C,D,E,F,G,H,I,J) :-
   E=pragma(K,_,_,_,L),
   K=rule(M,_,_,_),
   ( M==[] ->
     reorder_heads(L,A,C,D,N,O),
     propagation_code(A,B,N,O,K,L,F,G,H,I,J)
   ;
     simpagation_head2_code(A,B,C,D,E,F,G,H,I,J)
   ).
gen_alloc_inc_clause(E/F,A,B,C,D) :-
   vars_susp(F,G,H,I),
   build_head(E,F,B,I,J),
   inc_id(B,K),
   build_head(E,F,K,I,L),
   gen_occ_allocation(E/F,A,G,H,M),
   N= (J:-M,L),
   add_dummy_location(N,O),
   C=[O|D].
gen_occ_allocation(A,B,C,D,E) :-
   get_allocation_occurrence(A,F),
   get_occurrence_code_id(A,F,G),
   get_occurrence_code_id(A,B,H),
   ( chr_pp_flag(debugable,off),
     H==G ->
     allocate_constraint_goal(A,D,C,I),
     ( may_trigger(A) ->
       E= (var(D)->I;true)
     ;
       E=I
     )
   ;
     E=true
   ).
gen_occ_allocation_in_guard(A,B,C,D,E) :-
   get_allocation_occurrence(A,F),
   ( chr_pp_flag(debugable,off),
     B<F ->
     allocate_constraint_goal(A,D,C,G),
     ( may_trigger(A) ->
       E= (var(D)->G;true)
     ;
       E=G
     )
   ;
     E=true
   ).
guard_via_reschedule_new(A,B,C,D,E,F) :-
   ( chr_pp_flag(guard_via_reschedule,on) ->
     guard_via_reschedule_main_new(A,B,C,D,E,G),
     list2conj(G,F)
   ;
     length(A,H),
     length(E,H),
     length(B,I),
     length(D,I),
     append(E,D,J),
     list2conj(J,F)
   ).
guard_via_reschedule_main_new(A,B,C,D,E,F) :-
   initialize_unit_dictionary(C,G),
   maplist(wrap_in_functor(lookup),A,H),
   maplist(wrap_in_functor(guard),B,I),
   build_units(H,I,G,J),
   dependency_reorder(J,K),
   wrappedunits2lists(K,L,E,F),
   sort(L,M),
   snd_of_pairs(M,D).
wrappedunits2lists([],[],[],[]).
wrappedunits2lists([unit(E,F,_,_)|D],A,B,C) :-
   C=[G|H],
   ( F=lookup(I) ->
     B=[G|J],
     A=K
   ;
     ( F=guard(I) ->
       A=[E-G|K],
       B=J
     )
   ),
   wrappedunits2lists(D,K,J,H).
guard_splitting(A,B) :-
   A=rule(C,D,E,_),
   append(C,D,F),
   conj2list(E,G),
   term_variables(F,H),
   split_off_simple_guard_new(G,H,I,J),
   append(I,[K],B),
   term_variables(J,L),
   ground_vars(F,M),
   list_difference_eq(H,M,N),
   intersect_eq(N,L,O),
   maplist(chr_lock,O,P),
   maplist(chr_unlock,O,Q),
   list2conj(P,R),
   list2conj(Q,S),
   list2conj(J,T),
   K= (R,T,S).
guard_body_copies3(A,B,C,D,E) :-
   A=rule(_,_,_,F),
   my_term_copy(B,C,G,D),
   my_term_copy(F,G,E).
split_off_simple_guard_new([],_,[],[]).
split_off_simple_guard_new([D|E],A,B,C) :-
   ( simple_guard_new(D,A) ->
     B=[D|F],
     split_off_simple_guard_new(E,A,F,C)
   ;
     B=[],
     C=[D|E]
   ).
simple_guard_new(A,B) :-
   builtin_binds_b(A,C),
   not (member(D,C),memberchk_eq(D,B)).
dependency_reorder(A,B) :-
   dependency_reorder(A,[],B).
dependency_reorder([],A,B) :-
   reverse(A,B).
dependency_reorder([C|D],A,B) :-
   C=unit(_,_,E,F),
   ( E==fixed ->
     G=[C|A]
   ;
     dependency_insert(A,C,F,G)
   ),
   dependency_reorder(D,G,B).
dependency_insert([],A,_,[A]).
dependency_insert([D|E],A,B,C) :-
   D=unit(F,_,_,_),
   ( memberchk(F,B) ->
     C=[A,D|E]
   ;
     C=[D|G],
     dependency_insert(E,A,B,G)
   ).
build_units(A,B,C,D) :-
   build_retrieval_units(A,1,E,C,F,D,G),
   build_guard_units(B,E,F,G).
build_retrieval_units([],A,A,B,B,C,C).
build_retrieval_units([G|H],A,B,C,D,E,F) :-
   term_variables(G,I),
   update_unit_dictionary(I,A,C,J,[],K),
   E=[unit(A,G,fixed,K)|L],
   M is A+1,
   build_retrieval_units(H,M,B,J,D,L,F).
initialize_unit_dictionary(A,B) :-
   term_variables(A,C),
   pair_all_with(C,0,B).
update_unit_dictionary([],_,A,A,B,B).
update_unit_dictionary([F|G],A,B,C,D,E) :-
   ( lookup_eq(B,F,H) ->
     (
       (
         H==A
       ;
         memberchk(H,D)
       ) ->
       I=D
     ;
       I=[H|D]
     ),
     J=B
   ;
     J=[F-A|B],
     I=D
   ),
   update_unit_dictionary(G,A,J,C,I,E).
build_guard_units(A,B,C,D) :-
   ( A=[E] ->
     D=[unit(B,E,fixed,[])]
   ;
     ( A=[E|F] ->
       term_variables(E,G),
       update_unit_dictionary2(G,B,C,H,[],I),
       D=[unit(B,E,movable,I)|J],
       K is B+1,
       build_guard_units(F,K,H,J)
     )
   ).
update_unit_dictionary2([],_,A,A,B,B).
update_unit_dictionary2([F|G],A,B,C,D,E) :-
   ( lookup_eq(B,F,H) ->
     (
       (
         H==A
       ;
         memberchk(H,D)
       ) ->
       I=D
     ;
       I=[H|D]
     ),
     J=[F-A|B]
   ;
     J=[F-A|B],
     I=D
   ),
   update_unit_dictionary2(G,A,J,C,I,E).
functional_dependency_analysis(A) :-
   ( fail,
     chr_pp_flag(functional_dependency_analysis,on) ->
     functional_dependency_analysis_main(A)
   ;
     true
   ).
functional_dependency_analysis_main([]).
functional_dependency_analysis_main([A|B]) :-
   ( discover_unique_pattern(A,C,D,E,F) ->
     functional_dependency(C,D,E,F)
   ;
     true
   ),
   functional_dependency_analysis_main(B).
discover_unique_pattern(A,E/F,B,C,D) :-
   A=pragma(G,_,_,_,B),
   G=rule(H,I,J,_),
   ( H=[K],
     I=[L] ->
     true
   ;
     ( H=[K,L],
       I==[] ->
       true
     )
   ),
   check_unique_constraints(K,L,J,B,M),
   term_variables(K,N),
   \+ (member(O,N),lookup_eq(M,O,P),memberchk_eq(P,N)),
   select_pragma_unique_variables(N,M,Q),
   copy_term_nat(K-Q,C-D),
   functor(K,E,F).
select_pragma_unique_variables([],_,[]).
select_pragma_unique_variables([C|D],A,B) :-
   ( lookup_eq(A,C,_) ->
     B=E
   ;
     B=[C|E]
   ),
   select_pragma_unique_variables(D,A,E).
set_semantics_rules(A) :-
   ( fail,
     chr_pp_flag(set_semantics_rule,on) ->
     set_semantics_rules_main(A)
   ;
     true
   ).
set_semantics_rules_main([]).
set_semantics_rules_main([A|B]) :-
   set_semantics_rule_main(A),
   set_semantics_rules_main(B).
set_semantics_rule_main(A) :-
   A=pragma(B,C,_,_,D),
   ( B=rule([E],[F],true,_),
     C=ids([G],[H]),
     \+is_passive(D,G),
     functor(E,I,J),
     get_functional_dependency(I/J,D,K,L),
     copy_term_nat(K-L,E-M),
     copy_term_nat(K-L,F-N),
     M==N ->
     passive(D,H)
   ;
     true
   ).
check_unique_constraints(A,B,C,D,E) :-
   \+any_passive_head(D),
   variable_replacement(A-B,B-A,E),
   copy_with_variable_replacement(C,F,E),
   negate_b(C,G),
   once(entails_b(G,F)).
symmetry_analysis(A) :-
   ( chr_pp_flag(check_unnecessary_active,off) ->
     true
   ;
     symmetry_analysis_main(A)
   ).
symmetry_analysis_main([]).
symmetry_analysis_main([A|B]) :-
   A=pragma(C,ids(E,F),_,_,D),
   C=rule(G,H,_,_),
   (
     (
       \+chr_pp_flag(check_unnecessary_active,simplification)
     ;
       H==[]
     ),
     G\==[] ->
     symmetry_analysis_heads_simplification(G,E,[],[],C,D),
     symmetry_analysis_heads_propagation(H,F,[],[],C,D)
   ;
     true
   ),
   symmetry_analysis_main(B).
symmetry_analysis_heads_simplification([],[],_,_,_,_).
symmetry_analysis_heads_simplification([E|F],[G|H],A,B,C,D) :-
   ( \+is_passive(D,G),
     member2(A,B,I-J),
     \+is_passive(D,J),
     variable_replacement(I,E,K),
     copy_with_variable_replacement(C,L,K),
     identical_guarded_rules(C,L) ->
     passive(D,G)
   ;
     true
   ),
   symmetry_analysis_heads_simplification(F,H,[E|A],[G|B],C,D).
symmetry_analysis_heads_propagation([],[],_,_,_,_).
symmetry_analysis_heads_propagation([E|F],[G|H],A,B,C,D) :-
   ( \+is_passive(D,G),
     member2(A,B,I-J),
     \+is_passive(D,J),
     variable_replacement(I,E,K),
     copy_with_variable_replacement(C,L,K),
     identical_rules(C,L) ->
     passive(D,G)
   ;
     true
   ),
   symmetry_analysis_heads_propagation(F,H,[E|A],[G|B],C,D).
simplification_code(A,B,C,D,E,F,G,H,I,J) :-
   E=pragma(K,_,_,_,L),
   head_info1(A,F,_,M,N,O),
   build_head(F,H,N,P),
   get_constraint_mode(F,Q),
   head_arg_matches(O,Q,[],R,S,[],T),
   guard_splitting(K,U),
   ( is_stored_in_guard(F,L) ->
     V=[_|U]
   ;
     V=U
   ),
   guard_via_reschedule_new(C,V,A,W,X,Y),
   rest_heads_retrieval_and_matching(C,D,A,X,Z,S,A1,[],[],[],T,_),
   guard_body_copies3(K,V,A1,W,B1),
   ( is_stored_in_guard(F,L) ->
     gen_occ_allocation_in_guard(F,G,C1,M,D1),
     gen_uncond_attach_goal(F,M,C1,E1,_),
     W=[F1|_],
     F1= (D1,E1)
   ;
     true
   ),
   partner_constraint_detachments(Z,C,A1,G1),
   active_constraint_detachment(H,M,A,A1,H1),
   ( chr_pp_flag(debugable,on) ->
     K=rule(_,_,I1,J1),
     my_term_copy(I1-J1,A1,K1-L1),
     sort_by_key([M|Z],[B|D],M1),
     N1='chr debug_event'(try(M1,[],K1,L1)),
     O1='chr debug_event'(apply(M1,[],K1,L1)),
     instrument_goal(P1,N1,O1,Q1)
   ;
     Q1=P1
   ),
   actual_cut(F,G,P1),
   R1= (P:-R,Y,Q1,G1,H1,B1),
   add_location(R1,L,S1),
   I=[S1|J].
actual_cut(A,B,C) :-
   ( unconditional_occurrence(A,B),
     chr_pp_flag(late_allocation,on) ->
     C=true
   ;
     C=!
   ).
add_location(A,B,C) :-
   ( chr_pp_flag(line_numbers,on) ->
     get_chr_source_file(D),
     get_line_number(B,E),
     C='$source_location'(D,E):A
   ;
     C=A
   ).
add_dummy_location(A,B) :-
   ( chr_pp_flag(line_numbers,on) ->
     get_chr_source_file(C),
     B='$source_location'(C,1):A
   ;
     B=A
   ).
head_arg_matches(A,B,C,D,E) :-
   head_arg_matches(A,B,C,D,E,[],_).
head_arg_matches(A,B,C,D,E,F,G) :-
   head_arg_matches_(A,B,C,F,H,E,G),
   list2conj(H,D).
head_arg_matches_([],[],A,B,[],A,B).
head_arg_matches_([silent(G-_)|F],[H|I],A,B,C,D,E) :-
   !,
   ( H== (+) ->
     term_variables(G,J,B),
     head_arg_matches_(F,I,A,J,C,D,E)
   ;
     head_arg_matches_(F,I,A,B,C,D,E)
   ).
head_arg_matches_([G-H|F],[I|J],A,B,C,D,E) :-
   ( var(G) ->
     ( lookup_eq(A,G,K) ->
       ( I= (+) ->
         ( memberchk_eq(G,B) ->
           C=[H=K|L],
           M=B
         ;
           C=[H==K|L],
           M=[G|B]
         )
       ;
         C=[H==K|L],
         M=B
       ),
       N=A
     ;
       N=[G-H|A],
       C=L,
       ( I= (+) ->
         M=[G|B]
       ;
         M=B
       )
     ),
     O=F,
     P=J
   ;
     ( ground(G),
       G='$chr_identifier_match'(Q,R) ->
       identifier_label_atom(R,H,Q,S),
       C=[S|L],
       A=N,
       M=B,
       O=F,
       P=J
     )
   ;
     ( atomic(G) ->
       ( I= (+) ->
         C=[H=G|L]
       ;
         C=[H==G|L]
       ),
       A=N,
       M=B,
       O=F,
       P=J
     )
   ;
     ( I== (+),
       is_ground(B,G) ->
       copy_with_variable_replacement(G,T,A),
       C=[H=T|L],
       A=N,
       M=B,
       O=F,
       P=J
     )
   ;
     ( I== (?),
       is_ground(B,G) ->
       copy_with_variable_replacement(G,T,A),
       C=[H==T|L],
       A=N,
       M=B,
       O=F,
       P=J
     )
   ;
     G=..[_|U],
     functor(G,V,W),
     functor(X,V,W),
     X=..[_|Y],
     ( I= (+) ->
       C=[H=X|L]
     ;
       C=[nonvar(H),H=X|L]
     ),
     pairup(U,Y,Z),
     append(Z,F,O),
     replicate(W,I,A1),
     append(A1,J,P),
     N=A,
     M=B
   ),
   head_arg_matches_(O,P,N,M,L,D,E).
add_heads_types([],A,A).
add_heads_types([C|D],A,B) :-
   add_head_types(C,A,E),
   add_heads_types(D,E,B).
add_head_types(A,B,C) :-
   functor(A,D,E),
   get_constraint_type_det(D/E,F),
   A=..[_|G],
   add_args_types(G,F,B,C).
add_args_types([],[],A,A).
add_args_types([C|D],[E|F],A,B) :-
   add_arg_types(C,E,A,G),
   add_args_types(D,F,G,B).
add_arg_types(A,B,C,D) :-
   ( B==any ->
     D=C
   ;
     ( var(A) ->
       ( lookup_eq(C,A,_) ->
         D=C
       ;
         D=[A-B|C]
       )
     )
   ;
     D=C
   ).
add_heads_ground_variables([],A,A).
add_heads_ground_variables([C|D],A,B) :-
   add_head_ground_variables(C,A,E),
   add_heads_ground_variables(D,E,B).
add_head_ground_variables(A,B,C) :-
   functor(A,D,E),
   get_constraint_mode(D/E,F),
   A=..[_|G],
   add_arg_ground_variables(G,F,B,C).
add_arg_ground_variables([],[],A,A).
add_arg_ground_variables([C|D],[E|F],A,B) :-
   ( E== (+) ->
     term_variables(C,G),
     add_var_ground_variables(G,A,H)
   ;
     A=H
   ),
   add_arg_ground_variables(D,F,H,B).
add_var_ground_variables([],A,A).
add_var_ground_variables([C|D],A,B) :-
   ( memberchk_eq(C,A) ->
     E=A
   ;
     E=[C|A]
   ),
   add_var_ground_variables(D,E,B).
is_ground(A,B) :-
   ( ground(B) ->
     true
   ;
     ( compound(B) ->
       B=..[_|C],
       maplist(is_ground(A),C)
     )
   ;
     memberchk_eq(B,A)
   ).
check_ground(A,B,C) :-
   term_variables(B,D),
   check_ground_variables(D,A,C).
check_ground_variables([],_,true).
check_ground_variables([C|D],A,B) :-
   ( memberchk_eq(C,A) ->
     check_ground_variables(D,A,B)
   ;
     B= (ground(C),E),
     check_ground_variables(D,A,E)
   ).
rest_heads_retrieval_and_matching(A,B,C,D,E,F,G,H,I,J) :-
   rest_heads_retrieval_and_matching(A,B,C,D,E,F,G,H,I,J,[],_).
rest_heads_retrieval_and_matching(A,B,C,D,E,F,G,H,I,J,K,L) :-
   ( A=[_|_] ->
     rest_heads_retrieval_and_matching_n(A,B,H,I,C,D,E,F,G,J,K,L)
   ;
     D=[],
     E=[],
     F=G,
     K=L
   ).
rest_heads_retrieval_and_matching_n([],_,_,_,_,[],[],A,A,_,B,B).
rest_heads_retrieval_and_matching_n([H|I],[_|J],A,B,C,[K|L],[M|N],D,E,_,F,G) :-
   functor(H,O,P),
   head_info(H,P,Q,_,_,R),
   get_store_type(O/P,S),
   ( S==default ->
     passive_head_via(H,[C|A],D,T,U),
     delay_phase_end(validate_store_type_assumptions,(static_suspension_term(O/P,V),get_static_suspension_term_field(arguments,O/P,V,Q),get_static_suspension_field(O/P,V,state,active,W))),
     get_constraint_mode(O/P,X),
     head_arg_matches(R,X,D,Y,Z,F,A1),
     B1=R,
     sbag_member_call(M,U,C1),
     D1= (T,C1,M=V,W),
     inline_matching_goal(Y,E1)
   ;
     delay_phase_end(validate_store_type_assumptions,(static_suspension_term(O/P,V),get_static_suspension_term_field(arguments,O/P,V,Q))),
     existential_lookup(S,H,[C|A],D,F,V,D1,M,R,B1),
     get_constraint_mode(O/P,X),
     F1=X,
     head_arg_matches(B1,F1,D,Y,Z,F,A1),
     filter_append(B1,Z,G1),
     translate(A1,G1,H1),
     translate(A1,Z,I1),
     inline_matching_goal(Y,E1,H1,I1)
   ),
   different_from_other_susps(H,M,A,B,J1),
   K= (D1,J1,E1),
   rest_heads_retrieval_and_matching_n(I,J,[H|A],[M|B],C,L,N,Z,E,_,A1,G).
inline_matching_goal(A,B) :-
   inline_matching_goal(A,B,[],[]).
inline_matching_goal(C==D,true,A,B) :-
   memberchk_eq(C,A),
   memberchk_eq(D,B),
   C=D,
   !.
inline_matching_goal((C,D),(E,F),A,B) :-
   !,
   inline_matching_goal(C,E,A,B),
   inline_matching_goal(D,F,A,B).
inline_matching_goal(A,A,_,_).
filter_mode([],_,_,[]).
filter_mode([C-D|B],[_-F|E],[G|H],A) :-
   ( D==F ->
     A=[G|I],
     filter_mode(B,E,H,I)
   ;
     filter_mode([C-D|B],E,H,A)
   ).
filter_append([],A,A).
filter_append([C|D],A,B) :-
   ( C=silent(_) ->
     filter_append(D,A,B)
   ;
     B=[C|E],
     filter_append(D,A,E)
   ).
check_unique_keys([],_).
check_unique_keys([B|C],A) :-
   lookup_eq(A,B,_),
   check_unique_keys(C,A).
different_from_other_susps(A,B,C,D,E) :-
   different_from_other_susps_(C,D,A,B,F),
   list2conj(F,E).
different_from_other_susps_(_,[],_,_,[]) :-
   !.
different_from_other_susps_([D|E],[F|G],A,B,C) :-
   ( functor(A,H,I),
     functor(D,H,I),
     copy_term_nat(D-A,J-K),
     \+ \+J=K ->
     C=[B\==F|L]
   ;
     C=L
   ),
   different_from_other_susps_(E,G,A,B,L).
passive_head_via(A,B,C,D,E) :-
   functor(A,F,G),
   get_constraint_index(F/G,_),
   common_variables(A,B,H),
   ground_vars([A],I),
   list_difference_eq(H,I,J),
   global_list_store_name(F/G,K),
   L=nb_getval(K,E),
   get_constraint_mode(F/G,M),
   ( N==[] ->
     D=L
   ;
     ( member(O,J),
       nth1(P,M,-),
       arg(P,A,Q),
       Q==O ->
       translate([O],C,[R]),
       gen_get_mod_constraints(F/G,R,S,E),
       D=S
     )
   ;
     translate(J,C,N),
     add_heads_types(B,[],T),
     my_term_copy(T,C,U),
     gen_get_mod_constraints(F/G,N,U,V,S,E),
     D= (V->S;L)
   ).
common_variables(A,B,C) :-
   term_variables(A,D),
   term_variables(B,E),
   intersect_eq(D,E,C).
gen_get_mod_constraints(A,B,C,D,E,F) :-
   via_goal(B,C,D,G),
   get_target_module(H),
   E= (get_attr(G,H,J),I),
   get_max_constraint_index(K),
   ( K==1 ->
     I=true,
     F=J
   ;
     get_constraint_index(A,L),
     get_suspensions(K,L,J,I,F)
   ).
via_goal(A,B,C,D) :-
   ( A=[] ->
     C=fail
   ;
     ( A=[E] ->
       lookup_type(B,E,F),
       ( atomic_type(F) ->
         C=var(E),
         E=D
       ;
         C='chr newvia_1'(E,D)
       )
     )
   ;
     ( A=[E,G] ->
       C='chr newvia_2'(E,G,D)
     )
   ;
     C='chr newvia'(A,D)
   ).
lookup_type(A,B,C) :-
   ( lookup_eq(A,B,C) ->
     true
   ;
     C=any
   ).
gen_get_mod_constraints(A,B,C,D) :-
   get_target_module(E),
   C= (get_attr(B,E,G),F),
   get_max_constraint_index(H),
   ( H==1 ->
     F=true,
     D=G
   ;
     get_constraint_index(A,I),
     get_suspensions(H,I,G,F,D)
   ).
guard_body_copies(A,B,C,D) :-
   guard_body_copies2(A,B,E,D),
   list2conj(E,C).
guard_body_copies2(A,B,C,D) :-
   A=rule(_,E,F,G),
   conj2list(F,H),
   split_off_simple_guard(H,B,I,J),
   my_term_copy(I-J,B,K,L-M),
   append(L,[N],C),
   term_variables(J,O),
   term_variables(M,P),
   ground_vars(E,Q),
   list_difference_eq(O,Q,R),
   ( chr_pp_flag(guard_locks,off) ->
     S=[],
     T=[]
   ;
     ( bagof(V-W,X^Y^ (lists:member(X,R),pairlist:lookup_eq(B,X,Y),memberchk_eq(Y,P),chr_lock(Y,V),chr_unlock(Y,W)),U) ->
       once(pairup(S,T,U))
     )
   ;
     S=[],
     T=[]
   ),
   list2conj(S,Z),
   list2conj(T,A1),
   list2conj(M,B1),
   N= (Z,B1,A1),
   my_term_copy(G,K,D).
split_off_simple_guard([],_,[],[]).
split_off_simple_guard([D|E],A,B,C) :-
   ( simple_guard(D,A) ->
     B=[D|F],
     split_off_simple_guard(E,A,F,C)
   ;
     B=[],
     C=[D|E]
   ).
simple_guard(A,B) :-
   binds_b(A,C),
   \+ (member(D,C),lookup_eq(B,D,_)).
active_constraint_detachment(A,B,C,D,E) :-
   functor(C,F,G),
   H=F/G,
   ( is_stored(H) ->
     (
       (
         A==[0],
         chr_pp_flag(store_in_guards,off)
       ;
         get_allocation_occurrence(H,I),
         get_max_occurrence(H,J),
         J<I
       ),
       only_ground_indexed_arguments(H),
       chr_pp_flag(late_allocation,on) ->
       E=true
     ;
       gen_uncond_susp_detachment(C,B,active,D,K),
       ( chr_pp_flag(late_allocation,on) ->
         E= (var(B)->true;K)
       ;
         E=K
       )
     )
   ;
     E=true
   ).
partner_constraint_detachments([],[],_,true).
partner_constraint_detachments([B|C],[D|E],A,(F,G)) :-
   gen_uncond_susp_detachment(D,B,partner,A,F),
   partner_constraint_detachments(C,E,A,G).
gen_uncond_susp_detachment(A,B,C,D,E) :-
   functor(A,F,G),
   H=F/G,
   ( is_stored(H) ->
     E= (I,J),
     ( chr_pp_flag(debugable,on) ->
       I='chr debug_event'(remove(B))
     ;
       I=true
     ),
     remove_constraint_goal(H,B,K,true,(L,M),C,J),
     delete_constraint_goal(A,B,D,L),
     ( \+only_ground_indexed_arguments(H),
       \+get_store_type(H,var_assoc_store(_,_)) ->
       detach_constraint_atom(H,K,B,M)
     ;
       M=true
     )
   ;
     E=true
   ).
simpagation_head1_code(A,B,C,D,E,I/J,_,F,G,H) :-
   E=pragma(K,ids(_,M),_,_,L),
   K=rule(_,N,O,P),
   head_info(A,J,Q,R,S,T),
   get_constraint_mode(I/J,U),
   head_arg_matches(T,U,[],V,W,[],X),
   build_head(I,J,F,S,Y),
   append(C,N,Z),
   append(D,M,A1),
   reorder_heads(L,A,Z,A1,B1,C1),
   guard_splitting(K,D1),
   ( is_stored_in_guard(I/J,L) ->
     E1=[_|D1]
   ;
     E1=D1
   ),
   guard_via_reschedule_new(B1,E1,A,F1,G1,H1),
   rest_heads_retrieval_and_matching(B1,C1,A,G1,I1,W,J1,[],[],[],X,_),
   split_by_ids(C1,I1,D,K1,L1,M1,N1),
   guard_body_copies3(K,E1,J1,F1,O1),
   ( is_stored_in_guard(I/J,L) ->
     gen_uncond_attach_goal(I/J,R,Q,P1,_),
     F1=[Q1|_],
     Q1=P1
   ;
     true
   ),
   sort_by_key(K1,L1,R1),
   partner_constraint_detachments(R1,C,J1,S1),
   active_constraint_detachment(F,R,A,J1,T1),
   ( chr_pp_flag(debugable,on) ->
     my_term_copy(O-P,J1,U1-V1),
     sort_by_key([R|K1],[B|L1],W1),
     sort_by_key(M1,N1,X1),
     Y1='chr debug_event'(try(W1,X1,U1,V1)),
     Z1='chr debug_event'(apply(W1,X1,U1,V1)),
     instrument_goal(!,Y1,Z1,A2)
   ;
     A2=!
   ),
   B2= (Y:-V,H1,A2,S1,T1,O1),
   add_location(B2,L,C2),
   G=[C2|H].
split_by_ids([],[],_,[],[]).
split_by_ids([D|E],[F|G],A,B,C) :-
   ( memberchk_eq(D,A) ->
     B=[F|H],
     C=I
   ;
     B=H,
     C=[F|I]
   ),
   split_by_ids(E,G,A,H,I).
split_by_ids([],[],_,[],[],[],[]).
split_by_ids([F|G],[H|I],A,B,C,D,E) :-
   ( memberchk_eq(F,A) ->
     B=[H|J],
     C=[F|K],
     D=L,
     E=M
   ;
     B=J,
     C=K,
     D=[H|L],
     E=[F|M]
   ),
   split_by_ids(G,I,A,J,K,L,M).
simpagation_head2_code(A,B,C,D,E,F,G,H,I,J) :-
   E=pragma(K,ids(M,N),_,_,L),
   K=rule(O,_,P,Q),
   append(O,C,R),
   append(M,D,S),
   reorder_heads(L,A,R,S,[T|U],[V|W]),
   simpagation_head2_prelude(A,T,[U,P,Q],F,G,H,I,X),
   extend_id(H,Y),
   ( memberchk_eq(V,N) ->
     simpagation_universal_searches(U,W,N,[T,A],K,F,G,Z,A1,B1,Y,C1,X,D1)
   ;
     X=D1,
     Y=C1,
     Z=U,
     A1=[T,A],
     B1=W
   ),
   universal_search_iterator_end(A1,Z,K,F,G,C1,D1,E1),
   simpagation_head2_worker(A1,Z,B1,B,E,F,G,C1,E1,J).
simpagation_universal_searches([],[],_,A,_,_,_,[],A,[],B,B,C,C).
simpagation_universal_searches(A,[N|O],B,C,D,E,F,G,H,I,J,K,L,M) :-
   A=[P|Q],
   inc_id(J,R),
   universal_search_iterator_end(C,A,D,E,F,J,L,S),
   universal_search_iterator(A,C,D,E,F,J,S,T),
   ( memberchk_eq(N,B) ->
     simpagation_universal_searches(Q,O,B,[P|C],D,E,F,G,H,I,R,K,T,M)
   ;
     K=R,
     T=M,
     G=Q,
     H=[P|C],
     O=I
   ).
simpagation_head2_prelude(A,B,C,H/I,D,E,F,G) :-
   head_info(A,I,J,K,L,M),
   build_head(H,I,E,L,N),
   get_constraint_mode(H/I,O),
   head_arg_matches(M,O,[],P,Q,[],R),
   lookup_passive_head(B,[A],Q,R,S,T),
   gen_occ_allocation(H/I,D,J,K,U),
   extend_id(E,V),
   extra_active_delegate_variables(A,[B|C],Q,W),
   append([T|L],W,X),
   build_head(H,I,[D|V],X,Y),
   Z= (N:-P,S,!,U,Y),
   add_dummy_location(Z,A1),
   F=[A1|G].
extra_active_delegate_variables(A,B,C,D) :-
   A=..[_|E],
   delegate_variables(A,B,C,E,D).
passive_delegate_variables(A,B,C,D,E) :-
   term_variables(B,F),
   delegate_variables(A,C,D,F,E).
delegate_variables(A,B,C,D,E) :-
   term_variables(A,F),
   term_variables(B,G),
   intersect_eq(F,G,H),
   list_difference_eq(H,D,I),
   translate(I,C,E).
simpagation_head2_worker([H|I],A,B,_,C,J/K,D,E,F,G) :-
   C=pragma(L,ids(O,_),M,_,N),
   L=rule(_,_,P,Q),
   get_prop_inner_loop_vars(I,[H,A,P,Q],R,S,T,U,V),
   gen_var(W),
   gen_var(X),
   functor(H,Y,Z),
   gen_vars(Z,A1),
   head_info(H,Z,A1,W,_,B1),
   get_constraint_mode(Y/Z,C1),
   head_arg_matches(B1,C1,S,D1,E1,[],_),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(Y/Z,F1),get_static_suspension_field(Y/Z,F1,state,active,G1),get_static_suspension_term_field(arguments,Y/Z,F1,A1))),
   different_from_other_susps(H,W,I,V,H1),
   I1= (W=F1,G1,H1,D1),
   J1=[[W|X]|R],
   build_head(J,K,[D|E],J1,K1),
   guard_splitting(L,L1),
   ( is_stored_in_guard(J/K,N) ->
     M1=[_|L1]
   ;
     M1=L1
   ),
   guard_via_reschedule_new(A,M1,[H|I],N1,O1,P1),
   rest_heads_retrieval_and_matching(A,B,[H|I],O1,Q1,E1,R1,[H|I],[W|V],[]),
   split_by_ids(B,Q1,O,S1,T1),
   split_by_ids(B,A,O,U1,_),
   partner_constraint_detachments([W|S1],[H|U1],R1,V1),
   W1=[X|R],
   build_head(J,K,[D|E],W1,X1),
   Y1=[[]|R],
   build_head(J,K,[D|E],Y1,Z1),
   guard_body_copies3(L,M1,R1,N1,A2),
   ( is_stored_in_guard(J/K,N) ->
     N1=[B2|_]
   ;
     true
   ),
   ( is_observed(J/K,D) ->
     gen_uncond_attach_goal(J/K,T,U,C2,D2),
     gen_state_cond_call(T,J/K,X1,D2,E2),
     gen_state_cond_call(T,J/K,Z1,D2,F2)
   ;
     C2=true,
     E2=X1,
     F2=Z1
   ),
   ( chr_pp_flag(debugable,on) ->
     my_term_copy(P-Q,S,G2-H2),
     I2='chr debug_event'(try([W|S1],[T|T1],G2,H2)),
     J2='chr debug_event'(apply([W|S1],[T|T1],G2,H2))
   ;
     I2=true,
     J2=true
   ),
   ( is_stored_in_guard(J/K,N) ->
     B2=C2,
     K2=true
   ;
     B2=true,
     K2=C2
   ),
   ( member(unique(_,L2),M),
     check_unique_keys(L2,S) ->
     M2= (K1:-I1-> (P1,I2->J2,V1,K2,A2,F2;Z1);X1)
   ;
     M2= (K1:-I1,P1,I2->J2,V1,K2,A2,E2;X1)
   ),
   add_location(M2,N,N2),
   F=[N2|G].
gen_state_cond_call(A,B,C,D,E) :-
   ( may_trigger(B) ->
     does_use_field(B,generation),
     delay_phase_end(validate_store_type_assumptions,(static_suspension_term(B,F),get_update_static_suspension_field(B,A,F,state,active,inactive,G,H),get_static_suspension_field(B,F,generation,D,I),get_static_suspension_term_field(arguments,B,F,J)))
   ;
     delay_phase_end(validate_store_type_assumptions,(static_suspension_term(B,F),get_update_static_suspension_field(B,A,F,state,active,inactive,G,H),get_static_suspension_term_field(arguments,B,F,J))),
     I=true
   ),
   E= (A=F,G,I->H,C;true).
propagation_code(A,B,C,D,E,F,G,H,I,J,K) :-
   ( C==[] ->
     propagation_single_headed(A,B,E,F,G,H,I,J,K)
   ;
     propagation_multi_headed(A,C,D,E,F,G,H,I,J,K)
   ).
propagation_single_headed(A,_,B,C,H/I,D,E,F,G) :-
   head_info(A,I,J,K,L,M),
   build_head(H,I,E,L,N),
   inc_id(E,O),
   build_head(H,I,O,L,P),
   get_constraint_mode(H/I,Q),
   head_arg_matches(M,Q,[],R,S,[],_),
   guard_body_copies(B,S,T,U),
   V=P,
   actual_cut(H/I,D,W),
   B=rule(_,_,X,Y),
   ( chr_pp_flag(debugable,on) ->
     my_term_copy(X-Y,S,Z-A1),
     B1='chr debug_event'(try([],[K],Z,A1)),
     C1='chr debug_event'(apply([],[K],Z,A1)),
     instrument_goal(W,B1,C1,D1)
   ;
     D1=W
   ),
   ( may_trigger(H/I),
     \+has_no_history(C) ->
     use_auxiliary_predicate(novel_production),
     use_auxiliary_predicate(extend_history),
     does_use_history(H/I,D),
     gen_occ_allocation(H/I,D,J,K,E1),
     ( named_history(C,F1,G1) ->
       ( G1==[] ->
         empty_named_history_novel_production(F1,H1),
         empty_named_history_extend_history(F1,I1)
       ;
         J1=F1
       )
     ;
       J1=C
     ),
     ( var(H1) ->
       H1='$novel_production'(K,J1),
       I1='$extend_history'(K,J1)
     ;
       true
     ),
     ( is_observed(H/I,D) ->
       gen_uncond_attach_goal(H/I,K,J,K1,L1),
       gen_state_cond_call(K,H/I,V,L1,M1)
     ;
       K1=true,
       M1=V
     )
   ;
     E1=true,
     H1=true,
     I1=true,
     ( is_observed(H/I,D) ->
       get_allocation_occurrence(H/I,N1),
       ( D==N1 ->
         gen_insert_constraint_internal_goal(H/I,K1,L,J,K),
         L1=0
       ;
         K1= (O1,P1),
         gen_occ_allocation(H/I,D,J,K,O1),
         gen_uncond_attach_goal(H/I,K,J,P1,L1)
       ),
       gen_state_cond_call(K,H/I,V,L1,M1)
     ;
       gen_occ_allocation(H/I,D,J,K,K1),
       M1=V
     )
   ),
   ( is_stored_in_guard(H/I,C) ->
     Q1=K1,
     R1=true
   ;
     Q1=true,
     R1=K1
   ),
   S1= (N:-R,E1,H1,Q1,T,D1,I1,R1,U,M1),
   add_location(S1,C,T1),
   F=[T1|G].
propagation_multi_headed(A,B,C,D,E,F,G,H,I,J) :-
   B=[K|L],
   propagation_prelude(A,B,D,F,G,H,I,M),
   extend_id(H,N),
   propagation_nested_code(L,[K,A],C,D,E,F,G,N,M,J).
propagation_prelude(A,[G|H],B,I/J,C,D,E,F) :-
   head_info(A,J,K,L,M,N),
   build_head(I,J,D,M,O),
   get_constraint_mode(I/J,P),
   head_arg_matches(N,P,[],Q,R,[],S),
   B=rule(_,_,T,U),
   extra_active_delegate_variables(A,[G,H,T,U],R,V),
   lookup_passive_head(G,[A],R,S,W,X),
   gen_occ_allocation(I/J,C,K,L,Y),
   extend_id(D,Z),
   append([X|M],V,A1),
   build_head(I,J,[C|Z],A1,B1),
   C1=B1,
   D1= (O:-Q,W,!,Y,C1),
   add_dummy_location(D1,E1),
   E=[E1|F].
propagation_nested_code([],[I|J],A,B,C,D,E,F,G,H) :-
   universal_search_iterator_end([I|J],[],B,D,E,F,G,K),
   propagation_body(I,J,A,B,C,D,E,F,K,H).
propagation_nested_code([J|K],A,B,C,D,E,F,G,H,I) :-
   universal_search_iterator_end(A,[J|K],C,E,F,G,H,L),
   universal_search_iterator([J|K],A,C,E,F,G,L,M),
   inc_id(G,N),
   propagation_nested_code(K,[J|A],B,C,D,E,F,N,M,I).
check_fd_lookup_condition(A,B,_,_) :-
   get_store_type(A/B,global_singleton),
   !.
check_fd_lookup_condition(A,B,C,D) :-
   \+may_trigger(A/B),
   get_functional_dependency(A/B,1,E,F),
   copy_term(E-F,C-G),
   term_variables(D,H),
   intersect_eq(G,H,G),
   !.
propagation_body(A,B,C,D,E,J/K,F,G,H,I) :-
   D=rule(_,L,M,N),
   gen_var_susp_list_for_b(B,[A,M,N],O,P,Q,R,S),
   flatten(P,T),
   init(R,U),
   last(R,V),
   gen_var(W),
   gen_var(X),
   functor(A,Y,Z),
   gen_vars(Z,A1),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(Y/Z,B1),get_static_suspension_field(Y/Z,B1,state,active,C1),get_static_suspension_term_field(arguments,Y/Z,B1,A1))),
   D1= (W=B1,C1),
   E1=[[W|X]|T],
   build_head(J,K,[F|G],E1,F1),
   ( check_fd_lookup_condition(Y,Z,A,B) ->
     universal_search_iterator_failure_vars(B,G,P,Q,S,G1,H1),
     I1=G1
   ;
     I1=[X|T],
     H1=G
   ),
   ( H1=[_] ->
     J1=H1
   ;
     J1=[F|H1]
   ),
   build_head(J,K,J1,I1,K1),
   L1=K1,
   A=..[_|M1],
   pairup(M1,A1,N1),
   get_constraint_mode(Y/Z,O1),
   head_arg_matches(N1,O1,O,P1,Q1),
   different_from_other_susps(A,W,B,U,R1),
   guard_body_copies(D,Q1,S1,T1),
   get_occurrence(J/K,F,_,U1),
   ( is_observed(J/K,F) ->
     init(Q,V1),
     gen_uncond_attach_goal(J/K,V,V1,W1,X1),
     gen_state_cond_call(V,J/K,L1,X1,Y1)
   ;
     W1=true,
     Y1=L1
   ),
   (
     (
       is_least_occurrence(E)
     ;
       has_no_history(E)
     ) ->
     Z1=true,
     A2=true
   ;
     ( \+may_trigger(J/K),
       maplist(is_passive(E),C) ->
       Z1=true,
       A2=true
     )
   ;
     get_occurrence(J/K,F,_,U1),
     use_auxiliary_predicate(novel_production),
     use_auxiliary_predicate(extend_history),
     does_use_history(J/K,F),
     ( named_history(E,B2,C2) ->
       ( C2==[] ->
         empty_named_history_novel_production(B2,Z1),
         empty_named_history_extend_history(B2,A2)
       ;
         reverse([W|U],D2),
         named_history_susps(C2,[U1|C],[V|D2],E2),
         E2=[F2|_],
         ( length(C2,1) ->
           A2='$extend_history'(F2,B2),
           Z1='$novel_production'(F2,B2)
         ;
           findall(G2,(member(I2,C2),get_occurrence_from_id(G2,_,E,I2)),H2),
           J2=..[t,B2|E2]
         )
       )
     ;
       F2=V,
       maplist(extract_symbol,L,H2),
       sort([U1|C],C2),
       history_susps(C,[W|U],V,U1,E2),
       J2=..[t,E|E2]
     ),
     ( var(Z1) ->
       novel_production_calls(H2,C2,E2,E,K2,L2),
       A2='$extend_history'(F2,K2),
       Z1= (K2=J2,L2)
     ;
       true
     )
   ),
   ( chr_pp_flag(debugable,on) ->
     D=rule(_,_,M,N),
     my_term_copy(M-N,Q1,M2-N2),
     get_occurrence(J/K,F,_,U1),
     sort_by_key([V,W|U],[U1|C],O2),
     P2='chr debug_event'(try([],O2,M2,N2)),
     Q2='chr debug_event'(apply([],O2,M2,N2))
   ;
     P2=true,
     Q2=true
   ),
   ( is_stored_in_guard(J/K,E) ->
     R2=W1,
     S2=true
   ;
     R2=true,
     S2=W1
   ),
   T2= (F1:-D1,R1,P1,Z1,R2,S1,P2->Q2,A2,S2,T1,Y1;L1),
   add_location(T2,E,U2),
   H=[U2|I].
extract_symbol(A,B/C) :-
   functor(A,B,C).
novel_production_calls([],[],[],_,_,true).
novel_production_calls([C|D],[E|F],[G|H],A,B,(I,J)) :-
   get_occurrence_from_id(C,K,A,E),
   delay_phase_end(validate_store_type_assumptions,novel_production_call(C,K,'$novel_production'(G,B),I)),
   novel_production_calls(D,F,H,A,B,J).
history_susps(A,B,C,D,E) :-
   reverse(B,F),
   sort_by_key([C|F],[D|A],E).
named_history_susps([],_,_,[]).
named_history_susps([C|D],A,B,[E|F]) :-
   select2(C,E,A,B,G,H),
   !,
   named_history_susps(D,G,H,F).
gen_var_susp_list_for([F],A,B,C,D,E) :-
   !,
   functor(F,G,H),
   head_info(F,H,_,E,D,I),
   get_constraint_mode(G/H,J),
   head_arg_matches(I,J,[],_,B),
   extra_active_delegate_variables(F,A,B,K),
   append(D,K,C).
gen_var_susp_list_for([F|G],A,B,C,D,E) :-
   gen_var_susp_list_for(G,[F|A],H,D,_,_),
   functor(F,I,J),
   gen_var(E),
   head_info(F,J,_,K,_,L),
   get_constraint_mode(I/J,M),
   head_arg_matches(L,M,H,_,B),
   passive_delegate_variables(F,G,A,B,N),
   append(N,[K,E|D],C).
gen_var_susp_list_for_b([D],A,B,[E],C,[F],[]) :-
   !,
   functor(D,G,H),
   head_info(D,H,_,F,C,I),
   get_constraint_mode(G/H,J),
   head_arg_matches(I,J,[],_,B),
   extra_active_delegate_variables(D,A,B,K),
   append(C,K,E).
gen_var_susp_list_for_b([D|E],A,B,[F|G],C,[H|I],[J|K]) :-
   gen_var_susp_list_for_b(E,[D|A],L,G,C,I,K),
   functor(D,M,N),
   gen_var(J),
   head_info(D,N,_,H,_,O),
   get_constraint_mode(M/N,P),
   head_arg_matches(O,P,L,_,B),
   passive_delegate_variables(D,E,A,B,Q),
   append(Q,[H,J],F).
get_prop_inner_loop_vars([F],A,B,C,D,E,[]) :-
   !,
   functor(F,G,H),
   head_info(F,H,E,D,I,J),
   get_constraint_mode(G/H,K),
   head_arg_matches(J,K,[],_,C),
   extra_active_delegate_variables(F,A,C,L),
   append(I,L,B).
get_prop_inner_loop_vars([F|G],A,B,C,D,E,[H|I]) :-
   get_prop_inner_loop_vars(G,[F|A],J,K,D,E,I),
   functor(F,L,M),
   gen_var(N),
   head_info(F,M,_,H,_,O),
   get_constraint_mode(L/M,P),
   head_arg_matches(O,P,K,_,C),
   passive_delegate_variables(F,G,A,C,Q),
   append(Q,[H,N|J],B).
reorder_heads(A,B,C,D,E,F) :-
   ( chr_pp_flag(reorder_heads,on),
     length(C,G),
     G=<6 ->
     reorder_heads_main(A,B,C,D,E,F)
   ;
     E=C,
     F=D
   ).
reorder_heads_main(A,B,C,D,E,F) :-
   term_variables(B,G),
   H=entry([],[],G,C,D,A),
   copy_term_nat(H,I),
   a_star(I,K^ (chr_translate:final_data(K)),L^M^N^ (chr_translate:expand_data(L,M,N)),J),
   I=H,
   J=entry(O,P,_,_,_,_),
   reverse(O,E),
   reverse(P,F).
final_data(A) :-
   A=entry(_,_,_,_,[],_).
expand_data(A,B,C) :-
   A=entry(D,E,F,G,H,I),
   select2(J,K,G,H,L,M),
   term_variables([J|F],N),
   B=entry([J|D],[K|E],N,L,M,I),
   order_score(J,K,F,L,I,C).
order_score(A,B,C,D,E,F) :-
   functor(A,G,H),
   get_store_type(G/H,I),
   order_score(I,A,B,C,D,E,99999,F).
order_score(default,A,_,B,C,_,D,E) :-
   term_variables(A,F),
   term_variables(C,G),
   ground_vars([A],H),
   list_difference_eq(F,H,I),
   order_score_vars(I,B,G,J),
   E is min(D,J).
order_score(multi_inthash(E),A,_,B,_,_,C,D) :-
   ( C=<100 ->
     D=C
   ;
     order_score_indexes(E,A,B,D)
   ).
order_score(multi_hash(E),A,_,B,_,_,C,D) :-
   ( C=<100 ->
     D=C
   ;
     order_score_indexes(E,A,B,D)
   ).
order_score(global_ground,A,_,B,C,_,D,E) :-
   term_variables(A,F),
   term_variables(C,G),
   order_score_vars(F,B,G,H),
   I is H*200,
   E is min(D,I).
order_score(var_assoc_store(_,_),_,_,_,_,_,_,1).
order_score(global_singleton,_,_,_,_,_,_,A) :-
   A=1.
order_score(multi_store(H),A,B,C,D,E,F,G) :-
   multi_order_score(H,A,B,C,D,E,F,G).
multi_order_score([],_,_,_,_,_,A,A).
multi_order_score([H|I],A,B,C,D,E,F,G) :-
   ( order_score(H,A,B,C,D,E,F,J) ->
     true
   ;
     J=F
   ),
   multi_order_score(I,A,B,C,D,E,J,G).
order_score(identifier_store(E),A,_,B,_,_,C,D) :-
   arg(E,A,F),
   memberchk_eq(F,B),
   D is min(C,10).
order_score(type_indexed_identifier_store(E,_),A,_,B,_,_,C,D) :-
   arg(E,A,F),
   memberchk_eq(F,B),
   D is min(C,10).
order_score_indexes(A,B,C,D) :-
   copy_term_nat(B+C,E+F),
   numbervars(F,0,_),
   order_score_indexes(A,E,D).
order_score_indexes([C|D],A,B) :-
   args(C,A,E),
   ( maplist(ground,E) ->
     B=100
   ;
     order_score_indexes(D,A,B)
   ).
memberchk_eq_flip(A,B) :-
   memberchk_eq(B,A).
order_score_vars(A,B,C,D) :-
   order_score_count_vars(A,B,C,F-G-E),
   ( F-G-E==0-0-0 ->
     D=0
   ;
     ( F>0 ->
       D is max(10-F,0)
     )
   ;
     ( G>0 ->
       D is max(10-G,1)*100
     )
   ;
     D is max(10-E,1)*1000
   ).
order_score_count_vars([],_,_,0-0-0).
order_score_count_vars([C|D],A,B,F-G-E) :-
   order_score_count_vars(D,A,B,I-J-H),
   ( memberchk_eq(C,A) ->
     F is I+1,
     G=J,
     E=H
   ;
     ( memberchk_eq(C,B) ->
       G is J+1,
       F=I,
       E=H
     )
   ;
     E is H+1,
     F=I,
     G=J
   ).
create_get_mutable_ref(A,B,C) :-
   C= (B=mutable(A)).
create_get_mutable(A,B,C) :-
   B=mutable(A),
   C=true.
gen_var(_).
gen_vars(A,B) :-
   length(B,A).
ast_head_info1(A,B,C,D,E) :-
   A=chr_constraint(_/G,F,_),
   vars_susp(G,B,C,D),
   pairup(F,B,E).
head_info1(A,_/F,B,C,D,E) :-
   vars_susp(F,B,C,D),
   A=..[_|G],
   pairup(G,B,E).
head_info(A,B,C,D,E,F) :-
   vars_susp(B,C,D,E),
   A=..[_|G],
   pairup(G,C,F).
inc_id([A|B],[C|B]) :-
   C is A+1.
dec_id([A|B],[C|B]) :-
   C is A-1.
extend_id(A,[0|A]).
next_id([_,A|B],[C|B]) :-
   C is A+1.
build_head(D/E,A,B,C) :-
   build_head(D,E,A,B,C).
build_head(A,B,C,D,E) :-
   buildName(A,B,C,F),
   (
     (
       chr_pp_flag(debugable,on)
     ;
       is_stored(A/B),
       (
         has_active_occurrence(A/B)
       ;
         chr_pp_flag(late_allocation,off)
       ),
       (
         may_trigger(A/B)
       ;
         get_allocation_occurrence(A/B,G),
         get_max_occurrence(A/B,H),
         H>=G
       )
     ) ->
     E=..[F|D]
   ;
     init(D,I),
     E=..[F|I]
   ).
buildName(A,B,C,D) :-
   (
     (
       chr_pp_flag(debugable,on)
     ;
       once((is_stored(A/B),(has_active_occurrence(A/B);chr_pp_flag(late_allocation,off)),(may_trigger(A/B);get_allocation_occurrence(A/B,E),get_max_occurrence(A/B,F),F>=E);C\=[0]))
     ) ->
     atom_concat(A,'___',G),
     atomic_concat(G,B,H),
     buildName_(C,H,D)
   ;
     D=A
   ).
buildName_([],A,A).
buildName_([C|D],A,B) :-
   buildName_(D,A,E),
   atom_concat(E,'__',F),
   atomic_concat(F,C,B).
vars_susp(A,B,C,D) :-
   length(B,A),
   append(B,[C],D).
or_pattern(A,B) :-
   C is A-1,
   B is 1<<C.
and_pattern(A,B) :-
   C is A-1,
   D is 1<<C,
   B is -1* (D+1).
make_name(A,C/D,B) :-
   atom_concat_list([A,C,'___',D],B).
make_attr(A,B,C,D) :-
   length(C,A),
   D=..[v,B|C].
get_all_suspensions2(A,B,C) :-
   chr_pp_flag(dynattr,off),
   !,
   make_attr(A,_,C,B).
get_all_suspensions2(A,B,C,D) :-
   length(D,A),
   C='chr all_suspensions'(D,1,B).
normalize_attr(A,B,C) :-
   B='chr normalize_attr'(A,C).
get_suspensions(A,B,C,C=E,D) :-
   chr_pp_flag(dynattr,off),
   !,
   make_attr(A,_,F,E),
   nth1(B,F,D).
get_suspensions(_,A,B,C,D) :-
   C= (memberchk(A-D,B)->true;D=[]).
singleton_attr(A,B,C,D) :-
   chr_pp_flag(dynattr,off),
   !,
   or_pattern(C,E),
   make_attr(A,E,F,D),
   nth1(C,F,[B],G),
   set_elems(G,[]).
singleton_attr(_,A,B,C) :-
   C=[B-[A]].
add_attr(A,B,C,D,E,F) :-
   chr_pp_flag(dynattr,off),
   !,
   make_attr(A,G,H,I),
   or_pattern(C,J),
   nth1(C,H,K),
   substitute_eq(K,H,[B|K],L),
   make_attr(A,G,L,M),
   substitute_eq(K,H,[B],N),
   make_attr(A,O,N,P),
   E= (D=I,(G/\J=:=J->F=M;O is G\/J,F=P)),
   !.
add_attr(_,A,B,C,D,E) :-
   D= ('chr select'(C,B-G,F)->E=[B-[A|G]|F];E=[B-[A]|C]).
rem_attr(A,B,C,D,E,F) :-
   chr_pp_flag(dynattr,off),
   chr_pp_flag(experiment,off),
   !,
   or_pattern(D,G),
   and_pattern(D,H),
   make_attr(A,I,J,K),
   nth1(D,J,L),
   substitute_eq(L,J,[],M),
   make_attr(A,N,M,O),
   substitute_eq(L,J,P,Q),
   make_attr(A,I,Q,R),
   get_target_module(S),
   F= (E=K,(I/\G=:=G->'chr sbag_del_element'(L,C,P),(P==[]->N is I/\H,(N==0->del_attr(B,S);put_attr(B,S,O));put_attr(B,S,R));true)),
   !.
rem_attr(_,A,B,C,D,E) :-
   chr_pp_flag(dynattr,off),
   chr_pp_flag(experiment,on),
   !,
   or_pattern(C,F),
   and_pattern(C,G),
   H is C+1,
   get_target_module(I),
   E= (arg(1,D,J),(J/\F=:=F->arg(H,D,K),'chr sbag_del_element'(K,B,L),(L==[]->M is J/\G,(M==0->del_attr(A,I);setarg(1,D,M),setarg(H,D,L));setarg(H,D,L));true)),
   !.
rem_attr(_,A,B,C,D,E) :-
   get_target_module(F),
   E= ('chr select'(D,C-H,G)->'chr sbag_del_element'(H,B,I),(I==[]-> (G==[]->del_attr(A,F);put_attr(A,F,G));put_attr(A,F,[C-I|G]));true).
merge_attributes(A,B,C,D,E) :-
   chr_pp_flag(dynattr,off),
   !,
   make_attr(A,F,G,H),
   merge_attributes2(A,F,G,C,I,E),
   D= (B=H,I).
merge_attributes(_,A,B,C,D) :-
   C= (sort(A,E),sort(B,F),'chr new_merge_attributes'(E,F,D)).
merge_attributes2(A,B,C,D,E,F) :-
   make_attr(A,G,H,I),
   bagof(J,L^M^N^O^ (member2(C,H,L-M),J= (sort(M,N),'chr merge_attributes'(L,N,O))),K),
   list2conj(K,P),
   bagof(Q,S^T^U^member((S,'chr merge_attributes'(T,U,Q)),K),R),
   make_attr(A,V,R,F),
   E= (D=I,P,V is B\/G).
lookup_passive_head(A,B,C,D,E) :-
   functor(A,F,G),
   get_store_type(F/G,H),
   lookup_passive_head(H,A,B,C,[],D,E).
lookup_passive_head(A,B,C,D,E,F) :-
   functor(A,G,H),
   get_store_type(G/H,I),
   lookup_passive_head(I,A,B,C,D,E,F).
lookup_passive_head(default,A,B,C,_,D,E) :-
   functor(A,F,G),
   passive_head_via(A,B,C,D,E),
   update_store_type(F/G,default).
lookup_passive_head(multi_inthash(F),A,_,B,C,D,E) :-
   hash_lookup_passive_head(inthash,F,A,B,C,D,E,_).
lookup_passive_head(multi_hash(F),A,_,B,C,D,E) :-
   hash_lookup_passive_head(hash,F,A,B,C,D,E,_).
lookup_passive_head(global_ground,A,_,_,_,B,C) :-
   functor(A,D,E),
   global_ground_store_name(D/E,F),
   make_get_store_goal(F,C,B),
   update_store_type(D/E,global_ground).
lookup_passive_head(var_assoc_store(E,F),A,_,B,_,C,D) :-
   arg(E,A,G),
   arg(F,A,H),
   translate([G,H],B,[I,J]),
   get_target_module(K),
   C= (get_attr(I,K,L),lookup_assoc_store(L,J,D)).
lookup_passive_head(global_singleton,A,_,_,_,B,C) :-
   functor(A,D,E),
   global_singleton_store_name(D/E,F),
   make_get_store_goal(F,G,H),
   B= (H,G\==[],C=[G]),
   update_store_type(D/E,global_singleton).
lookup_passive_head(multi_store(G),A,B,C,D,E,F) :-
   once((member(H,G),lookup_passive_head(H,A,B,C,D,E,F))).
lookup_passive_head(identifier_store(E),A,_,B,_,C,D) :-
   functor(A,F,G),
   arg(E,A,H),
   translate([H],B,[I]),
   delay_phase_end(validate_store_type_assumptions,identifier_lookup(F/G,E,D,I,C)),
   update_store_type(F/G,identifier_store(E)),
   get_identifier_index(F/G,E,_).
lookup_passive_head(type_indexed_identifier_store(E,F),A,_,B,_,C,D) :-
   functor(A,G,H),
   arg(E,A,I),
   ( var(I) ->
     translate([I],B,[J]),
     C=K
   ;
     ( ground(I),
       I='$chr_identifier_match'(L,_) ->
       lookup_only_identifier_atom(F,L,J,M),
       C= (M,K)
     )
   ),
   delay_phase_end(validate_store_type_assumptions,type_indexed_identifier_lookup(G/H,E,F,D,J,K)),
   update_store_type(G/H,type_indexed_identifier_store(E,F)),
   get_type_indexed_identifier_index(F,G/H,E,_).
identifier_lookup(A,B,C,D,E) :-
   get_identifier_size(F),
   functor(G,struct,F),
   get_identifier_index(A,B,H),
   arg(H,G,C),
   E= (D=G).
type_indexed_identifier_lookup(A,B,C,D,E,F) :-
   type_indexed_identifier_structure(C,G),
   get_type_indexed_identifier_index(C,A,B,H),
   arg(H,G,D),
   F= (E=G).
hash_lookup_passive_head(A,B,C,D,E,F,G,H) :-
   pick_hash_index(B,C,D,H,I,J),
   ( J=[K] ->
     true
   ;
     K=..[k|J]
   ),
   functor(C,L,M),
   multi_hash_lookup_goal(L/M,A,H,K,G,N),
   check_ground(E,I,O),
   my_term_copy(O,D,P),
   F= (P,N),
   ( A==inthash ->
     update_store_type(L/M,multi_inthash([H]))
   ;
     update_store_type(L/M,multi_hash([H]))
   ).
pick_hash_index(A,B,C,D,E,F) :-
   member(D,A),
   args(D,B,E),
   key_in_scope(E,C,F),
   !.
key_in_scope([],_,[]).
key_in_scope([B|C],A,[D|E]) :-
   term_variables(B,F),
   translate(F,A,G),
   copy_term(B/F,D/G),
   key_in_scope(C,A,E).
existential_lookup(var_assoc_store(I,J),A,B,C,D,E,F,G,H,H) :-
   !,
   lookup_passive_head(var_assoc_store(I,J),A,B,C,D,K,L),
   sbag_member_call(G,L,M),
   functor(A,N,O),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(N/O,E),get_static_suspension_field(N/O,E,state,active,P))),
   F= (K,M,G=E,P).
existential_lookup(global_singleton,A,_,_,_,B,C,D,E,E) :-
   !,
   functor(A,F,G),
   global_singleton_store_name(F/G,H),
   make_get_store_goal(H,D,I),
   C= (I,D\==[],D=B),
   update_store_type(F/G,global_singleton).
existential_lookup(multi_store(J),A,B,C,D,E,F,G,H,I) :-
   !,
   once((member(K,J),existential_lookup(K,A,B,C,D,E,F,G,H,I))).
existential_lookup(multi_inthash(I),A,_,B,C,D,E,F,G,H) :-
   !,
   existential_hash_lookup(inthash,I,A,B,C,D,E,F,G,H).
existential_lookup(multi_hash(I),A,_,B,C,D,E,F,G,H) :-
   !,
   existential_hash_lookup(hash,I,A,B,C,D,E,F,G,H).
existential_lookup(identifier_store(J),A,B,C,D,E,F,G,H,I) :-
   !,
   lookup_passive_head(identifier_store(J),A,B,C,D,K,L),
   hash_index_filter(H,[J],I),
   functor(A,M,N),
   ( check_fd_lookup_condition(M,N,A,_) ->
     O= (L=[G])
   ;
     sbag_member_call(G,L,O)
   ),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(M/N,E),get_static_suspension_field(M/N,E,state,active,P))),
   F= (K,O,G=E,P).
existential_lookup(type_indexed_identifier_store(J,K),A,B,C,D,E,F,G,H,I) :-
   !,
   lookup_passive_head(type_indexed_identifier_store(J,K),A,B,C,D,L,M),
   hash_index_filter(H,[J],I),
   functor(A,N,O),
   ( check_fd_lookup_condition(N,O,A,_) ->
     P= (M=[G])
   ;
     sbag_member_call(G,M,P)
   ),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(N/O,E),get_static_suspension_field(N/O,E,state,active,Q))),
   F= (L,P,G=E,Q).
existential_lookup(A,B,C,D,E,F,G,H,I,I) :-
   lookup_passive_head(A,B,C,D,E,J,K),
   sbag_member_call(H,K,L),
   functor(B,M,N),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(M/N,F),get_static_suspension_field(M/N,F,state,active,O))),
   G= (J,L,H=F,O).
existential_hash_lookup(A,B,C,D,E,F,G,H,I,J) :-
   hash_lookup_passive_head(A,B,C,D,E,K,L,M),
   hash_index_filter(I,M,J),
   functor(C,N,O),
   ( check_fd_lookup_condition(N,O,C,_) ->
     P= (L=[H])
   ;
     sbag_member_call(H,L,P)
   ),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(N/O,F),get_static_suspension_field(N/O,F,state,active,Q))),
   G= (K,P,H=F,Q).
hash_index_filter(A,B,C) :-
   hash_index_filter(A,B,1,C).
hash_index_filter([],_,_,[]).
hash_index_filter([D|E],A,B,C) :-
   ( A=[F|G] ->
     H is B+1,
     ( F>B ->
       C=[D|I],
       hash_index_filter(E,[F|G],H,I)
     ;
       ( F==B ->
         C=[silent(D)|I],
         hash_index_filter(E,G,H,I)
       )
     )
   ;
     C=[D|E]
   ).
assume_constraint_stores([]).
assume_constraint_stores([A|B]) :-
   ( chr_pp_flag(debugable,off),
     (
       only_ground_indexed_arguments(A)
     ;
       chr_pp_flag(mixed_stores,on)
     ),
     is_stored(A),
     get_store_type(A,default) ->
     get_indexed_arguments(A,C),
     get_constraint_mode(A,D),
     aggregate_all(bag(E)-count,(member(E,C),nth1(E,D,+)),F-G),
     ( G>10 ->
       findall([E],member(E,F),H)
     ;
       findall(E,(sublist(E,F),E\==[]),I),
       predsort(longer_list,I,H)
     ),
     ( get_functional_dependency(A,1,J,K),
       all_distinct_var_args(J),
       K==[] ->
       assumed_store_type(A,global_singleton)
     ;
       (
         (
           only_ground_indexed_arguments(A)
         ;
           G>0
         ) ->
         get_constraint_type_det(A,L),
         partition_indexes(H,L,M,N,O,P),
         ( N=[] ->
           Q=R
         ;
           Q=[multi_inthash(N)|R]
         ),
         ( M=[] ->
           R=S
         ;
           R=[multi_hash(M)|S]
         ),
         ( O=[] ->
           S=T
         ;
           maplist(wrap_in_functor(identifier_store),O,U),
           append(U,T,S)
         ),
         append(P,V,T),
         ( only_ground_indexed_arguments(A) ->
           V=[global_ground]
         ;
           V=[default]
         ),
         assumed_store_type(A,multi_store(Q))
       )
     ;
       true
     )
   ;
     true
   ),
   assume_constraint_stores(B).
partition_indexes([],_,[],[],[],[]).
partition_indexes([F|G],A,B,C,D,E) :-
   ( F=[H],
     nth1(H,A,I),
     unalias_type(I,J),
     J==chr_identifier ->
     D=[H|K],
     C=L,
     B=M,
     E=N
   ;
     ( F=[H],
       nth1(H,A,I),
       unalias_type(I,J),
       nonvar(J),
       J=chr_identifier(O) ->
       E=[type_indexed_identifier_store(H,O)|N],
       D=K,
       C=L,
       B=M
     )
   ;
     ( F=[H],
       nth1(H,A,I),
       unalias_type(I,J),
       J==dense_int ->
       C=[F|L],
       B=M,
       D=K,
       E=N
     )
   ;
     ( member(H,F),
       nth1(H,A,I),
       unalias_type(I,J),
       nonvar(J),
       J=chr_identifier(_) ->
       C=L,
       B=M,
       D=K,
       E=N
     )
   ;
     C=L,
     B=[F|M],
     D=K,
     E=N
   ),
   partition_indexes(G,A,M,L,K,N).
longer_list(A,B,C) :-
   length(B,D),
   length(C,E),
   compare(F,E,D),
   ( F== (=) ->
     compare(A,B,C)
   ;
     A=F
   ).
all_distinct_var_args(A) :-
   copy_term_nat(A,B),
   functor(A,C,D),
   functor(E,C,D),
   E=@=B.
get_indexed_arguments(A,B) :-
   A=_/C,
   get_indexed_arguments(1,C,A,B).
get_indexed_arguments(A,B,C,D) :-
   ( A>B ->
     D=[]
   ;
     ( is_indexed_argument(C,A) ->
       D=[A|E]
     ;
       D=E
     ),
     F is A+1,
     get_indexed_arguments(F,B,C,E)
   ).
validate_store_type_assumptions([]).
validate_store_type_assumptions([A|B]) :-
   validate_store_type_assumption(A),
   validate_store_type_assumptions(B).
universal_search_iterator_end([G|H],A,B,I/J,C,D,E,F) :-
   B=rule(_,_,K,L),
   gen_var_susp_list_for_b(H,[G,A,K,L],_,M,N,_,O),
   universal_search_iterator_failure_vars(H,D,M,N,O,P,Q),
   flatten(M,R),
   S=[[]|R],
   build_head(I,J,[C|D],S,T),
   ( Q=[_] ->
     get_success_continuation_code_id(I/J,C,U),
     V=[U]
   ;
     V=[C|Q]
   ),
   build_head(I,J,V,P,W),
   X= (T:-W),
   add_dummy_location(X,Y),
   E=[Y|F].
universal_search_iterator_failure_vars(A,B,C,D,E,F,G) :-
   ( B=[0|_] ->
     next_id(B,G),
     F=D
   ;
     C=[_|H],
     dec_id(B,I),
     ( A=[J|K],
       functor(J,L,M),
       check_fd_lookup_condition(L,M,J,K) ->
       E=[_|N],
       universal_search_iterator_failure_vars(K,I,H,D,N,F,G)
     ;
       G=I,
       flatten(H,O),
       E=[P|_],
       F=[P|O]
     )
   ).
universal_search_iterator([F|G],[H|I],A,J/K,B,C,D,E) :-
   A=rule(_,_,L,M),
   gen_var_susp_list_for_b(I,[H,F,G,L,M],N,O,P,Q,R),
   init(Q,S),
   flatten(O,T),
   gen_var(U),
   functor(H,V,W),
   gen_vars(W,X),
   head_info(H,W,X,Y,_,Z),
   get_constraint_mode(V/W,A1),
   head_arg_matches(Z,A1,N,B1,C1),
   delay_phase_end(validate_store_type_assumptions,(static_suspension_term(V/W,D1),get_static_suspension_field(V/W,D1,state,active,E1),get_static_suspension_term_field(arguments,V/W,D1,X))),
   different_from_other_susps(H,Y,I,S,F1),
   G1= (Y=D1,E1,F1,B1),
   add_heads_ground_variables([H|I],[],H1),
   lookup_passive_head(F,[H|I],C1,H1,I1,J1),
   inc_id(C,K1),
   L1=[[Y|U]|T],
   build_head(J,K,[B|C],L1,M1),
   passive_delegate_variables(H,I,[F,G,L,M],C1,N1),
   append([J1|N1],[Y,U|T],O1),
   build_head(J,K,[B|K1],O1,P1),
   ( check_fd_lookup_condition(V,W,H,I) ->
     universal_search_iterator_failure_vars(I,C,O,P,R,Q1,R1),
     S1=Q1
   ;
     S1=[U|T],
     R1=C
   ),
   ( R1=[_] ->
     T1=R1
   ;
     T1=[B|R1]
   ),
   build_head(J,K,T1,S1,U1),
   V1= (M1:-G1,I1->P1;U1),
   add_dummy_location(V1,W1),
   D=[W1|E].
ai_observation_analysis(A) :-
   ( chr_pp_flag(ai_observation_analysis,on),
     get_target_module(_),
     '$chr_compiled_with_version'(3) ->
     list_to_ord_set(A,B),
     abstract_constraints(B),
     ai_observation_schedule_initial_calls(B,B),
     ai_observation_gather_results
   ;
     true
   ).
ai_observation_schedule_initial_calls([],_).
ai_observation_schedule_initial_calls([B|C],A) :-
   ai_observation_schedule_initial_call(B,A),
   ai_observation_schedule_initial_calls(C,A).
ai_observation_schedule_initial_call(A,_) :-
   ai_observation_top(A,B),
   initial_call_pattern(B).
ai_observation_schedule_new_calls([],_).
ai_observation_schedule_new_calls([B|C],A) :-
   A=odom(_,D),
   initial_call_pattern(odom(B,D)),
   ai_observation_schedule_new_calls(C,A).
ai_observation_lub(odom(A,B),odom(A,C),odom(A,D)) :-
   ord_intersection(B,C,D).
ai_observation_bot(A,B,odom(A,B)).
ai_observation_top(A,odom(A,B)) :-
   ord_empty(B).
ai_observation_leq(odom(A,B),odom(A,C)) :-
   ord_subset(C,B).
ai_observation_observe_set(A,B,C) :-
   ord_subtract(A,B,C).
ai_observation_abstract_constraint(A,B,C) :-
   functor(A,D,E),
   C=D/E,
   memberchk(C,B).
ai_observation_abstract_constraints(A,B,C) :-
   findall(D,(member(E,A),ai_observation_abstract_constraint(E,B,D)),C).
ai_observation_abstract_goal_(A,B,C,D,E,F) :-
   term_variables((A,B,C),G),
   append(A,B,H),
   ground_vars(H,I),
   list_difference_eq(G,I,J),
   ai_observation_abstract_goal(D,E,F,[],J),
   !.
ground_vars([],[]).
ground_vars([B|C],A) :-
   functor(B,D,E),
   get_constraint_mode(D/E,F),
   head_info(B,E,_,_,_,G),
   head_arg_matches(G,F,[],_,_,[],H),
   ground_vars(C,I),
   append(H,I,A).
ai_observation_abstract_goal((E,F),A,B,C,D) :-
   !,
   ai_observation_abstract_goal(E,A,B,G,D),
   ai_observation_abstract_goal(F,A,G,C,D).
ai_observation_abstract_goal((C;D),A,[(F;G)|E],E,B) :-
   !,
   ai_observation_abstract_goal(C,A,F,[],B),
   ai_observation_abstract_goal(D,A,G,[],B).
ai_observation_abstract_goal((E->F),A,B,C,D) :-
   !,
   ai_observation_abstract_goal(E,A,B,G,D),
   ai_observation_abstract_goal(F,A,G,C,D).
ai_observation_abstract_goal(A,B,[C|D],D,_) :-
   ai_observation_abstract_constraint(A,B,C),
   !.
ai_observation_abstract_goal(true,_,A,A,_) :-
   !.
ai_observation_abstract_goal(writeln(_),_,A,A,_) :-
   !.
ai_observation_abstract_goal(A,_,B,B,C) :-
   builtin_binds_b(A,D),
   intersect_eq(D,C,[]),
   !.
ai_observation_abstract_goal(_,_,[A|B],B,_) :-
   A=builtin.
ai_observation_is_observed(odom(_,B),A) :-
   \+ord_memberchk(A,B).
unconditional_occurrence(A,B) :-
   get_occurrence(A,B,C,_),
   get_rule(C,D),
   D=pragma(E,_,_,_,_),
   copy_term_nat(E,F),
   F=rule(G,H,I,_),
   guard_entailment:entails_guard([chr_pp_headvariables(G,H)],I),
   once((G=[J],H==[];H=[J],G==[],\+may_trigger(A))),
   all_distinct_var_args(J).
partial_wake_args([],_,_,_).
partial_wake_args([C|D],[E|F],A,B) :-
   ( E\== (+) ->
     ( nonvar(C) ->
       no_partial_wake(B)
     ;
       ( memberchk_eq(C,A) ->
         no_partial_wake(B)
       )
     ;
       true
     )
   ;
     true
   ),
   partial_wake_args(D,F,A,B).
generate_show_constraint(A,B,C,D) :-
   ( chr_pp_flag(show,on) ->
     B=['$show'/0|A],
     generate_show_rules(A,D,[E|C]),
     inc_rule_count(F),
     E=pragma(rule(['$show'],[],true,true),ids([0],[]),[],no,F)
   ;
     B=A,
     D=C
   ).
generate_show_rules([],A,A).
generate_show_rules([C/D|B],[E|F],A) :-
   functor(G,C,D),
   inc_rule_count(H),
   E=pragma(rule([],['$show',G],true,writeln(G)),ids([],[0,1]),[passive(1)],no,H),
   generate_show_rules(B,F,A).
static_suspension_term(B/C,A) :-
   suspension_term_base(B/C,D),
   E is D+C,
   functor(A,suspension,E).
has_suspension_field(A,B) :-
   suspension_term_base_fields(A,C),
   memberchk(B,C).
suspension_term_base(A,B) :-
   suspension_term_base_fields(A,C),
   length(C,B).
suspension_term_base_fields(A,B) :-
   ( chr_pp_flag(debugable,on) ->
     B=[id,state,history,generation,continuation,functor]
   ;
     ( uses_history(A) ->
       B=[id,state,history|C]
     ;
       ( only_ground_indexed_arguments(A),
         get_functional_dependency(A,1,_,_) ->
         B=[state|C]
       )
     ;
       B=[id,state|C]
     ),
     ( only_ground_indexed_arguments(A) ->
       get_store_type(A,D),
       basic_store_types(D,E),
       ( memberchk(global_ground,E) ->
         C=[global_list_prev|F]
       ;
         C=F
       ),
       ( chr_pp_flag(ht_removal,on) ->
         ht_prev_fields(E,F)
       ;
         F=[]
       )
     ;
       ( may_trigger(A) ->
         ( uses_field(A,generation) ->
           C=[generation,global_list_prev|F]
         ;
           C=[global_list_prev|F]
         ),
         ( chr_pp_flag(mixed_stores,on),
           chr_pp_flag(ht_removal,on) ->
           get_store_type(A,D),
           basic_store_types(D,E),
           ht_prev_fields(E,F)
         ;
           F=[]
         )
       )
     ;
       C=[global_list_prev|F],
       ( chr_pp_flag(mixed_stores,on),
         chr_pp_flag(ht_removal,on) ->
         get_store_type(A,D),
         basic_store_types(D,E),
         ht_prev_fields(E,F)
       ;
         F=[]
       )
     )
   ).
ht_prev_fields(A,B) :-
   ht_prev_fields_int(A,C),
   append(C,B).
ht_prev_fields_int([],[]).
ht_prev_fields_int([B|C],A) :-
   ( B=multi_hash(D) ->
     maplist(ht_prev_field,D,E),
     A=[E|F]
   ;
     A=F
   ),
   ht_prev_fields_int(C,F).
ht_prev_field(A,B) :-
   concat_atom(['multi_hash_prev-'|A],B).
get_static_suspension_term_field(A,B,C,D) :-
   suspension_term_base_fields(B,E),
   nth1(F,E,A),
   !,
   arg(F,C,D).
get_static_suspension_term_field(arguments,A,B,C) :-
   !,
   suspension_term_base(A,D),
   B=..[_|E],
   drop(D,E,C).
get_static_suspension_term_field(A,B,_,_) :-
   chr_error(internal,'Trying to obtain field ~w of ~w, wich does not have it!',[A,B]).
get_dynamic_suspension_term_field(A,B,C,D,E) :-
   suspension_term_base_fields(B,F),
   nth1(G,F,A),
   !,
   E=arg(G,C,D).
get_dynamic_suspension_term_field(arguments,A,B,C,D) :-
   !,
   static_suspension_term(A,E),
   get_static_suspension_term_field(arguments,A,E,C),
   D= (B=E).
get_dynamic_suspension_term_field(argument(E),A,B,C,D) :-
   !,
   suspension_term_base(A,F),
   G is E+F,
   D=arg(G,B,C).
get_dynamic_suspension_term_field(A,B,_,_,_) :-
   chr_error(internal,'Dynamic goal to get ~w of ~w, which does not have this field!',[A,B]).
set_dynamic_suspension_term_field(A,B,C,D,E) :-
   suspension_term_base_fields(B,F),
   nth1(G,F,A),
   !,
   E=setarg(G,C,D).
set_dynamic_suspension_term_field(A,B,_,_,_) :-
   chr_error(internal,'Dynamic goal to set ~w of ~w, which does not have this field!',[A,B]).
basic_store_types(multi_store(A),A) :-
   !.
basic_store_types(A,[A]).
generate_never_stored_rules(A,B) :-
   ( chr_pp_flag(declare_stored_constraints,on) ->
     never_stored_rules(A,B)
   ;
     B=[]
   ).
check_storedness_assertions(A) :-
   ( chr_pp_flag(storage_analysis,on),
     chr_pp_flag(declare_stored_constraints,on) ->
     forall(B,A,check_storedness_assertion(B))
   ;
     true
   ).
continuation_analysis(A) :-
   maplist(analyse_continuations,A).
analyse_continuations(A) :-
   continuation_analysis(A,1),
   get_max_occurrence(A,B),
   C is B+1,
   bulk_propagation(A,1,C),
   set_occurrence_code_id(A,1,0).
continuation_analysis(A,B) :-
   get_max_occurrence(A,C),
   ( B>C ->
     true
   ;
     ( B==C ->
       D is B+1,
       continuation_occurrence(A,B,D)
     )
   ;
     constraint_continuation(A,B,C,D),
     continuation_occurrence(A,B,D),
     E is B+1,
     continuation_analysis(A,E)
   ).
constraint_continuation(A,B,C,D) :-
   ( get_occurrence_head(A,B,E) ->
     F is B+1,
     ( between(F,C,D),
       get_occurrence_head(A,D,G),
       unifiable(E,G,_) ->
       true
     ;
       D is C+1
     )
   ;
     D=C
   ).
get_occurrence_head(A,B,C) :-
   get_occurrence(A,B,D,E),
   \+is_passive(D,E),
   get_rule(D,F),
   F=pragma(rule(G,H,_,_),ids(I,J),_,_,_),
   ( select2(E,C,I,G,_,_) ->
     true
   ;
     select2(E,C,J,H,_,_)
   ).
get_success_continuation_code_id(A,B,C) :-
   get_success_continuation_occurrence(A,B,D),
   get_occurrence_code_id(A,D,C).
collect_constants(_,A,B,C) :-
   ( not_restarted,
     chr_pp_flag(experiment,on) ->
     ( chr_pp_flag(sss,on) ->
       D=[fep/4-[2,3]-[[a,b]-fep1,[c,d]-fep2]-no],
       copy_term_nat(C,E),
       flatten_clauses(E,D,F),
       install_new_declarations_and_restart(F)
     ;
       maplist(collect_rule_constants(B),A),
       ( chr_pp_flag(verbose,on) ->
         print_chr_constants
       ;
         true
       ),
       ( chr_pp_flag(experiment,on) ->
         flattening_dictionary(B,D),
         copy_term_nat(C,E),
         flatten_clauses(E,D,F),
         install_new_declarations_and_restart(F)
       ;
         true
       )
     )
   ;
     true
   ).
collect_rule_constants(A,B) :-
   B=ast_rule(C,_,_,D,_),
   collect_head_constants(C),
   collect_body_constants(D,A).
collect_head_constants(simplification(A)) :-
   maplist(collect_constraint_constants,A).
collect_head_constants(propagation(A)) :-
   maplist(collect_constraint_constants,A).
collect_head_constants(simpagation(A,B)) :-
   maplist(collect_constraint_constants,A),
   maplist(collect_constraint_constants,B).
collect_body_constants(A,B) :-
   maplist(collect_goal_constants(B),A).
collect_goal_constants(A,B) :-
   ( ast_nonvar(B) ->
     ast_symbol(B,C),
     ( memberchk(C,A) ->
       ast_term_to_term(B,D),
       ast_args(B,E),
       collect_constraint_constants(chr_constraint(C,E,D))
     ;
       ( C== (:)/2,
         ast_args(B,[F,G]),
         F=atomic(H),
         get_target_module(I),
         H==I,
         ast_nonvar(G),
         ast_symbol(G,J),
         memberchk(J,A) ->
         ast_term_to_term(G,K),
         ast_args(G,L),
         collect_constraint_constants(chr_constraint(J,L,K))
       )
     ;
       true
     )
   ;
     true
   ).
collect_constraint_constants(A) :-
   A=chr_constraint(B,C,_),
   get_constraint_type_det(B,D),
   collect_all_arg_constants(C,D,[]).
collect_all_arg_constants([],[],A) :-
   ( A\==[] ->
     add_chr_constants(A)
   ;
     true
   ).
collect_all_arg_constants([B|C],[D|E],A) :-
   unalias_type(D,F),
   ( is_chr_constants_type(F,G,_) ->
     ( ast_ground(B) ->
       ast_term_to_term(B,H),
       collect_all_arg_constants(C,E,[G-H|A])
     ;
       true
     )
   ;
     collect_all_arg_constants(C,E,A)
   ).
add_chr_constants(A) :-
   keysort(A,B),
   add_chr_constants_(B).
flattening_dictionary([],[]).
flattening_dictionary([B|C],A) :-
   ( flattening_dictionary_entry(B,D) ->
     A=[D|E]
   ;
     A=E
   ),
   flattening_dictionary(C,E).
flattening_dictionary_entry(A,B) :-
   get_constraint_type_det(A,C),
   constant_positions(C,1,D,E,F,G),
   ( D\==[] ->
     pairup(E,H,I),
     keysort(I,J),
     B=A-D-K-F,
     get_chr_constants(L),
     findall(M,(member(J,L),flat_spec(A,D,H,M)),K)
   ;
     ( G==yes ->
       enum_positions(C,1,N,O,P),
       B=A-N-K-P,
       findall(M,(cartesian_product(Q,O),flat_spec(A,N,Q,M)),K)
     )
   ).
constant_positions([],_,[],[],no,no).
constant_positions([F|G],A,B,C,D,E) :-
   unalias_type(F,H),
   ( is_chr_constants_type(H,I,J) ->
     compose_error_handlers(J,K,D),
     B=[A|L],
     C=[I|M],
     E=N
   ;
     ( is_chr_enum_type(H,_,_) ->
       E=yes
     ;
       E=N
     ),
     L=B,
     M=C,
     K=D
   ),
   O is A+1,
   constant_positions(G,O,L,M,K,N).
compose_error_handlers(no,A,A).
compose_error_handlers(yes(A),_,yes(A)).
enum_positions([],_,[],[],no).
enum_positions([E|F],A,B,C,D) :-
   unalias_type(E,G),
   ( is_chr_enum_type(G,H,I) ->
     compose_error_handlers(I,J,D),
     B=[A|K],
     C=[H|L]
   ;
     B=K,
     C=L,
     D=J
   ),
   M is A+1,
   enum_positions(F,M,K,L,J).
cartesian_product([],[]).
cartesian_product([A|B],[C|D]) :-
   member(A,C),
   cartesian_product(B,D).
flat_spec(D/E,A,B,C) :-
   C=B-F,
   term_to_atom(B,G),
   term_to_atom(A,H),
   atom_concat_list(['$flat_',D,/,E,'___',H,'___',G],F).
restart_after_flattening(A,A) :-
   nb_setval('$chr_restart_after_flattening',started).
restart_after_flattening(_,A) :-
   nb_getval('$chr_restart_after_flattening',restart(A)),
   nb_setval('$chr_restart_after_flattening',restarted).
not_restarted :-
   nb_getval('$chr_restart_after_flattening',started).
install_new_declarations_and_restart(A) :-
   nb_setval('$chr_restart_after_flattening',restart(A)),
   fail.
flatten_clauses(A,B,C) :-
   flatten_readcontent(A,D,E,F,_,G,H),
   flatten_clauses_(B,D,H,E,F,G,C).
flatten_clauses_(A,B,C,D,E,F,G) :-
   auxiliary_constraints_declarations(A,E,F,H),
   dispatching_rules(A,I),
   declarations(D,A,E,F,J),
   flatten_rules(B,A,K),
   append([C,H,I,J,K],G).
declarations(A,B,C,D,E) :-
   findall(F,(member(F,A),\+memberchk(F-_-_-_,B)),G),
   maplist(declaration(C,D),G,H),
   flatten(H,E).
declaration(A,B,C,[(:-chr_constraint C),(:-chr_option(mode,D)),(:-chr_option(type_declaration,E))]) :-
   C=F/G,
   functor(D,F,G),
   ( memberchk(D,A) ->
     true
   ;
     replicate(G,?,H),
     D=..[_|H]
   ),
   functor(E,F,G),
   ( memberchk(E,B) ->
     true
   ;
     replicate(G,any,I),
     E=..[_|I]
   ).
flatten_readcontent([],[],[],[],[],[],[]).
flatten_readcontent([G|H],A,B,C,D,E,F) :-
   ( G==end_of_file ->
     A=[],
     B=[],
     C=[],
     E=[],
     D=[],
     F=[]
   ;
     ( crude_is_rule(G) ->
       A=[G|I],
       flatten_readcontent(H,I,B,C,D,E,F)
     )
   ;
     ( pure_is_declaration(G,J,K,L) ->
       append(J,M,B),
       append(K,N,C),
       append(L,O,E),
       flatten_readcontent(H,A,M,N,D,O,F)
     )
   ;
     ( is_mode_declaration(G,P) ->
       C=[P|N],
       flatten_readcontent(H,A,B,N,D,E,F)
     )
   ;
     ( is_type_declaration(G,Q) ->
       E=[Q|O],
       flatten_readcontent(H,A,B,C,D,O,F)
     )
   ;
     ( is_type_definition(G,R) ->
       F=[G|S],
       D=[R|T],
       flatten_readcontent(H,A,B,C,T,E,S)
     )
   ;
     ( G= (:-op(U,V,W)) ->
       op(U,V,W)
     ;
       true
     ),
     F=[G|S],
     flatten_readcontent(H,A,B,C,D,E,S)
   ).
crude_is_rule(@(_,_)).
crude_is_rule(pragma(_,_)).
crude_is_rule(==>(_,_)).
crude_is_rule(<=>(_,_)).
pure_is_declaration(A,B,C,D) :-
   A= (:-E),
   E=..[F,G],
   F== (chr_constraint),
   conj2list(G,H),
   pure_extract_type_mode(H,B,C,D).
pure_extract_type_mode([],[],[],[]).
pure_extract_type_mode([D/E|C],[D/E|F],A,B) :-
   !,
   pure_extract_type_mode(C,F,A,B).
pure_extract_type_mode([B|C],[D|E],[F|G],A) :-
   functor(B,H,I),
   D=H/I,
   B=..[_|J],
   extract_types_and_modes(J,K,L),
   F=..[H|L],
   ( forall(member(M,K),M==any) ->
     A=N
   ;
     A=[O|N],
     O=..[H|K]
   ),
   pure_extract_type_mode(C,E,G,N).
is_mode_declaration((:-chr_option(mode,A)),A).
is_type_declaration((:-chr_option(type_declaration,A)),A).
auxiliary_constraints_declarations(A,B,C,D) :-
   findall(E,auxiliary_constraints_declaration(A,B,C,E),F),
   flatten(F,D).
auxiliary_constraints_declaration(A,B,C,[(:-chr_constraint D),(:-chr_option(mode,E)),(:-chr_option(type_declaration,F))]) :-
   member(I/J-H-G-_,A),
   arg_modes(I,J,B,K),
   specialize_modes(K,H,L),
   arg_types(I,J,C,M),
   specialize_types(M,H,N),
   length(H,O),
   P is J-O,
   member(_-Q,G),
   D=Q/P,
   E=..[Q|L],
   F=..[Q|N].
arg_modes(A,B,C,D) :-
   functor(E,A,B),
   ( memberchk(E,C) ->
     E=..[_|D]
   ;
     replicate(B,?,D)
   ).
specialize_modes(A,B,C) :-
   split_args(B,A,_,C).
arg_types(A,B,C,D) :-
   functor(E,A,B),
   ( memberchk(E,C) ->
     E=..[_|D]
   ;
     replicate(B,any,D)
   ).
specialize_types(A,B,C) :-
   split_args(B,A,_,C).
dispatching_rules([],[]).
dispatching_rules([E-F-D-C|B],A) :-
   constraint_dispatching_rule(D,E,F,C,A,G),
   dispatching_rules(B,G).
constraint_dispatching_rule(A,F/G,B,C,D,E) :-
   ( increasing_numbers(B,1) ->
     H=D,
     I=F/G
   ;
     functor(J,F,G),
     J=..[_|K],
     split_args(B,K,L,M),
     append(L,M,N),
     atom_concat(F,'_$shuffled',O),
     P=..[O|N],
     [(J:-P)|H]=D,
     I=O/G
   ),
   Q=swap(F,B),
   dispatching_rule_term_cases(A,B,I,C,Q,H,E).
increasing_numbers([],_).
increasing_numbers([A|B],A) :-
   C is A+1,
   increasing_numbers(B,C).
dispatching_rule_term_cases(A,B,G/H,C,D,E,F) :-
   length(B,I),
   once(pairup(J,K,A)),
   maplist(head_tail,J,L,M),
   N is H-I,
   maplist(wrap_in_functor(dispatching_action),K,O),
   dispatch_trie_index(L,M,N,C,D,O,G,E,F).
dispatching_action(A,B,C) :-
   C=..[A|B].
dispatch_trie_index(A,B,C,D,E,F,G,H,I) :-
   dispatch_trie_step(A,G,G,B,C,D,E,F,H,I).
dispatch_trie_step([],_,_,_,[],_,_,[],A,A) :-
   !.
dispatch_trie_step(A,B,C,D,E,F,G,H,I,J) :-
   D=[K|_],
   length(K,L),
   aggregate_all(set(N/O),(member(P,A),functor(P,N,O)),M),
   Q is L+1,
   dispatch_trie_step_cases(M,Q,A,D,E,F,G,H,B,C,I,J).
dispatch_trie_step_cases([],A,_,_,B,C,D,_,E,_,F,G) :-
   ( C=yes(H) ->
     F=[I|G],
     I= (J:-K),
     L is A+B,
     functor(J,E,L),
     reconstruct_original_term(D,J,M),
     K=..[H,M]
   ;
     F=G
   ).
dispatch_trie_step_cases([L|M],A,B,C,D,E,F,G,H,I,J,K) :-
   dispatch_trie_step_case(L,A,B,C,D,E,F,G,H,I,J,N),
   dispatch_trie_step_cases(M,A,B,C,D,E,F,G,H,I,N,K).
dispatch_trie_step_case(K/L,A,B,C,D,E,F,G,H,I,[M|N],J) :-
   M= (O:-P,Q),
   ( E=yes(_) ->
     P=!
   ;
     P=true
   ),
   R is A+D,
   functor(O,H,R),
   arg(1,O,S),
   O=..[_,_|T],
   length(U,D),
   once(append(V,U,T)),
   functor(S,K,L),
   W=index_functor(K,L,F),
   S=..[_|X],
   append(X,T,Y),
   ( Y==U ->
     N=J,
     rec_cases(B,_,G,K/L,_,_,Z),
     Z=[A1],
     call(A1,U,Q)
   ;
     rec_cases(B,C,G,K/L,B1,C1,Z),
     ( Z=[D1] ->
       C1=[E1],
       append([B1,E1,U],Y),
       N=J,
       call(D1,U,Q)
     ;
       pairup(B1,C1,F1),
       common_pattern(F1,G1,H1,I1),
       append(X,V,[J1|K1]),
       J1-K1=G1,
       L1=gct([J1|K1],W),
       fresh_symbol(I,M1),
       append(H1,U,N1),
       Q=..[M1|N1],
       findall(P1-Q1,member([P1|Q1],I1),O1),
       once(pairup(R1,S1,O1)),
       dispatch_trie_step(R1,M1,I,S1,D,E,L1,Z,N,J)
     )
   ).
split([E|F],A,B,C,D) :-
   ( A==1 ->
     B=[],
     C=E,
     D=F
   ;
     G is A-1,
     B=[E|H],
     split(F,G,H,C,D)
   ).
reconstruct_original_term(swap(C,D),A,B) :-
   functor(A,_,E),
   functor(B,C,E),
   B=..[_|F],
   split_args(D,F,G,H),
   A=..[_|I],
   append(G,H,I).
reconstruct_original_term(index_functor(C,D,E),A,B) :-
   A=..[F|G],
   split_at(D,G,H,I),
   J=..[C|H],
   K=..[F,J|I],
   reconstruct_original_term(E,K,B).
reconstruct_original_term(gct(C,D),A,B) :-
   copy_term_nat(C,E),
   term_variables(E,F),
   A=..[G|H],
   append(F,I,H),
   append(E,I,J),
   K=..[G|J],
   reconstruct_original_term(D,K,B).
flatten_rules(A,B,C) :-
   flatten_rules1(A,B,D),
   flatten(D,C).
flatten_rules1([],_,[]).
flatten_rules1([B|C],A,[D|E]) :-
   findall(F,flatten_rule(B,A,F),D),
   flatten_rules1(C,A,E).
flatten_rule(@(B,C),A,@(B,D)) :-
   !,
   flatten_rule(C,A,D).
flatten_rule(pragma(B,C),A,pragma(D,C)) :-
   !,
   flatten_rule(B,A,D).
flatten_rule(==>(B,C),A,==>(D,E)) :-
   !,
   flatten_heads(B,A,D),
   flatten_body(C,A,E).
flatten_rule(<=>(\(C,D),B),A,<=>(\(F,G),E)) :-
   !,
   flatten_heads((C,D),A,(F,G)),
   flatten_body(B,A,E).
flatten_rule(<=>(B,C),A,<=>(D,E)) :-
   flatten_heads(B,A,D),
   flatten_body(C,A,E).
flatten_heads((B,C),A,(D,E)) :-
   !,
   flatten_heads(B,A,D),
   flatten_heads(C,A,E).
flatten_heads(B#C,A,D#C) :-
   !,
   flatten_heads(B,A,D).
flatten_heads(A,B,C) :-
   ( functor(A,D,E),
     memberchk(D/E-G-F-_,B) ->
     A=..[_|H],
     split_args(G,H,I,J),
     member(I-K,F),
     C=..[K|J]
   ;
     C=A
   ).
flatten_body((B|C),A,(D|E)) :-
   !,
   conj2list(B,F),
   maplist(flatten_goal(A),F,G),
   list2conj(G,D),
   conj2list(C,H),
   maplist(flatten_goal(A),H,I),
   list2conj(I,E).
flatten_body(A,B,C) :-
   conj2list(A,D),
   maplist(flatten_goal(B),D,E),
   list2conj(E,C).
flatten_goal(_,A,B) :-
   var(A),
   !,
   B=A.
flatten_goal(A,B,C) :-
   ( is_specializable_goal(B,A,D) ->
     specialize_goal(B,D,C)
   ;
     ( B=E:F,
       get_target_module(G),
       E==G,
       nonvar(F),
       is_specializable_goal(F,A,D) ->
       specialize_goal(F,D,H),
       C=E:H
     )
   ;
     ( partial_eval(B,C) ->
       true
     )
   ;
     C=B
   ).
is_specializable_goal(A,B,C) :-
   functor(A,D,E),
   memberchk(D/E-C-_-_,B),
   args(C,A,F),
   ground(F).
specialize_goal(A,B,C) :-
   functor(A,D,E),
   A=..[_|F],
   split_args(B,F,G,H),
   flat_spec(D/E,B,G,_-I),
   C=..[I|H].
partial_eval(append(B,C,D),A) :-
   ( B==[] ->
     A= (D=C)
   ;
     ( C==[] ->
       A= (D=B)
     )
   ).
partial_eval(flatten_path(B,C),A) :-
   ( nonvar(B),
     flatten(B,D),
     D\==B ->
     A=flatten_path(D,C)
   ).
dump_code(A) :-
   ( chr_pp_flag(dump,on) ->
     maplist(portray_clause,A)
   ;
     true
   ).
chr_banner :-
   chr_info(banner,'\tThe K.U.Leuven CHR System\n\t\tMain Developer:\tTom Schrijvers\n\t\tContributors:\tJon Sneyers, Bart Demoen, Jan Wielemaker\n\t\tCopyright:\tK.U.Leuven, Belgium\n\t\tURL:\t\thttp://www.cs.kuleuven.be/~~toms/CHR/\n',[]).
chr_none_locked(A,B) :-
   chr_pp_flag(guard_locks,C),
   ( C==off ->
     B=true
   ;
     ( C==on ->
       B='chr none_locked'(A)
     )
   ;
     ( C==error ->
       B='chr none_error_locked'(A)
     )
   ).
chr_not_locked(A,B) :-
   chr_pp_flag(guard_locks,C),
   ( C==off ->
     B=true
   ;
     ( C==on ->
       B='chr not_locked'(A)
     )
   ;
     ( C==error ->
       B='chr not_error_locked'(A)
     )
   ).
chr_lock(A,B) :-
   chr_pp_flag(guard_locks,C),
   ( C==off ->
     B=true
   ;
     ( C==on ->
       B='chr lock'(A)
     )
   ;
     ( C==error ->
       B='chr error_lock'(A)
     )
   ).
chr_unlock(A,B) :-
   chr_pp_flag(guard_locks,C),
   ( C==off ->
     B=true
   ;
     ( C==on ->
       B='chr unlock'(A)
     )
   ;
     ( C==error ->
       B='chr unerror_lock'(A)
     )
   ).
term_to_ast_term(A,B,C,D) :-
   ( atomic(A) ->
     B=atomic(A),
     D=C
   ;
     ( compound(A) ->
       functor(A,E,F),
       B=compound(E,F,G,A),
       A=..[_|H],
       maplist_dcg(chr_translate:term_to_ast_term,H,G,C,D)
     )
   ;
     ( var(A) ->
       var_to_ast_term(A,C,B,D)
     )
   ).
var_to_ast_term(A,B,C,D) :-
   B=E-F,
   ( lookup_eq(E,A,C) ->
     D=B
   ;
     C=var(F,A),
     G is F+1,
     H=[A-C|E],
     D=H-G
   ).
chr_constraint_to_ast_constraint(A,B,C,D) :-
   B=chr_constraint(F/G,E,A),
   functor(A,F,G),
   A=..[_|H],
   maplist_dcg(chr_translate:term_to_ast_term,H,E,C,D).
rule_to_ast_rule(A,B) :-
   B=ast_rule(C,D,E,F,G),
   A=rule(H,I,E,G),
   J=[]-1,
   ( H==[] ->
     C=propagation(K),
     maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,I,K,J,L)
   ;
     ( I==[] ->
       C=simplification(K),
       maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,H,K,J,L)
     )
   ;
     C=simpagation(M,N),
     maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,H,M,J,O),
     maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,I,N,O,L)
   ),
   conj2list(E,P),
   maplist_dcg(chr_translate:term_to_ast_term,P,D,L,Q),
   conj2list(G,R),
   maplist_dcg(chr_translate:term_to_ast_term,R,F,Q,_).
pragma_rule_to_ast_rule(pragma(B,_,_,_,_),A) :-
   rule_to_ast_rule(B,A).
check_rule_to_ast_rule(A) :-
   ( rule_to_ast_rule(A,B) ->
     writeln(B)
   ;
     writeln(failed(rule_to_ast_rule(A,B)))
   ).
ast_term_to_term(var(_,A),A).
ast_term_to_term(atomic(A),A).
ast_term_to_term(compound(_,_,_,A),A).
ast_nonvar(atomic(_)).
ast_nonvar(compound(_,_,_,_)).
ast_ground(atomic(_)).
ast_ground(compound(_,_,A,_)) :-
   maplist(ast_ground,A).
ast_is_ground(A,B) :-
   ast_is_ground_(B,A).
ast_is_ground_(var(B,_),A) :-
   tree_set_memberchk(B,A).
ast_is_ground_(atomic(_),_).
ast_is_ground_(compound(_,_,B,_),A) :-
   maplist(ast_is_ground(A),B).
ast_functor(atomic(A),A,0).
ast_functor(compound(A,B,_,_),A,B).
ast_symbol(atomic(A),A/0).
ast_symbol(compound(A,B,_,_),A/B).
ast_args(atomic(_),[]).
ast_args(compound(_,_,A,_),A).
ast_term_variables(atomic(_),A,A).
ast_term_variables(compound(_,_,C,_),A,B) :-
   ast_term_list_variables(C,A,B).
ast_term_variables(var(C,_),A,B) :-
   tree_set_add(A,C,B).
ast_term_list_variables(A,B,C) :-
   fold(A,chr_translate:ast_term_variables,B,C).
ast_constraint_variables(chr_constraint(_,C,_),A,B) :-
   ast_term_list_variables(C,A,B).
ast_constraint_list_variables(A,B,C) :-
   fold(A,chr_translate:ast_constraint_variables,B,C).
ast_head_variables(simplification(C),A,B) :-
   ast_constraint_list_variables(C,A,B).
ast_head_variables(propagation(C),A,B) :-
   ast_constraint_list_variables(C,A,B).
ast_head_variables(simpagation(C,D),A,B) :-
   ast_constraint_list_variables(C,A,E),
   ast_constraint_list_variables(D,E,B).
ast_var_memberchk(var(B,_),A) :-
   tree_set_memberchk(B,A).
ast_instantiate(A,B,C) :-
   ast_instantiate_(B,A,C).
ast_instantiate_(var(C,_),A,B) :-
   get_assoc(C,A,B).
ast_instantiate_(atomic(A),_,A).
ast_instantiate_(compound(C,D,E,_),A,B) :-
   functor(B,C,D),
   B=..[_|F],
   maplist(ast_instantiate(A),E,F).
ast_head_arg_matches_([],[],A,B,[],A,B).
ast_head_arg_matches_([silent(G-_)|F],[H|I],A,B,C,D,E) :-
   !,
   ( H== (+) ->
     ast_term_variables(G,J,B),
     ast_head_arg_matches_(F,I,A,J,C,D,E)
   ;
     ast_head_arg_matches_(F,I,A,B,C,D,E)
   ).
ast_head_arg_matches_([G-H|F],[I|J],A,B,C,D,E) :-
   ( G=var(K,_) ->
     ( get_assoc(K,A,L) ->
       ( I= (+) ->
         ( tree_set_memberchk(K,B) ->
           C=[H=L|M],
           N=B
         ;
           C=[H==L|M],
           tree_set_add(B,K,N)
         )
       ;
         C=[H==L|M],
         N=B
       ),
       O=A
     ;
       put_assoc(K,A,H,O),
       C=M,
       ( I= (+) ->
         tree_set_add(B,K,N)
       ;
         N=B
       )
     ),
     P=F,
     Q=J
   ;
     ( ground(G),
       G='$chr_identifier_match'(R,S) ->
       identifier_label_atom(S,H,R,T),
       C=[T|M],
       A=O,
       N=B,
       P=F,
       Q=J
     )
   ;
     ( G=atomic(U) ->
       ( I= (+) ->
         C=[H=U|M]
       ;
         C=[H==U|M]
       ),
       A=O,
       N=B,
       P=F,
       Q=J
     )
   ;
     ( I== (+),
       ast_is_ground(B,G) ->
       ast_instantiate(A,G,V),
       C=[H=V|M],
       A=O,
       N=B,
       P=F,
       Q=J
     )
   ;
     ( I== (?),
       ast_is_ground(B,G) ->
       ast_instantiate(A,G,V),
       C=[H==V|M],
       A=O,
       N=B,
       P=F,
       Q=J
     )
   ;
     G=compound(W,X,Y,_),
     functor(Z,W,X),
     Z=..[_|A1],
     ( I= (+) ->
       C=[H=Z|M]
     ;
       C=[nonvar(H),H=Z|M]
     ),
     pairup(Y,A1,B1),
     append(B1,F,P),
     replicate(_,I,C1),
     append(C1,J,Q),
     O=A,
     N=B
   ),
   ast_head_arg_matches_(P,Q,O,N,M,D,E).
:-use_module(chr(chr_runtime)).
:-use_module(chr(chr_hashtable_store)).
attach_generate_empty_named_history_initialisation___1([],_).
attach_generate_empty_named_history_initialisation___1([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\1=:=1 ->
       P=v(E,[A|F],G,H,I,J,K,L,M,N,O)
     ;
       Q is E\/1,
       P=v(Q,[A],G,H,I,J,K,L,M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(1,[A],[],[],[],[],[],[],[],[],[]))
   ),
   attach_generate_empty_named_history_initialisation___1(C,A).
detach_generate_empty_named_history_initialisation___1([],_).
detach_generate_empty_named_history_initialisation___1([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\1=:=1 ->
       'chr sbag_del_element'(F,A,P),
       ( P==[] ->
         Q is E/\ -2,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,[],G,H,I,J,K,L,M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,P,G,H,I,J,K,L,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_generate_empty_named_history_initialisation___1(C,A).
attach_symbol_count___2([],_).
attach_symbol_count___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\2=:=2 ->
       P=v(E,F,[A|G],H,I,J,K,L,M,N,O)
     ;
       Q is E\/2,
       P=v(Q,F,[A],H,I,J,K,L,M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(2,[],[A],[],[],[],[],[],[],[],[]))
   ),
   attach_symbol_count___2(C,A).
detach_symbol_count___2([],_).
detach_symbol_count___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\2=:=2 ->
       'chr sbag_del_element'(G,A,P),
       ( P==[] ->
         Q is E/\ -3,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,[],H,I,J,K,L,M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,P,H,I,J,K,L,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_symbol_count___2(C,A).
attach_fresh_symbol___2([],_).
attach_fresh_symbol___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\4=:=4 ->
       P=v(E,F,G,[A|H],I,J,K,L,M,N,O)
     ;
       Q is E\/4,
       P=v(Q,F,G,[A],I,J,K,L,M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(4,[],[],[A],[],[],[],[],[],[],[]))
   ),
   attach_fresh_symbol___2(C,A).
detach_fresh_symbol___2([],_).
detach_fresh_symbol___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\4=:=4 ->
       'chr sbag_del_element'(H,A,P),
       ( P==[] ->
         Q is E/\ -5,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,[],I,J,K,L,M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,P,I,J,K,L,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_fresh_symbol___2(C,A).
attach_background_info___2([],_).
attach_background_info___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\8=:=8 ->
       P=v(E,F,G,H,[A|I],J,K,L,M,N,O)
     ;
       Q is E\/8,
       P=v(Q,F,G,H,[A],J,K,L,M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(8,[],[],[],[A],[],[],[],[],[],[]))
   ),
   attach_background_info___2(C,A).
detach_background_info___2([],_).
detach_background_info___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\8=:=8 ->
       'chr sbag_del_element'(I,A,P),
       ( P==[] ->
         Q is E/\ -9,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,[],J,K,L,M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,P,J,K,L,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_background_info___2(C,A).
attach_get_bg_info___2([],_).
attach_get_bg_info___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\16=:=16 ->
       P=v(E,F,G,H,I,[A|J],K,L,M,N,O)
     ;
       Q is E\/16,
       P=v(Q,F,G,H,I,[A],K,L,M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(16,[],[],[],[],[A],[],[],[],[],[]))
   ),
   attach_get_bg_info___2(C,A).
detach_get_bg_info___2([],_).
detach_get_bg_info___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\16=:=16 ->
       'chr sbag_del_element'(J,A,P),
       ( P==[] ->
         Q is E/\ -17,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,I,[],K,L,M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,I,P,K,L,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_get_bg_info___2(C,A).
attach_type_definition___2([],_).
attach_type_definition___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\32=:=32 ->
       P=v(E,F,G,H,I,J,[A|K],L,M,N,O)
     ;
       Q is E\/32,
       P=v(Q,F,G,H,I,J,[A],L,M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(32,[],[],[],[],[],[A],[],[],[],[]))
   ),
   attach_type_definition___2(C,A).
detach_type_definition___2([],_).
detach_type_definition___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\32=:=32 ->
       'chr sbag_del_element'(K,A,P),
       ( P==[] ->
         Q is E/\ -33,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,I,J,[],L,M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,I,J,P,L,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_type_definition___2(C,A).
attach_type_alias___2([],_).
attach_type_alias___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\64=:=64 ->
       P=v(E,F,G,H,I,J,K,[A|L],M,N,O)
     ;
       Q is E\/64,
       P=v(Q,F,G,H,I,J,K,[A],M,N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(64,[],[],[],[],[],[],[A],[],[],[]))
   ),
   attach_type_alias___2(C,A).
detach_type_alias___2([],_).
detach_type_alias___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\64=:=64 ->
       'chr sbag_del_element'(L,A,P),
       ( P==[] ->
         Q is E/\ -65,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,I,J,K,[],M,N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,I,J,K,P,M,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_type_alias___2(C,A).
attach_unalias_type___2([],_).
attach_unalias_type___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\128=:=128 ->
       P=v(E,F,G,H,I,J,K,L,[A|M],N,O)
     ;
       Q is E\/128,
       P=v(Q,F,G,H,I,J,K,L,[A],N,O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(128,[],[],[],[],[],[],[],[A],[],[]))
   ),
   attach_unalias_type___2(C,A).
detach_unalias_type___2([],_).
detach_unalias_type___2([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\128=:=128 ->
       'chr sbag_del_element'(M,A,P),
       ( P==[] ->
         Q is E/\ -129,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,I,J,K,L,[],N,O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,I,J,K,L,P,N,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_unalias_type___2(C,A).
attach_ast_static_type_check_var___4([],_).
attach_ast_static_type_check_var___4([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\256=:=256 ->
       P=v(E,F,G,H,I,J,K,L,M,[A|N],O)
     ;
       Q is E\/256,
       P=v(Q,F,G,H,I,J,K,L,M,[A],O)
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(256,[],[],[],[],[],[],[],[],[A],[]))
   ),
   attach_ast_static_type_check_var___4(C,A).
detach_ast_static_type_check_var___4([],_).
detach_ast_static_type_check_var___4([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\256=:=256 ->
       'chr sbag_del_element'(N,A,P),
       ( P==[] ->
         Q is E/\ -257,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,I,J,K,L,M,[],O))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,I,J,K,L,M,P,O))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_ast_static_type_check_var___4(C,A).
attach_atomic_type___1([],_).
attach_atomic_type___1([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\512=:=512 ->
       P=v(E,F,G,H,I,J,K,L,M,N,[A|O])
     ;
       Q is E\/512,
       P=v(Q,F,G,H,I,J,K,L,M,N,[A])
     ),
     put_attr(B,chr_translate,P)
   ;
     put_attr(B,chr_translate,v(512,[],[],[],[],[],[],[],[],[],[A]))
   ),
   attach_atomic_type___1(C,A).
detach_atomic_type___1([],_).
detach_atomic_type___1([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     D=v(E,F,G,H,I,J,K,L,M,N,O),
     ( E/\512=:=512 ->
       'chr sbag_del_element'(O,A,P),
       ( P==[] ->
         Q is E/\ -513,
         ( Q==0 ->
           del_attr(B,chr_translate)
         ;
           put_attr(B,chr_translate,v(Q,F,G,H,I,J,K,L,M,N,[]))
         )
       ;
         put_attr(B,chr_translate,v(E,F,G,H,I,J,K,L,M,N,P))
       )
     ;
       true
     )
   ;
     true
   ),
   detach_atomic_type___1(C,A).
attach_increment([],_).
attach_increment([B|C],A) :-
   ( get_attr(B,chr_translate,D) ->
     A=v(E,F,G,H,I,J,K,L,M,N,O),
     D=v(P,Q,R,S,T,U,V,W,X,Y,Z),
     sort(Q,A1),
     'chr merge_attributes'(F,A1,B1),
     sort(R,C1),
     'chr merge_attributes'(G,C1,D1),
     sort(S,E1),
     'chr merge_attributes'(H,E1,F1),
     sort(T,G1),
     'chr merge_attributes'(I,G1,H1),
     sort(U,I1),
     'chr merge_attributes'(J,I1,J1),
     sort(V,K1),
     'chr merge_attributes'(K,K1,L1),
     sort(W,M1),
     'chr merge_attributes'(L,M1,N1),
     sort(X,O1),
     'chr merge_attributes'(M,O1,P1),
     sort(Y,Q1),
     'chr merge_attributes'(N,Q1,R1),
     sort(Z,S1),
     'chr merge_attributes'(O,S1,T1),
     U1 is E\/P,
     put_attr(B,chr_translate,v(U1,B1,D1,F1,H1,J1,L1,N1,P1,R1,T1))
   ;
     put_attr(B,chr_translate,A)
   ),
   attach_increment(C,A).
attribute_goals(_,A,A).
attr_unify_hook(v(B,C,D,E,F,G,H,I,J,K,L),A) :-
   sort(C,M),
   sort(D,N),
   sort(E,O),
   sort(F,P),
   sort(G,Q),
   sort(H,R),
   sort(I,S),
   sort(J,T),
   sort(K,U),
   sort(L,V),
   ( var(A) ->
     ( get_attr(A,chr_translate,W) ->
       W=v(X,Y,Z,A1,B1,C1,D1,E1,F1,G1,H1),
       sort(Y,I1),
       'chr merge_attributes'(M,I1,J1),
       sort(Z,K1),
       'chr merge_attributes'(N,K1,L1),
       sort(A1,M1),
       'chr merge_attributes'(O,M1,N1),
       sort(B1,O1),
       'chr merge_attributes'(P,O1,P1),
       sort(C1,Q1),
       'chr merge_attributes'(Q,Q1,R1),
       sort(D1,S1),
       'chr merge_attributes'(R,S1,T1),
       sort(E1,U1),
       'chr merge_attributes'(S,U1,V1),
       sort(F1,W1),
       'chr merge_attributes'(T,W1,X1),
       sort(G1,Y1),
       'chr merge_attributes'(U,Y1,Z1),
       sort(H1,A2),
       'chr merge_attributes'(V,A2,B2),
       C2 is B\/X,
       put_attr(A,chr_translate,v(C2,J1,L1,N1,P1,R1,T1,V1,X1,Z1,B2)),
       '$run_suspensions_generate_empty_named_history_initialisation___1'(M),
       '$run_suspensions_symbol_count___2'(N),
       '$run_suspensions_fresh_symbol___2'(O),
       '$run_suspensions_background_info___2'(P1),
       '$run_suspensions_get_bg_info___2'(R1),
       '$run_suspensions_type_definition___2'(T1),
       '$run_suspensions_type_alias___2'(V1),
       '$run_suspensions_unalias_type___2'(X1),
       '$run_suspensions_ast_static_type_check_var___4'(Z1),
       '$run_suspensions_atomic_type___1'(B2)
     ;
       put_attr(A,chr_translate,v(B,M,N,O,P,Q,R,S,T,U,V)),
       '$run_suspensions_generate_empty_named_history_initialisation___1'(M),
       '$run_suspensions_symbol_count___2'(N),
       '$run_suspensions_fresh_symbol___2'(O),
       '$run_suspensions_background_info___2'(P),
       '$run_suspensions_get_bg_info___2'(Q),
       '$run_suspensions_type_definition___2'(R),
       '$run_suspensions_type_alias___2'(S),
       '$run_suspensions_unalias_type___2'(T),
       '$run_suspensions_ast_static_type_check_var___4'(U),
       '$run_suspensions_atomic_type___1'(V)
     )
   ;
     ( compound(A) ->
       term_variables(A,D2),
       attach_increment(D2,v(B,M,N,O,P,Q,R,S,T,U,V))
     ;
       true
     ),
     '$run_suspensions_generate_empty_named_history_initialisation___1'(M),
     '$run_suspensions_symbol_count___2'(N),
     '$run_suspensions_fresh_symbol___2'(O),
     '$run_suspensions_background_info___2'(P),
     '$run_suspensions_get_bg_info___2'(Q),
     '$run_suspensions_type_definition___2'(R),
     '$run_suspensions_type_alias___2'(S),
     '$run_suspensions_unalias_type___2'(T),
     '$run_suspensions_ast_static_type_check_var___4'(U),
     '$run_suspensions_atomic_type___1'(V)
   ).
'$novel_production'(A,B) :-
   arg(3,A,C),
   ( hprolog:get_ds(B,C,_) ->
     fail
   ;
     true
   ).
'$extend_history'(A,B) :-
   arg(3,A,C),
   hprolog:put_ds(B,C,x,D),
   setarg(3,A,D).
'$run_suspensions_generate_empty_named_history_initialisation___1'([]).
'$run_suspensions_generate_empty_named_history_initialisation___1'([A|B]) :-
   A=suspension(_,C,D,_,E),
   ( C==active ->
     setarg(2,A,triggered),
     F is D+1,
     setarg(3,A,F),
     generate_empty_named_history_initialisation___1__0(E,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_generate_empty_named_history_initialisation___1'(B).
'$run_suspensions_symbol_count___2'([]).
'$run_suspensions_symbol_count___2'([A|B]) :-
   A=suspension(_,C,_,D,E),
   ( C==active ->
     setarg(2,A,triggered),
     symbol_count___2__0(D,E,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_symbol_count___2'(B).
'$run_suspensions_fresh_symbol___2'([]).
'$run_suspensions_fresh_symbol___2'([A|B]) :-
   A=suspension(_,C,_,D,_,E,F),
   ( C==active ->
     setarg(2,A,triggered),
     G is D+1,
     setarg(4,A,G),
     fresh_symbol___2__0(E,F,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_fresh_symbol___2'(B).
'$run_suspensions_background_info___2'([]).
'$run_suspensions_background_info___2'([A|B]) :-
   A=suspension(_,C,_,D,_,E,F),
   setarg(2,A,triggered),
   G is D+1,
   setarg(4,A,G),
   background_info___2__0(E,F,A),
   ( C==triggered ->
     setarg(2,A,active)
   ;
     true
   ),
   '$run_suspensions_background_info___2'(B).
'$run_suspensions_get_bg_info___2'([]).
'$run_suspensions_get_bg_info___2'([A|B]) :-
   A=suspension(_,C,_,D,_,E,F),
   ( C==active ->
     setarg(2,A,triggered),
     G is D+1,
     setarg(4,A,G),
     get_bg_info___2__0(E,F,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_get_bg_info___2'(B).
'$run_suspensions_type_definition___2'([]).
'$run_suspensions_type_definition___2'([A|B]) :-
   A=suspension(_,C,_,D,_,E,F),
   ( C==active ->
     setarg(2,A,triggered),
     G is D+1,
     setarg(4,A,G),
     type_definition___2__0(E,F,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_type_definition___2'(B).
'$run_suspensions_type_alias___2'([]).
'$run_suspensions_type_alias___2'([A|B]) :-
   A=suspension(_,C,_,D,_,E,F),
   ( C==active ->
     setarg(2,A,triggered),
     G is D+1,
     setarg(4,A,G),
     type_alias___2__0(E,F,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_type_alias___2'(B).
'$run_suspensions_unalias_type___2'([]).
'$run_suspensions_unalias_type___2'([A|B]) :-
   A=suspension(_,C,_,D,E),
   ( C==active ->
     setarg(2,A,triggered),
     unalias_type___2__0(D,E,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_unalias_type___2'(B).
'$run_suspensions_ast_static_type_check_var___4'([]).
'$run_suspensions_ast_static_type_check_var___4'([A|B]) :-
   A=suspension(_,C,_,D,E,F,G),
   ( C==active ->
     setarg(2,A,triggered),
     ast_static_type_check_var___4__0(D,E,F,G,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_ast_static_type_check_var___4'(B).
'$run_suspensions_atomic_type___1'([]).
'$run_suspensions_atomic_type___1'([A|B]) :-
   A=suspension(_,C,_,D),
   ( C==active ->
     setarg(2,A,triggered),
     atomic_type___1__0(D,A),
     ( C==triggered ->
       setarg(2,A,active)
     ;
       true
     )
   ;
     true
   ),
   '$run_suspensions_atomic_type___1'(B).
'$enumerate_constraints'(A) :-
   ( nonvar(A) ->
     functor(A,B,_),
     '$enumerate_constraints'(B,A)
   ;
     '$enumerate_constraints'(_,A)
   ).
'$enumerate_constraints'(chr_source_file,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=chr_source_file(D).
'$enumerate_constraints'(target_module,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____target_module___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=target_module(D).
'$enumerate_constraints'(line_number,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=line_number(D,E).
'$enumerate_constraints'(indexed_argument,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=indexed_argument(D,E).
'$enumerate_constraints'(constraint_mode,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D,E),
   A=constraint_mode(D,E).
'$enumerate_constraints'(none_suspended_on_variables,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_),
   A=none_suspended_on_variables.
'$enumerate_constraints'(store_type,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=store_type(D,E).
'$enumerate_constraints'(actual_store_types,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=actual_store_types(D,E).
'$enumerate_constraints'(assumed_store_type,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=assumed_store_type(D,E).
'$enumerate_constraints'(validate_store_type_assumption,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=validate_store_type_assumption(D).
'$enumerate_constraints'(rule_count,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=rule_count(D).
'$enumerate_constraints'(passive,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=passive(D,E).
'$enumerate_constraints'(occurrence,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D,E,F,G,H),
   A=occurrence(D,E,F,G,H).
'$enumerate_constraints'(max_occurrence,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=max_occurrence(D,E).
'$enumerate_constraints'(allocation_occurrence,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=allocation_occurrence(D,E).
'$enumerate_constraints'(rule,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____rule___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D,E),
   A=rule(D,E).
'$enumerate_constraints'(least_occurrence,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=least_occurrence(D,E).
'$enumerate_constraints'(constraint_index,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=constraint_index(D,E).
'$enumerate_constraints'(max_constraint_index,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____max_constraint_index___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=max_constraint_index(D).
'$enumerate_constraints'(identifier_size,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=identifier_size(D).
'$enumerate_constraints'(identifier_index,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=identifier_index(D,E,F).
'$enumerate_constraints'(type_indexed_identifier_size,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=type_indexed_identifier_size(D,E).
'$enumerate_constraints'(type_indexed_identifier_index,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F,G),
   A=type_indexed_identifier_index(D,E,F,G).
'$enumerate_constraints'(no_history,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=no_history(D).
'$enumerate_constraints'(history,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E,F),
   A=history(D,E,F).
'$enumerate_constraints'(indexing_spec,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=indexing_spec(D,E).
'$enumerate_constraints'(observation_analysis,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____observation_analysis___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=observation_analysis(D).
'$enumerate_constraints'(spawns,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns___3',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D,E,F),
   A=spawns(D,E,F).
'$enumerate_constraints'(spawns_all,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=spawns_all(D,E).
'$enumerate_constraints'(spawns_all_triggers,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D,E),
   A=spawns_all_triggers(D,E).
'$enumerate_constraints'(spawns_all_triggers_implies_spawns_all,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_),
   A=spawns_all_triggers_implies_spawns_all.
'$enumerate_constraints'(empty_named_history_initialisations,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=empty_named_history_initialisations(D,E).
'$enumerate_constraints'(generate_empty_named_history_initialisation,A) :-
   nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D),
   A=generate_empty_named_history_initialisation(D).
'$enumerate_constraints'(find_empty_named_histories,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_),
   A=find_empty_named_histories.
'$enumerate_constraints'(module_initializer,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=module_initializer(D).
'$enumerate_constraints'(actual_atomic_multi_hash_keys,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=actual_atomic_multi_hash_keys(D,E,F).
'$enumerate_constraints'(actual_ground_multi_hash_keys,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=actual_ground_multi_hash_keys(D,E,F).
'$enumerate_constraints'(actual_non_ground_multi_hash_key,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=actual_non_ground_multi_hash_key(D,E).
'$enumerate_constraints'(symbol_count,A) :-
   nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=symbol_count(D,E).
'$enumerate_constraints'(fresh_symbol,A) :-
   nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,_,D,E),
   A=fresh_symbol(D,E).
'$enumerate_constraints'(prolog_global_variable,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=prolog_global_variable(D).
'$enumerate_constraints'(background_info,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____background_info___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=background_info(D).
'$enumerate_constraints'(background_info,A) :-
   nb_getval('$chr_store_global_list_chr_translate____background_info___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,_,D,E),
   A=background_info(D,E).
'$enumerate_constraints'(get_bg_info,A) :-
   nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,_,D,E),
   A=get_bg_info(D,E).
'$enumerate_constraints'(get_bg_info_answer,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=get_bg_info_answer(D).
'$enumerate_constraints'(prev_guard_list,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,D,E,F,G,H,I),
   A=prev_guard_list(D,E,F,G,H,I).
'$enumerate_constraints'(set_all_passive,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D),
   A=set_all_passive(D).
'$enumerate_constraints'(precompute_head_matchings,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_),
   A=precompute_head_matchings.
'$enumerate_constraints'(make_head_matchings_explicit_memo_table,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=make_head_matchings_explicit_memo_table(D,E,F).
'$enumerate_constraints'(multiple_occ_constraints_checked,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=multiple_occ_constraints_checked(D).
'$enumerate_constraints'(type_definition,A) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,_,D,E),
   A=type_definition(D,E).
'$enumerate_constraints'(type_alias,A) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_,_,D,E),
   A=type_alias(D,E).
'$enumerate_constraints'(constraint_type,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=constraint_type(D,E).
'$enumerate_constraints'(unalias_type,A) :-
   nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=unalias_type(D,E).
'$enumerate_constraints'(types_modes_condition,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E,F),
   A=types_modes_condition(D,E,F).
'$enumerate_constraints'(static_type_check,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=static_type_check(D,E).
'$enumerate_constraints'(ast_static_type_check_var,A) :-
   nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E,F,G),
   A=ast_static_type_check_var(D,E,F,G).
'$enumerate_constraints'(ast_static_atomic_builtin_type_check_var,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F,G),
   A=ast_static_atomic_builtin_type_check_var(D,E,F,G).
'$enumerate_constraints'(dynamic_type_check,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_),
   A=dynamic_type_check.
'$enumerate_constraints'(dynamic_type_check_clauses,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=dynamic_type_check_clauses(D).
'$enumerate_constraints'(atomic_type,A) :-
   nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=atomic_type(D).
'$enumerate_constraints'(stored,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=stored(D,E,F).
'$enumerate_constraints'(stored_complete,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E,F),
   A=stored_complete(D,E,F).
'$enumerate_constraints'(check_all_passive,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=check_all_passive(D,E).
'$enumerate_constraints'(constraints_code1,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____constraints_code1___3',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E,F),
   A=constraints_code1(D,E,F).
'$enumerate_constraints'(memo_has_active_occurrence,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=memo_has_active_occurrence(D).
'$enumerate_constraints'(use_auxiliary_predicate,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=use_auxiliary_predicate(D).
'$enumerate_constraints'(use_auxiliary_predicate,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=use_auxiliary_predicate(D,E).
'$enumerate_constraints'(use_auxiliary_module,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=use_auxiliary_module(D).
'$enumerate_constraints'(functional_dependency,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F,G),
   A=functional_dependency(D,E,F,G).
'$enumerate_constraints'(initial_call_pattern,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D),
   A=initial_call_pattern(D).
'$enumerate_constraints'(call_pattern,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=call_pattern(D).
'$enumerate_constraints'(final_answer_pattern,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=final_answer_pattern(D,E).
'$enumerate_constraints'(abstract_constraints,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=abstract_constraints(D).
'$enumerate_constraints'(depends_on,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=depends_on(D,E).
'$enumerate_constraints'(depends_on_ap,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E,F,G),
   A=depends_on_ap(D,E,F,G).
'$enumerate_constraints'(depends_on_goal,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=depends_on_goal(D,E).
'$enumerate_constraints'(ai_observed_internal,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=ai_observed_internal(D,E).
'$enumerate_constraints'(ai_not_observed_internal,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=ai_not_observed_internal(D,E).
'$enumerate_constraints'(ai_not_observed,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=ai_not_observed(D,E).
'$enumerate_constraints'(depends_on_as,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E,F),
   A=depends_on_as(D,E,F).
'$enumerate_constraints'(ai_observation_gather_results,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_),
   A=ai_observation_gather_results.
'$enumerate_constraints'(ai_observation_memoed_simplification_rest_heads,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=ai_observation_memoed_simplification_rest_heads(D,E,F).
'$enumerate_constraints'(ai_observation_memoed_propagation_rest_heads,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=ai_observation_memoed_propagation_rest_heads(D,E,F).
'$enumerate_constraints'(ai_observation_memoed_abstract_goal,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=ai_observation_memoed_abstract_goal(D,E).
'$enumerate_constraints'(ai_observation_memo_abstract_goal,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=ai_observation_memo_abstract_goal(D,E).
'$enumerate_constraints'(partial_wake_analysis,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,_),
   A=partial_wake_analysis.
'$enumerate_constraints'(no_partial_wake,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=no_partial_wake(D).
'$enumerate_constraints'(phase_end,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=phase_end(D).
'$enumerate_constraints'(delay_phase_end,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=delay_phase_end(D,E).
'$enumerate_constraints'(does_use_history,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=does_use_history(D,E).
'$enumerate_constraints'(does_use_field,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=does_use_field(D,E).
'$enumerate_constraints'(uses_state,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=uses_state(D,E).
'$enumerate_constraints'(if_used_state,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E,F,G,H),
   A=if_used_state(D,E,F,G,H).
'$enumerate_constraints'(used_states_known,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_),
   A=used_states_known.
'$enumerate_constraints'(stored_assertion,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',B),
   value_ht(B,C),
   C=suspension(_,_,D),
   A=stored_assertion(D).
'$enumerate_constraints'(never_stored_default,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',B),
   value_ht(B,C),
   C=suspension(_,_,D,E),
   A=never_stored_default(D,E).
'$enumerate_constraints'(never_stored_rules,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D,E),
   A=never_stored_rules(D,E).
'$enumerate_constraints'(continuation_occurrence,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=continuation_occurrence(D,E,F).
'$enumerate_constraints'(skip_to_next_id,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',B),
   value_ht(B,C),
   C=suspension(_,_,_,D,E),
   A=skip_to_next_id(D,E).
'$enumerate_constraints'(set_occurrence_code_id,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=set_occurrence_code_id(D,E,F).
'$enumerate_constraints'(occurrence_code_id,A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',B),
   value_ht(B,C),
   C=suspension(_,_,D,E,F),
   A=occurrence_code_id(D,E,F).
'$enumerate_constraints'(chr_constants,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_,D),
   A=chr_constants(D).
'$enumerate_constraints'(print_chr_constants,A) :-
   nb_getval('$chr_store_global_ground_chr_translate____print_chr_constants___0',B),
   'chr sbag_member'(C,B),
   C=suspension(_,_,_),
   A=print_chr_constants.
'$via1_multi_hash_line_number___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_indexed_argument___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_indexed_argument___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_constraint_mode___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_store_type___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_actual_store_types___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_assumed_store_type___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_validate_store_type_assumption___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_passive___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_passive___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-15'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-125'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-134'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-3'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-13'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-34'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence___5-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_max_occurrence___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_allocation_occurrence___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_allocation_occurrence___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_rule___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_least_occurrence___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_least_occurrence___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_constraint_index___2-2'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_constraint_index___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_identifier_index___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_type_indexed_identifier_size___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_type_indexed_identifier_index___4-123'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_type_indexed_identifier_index___4-23'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_no_history___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',C),
   lookup_ht(C,A,B).
'$chr_store_constants_chr_translate____history___3___[3]'([],'$chr_store_constants_chr_translate____history___3___[3]___[]').
'$via1_multi_hash_history___3-2'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_history___3-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_indexing_spec___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns___3-13'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns___3-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns___3-3'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns___3-123'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns_all___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns_all___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns_all_triggers___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_spawns_all_triggers___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_actual_atomic_multi_hash_keys___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_actual_atomic_multi_hash_keys___3-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_actual_ground_multi_hash_keys___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_actual_ground_multi_hash_keys___3-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_actual_non_ground_multi_hash_key___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_prolog_global_variable___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_prev_guard_list___6-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_set_all_passive___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_make_head_matchings_explicit_memo_table___3-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_constraint_type___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ast_static_atomic_builtin_type_check_var___4-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ast_static_atomic_builtin_type_check_var___4-13'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_stored___3-13'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_stored___3-123'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_stored_complete___3-13'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_stored_complete___3-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_check_all_passive___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_check_all_passive___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_memo_has_active_occurrence___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_use_auxiliary_predicate___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_use_auxiliary_predicate___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_use_auxiliary_predicate___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_use_auxiliary_module___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_functional_dependency___4-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_functional_dependency___4-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_initial_call_pattern___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_call_pattern___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_final_answer_pattern___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on___2-2'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on_ap___4-2'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on_ap___4-3'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on_goal___2-2'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ai_observed_internal___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ai_not_observed_internal___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ai_not_observed___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on_as___3-3'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_depends_on_as___3-2'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ai_observation_memoed_simplification_rest_heads___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ai_observation_memoed_propagation_rest_heads___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_ai_observation_memoed_abstract_goal___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_no_partial_wake___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_phase_end___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_delay_phase_end___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_does_use_history___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_does_use_history___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_does_use_field___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_uses_state___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_if_used_state___5-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_stored_assertion___1-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_never_stored_default___2-1'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_continuation_occurrence___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_skip_to_next_id___2-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_set_occurrence_code_id___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',C),
   lookup_ht(C,A,B).
'$via1_multi_hash_occurrence_code_id___3-12'(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',C),
   lookup_ht(C,A,B).
'$chr_initialization' :-
   nb_setval('$chr_store_global_ground_chr_translate____print_chr_constants___0',[]),
   nb_setval('$chr_store_global_ground_chr_translate____chr_constants___1',[]),
   new_ht(A),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',A),
   new_ht(B),
   nb_setval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',B),
   new_ht(C),
   nb_setval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',C),
   new_ht(D),
   nb_setval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',D),
   nb_setval('$chr_store_global_ground_chr_translate____never_stored_rules___2',[]),
   new_ht(E),
   nb_setval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',E),
   new_ht(F),
   nb_setval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',F),
   nb_setval('$chr_store_global_ground_chr_translate____used_states_known___0',[]),
   new_ht(G),
   nb_setval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',G),
   nb_setval('$chr_store_global_ground_chr_translate____if_used_state___5',[]),
   new_ht(H),
   nb_setval('$chr_store_multi_hash_chr_translate____uses_state___2-12',H),
   new_ht(I),
   nb_setval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',I),
   new_ht(J),
   nb_setval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',J),
   new_ht(K),
   nb_setval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',K),
   new_ht(L),
   nb_setval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',L),
   new_ht(M),
   nb_setval('$chr_store_multi_hash_chr_translate____phase_end___1-1',M),
   new_ht(N),
   nb_setval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',N),
   nb_setval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',[]),
   nb_setval('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2',[]),
   new_ht(O),
   nb_setval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',O),
   new_ht(P),
   nb_setval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',P),
   new_ht(Q),
   nb_setval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',Q),
   nb_setval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',[]),
   new_ht(R),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',R),
   new_ht(S),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',S),
   new_ht(T),
   nb_setval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',T),
   new_ht(U),
   nb_setval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',U),
   nb_setval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',[]),
   new_ht(V),
   nb_setval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',V),
   nb_setval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',[]),
   new_ht(W),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',W),
   new_ht(X),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',X),
   new_ht(Y),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',Y),
   new_ht(Z),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on___2-2',Z),
   new_ht(A1),
   nb_setval('$chr_store_multi_hash_chr_translate____depends_on___2-1',A1),
   nb_setval('$chr_store_global_ground_chr_translate____abstract_constraints___1',[]),
   new_ht(B1),
   nb_setval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',B1),
   new_ht(C1),
   nb_setval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',C1),
   new_ht(D1),
   nb_setval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',D1),
   new_ht(E1),
   nb_setval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',E1),
   new_ht(F1),
   nb_setval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',F1),
   new_ht(G1),
   nb_setval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',G1),
   new_ht(H1),
   nb_setval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',H1),
   new_ht(I1),
   nb_setval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',I1),
   new_ht(J1),
   nb_setval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',J1),
   new_ht(K1),
   nb_setval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',K1),
   nb_setval('$chr_store_global_ground_chr_translate____constraints_code1___3',[]),
   new_ht(L1),
   nb_setval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',L1),
   new_ht(M1),
   nb_setval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',M1),
   new_ht(N1),
   nb_setval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',N1),
   new_ht(O1),
   nb_setval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',O1),
   new_ht(P1),
   nb_setval('$chr_store_multi_hash_chr_translate____stored___3-123',P1),
   new_ht(Q1),
   nb_setval('$chr_store_multi_hash_chr_translate____stored___3-13',Q1),
   nb_setval('$chr_store_global_list_chr_translate____atomic_type___1',[]),
   nb_setval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',[]),
   nb_setval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',[]),
   new_ht(R1),
   nb_setval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',R1),
   new_ht(S1),
   nb_setval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',S1),
   nb_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',[]),
   nb_setval('$chr_store_global_ground_chr_translate____static_type_check___2',[]),
   nb_setval('$chr_store_global_ground_chr_translate____types_modes_condition___3',[]),
   nb_setval('$chr_store_global_list_chr_translate____unalias_type___2',[]),
   new_ht(T1),
   nb_setval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',T1),
   nb_setval('$chr_store_global_ground_chr_translate____constraint_type___2',[]),
   nb_setval('$chr_store_global_list_chr_translate____type_alias___2',[]),
   nb_setval('$chr_store_global_list_chr_translate____type_definition___2',[]),
   nb_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',[]),
   new_ht(U1),
   nb_setval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',U1),
   nb_setval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',[]),
   new_ht(V1),
   nb_setval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',V1),
   new_ht(W1),
   nb_setval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',W1),
   nb_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',[]),
   nb_setval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',[]),
   nb_setval('$chr_store_global_list_chr_translate____get_bg_info___2',[]),
   nb_setval('$chr_store_global_list_chr_translate____background_info___2',[]),
   nb_setval('$chr_store_global_ground_chr_translate____background_info___1',[]),
   new_ht(X1),
   nb_setval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',X1),
   nb_setval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',[]),
   nb_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',[]),
   nb_setval('$chr_store_global_list_chr_translate____symbol_count___2',[]),
   new_ht(Y1),
   nb_setval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',Y1),
   new_ht(Z1),
   nb_setval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',Z1),
   new_ht(A2),
   nb_setval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',A2),
   new_ht(B2),
   nb_setval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',B2),
   new_ht(C2),
   nb_setval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',C2),
   nb_setval('$chr_store_global_ground_chr_translate____module_initializer___1',[]),
   nb_setval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',[]),
   nb_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',[]),
   nb_setval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',[]),
   nb_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',[]),
   new_ht(D2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',D2),
   new_ht(E2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',E2),
   nb_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',[]),
   new_ht(F2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',F2),
   new_ht(G2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',G2),
   new_ht(H2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns___3-123',H2),
   new_ht(I2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns___3-3',I2),
   new_ht(J2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns___3-1',J2),
   new_ht(K2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns___3-12',K2),
   nb_setval('$chr_store_global_ground_chr_translate____spawns___3',[]),
   new_ht(L2),
   nb_setval('$chr_store_multi_hash_chr_translate____spawns___3-13',L2),
   nb_setval('$chr_store_global_ground_chr_translate____observation_analysis___1',[]),
   new_ht(M2),
   nb_setval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',M2),
   new_ht(N2),
   nb_setval('$chr_store_multi_hash_chr_translate____history___3-1',N2),
   new_ht(O2),
   nb_setval('$chr_store_multi_hash_chr_translate____history___3-2',O2),
   nb_setval('$chr_store_constants_chr_translate____history___3___[3]___[]',[]),
   new_ht(P2),
   nb_setval('$chr_store_multi_hash_chr_translate____no_history___1-1',P2),
   new_ht(Q2),
   nb_setval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',Q2),
   new_ht(R2),
   nb_setval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',R2),
   new_ht(S2),
   nb_setval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',S2),
   new_ht(T2),
   nb_setval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',T2),
   nb_setval('$chr_store_global_ground_chr_translate____identifier_size___1',[]),
   nb_setval('$chr_store_global_ground_chr_translate____max_constraint_index___1',[]),
   new_ht(U2),
   nb_setval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',U2),
   new_ht(V2),
   nb_setval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',V2),
   new_ht(W2),
   nb_setval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',W2),
   new_ht(X2),
   nb_setval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',X2),
   new_ht(Y2),
   nb_setval('$chr_store_multi_hash_chr_translate____rule___2-1',Y2),
   nb_setval('$chr_store_global_ground_chr_translate____rule___2',[]),
   new_ht(Z2),
   nb_setval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',Z2),
   new_ht(A3),
   nb_setval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',A3),
   new_ht(B3),
   nb_setval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',B3),
   new_ht(C3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-1',C3),
   new_ht(D3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-34',D3),
   new_ht(E3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-13',E3),
   new_ht(F3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-3',F3),
   new_ht(G3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-12',G3),
   new_ht(H3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-134',H3),
   new_ht(I3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-125',I3),
   nb_setval('$chr_store_global_ground_chr_translate____occurrence___5',[]),
   new_ht(J3),
   nb_setval('$chr_store_multi_hash_chr_translate____occurrence___5-15',J3),
   new_ht(K3),
   nb_setval('$chr_store_multi_hash_chr_translate____passive___2-12',K3),
   new_ht(L3),
   nb_setval('$chr_store_multi_hash_chr_translate____passive___2-1',L3),
   nb_setval('$chr_store_global_ground_chr_translate____rule_count___1',[]),
   new_ht(M3),
   nb_setval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',M3),
   new_ht(N3),
   nb_setval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',N3),
   new_ht(O3),
   nb_setval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',O3),
   new_ht(P3),
   nb_setval('$chr_store_multi_hash_chr_translate____store_type___2-1',P3),
   nb_setval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',[]),
   new_ht(Q3),
   nb_setval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',Q3),
   nb_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',[]),
   new_ht(R3),
   nb_setval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',R3),
   new_ht(S3),
   nb_setval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',S3),
   new_ht(T3),
   nb_setval('$chr_store_multi_hash_chr_translate____line_number___2-1',T3),
   nb_setval('$chr_store_global_ground_chr_translate____target_module___1',[]),
   nb_setval('$chr_store_global_ground_chr_translate____chr_source_file___1',[]).
:-initialization '$chr_initialization'.
:-dynamic user:exception/3.
:-multifile user:exception/3.
user:exception(undefined_global_variable,A,retry) :-
   '$chr_prolog_global_variable'(A),
   '$chr_initialization'.
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____print_chr_constants___0').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____chr_constants___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____never_stored_rules___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____never_stored_default___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____stored_assertion___1-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____used_states_known___0').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____if_used_state___5-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____if_used_state___5').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____uses_state___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____does_use_field___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____does_use_history___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____does_use_history___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____phase_end___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____partial_wake_analysis___0').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on_as___3-2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on_as___3-3').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____ai_observed_internal___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on___2-2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____depends_on___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____abstract_constraints___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____call_pattern___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____functional_dependency___4-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____functional_dependency___4-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____constraints_code1___3').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____check_all_passive___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____check_all_passive___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____stored_complete___3-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____stored_complete___3-13').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____stored___3-123').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____stored___3-13').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____atomic_type___1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____dynamic_type_check___0').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____ast_static_type_check_var___4').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____static_type_check___2').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____types_modes_condition___3').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____unalias_type___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____constraint_type___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____constraint_type___2').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____type_alias___2').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____type_definition___2').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____precompute_head_matchings___0').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____set_all_passive___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____prev_guard_list___6').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____get_bg_info_answer___1').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____get_bg_info___2').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____background_info___2').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____background_info___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____prolog_global_variable___1').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____fresh_symbol___2').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____symbol_count___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____module_initializer___1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____find_empty_named_histories___0').
'$chr_prolog_global_variable'('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____spawns_all_triggers___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns_all___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns_all___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns___3-123').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns___3-3').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns___3-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns___3-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____spawns___3').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____spawns___3-13').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____observation_analysis___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____indexing_spec___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____history___3-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____history___3-2').
'$chr_prolog_global_variable'('$chr_store_constants_chr_translate____history___3___[3]___[]').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____no_history___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____identifier_index___3-12').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____identifier_size___1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____max_constraint_index___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____constraint_index___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____constraint_index___2-2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____least_occurrence___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____least_occurrence___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____rule___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____rule___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____max_occurrence___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-34').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-13').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-3').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-134').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-125').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____occurrence___5').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____occurrence___5-15').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____passive___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____passive___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____rule_count___1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____actual_store_types___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____store_type___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____constraint_mode___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____constraint_mode___2').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____indexed_argument___2-12').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____indexed_argument___2-1').
'$chr_prolog_global_variable'('$chr_store_multi_hash_chr_translate____line_number___2-1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____target_module___1').
'$chr_prolog_global_variable'('$chr_store_global_ground_chr_translate____chr_source_file___1').
chr_source_file(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',B),
   (
     'chr sbag_member'(C,B),
     C=suspension(_,active,_,_),
     !
   ;
     !,
     chr_source_file___1__0__0__2(B,A)
   ).
chr_source_file___1__0__0__2([],A) :-
   chr_source_file___1__1(A).
chr_source_file___1__0__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_) ->
     setarg(2,B,removed),
     arg(3,B,D),
     ( var(D) ->
       nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',E),
       E=[_|F],
       b_setval('$chr_store_global_ground_chr_translate____chr_source_file___1',F),
       ( F=[G|_] ->
         setarg(3,G,_)
       ;
         true
       )
     ;
       D=[_,_|F],
       setarg(2,D,F),
       ( F=[G|_] ->
         setarg(3,G,D)
       ;
         true
       )
     ),
     chr_source_file___1__0__0__2(C,A)
   ;
     chr_source_file___1__0__0__2(C,A)
   ).
chr_source_file(A) :-
   chr_source_file___1__1(A).
chr_source_file___1__1(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____chr_source_file___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
get_chr_source_file(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   A=D.
get_chr_source_file(user).
target_module(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____target_module___1',B),
   (
     'chr sbag_member'(C,B),
     C=suspension(_,active,_,_),
     !
   ;
     !,
     target_module___1__0__0__2(B,A)
   ).
target_module___1__0__0__2([],A) :-
   target_module___1__1(A).
target_module___1__0__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_) ->
     setarg(2,B,removed),
     arg(3,B,D),
     ( var(D) ->
       nb_getval('$chr_store_global_ground_chr_translate____target_module___1',E),
       E=[_|F],
       b_setval('$chr_store_global_ground_chr_translate____target_module___1',F),
       ( F=[G|_] ->
         setarg(3,G,_)
       ;
         true
       )
     ;
       D=[_,_|F],
       setarg(2,D,F),
       ( F=[G|_] ->
         setarg(3,G,D)
       ;
         true
       )
     ),
     target_module___1__0__0__2(C,A)
   ;
     target_module___1__0__0__2(C,A)
   ).
target_module(A) :-
   target_module___1__1(A).
target_module___1__1(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____target_module___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____target_module___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
get_target_module(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____target_module___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   A=D.
get_target_module(user).
line_number(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',C),
   lookup_ht(C,A,D),
   (
     'chr sbag_member'(E,D),
     E=suspension(_,active,_,_),
     !
   ;
     !,
     line_number___2__0__0__2(D,A,B)
   ).
line_number___2__0__0__2([],A,B) :-
   line_number___2__1(A,B).
line_number___2__0__0__2([C|D],A,B) :-
   ( C=suspension(_,active,E,_),
     E==A ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',F),
     delete_ht(F,A,C),
     line_number___2__0__0__2(D,A,B)
   ;
     line_number___2__0__0__2(D,A,B)
   ).
line_number(A,B) :-
   line_number___2__1(A,B).
line_number___2__1(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',E),
   insert_ht(E,A,C).
get_line_number(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
get_line_number(_,0).
indexed_argument(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
indexed_argument(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',E),
   insert_ht(E,A,C),
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',F),
   insert_ht(F,k(A,B),C).
is_indexed_argument(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
is_indexed_argument(_,_) :-
   fail.
constraint_mode(A,B) :-
   constraint_mode___2__0(A,B,_).
constraint_mode___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',D),
   lookup_ht(D,A,E),
   (
     'chr sbag_member'(F,E),
     F=suspension(_,active,_,_,_,_),
     !
   ;
     !,
     constraint_mode___2__0__0__2(E,A,B,C)
   ).
constraint_mode___2__0__0__2([],A,B,C) :-
   constraint_mode___2__1(A,B,C).
constraint_mode___2__0__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_),
     F==A ->
     setarg(2,D,removed),
     arg(4,D,G),
     ( var(G) ->
       nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',H),
       H=[_|I],
       b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',I),
       ( I=[J|_] ->
         setarg(4,J,_)
       ;
         true
       )
     ;
       G=[_,_|I],
       setarg(2,G,I),
       ( I=[J|_] ->
         setarg(4,J,G)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',K),
     delete_ht(K,A,D),
     constraint_mode___2__0__0__2(E,A,B,C)
   ;
     constraint_mode___2__0__0__2(E,A,B,C)
   ).
constraint_mode___2__0(A,B,C) :-
   constraint_mode___2__1(A,B,C).
constraint_mode___2__1(A,B,C) :-
   A=D/E,
   nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',F),
   !,
   C=suspension(G,not_stored_yet,t,_,A,B),
   'chr gen_id'(G),
   constraint_mode___2__1__0__7(F,A,B,C,D,E).
constraint_mode___2__1__0__7([],A,B,C,_,_) :-
   constraint_mode___2__2(A,B,C).
constraint_mode___2__1__0__7([F|G],A,B,C,D,E) :-
   ( F=suspension(_,active,_,H,I,J),
     H=[K|L],
     I=[M|N],
     functor(K,D,E) ->
     setarg(2,F,removed),
     arg(3,F,O),
     ( var(O) ->
       nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',P),
       P=[_|Q],
       b_setval('$chr_store_global_ground_chr_translate____types_modes_condition___3',Q),
       ( Q=[R|_] ->
         setarg(3,R,_)
       ;
         true
       )
     ;
       O=[_,_|Q],
       setarg(2,O,Q),
       ( Q=[R|_] ->
         setarg(3,R,O)
       ;
         true
       )
     ),
     arg(2,C,S),
     setarg(2,C,active),
     ( S==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',T),
       U=[C|T],
       b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',U),
       ( T=[V|_] ->
         setarg(4,V,U)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',W),
       insert_ht(W,A,C)
     ;
       true
     ),
     K=..[_|X],
     J= (Y,Z,A1),
     modes_condition(B,X,Y),
     get_constraint_type_det(D/E,B1),
     M=..[_|C1],
     types_condition(B1,X,C1,B,Z),
     types_modes_condition(L,N,A1),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       constraint_mode___2__1__0__7(G,A,B,C,D,E)
     ;
       true
     )
   ;
     constraint_mode___2__1__0__7(G,A,B,C,D,E)
   ).
constraint_mode___2__1(A,B,C) :-
   C=suspension(D,not_stored_yet,t,_,A,B),
   'chr gen_id'(D),
   constraint_mode___2__2(A,B,C).
constraint_mode___2__2(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D),
   lookup_ht(D,A,E),
   !,
   constraint_mode___2__2__0__8(E,A,B,C).
constraint_mode___2__2__0__8([],A,B,C) :-
   constraint_mode___2__3(A,B,C).
constraint_mode___2__2__0__8([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,I),
     F==A,
     nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',J) ->
     constraint_mode___2__2__1__8(J,G,H,I,D,E,A,B,C)
   ;
     constraint_mode___2__2__0__8(E,A,B,C)
   ).
constraint_mode___2__2__1__8([],_,_,_,_,A,B,C,D) :-
   constraint_mode___2__2__0__8(A,B,C,D).
constraint_mode___2__2__1__8([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',K),
     lookup_ht(K,A,L) ->
     constraint_mode___2__2__2__8(L,I,J,A,B,C,D,E,F,G,H)
   ;
     constraint_mode___2__2__1__8(J,A,B,C,D,E,F,G,H)
   ).
constraint_mode___2__2__2__8([],_,A,B,C,D,E,F,G,H,I) :-
   constraint_mode___2__2__1__8(A,B,C,D,E,F,G,H,I).
constraint_mode___2__2__2__8([K|L],A,B,C,D,E,F,G,H,I,J) :-
   ( K=suspension(_,active,_,_,M,N),
     M==C,
     O=t(330,A,F,K,J),
     '$novel_production'(A,O),
     '$novel_production'(F,O),
     '$novel_production'(K,O),
     '$novel_production'(J,O) ->
     '$extend_history'(J,O),
     arg(2,J,P),
     setarg(2,J,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',Q),
       R=[J|Q],
       b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',R),
       ( Q=[S|_] ->
         setarg(4,S,R)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',T),
       insert_ht(T,H,J)
     ;
       true
     ),
     N=pragma(rule(U,V,W,_),_,_,_,_),
     ( is_passive(C,D) ->
       true
     ;
       ( E==simplification ->
         select(X,U,_),
         X=..[_|Y],
         term_variables(W,Z),
         partial_wake_args(Y,I,Z,H)
       )
     ;
       select(X,V,_),
       X=..[_|Y],
       term_variables(W,Z),
       partial_wake_args(Y,I,Z,H)
     ),
     ( J=suspension(_,active,_,_,_,_) ->
       setarg(2,J,inactive),
       constraint_mode___2__2__2__8(L,A,B,C,D,E,F,G,H,I,J)
     ;
       true
     )
   ;
     constraint_mode___2__2__2__8(L,A,B,C,D,E,F,G,H,I,J)
   ).
constraint_mode___2__2(A,B,C) :-
   constraint_mode___2__3(A,B,C).
constraint_mode___2__3(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',D),
     E=[B|D],
     b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',E),
     ( D=[F|_] ->
       setarg(4,F,E)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',G),
     insert_ht(G,A,B)
   ;
     true
   ).
get_constraint_mode(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F),
   !,
   B=F.
get_constraint_mode(_/B,A) :-
   replicate(B,?,A).
may_trigger(A) :-
   \+has_active_occurrence(A),
   !,
   fail.
may_trigger(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E),
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',F),
   lookup_ht(F,A,G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,I),
   nth1(I,E,J),
   J\== (+),
   !,
   is_stored(A).
may_trigger(_) :-
   chr_pp_flag(debugable,on).
only_ground_indexed_arguments(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E),
   nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',F),
   lookup_ht(F,A,G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,I),
   nth1(I,E,J),
   J\== (+),
   !,
   fail.
only_ground_indexed_arguments(_).
none_suspended_on_variables :-
   nb_getval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',A),
   'chr sbag_member'(B,A),
   B=suspension(_,active,_),
   !.
none_suspended_on_variables :-
   A=suspension(B,active,_),
   'chr gen_id'(B),
   nb_getval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',C),
   D=[A|C],
   b_setval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',D),
   ( C=[E|_] ->
     setarg(3,E,D)
   ;
     true
   ).
are_none_suspended_on_variables :-
   nb_getval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',A),
   'chr sbag_member'(B,A),
   B=suspension(_,active,_),
   !.
are_none_suspended_on_variables :-
   fail.
store_type(A,B) :-
   store_type___2__0(A,B,_).
store_type___2__0(A,B,C) :-
   chr_pp_flag(verbose,on),
   !,
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',E),
   insert_ht(E,A,C),
   format('The indexes for ~w are:\n',[A]),
   format_storetype(B),
   ( C=suspension(_,active,_,_) ->
     setarg(2,C,inactive),
     store_type___2__1(A,B,C)
   ;
     true
   ).
store_type___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,A,B),
   'chr gen_id'(D),
   store_type___2__1(A,B,C).
store_type___2__1(A,_,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',F),
   lookup_ht(F,A,G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,I),
   !,
   setarg(2,E,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',J),
   delete_ht(J,A,E),
   setarg(2,H,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',K),
   delete_ht(K,A,H),
   ( var(B) ->
     true
   ;
     arg(2,B,L),
     setarg(2,B,removed),
     ( L==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',M),
       delete_ht(M,A,B)
     )
   ),
   store_type(A,multi_store(I)).
store_type___2__1(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',D),
     insert_ht(D,A,B)
   ;
     true
   ).
get_store_type(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
get_store_type(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
get_store_type(_,default).
update_store_type(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   (
     memberchk(B,F),
     !
   ;
     !,
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',G),
     delete_ht(G,A,E),
     actual_store_types(A,[B|F])
   ).
update_store_type(A,B) :-
   actual_store_types(A,[B]).
actual_store_types(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F,G),
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',H),
   lookup_ht(H,A,I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_),
   !,
   setarg(2,E,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',K),
   delete_ht(K,k(A,F),E),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',L),
   delete_ht(L,A,E),
   selectchk(multi_hash([F]),B,M),
   F=[N],
   ( get_constraint_arg_type(A,N,O),
     enumerated_atomic_type(O,P) ->
     Q=P,
     R=complete
   ;
     Q=G,
     R=incomplete
   ),
   actual_store_types(A,[atomic_constants(F,Q,R)|M]).
actual_store_types(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F,G),
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',H),
   lookup_ht(H,A,I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_),
   !,
   setarg(2,E,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',K),
   delete_ht(K,k(A,F),E),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',L),
   delete_ht(L,A,E),
   ( F=[M],
     get_constraint_arg_type(A,M,N),
     N=chr_enum(O) ->
     P=complete
   ;
     O=G,
     P=incomplete
   ),
   selectchk(multi_hash([F]),B,Q),
   actual_store_types(A,[ground_constants(F,O,P)|Q]).
actual_store_types(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_),
   (
     (
       memberchk(multi_hash([[F]]),B),
       (
         get_constraint_type(A,G),
         nth1(F,G,H),
         enumerated_atomic_type(H,I),
         !,
         selectchk(multi_hash([[F]]),B,J),
         actual_store_types(A,[atomic_constants([F],I,complete)|J])
       ;
         get_constraint_arg_type(A,F,K),
         K=chr_enum(L),
         !,
         selectchk(multi_hash([[F]]),B,M),
         actual_store_types(A,[ground_constants([F],L,complete)|M])
       )
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',N),
       lookup_ht(N,A,O),
       'chr sbag_member'(P,O),
       P=suspension(_,active,_,_),
       !,
       setarg(2,E,removed),
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',Q),
       delete_ht(Q,A,E),
       setarg(2,P,removed),
       nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',R),
       delete_ht(R,A,P),
       ( maplist(partial_store,B) ->
         S=[global_ground|B]
       ;
         S=B
       ),
       store_type(A,multi_store(S))
     )
   ;
     nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',T),
     lookup_ht(T,A,U),
     'chr sbag_member'(V,U),
     V=suspension(_,active,_,_),
     !,
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',W),
     delete_ht(W,A,E),
     setarg(2,V,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',X),
     delete_ht(X,A,V),
     store_type(A,multi_store(B))
   ).
actual_store_types(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',E),
   insert_ht(E,A,C).
assumed_store_type(A,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   (
     (
       nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',E),
       lookup_ht(E,A,F),
       'chr sbag_member'(G,F),
       G=suspension(_,active,_,H),
       !,
       setarg(2,D,removed),
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',I),
       delete_ht(I,A,D),
       setarg(2,G,removed),
       nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',J),
       delete_ht(J,A,G),
       ( maplist(partial_store,H) ->
         K=[global_ground|H]
       ;
         K=H
       ),
       store_type(A,multi_store(K))
     ;
       chr_pp_flag(debugable,on),
       !,
       setarg(2,D,removed),
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',L),
       delete_ht(L,A,D),
       store_type(A,default)
     )
   ;
     !,
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',M),
     delete_ht(M,A,D),
     store_type(A,global_ground)
   ).
assumed_store_type(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',E),
   insert_ht(E,A,C).
validate_store_type_assumption(A) :-
   validate_store_type_assumption___1__0(A,_).
validate_store_type_assumption___1__0(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,D),
   !,
   B=suspension(E,not_stored_yet,A),
   'chr gen_id'(E),
   validate_store_type_assumption___1__0__0__1(D,A,B).
validate_store_type_assumption___1__0__0__1([],A,B) :-
   validate_store_type_assumption___1__1(A,B).
validate_store_type_assumption___1__0__0__1([C|D],A,B) :-
   ( C=suspension(_,active,E,F),
     E==A,
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',G),
     lookup_ht(G,A,H),
     'chr sbag_member'(I,H),
     I=suspension(_,active,_,J,K) ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',L),
     delete_ht(L,A,C),
     setarg(2,I,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',M),
     delete_ht(M,k(A,J),I),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',N),
     delete_ht(N,A,I),
     arg(2,B,O),
     setarg(2,B,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',P),
       insert_ht(P,A,B)
     ;
       true
     ),
     selectchk(multi_hash([J]),F,Q),
     J=[R],
     ( get_constraint_arg_type(A,R,S),
       enumerated_atomic_type(S,T) ->
       U=T,
       V=complete
     ;
       U=K,
       V=incomplete
     ),
     actual_store_types(A,[atomic_constants(J,U,V)|Q]),
     ( B=suspension(_,active,_) ->
       setarg(2,B,inactive),
       validate_store_type_assumption___1__0__0__1(D,A,B)
     ;
       true
     )
   ;
     validate_store_type_assumption___1__0__0__1(D,A,B)
   ).
validate_store_type_assumption___1__0(A,B) :-
   B=suspension(C,not_stored_yet,A),
   'chr gen_id'(C),
   validate_store_type_assumption___1__1(A,B).
validate_store_type_assumption___1__1(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,D),
   !,
   validate_store_type_assumption___1__1__0__2(D,A,B).
validate_store_type_assumption___1__1__0__2([],A,B) :-
   validate_store_type_assumption___1__2(A,B).
validate_store_type_assumption___1__1__0__2([C|D],A,B) :-
   ( C=suspension(_,active,E,F),
     E==A,
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',G),
     lookup_ht(G,A,H),
     'chr sbag_member'(I,H),
     I=suspension(_,active,_,J,K) ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',L),
     delete_ht(L,A,C),
     setarg(2,I,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',M),
     delete_ht(M,k(A,J),I),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',N),
     delete_ht(N,A,I),
     arg(2,B,O),
     setarg(2,B,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',P),
       insert_ht(P,A,B)
     ;
       true
     ),
     ( J=[Q],
       get_constraint_arg_type(A,Q,R),
       R=chr_enum(S) ->
       T=complete
     ;
       S=K,
       T=incomplete
     ),
     selectchk(multi_hash([J]),F,U),
     actual_store_types(A,[ground_constants(J,S,T)|U]),
     ( B=suspension(_,active,_) ->
       setarg(2,B,inactive),
       validate_store_type_assumption___1__1__0__2(D,A,B)
     ;
       true
     )
   ;
     validate_store_type_assumption___1__1__0__2(D,A,B)
   ).
validate_store_type_assumption___1__1(A,B) :-
   validate_store_type_assumption___1__2(A,B).
validate_store_type_assumption___1__2(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,D),
   !,
   validate_store_type_assumption___1__2__0__3(D,A,B).
validate_store_type_assumption___1__2__0__3([],A,B) :-
   validate_store_type_assumption___1__3(A,B).
validate_store_type_assumption___1__2__0__3([C|D],A,B) :-
   ( C=suspension(_,active,E,F),
     E==A,
     memberchk(multi_hash([[G]]),F),
     get_constraint_type(A,H),
     nth1(G,H,I),
     enumerated_atomic_type(I,J) ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',K),
     delete_ht(K,A,C),
     arg(2,B,L),
     setarg(2,B,active),
     ( L==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',M),
       insert_ht(M,A,B)
     ;
       true
     ),
     selectchk(multi_hash([[G]]),F,N),
     actual_store_types(A,[atomic_constants([G],J,complete)|N]),
     ( B=suspension(_,active,_) ->
       setarg(2,B,inactive),
       validate_store_type_assumption___1__2__0__3(D,A,B)
     ;
       true
     )
   ;
     validate_store_type_assumption___1__2__0__3(D,A,B)
   ).
validate_store_type_assumption___1__2(A,B) :-
   validate_store_type_assumption___1__3(A,B).
validate_store_type_assumption___1__3(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,D),
   !,
   validate_store_type_assumption___1__3__0__4(D,A,B).
validate_store_type_assumption___1__3__0__4([],A,B) :-
   validate_store_type_assumption___1__4(A,B).
validate_store_type_assumption___1__3__0__4([C|D],A,B) :-
   ( C=suspension(_,active,E,F),
     E==A,
     memberchk(multi_hash([[G]]),F),
     get_constraint_arg_type(A,G,H),
     H=chr_enum(I) ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',J),
     delete_ht(J,A,C),
     arg(2,B,K),
     setarg(2,B,active),
     ( K==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',L),
       insert_ht(L,A,B)
     ;
       true
     ),
     selectchk(multi_hash([[G]]),F,M),
     actual_store_types(A,[ground_constants([G],I,complete)|M]),
     ( B=suspension(_,active,_) ->
       setarg(2,B,inactive),
       validate_store_type_assumption___1__3__0__4(D,A,B)
     ;
       true
     )
   ;
     validate_store_type_assumption___1__3__0__4(D,A,B)
   ).
validate_store_type_assumption___1__3(A,B) :-
   validate_store_type_assumption___1__4(A,B).
validate_store_type_assumption___1__4(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   (
     nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',G),
     lookup_ht(G,A,H),
     'chr sbag_member'(I,H),
     I=suspension(_,active,_,_),
     !,
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',J),
     delete_ht(J,A,E),
     setarg(2,I,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',K),
     delete_ht(K,A,I),
     ( var(B) ->
       true
     ;
       arg(2,B,L),
       setarg(2,B,removed),
       ( L==not_stored_yet ->
         true
       ;
         nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',M),
         delete_ht(M,A,B)
       )
     ),
     ( maplist(partial_store,F) ->
       N=[global_ground|F]
     ;
       N=F
     ),
     store_type(A,multi_store(N))
   ;
     nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',O),
     lookup_ht(O,A,P),
     'chr sbag_member'(Q,P),
     Q=suspension(_,active,_,_),
     !,
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',R),
     delete_ht(R,A,E),
     setarg(2,Q,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',S),
     delete_ht(S,A,Q),
     ( var(B) ->
       true
     ;
       arg(2,B,T),
       setarg(2,B,removed),
       ( T==not_stored_yet ->
         true
       ;
         nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',U),
         delete_ht(U,A,B)
       )
     ),
     store_type(A,multi_store(F))
   ).
validate_store_type_assumption___1__4(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   (
     chr_pp_flag(debugable,on),
     !,
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',F),
     delete_ht(F,A,E),
     ( var(B) ->
       true
     ;
       arg(2,B,G),
       setarg(2,B,removed),
       ( G==not_stored_yet ->
         true
       ;
         nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',H),
         delete_ht(H,A,B)
       )
     ),
     store_type(A,default)
   ;
     !,
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',I),
     delete_ht(I,A,E),
     ( var(B) ->
       true
     ;
       arg(2,B,J),
       setarg(2,B,removed),
       ( J==not_stored_yet ->
         true
       ;
         nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',K),
         delete_ht(K,A,B)
       )
     ),
     store_type(A,global_ground)
   ).
validate_store_type_assumption___1__4(A,B) :-
   ( var(B) ->
     true
   ;
     arg(2,B,C),
     setarg(2,B,removed),
     ( C==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',D),
       delete_ht(D,A,B)
     )
   ).
rule_count(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',B),
   (
     'chr sbag_member'(C,B),
     C=suspension(_,active,_,_),
     !
   ;
     !,
     rule_count___1__0__0__2(B,A)
   ).
rule_count___1__0__0__2([],A) :-
   rule_count___1__1(A).
rule_count___1__0__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_) ->
     setarg(2,B,removed),
     arg(3,B,D),
     ( var(D) ->
       nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',E),
       E=[_|F],
       b_setval('$chr_store_global_ground_chr_translate____rule_count___1',F),
       ( F=[G|_] ->
         setarg(3,G,_)
       ;
         true
       )
     ;
       D=[_,_|F],
       setarg(2,D,F),
       ( F=[G|_] ->
         setarg(3,G,D)
       ;
         true
       )
     ),
     rule_count___1__0__0__2(C,A)
   ;
     rule_count___1__0__0__2(C,A)
   ).
rule_count(A) :-
   rule_count___1__1(A).
rule_count___1__1(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____rule_count___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
inc_rule_count(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____rule_count___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   A is D+1,
   rule_count(A).
inc_rule_count(1) :-
   rule_count(1).
passive(A,B) :-
   passive___2__0(A,B,_).
passive___2__0(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
passive___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',D),
   lookup_ht(D,A,E),
   !,
   C=suspension(F,not_stored_yet,t,A,B),
   'chr gen_id'(F),
   passive___2__0__0__6(E,A,B,C).
passive___2__0__0__6([],A,B,C) :-
   passive___2__1(A,B,C).
passive___2__0__0__6([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G),
     F==A,
     G=[H|I],
     H==B,
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',J),
     lookup_ht(J,A,K),
     'chr sbag_member'(L,K),
     L=suspension(_,active,_,_,_,_) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',M),
     delete_ht(M,k(A,[B|I]),D),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',N),
     delete_ht(N,A,D),
     arg(2,C,O),
     setarg(2,C,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',P),
       insert_ht(P,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',Q),
       insert_ht(Q,k(A,B),C)
     ;
       true
     ),
     least_occurrence(A,I),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       passive___2__0__0__6(E,A,B,C)
     ;
       true
     )
   ;
     passive___2__0__0__6(E,A,B,C)
   ).
passive___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   passive___2__1(A,B,C).
passive___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',D),
   lookup_ht(D,k(A,B),E),
   !,
   passive___2__1__0__8(E,A,B,C).
passive___2__1__0__8([],A,B,C) :-
   passive___2__2(A,B,C).
passive___2__1__0__8([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,_),
     H==A,
     I==B,
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',J),
     lookup_ht(J,F,K) ->
     passive___2__1__1__8(K,F,G,D,E,A,B,C)
   ;
     passive___2__1__0__8(E,A,B,C)
   ).
passive___2__1__1__8([],_,_,_,A,B,C,D) :-
   passive___2__1__0__8(A,B,C,D).
passive___2__1__1__8([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,J,K,L),
     J==A,
     B<K,
     ground(A),
     ground(B),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',M),
     lookup_ht(M,k(A,B,yes),N),
     'chr sbag_member'(O,N),
     O=suspension(_,active,_,_,_) ->
     setarg(2,H,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',P),
     delete_ht(P,k(A,L),H),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',Q),
     delete_ht(Q,A,H),
     setarg(2,O,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',R),
     delete_ht(R,k(A,yes),O),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',S),
     delete_ht(S,k(A,B,yes),O),
     arg(2,G,T),
     setarg(2,G,active),
     ( T==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',U),
       insert_ht(U,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',V),
       insert_ht(V,k(E,F),G)
     ;
       true
     ),
     W is L-1,
     stored(A,B,maybe),
     stored_complete(A,K,W),
     ( G=suspension(_,active,_,_,_) ->
       setarg(2,G,inactive),
       passive___2__1__1__8(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     passive___2__1__1__8(I,A,B,C,D,E,F,G)
   ).
passive___2__1(A,B,C) :-
   passive___2__2(A,B,C).
passive___2__2(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',D),
   lookup_ht(D,A,E),
   !,
   passive___2__2__0__9(E,A,B,C).
passive___2__2__0__9([],A,B,C) :-
   passive___2__3(A,B,C).
passive___2__2__0__9([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G),
     F==A,
     H=t(251,D,C),
     '$novel_production'(D,H),
     '$novel_production'(C,H),
     G=pragma(rule(_,_,_,_),ids([B|J],I),_,_,A) ->
     '$extend_history'(C,H),
     arg(2,C,K),
     setarg(2,C,active),
     ( K==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',L),
       insert_ht(L,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',M),
       insert_ht(M,k(A,B),C)
     ;
       true
     ),
     append(J,I,N),
     check_all_passive(A,N),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       passive___2__2__0__9(E,A,B,C)
     ;
       true
     )
   ;
     passive___2__2__0__9(E,A,B,C)
   ).
passive___2__2(A,B,C) :-
   passive___2__3(A,B,C).
passive___2__3(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',D),
   lookup_ht(D,A,E),
   !,
   passive___2__3__0__10(E,A,B,C).
passive___2__3__0__10([],A,B,C) :-
   passive___2__4(A,B,C).
passive___2__3__0__10([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G),
     F==A,
     H=t(252,D,C),
     '$novel_production'(D,H),
     '$novel_production'(C,H),
     G=pragma(rule(_,_,_,_),ids([],[B|I]),_,_,A) ->
     '$extend_history'(C,H),
     arg(2,C,J),
     setarg(2,C,active),
     ( J==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',K),
       insert_ht(K,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',L),
       insert_ht(L,k(A,B),C)
     ;
       true
     ),
     check_all_passive(A,I),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       passive___2__3__0__10(E,A,B,C)
     ;
       true
     )
   ;
     passive___2__3__0__10(E,A,B,C)
   ).
passive___2__3(A,B,C) :-
   passive___2__4(A,B,C).
passive___2__4(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',D),
   lookup_ht(D,A,E),
   !,
   passive___2__4__0__11(E,A,B,C).
passive___2__4__0__11([],A,B,C) :-
   passive___2__5(A,B,C).
passive___2__4__0__11([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G),
     F==A,
     G=[H|I],
     H==B ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',J),
     delete_ht(J,k(A,[B|I]),D),
     nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',K),
     delete_ht(K,A,D),
     arg(2,C,L),
     setarg(2,C,active),
     ( L==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',M),
       insert_ht(M,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',N),
       insert_ht(N,k(A,B),C)
     ;
       true
     ),
     check_all_passive(A,I),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       passive___2__4__0__11(E,A,B,C)
     ;
       true
     )
   ;
     passive___2__4__0__11(E,A,B,C)
   ).
passive___2__4(A,B,C) :-
   passive___2__5(A,B,C).
passive___2__5(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',D),
   lookup_ht(D,k(A,B),E),
   !,
   passive___2__5__0__14(E,A,B,C).
passive___2__5__0__14([],A,B,C) :-
   passive___2__6(A,B,C).
passive___2__5__0__14([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,_),
     H==A,
     I==B,
     nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',J),
     lookup_ht(J,k(F,G),K) ->
     passive___2__5__1__14(K,F,G,D,E,A,B,C)
   ;
     passive___2__5__0__14(E,A,B,C)
   ).
passive___2__5__1__14([],_,_,_,A,B,C,D) :-
   passive___2__5__0__14(A,B,C,D).
passive___2__5__1__14([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,J,K),
     J==A,
     K==B,
     L=t(362,C,G,H),
     '$novel_production'(C,L),
     '$novel_production'(G,L),
     '$novel_production'(H,L),
     B>1 ->
     '$extend_history'(G,L),
     arg(2,G,M),
     setarg(2,G,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',N),
       insert_ht(N,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',O),
       insert_ht(O,k(E,F),G)
     ;
       true
     ),
     P is B-1,
     skip_to_next_id(A,P),
     ( G=suspension(_,active,_,_,_) ->
       setarg(2,G,inactive),
       passive___2__5__1__14(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     passive___2__5__1__14(I,A,B,C,D,E,F,G)
   ).
passive___2__5(A,B,C) :-
   passive___2__6(A,B,C).
passive___2__6(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',D),
   lookup_ht(D,k(A,B),E),
   !,
   passive___2__6__0__15(E,A,B,C).
passive___2__6__0__15([],A,B,C) :-
   passive___2__7(A,B,C).
passive___2__6__0__15([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,_),
     H==A,
     I==B,
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',J),
     lookup_ht(J,k(F,G),K) ->
     passive___2__6__1__15(K,F,G,D,E,A,B,C)
   ;
     passive___2__6__0__15(E,A,B,C)
   ).
passive___2__6__1__15([],_,_,_,A,B,C,D) :-
   passive___2__6__0__15(A,B,C,D).
passive___2__6__1__15([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,J,K,L),
     J==A,
     K==B ->
     setarg(2,H,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',M),
     delete_ht(M,k(A,B),H),
     arg(2,G,N),
     setarg(2,G,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',O),
       insert_ht(O,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',P),
       insert_ht(P,k(E,F),G)
     ;
       true
     ),
     occurrence_code_id(A,B,L),
     Q is B+1,
     set_occurrence_code_id(A,Q,L),
     ( G=suspension(_,active,_,_,_) ->
       setarg(2,G,inactive),
       passive___2__6__1__15(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     passive___2__6__1__15(I,A,B,C,D,E,F,G)
   ).
passive___2__6(A,B,C) :-
   passive___2__7(A,B,C).
passive___2__7(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',E),
     insert_ht(E,A,C),
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',F),
     insert_ht(F,k(A,B),C)
   ;
     true
   ).
is_passive(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
is_passive(_,_) :-
   fail.
any_passive_head(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_),
   !.
any_passive_head(_) :-
   fail.
new_occurrence(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',E),
   lookup_ht(E,A,F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,H),
   !,
   setarg(2,G,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',I),
   delete_ht(I,A,G),
   J is H+1,
   occurrence(A,J,B,C,D),
   max_occurrence(A,J).
new_occurrence(A,B,_,_) :-
   chr_error(internal,'new_occurrence: missing max_occurrence for ~w in rule ~w\n',[A,B]).
occurrence(A,B,C,D,E) :-
   occurrence___5__0(A,B,C,D,E,_).
occurrence___5__0(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',G),
   lookup_ht(G,C,H),
   !,
   F=suspension(I,not_stored_yet,t,_,A,B,C,D,E),
   'chr gen_id'(I),
   occurrence___5__0__0__4(H,A,B,C,D,E,F).
occurrence___5__0__0__4([],A,B,C,D,E,F) :-
   occurrence___5__1(A,B,C,D,E,F).
occurrence___5__0__0__4([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,I,J),
     I==C,
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',K),
     lookup_ht(K,k(A,B),L) ->
     occurrence___5__0__1__4(L,J,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__0__0__4(H,A,B,C,D,E,F)
   ).
occurrence___5__0__1__4([],_,_,A,B,C,D,E,F,G) :-
   occurrence___5__0__0__4(A,B,C,D,E,F,G).
occurrence___5__0__1__4([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,L,M),
     L==D,
     M==E,
     N=t(60,B,I,J),
     '$novel_production'(B,N),
     '$novel_production'(I,N),
     '$novel_production'(J,N) ->
     '$extend_history'(I,N),
     arg(2,I,O),
     setarg(2,I,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',P),
       insert_ht(P,k(D,H),I),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',Q),
       R=[I|Q],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',R),
       ( Q=[S|_] ->
         setarg(4,S,R)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',T),
       insert_ht(T,k(D,E,H),I),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',U),
       insert_ht(U,k(D,F,G),I),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',V),
       insert_ht(V,k(D,E),I),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',W),
       insert_ht(W,F,I),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',X),
       insert_ht(X,k(D,F),I),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',Y),
       insert_ht(Y,k(F,G),I),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',Z),
       insert_ht(Z,D,I)
     ;
       true
     ),
     \+is_passive(F,G),
     H==propagation,
     ( stored_in_guard_before_next_kept_occurrence(D,E) ->
       true
     ;
       ( A=pragma(rule([_|_],_,_,_),_,_,_,_) ->
         is_observed(D,E)
       )
     ;
       ( is_least_occurrence(F) ->
         is_observed(D,E)
       )
     ;
       true
     ),
     ( I=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,I,inactive),
       occurrence___5__0__1__4(K,A,B,C,D,E,F,G,H,I)
     ;
       true
     )
   ;
     occurrence___5__0__1__4(K,A,B,C,D,E,F,G,H,I)
   ).
occurrence___5__0(A,B,C,D,E,F) :-
   F=suspension(G,not_stored_yet,t,_,A,B,C,D,E),
   'chr gen_id'(G),
   occurrence___5__1(A,B,C,D,E,F).
occurrence___5__1(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',G),
   lookup_ht(G,C,H),
   !,
   occurrence___5__1__0__7(H,A,B,C,D,E,F).
occurrence___5__1__0__7([],A,B,C,D,E,F) :-
   occurrence___5__2(A,B,C,D,E,F).
occurrence___5__1__0__7([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J),
     I==C,
     J=[K|L],
     K==D,
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',M),
     lookup_ht(M,A,N),
     'chr sbag_member'(O,N),
     O=suspension(_,active,_,_,P),
     P>=B,
     ground(C),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',Q),
     lookup_ht(Q,C,R),
     'chr sbag_member'(S,R),
     S=suspension(_,active,_,_,_,_),
     \+may_trigger(A) ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',T),
     delete_ht(T,k(C,[D|L]),G),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',U),
     delete_ht(U,C,G),
     arg(2,F,V),
     setarg(2,F,active),
     ( V==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',W),
       insert_ht(W,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',X),
       Y=[F|X],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',Y),
       ( X=[Z|_] ->
         setarg(4,Z,Y)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',A1),
       insert_ht(A1,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',B1),
       insert_ht(B1,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',C1),
       insert_ht(C1,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D1),
       insert_ht(D1,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',E1),
       insert_ht(E1,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',F1),
       insert_ht(F1,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',G1),
       insert_ht(G1,A,F)
     ;
       true
     ),
     least_occurrence(C,L),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__1__0__7(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__1__0__7(H,A,B,C,D,E,F)
   ).
occurrence___5__1(A,B,C,D,E,F) :-
   occurrence___5__2(A,B,C,D,E,F).
occurrence___5__2(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',G),
   lookup_ht(G,C,H),
   !,
   occurrence___5__2__0__29(H,A,B,C,D,E,F).
occurrence___5__2__0__29([],A,B,C,D,E,F) :-
   occurrence___5__3(A,B,C,D,E,F).
occurrence___5__2__0__29([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,I),
     I==C,
     J=t(180,G,F),
     '$novel_production'(G,J),
     '$novel_production'(F,J) ->
     '$extend_history'(F,J),
     arg(2,F,K),
     setarg(2,F,active),
     ( K==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',L),
       insert_ht(L,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',M),
       N=[F|M],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',N),
       ( M=[O|_] ->
         setarg(4,O,N)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',P),
       insert_ht(P,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',Q),
       insert_ht(Q,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',R),
       insert_ht(R,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',S),
       insert_ht(S,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',T),
       insert_ht(T,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',U),
       insert_ht(U,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',V),
       insert_ht(V,A,F)
     ;
       true
     ),
     passive(C,D),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__2__0__29(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__2__0__29(H,A,B,C,D,E,F)
   ).
occurrence___5__2(A,B,C,D,E,F) :-
   occurrence___5__3(A,B,C,D,E,F).
occurrence___5__3(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',G),
   lookup_ht(G,C,H),
   !,
   occurrence___5__3__0__30(H,A,B,C,D,E,F).
occurrence___5__3__0__30([],A,B,C,D,E,F) :-
   occurrence___5__4(A,B,C,D,E,F).
occurrence___5__3__0__30([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,I,J),
     I==C,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',K),
     lookup_ht(K,k(A,C),L) ->
     occurrence___5__3__1__30(L,J,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__3__0__30(H,A,B,C,D,E,F)
   ).
occurrence___5__3__1__30([],_,_,A,B,C,D,E,F,G) :-
   occurrence___5__3__0__30(A,B,C,D,E,F,G).
occurrence___5__3__1__30([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,_,L,M,N,_,_),
     L==D,
     N==F,
     nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',O),
     lookup_ht(O,F,P) ->
     occurrence___5__3__2__30(P,M,J,K,A,B,C,D,E,F,G,H,I)
   ;
     occurrence___5__3__1__30(K,A,B,C,D,E,F,G,H,I)
   ).
occurrence___5__3__2__30([],_,_,A,B,C,D,E,F,G,H,I,J) :-
   occurrence___5__3__1__30(A,B,C,D,E,F,G,H,I,J).
occurrence___5__3__2__30([M|N],A,B,C,D,E,F,G,H,I,J,K,L) :-
   ( M=suspension(_,active,_,_,O,_,_,_,_,_),
     O==I,
     nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',P) ->
     occurrence___5__3__3__30(P,M,N,A,B,C,D,E,F,G,H,I,J,K,L)
   ;
     occurrence___5__3__2__30(N,A,B,C,D,E,F,G,H,I,J,K,L)
   ).
occurrence___5__3__3__30([],_,A,B,C,D,E,F,G,H,I,J,K,L,M) :-
   occurrence___5__3__2__30(A,B,C,D,E,F,G,H,I,J,K,L,M).
occurrence___5__3__3__30([O|P],A,B,C,D,E,F,G,H,I,J,K,L,M,N) :-
   ( O=suspension(_,active,_,Q),
     J<C,
     chr_pp_flag(occurrence_subsumption,on),
     F=pragma(rule(R,_,_,_),_,_,_,_),
     R\==[],
     \+tree_set_memberchk(I,Q) ->
     setarg(2,O,removed),
     arg(3,O,S),
     ( var(S) ->
       nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',T),
       T=[_|U],
       b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',U),
       ( U=[V|_] ->
         setarg(3,V,_)
       ;
         true
       )
     ;
       S=[_,_|U],
       setarg(2,S,U),
       ( U=[V|_] ->
         setarg(3,V,S)
       ;
         true
       )
     ),
     arg(2,N,W),
     setarg(2,N,active),
     ( W==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',X),
       insert_ht(X,k(I,M),N),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',Y),
       Z=[N|Y],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',Z),
       ( Y=[A1|_] ->
         setarg(4,A1,Z)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',B1),
       insert_ht(B1,k(I,J,M),N),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',C1),
       insert_ht(C1,k(I,K,L),N),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D1),
       insert_ht(D1,k(I,J),N),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',E1),
       insert_ht(E1,K,N),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',F1),
       insert_ht(F1,k(I,K),N),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',G1),
       insert_ht(G1,k(K,L),N),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',H1),
       insert_ht(H1,I,N)
     ;
       true
     ),
     first_occ_in_rule(K,I,J,L),
     tree_set_add(Q,I,I1),
     multiple_occ_constraints_checked(I1),
     ( N=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,N,inactive),
       occurrence___5__3__3__30(P,A,B,C,D,E,F,G,H,I,J,K,L,M,N)
     ;
       true
     )
   ;
     occurrence___5__3__3__30(P,A,B,C,D,E,F,G,H,I,J,K,L,M,N)
   ).
occurrence___5__3(A,B,C,D,E,F) :-
   occurrence___5__4(A,B,C,D,E,F).
occurrence___5__4(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',G),
   lookup_ht(G,C,H),
   !,
   occurrence___5__4__0__31(H,A,B,C,D,E,F).
occurrence___5__4__0__31([],A,B,C,D,E,F) :-
   occurrence___5__5(A,B,C,D,E,F).
occurrence___5__4__0__31([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,I,J),
     I==C,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',K),
     lookup_ht(K,k(A,C),L) ->
     occurrence___5__4__1__31(L,J,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__4__0__31(H,A,B,C,D,E,F)
   ).
occurrence___5__4__1__31([],_,_,A,B,C,D,E,F,G) :-
   occurrence___5__4__0__31(A,B,C,D,E,F,G).
occurrence___5__4__1__31([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,_,L,M,N,O,_),
     L==D,
     N==F,
     nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',P),
     lookup_ht(P,F,Q) ->
     occurrence___5__4__2__31(Q,M,O,J,K,A,B,C,D,E,F,G,H,I)
   ;
     occurrence___5__4__1__31(K,A,B,C,D,E,F,G,H,I)
   ).
occurrence___5__4__2__31([],_,_,_,A,B,C,D,E,F,G,H,I,J) :-
   occurrence___5__4__1__31(A,B,C,D,E,F,G,H,I,J).
occurrence___5__4__2__31([N|O],A,B,C,D,E,F,G,H,I,J,K,L,M) :-
   ( N=suspension(_,active,_,_,P,_,_,_,_,_),
     P==J,
     nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',Q) ->
     occurrence___5__4__3__31(Q,N,O,A,B,C,D,E,F,G,H,I,J,K,L,M)
   ;
     occurrence___5__4__2__31(O,A,B,C,D,E,F,G,H,I,J,K,L,M)
   ).
occurrence___5__4__3__31([],_,A,B,C,D,E,F,G,H,I,J,K,L,M,N) :-
   occurrence___5__4__2__31(A,B,C,D,E,F,G,H,I,J,K,L,M,N).
occurrence___5__4__3__31([P|Q],A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) :-
   ( P=suspension(_,active,_,R),
     C<K,
     chr_pp_flag(occurrence_subsumption,on),
     G=pragma(rule(S,_,_,_),_,_,_,_),
     S\==[],
     \+tree_set_memberchk(J,R) ->
     setarg(2,P,removed),
     arg(3,P,T),
     ( var(T) ->
       nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',U),
       U=[_|V],
       b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',V),
       ( V=[W|_] ->
         setarg(3,W,_)
       ;
         true
       )
     ;
       T=[_,_|V],
       setarg(2,T,V),
       ( V=[W|_] ->
         setarg(3,W,T)
       ;
         true
       )
     ),
     arg(2,O,X),
     setarg(2,O,active),
     ( X==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',Y),
       insert_ht(Y,k(J,N),O),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',Z),
       A1=[O|Z],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',A1),
       ( Z=[B1|_] ->
         setarg(4,B1,A1)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',C1),
       insert_ht(C1,k(J,K,N),O),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',D1),
       insert_ht(D1,k(J,L,M),O),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',E1),
       insert_ht(E1,k(J,K),O),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',F1),
       insert_ht(F1,L,O),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',G1),
       insert_ht(G1,k(J,L),O),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',H1),
       insert_ht(H1,k(L,M),O),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',I1),
       insert_ht(I1,J,O)
     ;
       true
     ),
     first_occ_in_rule(L,J,C,D),
     tree_set_add(R,J,J1),
     multiple_occ_constraints_checked(J1),
     ( O=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,O,inactive),
       occurrence___5__4__3__31(Q,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O)
     ;
       true
     )
   ;
     occurrence___5__4__3__31(Q,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O)
   ).
occurrence___5__4(A,B,C,D,E,F) :-
   occurrence___5__5(A,B,C,D,E,F).
occurrence___5__5(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',G),
   lookup_ht(G,k(A,B,yes),H),
   !,
   occurrence___5__5__0__35(H,A,B,C,D,E,F).
occurrence___5__5__0__35([],A,B,C,D,E,F) :-
   occurrence___5__6(A,B,C,D,E,F).
occurrence___5__5__0__35([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J,K),
     I==A,
     J==B,
     K=yes,
     ground(C),
     ground(D),
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',L),
     lookup_ht(L,k(C,D),M),
     'chr sbag_member'(N,M),
     N=suspension(_,active,_,_,_),
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',O),
     lookup_ht(O,A,P),
     'chr sbag_member'(Q,P),
     Q=suspension(_,active,_,_,R,S),
     B<R ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',T),
     delete_ht(T,k(A,yes),G),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',U),
     delete_ht(U,k(A,B,yes),G),
     setarg(2,Q,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',V),
     delete_ht(V,k(A,S),Q),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',W),
     delete_ht(W,A,Q),
     arg(2,F,X),
     setarg(2,F,active),
     ( X==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',Y),
       insert_ht(Y,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',Z),
       A1=[F|Z],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',A1),
       ( Z=[B1|_] ->
         setarg(4,B1,A1)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',C1),
       insert_ht(C1,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',D1),
       insert_ht(D1,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',E1),
       insert_ht(E1,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',F1),
       insert_ht(F1,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',G1),
       insert_ht(G1,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',H1),
       insert_ht(H1,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',I1),
       insert_ht(I1,A,F)
     ;
       true
     ),
     J1 is S-1,
     stored(A,B,maybe),
     stored_complete(A,R,J1),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__5__0__35(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__5__0__35(H,A,B,C,D,E,F)
   ).
occurrence___5__5(A,B,C,D,E,F) :-
   occurrence___5__6(A,B,C,D,E,F).
occurrence___5__6(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',G),
   lookup_ht(G,C,H),
   !,
   occurrence___5__6__0__36(H,A,B,C,D,E,F).
occurrence___5__6__0__36([],A,B,C,D,E,F) :-
   occurrence___5__7(A,B,C,D,E,F).
occurrence___5__6__0__36([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,I,_,J,_,_),
     J==C,
     nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',K),
     lookup_ht(K,I,L) ->
     occurrence___5__6__1__36(L,I,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__6__0__36(H,A,B,C,D,E,F)
   ).
occurrence___5__6__1__36([],_,_,A,B,C,D,E,F,G) :-
   occurrence___5__6__0__36(A,B,C,D,E,F,G).
occurrence___5__6__1__36([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,L,M),
     L==A,
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',N),
     lookup_ht(N,k(A,0),O) ->
     occurrence___5__6__2__36(O,M,J,K,A,B,C,D,E,F,G,H,I)
   ;
     occurrence___5__6__1__36(K,A,B,C,D,E,F,G,H,I)
   ).
occurrence___5__6__2__36([],_,_,A,B,C,D,E,F,G,H,I,J) :-
   occurrence___5__6__1__36(A,B,C,D,E,F,G,H,I,J).
occurrence___5__6__2__36([M|N],A,B,C,D,E,F,G,H,I,J,K,L) :-
   ( M=suspension(_,active,_,O,P,Q),
     O==D,
     Q=0,
     R=t(250,L,E,M,B),
     '$novel_production'(L,R),
     '$novel_production'(E,R),
     '$novel_production'(M,R),
     '$novel_production'(B,R),
     P=<A ->
     '$extend_history'(L,R),
     arg(2,L,S),
     setarg(2,L,active),
     ( S==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',T),
       insert_ht(T,k(G,K),L),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',U),
       V=[L|U],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',V),
       ( U=[W|_] ->
         setarg(4,W,V)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',X),
       insert_ht(X,k(G,H,K),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',Y),
       insert_ht(Y,k(G,I,J),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',Z),
       insert_ht(Z,k(G,H),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',A1),
       insert_ht(A1,I,L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',B1),
       insert_ht(B1,k(G,I),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',C1),
       insert_ht(C1,k(I,J),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D1),
       insert_ht(D1,G,L)
     ;
       true
     ),
     passive(I,J),
     ( L=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,L,inactive),
       occurrence___5__6__2__36(N,A,B,C,D,E,F,G,H,I,J,K,L)
     ;
       true
     )
   ;
     occurrence___5__6__2__36(N,A,B,C,D,E,F,G,H,I,J,K,L)
   ).
occurrence___5__6(A,B,C,D,E,F) :-
   occurrence___5__7(A,B,C,D,E,F).
occurrence___5__7(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',G),
   lookup_ht(G,C,H),
   !,
   occurrence___5__7__0__37(H,A,B,C,D,E,F).
occurrence___5__7__0__37([],A,B,C,D,E,F) :-
   occurrence___5__8(A,B,C,D,E,F).
occurrence___5__7__0__37([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,_,_,I,J,_),
     I==C,
     nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',K),
     lookup_ht(K,A,L) ->
     occurrence___5__7__1__37(L,J,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__7__0__37(H,A,B,C,D,E,F)
   ).
occurrence___5__7__1__37([],_,_,A,B,C,D,E,F,G) :-
   occurrence___5__7__0__37(A,B,C,D,E,F,G).
occurrence___5__7__1__37([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,L,M),
     L==D,
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',N),
     lookup_ht(N,k(D,0),O) ->
     occurrence___5__7__2__37(O,M,J,K,A,B,C,D,E,F,G,H,I)
   ;
     occurrence___5__7__1__37(K,A,B,C,D,E,F,G,H,I)
   ).
occurrence___5__7__2__37([],_,_,A,B,C,D,E,F,G,H,I,J) :-
   occurrence___5__7__1__37(A,B,C,D,E,F,G,H,I,J).
occurrence___5__7__2__37([M|N],A,B,C,D,E,F,G,H,I,J,K,L) :-
   ( M=suspension(_,active,_,O,P,Q),
     O==G,
     Q=0,
     R=t(250,E,L,M,B),
     '$novel_production'(E,R),
     '$novel_production'(L,R),
     '$novel_production'(M,R),
     '$novel_production'(B,R),
     P=<A ->
     '$extend_history'(L,R),
     arg(2,L,S),
     setarg(2,L,active),
     ( S==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',T),
       insert_ht(T,k(G,K),L),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',U),
       V=[L|U],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',V),
       ( U=[W|_] ->
         setarg(4,W,V)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',X),
       insert_ht(X,k(G,H,K),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',Y),
       insert_ht(Y,k(G,I,J),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',Z),
       insert_ht(Z,k(G,H),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',A1),
       insert_ht(A1,I,L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',B1),
       insert_ht(B1,k(G,I),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',C1),
       insert_ht(C1,k(I,J),L),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D1),
       insert_ht(D1,G,L)
     ;
       true
     ),
     passive(I,D),
     ( L=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,L,inactive),
       occurrence___5__7__2__37(N,A,B,C,D,E,F,G,H,I,J,K,L)
     ;
       true
     )
   ;
     occurrence___5__7__2__37(N,A,B,C,D,E,F,G,H,I,J,K,L)
   ).
occurrence___5__7(A,B,C,D,E,F) :-
   occurrence___5__8(A,B,C,D,E,F).
occurrence___5__8(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',G),
   lookup_ht(G,A,H),
   !,
   occurrence___5__8__0__38(H,A,B,C,D,E,F).
occurrence___5__8__0__38([],A,B,C,D,E,F) :-
   occurrence___5__9(A,B,C,D,E,F).
occurrence___5__8__0__38([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,I,J,_),
     I==A,
     K=t(259,G,F),
     '$novel_production'(G,K),
     '$novel_production'(F,K),
     B>J ->
     '$extend_history'(F,K),
     arg(2,F,L),
     setarg(2,F,active),
     ( L==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',M),
       insert_ht(M,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',N),
       O=[F|N],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',O),
       ( N=[P|_] ->
         setarg(4,P,O)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',Q),
       insert_ht(Q,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',R),
       insert_ht(R,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',S),
       insert_ht(S,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',T),
       insert_ht(T,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',U),
       insert_ht(U,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',V),
       insert_ht(V,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',W),
       insert_ht(W,A,F)
     ;
       true
     ),
     passive(C,D),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__8__0__38(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__8__0__38(H,A,B,C,D,E,F)
   ).
occurrence___5__8(A,B,C,D,E,F) :-
   occurrence___5__9(A,B,C,D,E,F).
occurrence___5__9(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',G),
   lookup_ht(G,k(A,C),H),
   !,
   occurrence___5__9__0__42(H,A,B,C,D,E,F).
occurrence___5__9__0__42([],A,B,C,D,E,F) :-
   occurrence___5__10(A,B,C,D,E,F).
occurrence___5__9__0__42([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J,K,L),
     I==A,
     J==C,
     C>1,
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',M),
     lookup_ht(M,A,N),
     'chr sbag_member'(O,N),
     O=suspension(_,active,_,_,P),
     P>B ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',Q),
     delete_ht(Q,A,G),
     nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',R),
     delete_ht(R,k(A,C),G),
     arg(2,F,S),
     setarg(2,F,active),
     ( S==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',T),
       insert_ht(T,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',U),
       V=[F|U],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',V),
       ( U=[W|_] ->
         setarg(4,W,V)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',X),
       insert_ht(X,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',Y),
       insert_ht(Y,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',Z),
       insert_ht(Z,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',A1),
       insert_ht(A1,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',B1),
       insert_ht(B1,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',C1),
       insert_ht(C1,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D1),
       insert_ht(D1,A,F)
     ;
       true
     ),
     functional_dependency(A,1,K,L),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__9__0__42(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__9__0__42(H,A,B,C,D,E,F)
   ).
occurrence___5__9(A,B,C,D,E,F) :-
   occurrence___5__10(A,B,C,D,E,F).
occurrence___5__10(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',G),
   lookup_ht(G,A,H),
   !,
   occurrence___5__10__0__48(H,A,B,C,D,E,F).
occurrence___5__10__0__48([],A,B,C,D,E,F) :-
   occurrence___5__11(A,B,C,D,E,F).
occurrence___5__10__0__48([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,I,J),
     I==A,
     nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',K) ->
     occurrence___5__10__1__48(K,J,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__10__0__48(H,A,B,C,D,E,F)
   ).
occurrence___5__10__1__48([],_,_,A,B,C,D,E,F,G) :-
   occurrence___5__10__0__48(A,B,C,D,E,F,G).
occurrence___5__10__1__48([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,_),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',L),
     lookup_ht(L,F,M) ->
     occurrence___5__10__2__48(M,J,K,A,B,C,D,E,F,G,H,I)
   ;
     occurrence___5__10__1__48(K,A,B,C,D,E,F,G,H,I)
   ).
occurrence___5__10__2__48([],_,A,B,C,D,E,F,G,H,I,J) :-
   occurrence___5__10__1__48(A,B,C,D,E,F,G,H,I,J).
occurrence___5__10__2__48([L|M],A,B,C,D,E,F,G,H,I,J,K) :-
   ( L=suspension(_,active,_,_,N,O),
     N==H,
     P=t(330,A,K,L,D),
     '$novel_production'(A,P),
     '$novel_production'(K,P),
     '$novel_production'(L,P),
     '$novel_production'(D,P) ->
     '$extend_history'(K,P),
     arg(2,K,Q),
     setarg(2,K,active),
     ( Q==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',R),
       insert_ht(R,k(F,J),K),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',S),
       T=[K|S],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',T),
       ( S=[U|_] ->
         setarg(4,U,T)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',V),
       insert_ht(V,k(F,G,J),K),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',W),
       insert_ht(W,k(F,H,I),K),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',X),
       insert_ht(X,k(F,G),K),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',Y),
       insert_ht(Y,H,K),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',Z),
       insert_ht(Z,k(F,H),K),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',A1),
       insert_ht(A1,k(H,I),K),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',B1),
       insert_ht(B1,F,K)
     ;
       true
     ),
     O=pragma(rule(C1,D1,E1,_),_,_,_,_),
     ( is_passive(H,I) ->
       true
     ;
       ( J==simplification ->
         select(F1,C1,_),
         F1=..[_|G1],
         term_variables(E1,H1),
         partial_wake_args(G1,C,H1,F)
       )
     ;
       select(F1,D1,_),
       F1=..[_|G1],
       term_variables(E1,H1),
       partial_wake_args(G1,C,H1,F)
     ),
     ( K=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,K,inactive),
       occurrence___5__10__2__48(M,A,B,C,D,E,F,G,H,I,J,K)
     ;
       true
     )
   ;
     occurrence___5__10__2__48(M,A,B,C,D,E,F,G,H,I,J,K)
   ).
occurrence___5__10(A,B,C,D,E,F) :-
   occurrence___5__11(A,B,C,D,E,F).
occurrence___5__11(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',G),
   lookup_ht(G,k(C,D),H),
   !,
   occurrence___5__11__0__50(H,A,B,C,D,E,F).
occurrence___5__11__0__50([],A,B,C,D,E,F) :-
   occurrence___5__12(A,B,C,D,E,F).
occurrence___5__11__0__50([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,I,J),
     I==C,
     J==D,
     nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',K),
     lookup_ht(K,k(A,B),L) ->
     occurrence___5__11__1__50(L,G,H,A,B,C,D,E,F)
   ;
     occurrence___5__11__0__50(H,A,B,C,D,E,F)
   ).
occurrence___5__11__1__50([],_,A,B,C,D,E,F,G) :-
   occurrence___5__11__0__50(A,B,C,D,E,F,G).
occurrence___5__11__1__50([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,K,L),
     K==C,
     L==D,
     M=t(362,H,A,I),
     '$novel_production'(H,M),
     '$novel_production'(A,M),
     '$novel_production'(I,M),
     D>1 ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',O),
       insert_ht(O,k(C,G),H),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',P),
       Q=[H|P],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',Q),
       ( P=[R|_] ->
         setarg(4,R,Q)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',S),
       insert_ht(S,k(C,D,G),H),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',T),
       insert_ht(T,k(C,E,F),H),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',U),
       insert_ht(U,k(C,D),H),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',V),
       insert_ht(V,E,H),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',W),
       insert_ht(W,k(C,E),H),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',X),
       insert_ht(X,k(E,F),H),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',Y),
       insert_ht(Y,C,H)
     ;
       true
     ),
     Z is D-1,
     skip_to_next_id(C,Z),
     ( H=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,H,inactive),
       occurrence___5__11__1__50(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     occurrence___5__11__1__50(J,A,B,C,D,E,F,G,H)
   ).
occurrence___5__11(A,B,C,D,E,F) :-
   occurrence___5__12(A,B,C,D,E,F).
occurrence___5__12(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',G),
   lookup_ht(G,k(A,B),H),
   !,
   occurrence___5__12__0__51(H,A,B,C,D,E,F).
occurrence___5__12__0__51([],A,B,C,D,E,F) :-
   occurrence___5__13(A,B,C,D,E,F).
occurrence___5__12__0__51([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J,K),
     I==A,
     J==B,
     ground(C),
     ground(D),
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',L),
     lookup_ht(L,k(C,D),M),
     'chr sbag_member'(N,M),
     N=suspension(_,active,_,_,_) ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',O),
     delete_ht(O,k(A,B),G),
     arg(2,F,P),
     setarg(2,F,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',Q),
       insert_ht(Q,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',R),
       S=[F|R],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',S),
       ( R=[T|_] ->
         setarg(4,T,S)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',U),
       insert_ht(U,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',V),
       insert_ht(V,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',W),
       insert_ht(W,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',X),
       insert_ht(X,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',Y),
       insert_ht(Y,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',Z),
       insert_ht(Z,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',A1),
       insert_ht(A1,A,F)
     ;
       true
     ),
     occurrence_code_id(A,B,K),
     B1 is B+1,
     set_occurrence_code_id(A,B1,K),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__12__0__51(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__12__0__51(H,A,B,C,D,E,F)
   ).
occurrence___5__12(A,B,C,D,E,F) :-
   occurrence___5__13(A,B,C,D,E,F).
occurrence___5__13(A,B,C,D,simplification,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',F),
   lookup_ht(F,k(A,B),G),
   !,
   occurrence___5__13__0__52(G,A,B,C,D,simplification,E).
occurrence___5__13__0__52([],A,B,C,D,E,F) :-
   occurrence___5__15(A,B,C,D,E,F).
occurrence___5__13__0__52([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J,K),
     I==A,
     J==B ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',L),
     delete_ht(L,k(A,B),G),
     arg(2,F,M),
     setarg(2,F,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',N),
       insert_ht(N,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',O),
       P=[F|O],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',P),
       ( O=[Q|_] ->
         setarg(4,Q,P)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',R),
       insert_ht(R,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',S),
       insert_ht(S,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',T),
       insert_ht(T,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',U),
       insert_ht(U,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',V),
       insert_ht(V,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',W),
       insert_ht(W,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',X),
       insert_ht(X,A,F)
     ;
       true
     ),
     occurrence_code_id(A,B,K),
     Y is B+1,
     set_occurrence_code_id(A,Y,K),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__13__0__52(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__13__0__52(H,A,B,C,D,E,F)
   ).
occurrence___5__13(A,B,C,D,propagation,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',F),
   lookup_ht(F,k(A,B),G),
   !,
   occurrence___5__13__0__53(G,A,B,C,D,propagation,E).
occurrence___5__13__0__53([],A,B,C,D,E,F) :-
   occurrence___5__14(A,B,C,D,E,F).
occurrence___5__13__0__53([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J,K),
     I==A,
     J==B,
     ground(A),
     ground(B),
     nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',L),
     lookup_ht(L,k(A,B),M),
     'chr sbag_member'(N,M),
     N=suspension(_,active,_,_,_) ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',O),
     delete_ht(O,k(A,B),G),
     arg(2,F,P),
     setarg(2,F,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',Q),
       insert_ht(Q,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',R),
       S=[F|R],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',S),
       ( R=[T|_] ->
         setarg(4,T,S)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',U),
       insert_ht(U,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',V),
       insert_ht(V,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',W),
       insert_ht(W,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',X),
       insert_ht(X,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',Y),
       insert_ht(Y,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',Z),
       insert_ht(Z,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',A1),
       insert_ht(A1,A,F)
     ;
       true
     ),
     occurrence_code_id(A,B,K),
     B1 is B+1,
     C1 is K+1,
     set_occurrence_code_id(A,B1,C1),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__13__0__53(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__13__0__53(H,A,B,C,D,E,F)
   ).
occurrence___5__13(A,B,C,D,E,F) :-
   occurrence___5__14(A,B,C,D,E,F).
occurrence___5__14(A,B,C,D,propagation,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',F),
   lookup_ht(F,k(A,B),G),
   !,
   occurrence___5__14__0__54(G,A,B,C,D,propagation,E).
occurrence___5__14__0__54([],A,B,C,D,E,F) :-
   occurrence___5__15(A,B,C,D,E,F).
occurrence___5__14__0__54([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,I,J,K),
     I==A,
     J==B ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',L),
     delete_ht(L,k(A,B),G),
     arg(2,F,M),
     setarg(2,F,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',N),
       insert_ht(N,k(A,E),F),
       nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',O),
       P=[F|O],
       b_setval('$chr_store_global_ground_chr_translate____occurrence___5',P),
       ( O=[Q|_] ->
         setarg(4,Q,P)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',R),
       insert_ht(R,k(A,B,E),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',S),
       insert_ht(S,k(A,C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',T),
       insert_ht(T,k(A,B),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',U),
       insert_ht(U,C,F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',V),
       insert_ht(V,k(A,C),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',W),
       insert_ht(W,k(C,D),F),
       nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',X),
       insert_ht(X,A,F)
     ;
       true
     ),
     occurrence_code_id(A,B,K),
     Y is B+1,
     set_occurrence_code_id(A,Y,K),
     ( F=suspension(_,active,_,_,_,_,_,_,_) ->
       setarg(2,F,inactive),
       occurrence___5__14__0__54(H,A,B,C,D,E,F)
     ;
       true
     )
   ;
     occurrence___5__14__0__54(H,A,B,C,D,E,F)
   ).
occurrence___5__14(A,B,C,D,E,F) :-
   occurrence___5__15(A,B,C,D,E,F).
occurrence___5__15(A,B,C,D,E,F) :-
   arg(2,F,G),
   setarg(2,F,active),
   ( G==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',H),
     insert_ht(H,k(A,E),F),
     nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',I),
     J=[F|I],
     b_setval('$chr_store_global_ground_chr_translate____occurrence___5',J),
     ( I=[K|_] ->
       setarg(4,K,J)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',L),
     insert_ht(L,k(A,B,E),F),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',M),
     insert_ht(M,k(A,C,D),F),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',N),
     insert_ht(N,k(A,B),F),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',O),
     insert_ht(O,C,F),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',P),
     insert_ht(P,k(A,C),F),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',Q),
     insert_ht(Q,k(C,D),F),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',R),
     insert_ht(R,A,F)
   ;
     true
   ).
get_occurrence(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',E),
   lookup_ht(E,k(A,B),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,_,_,H,I,_),
   !,
   H=C,
   I=D.
get_occurrence(A,B,_,_) :-
   chr_error(internal,'get_occurrence: missing occurrence ~w:~w\n',[A,B]).
get_occurrence(A,B,C,D,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',F),
   lookup_ht(F,k(A,B),G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,_,_,_,I,J,K),
   !,
   I=C,
   J=D,
   K=E.
get_occurrence(A,B,_,_,_) :-
   chr_error(internal,'get_occurrence: missing occurrence ~w:~w\n',[A,B]).
get_occurrence_from_id(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',E),
   lookup_ht(E,k(C,D),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,H,I,_,_,_),
   !,
   A=H,
   B=I.
get_occurrence_from_id(_,_,_,_) :-
   chr_error(internal,'get_occurrence_from_id: missing occurrence ~w:~w\n',[]).
max_occurrence(A,B) :-
   max_occurrence___2__0(A,B,_).
max_occurrence___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',D),
   lookup_ht(D,A,E),
   (
     'chr sbag_member'(F,E),
     F=suspension(_,active,_,_,G),
     G>=B,
     !
   ;
     !,
     max_occurrence___2__0__0__2(E,A,B,C)
   ).
max_occurrence___2__0__0__2([],A,B,C) :-
   max_occurrence___2__1(A,B,C).
max_occurrence___2__0__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==A,
     B>=G ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',H),
     delete_ht(H,A,D),
     max_occurrence___2__0__0__2(E,A,B,C)
   ;
     max_occurrence___2__0__0__2(E,A,B,C)
   ).
max_occurrence___2__0(A,B,C) :-
   max_occurrence___2__1(A,B,C).
max_occurrence___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',D),
   lookup_ht(D,k(A,0),E),
   !,
   C=suspension(F,not_stored_yet,t,A,B),
   'chr gen_id'(F),
   max_occurrence___2__1__0__5(E,A,B,C).
max_occurrence___2__1__0__5([],A,B,C) :-
   max_occurrence___2__2(A,B,C).
max_occurrence___2__1__0__5([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G,H),
     F==A,
     H=0,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',I),
     lookup_ht(I,A,J) ->
     max_occurrence___2__1__1__5(J,G,D,E,A,B,C)
   ;
     max_occurrence___2__1__0__5(E,A,B,C)
   ).
max_occurrence___2__1__1__5([],_,_,A,B,C,D) :-
   max_occurrence___2__1__0__5(A,B,C,D).
max_occurrence___2__1__1__5([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,_,I,_,J,_,_),
     I==D,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',K),
     lookup_ht(K,J,L) ->
     max_occurrence___2__1__2__5(L,J,G,H,A,B,C,D,E,F)
   ;
     max_occurrence___2__1__1__5(H,A,B,C,D,E,F)
   ).
max_occurrence___2__1__2__5([],_,_,A,B,C,D,E,F,G) :-
   max_occurrence___2__1__1__5(A,B,C,D,E,F,G).
max_occurrence___2__1__2__5([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,_,_,_,L,M,_),
     J\==B,
     L==A,
     N=t(250,J,B,E,I),
     '$novel_production'(J,N),
     '$novel_production'(B,N),
     '$novel_production'(E,N),
     '$novel_production'(I,N),
     D=<H ->
     '$extend_history'(I,N),
     arg(2,I,O),
     setarg(2,I,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',P),
       insert_ht(P,G,I)
     ;
       true
     ),
     passive(A,M),
     ( I=suspension(_,active,_,_,_) ->
       setarg(2,I,inactive),
       max_occurrence___2__1__2__5(K,A,B,C,D,E,F,G,H,I)
     ;
       true
     )
   ;
     max_occurrence___2__1__2__5(K,A,B,C,D,E,F,G,H,I)
   ).
max_occurrence___2__1(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   max_occurrence___2__2(A,B,C).
max_occurrence___2__2(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',D),
     insert_ht(D,A,B)
   ;
     true
   ).
get_max_occurrence(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,F),
   !,
   B=F.
get_max_occurrence(A,_) :-
   chr_error(internal,'get_max_occurrence: missing max occurrence for ~w\n',[A]).
allocation_occurrence(A,B) :-
   allocation_occurrence___2__0(A,B,_).
allocation_occurrence___2__0(A,0,B) :-
   !,
   B=suspension(C,active,t,A,0),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',D),
   insert_ht(D,A,B),
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',E),
   insert_ht(E,k(A,0),B),
   stored_in_guard_before_next_kept_occurrence(A,0),
   ( B=suspension(_,active,_,_,_) ->
     setarg(2,B,inactive),
     allocation_occurrence___2__1(A,0,B)
   ;
     true
   ).
allocation_occurrence___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   allocation_occurrence___2__1(A,B,C).
allocation_occurrence___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(A,B),E),
   !,
   allocation_occurrence___2__1__0__2(E,A,B,C).
allocation_occurrence___2__1__0__2([],A,B,C) :-
   allocation_occurrence___2__2(A,B,C).
allocation_occurrence___2__1__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,J),
     F==A,
     G==B,
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',K),
     lookup_ht(K,H,L) ->
     allocation_occurrence___2__1__1__2(L,H,I,J,D,E,A,B,C)
   ;
     allocation_occurrence___2__1__0__2(E,A,B,C)
   ).
allocation_occurrence___2__1__1__2([],_,_,_,_,A,B,C,D) :-
   allocation_occurrence___2__1__0__2(A,B,C,D).
allocation_occurrence___2__1__1__2([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_,K,L),
     K==A,
     M=t(60,I,D,H),
     '$novel_production'(I,M),
     '$novel_production'(D,M),
     '$novel_production'(H,M) ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',O),
       insert_ht(O,F,H),
       nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',P),
       insert_ht(P,k(F,G),H)
     ;
       true
     ),
     \+is_passive(A,B),
     C==propagation,
     ( stored_in_guard_before_next_kept_occurrence(F,G) ->
       true
     ;
       ( L=pragma(rule([_|_],_,_,_),_,_,_,_) ->
         is_observed(F,G)
       )
     ;
       ( is_least_occurrence(A) ->
         is_observed(F,G)
       )
     ;
       true
     ),
     ( H=suspension(_,active,_,_,_) ->
       setarg(2,H,inactive),
       allocation_occurrence___2__1__1__2(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     allocation_occurrence___2__1__1__2(J,A,B,C,D,E,F,G,H)
   ).
allocation_occurrence___2__1(A,B,C) :-
   allocation_occurrence___2__2(A,B,C).
allocation_occurrence___2__2(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D),
   lookup_ht(D,A,E),
   !,
   allocation_occurrence___2__2__0__3(E,A,B,C).
allocation_occurrence___2__2__0__3([],A,B,C) :-
   allocation_occurrence___2__3(A,B,C).
allocation_occurrence___2__2__0__3([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,_),
     F==A,
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',J),
     lookup_ht(J,H,K) ->
     allocation_occurrence___2__2__1__3(K,G,H,I,D,E,A,B,C)
   ;
     allocation_occurrence___2__2__0__3(E,A,B,C)
   ).
allocation_occurrence___2__2__1__3([],_,_,_,_,A,B,C,D) :-
   allocation_occurrence___2__2__0__3(A,B,C,D).
allocation_occurrence___2__2__1__3([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,K,L),
     K==B,
     L=[M|N],
     M==C,
     G>=A,
     ground(B),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',O),
     lookup_ht(O,B,P),
     'chr sbag_member'(Q,P),
     Q=suspension(_,active,_,_,_,_),
     \+may_trigger(F) ->
     setarg(2,I,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',R),
     delete_ht(R,k(B,[C|N]),I),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',S),
     delete_ht(S,B,I),
     arg(2,H,T),
     setarg(2,H,active),
     ( T==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',U),
       insert_ht(U,F,H),
       nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',V),
       insert_ht(V,k(F,G),H)
     ;
       true
     ),
     least_occurrence(B,N),
     ( H=suspension(_,active,_,_,_) ->
       setarg(2,H,inactive),
       allocation_occurrence___2__2__1__3(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     allocation_occurrence___2__2__1__3(J,A,B,C,D,E,F,G,H)
   ).
allocation_occurrence___2__2(A,B,C) :-
   allocation_occurrence___2__3(A,B,C).
allocation_occurrence___2__3(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',D),
   lookup_ht(D,A,E),
   !,
   allocation_occurrence___2__3__0__5(E,A,B,C).
allocation_occurrence___2__3__0__5([],A,B,C) :-
   allocation_occurrence___2__4(A,B,C).
allocation_occurrence___2__3__0__5([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G,H,I),
     F==A,
     G>1,
     ground(A),
     ground(G),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',J),
     lookup_ht(J,k(A,G),K),
     'chr sbag_member'(L,K),
     L=suspension(_,active,_,_,_,M,_,_,_),
     B>M ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',N),
     delete_ht(N,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',O),
     delete_ht(O,k(A,G),D),
     arg(2,C,P),
     setarg(2,C,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',Q),
       insert_ht(Q,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',R),
       insert_ht(R,k(A,B),C)
     ;
       true
     ),
     functional_dependency(A,1,H,I),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       allocation_occurrence___2__3__0__5(E,A,B,C)
     ;
       true
     )
   ;
     allocation_occurrence___2__3__0__5(E,A,B,C)
   ).
allocation_occurrence___2__3(A,B,C) :-
   allocation_occurrence___2__4(A,B,C).
allocation_occurrence___2__4(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',E),
     insert_ht(E,A,C),
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',F),
     insert_ht(F,k(A,B),C)
   ;
     true
   ).
get_allocation_occurrence(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,F),
   !,
   B=F.
get_allocation_occurrence(_,A) :-
   chr_pp_flag(late_allocation,off),
   A=0.
rule(A,B) :-
   rule___2__0(A,B,_).
rule___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   C=suspension(F,not_stored_yet,t,_,A,B),
   'chr gen_id'(F),
   rule___2__0__0__1(E,A,B,C).
rule___2__0__0__1([],A,B,C) :-
   rule___2__1(A,B,C).
rule___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,J),
     H==A,
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',K),
     lookup_ht(K,k(F,G),L) ->
     rule___2__0__1__1(L,F,G,I,J,D,E,A,B,C)
   ;
     rule___2__0__0__1(E,A,B,C)
   ).
rule___2__0__1__1([],_,_,_,_,_,A,B,C,D) :-
   rule___2__0__0__1(A,B,C,D).
rule___2__0__1__1([J|K],A,B,C,D,E,F,G,H,I) :-
   ( J=suspension(_,active,_,L,M),
     L==A,
     M==B,
     N=t(60,I,E,J),
     '$novel_production'(I,N),
     '$novel_production'(E,N),
     '$novel_production'(J,N) ->
     '$extend_history'(I,N),
     arg(2,I,O),
     setarg(2,I,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',P),
       Q=[I|P],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',Q),
       ( P=[R|_] ->
         setarg(4,R,Q)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',S),
       insert_ht(S,G,I)
     ;
       true
     ),
     \+is_passive(G,C),
     D==propagation,
     ( stored_in_guard_before_next_kept_occurrence(A,B) ->
       true
     ;
       ( H=pragma(rule([_|_],_,_,_),_,_,_,_) ->
         is_observed(A,B)
       )
     ;
       ( is_least_occurrence(G) ->
         is_observed(A,B)
       )
     ;
       true
     ),
     ( I=suspension(_,active,_,_,_,_) ->
       setarg(2,I,inactive),
       rule___2__0__1__1(K,A,B,C,D,E,F,G,H,I)
     ;
       true
     )
   ;
     rule___2__0__1__1(K,A,B,C,D,E,F,G,H,I)
   ).
rule___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,t,_,A,B),
   'chr gen_id'(D),
   rule___2__1(A,B,C).
rule___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',D),
   lookup_ht(D,A,E),
   !,
   rule___2__1__0__2(E,A,B,C).
rule___2__1__0__2([],A,B,C) :-
   rule___2__2(A,B,C).
rule___2__1__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G),
     F==A,
     G=[H|I],
     ground(A),
     ground(H),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',J),
     lookup_ht(J,k(A,H),K),
     'chr sbag_member'(L,K),
     L=suspension(_,active,_,_,M,N,_,_,_),
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',O),
     lookup_ht(O,M,P),
     'chr sbag_member'(Q,P),
     Q=suspension(_,active,_,_,R),
     R>=N,
     \+may_trigger(M) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',S),
     delete_ht(S,k(A,[H|I]),D),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',T),
     delete_ht(T,A,D),
     arg(2,C,U),
     setarg(2,C,active),
     ( U==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',V),
       W=[C|V],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',W),
       ( V=[X|_] ->
         setarg(4,X,W)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',Y),
       insert_ht(Y,A,C)
     ;
       true
     ),
     least_occurrence(A,I),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__1__0__2(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__1__0__2(E,A,B,C)
   ).
rule___2__1(A,B,C) :-
   rule___2__2(A,B,C).
rule___2__2(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',D),
   lookup_ht(D,A,E),
   !,
   rule___2__2__0__3(E,A,B,C).
rule___2__2__0__3([],A,B,C) :-
   rule___2__3(A,B,C).
rule___2__2__0__3([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G),
     F==A,
     G=[H|I],
     ground(A),
     ground(H),
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',J),
     lookup_ht(J,k(A,H),K),
     'chr sbag_member'(L,K),
     L=suspension(_,active,_,_,_) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',M),
     delete_ht(M,k(A,[H|I]),D),
     nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',N),
     delete_ht(N,A,D),
     arg(2,C,O),
     setarg(2,C,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',P),
       Q=[C|P],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',Q),
       ( P=[R|_] ->
         setarg(4,R,Q)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',S),
       insert_ht(S,A,C)
     ;
       true
     ),
     least_occurrence(A,I),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__2__0__3(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__2__0__3(E,A,B,C)
   ).
rule___2__2(A,B,C) :-
   rule___2__3(A,B,C).
rule___2__3(A,B,C) :-
   B=pragma(rule([],_,_,_),ids([],D),_,_,_),
   !,
   arg(2,C,E),
   setarg(2,C,active),
   ( E==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____rule___2',F),
     G=[C|F],
     b_setval('$chr_store_global_ground_chr_translate____rule___2',G),
     ( F=[H|_] ->
       setarg(4,H,G)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',I),
     insert_ht(I,A,C)
   ;
     true
   ),
   least_occurrence(A,D),
   ( C=suspension(_,active,_,_,_,_) ->
     setarg(2,C,inactive),
     rule___2__4(A,B,C)
   ;
     true
   ).
rule___2__3(A,B,C) :-
   rule___2__4(A,B,C).
rule___2__4(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,G,H,I,J,_),
   B=pragma(rule(N,O,H,P),K,L,M,A),
   H\==true,
   append(J,I,Q),
   ( conj2list(H,R),
     append(Q,R,S),
     guard_entailment:entails_guard(S,fail) ->
     T=fail
   ;
     simplify_guard(H,P,Q,T,U)
   ),
   H\==T,
   !,
   setarg(2,F,removed),
   arg(4,F,V),
   ( var(V) ->
     nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',W),
     W=[_|X],
     b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',X),
     ( X=[Y|_] ->
       setarg(4,Y,_)
     ;
       true
     )
   ;
     V=[_,_|X],
     setarg(2,V,X),
     ( X=[Y|_] ->
       setarg(4,Y,V)
     ;
       true
     )
   ),
   nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',Z),
   delete_ht(Z,A,F),
   ( var(C) ->
     true
   ;
     arg(2,C,A1),
     setarg(2,C,removed),
     ( A1==not_stored_yet ->
       true
     ;
       arg(4,C,B1),
       ( var(B1) ->
         nb_getval('$chr_store_global_ground_chr_translate____rule___2',C1),
         C1=[_|D1],
         b_setval('$chr_store_global_ground_chr_translate____rule___2',D1),
         ( D1=[E1|_] ->
           setarg(4,E1,_)
         ;
           true
         )
       ;
         B1=[_,_|D1],
         setarg(2,B1,D1),
         ( D1=[E1|_] ->
           setarg(4,E1,B1)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',F1),
       delete_ht(F1,A,C)
     )
   ),
   rule(A,pragma(rule(N,O,T,U),K,L,M,A)),
   prev_guard_list(A,G,T,I,J,[]).
rule___2__4(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',D),
   !,
   rule___2__4__0__10(D,A,B,C).
rule___2__4__0__10([],A,B,C) :-
   rule___2__5(A,B,C).
rule___2__4__0__10([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_),
     F=t(174,C,D),
     '$novel_production'(C,F),
     '$novel_production'(D,F) ->
     '$extend_history'(C,F),
     arg(2,C,G),
     setarg(2,C,active),
     ( G==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',H),
       I=[C|H],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',I),
       ( H=[J|_] ->
         setarg(4,J,I)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',K),
       insert_ht(K,A,C)
     ;
       true
     ),
     B=pragma(rule(L,M,_,_),_,_,_,_),
     append(L,M,N),
     make_head_matchings_explicit_(N,O,P),
     copy_term_nat(O-P,Q-R),
     make_head_matchings_explicit_memo_table(A,Q,R),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__4__0__10(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__4__0__10(E,A,B,C)
   ).
rule___2__4(A,B,C) :-
   rule___2__5(A,B,C).
rule___2__5(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',D),
   lookup_ht(D,A,E),
   !,
   rule___2__5__0__11(E,A,B,C).
rule___2__5__0__11([],A,B,C) :-
   rule___2__6(A,B,C).
rule___2__5__0__11([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,I,_),
     F==A,
     J=t(178,D,C),
     '$novel_production'(D,J),
     '$novel_production'(C,J),
     chr_pp_flag(check_impossible_rules,on),
     B=pragma(rule(_,_,G,_),_,_,_,A),
     conj2list(G,K),
     append(I,H,L),
     append(L,K,M),
     guard_entailment:entails_guard(M,fail) ->
     '$extend_history'(C,J),
     arg(2,C,N),
     setarg(2,C,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',O),
       P=[C|O],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',P),
       ( O=[Q|_] ->
         setarg(4,Q,P)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',R),
       insert_ht(R,A,C)
     ;
       true
     ),
     chr_warning(weird_program,'Heads will never match or guard will always fail in ~@.\n\tThis rule will never fire!\n',[format_rule(B)]),
     set_all_passive(A),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__5__0__11(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__5__0__11(E,A,B,C)
   ).
rule___2__5(A,B,C) :-
   rule___2__6(A,B,C).
rule___2__6(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,G,H,I,J,_),
   B=pragma(rule(N,O,H,P),K,L,M,A),
   simplify_heads(J,I,H,P,Q,R),
   Q\==[],
   extract_arguments(N,S),
   extract_arguments(O,T),
   extract_arguments(G,U),
   replace_some_heads(S,T,U,Q,V,W,H,P,X),
   substitute_arguments(N,V,Y),
   substitute_arguments(O,W,Z),
   append(R,X,A1),
   list2conj(A1,B1),
   C1=pragma(rule(Y,Z,H,(B1,P)),K,L,M,A),
   (
     N\==Y
   ;
     O\==Z
   ),
   !,
   ( var(C) ->
     true
   ;
     arg(2,C,D1),
     setarg(2,C,removed),
     ( D1==not_stored_yet ->
       true
     ;
       arg(4,C,E1),
       ( var(E1) ->
         nb_getval('$chr_store_global_ground_chr_translate____rule___2',F1),
         F1=[_|G1],
         b_setval('$chr_store_global_ground_chr_translate____rule___2',G1),
         ( G1=[H1|_] ->
           setarg(4,H1,_)
         ;
           true
         )
       ;
         E1=[_,_|G1],
         setarg(2,E1,G1),
         ( G1=[H1|_] ->
           setarg(4,H1,E1)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',I1),
       delete_ht(I1,A,C)
     )
   ),
   rule(A,C1).
rule___2__6(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   rule___2__6__0__13(E,A,B,C).
rule___2__6__0__13([],A,B,C) :-
   rule___2__7(A,B,C).
rule___2__6__0__13([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,_,_),
     H==A,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',I),
     lookup_ht(I,k(F,A),J) ->
     rule___2__6__1__13(J,F,G,D,E,A,B,C)
   ;
     rule___2__6__0__13(E,A,B,C)
   ).
rule___2__6__1__13([],_,_,_,A,B,C,D) :-
   rule___2__6__0__13(A,B,C,D).
rule___2__6__1__13([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K,L,M,_),
     H\==C,
     J==A,
     L==E,
     nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',N),
     lookup_ht(N,E,O) ->
     rule___2__6__2__13(O,K,M,H,I,A,B,C,D,E,F,G)
   ;
     rule___2__6__1__13(I,A,B,C,D,E,F,G)
   ).
rule___2__6__2__13([],_,_,_,A,B,C,D,E,F,G,H) :-
   rule___2__6__1__13(A,B,C,D,E,F,G,H).
rule___2__6__2__13([L|M],A,B,C,D,E,F,G,H,I,J,K) :-
   ( L=suspension(_,active,_,_,N,_,_,_,_,_),
     N==I,
     nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',O) ->
     rule___2__6__3__13(O,L,M,A,B,C,D,E,F,G,H,I,J,K)
   ;
     rule___2__6__2__13(M,A,B,C,D,E,F,G,H,I,J,K)
   ).
rule___2__6__3__13([],_,A,B,C,D,E,F,G,H,I,J,K,L) :-
   rule___2__6__2__13(A,B,C,D,E,F,G,H,I,J,K,L).
rule___2__6__3__13([N|O],A,B,C,D,E,F,G,H,I,J,K,L,M) :-
   ( N=suspension(_,active,_,P),
     C<H,
     chr_pp_flag(occurrence_subsumption,on),
     L=pragma(rule(Q,_,_,_),_,_,_,_),
     Q\==[],
     \+tree_set_memberchk(G,P) ->
     setarg(2,N,removed),
     arg(3,N,R),
     ( var(R) ->
       nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',S),
       S=[_|T],
       b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',T),
       ( T=[U|_] ->
         setarg(3,U,_)
       ;
         true
       )
     ;
       R=[_,_|T],
       setarg(2,R,T),
       ( T=[U|_] ->
         setarg(3,U,R)
       ;
         true
       )
     ),
     arg(2,M,V),
     setarg(2,M,active),
     ( V==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',W),
       X=[M|W],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',X),
       ( W=[Y|_] ->
         setarg(4,Y,X)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',Z),
       insert_ht(Z,K,M)
     ;
       true
     ),
     first_occ_in_rule(K,G,C,D),
     tree_set_add(P,G,A1),
     multiple_occ_constraints_checked(A1),
     ( M=suspension(_,active,_,_,_,_) ->
       setarg(2,M,inactive),
       rule___2__6__3__13(O,A,B,C,D,E,F,G,H,I,J,K,L,M)
     ;
       true
     )
   ;
     rule___2__6__3__13(O,A,B,C,D,E,F,G,H,I,J,K,L,M)
   ).
rule___2__6(A,B,C) :-
   rule___2__7(A,B,C).
rule___2__7(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',D),
   lookup_ht(D,A,E),
   !,
   rule___2__7__0__15(E,A,B,C).
rule___2__7__0__15([],A,B,C) :-
   rule___2__8(A,B,C).
rule___2__7__0__15([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==A,
     H=t(251,C,D),
     '$novel_production'(C,H),
     '$novel_production'(D,H),
     B=pragma(rule(_,_,_,_),ids([G|J],I),_,_,A) ->
     '$extend_history'(C,H),
     arg(2,C,K),
     setarg(2,C,active),
     ( K==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',L),
       M=[C|L],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',M),
       ( L=[N|_] ->
         setarg(4,N,M)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',O),
       insert_ht(O,A,C)
     ;
       true
     ),
     append(J,I,P),
     check_all_passive(A,P),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__7__0__15(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__7__0__15(E,A,B,C)
   ).
rule___2__7(A,B,C) :-
   rule___2__8(A,B,C).
rule___2__8(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',D),
   lookup_ht(D,A,E),
   !,
   rule___2__8__0__16(E,A,B,C).
rule___2__8__0__16([],A,B,C) :-
   rule___2__9(A,B,C).
rule___2__8__0__16([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==A,
     H=t(252,C,D),
     '$novel_production'(C,H),
     '$novel_production'(D,H),
     B=pragma(rule(_,_,_,_),ids([],[G|I]),_,_,A) ->
     '$extend_history'(C,H),
     arg(2,C,J),
     setarg(2,C,active),
     ( J==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',K),
       L=[C|K],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',L),
       ( K=[M|_] ->
         setarg(4,M,L)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',N),
       insert_ht(N,A,C)
     ;
       true
     ),
     check_all_passive(A,I),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__8__0__16(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__8__0__16(E,A,B,C)
   ).
rule___2__8(A,B,C) :-
   rule___2__9(A,B,C).
rule___2__9(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',D),
   lookup_ht(D,k(A,[]),E),
   !,
   rule___2__9__0__17(E,A,B,C).
rule___2__9__0__17([],A,B,C) :-
   rule___2__10(A,B,C).
rule___2__9__0__17([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G),
     F==A,
     G=[] ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',H),
     delete_ht(H,k(A,[]),D),
     nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',I),
     delete_ht(I,A,D),
     arg(2,C,J),
     setarg(2,C,active),
     ( J==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',K),
       L=[C|K],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',L),
       ( K=[M|_] ->
         setarg(4,M,L)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',N),
       insert_ht(N,A,C)
     ;
       true
     ),
     chr_warning(weird_program,'All heads passive in ~@.\n\tThis rule never fires. Please check your program.\n',[format_rule(B)]),
     ( C=suspension(_,active,_,_,_,_) ->
       setarg(2,C,inactive),
       rule___2__9__0__17(E,A,B,C)
     ;
       true
     )
   ;
     rule___2__9__0__17(E,A,B,C)
   ).
rule___2__9(A,B,C) :-
   rule___2__10(A,B,C).
rule___2__10(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   rule___2__10__0__22(E,A,B,C).
rule___2__10__0__22([],A,B,C) :-
   rule___2__11(A,B,C).
rule___2__10__0__22([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,I),
     G==A,
     nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',J) ->
     rule___2__10__1__22(J,F,H,I,D,E,A,B,C)
   ;
     rule___2__10__0__22(E,A,B,C)
   ).
rule___2__10__1__22([],_,_,_,_,A,B,C,D) :-
   rule___2__10__0__22(A,B,C,D).
rule___2__10__1__22([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_),
     nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',K),
     lookup_ht(K,A,L) ->
     rule___2__10__2__22(L,I,J,A,B,C,D,E,F,G,H)
   ;
     rule___2__10__1__22(J,A,B,C,D,E,F,G,H)
   ).
rule___2__10__2__22([],_,A,B,C,D,E,F,G,H,I) :-
   rule___2__10__1__22(A,B,C,D,E,F,G,H,I).
rule___2__10__2__22([K|L],A,B,C,D,E,F,G,H,I,J) :-
   ( K=suspension(_,active,_,_,M,N),
     M==C,
     O=t(330,A,F,J,K),
     '$novel_production'(A,O),
     '$novel_production'(F,O),
     '$novel_production'(J,O),
     '$novel_production'(K,O) ->
     '$extend_history'(J,O),
     arg(2,J,P),
     setarg(2,J,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',Q),
       R=[J|Q],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',R),
       ( Q=[S|_] ->
         setarg(4,S,R)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',T),
       insert_ht(T,H,J)
     ;
       true
     ),
     I=pragma(rule(U,V,W,_),_,_,_,_),
     ( is_passive(H,D) ->
       true
     ;
       ( E==simplification ->
         select(X,U,_),
         X=..[_|Y],
         term_variables(W,Z),
         partial_wake_args(Y,N,Z,C)
       )
     ;
       select(X,V,_),
       X=..[_|Y],
       term_variables(W,Z),
       partial_wake_args(Y,N,Z,C)
     ),
     ( J=suspension(_,active,_,_,_,_) ->
       setarg(2,J,inactive),
       rule___2__10__2__22(L,A,B,C,D,E,F,G,H,I,J)
     ;
       true
     )
   ;
     rule___2__10__2__22(L,A,B,C,D,E,F,G,H,I,J)
   ).
rule___2__10(A,B,C) :-
   rule___2__11(A,B,C).
rule___2__11(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____rule___2',D),
     E=[B|D],
     b_setval('$chr_store_global_ground_chr_translate____rule___2',E),
     ( D=[F|_] ->
       setarg(4,F,E)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',G),
     insert_ht(G,A,B)
   ;
     true
   ).
get_rule(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F),
   !,
   B=F.
get_rule(_,_) :-
   fail.
least_occurrence(A,[B|C]) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_),
   (
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',G),
     lookup_ht(G,k(A,B),H),
     'chr sbag_member'(I,H),
     I=suspension(_,active,_,_,J,K,_,_,_),
     nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',L),
     lookup_ht(L,J,M),
     'chr sbag_member'(N,M),
     N=suspension(_,active,_,_,O),
     O>=K,
     \+may_trigger(J),
     !,
     least_occurrence(A,C)
   ;
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',P),
     lookup_ht(P,k(A,B),Q),
     'chr sbag_member'(R,Q),
     R=suspension(_,active,_,_,_),
     !,
     least_occurrence(A,C)
   ).
least_occurrence(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',E),
   insert_ht(E,k(A,B),C),
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',F),
   insert_ht(F,A,C).
is_least_occurrence(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',B),
   lookup_ht(B,k(A,[]),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !.
is_least_occurrence(_) :-
   fail.
stored_in_guard_lookahead(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,_,F,G,H),
   (
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',I),
     lookup_ht(I,k(F,G),J),
     'chr sbag_member'(K,J),
     K=suspension(_,active,_,_,_),
     !,
     L is B+1,
     stored_in_guard_lookahead(A,L)
   ;
     !,
     H==simplification,
     ( is_stored_in_guard(A,F) ->
       true
     ;
       M is B+1,
       stored_in_guard_lookahead(A,M)
     )
   ).
stored_in_guard_lookahead(_,_) :-
   fail.
constraint_index(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',E),
   insert_ht(E,B,C),
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',F),
   insert_ht(F,A,C).
get_constraint_index(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
get_constraint_index(_,_) :-
   fail.
get_indexed_constraint(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,F,_),
   !,
   B=F.
get_indexed_constraint(_,_) :-
   fail.
max_constraint_index(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____max_constraint_index___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____max_constraint_index___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
get_max_constraint_index(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____max_constraint_index___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   A=D.
get_max_constraint_index(0).
identifier_size(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',B),
   (
     'chr sbag_member'(C,B),
     C=suspension(_,active,_,_),
     !
   ;
     !,
     identifier_size___1__0__0__2(B,A)
   ).
identifier_size___1__0__0__2([],A) :-
   identifier_size___1__1(A).
identifier_size___1__0__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_) ->
     setarg(2,B,removed),
     arg(3,B,D),
     ( var(D) ->
       nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',E),
       E=[_|F],
       b_setval('$chr_store_global_ground_chr_translate____identifier_size___1',F),
       ( F=[G|_] ->
         setarg(3,G,_)
       ;
         true
       )
     ;
       D=[_,_|F],
       setarg(2,D,F),
       ( F=[G|_] ->
         setarg(3,G,D)
       ;
         true
       )
     ),
     identifier_size___1__0__0__2(C,A)
   ;
     identifier_size___1__0__0__2(C,A)
   ).
identifier_size(A) :-
   identifier_size___1__1(A).
identifier_size___1__1(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____identifier_size___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
get_identifier_size(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   A=D.
get_identifier_size(1).
identifier_index(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',D),
   lookup_ht(D,k(A,B),E),
   (
     'chr sbag_member'(F,E),
     F=suspension(_,active,_,_,_),
     !
   ;
     !,
     identifier_index___3__0__0__2(E,A,B,C)
   ).
identifier_index___3__0__0__2([],A,B,C) :-
   identifier_index___3__1(A,B,C).
identifier_index___3__0__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G,_),
     F==A,
     G==B ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',H),
     delete_ht(H,k(A,B),D),
     identifier_index___3__0__0__2(E,A,B,C)
   ;
     identifier_index___3__0__0__2(E,A,B,C)
   ).
identifier_index(A,B,C) :-
   identifier_index___3__1(A,B,C).
identifier_index___3__1(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',F),
   insert_ht(F,k(A,B),D).
get_identifier_index(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   C=G.
get_identifier_index(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   setarg(2,E,removed),
   arg(3,E,G),
   ( var(G) ->
     nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',H),
     H=[_|I],
     b_setval('$chr_store_global_ground_chr_translate____identifier_size___1',I),
     ( I=[J|_] ->
       setarg(3,J,_)
     ;
       true
     )
   ;
     G=[_,_|I],
     setarg(2,G,I),
     ( I=[J|_] ->
       setarg(3,J,G)
     ;
       true
     )
   ),
   K is F+1,
   identifier_index(A,B,K),
   identifier_size(K),
   C=K.
get_identifier_index(A,B,C) :-
   identifier_index(A,B,2),
   identifier_size(2),
   C=2.
type_indexed_identifier_size(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',C),
   lookup_ht(C,A,D),
   (
     'chr sbag_member'(E,D),
     E=suspension(_,active,_,_),
     !
   ;
     !,
     type_indexed_identifier_size___2__0__0__2(D,A,B)
   ).
type_indexed_identifier_size___2__0__0__2([],A,B) :-
   type_indexed_identifier_size___2__1(A,B).
type_indexed_identifier_size___2__0__0__2([C|D],A,B) :-
   ( C=suspension(_,active,E,_),
     E==A ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',F),
     delete_ht(F,A,C),
     type_indexed_identifier_size___2__0__0__2(D,A,B)
   ;
     type_indexed_identifier_size___2__0__0__2(D,A,B)
   ).
type_indexed_identifier_size(A,B) :-
   type_indexed_identifier_size___2__1(A,B).
type_indexed_identifier_size___2__1(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',E),
   insert_ht(E,A,C).
get_type_indexed_identifier_size(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
get_type_indexed_identifier_size(_,1).
type_indexed_identifier_index(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',E),
   lookup_ht(E,k(B,C),F),
   (
     'chr sbag_member'(G,F),
     G=suspension(_,active,_,_,_,_),
     !
   ;
     !,
     type_indexed_identifier_index___4__0__0__2(F,A,B,C,D)
   ).
type_indexed_identifier_index___4__0__0__2([],A,B,C,D) :-
   type_indexed_identifier_index___4__1(A,B,C,D).
type_indexed_identifier_index___4__0__0__2([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,H,I,_),
     H==B,
     I==C ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',J),
     delete_ht(J,k(G,B,C),E),
     nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',K),
     delete_ht(K,k(B,C),E),
     type_indexed_identifier_index___4__0__0__2(F,A,B,C,D)
   ;
     type_indexed_identifier_index___4__0__0__2(F,A,B,C,D)
   ).
type_indexed_identifier_index(A,B,C,D) :-
   type_indexed_identifier_index___4__1(A,B,C,D).
type_indexed_identifier_index___4__1(A,B,C,D) :-
   E=suspension(F,active,A,B,C,D),
   'chr gen_id'(F),
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',G),
   insert_ht(G,k(A,B,C),E),
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',H),
   insert_ht(H,k(B,C),E).
get_type_indexed_identifier_index(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',E),
   lookup_ht(E,k(A,B,C),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,_,H),
   !,
   D=H.
get_type_indexed_identifier_index(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',E),
   lookup_ht(E,A,F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,H),
   !,
   setarg(2,G,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',I),
   delete_ht(I,A,G),
   J is H+1,
   type_indexed_identifier_index(A,B,C,J),
   type_indexed_identifier_size(A,J),
   D=J.
get_type_indexed_identifier_index(A,B,C,D) :-
   type_indexed_identifier_index(A,B,C,2),
   type_indexed_identifier_size(A,2),
   D=2.
no_history(A) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',D),
   insert_ht(D,A,B).
has_no_history(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
has_no_history(_) :-
   fail.
history(A,B,C) :-
   history___3__0(A,B,C,_).
history___3__0(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',E),
   lookup_ht(E,A,F),
   !,
   D=suspension(G,not_stored_yet,t,A,B,C),
   'chr gen_id'(G),
   history___3__0__0__1(F,A,B,C,D).
history___3__0__0__1([],A,B,C,D) :-
   history___3__1(A,B,C,D).
history___3__0__0__1([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,G,_,_),
     G==A,
     H=t(95,D,E),
     '$novel_production'(D,H),
     '$novel_production'(E,H) ->
     '$extend_history'(D,H),
     arg(2,D,I),
     setarg(2,D,active),
     ( I==not_stored_yet ->
       ( '$chr_store_constants_chr_translate____history___3___[3]'(C,J) ->
         nb_getval(J,K),
         b_setval(J,[D|K])
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',L),
       insert_ht(L,B,D),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',M),
       insert_ht(M,A,D)
     ;
       true
     ),
     chr_error(syntax,'Only one pragma history allowed per rule (rule number ~w)\n',[A]),
     ( D=suspension(_,active,_,_,_,_) ->
       setarg(2,D,inactive),
       history___3__0__0__1(F,A,B,C,D)
     ;
       true
     )
   ;
     history___3__0__0__1(F,A,B,C,D)
   ).
history___3__0(A,B,C,D) :-
   D=suspension(E,not_stored_yet,t,A,B,C),
   'chr gen_id'(E),
   history___3__1(A,B,C,D).
history___3__1(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',E),
   lookup_ht(E,A,F),
   !,
   history___3__1__0__2(F,A,B,C,D).
history___3__1__0__2([],A,B,C,D) :-
   history___3__2(A,B,C,D).
history___3__1__0__2([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,G,_,_),
     G==A,
     H=t(95,E,D),
     '$novel_production'(E,H),
     '$novel_production'(D,H) ->
     '$extend_history'(D,H),
     arg(2,D,I),
     setarg(2,D,active),
     ( I==not_stored_yet ->
       ( '$chr_store_constants_chr_translate____history___3___[3]'(C,J) ->
         nb_getval(J,K),
         b_setval(J,[D|K])
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',L),
       insert_ht(L,B,D),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',M),
       insert_ht(M,A,D)
     ;
       true
     ),
     chr_error(syntax,'Only one pragma history allowed per rule (rule number ~w)\n',[A]),
     ( D=suspension(_,active,_,_,_,_) ->
       setarg(2,D,inactive),
       history___3__1__0__2(F,A,B,C,D)
     ;
       true
     )
   ;
     history___3__1__0__2(F,A,B,C,D)
   ).
history___3__1(A,B,C,D) :-
   history___3__2(A,B,C,D).
history___3__2(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',E),
   lookup_ht(E,B,F),
   !,
   history___3__2__0__3(F,A,B,C,D).
history___3__2__0__3([],A,B,C,D) :-
   history___3__3(A,B,C,D).
history___3__2__0__3([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,G,H,I),
     H==B,
     J=t(96,D,E),
     '$novel_production'(D,J),
     '$novel_production'(E,J) ->
     '$extend_history'(D,J),
     arg(2,D,K),
     setarg(2,D,active),
     ( K==not_stored_yet ->
       ( '$chr_store_constants_chr_translate____history___3___[3]'(C,L) ->
         nb_getval(L,M),
         b_setval(L,[D|M])
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',N),
       insert_ht(N,B,D),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',O),
       insert_ht(O,A,D)
     ;
       true
     ),
     length(C,P),
     length(I,Q),
     ( P\==Q ->
       chr_error(syntax,'The history named ~w does not always range over an equal amount of occurrences.\n',[B])
     ;
       test_named_history_id_pairs(A,C,G,I)
     ),
     ( D=suspension(_,active,_,_,_,_) ->
       setarg(2,D,inactive),
       history___3__2__0__3(F,A,B,C,D)
     ;
       true
     )
   ;
     history___3__2__0__3(F,A,B,C,D)
   ).
history___3__2(A,B,C,D) :-
   history___3__3(A,B,C,D).
history___3__3(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',E),
   lookup_ht(E,B,F),
   !,
   history___3__3__0__4(F,A,B,C,D).
history___3__3__0__4([],A,B,C,D) :-
   history___3__4(A,B,C,D).
history___3__3__0__4([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,G,H,I),
     H==B,
     J=t(96,E,D),
     '$novel_production'(E,J),
     '$novel_production'(D,J) ->
     '$extend_history'(D,J),
     arg(2,D,K),
     setarg(2,D,active),
     ( K==not_stored_yet ->
       ( '$chr_store_constants_chr_translate____history___3___[3]'(C,L) ->
         nb_getval(L,M),
         b_setval(L,[D|M])
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',N),
       insert_ht(N,B,D),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',O),
       insert_ht(O,A,D)
     ;
       true
     ),
     length(I,P),
     length(C,Q),
     ( P\==Q ->
       chr_error(syntax,'The history named ~w does not always range over an equal amount of occurrences.\n',[B])
     ;
       test_named_history_id_pairs(G,I,A,C)
     ),
     ( D=suspension(_,active,_,_,_,_) ->
       setarg(2,D,inactive),
       history___3__3__0__4(F,A,B,C,D)
     ;
       true
     )
   ;
     history___3__3__0__4(F,A,B,C,D)
   ).
history___3__3(A,B,C,D) :-
   history___3__4(A,B,C,D).
history___3__4(A,B,[],C) :-
   nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',D),
   !,
   history___3__4__0__6(D,A,B,[],C).
history___3__4__0__6([],A,B,C,D) :-
   history___3__5(A,B,C,D).
history___3__4__0__6([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_),
     G=t(142,E,D),
     '$novel_production'(E,G),
     '$novel_production'(D,G) ->
     '$extend_history'(D,G),
     arg(2,D,H),
     setarg(2,D,active),
     ( H==not_stored_yet ->
       ( '$chr_store_constants_chr_translate____history___3___[3]'(C,I) ->
         nb_getval(I,J),
         b_setval(I,[D|J])
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',K),
       insert_ht(K,B,D),
       nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',L),
       insert_ht(L,A,D)
     ;
       true
     ),
     generate_empty_named_history_initialisation(B),
     ( D=suspension(_,active,_,_,_,_) ->
       setarg(2,D,inactive),
       history___3__4__0__6(F,A,B,C,D)
     ;
       true
     )
   ;
     history___3__4__0__6(F,A,B,C,D)
   ).
history___3__4(A,B,C,D) :-
   history___3__5(A,B,C,D).
history___3__5(A,B,C,D) :-
   arg(2,D,E),
   setarg(2,D,active),
   ( E==not_stored_yet ->
     ( '$chr_store_constants_chr_translate____history___3___[3]'(C,F) ->
       nb_getval(F,G),
       b_setval(F,[D|G])
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',H),
     insert_ht(H,B,D),
     nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',I),
     insert_ht(I,A,D)
   ;
     true
   ).
named_history(A,B,C) :-
   ground(A),
   nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G,H),
   !,
   B=G,
   C=H.
named_history(_,_,_) :-
   fail.
test_named_history_id_pair(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',E),
   lookup_ht(E,k(A,B),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,H,_,_,_,_),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',I),
   lookup_ht(I,k(H,C,D),J),
   'chr sbag_member'(K,J),
   K=suspension(_,active,_,_,_,_,_,_,_),
   K\==G,
   !.
test_named_history_id_pair(A,_,B,_) :-
   chr_error(syntax,'Occurrences of shared history in rules number ~w and ~w do not correspond\n',[B,A]).
indexing_spec(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   setarg(2,E,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',G),
   delete_ht(G,A,E),
   append(B,F,H),
   indexing_spec(A,H).
indexing_spec(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',E),
   insert_ht(E,A,C).
get_indexing_spec(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
get_indexing_spec(_,[]).
observation_analysis(A) :-
   observation_analysis___1__0(A,_).
observation_analysis___1__0(A,B) :-
   nb_getval('$chr_store_global_ground_chr_translate____rule___2',C),
   !,
   B=suspension(D,not_stored_yet,_,A),
   'chr gen_id'(D),
   observation_analysis___1__0__0__1(C,A,B).
observation_analysis___1__0__0__1([],A,B) :-
   observation_analysis___1__1(A,B).
observation_analysis___1__0__0__1([C|D],A,B) :-
   ( C=suspension(_,active,_,_,E,F) ->
     F=pragma(rule(_,_,G,H),_,_,_,_),
     ( chr_pp_flag(store_in_guards,on) ->
       observation_analysis(E,G,guard,A)
     ;
       true
     ),
     observation_analysis(E,H,body,A),
     observation_analysis___1__0__0__1(D,A,B)
   ;
     observation_analysis___1__0__0__1(D,A,B)
   ).
observation_analysis___1__0(A,B) :-
   B=suspension(C,not_stored_yet,_,A),
   'chr gen_id'(C),
   observation_analysis___1__1(A,B).
observation_analysis___1__1(_,A) :-
   ( var(A) ->
     true
   ;
     arg(2,A,B),
     setarg(2,A,removed),
     ( B==not_stored_yet ->
       true
     ;
       arg(3,A,C),
       ( var(C) ->
         nb_getval('$chr_store_global_ground_chr_translate____observation_analysis___1',D),
         D=[_|E],
         b_setval('$chr_store_global_ground_chr_translate____observation_analysis___1',E),
         ( E=[F|_] ->
           setarg(3,F,_)
         ;
           true
         )
       ;
         C=[_,_|E],
         setarg(2,C,E),
         ( E=[F|_] ->
           setarg(3,F,C)
         ;
           true
         )
       )
     )
   ).
spawns(A,B,C) :-
   spawns___3__0(A,B,C,_).
spawns___3__0(A,B,C,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',D),
   lookup_ht(D,k(A,B,C),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,_),
   !.
spawns___3__0(A,body,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',C),
   lookup_ht(C,k(A,guard,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,_,_),
   !.
spawns___3__0(A,guard,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',D),
   lookup_ht(D,k(A,body,B),E),
   !,
   spawns___3__0__0__4(E,A,guard,B,C).
spawns___3__0__0__4([],A,B,C,D) :-
   spawns___3__1(A,B,C,D).
spawns___3__0__0__4([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_,G,H,I),
     G==A,
     H=body,
     I==C ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',J),
     delete_ht(J,k(A,C),E),
     arg(4,E,K),
     ( var(K) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',L),
       L=[_|M],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',M),
       ( M=[N|_] ->
         setarg(4,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(4,N,K)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',O),
     delete_ht(O,k(A,body),E),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',P),
     delete_ht(P,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',Q),
     delete_ht(Q,C,E),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',R),
     delete_ht(R,k(A,body,C),E),
     spawns___3__0__0__4(F,A,B,C,D)
   ;
     spawns___3__0__0__4(F,A,B,C,D)
   ).
spawns___3__0(A,B,C,D) :-
   spawns___3__1(A,B,C,D).
spawns___3__1(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',E),
   lookup_ht(E,k(A,B),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_),
   !,
   ( var(D) ->
     true
   ;
     arg(2,D,H),
     setarg(2,D,removed),
     ( H==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',I),
       delete_ht(I,k(A,C),D),
       arg(4,D,J),
       ( var(J) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns___3',K),
         K=[_|L],
         b_setval('$chr_store_global_ground_chr_translate____spawns___3',L),
         ( L=[M|_] ->
           setarg(4,M,_)
         ;
           true
         )
       ;
         J=[_,_|L],
         setarg(2,J,L),
         ( L=[M|_] ->
           setarg(4,M,J)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',N),
       delete_ht(N,k(A,B),D),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',O),
       delete_ht(O,A,D),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',P),
       delete_ht(P,C,D),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',Q),
       delete_ht(Q,k(A,B,C),D)
     )
   ).
spawns___3__1(A,body,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',D),
   lookup_ht(D,k(A,guard),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_),
   !,
   ( var(C) ->
     true
   ;
     arg(2,C,G),
     setarg(2,C,removed),
     ( G==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',H),
       delete_ht(H,k(A,B),C),
       arg(4,C,I),
       ( var(I) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns___3',J),
         J=[_|K],
         b_setval('$chr_store_global_ground_chr_translate____spawns___3',K),
         ( K=[L|_] ->
           setarg(4,L,_)
         ;
           true
         )
       ;
         I=[_,_|K],
         setarg(2,I,K),
         ( K=[L|_] ->
           setarg(4,L,I)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',M),
       delete_ht(M,k(A,body),C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',N),
       delete_ht(N,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',O),
       delete_ht(O,B,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',P),
       delete_ht(P,k(A,body,B),C)
     )
   ).
spawns___3__1(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',E),
   lookup_ht(E,k(A,B),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,_,_),
   may_trigger(C),
   !,
   ( var(D) ->
     true
   ;
     arg(2,D,H),
     setarg(2,D,removed),
     ( H==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',I),
       delete_ht(I,k(A,C),D),
       arg(4,D,J),
       ( var(J) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns___3',K),
         K=[_|L],
         b_setval('$chr_store_global_ground_chr_translate____spawns___3',L),
         ( L=[M|_] ->
           setarg(4,M,_)
         ;
           true
         )
       ;
         J=[_,_|L],
         setarg(2,J,L),
         ( L=[M|_] ->
           setarg(4,M,J)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',N),
       delete_ht(N,k(A,B),D),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',O),
       delete_ht(O,A,D),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',P),
       delete_ht(P,C,D),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',Q),
       delete_ht(Q,k(A,B,C),D)
     )
   ).
spawns___3__1(A,body,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',D),
   lookup_ht(D,k(A,guard),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_),
   may_trigger(B),
   !,
   ( var(C) ->
     true
   ;
     arg(2,C,G),
     setarg(2,C,removed),
     ( G==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',H),
       delete_ht(H,k(A,B),C),
       arg(4,C,I),
       ( var(I) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns___3',J),
         J=[_|K],
         b_setval('$chr_store_global_ground_chr_translate____spawns___3',K),
         ( K=[L|_] ->
           setarg(4,L,_)
         ;
           true
         )
       ;
         I=[_,_|K],
         setarg(2,I,K),
         ( K=[L|_] ->
           setarg(4,L,I)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',M),
       delete_ht(M,k(A,body),C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',N),
       delete_ht(N,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',O),
       delete_ht(O,B,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',P),
       delete_ht(P,k(A,body,B),C)
     )
   ).
spawns___3__1(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',E),
   lookup_ht(E,C,F),
   (
     'chr sbag_member'(G,F),
     G=suspension(_,active,_,_,_,_,H,I,_),
     (
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',J),
       lookup_ht(J,H,K),
       'chr sbag_member'(L,K),
       L=suspension(_,active,_,_),
       \+is_passive(H,I),
       !,
       ( var(D) ->
         true
       ;
         arg(2,D,M),
         setarg(2,D,removed),
         ( M==not_stored_yet ->
           true
         ;
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',N),
           delete_ht(N,k(A,C),D),
           arg(4,D,O),
           ( var(O) ->
             nb_getval('$chr_store_global_ground_chr_translate____spawns___3',P),
             P=[_|Q],
             b_setval('$chr_store_global_ground_chr_translate____spawns___3',Q),
             ( Q=[R|_] ->
               setarg(4,R,_)
             ;
               true
             )
           ;
             O=[_,_|Q],
             setarg(2,O,Q),
             ( Q=[R|_] ->
               setarg(4,R,O)
             ;
               true
             )
           ),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',S),
           delete_ht(S,k(A,B),D),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',T),
           delete_ht(T,A,D),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',U),
           delete_ht(U,C,D),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',V),
           delete_ht(V,k(A,B,C),D)
         )
       ),
       spawns_all(A,B)
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',W),
       lookup_ht(W,H,X),
       'chr sbag_member'(Y,X),
       Y=suspension(_,active,_,_,_,_),
       may_trigger(C),
       \+is_passive(H,I),
       !,
       ( var(D) ->
         true
       ;
         arg(2,D,Z),
         setarg(2,D,removed),
         ( Z==not_stored_yet ->
           true
         ;
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',A1),
           delete_ht(A1,k(A,C),D),
           arg(4,D,B1),
           ( var(B1) ->
             nb_getval('$chr_store_global_ground_chr_translate____spawns___3',C1),
             C1=[_|D1],
             b_setval('$chr_store_global_ground_chr_translate____spawns___3',D1),
             ( D1=[E1|_] ->
               setarg(4,E1,_)
             ;
               true
             )
           ;
             B1=[_,_|D1],
             setarg(2,B1,D1),
             ( D1=[E1|_] ->
               setarg(4,E1,B1)
             ;
               true
             )
           ),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',F1),
           delete_ht(F1,k(A,B),D),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',G1),
           delete_ht(G1,A,D),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',H1),
           delete_ht(H1,C,D),
           nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',I1),
           delete_ht(I1,k(A,B,C),D)
         )
       ),
       spawns_all_triggers(A,B)
     )
   ;
     !,
     D=suspension(J1,not_stored_yet,t,_,A,B,C),
     'chr gen_id'(J1),
     spawns___3__1__0__11(F,A,B,C,D)
   ).
spawns___3__1__0__11([],A,B,C,D) :-
   spawns___3__2(A,B,C,D).
spawns___3__1__0__11([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_,G,_,H,I,_),
     G==C,
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',J),
     lookup_ht(J,H,K) ->
     spawns___3__1__1__11(K,H,I,E,F,A,B,C,D)
   ;
     spawns___3__1__0__11(F,A,B,C,D)
   ).
spawns___3__1__1__11([],_,_,_,A,B,C,D,E) :-
   spawns___3__1__0__11(A,B,C,D,E).
spawns___3__1__1__11([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_,K,_),
     K==A,
     L=t(123,I,C,H),
     '$novel_production'(I,L),
     '$novel_production'(H,L),
     \+may_trigger(G),
     \+is_passive(A,B) ->
     '$extend_history'(H,L),
     arg(2,H,M),
     setarg(2,H,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',N),
       insert_ht(N,k(E,G),H),
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',O),
       P=[H|O],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',P),
       ( O=[Q|_] ->
         setarg(4,Q,P)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',R),
       insert_ht(R,k(E,F),H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',S),
       insert_ht(S,E,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',T),
       insert_ht(T,G,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',U),
       insert_ht(U,k(E,F,G),H)
     ;
       true
     ),
     spawns_all_triggers(E,F),
     ( H=suspension(_,active,_,_,_,_,_) ->
       setarg(2,H,inactive),
       spawns___3__1__1__11(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     spawns___3__1__1__11(J,A,B,C,D,E,F,G,H)
   ).
spawns___3__1(A,B,C,D) :-
   D=suspension(E,not_stored_yet,t,_,A,B,C),
   'chr gen_id'(E),
   spawns___3__2(A,B,C,D).
spawns___3__2(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',E),
   lookup_ht(E,A,F),
   !,
   spawns___3__2__0__12(F,A,B,C,D).
spawns___3__2__0__12([],A,B,C,D) :-
   spawns___3__3(A,B,C,D).
spawns___3__2__0__12([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_,G,_,H,I,_),
     H==A,
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',J),
     lookup_ht(J,G,K) ->
     spawns___3__2__1__12(K,G,I,E,F,A,B,C,D)
   ;
     spawns___3__2__0__12(F,A,B,C,D)
   ).
spawns___3__2__1__12([],_,_,_,A,B,C,D,E) :-
   spawns___3__2__0__12(A,B,C,D,E).
spawns___3__2__1__12([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_,K,L,M),
     M==A,
     N=t(124,H,C,I),
     '$novel_production'(H,N),
     '$novel_production'(I,N),
     K\==E,
     A\==G,
     \+is_passive(E,B) ->
     '$extend_history'(H,N),
     arg(2,H,O),
     setarg(2,H,active),
     ( O==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',P),
       insert_ht(P,k(E,G),H),
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',Q),
       R=[H|Q],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',R),
       ( Q=[S|_] ->
         setarg(4,S,R)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',T),
       insert_ht(T,k(E,F),H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',U),
       insert_ht(U,E,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',V),
       insert_ht(V,G,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',W),
       insert_ht(W,k(E,F,G),H)
     ;
       true
     ),
     spawns(K,L,G),
     ( H=suspension(_,active,_,_,_,_,_) ->
       setarg(2,H,inactive),
       spawns___3__2__1__12(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     spawns___3__2__1__12(J,A,B,C,D,E,F,G,H)
   ).
spawns___3__2(A,B,C,D) :-
   spawns___3__3(A,B,C,D).
spawns___3__3(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',E),
   lookup_ht(E,C,F),
   !,
   spawns___3__3__0__13(F,A,B,C,D).
spawns___3__3__0__13([],A,B,C,D) :-
   spawns___3__4(A,B,C,D).
spawns___3__3__0__13([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_,G,_,H,I,_),
     G==C,
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',J),
     lookup_ht(J,H,K) ->
     spawns___3__3__1__13(K,H,I,E,F,A,B,C,D)
   ;
     spawns___3__3__0__13(F,A,B,C,D)
   ).
spawns___3__3__1__13([],_,_,_,A,B,C,D,E) :-
   spawns___3__3__0__13(A,B,C,D,E).
spawns___3__3__1__13([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_,K,_,L),
     K==A,
     M=t(124,I,C,H),
     '$novel_production'(I,M),
     '$novel_production'(H,M),
     E\==A,
     G\==L,
     \+is_passive(A,B) ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',O),
       insert_ht(O,k(E,G),H),
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',P),
       Q=[H|P],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',Q),
       ( P=[R|_] ->
         setarg(4,R,Q)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',S),
       insert_ht(S,k(E,F),H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',T),
       insert_ht(T,E,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',U),
       insert_ht(U,G,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',V),
       insert_ht(V,k(E,F,G),H)
     ;
       true
     ),
     spawns(E,F,L),
     ( H=suspension(_,active,_,_,_,_,_) ->
       setarg(2,H,inactive),
       spawns___3__3__1__13(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     spawns___3__3__1__13(J,A,B,C,D,E,F,G,H)
   ).
spawns___3__3(A,B,C,D) :-
   spawns___3__4(A,B,C,D).
spawns___3__4(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',E),
   lookup_ht(E,A,F),
   !,
   spawns___3__4__0__14(F,A,B,C,D).
spawns___3__4__0__14([],A,B,C,D) :-
   spawns___3__5(A,B,C,D).
spawns___3__4__0__14([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_,G,_,H,I,_),
     H==A,
     nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',J) ->
     spawns___3__4__1__14(J,G,I,E,F,A,B,C,D)
   ;
     spawns___3__4__0__14(F,A,B,C,D)
   ).
spawns___3__4__1__14([],_,_,_,A,B,C,D,E) :-
   spawns___3__4__0__14(A,B,C,D,E).
spawns___3__4__1__14([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,_,K,L),
     M=t(125,H,C,I),
     '$novel_production'(H,M),
     '$novel_production'(I,M),
     \+is_passive(E,B),
     may_trigger(A),
     \+may_trigger(G) ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',O),
       insert_ht(O,k(E,G),H),
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',P),
       Q=[H|P],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',Q),
       ( P=[R|_] ->
         setarg(4,R,Q)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',S),
       insert_ht(S,k(E,F),H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',T),
       insert_ht(T,E,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',U),
       insert_ht(U,G,H),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',V),
       insert_ht(V,k(E,F,G),H)
     ;
       true
     ),
     spawns(K,L,G),
     ( H=suspension(_,active,_,_,_,_,_) ->
       setarg(2,H,inactive),
       spawns___3__4__1__14(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     spawns___3__4__1__14(J,A,B,C,D,E,F,G,H)
   ).
spawns___3__4(A,B,C,D) :-
   spawns___3__5(A,B,C,D).
spawns___3__5(A,B,C,D) :-
   arg(2,D,E),
   setarg(2,D,active),
   ( E==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',F),
     insert_ht(F,k(A,C),D),
     nb_getval('$chr_store_global_ground_chr_translate____spawns___3',G),
     H=[D|G],
     b_setval('$chr_store_global_ground_chr_translate____spawns___3',H),
     ( G=[I|_] ->
       setarg(4,I,H)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',J),
     insert_ht(J,k(A,B),D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',K),
     insert_ht(K,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',L),
     insert_ht(L,C,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',M),
     insert_ht(M,k(A,B,C),D)
   ;
     true
   ).
spawns_all(A,B) :-
   spawns_all___2__0(A,B,_).
spawns_all___2__0(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
spawns_all___2__0(A,body,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',B),
   lookup_ht(B,k(A,guard),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !.
spawns_all___2__0(A,guard,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',C),
   lookup_ht(C,k(A,body),D),
   !,
   spawns_all___2__0__0__4(D,A,guard,B).
spawns_all___2__0__0__4([],A,B,C) :-
   spawns_all___2__1(A,B,C).
spawns_all___2__0__0__4([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G),
     F==A,
     G=body ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',H),
     delete_ht(H,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',I),
     delete_ht(I,k(A,body),D),
     spawns_all___2__0__0__4(E,A,B,C)
   ;
     spawns_all___2__0__0__4(E,A,B,C)
   ).
spawns_all___2__0(A,B,C) :-
   spawns_all___2__1(A,B,C).
spawns_all___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',D),
   lookup_ht(D,k(A,B),E),
   !,
   spawns_all___2__1__0__5(E,A,B,C).
spawns_all___2__1__0__5([],A,B,C) :-
   spawns_all___2__2(A,B,C).
spawns_all___2__1__0__5([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H),
     F==A,
     G==B ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',I),
     delete_ht(I,k(A,H),D),
     arg(4,D,J),
     ( var(J) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',K),
       K=[_|L],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',L),
       ( L=[M|_] ->
         setarg(4,M,_)
       ;
         true
       )
     ;
       J=[_,_|L],
       setarg(2,J,L),
       ( L=[M|_] ->
         setarg(4,M,J)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',N),
     delete_ht(N,k(A,B),D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',O),
     delete_ht(O,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',P),
     delete_ht(P,H,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',Q),
     delete_ht(Q,k(A,B,H),D),
     spawns_all___2__1__0__5(E,A,B,C)
   ;
     spawns_all___2__1__0__5(E,A,B,C)
   ).
spawns_all___2__1(A,B,C) :-
   spawns_all___2__2(A,B,C).
spawns_all___2__2(A,guard,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',C),
   lookup_ht(C,k(A,body),D),
   !,
   spawns_all___2__2__0__6(D,A,guard,B).
spawns_all___2__2__0__6([],A,B,C) :-
   spawns_all___2__3(A,B,C).
spawns_all___2__2__0__6([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H),
     F==A,
     G=body ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',I),
     delete_ht(I,k(A,H),D),
     arg(4,D,J),
     ( var(J) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',K),
       K=[_|L],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',L),
       ( L=[M|_] ->
         setarg(4,M,_)
       ;
         true
       )
     ;
       J=[_,_|L],
       setarg(2,J,L),
       ( L=[M|_] ->
         setarg(4,M,J)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',N),
     delete_ht(N,k(A,body),D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',O),
     delete_ht(O,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',P),
     delete_ht(P,H,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',Q),
     delete_ht(Q,k(A,body,H),D),
     spawns_all___2__2__0__6(E,A,B,C)
   ;
     spawns_all___2__2__0__6(E,A,B,C)
   ).
spawns_all___2__2(A,B,C) :-
   spawns_all___2__3(A,B,C).
spawns_all___2__3(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',D),
   lookup_ht(D,k(A,B),E),
   !,
   spawns_all___2__3__0__7(E,A,B,C).
spawns_all___2__3__0__7([],A,B,C) :-
   spawns_all___2__4(A,B,C).
spawns_all___2__3__0__7([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G),
     F==A,
     G==B ->
     setarg(2,D,removed),
     arg(4,D,H),
     ( var(H) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',I),
       I=[_|J],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',J),
       ( J=[K|_] ->
         setarg(4,K,_)
       ;
         true
       )
     ;
       H=[_,_|J],
       setarg(2,H,J),
       ( J=[K|_] ->
         setarg(4,K,H)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',L),
     delete_ht(L,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',M),
     delete_ht(M,k(A,B),D),
     spawns_all___2__3__0__7(E,A,B,C)
   ;
     spawns_all___2__3__0__7(E,A,B,C)
   ).
spawns_all___2__3(A,B,C) :-
   spawns_all___2__4(A,B,C).
spawns_all___2__4(A,guard,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',C),
   lookup_ht(C,k(A,body),D),
   !,
   spawns_all___2__4__0__8(D,A,guard,B).
spawns_all___2__4__0__8([],A,B,C) :-
   spawns_all___2__5(A,B,C).
spawns_all___2__4__0__8([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G),
     F==A,
     G=body ->
     setarg(2,D,removed),
     arg(4,D,H),
     ( var(H) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',I),
       I=[_|J],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',J),
       ( J=[K|_] ->
         setarg(4,K,_)
       ;
         true
       )
     ;
       H=[_,_|J],
       setarg(2,H,J),
       ( J=[K|_] ->
         setarg(4,K,H)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',L),
     delete_ht(L,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',M),
     delete_ht(M,k(A,body),D),
     spawns_all___2__4__0__8(E,A,B,C)
   ;
     spawns_all___2__4__0__8(E,A,B,C)
   ).
spawns_all___2__4(A,B,C) :-
   spawns_all___2__5(A,B,C).
spawns_all___2__5(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   C=suspension(F,not_stored_yet,A,B),
   'chr gen_id'(F),
   spawns_all___2__5__0__9(E,A,B,C).
spawns_all___2__5__0__9([],A,B,C) :-
   spawns_all___2__6(A,B,C).
spawns_all___2__5__0__9([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,_),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',I),
     lookup_ht(I,F,J) ->
     spawns_all___2__5__1__9(J,F,H,D,E,A,B,C)
   ;
     spawns_all___2__5__0__9(E,A,B,C)
   ).
spawns_all___2__5__1__9([],_,_,_,A,B,C,D) :-
   spawns_all___2__5__0__9(A,B,C,D).
spawns_all___2__5__1__9([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K,L),
     L==A,
     \+is_passive(E,B) ->
     setarg(2,H,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',M),
     delete_ht(M,k(J,A),H),
     arg(4,H,N),
     ( var(N) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',O),
       O=[_|P],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',P),
       ( P=[Q|_] ->
         setarg(4,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(4,Q,N)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',R),
     delete_ht(R,k(J,K),H),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',S),
     delete_ht(S,J,H),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',T),
     delete_ht(T,A,H),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',U),
     delete_ht(U,k(J,K,A),H),
     arg(2,G,V),
     setarg(2,G,active),
     ( V==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',W),
       insert_ht(W,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',X),
       insert_ht(X,k(E,F),G)
     ;
       true
     ),
     spawns_all(J,K),
     ( G=suspension(_,active,_,_) ->
       setarg(2,G,inactive),
       spawns_all___2__5__1__9(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     spawns_all___2__5__1__9(I,A,B,C,D,E,F,G)
   ).
spawns_all___2__5(A,B,C) :-
   C=suspension(D,not_stored_yet,A,B),
   'chr gen_id'(D),
   spawns_all___2__6(A,B,C).
spawns_all___2__6(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   spawns_all___2__6__0__10(E,A,B,C).
spawns_all___2__6__0__10([],A,B,C) :-
   spawns_all___2__7(A,B,C).
spawns_all___2__6__0__10([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,_),
     G==A,
     \+ \+spawns_all_triggers_implies_spawns_all,
     \+is_passive(A,H),
     may_trigger(F) ->
     arg(2,C,I),
     setarg(2,C,active),
     ( I==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',J),
       insert_ht(J,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',K),
       insert_ht(K,k(A,B),C)
     ;
       true
     ),
     spawns_all_triggers_implies_spawns_all,
     ( C=suspension(_,active,_,_) ->
       setarg(2,C,inactive),
       spawns_all___2__6__0__10(E,A,B,C)
     ;
       true
     )
   ;
     spawns_all___2__6__0__10(E,A,B,C)
   ).
spawns_all___2__6(A,B,C) :-
   spawns_all___2__7(A,B,C).
spawns_all___2__7(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',E),
     insert_ht(E,A,C),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',F),
     insert_ht(F,k(A,B),C)
   ;
     true
   ).
spawns_all_triggers(A,B) :-
   spawns_all_triggers___2__0(A,B,_).
spawns_all_triggers___2__0(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,_),
   !.
spawns_all_triggers___2__0(A,body,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',B),
   lookup_ht(B,k(A,guard),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
spawns_all_triggers___2__0(A,guard,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',C),
   lookup_ht(C,k(A,body),D),
   !,
   spawns_all_triggers___2__0__0__4(D,A,guard,B).
spawns_all_triggers___2__0__0__4([],A,B,C) :-
   spawns_all_triggers___2__1(A,B,C).
spawns_all_triggers___2__0__0__4([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G),
     F==A,
     G=body ->
     setarg(2,D,removed),
     arg(4,D,H),
     ( var(H) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',I),
       I=[_|J],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',J),
       ( J=[K|_] ->
         setarg(4,K,_)
       ;
         true
       )
     ;
       H=[_,_|J],
       setarg(2,H,J),
       ( J=[K|_] ->
         setarg(4,K,H)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',L),
     delete_ht(L,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',M),
     delete_ht(M,k(A,body),D),
     spawns_all_triggers___2__0__0__4(E,A,B,C)
   ;
     spawns_all_triggers___2__0__0__4(E,A,B,C)
   ).
spawns_all_triggers___2__0(A,B,C) :-
   spawns_all_triggers___2__1(A,B,C).
spawns_all_triggers___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_),
   !,
   ( var(C) ->
     true
   ;
     arg(2,C,G),
     setarg(2,C,removed),
     ( G==not_stored_yet ->
       true
     ;
       arg(4,C,H),
       ( var(H) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',I),
         I=[_|J],
         b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',J),
         ( J=[K|_] ->
           setarg(4,K,_)
         ;
           true
         )
       ;
         H=[_,_|J],
         setarg(2,H,J),
         ( J=[K|_] ->
           setarg(4,K,H)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',L),
       delete_ht(L,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',M),
       delete_ht(M,k(A,B),C)
     )
   ).
spawns_all_triggers___2__1(A,body,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',C),
   lookup_ht(C,k(A,guard),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !,
   ( var(B) ->
     true
   ;
     arg(2,B,F),
     setarg(2,B,removed),
     ( F==not_stored_yet ->
       true
     ;
       arg(4,B,G),
       ( var(G) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',H),
         H=[_|I],
         b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',I),
         ( I=[J|_] ->
           setarg(4,J,_)
         ;
           true
         )
       ;
         G=[_,_|I],
         setarg(2,G,I),
         ( I=[J|_] ->
           setarg(4,J,G)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',K),
       delete_ht(K,A,B),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',L),
       delete_ht(L,k(A,body),B)
     )
   ).
spawns_all_triggers___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',D),
   lookup_ht(D,k(A,B),E),
   !,
   spawns_all_triggers___2__1__0__7(E,A,B,C).
spawns_all_triggers___2__1__0__7([],A,B,C) :-
   spawns_all_triggers___2__2(A,B,C).
spawns_all_triggers___2__1__0__7([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H),
     F==A,
     G==B,
     may_trigger(H) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',I),
     delete_ht(I,k(A,H),D),
     arg(4,D,J),
     ( var(J) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',K),
       K=[_|L],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',L),
       ( L=[M|_] ->
         setarg(4,M,_)
       ;
         true
       )
     ;
       J=[_,_|L],
       setarg(2,J,L),
       ( L=[M|_] ->
         setarg(4,M,J)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',N),
     delete_ht(N,k(A,B),D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',O),
     delete_ht(O,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',P),
     delete_ht(P,H,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',Q),
     delete_ht(Q,k(A,B,H),D),
     spawns_all_triggers___2__1__0__7(E,A,B,C)
   ;
     spawns_all_triggers___2__1__0__7(E,A,B,C)
   ).
spawns_all_triggers___2__1(A,B,C) :-
   spawns_all_triggers___2__2(A,B,C).
spawns_all_triggers___2__2(A,guard,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',C),
   lookup_ht(C,k(A,body),D),
   !,
   spawns_all_triggers___2__2__0__8(D,A,guard,B).
spawns_all_triggers___2__2__0__8([],A,B,C) :-
   spawns_all_triggers___2__3(A,B,C).
spawns_all_triggers___2__2__0__8([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H),
     F==A,
     G=body,
     may_trigger(H) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',I),
     delete_ht(I,k(A,H),D),
     arg(4,D,J),
     ( var(J) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',K),
       K=[_|L],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',L),
       ( L=[M|_] ->
         setarg(4,M,_)
       ;
         true
       )
     ;
       J=[_,_|L],
       setarg(2,J,L),
       ( L=[M|_] ->
         setarg(4,M,J)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',N),
     delete_ht(N,k(A,body),D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',O),
     delete_ht(O,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',P),
     delete_ht(P,H,D),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',Q),
     delete_ht(Q,k(A,body,H),D),
     spawns_all_triggers___2__2__0__8(E,A,B,C)
   ;
     spawns_all_triggers___2__2__0__8(E,A,B,C)
   ).
spawns_all_triggers___2__2(A,B,C) :-
   spawns_all_triggers___2__3(A,B,C).
spawns_all_triggers___2__3(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_),
   !,
   ( var(C) ->
     true
   ;
     arg(2,C,F),
     setarg(2,C,removed),
     ( F==not_stored_yet ->
       true
     ;
       arg(4,C,G),
       ( var(G) ->
         nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',H),
         H=[_|I],
         b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',I),
         ( I=[J|_] ->
           setarg(4,J,_)
         ;
           true
         )
       ;
         G=[_,_|I],
         setarg(2,G,I),
         ( I=[J|_] ->
           setarg(4,J,G)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',K),
       delete_ht(K,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',L),
       delete_ht(L,k(A,B),C)
     )
   ),
   spawns_all(A,B).
spawns_all_triggers___2__3(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   C=suspension(F,not_stored_yet,t,_,A,B),
   'chr gen_id'(F),
   spawns_all_triggers___2__3__0__10(E,A,B,C).
spawns_all_triggers___2__3__0__10([],A,B,C) :-
   spawns_all_triggers___2__4(A,B,C).
spawns_all_triggers___2__3__0__10([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,_),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',I),
     lookup_ht(I,F,J) ->
     spawns_all_triggers___2__3__1__10(J,F,H,D,E,A,B,C)
   ;
     spawns_all_triggers___2__3__0__10(E,A,B,C)
   ).
spawns_all_triggers___2__3__1__10([],_,_,_,A,B,C,D) :-
   spawns_all_triggers___2__3__0__10(A,B,C,D).
spawns_all_triggers___2__3__1__10([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K,L),
     L==A,
     may_trigger(A),
     \+is_passive(E,B) ->
     setarg(2,H,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',M),
     delete_ht(M,k(J,A),H),
     arg(4,H,N),
     ( var(N) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns___3',O),
       O=[_|P],
       b_setval('$chr_store_global_ground_chr_translate____spawns___3',P),
       ( P=[Q|_] ->
         setarg(4,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(4,Q,N)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',R),
     delete_ht(R,k(J,K),H),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',S),
     delete_ht(S,J,H),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',T),
     delete_ht(T,A,H),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',U),
     delete_ht(U,k(J,K,A),H),
     arg(2,G,V),
     setarg(2,G,active),
     ( V==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',W),
       X=[G|W],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',X),
       ( W=[Y|_] ->
         setarg(4,Y,X)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',Z),
       insert_ht(Z,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',A1),
       insert_ht(A1,k(E,F),G)
     ;
       true
     ),
     spawns_all_triggers(J,K),
     ( G=suspension(_,active,_,_,_,_) ->
       setarg(2,G,inactive),
       spawns_all_triggers___2__3__1__10(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     spawns_all_triggers___2__3__1__10(I,A,B,C,D,E,F,G)
   ).
spawns_all_triggers___2__3(A,B,C) :-
   C=suspension(D,not_stored_yet,t,_,A,B),
   'chr gen_id'(D),
   spawns_all_triggers___2__4(A,B,C).
spawns_all_triggers___2__4(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',D),
   lookup_ht(D,A,E),
   !,
   spawns_all_triggers___2__4__0__11(E,A,B,C).
spawns_all_triggers___2__4__0__11([],A,B,C) :-
   spawns_all_triggers___2__5(A,B,C).
spawns_all_triggers___2__4__0__11([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G,H,_),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',I),
     lookup_ht(I,F,J) ->
     spawns_all_triggers___2__4__1__11(J,F,H,D,E,A,B,C)
   ;
     spawns_all_triggers___2__4__0__11(E,A,B,C)
   ).
spawns_all_triggers___2__4__1__11([],_,_,_,A,B,C,D) :-
   spawns_all_triggers___2__4__0__11(A,B,C,D).
spawns_all_triggers___2__4__1__11([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K,L),
     L==A,
     M=t(123,G,C,H),
     '$novel_production'(G,M),
     '$novel_production'(H,M),
     \+may_trigger(A),
     \+is_passive(E,B) ->
     '$extend_history'(G,M),
     arg(2,G,N),
     setarg(2,G,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',O),
       P=[G|O],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',P),
       ( O=[Q|_] ->
         setarg(4,Q,P)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',R),
       insert_ht(R,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',S),
       insert_ht(S,k(E,F),G)
     ;
       true
     ),
     spawns_all_triggers(J,K),
     ( G=suspension(_,active,_,_,_,_) ->
       setarg(2,G,inactive),
       spawns_all_triggers___2__4__1__11(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     spawns_all_triggers___2__4__1__11(I,A,B,C,D,E,F,G)
   ).
spawns_all_triggers___2__4(A,B,C) :-
   spawns_all_triggers___2__5(A,B,C).
spawns_all_triggers___2__5(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns___3',D),
   !,
   spawns_all_triggers___2__5__0__12(D,A,B,C).
spawns_all_triggers___2__5__0__12([],A,B,C) :-
   spawns_all_triggers___2__6(A,B,C).
spawns_all_triggers___2__5__0__12([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,_,G),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',H),
     lookup_ht(H,F,I) ->
     spawns_all_triggers___2__5__1__12(I,F,G,D,E,A,B,C)
   ;
     spawns_all_triggers___2__5__0__12(E,A,B,C)
   ).
spawns_all_triggers___2__5__1__12([],_,_,_,A,B,C,D) :-
   spawns_all_triggers___2__5__0__12(A,B,C,D).
spawns_all_triggers___2__5__1__12([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,_,K,L,_),
     K==A,
     M=t(125,C,H,G),
     '$novel_production'(C,M),
     '$novel_production'(G,M),
     \+is_passive(A,L),
     may_trigger(J),
     \+may_trigger(B) ->
     '$extend_history'(G,M),
     arg(2,G,N),
     setarg(2,G,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',O),
       P=[G|O],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',P),
       ( O=[Q|_] ->
         setarg(4,Q,P)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',R),
       insert_ht(R,E,G),
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',S),
       insert_ht(S,k(E,F),G)
     ;
       true
     ),
     spawns(E,F,B),
     ( G=suspension(_,active,_,_,_,_) ->
       setarg(2,G,inactive),
       spawns_all_triggers___2__5__1__12(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     spawns_all_triggers___2__5__1__12(I,A,B,C,D,E,F,G)
   ).
spawns_all_triggers___2__5(A,B,C) :-
   spawns_all_triggers___2__6(A,B,C).
spawns_all_triggers___2__6(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',E),
     F=[C|E],
     b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',F),
     ( E=[G|_] ->
       setarg(4,G,F)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',H),
     insert_ht(H,A,C),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',I),
     insert_ht(I,k(A,B),C)
   ;
     true
   ).
spawns_all_triggers_implies_spawns_all :-
   spawns_all_triggers_implies_spawns_all___0__0(_).
spawns_all_triggers_implies_spawns_all___0__0(_) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',A),
   'chr sbag_member'(B,A),
   B=suspension(_,active,_),
   !,
   setarg(2,B,removed),
   arg(3,B,C),
   ( var(C) ->
     nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',D),
     D=[_|E],
     b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',E),
     ( E=[F|_] ->
       setarg(3,F,_)
     ;
       true
     )
   ;
     C=[_,_|E],
     setarg(2,C,E),
     ( E=[F|_] ->
       setarg(3,F,C)
     ;
       true
     )
   ),
   fail.
spawns_all_triggers_implies_spawns_all___0__0(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',B),
   !,
   A=suspension(C,not_stored_yet,_),
   'chr gen_id'(C),
   spawns_all_triggers_implies_spawns_all___0__0__0__3(B,A).
spawns_all_triggers_implies_spawns_all___0__0__0__3([],A) :-
   spawns_all_triggers_implies_spawns_all___0__1(A).
spawns_all_triggers_implies_spawns_all___0__0__0__3([B|C],A) :-
   ( B=suspension(_,active,_,_,D,E) ->
     setarg(2,B,removed),
     arg(4,B,F),
     ( var(F) ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',G),
       G=[_|H],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',H),
       ( H=[I|_] ->
         setarg(4,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(4,I,F)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',J),
     delete_ht(J,D,B),
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',K),
     delete_ht(K,k(D,E),B),
     arg(2,A,L),
     setarg(2,A,active),
     ( L==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',M),
       N=[A|M],
       b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',N),
       ( M=[O|_] ->
         setarg(3,O,N)
       ;
         true
       )
     ;
       true
     ),
     spawns_all(D,E),
     ( A=suspension(_,active,_) ->
       setarg(2,A,inactive),
       spawns_all_triggers_implies_spawns_all___0__0__0__3(C,A)
     ;
       true
     )
   ;
     spawns_all_triggers_implies_spawns_all___0__0__0__3(C,A)
   ).
spawns_all_triggers_implies_spawns_all___0__0(A) :-
   A=suspension(B,not_stored_yet,_),
   'chr gen_id'(B),
   spawns_all_triggers_implies_spawns_all___0__1(A).
spawns_all_triggers_implies_spawns_all___0__1(A) :-
   arg(2,A,B),
   setarg(2,A,active),
   ( B==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',C),
     D=[A|C],
     b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',D),
     ( C=[E|_] ->
       setarg(3,E,D)
     ;
       true
     )
   ;
     true
   ).
all_spawned(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',C),
   (
     lookup_ht(C,k(A,guard),D),
     'chr sbag_member'(E,D),
     E=suspension(_,active,_,_),
     !
   ;
     lookup_ht(C,k(A,B),F),
     'chr sbag_member'(G,F),
     G=suspension(_,active,_,_),
     !
   ).
all_spawned(_,_) :-
   fail.
is_observed(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,G,_,_),
   !,
   do_is_observed(A,G,C).
is_observed(_,_,_) :-
   fail.
do_is_observed(A,B,C) :-
   var(C),
   !,
   do_is_observed(A,B).
do_is_observed(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,G,_,_),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',H),
   lookup_ht(H,G,I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_,_,K,_,_,L,_),
   J\==F,
   ground(C),
   (
     (
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',M),
       lookup_ht(M,k(B,C),N),
       'chr sbag_member'(O,N),
       O=suspension(_,active,_,_),
       \+is_passive(G,L),
       !
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',P),
       lookup_ht(P,k(B,C,K),Q),
       'chr sbag_member'(R,Q),
       R=suspension(_,active,_,_,_,_,_),
       \+is_passive(G,L),
       !
     )
   ;
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',S),
     lookup_ht(S,k(B,C),T),
     'chr sbag_member'(U,T),
     U=suspension(_,active,_,_,_,_),
     \+is_passive(G,L),
     may_trigger(K),
     !
   ).
do_is_observed(_,_,_) :-
   chr_pp_flag(observation_analysis,off).
do_is_observed(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,_,F,_,_),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',G),
   lookup_ht(G,F,H),
   'chr sbag_member'(I,H),
   I=suspension(_,active,_,_,J,_,_,K,_),
   I\==E,
   (
     (
       nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',L),
       lookup_ht(L,B,M),
       'chr sbag_member'(N,M),
       N=suspension(_,active,_,_),
       \+is_passive(F,K),
       !
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',O),
       lookup_ht(O,k(B,J),P),
       'chr sbag_member'(Q,P),
       Q=suspension(_,active,_,_,_,_,_),
       \+is_passive(F,K),
       !
     )
   ;
     nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',R),
     lookup_ht(R,B,S),
     'chr sbag_member'(T,S),
     T=suspension(_,active,_,_,_,_),
     \+is_passive(F,K),
     may_trigger(J),
     !
   ).
do_is_observed(_,_) :-
   chr_pp_flag(observation_analysis,off).
generate_indexed_variables_body(D/E,A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',F),
   lookup_ht(F,D/E,G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,_,_,I),
   !,
   get_indexing_spec(D/E,J),
   ( chr_pp_flag(term_indexing,on) ->
     spectermvars(J,A,D,E,B,C)
   ;
     get_constraint_type_det(D/E,K),
     create_indexed_variables_body(A,I,K,C,1,D/E,L,M),
     ( L==empty ->
       B=true,
       C=[]
     ;
       ( M==0 ->
         ( A=[N] ->
           true
         ;
           N=..[term|A]
         ),
         B=term_variables(N,C)
       )
     ;
       L=B
     )
   ).
generate_indexed_variables_body(A,_,_,_) :-
   chr_error(internal,'generate_indexed_variables_body: missing mode info for ~w.\n',[A]).
empty_named_history_initialisations(A,B) :-
   C=suspension(D,active,_,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',E),
   F=[C|E],
   b_setval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',F),
   ( E=[G|_] ->
     setarg(3,G,F)
   ;
     true
   ).
generate_empty_named_history_initialisation(A) :-
   generate_empty_named_history_initialisation___1__0(A,_).
generate_empty_named_history_initialisation___1__0(A,B) :-
   ( 'chr newvia_1'(A,C) ->
     get_attr(C,chr_translate,D),
     D=v(_,E,_,_,_,_,_,_,_,_,_)
   ;
     nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',E)
   ),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   G==A,
   !,
   ( var(B) ->
     true
   ;
     B=suspension(_,H,_,_,I),
     setarg(2,B,removed),
     ( H==not_stored_yet ->
       J=[]
     ;
       term_variables(I,J),
       arg(4,B,K),
       ( var(K) ->
         nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',L),
         L=[_|M],
         b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',M),
         ( M=[N|_] ->
           setarg(4,N,_)
         ;
           true
         )
       ;
         K=[_,_|M],
         setarg(2,K,M),
         ( M=[N|_] ->
           setarg(4,N,K)
         ;
           true
         )
       ),
       detach_generate_empty_named_history_initialisation___1(J,B)
     )
   ).
generate_empty_named_history_initialisation___1__0(A,B) :-
   nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',C),
   !,
   ( var(B) ->
     B=suspension(D,not_stored_yet,0,_,A),
     'chr gen_id'(D)
   ;
     true
   ),
   generate_empty_named_history_initialisation___1__0__0__3(C,A,B).
generate_empty_named_history_initialisation___1__0__0__3([],A,B) :-
   generate_empty_named_history_initialisation___1__1(A,B).
generate_empty_named_history_initialisation___1__0__0__3([C|D],A,B) :-
   ( C=suspension(_,active,_,E,F) ->
     setarg(2,C,removed),
     arg(3,C,G),
     ( var(G) ->
       nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',H),
       H=[_|I],
       b_setval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',I),
       ( I=[J|_] ->
         setarg(3,J,_)
       ;
         true
       )
     ;
       G=[_,_|I],
       setarg(2,G,I),
       ( I=[J|_] ->
         setarg(3,J,G)
       ;
         true
       )
     ),
     arg(2,B,K),
     setarg(2,B,active),
     arg(3,B,L),
     M is L+1,
     setarg(3,B,M),
     ( K==not_stored_yet ->
       B=suspension(_,_,_,_,N),
       term_variables(N,O),
       nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',P),
       Q=[B|P],
       b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',Q),
       ( P=[R|_] ->
         setarg(4,R,Q)
       ;
         true
       ),
       attach_generate_empty_named_history_initialisation___1(O,B)
     ;
       true
     ),
     empty_named_history_global_variable(A,S),
     E=[(:-nb_setval(S,0))|T],
     empty_named_history_initialisations(T,F),
     ( B=suspension(_,active,M,_,_) ->
       setarg(2,B,inactive),
       generate_empty_named_history_initialisation___1__0__0__3(D,A,B)
     ;
       true
     )
   ;
     generate_empty_named_history_initialisation___1__0__0__3(D,A,B)
   ).
generate_empty_named_history_initialisation___1__0(A,B) :-
   ( var(B) ->
     B=suspension(C,not_stored_yet,0,_,A),
     'chr gen_id'(C)
   ;
     true
   ),
   generate_empty_named_history_initialisation___1__1(A,B).
generate_empty_named_history_initialisation___1__1(_,A) :-
   arg(2,A,B),
   setarg(2,A,active),
   arg(3,A,C),
   D is C+1,
   setarg(3,A,D),
   ( B==not_stored_yet ->
     A=suspension(_,_,_,_,E),
     term_variables(E,F),
     nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',G),
     H=[A|G],
     b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',H),
     ( G=[I|_] ->
       setarg(4,I,H)
     ;
       true
     ),
     attach_generate_empty_named_history_initialisation___1(F,A)
   ;
     true
   ).
find_empty_named_histories :-
   find_empty_named_histories___0__0(_).
find_empty_named_histories___0__0(A) :-
   nb_getval('$chr_store_constants_chr_translate____history___3___[3]___[]',B),
   !,
   A=suspension(C,not_stored_yet,t,_),
   'chr gen_id'(C),
   find_empty_named_histories___0__0__0__1(B,A).
find_empty_named_histories___0__0__0__1([],A) :-
   find_empty_named_histories___0__1(A).
find_empty_named_histories___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,_,D,E),
     E=[],
     F=t(142,A,B),
     '$novel_production'(A,F),
     '$novel_production'(B,F) ->
     '$extend_history'(A,F),
     arg(2,A,G),
     setarg(2,A,active),
     ( G==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',H),
       I=[A|H],
       b_setval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',I),
       ( H=[J|_] ->
         setarg(4,J,I)
       ;
         true
       )
     ;
       true
     ),
     generate_empty_named_history_initialisation(D),
     ( A=suspension(_,active,_,_) ->
       setarg(2,A,inactive),
       find_empty_named_histories___0__0__0__1(C,A)
     ;
       true
     )
   ;
     find_empty_named_histories___0__0__0__1(C,A)
   ).
find_empty_named_histories___0__0(A) :-
   A=suspension(B,not_stored_yet,t,_),
   'chr gen_id'(B),
   find_empty_named_histories___0__1(A).
find_empty_named_histories___0__1(A) :-
   nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',B),
   !,
   find_empty_named_histories___0__1__0__2(B,A).
find_empty_named_histories___0__1__0__2([],A) :-
   find_empty_named_histories___0__2(A).
find_empty_named_histories___0__1__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_,_) ->
     B=suspension(_,_,_,_,D),
     setarg(2,B,removed),
     term_variables(D,E),
     arg(4,B,F),
     ( var(F) ->
       nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',G),
       G=[_|H],
       b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',H),
       ( H=[I|_] ->
         setarg(4,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(4,I,F)
       ;
         true
       )
     ),
     detach_generate_empty_named_history_initialisation___1(E,B),
     find_empty_named_histories___0__1__0__2(C,A)
   ;
     find_empty_named_histories___0__1__0__2(C,A)
   ).
find_empty_named_histories___0__1(A) :-
   find_empty_named_histories___0__2(A).
find_empty_named_histories___0__2(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D,E),
   !,
   setarg(2,C,removed),
   arg(3,C,F),
   ( var(F) ->
     nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',G),
     G=[_|H],
     b_setval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',H),
     ( H=[I|_] ->
       setarg(3,I,_)
     ;
       true
     )
   ;
     F=[_,_|H],
     setarg(2,F,H),
     ( H=[I|_] ->
       setarg(3,I,F)
     ;
       true
     )
   ),
   ( var(A) ->
     true
   ;
     arg(2,A,J),
     setarg(2,A,removed),
     ( J==not_stored_yet ->
       true
     ;
       arg(4,A,K),
       ( var(K) ->
         nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',L),
         L=[_|M],
         b_setval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',M),
         ( M=[N|_] ->
           setarg(4,N,_)
         ;
           true
         )
       ;
         K=[_,_|M],
         setarg(2,K,M),
         ( M=[N|_] ->
           setarg(4,N,K)
         ;
           true
         )
       )
     )
   ),
   D=E.
find_empty_named_histories___0__2(A) :-
   ( var(A) ->
     true
   ;
     arg(2,A,B),
     setarg(2,A,removed),
     ( B==not_stored_yet ->
       true
     ;
       arg(4,A,C),
       ( var(C) ->
         nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',D),
         D=[_|E],
         b_setval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',E),
         ( E=[F|_] ->
           setarg(4,F,_)
         ;
           true
         )
       ;
         C=[_,_|E],
         setarg(2,C,E),
         ( E=[F|_] ->
           setarg(4,F,C)
         ;
           true
         )
       )
     )
   ),
   chr_error(internal,'find_empty_named_histories was not removed',[]).
module_initializer(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____module_initializer___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
module_initializers(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____module_initializer___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   A= (D,I),
   module_initializers(I).
module_initializers(true).
actual_atomic_multi_hash_keys(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,G),
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',H),
   lookup_ht(H,A,I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',K),
   delete_ht(K,A,F),
   selectchk(multi_hash([B]),G,L),
   B=[M],
   ( get_constraint_arg_type(A,M,N),
     enumerated_atomic_type(N,O) ->
     P=O,
     Q=complete
   ;
     P=C,
     Q=incomplete
   ),
   actual_store_types(A,[atomic_constants(B,P,Q)|L]).
actual_atomic_multi_hash_keys(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',H),
   delete_ht(H,k(A,B),F),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',I),
   delete_ht(I,A,F),
   append(C,G,J),
   sort(J,K),
   actual_atomic_multi_hash_keys(A,B,K).
actual_atomic_multi_hash_keys(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',H),
   delete_ht(H,k(A,B),F),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',I),
   delete_ht(I,A,F),
   append(G,C,J),
   sort(J,K),
   actual_ground_multi_hash_keys(A,B,K).
actual_atomic_multi_hash_keys(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
actual_atomic_multi_hash_keys(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',F),
   insert_ht(F,k(A,B),D),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',G),
   insert_ht(G,A,D).
actual_ground_multi_hash_keys(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,G),
   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',H),
   lookup_ht(H,A,I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',K),
   delete_ht(K,A,F),
   ( B=[L],
     get_constraint_arg_type(A,L,M),
     M=chr_enum(N) ->
     O=complete
   ;
     N=C,
     O=incomplete
   ),
   selectchk(multi_hash([B]),G,P),
   actual_store_types(A,[ground_constants(B,N,O)|P]).
actual_ground_multi_hash_keys(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',H),
   delete_ht(H,k(A,B),F),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',I),
   delete_ht(I,A,F),
   append(C,G,J),
   sort(J,K),
   actual_ground_multi_hash_keys(A,B,K).
actual_ground_multi_hash_keys(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',H),
   delete_ht(H,k(A,B),F),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',I),
   delete_ht(I,A,F),
   append(C,G,J),
   sort(J,K),
   actual_ground_multi_hash_keys(A,B,K).
actual_ground_multi_hash_keys(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
actual_ground_multi_hash_keys(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',F),
   insert_ht(F,k(A,B),D),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',G),
   insert_ht(G,A,D).
actual_non_ground_multi_hash_key(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
actual_non_ground_multi_hash_key(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',C),
   lookup_ht(C,k(A,B),D),
   !,
   actual_non_ground_multi_hash_key___2__0__0__3(D,A,B).
actual_non_ground_multi_hash_key___2__0__0__3([],A,B) :-
   actual_non_ground_multi_hash_key___2__1(A,B).
actual_non_ground_multi_hash_key___2__0__0__3([C|D],A,B) :-
   ( C=suspension(_,active,E,F,_),
     E==A,
     F==B ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',G),
     delete_ht(G,k(A,B),C),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',H),
     delete_ht(H,A,C),
     actual_non_ground_multi_hash_key___2__0__0__3(D,A,B)
   ;
     actual_non_ground_multi_hash_key___2__0__0__3(D,A,B)
   ).
actual_non_ground_multi_hash_key(A,B) :-
   actual_non_ground_multi_hash_key___2__1(A,B).
actual_non_ground_multi_hash_key___2__1(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',C),
   lookup_ht(C,k(A,B),D),
   !,
   actual_non_ground_multi_hash_key___2__1__0__4(D,A,B).
actual_non_ground_multi_hash_key___2__1__0__4([],A,B) :-
   actual_non_ground_multi_hash_key___2__2(A,B).
actual_non_ground_multi_hash_key___2__1__0__4([C|D],A,B) :-
   ( C=suspension(_,active,E,F,_),
     E==A,
     F==B ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',G),
     delete_ht(G,k(A,B),C),
     nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',H),
     delete_ht(H,A,C),
     actual_non_ground_multi_hash_key___2__1__0__4(D,A,B)
   ;
     actual_non_ground_multi_hash_key___2__1__0__4(D,A,B)
   ).
actual_non_ground_multi_hash_key___2__1(A,B) :-
   actual_non_ground_multi_hash_key___2__2(A,B).
actual_non_ground_multi_hash_key___2__2(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',E),
   insert_ht(E,k(A,B),C).
symbol_count(A,B) :-
   symbol_count___2__0(A,B,_).
symbol_count___2__0(A,B,C) :-
   ( 'chr newvia_1'(A,D) ->
     get_attr(D,chr_translate,E),
     E=v(_,_,_,F,_,_,_,_,_,_,_)
   ;
     nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',F)
   ),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,_,H,I),
   H==A,
   !,
   G=suspension(_,_,_,_,_,J,_),
   setarg(2,G,removed),
   term_variables(J,K),
   arg(5,G,L),
   ( var(L) ->
     nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',M),
     M=[_|N],
     b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',N),
     ( N=[O|_] ->
       setarg(5,O,_)
     ;
       true
     )
   ;
     L=[_,_|N],
     setarg(2,L,N),
     ( N=[O|_] ->
       setarg(5,O,L)
     ;
       true
     )
   ),
   detach_fresh_symbol___2(K,G),
   ( var(C) ->
     true
   ;
     C=suspension(_,_,_,P,_),
     setarg(2,C,removed),
     term_variables(P,Q),
     arg(3,C,R),
     ( var(R) ->
       nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',S),
       S=[_|T],
       b_setval('$chr_store_global_list_chr_translate____symbol_count___2',T),
       ( T=[U|_] ->
         setarg(3,U,_)
       ;
         true
       )
     ;
       R=[_,_|T],
       setarg(2,R,T),
       ( T=[U|_] ->
         setarg(3,U,R)
       ;
         true
       )
     ),
     detach_symbol_count___2(Q,C)
   ),
   atom_concat(A,B,I),
   V is B+1,
   symbol_count(A,V).
symbol_count___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,active,_,A,B),
     term_variables(A,E),
     'chr gen_id'(D),
     nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',F),
     G=[C|F],
     b_setval('$chr_store_global_list_chr_translate____symbol_count___2',G),
     ( F=[H|_] ->
       setarg(3,H,G)
     ;
       true
     ),
     attach_symbol_count___2(E,C)
   ;
     setarg(2,C,active)
   ).
fresh_symbol(A,B) :-
   fresh_symbol___2__0(A,B,_).
fresh_symbol___2__0(A,B,C) :-
   ( 'chr newvia_1'(A,D) ->
     get_attr(D,chr_translate,E),
     E=v(_,_,F,_,_,_,_,_,_,_,_)
   ;
     nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',F)
   ),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,H,I),
   H==A,
   !,
   G=suspension(_,_,_,J,_),
   setarg(2,G,removed),
   term_variables(J,K),
   arg(3,G,L),
   ( var(L) ->
     nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',M),
     M=[_|N],
     b_setval('$chr_store_global_list_chr_translate____symbol_count___2',N),
     ( N=[O|_] ->
       setarg(3,O,_)
     ;
       true
     )
   ;
     L=[_,_|N],
     setarg(2,L,N),
     ( N=[O|_] ->
       setarg(3,O,L)
     ;
       true
     )
   ),
   detach_symbol_count___2(K,G),
   ( var(C) ->
     true
   ;
     C=suspension(_,P,_,_,_,Q,_),
     setarg(2,C,removed),
     ( P==not_stored_yet ->
       R=[]
     ;
       term_variables(Q,R),
       arg(5,C,S),
       ( var(S) ->
         nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',T),
         T=[_|U],
         b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',U),
         ( U=[V|_] ->
           setarg(5,V,_)
         ;
           true
         )
       ;
         S=[_,_|U],
         setarg(2,S,U),
         ( U=[V|_] ->
           setarg(5,V,S)
         ;
           true
         )
       ),
       detach_fresh_symbol___2(R,C)
     )
   ),
   atom_concat(A,I,B),
   W is I+1,
   symbol_count(A,W).
fresh_symbol___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(D)
   ;
     true
   ),
   (
     '$novel_production'(C,157),
     !,
     '$extend_history'(C,157),
     arg(2,C,E),
     setarg(2,C,active),
     arg(4,C,F),
     G is F+1,
     setarg(4,C,G),
     ( E==not_stored_yet ->
       C=suspension(_,_,_,_,_,H,_),
       term_variables(H,I),
       nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',J),
       K=[C|J],
       b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',K),
       ( J=[L|_] ->
         setarg(5,L,K)
       ;
         true
       ),
       attach_fresh_symbol___2(I,C)
     ;
       true
     ),
     symbol_count(A,0),
     ( C=suspension(_,active,_,G,_,_,_) ->
       setarg(2,C,inactive),
       fresh_symbol___2__1(A,B,C)
     ;
       true
     )
   ;
     fresh_symbol___2__1(A,B,C)
   ).
fresh_symbol___2__1(_,_,A) :-
   arg(2,A,B),
   setarg(2,A,active),
   arg(4,A,C),
   D is C+1,
   setarg(4,A,D),
   ( B==not_stored_yet ->
     A=suspension(_,_,_,_,_,E,_),
     term_variables(E,F),
     nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',G),
     H=[A|G],
     b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',H),
     ( G=[I|_] ->
       setarg(5,I,H)
     ;
       true
     ),
     attach_fresh_symbol___2(F,A)
   ;
     true
   ).
prolog_global_variable(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !.
prolog_global_variable(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ),
   nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',G),
   insert_ht(G,A,B).
prolog_global_variables(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',I),
   delete_ht(I,D,C),
   A=[D|J],
   prolog_global_variables(J).
prolog_global_variables([]).
background_info(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____background_info___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____background_info___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____background_info___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   append(A,D,I),
   background_info(I).
background_info(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____background_info___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____background_info___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
background_info(A,B) :-
   background_info___2__0(A,B,_).
background_info___2__0(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',D),
   !,
   ( var(C) ->
     C=suspension(E,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(E)
   ;
     true
   ),
   background_info___2__0__0__1(D,A,B,C).
background_info___2__0__0__1([],A,B,C) :-
   background_info___2__1(A,B,C).
background_info___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,_,F,_),
     G=t(164,C,D),
     '$novel_production'(C,G),
     '$novel_production'(D,G),
     copy_term_nat(A,H),
     subsumes_chk(H,F) ->
     '$extend_history'(C,G),
     arg(2,C,I),
     setarg(2,C,active),
     arg(4,C,J),
     K is J+1,
     setarg(4,C,K),
     ( I==not_stored_yet ->
       C=suspension(_,_,_,_,_,L,_),
       term_variables(L,M),
       nb_getval('$chr_store_global_list_chr_translate____background_info___2',N),
       O=[C|N],
       b_setval('$chr_store_global_list_chr_translate____background_info___2',O),
       ( N=[P|_] ->
         setarg(5,P,O)
       ;
         true
       ),
       attach_background_info___2(M,C)
     ;
       true
     ),
     copy_term_nat(A-B,F-Q),
     get_bg_info_answer([Q]),
     ( C=suspension(_,active,_,K,_,_,_) ->
       setarg(2,C,inactive),
       background_info___2__0__0__1(E,A,B,C)
     ;
       true
     )
   ;
     background_info___2__0__0__1(E,A,B,C)
   ).
background_info___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(D)
   ;
     true
   ),
   background_info___2__1(A,B,C).
background_info___2__1(_,_,A) :-
   arg(2,A,B),
   setarg(2,A,active),
   arg(4,A,C),
   D is C+1,
   setarg(4,A,D),
   ( B==not_stored_yet ->
     A=suspension(_,_,_,_,_,E,_),
     term_variables(E,F),
     nb_getval('$chr_store_global_list_chr_translate____background_info___2',G),
     H=[A|G],
     b_setval('$chr_store_global_list_chr_translate____background_info___2',H),
     ( G=[I|_] ->
       setarg(5,I,H)
     ;
       true
     ),
     attach_background_info___2(F,A)
   ;
     true
   ).
get_bg_info(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____background_info___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   A=D.
get_bg_info([]).
get_bg_info(A,B) :-
   get_bg_info___2__0(A,B,_).
get_bg_info___2__0(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____background_info___2',D),
   !,
   ( var(C) ->
     C=suspension(E,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(E)
   ;
     true
   ),
   get_bg_info___2__0__0__1(D,A,B,C).
get_bg_info___2__0__0__1([],A,B,C) :-
   get_bg_info___2__1(A,B,C).
get_bg_info___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,_,F,G),
     H=t(164,D,C),
     '$novel_production'(D,H),
     '$novel_production'(C,H),
     copy_term_nat(F,I),
     subsumes_chk(I,A) ->
     '$extend_history'(C,H),
     arg(2,C,J),
     setarg(2,C,active),
     arg(4,C,K),
     L is K+1,
     setarg(4,C,L),
     ( J==not_stored_yet ->
       C=suspension(_,_,_,_,_,M,_),
       term_variables(M,N),
       nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',O),
       P=[C|O],
       b_setval('$chr_store_global_list_chr_translate____get_bg_info___2',P),
       ( O=[Q|_] ->
         setarg(5,Q,P)
       ;
         true
       ),
       attach_get_bg_info___2(N,C)
     ;
       true
     ),
     copy_term_nat(F-G,A-R),
     get_bg_info_answer([R]),
     ( C=suspension(_,active,_,L,_,_,_) ->
       setarg(2,C,inactive),
       get_bg_info___2__0__0__1(E,A,B,C)
     ;
       true
     )
   ;
     get_bg_info___2__0__0__1(E,A,B,C)
   ).
get_bg_info___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(D)
   ;
     true
   ),
   get_bg_info___2__1(A,B,C).
get_bg_info___2__1(_,A,B) :-
   nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,E),
   !,
   setarg(2,D,removed),
   arg(3,D,F),
   ( var(F) ->
     nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',G),
     G=[_|H],
     b_setval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',H),
     ( H=[I|_] ->
       setarg(3,I,_)
     ;
       true
     )
   ;
     F=[_,_|H],
     setarg(2,F,H),
     ( H=[I|_] ->
       setarg(3,I,F)
     ;
       true
     )
   ),
   ( var(B) ->
     true
   ;
     B=suspension(_,J,_,_,_,K,_),
     setarg(2,B,removed),
     ( J==not_stored_yet ->
       L=[]
     ;
       term_variables(K,L),
       arg(5,B,M),
       ( var(M) ->
         nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',N),
         N=[_|O],
         b_setval('$chr_store_global_list_chr_translate____get_bg_info___2',O),
         ( O=[P|_] ->
           setarg(5,P,_)
         ;
           true
         )
       ;
         M=[_,_|O],
         setarg(2,M,O),
         ( O=[P|_] ->
           setarg(5,P,M)
         ;
           true
         )
       ),
       detach_get_bg_info___2(L,B)
     )
   ),
   A=E.
get_bg_info___2__1(_,A,B) :-
   ( var(B) ->
     true
   ;
     B=suspension(_,C,_,_,_,D,_),
     setarg(2,B,removed),
     ( C==not_stored_yet ->
       E=[]
     ;
       term_variables(D,E),
       arg(5,B,F),
       ( var(F) ->
         nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',G),
         G=[_|H],
         b_setval('$chr_store_global_list_chr_translate____get_bg_info___2',H),
         ( H=[I|_] ->
           setarg(5,I,_)
         ;
           true
         )
       ;
         F=[_,_|H],
         setarg(2,F,H),
         ( H=[I|_] ->
           setarg(5,I,F)
         ;
           true
         )
       ),
       detach_get_bg_info___2(E,B)
     )
   ),
   A=[].
get_bg_info_answer(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   append(A,D,I),
   get_bg_info_answer(I).
get_bg_info_answer(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
prev_guard_list(A,B,C,D,E,F,G,H) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',I),
   lookup_ht(I,B,J),
   'chr sbag_member'(K,J),
   K=suspension(_,active,_,_,_,L),
   L=pragma(rule(M,N,O,_),_,_,_,_),
   M\==[],
   make_head_matchings_explicit(B,P,Q),
   setof(R,chr_translate:head_subset(P,D,R),S),
   !,
   append(M,N,T),
   compute_derived_info(S,Q,P,T,O,G,D,H,U,V),
   append(F,U,W),
   normalize_conj_list(W,X),
   append(V,H,Y),
   normalize_conj_list(Y,Z),
   next_prev_rule(C,A1,B1),
   prev_guard_list(A,A1,B1,D,E,X,G,Z).
prev_guard_list(A,B,C,D,E,F,G,H) :-
   ( B>0 ->
     next_prev_rule(C,I,J),
     prev_guard_list(A,I,J,D,E,F,G,H)
   ;
     prev_guard_list(A,D,E,F,G,H)
   ).
prev_guard_list(A,B,C,D,E,F) :-
   prev_guard_list___6__0(A,B,C,D,E,F,_).
prev_guard_list___6__0(A,B,C,D,E,F,_) :-
   F\==[],
   !,
   head_types_modes_condition(F,B,G),
   conj2list(G,H),
   term_variables(B,I),
   append([chr_pp_headvariables(I)|H],D,J),
   normalize_conj_list(J,K),
   append(B,K,L),
   add_background_info([C|L],M),
   append(K,M,N),
   normalize_conj_list(N,O),
   prev_guard_list(A,B,C,O,E,[]).
prev_guard_list___6__0(A,B,C,D,E,F,G) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',H),
   lookup_ht(H,A,I),
   (
     'chr sbag_member'(J,I),
     J=suspension(_,active,_,_,_,K),
     K=pragma(rule(O,P,C,Q),L,M,N,A),
     C\==true,
     append(E,D,R),
     ( conj2list(C,S),
       append(R,S,T),
       guard_entailment:entails_guard(T,fail) ->
       U=fail
     ;
       simplify_guard(C,Q,R,U,V)
     ),
     C\==U,
     !,
     setarg(2,J,removed),
     arg(4,J,W),
     ( var(W) ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',X),
       X=[_|Y],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',Y),
       ( Y=[Z|_] ->
         setarg(4,Z,_)
       ;
         true
       )
     ;
       W=[_,_|Y],
       setarg(2,W,Y),
       ( Y=[Z|_] ->
         setarg(4,Z,W)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',A1),
     delete_ht(A1,A,J),
     rule(A,pragma(rule(O,P,U,V),L,M,N,A)),
     prev_guard_list(A,B,U,D,E,[])
   ;
     !,
     G=suspension(B1,not_stored_yet,t,_,A,B,C,D,E,F),
     'chr gen_id'(B1),
     prev_guard_list___6__0__0__3(I,A,B,C,D,E,F,G)
   ).
prev_guard_list___6__0__0__3([],A,B,C,D,E,F,G) :-
   prev_guard_list___6__1(A,B,C,D,E,F,G).
prev_guard_list___6__0__0__3([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K),
     J==A,
     L=t(178,G,H),
     '$novel_production'(G,L),
     '$novel_production'(H,L),
     chr_pp_flag(check_impossible_rules,on),
     K=pragma(rule(_,_,C,_),_,_,_,A),
     conj2list(C,M),
     append(E,D,N),
     append(N,M,O),
     guard_entailment:entails_guard(O,fail) ->
     '$extend_history'(G,L),
     arg(2,G,P),
     setarg(2,G,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',Q),
       R=[G|Q],
       b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',R),
       ( Q=[S|_] ->
         setarg(4,S,R)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',T),
       insert_ht(T,A,G)
     ;
       true
     ),
     chr_warning(weird_program,'Heads will never match or guard will always fail in ~@.\n\tThis rule will never fire!\n',[format_rule(K)]),
     set_all_passive(A),
     ( G=suspension(_,active,_,_,_,_,_,_,_,_) ->
       setarg(2,G,inactive),
       prev_guard_list___6__0__0__3(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     prev_guard_list___6__0__0__3(I,A,B,C,D,E,F,G)
   ).
prev_guard_list___6__0(A,B,C,D,E,F,G) :-
   G=suspension(H,not_stored_yet,t,_,A,B,C,D,E,F),
   'chr gen_id'(H),
   prev_guard_list___6__1(A,B,C,D,E,F,G).
prev_guard_list___6__1(A,B,C,D,E,F,G) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',H),
   lookup_ht(H,A,I),
   !,
   prev_guard_list___6__1__0__4(I,A,B,C,D,E,F,G).
prev_guard_list___6__1__0__4([],A,B,C,D,E,F,G) :-
   prev_guard_list___6__2(A,B,C,D,E,F,G).
prev_guard_list___6__1__0__4([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K),
     J==A,
     K=pragma(rule(O,P,C,Q),L,M,N,A),
     simplify_heads(E,D,C,Q,R,S),
     R\==[],
     extract_arguments(O,T),
     extract_arguments(P,U),
     extract_arguments(B,V),
     replace_some_heads(T,U,V,R,W,X,C,Q,Y),
     substitute_arguments(O,W,Z),
     substitute_arguments(P,X,A1),
     append(S,Y,B1),
     list2conj(B1,C1),
     D1=pragma(rule(Z,A1,C,(C1,Q)),L,M,N,A),
     (
       O\==Z
     ;
       P\==A1
     ) ->
     setarg(2,H,removed),
     arg(4,H,E1),
     ( var(E1) ->
       nb_getval('$chr_store_global_ground_chr_translate____rule___2',F1),
       F1=[_|G1],
       b_setval('$chr_store_global_ground_chr_translate____rule___2',G1),
       ( G1=[H1|_] ->
         setarg(4,H1,_)
       ;
         true
       )
     ;
       E1=[_,_|G1],
       setarg(2,E1,G1),
       ( G1=[H1|_] ->
         setarg(4,H1,E1)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',I1),
     delete_ht(I1,A,H),
     arg(2,G,J1),
     setarg(2,G,active),
     ( J1==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',K1),
       L1=[G|K1],
       b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',L1),
       ( K1=[M1|_] ->
         setarg(4,M1,L1)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',N1),
       insert_ht(N1,A,G)
     ;
       true
     ),
     rule(A,D1),
     ( G=suspension(_,active,_,_,_,_,_,_,_,_) ->
       setarg(2,G,inactive),
       prev_guard_list___6__1__0__4(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     prev_guard_list___6__1__0__4(I,A,B,C,D,E,F,G)
   ).
prev_guard_list___6__1(A,B,C,D,E,F,G) :-
   prev_guard_list___6__2(A,B,C,D,E,F,G).
prev_guard_list___6__2(A,B,C,D,E,F,G) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',H),
   lookup_ht(H,A,I),
   !,
   prev_guard_list___6__2__0__5(I,A,B,C,D,E,F,G).
prev_guard_list___6__2__0__5([],A,B,C,D,E,F,G) :-
   prev_guard_list___6__3(A,B,C,D,E,F,G).
prev_guard_list___6__2__0__5([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K),
     J==A,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',L),
     lookup_ht(L,A,M) ->
     prev_guard_list___6__2__1__5(M,K,H,I,A,B,C,D,E,F,G)
   ;
     prev_guard_list___6__2__0__5(I,A,B,C,D,E,F,G)
   ).
prev_guard_list___6__2__1__5([],_,_,A,B,C,D,E,F,G,H) :-
   prev_guard_list___6__2__0__5(A,B,C,D,E,F,G,H).
prev_guard_list___6__2__1__5([K|L],A,B,C,D,E,F,G,H,I,J) :-
   ( K=suspension(_,active,_,_,M,N,O,_,_),
     O==D,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',P),
     lookup_ht(P,k(M,D),Q) ->
     prev_guard_list___6__2__2__5(Q,M,N,K,L,A,B,C,D,E,F,G,H,I,J)
   ;
     prev_guard_list___6__2__1__5(L,A,B,C,D,E,F,G,H,I,J)
   ).
prev_guard_list___6__2__2__5([],_,_,_,A,B,C,D,E,F,G,H,I,J,K) :-
   prev_guard_list___6__2__1__5(A,B,C,D,E,F,G,H,I,J,K).
prev_guard_list___6__2__2__5([O|P],A,B,C,D,E,F,G,H,I,J,K,L,M,N) :-
   ( O=suspension(_,active,_,_,Q,R,S,T,_),
     O\==C,
     Q==A,
     S==H,
     nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',U) ->
     prev_guard_list___6__2__3__5(U,R,T,O,P,A,B,C,D,E,F,G,H,I,J,K,L,M,N)
   ;
     prev_guard_list___6__2__2__5(P,A,B,C,D,E,F,G,H,I,J,K,L,M,N)
   ).
prev_guard_list___6__2__3__5([],_,_,_,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) :-
   prev_guard_list___6__2__2__5(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O).
prev_guard_list___6__2__3__5([S|T],A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R) :-
   ( S=suspension(_,active,_,U),
     A<F,
     chr_pp_flag(occurrence_subsumption,on),
     I=pragma(rule(V,_,_,_),_,_,_,_),
     V\==[],
     \+tree_set_memberchk(E,U) ->
     setarg(2,S,removed),
     arg(3,S,W),
     ( var(W) ->
       nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',X),
       X=[_|Y],
       b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',Y),
       ( Y=[Z|_] ->
         setarg(3,Z,_)
       ;
         true
       )
     ;
       W=[_,_|Y],
       setarg(2,W,Y),
       ( Y=[Z|_] ->
         setarg(3,Z,W)
       ;
         true
       )
     ),
     arg(2,R,A1),
     setarg(2,R,active),
     ( A1==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',B1),
       C1=[R|B1],
       b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',C1),
       ( B1=[D1|_] ->
         setarg(4,D1,C1)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',E1),
       insert_ht(E1,L,R)
     ;
       true
     ),
     first_occ_in_rule(L,E,A,B),
     tree_set_add(U,E,F1),
     multiple_occ_constraints_checked(F1),
     ( R=suspension(_,active,_,_,_,_,_,_,_,_) ->
       setarg(2,R,inactive),
       prev_guard_list___6__2__3__5(T,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R)
     ;
       true
     )
   ;
     prev_guard_list___6__2__3__5(T,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R)
   ).
prev_guard_list___6__2(A,B,C,D,E,F,G) :-
   prev_guard_list___6__3(A,B,C,D,E,F,G).
prev_guard_list___6__3(A,_,_,_,_,_,B) :-
   nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !,
   setarg(2,D,removed),
   arg(3,D,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   ( var(B) ->
     true
   ;
     arg(2,B,I),
     setarg(2,B,removed),
     ( I==not_stored_yet ->
       true
     ;
       arg(4,B,J),
       ( var(J) ->
         nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',K),
         K=[_|L],
         b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',L),
         ( L=[M|_] ->
           setarg(4,M,_)
         ;
           true
         )
       ;
         J=[_,_|L],
         setarg(2,J,L),
         ( L=[M|_] ->
           setarg(4,M,J)
         ;
           true
         )
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',N),
       delete_ht(N,A,B)
     )
   ).
prev_guard_list___6__3(A,_,_,_,_,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',D),
     E=[B|D],
     b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',E),
     ( D=[F|_] ->
       setarg(4,F,E)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',G),
     insert_ht(G,A,B)
   ;
     true
   ).
simplify_guards(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E),
   !,
   E=pragma(rule(F,G,H,_),ids(I,J),_,_,A),
   append(F,G,K),
   make_head_matchings_explicit_not_negated(K,L,M),
   tree_set_empty(N),
   multiple_occ_constraints_checked(N),
   apply_guard_wrt_term(K,H,O),
   append(I,J,P),
   findall(tuple(R,S,A)- (-A),(member(T,P),get_occurrence_from_id(R,S,A,T)),Q),
   empty_q(U),
   insert_list_q(Q,U,V),
   next_prev_rule(V,_,W),
   next_prev_rule(W,X,Y),
   prev_guard_list(A,X,Y,L,H,[],M,[O]),
   Z is A+1,
   simplify_guards(Z).
simplify_guards(_).
set_all_passive(A) :-
   set_all_passive___1__0(A,_).
set_all_passive___1__0(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',C),
   lookup_ht(C,A,D),
   !,
   B=suspension(E,not_stored_yet,t,A),
   'chr gen_id'(E),
   set_all_passive___1__0__0__1(D,A,B).
set_all_passive___1__0__0__1([],A,B) :-
   set_all_passive___1__1(A,B).
set_all_passive___1__0__0__1([C|D],A,B) :-
   ( C=suspension(_,active,_,_,_,_,E,F,_),
     E==A,
     G=t(180,B,C),
     '$novel_production'(B,G),
     '$novel_production'(C,G) ->
     '$extend_history'(B,G),
     arg(2,B,H),
     setarg(2,B,active),
     ( H==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',I),
       insert_ht(I,A,B)
     ;
       true
     ),
     passive(A,F),
     ( B=suspension(_,active,_,_) ->
       setarg(2,B,inactive),
       set_all_passive___1__0__0__1(D,A,B)
     ;
       true
     )
   ;
     set_all_passive___1__0__0__1(D,A,B)
   ).
set_all_passive___1__0(A,B) :-
   B=suspension(C,not_stored_yet,t,A),
   'chr gen_id'(C),
   set_all_passive___1__1(A,B).
set_all_passive___1__1(A,B) :-
   ( var(B) ->
     true
   ;
     arg(2,B,C),
     setarg(2,B,removed),
     ( C==not_stored_yet ->
       true
     ;
       nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',D),
       delete_ht(D,A,B)
     )
   ).
precompute_head_matchings :-
   precompute_head_matchings___0__0(_).
precompute_head_matchings___0__0(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____rule___2',B),
   !,
   A=suspension(C,not_stored_yet,t,_),
   'chr gen_id'(C),
   precompute_head_matchings___0__0__0__1(B,A).
precompute_head_matchings___0__0__0__1([],A) :-
   precompute_head_matchings___0__1(A).
precompute_head_matchings___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,_,D,E),
     F=t(174,B,A),
     '$novel_production'(B,F),
     '$novel_production'(A,F) ->
     '$extend_history'(A,F),
     arg(2,A,G),
     setarg(2,A,active),
     ( G==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',H),
       I=[A|H],
       b_setval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',I),
       ( H=[J|_] ->
         setarg(4,J,I)
       ;
         true
       )
     ;
       true
     ),
     E=pragma(rule(K,L,_,_),_,_,_,_),
     append(K,L,M),
     make_head_matchings_explicit_(M,N,O),
     copy_term_nat(N-O,P-Q),
     make_head_matchings_explicit_memo_table(D,P,Q),
     ( A=suspension(_,active,_,_) ->
       setarg(2,A,inactive),
       precompute_head_matchings___0__0__0__1(C,A)
     ;
       true
     )
   ;
     precompute_head_matchings___0__0__0__1(C,A)
   ).
precompute_head_matchings___0__0(A) :-
   A=suspension(B,not_stored_yet,t,_),
   'chr gen_id'(B),
   precompute_head_matchings___0__1(A).
precompute_head_matchings___0__1(A) :-
   ( var(A) ->
     true
   ;
     arg(2,A,B),
     setarg(2,A,removed),
     ( B==not_stored_yet ->
       true
     ;
       arg(4,A,C),
       ( var(C) ->
         nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',D),
         D=[_|E],
         b_setval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',E),
         ( E=[F|_] ->
           setarg(4,F,_)
         ;
           true
         )
       ;
         C=[_,_|E],
         setarg(2,C,E),
         ( E=[F|_] ->
           setarg(4,F,C)
         ;
           true
         )
       )
     )
   ).
make_head_matchings_explicit_memo_table(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',F),
   insert_ht(F,A,D).
make_head_matchings_explicit_memo_lookup(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,G,H),
   !,
   B=G,
   C=H.
make_head_matchings_explicit_memo_lookup(_,_,_) :-
   fail.
first_occ_in_rule(A,B,C,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',D),
   lookup_ht(D,k(B,A),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,G,_,H,_),
   G<C,
   !,
   first_occ_in_rule(A,B,G,H).
first_occ_in_rule(A,B,C,D) :-
   B=E/F,
   functor(G,E,F),
   next_occ_in_rule(A,B,C,D,[],G).
next_occ_in_rule(A,B,C,D,_,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',F),
   lookup_ht(F,A,G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,_,I),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',J),
   lookup_ht(J,k(B,A,I),K),
   'chr sbag_member'(L,K),
   L=suspension(_,active,_,_,_,M,_,_,_),
   M is C+1,
   !,
   next_occ_in_rule(A,B,M,D,_,E).
next_occ_in_rule(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',G),
   lookup_ht(G,A,H),
   'chr sbag_member'(I,H),
   I=suspension(_,active,_,_,_,J,K,L,M,_),
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',N),
   lookup_ht(N,A,O),
   'chr sbag_member'(P,O),
   P=suspension(_,active,_,_,_,Q),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',R),
   lookup_ht(R,k(B,A),S),
   'chr sbag_member'(T,S),
   T=suspension(_,active,_,_,_,U,_,V,_),
   U is C+1,
   Q=pragma(rule(W,X,K,_),ids(_,_),_,_,A),
   !,
   append(W,X,Y),
   add_failing_occ(Q,Y,J,D,Z,F,M,B,A1),
   ( Z==[chr_pp_void_info] ->
     next_occ_in_rule(A,B,U,V,E,F)
   ;
     append(Z,E,B1),
     add_failing_occ(Q,Y,J,V,C1,F,M,B,D1),
     copy_term(L,E1),
     variable_replacement(L,E1,F1),
     copy_with_variable_replacement(L,G1,A1),
     copy_with_variable_replacement(L,H1,D1),
     copy_with_variable_replacement(H1,I1,F1),
     append(B1,G1,J1),
     append(J1,I1,K1),
     copy_with_variable_replacement(M,L1,A1),
     copy_with_variable_replacement(M,M1,D1),
     append(M1,K1,N1),
     append([chr_pp_active_constraint(F)|L1],N1,O1),
     list2conj(C1,P1),
     copy_term((B1,K1,O1,P1,F),(_,_,Q1,R1,_)),
     ( P1\=chr_pp_void_info ->
       ( guard_entailment:entails_guard(Q1,R1) ->
         passive(A,V)
       ;
         true
       )
     ;
       true
     ),
     !,
     next_occ_in_rule(A,B,U,V,B1,F)
   ).
next_occ_in_rule(_,_,_,_,_,_).
multiple_occ_constraints_checked(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,_,D,_,_,_,_,_),
   (
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',E),
     lookup_ht(E,D,F),
     'chr sbag_member'(G,F),
     G=suspension(_,active,_,_,H,I,_,_,_),
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',J),
     lookup_ht(J,D,K),
     'chr sbag_member'(L,K),
     L=suspension(_,active,_,_,_,M),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',N),
     lookup_ht(N,k(H,D),O),
     'chr sbag_member'(P,O),
     P=suspension(_,active,_,_,_,Q,_,R,_),
     P\==G,
     Q<I,
     chr_pp_flag(occurrence_subsumption,on),
     M=pragma(rule(S,_,_,_),_,_,_,_),
     S\==[],
     \+tree_set_memberchk(H,A),
     !,
     first_occ_in_rule(D,H,Q,R),
     tree_set_add(A,H,T),
     multiple_occ_constraints_checked(T)
   ;
     !,
     setarg(2,C,removed),
     arg(4,C,U),
     ( var(U) ->
       nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',V),
       V=[_|W],
       b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',W),
       ( W=[X|_] ->
         setarg(4,X,_)
       ;
         true
       )
     ;
       U=[_,_|W],
       setarg(2,U,W),
       ( W=[X|_] ->
         setarg(4,X,U)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',Y),
     delete_ht(Y,D,C)
   ).
multiple_occ_constraints_checked(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
type_definition(A,B) :-
   type_definition___2__0(A,B,_).
type_definition___2__0(A,_,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,_),
   (
     functor(A,F,G),
     functor(E,F,G),
     !,
     D=suspension(_,_,_,_,_,H,I),
     setarg(2,D,removed),
     term_variables(term(H,I),J),
     arg(5,D,K),
     ( var(K) ->
       nb_getval('$chr_store_global_list_chr_translate____type_definition___2',L),
       L=[_|M],
       b_setval('$chr_store_global_list_chr_translate____type_definition___2',M),
       ( M=[N|_] ->
         setarg(5,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(5,N,K)
       ;
         true
       )
     ),
     detach_type_definition___2(J,D),
     ( var(B) ->
       true
     ;
       B=suspension(_,O,_,_,_,P,Q),
       setarg(2,B,removed),
       ( O==not_stored_yet ->
         R=[]
       ;
         term_variables(term(P,Q),R),
         arg(5,B,S),
         ( var(S) ->
           nb_getval('$chr_store_global_list_chr_translate____type_definition___2',T),
           T=[_|U],
           b_setval('$chr_store_global_list_chr_translate____type_definition___2',U),
           ( U=[V|_] ->
             setarg(5,V,_)
           ;
             true
           )
         ;
           S=[_,_|U],
           setarg(2,S,U),
           ( U=[V|_] ->
             setarg(5,V,S)
           ;
             true
           )
         ),
         detach_type_definition___2(R,B)
       )
     ),
     chr_error(type_error,'Multiple definitions for type: ~w/~w.\n',[F,G])
   ;
     functor(E,W,X),
     functor(A,W,X),
     !,
     D=suspension(_,_,_,_,_,Y,Z),
     setarg(2,D,removed),
     term_variables(term(Y,Z),A1),
     arg(5,D,B1),
     ( var(B1) ->
       nb_getval('$chr_store_global_list_chr_translate____type_definition___2',C1),
       C1=[_|D1],
       b_setval('$chr_store_global_list_chr_translate____type_definition___2',D1),
       ( D1=[E1|_] ->
         setarg(5,E1,_)
       ;
         true
       )
     ;
       B1=[_,_|D1],
       setarg(2,B1,D1),
       ( D1=[E1|_] ->
         setarg(5,E1,B1)
       ;
         true
       )
     ),
     detach_type_definition___2(A1,D),
     ( var(B) ->
       true
     ;
       B=suspension(_,F1,_,_,_,G1,H1),
       setarg(2,B,removed),
       ( F1==not_stored_yet ->
         I1=[]
       ;
         term_variables(term(G1,H1),I1),
         arg(5,B,J1),
         ( var(J1) ->
           nb_getval('$chr_store_global_list_chr_translate____type_definition___2',K1),
           K1=[_|L1],
           b_setval('$chr_store_global_list_chr_translate____type_definition___2',L1),
           ( L1=[M1|_] ->
             setarg(5,M1,_)
           ;
             true
           )
         ;
           J1=[_,_|L1],
           setarg(2,J1,L1),
           ( L1=[M1|_] ->
             setarg(5,M1,J1)
           ;
             true
           )
         ),
         detach_type_definition___2(I1,B)
       )
     ),
     chr_error(type_error,'Multiple definitions for type: ~w/~w.\n',[W,X])
   ).
type_definition___2__0(A,_,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,_),
   functor(A,F,G),
   functor(E,F,G),
   !,
   D=suspension(_,_,_,_,_,H,I),
   setarg(2,D,removed),
   term_variables(term(H,I),J),
   arg(5,D,K),
   ( var(K) ->
     nb_getval('$chr_store_global_list_chr_translate____type_alias___2',L),
     L=[_|M],
     b_setval('$chr_store_global_list_chr_translate____type_alias___2',M),
     ( M=[N|_] ->
       setarg(5,N,_)
     ;
       true
     )
   ;
     K=[_,_|M],
     setarg(2,K,M),
     ( M=[N|_] ->
       setarg(5,N,K)
     ;
       true
     )
   ),
   detach_type_alias___2(J,D),
   ( var(B) ->
     true
   ;
     B=suspension(_,O,_,_,_,P,Q),
     setarg(2,B,removed),
     ( O==not_stored_yet ->
       R=[]
     ;
       term_variables(term(P,Q),R),
       arg(5,B,S),
       ( var(S) ->
         nb_getval('$chr_store_global_list_chr_translate____type_definition___2',T),
         T=[_|U],
         b_setval('$chr_store_global_list_chr_translate____type_definition___2',U),
         ( U=[V|_] ->
           setarg(5,V,_)
         ;
           true
         )
       ;
         S=[_,_|U],
         setarg(2,S,U),
         ( U=[V|_] ->
           setarg(5,V,S)
         ;
           true
         )
       ),
       detach_type_definition___2(R,B)
     )
   ),
   chr_error(type_error,'Multiple definitions for type, once in a type definition and once as a type alias: ~w/~w.\n',[F,G]).
type_definition___2__0(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',D),
   !,
   ( var(C) ->
     C=suspension(E,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(E)
   ;
     true
   ),
   type_definition___2__0__0__5(D,A,B,C).
type_definition___2__0__0__5([],A,B,C) :-
   type_definition___2__1(A,B,C).
type_definition___2__0__0__5([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     nonvar(A),
     functor(A,H,I),
     functor(F,H,I) ->
     D=suspension(_,_,_,J,_),
     setarg(2,D,removed),
     term_variables(J,K),
     arg(3,D,L),
     ( var(L) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',M),
       M=[_|N],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',N),
       ( N=[O|_] ->
         setarg(3,O,_)
       ;
         true
       )
     ;
       L=[_,_|N],
       setarg(2,L,N),
       ( N=[O|_] ->
         setarg(3,O,L)
       ;
         true
       )
     ),
     detach_unalias_type___2(K,D),
     arg(2,C,P),
     setarg(2,C,active),
     arg(4,C,Q),
     R is Q+1,
     setarg(4,C,R),
     ( P==not_stored_yet ->
       C=suspension(_,_,_,_,_,S,T),
       term_variables(term(S,T),U),
       nb_getval('$chr_store_global_list_chr_translate____type_definition___2',V),
       W=[C|V],
       b_setval('$chr_store_global_list_chr_translate____type_definition___2',W),
       ( V=[X|_] ->
         setarg(5,X,W)
       ;
         true
       ),
       attach_type_definition___2(U,C)
     ;
       true
     ),
     G=F,
     ( C=suspension(_,active,_,R,_,_,_) ->
       setarg(2,C,inactive),
       type_definition___2__0__0__5(E,A,B,C)
     ;
       true
     )
   ;
     type_definition___2__0__0__5(E,A,B,C)
   ).
type_definition___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(D)
   ;
     true
   ),
   type_definition___2__1(A,B,C).
type_definition___2__1(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',D),
   !,
   type_definition___2__1__0__7(D,A,B,C).
type_definition___2__1__0__7([],A,B,C) :-
   type_definition___2__2(A,B,C).
type_definition___2__1__0__7([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_),
     F=t(235,C,D),
     '$novel_production'(C,F),
     '$novel_production'(D,F) ->
     '$extend_history'(C,F),
     arg(2,C,G),
     setarg(2,C,active),
     arg(4,C,H),
     I is H+1,
     setarg(4,C,I),
     ( G==not_stored_yet ->
       C=suspension(_,_,_,_,_,J,K),
       term_variables(term(J,K),L),
       nb_getval('$chr_store_global_list_chr_translate____type_definition___2',M),
       N=[C|M],
       b_setval('$chr_store_global_list_chr_translate____type_definition___2',N),
       ( M=[O|_] ->
         setarg(5,O,N)
       ;
         true
       ),
       attach_type_definition___2(L,C)
     ;
       true
     ),
     copy_term_nat(A-B,P-Q),
     maplist(dynamic_type_check_clause(P),Q,R),
     dynamic_type_check_clauses(R),
     ( C=suspension(_,active,_,I,_,_,_) ->
       setarg(2,C,inactive),
       type_definition___2__1__0__7(E,A,B,C)
     ;
       true
     )
   ;
     type_definition___2__1__0__7(E,A,B,C)
   ).
type_definition___2__1(A,B,C) :-
   type_definition___2__2(A,B,C).
type_definition___2__2(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',D),
   !,
   type_definition___2__2__0__8(D,A,B,C).
type_definition___2__2__0__8([],A,B,C) :-
   type_definition___2__3(A,B,C).
type_definition___2__2__0__8([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F),
     functor(F,G,H),
     functor(A,G,H) ->
     D=suspension(_,_,_,I),
     setarg(2,D,removed),
     term_variables(I,J),
     arg(3,D,K),
     ( var(K) ->
       nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',L),
       L=[_|M],
       b_setval('$chr_store_global_list_chr_translate____atomic_type___1',M),
       ( M=[N|_] ->
         setarg(3,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(3,N,K)
       ;
         true
       )
     ),
     detach_atomic_type___1(J,D),
     arg(2,C,O),
     setarg(2,C,active),
     arg(4,C,P),
     Q is P+1,
     setarg(4,C,Q),
     ( O==not_stored_yet ->
       C=suspension(_,_,_,_,_,R,S),
       term_variables(term(R,S),T),
       nb_getval('$chr_store_global_list_chr_translate____type_definition___2',U),
       V=[C|U],
       b_setval('$chr_store_global_list_chr_translate____type_definition___2',V),
       ( U=[W|_] ->
         setarg(5,W,V)
       ;
         true
       ),
       attach_type_definition___2(T,C)
     ;
       true
     ),
     maplist(atomic,B),
     ( C=suspension(_,active,_,Q,_,_,_) ->
       setarg(2,C,inactive),
       type_definition___2__2__0__8(E,A,B,C)
     ;
       true
     )
   ;
     type_definition___2__2__0__8(E,A,B,C)
   ).
type_definition___2__2(A,B,C) :-
   type_definition___2__3(A,B,C).
type_definition___2__3(_,_,A) :-
   arg(2,A,B),
   setarg(2,A,active),
   arg(4,A,C),
   D is C+1,
   setarg(4,A,D),
   ( B==not_stored_yet ->
     A=suspension(_,_,_,_,_,E,F),
     term_variables(term(E,F),G),
     nb_getval('$chr_store_global_list_chr_translate____type_definition___2',H),
     I=[A|H],
     b_setval('$chr_store_global_list_chr_translate____type_definition___2',I),
     ( H=[J|_] ->
       setarg(5,J,I)
     ;
       true
     ),
     attach_type_definition___2(G,A)
   ;
     true
   ).
type_alias(A,B) :-
   type_alias___2__0(A,B,_).
type_alias___2__0(A,B,C) :-
   var(A),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,D,_,_,_,E,F),
     setarg(2,C,removed),
     ( D==not_stored_yet ->
       G=[]
     ;
       term_variables(term(E,F),G),
       arg(5,C,H),
       ( var(H) ->
         nb_getval('$chr_store_global_list_chr_translate____type_alias___2',I),
         I=[_|J],
         b_setval('$chr_store_global_list_chr_translate____type_alias___2',J),
         ( J=[K|_] ->
           setarg(5,K,_)
         ;
           true
         )
       ;
         H=[_,_|J],
         setarg(2,H,J),
         ( J=[K|_] ->
           setarg(5,K,H)
         ;
           true
         )
       ),
       detach_type_alias___2(G,C)
     )
   ),
   chr_error(type_error,'Variable alias definition: "~w".\n',[(:-chr_type A==B)]).
type_alias___2__0(A,B,C) :-
   var(B),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,D,_,_,_,E,F),
     setarg(2,C,removed),
     ( D==not_stored_yet ->
       G=[]
     ;
       term_variables(term(E,F),G),
       arg(5,C,H),
       ( var(H) ->
         nb_getval('$chr_store_global_list_chr_translate____type_alias___2',I),
         I=[_|J],
         b_setval('$chr_store_global_list_chr_translate____type_alias___2',J),
         ( J=[K|_] ->
           setarg(5,K,_)
         ;
           true
         )
       ;
         H=[_,_|J],
         setarg(2,H,J),
         ( J=[K|_] ->
           setarg(5,K,H)
         ;
           true
         )
       ),
       detach_type_alias___2(G,C)
     )
   ),
   chr_error(type_error,'Variable alias definition: "~w".\n',[(:-chr_type A==B)]).
type_alias___2__0(A,B,C) :-
   functor(A,D,E),
   functor(B,D,E),
   copy_term((A,B),(F,G)),
   subsumes(F,G),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,H,_,_,_,I,J),
     setarg(2,C,removed),
     ( H==not_stored_yet ->
       K=[]
     ;
       term_variables(term(I,J),K),
       arg(5,C,L),
       ( var(L) ->
         nb_getval('$chr_store_global_list_chr_translate____type_alias___2',M),
         M=[_|N],
         b_setval('$chr_store_global_list_chr_translate____type_alias___2',N),
         ( N=[O|_] ->
           setarg(5,O,_)
         ;
           true
         )
       ;
         L=[_,_|N],
         setarg(2,L,N),
         ( N=[O|_] ->
           setarg(5,O,L)
         ;
           true
         )
       ),
       detach_type_alias___2(K,C)
     )
   ),
   chr_error(type_error,'Cyclic alias definition: "~w".\n',[A==B]).
type_alias___2__0(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',D),
   (
     'chr sbag_member'(E,D),
     E=suspension(_,active,_,_,_,F,G),
     (
       (
         functor(A,H,I),
         functor(F,H,I),
         \+A\=F,
         !,
         E=suspension(_,_,_,_,_,J,K),
         setarg(2,E,removed),
         term_variables(term(J,K),L),
         arg(5,E,M),
         ( var(M) ->
           nb_getval('$chr_store_global_list_chr_translate____type_alias___2',N),
           N=[_|O],
           b_setval('$chr_store_global_list_chr_translate____type_alias___2',O),
           ( O=[P|_] ->
             setarg(5,P,_)
           ;
             true
           )
         ;
           M=[_,_|O],
           setarg(2,M,O),
           ( O=[P|_] ->
             setarg(5,P,M)
           ;
             true
           )
         ),
         detach_type_alias___2(L,E),
         ( var(C) ->
           true
         ;
           C=suspension(_,Q,_,_,_,R,S),
           setarg(2,C,removed),
           ( Q==not_stored_yet ->
             T=[]
           ;
             term_variables(term(R,S),T),
             arg(5,C,U),
             ( var(U) ->
               nb_getval('$chr_store_global_list_chr_translate____type_alias___2',V),
               V=[_|W],
               b_setval('$chr_store_global_list_chr_translate____type_alias___2',W),
               ( W=[X|_] ->
                 setarg(5,X,_)
               ;
                 true
               )
             ;
               U=[_,_|W],
               setarg(2,U,W),
               ( W=[X|_] ->
                 setarg(5,X,U)
               ;
                 true
               )
             ),
             detach_type_alias___2(T,C)
           )
         ),
         copy_term_nat(A,Y),
         copy_term_nat(F,Z),
         Y=Z,
         chr_error(type_error,'Ambiguous type aliases: you have defined \n\t`~w\'\n\t`~w\'\n\tresulting in two definitions for "~w".\n',[A==B,F==G,Y])
       ;
         functor(F,A1,B1),
         functor(A,A1,B1),
         \+F\=A,
         !,
         E=suspension(_,_,_,_,_,C1,D1),
         setarg(2,E,removed),
         term_variables(term(C1,D1),E1),
         arg(5,E,F1),
         ( var(F1) ->
           nb_getval('$chr_store_global_list_chr_translate____type_alias___2',G1),
           G1=[_|H1],
           b_setval('$chr_store_global_list_chr_translate____type_alias___2',H1),
           ( H1=[I1|_] ->
             setarg(5,I1,_)
           ;
             true
           )
         ;
           F1=[_,_|H1],
           setarg(2,F1,H1),
           ( H1=[I1|_] ->
             setarg(5,I1,F1)
           ;
             true
           )
         ),
         detach_type_alias___2(E1,E),
         ( var(C) ->
           true
         ;
           C=suspension(_,J1,_,_,_,K1,L1),
           setarg(2,C,removed),
           ( J1==not_stored_yet ->
             M1=[]
           ;
             term_variables(term(K1,L1),M1),
             arg(5,C,N1),
             ( var(N1) ->
               nb_getval('$chr_store_global_list_chr_translate____type_alias___2',O1),
               O1=[_|P1],
               b_setval('$chr_store_global_list_chr_translate____type_alias___2',P1),
               ( P1=[Q1|_] ->
                 setarg(5,Q1,_)
               ;
                 true
               )
             ;
               N1=[_,_|P1],
               setarg(2,N1,P1),
               ( P1=[Q1|_] ->
                 setarg(5,Q1,N1)
               ;
                 true
               )
             ),
             detach_type_alias___2(M1,C)
           )
         ),
         copy_term_nat(F,R1),
         copy_term_nat(A,S1),
         R1=S1,
         chr_error(type_error,'Ambiguous type aliases: you have defined \n\t`~w\'\n\t`~w\'\n\tresulting in two definitions for "~w".\n',[F==G,A==B,R1])
       )
     ;
       functor(F,T1,U1),
       functor(B,T1,U1),
       copy_term_nat((A,B,F,G),(V1,W1,X1,Y1)),
       subsumes(X1,W1),
       !,
       ( var(C) ->
         true
       ;
         C=suspension(_,Z1,_,_,_,A2,B2),
         setarg(2,C,removed),
         ( Z1==not_stored_yet ->
           C2=[]
         ;
           term_variables(term(A2,B2),C2),
           arg(5,C,D2),
           ( var(D2) ->
             nb_getval('$chr_store_global_list_chr_translate____type_alias___2',E2),
             E2=[_|F2],
             b_setval('$chr_store_global_list_chr_translate____type_alias___2',F2),
             ( F2=[G2|_] ->
               setarg(5,G2,_)
             ;
               true
             )
           ;
             D2=[_,_|F2],
             setarg(2,D2,F2),
             ( F2=[G2|_] ->
               setarg(5,G2,D2)
             ;
               true
             )
           ),
           detach_type_alias___2(C2,C)
         )
       ),
       type_alias(V1,Y1)
     )
   ;
     !,
     ( var(C) ->
       C=suspension(H2,not_stored_yet,t,0,_,A,B),
       'chr gen_id'(H2)
     ;
       true
     ),
     type_alias___2__0__0__7(D,A,B,C)
   ).
type_alias___2__0__0__7([],A,B,C) :-
   type_alias___2__1(A,B,C).
type_alias___2__0__0__7([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,_,F,G),
     functor(A,H,I),
     functor(G,H,I),
     copy_term_nat((F,G,A,B),(J,K,L,M)),
     subsumes(L,K) ->
     D=suspension(_,_,_,_,_,N,O),
     setarg(2,D,removed),
     term_variables(term(N,O),P),
     arg(5,D,Q),
     ( var(Q) ->
       nb_getval('$chr_store_global_list_chr_translate____type_alias___2',R),
       R=[_|S],
       b_setval('$chr_store_global_list_chr_translate____type_alias___2',S),
       ( S=[T|_] ->
         setarg(5,T,_)
       ;
         true
       )
     ;
       Q=[_,_|S],
       setarg(2,Q,S),
       ( S=[T|_] ->
         setarg(5,T,Q)
       ;
         true
       )
     ),
     detach_type_alias___2(P,D),
     arg(2,C,U),
     setarg(2,C,active),
     arg(4,C,V),
     W is V+1,
     setarg(4,C,W),
     ( U==not_stored_yet ->
       C=suspension(_,_,_,_,_,X,Y),
       term_variables(term(X,Y),Z),
       nb_getval('$chr_store_global_list_chr_translate____type_alias___2',A1),
       B1=[C|A1],
       b_setval('$chr_store_global_list_chr_translate____type_alias___2',B1),
       ( A1=[C1|_] ->
         setarg(5,C1,B1)
       ;
         true
       ),
       attach_type_alias___2(Z,C)
     ;
       true
     ),
     type_alias(J,M),
     ( C=suspension(_,active,_,W,_,_,_) ->
       setarg(2,C,inactive),
       type_alias___2__0__0__7(E,A,B,C)
     ;
       true
     )
   ;
     type_alias___2__0__0__7(E,A,B,C)
   ).
type_alias___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,not_stored_yet,t,0,_,A,B),
     'chr gen_id'(D)
   ;
     true
   ),
   type_alias___2__1(A,B,C).
type_alias___2__1(A,_,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,_),
   functor(E,F,G),
   functor(A,F,G),
   !,
   D=suspension(_,_,_,_,_,H,I),
   setarg(2,D,removed),
   term_variables(term(H,I),J),
   arg(5,D,K),
   ( var(K) ->
     nb_getval('$chr_store_global_list_chr_translate____type_definition___2',L),
     L=[_|M],
     b_setval('$chr_store_global_list_chr_translate____type_definition___2',M),
     ( M=[N|_] ->
       setarg(5,N,_)
     ;
       true
     )
   ;
     K=[_,_|M],
     setarg(2,K,M),
     ( M=[N|_] ->
       setarg(5,N,K)
     ;
       true
     )
   ),
   detach_type_definition___2(J,D),
   ( var(B) ->
     true
   ;
     B=suspension(_,O,_,_,_,P,Q),
     setarg(2,B,removed),
     ( O==not_stored_yet ->
       R=[]
     ;
       term_variables(term(P,Q),R),
       arg(5,B,S),
       ( var(S) ->
         nb_getval('$chr_store_global_list_chr_translate____type_alias___2',T),
         T=[_|U],
         b_setval('$chr_store_global_list_chr_translate____type_alias___2',U),
         ( U=[V|_] ->
           setarg(5,V,_)
         ;
           true
         )
       ;
         S=[_,_|U],
         setarg(2,S,U),
         ( U=[V|_] ->
           setarg(5,V,S)
         ;
           true
         )
       ),
       detach_type_alias___2(R,B)
     )
   ),
   chr_error(type_error,'Multiple definitions for type, once in a type definition and once as a type alias: ~w/~w.\n',[F,G]).
type_alias___2__1(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',D),
   !,
   type_alias___2__1__0__10(D,A,B,C).
type_alias___2__1__0__10([],A,B,C) :-
   type_alias___2__2(A,B,C).
type_alias___2__1__0__10([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     functor(A,H,I),
     functor(F,H,I),
     copy_term_nat((A,B),(J,K)),
     F=J ->
     D=suspension(_,_,_,L,_),
     setarg(2,D,removed),
     term_variables(L,M),
     arg(3,D,N),
     ( var(N) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',O),
       O=[_|P],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',P),
       ( P=[Q|_] ->
         setarg(3,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(3,Q,N)
       ;
         true
       )
     ),
     detach_unalias_type___2(M,D),
     arg(2,C,R),
     setarg(2,C,active),
     arg(4,C,S),
     T is S+1,
     setarg(4,C,T),
     ( R==not_stored_yet ->
       C=suspension(_,_,_,_,_,U,V),
       term_variables(term(U,V),W),
       nb_getval('$chr_store_global_list_chr_translate____type_alias___2',X),
       Y=[C|X],
       b_setval('$chr_store_global_list_chr_translate____type_alias___2',Y),
       ( X=[Z|_] ->
         setarg(5,Z,Y)
       ;
         true
       ),
       attach_type_alias___2(W,C)
     ;
       true
     ),
     unalias_type(K,G),
     ( C=suspension(_,active,_,T,_,_,_) ->
       setarg(2,C,inactive),
       type_alias___2__1__0__10(E,A,B,C)
     ;
       true
     )
   ;
     type_alias___2__1__0__10(E,A,B,C)
   ).
type_alias___2__1(A,B,C) :-
   type_alias___2__2(A,B,C).
type_alias___2__2(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',D),
   !,
   type_alias___2__2__0__12(D,A,B,C).
type_alias___2__2__0__12([],A,B,C) :-
   type_alias___2__3(A,B,C).
type_alias___2__2__0__12([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G,H,I),
     functor(A,J,K),
     functor(H,J,K) ->
     D=suspension(_,_,_,_,_,L,_),
     setarg(2,D,removed),
     term_variables(L,M),
     arg(3,D,N),
     ( var(N) ->
       nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',O),
       O=[_|P],
       b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',P),
       ( P=[Q|_] ->
         setarg(3,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(3,Q,N)
       ;
         true
       )
     ),
     detach_ast_static_type_check_var___4(M,D),
     arg(2,C,R),
     setarg(2,C,active),
     arg(4,C,S),
     T is S+1,
     setarg(4,C,T),
     ( R==not_stored_yet ->
       C=suspension(_,_,_,_,_,U,V),
       term_variables(term(U,V),W),
       nb_getval('$chr_store_global_list_chr_translate____type_alias___2',X),
       Y=[C|X],
       b_setval('$chr_store_global_list_chr_translate____type_alias___2',Y),
       ( X=[Z|_] ->
         setarg(5,Z,Y)
       ;
         true
       ),
       attach_type_alias___2(W,C)
     ;
       true
     ),
     copy_term_nat(A-B,H-A1),
     ast_static_type_check_var(F,G,A1,I),
     ( C=suspension(_,active,_,T,_,_,_) ->
       setarg(2,C,inactive),
       type_alias___2__2__0__12(E,A,B,C)
     ;
       true
     )
   ;
     type_alias___2__2__0__12(E,A,B,C)
   ).
type_alias___2__2(A,B,C) :-
   type_alias___2__3(A,B,C).
type_alias___2__3(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',D),
   !,
   type_alias___2__3__0__13(D,A,B,C).
type_alias___2__3__0__13([],A,B,C) :-
   type_alias___2__4(A,B,C).
type_alias___2__3__0__13([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_),
     F=t(236,C,D),
     '$novel_production'(C,F),
     '$novel_production'(D,F) ->
     '$extend_history'(C,F),
     arg(2,C,G),
     setarg(2,C,active),
     arg(4,C,H),
     I is H+1,
     setarg(4,C,I),
     ( G==not_stored_yet ->
       C=suspension(_,_,_,_,_,J,K),
       term_variables(term(J,K),L),
       nb_getval('$chr_store_global_list_chr_translate____type_alias___2',M),
       N=[C|M],
       b_setval('$chr_store_global_list_chr_translate____type_alias___2',N),
       ( M=[O|_] ->
         setarg(5,O,N)
       ;
         true
       ),
       attach_type_alias___2(L,C)
     ;
       true
     ),
     copy_term_nat(A-B,P-Q),
     dynamic_type_check_alias_clause(P,Q,R),
     dynamic_type_check_clauses([R]),
     ( C=suspension(_,active,_,I,_,_,_) ->
       setarg(2,C,inactive),
       type_alias___2__3__0__13(E,A,B,C)
     ;
       true
     )
   ;
     type_alias___2__3__0__13(E,A,B,C)
   ).
type_alias___2__3(A,B,C) :-
   type_alias___2__4(A,B,C).
type_alias___2__4(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',D),
   !,
   type_alias___2__4__0__14(D,A,B,C).
type_alias___2__4__0__14([],A,B,C) :-
   type_alias___2__5(A,B,C).
type_alias___2__4__0__14([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F),
     functor(F,G,H),
     functor(A,G,H) ->
     D=suspension(_,_,_,I),
     setarg(2,D,removed),
     term_variables(I,J),
     arg(3,D,K),
     ( var(K) ->
       nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',L),
       L=[_|M],
       b_setval('$chr_store_global_list_chr_translate____atomic_type___1',M),
       ( M=[N|_] ->
         setarg(3,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(3,N,K)
       ;
         true
       )
     ),
     detach_atomic_type___1(J,D),
     arg(2,C,O),
     setarg(2,C,active),
     arg(4,C,P),
     Q is P+1,
     setarg(4,C,Q),
     ( O==not_stored_yet ->
       C=suspension(_,_,_,_,_,R,S),
       term_variables(term(R,S),T),
       nb_getval('$chr_store_global_list_chr_translate____type_alias___2',U),
       V=[C|U],
       b_setval('$chr_store_global_list_chr_translate____type_alias___2',V),
       ( U=[W|_] ->
         setarg(5,W,V)
       ;
         true
       ),
       attach_type_alias___2(T,C)
     ;
       true
     ),
     atomic(B),
     copy_term_nat(A-B,F-X),
     atomic_type(X),
     ( C=suspension(_,active,_,Q,_,_,_) ->
       setarg(2,C,inactive),
       type_alias___2__4__0__14(E,A,B,C)
     ;
       true
     )
   ;
     type_alias___2__4__0__14(E,A,B,C)
   ).
type_alias___2__4(A,B,C) :-
   type_alias___2__5(A,B,C).
type_alias___2__5(_,_,A) :-
   arg(2,A,B),
   setarg(2,A,active),
   arg(4,A,C),
   D is C+1,
   setarg(4,A,D),
   ( B==not_stored_yet ->
     A=suspension(_,_,_,_,_,E,F),
     term_variables(term(E,F),G),
     nb_getval('$chr_store_global_list_chr_translate____type_alias___2',H),
     I=[A|H],
     b_setval('$chr_store_global_list_chr_translate____type_alias___2',I),
     ( H=[J|_] ->
       setarg(5,J,I)
     ;
       true
     ),
     attach_type_alias___2(G,A)
   ;
     true
   ).
constraint_type(A,B) :-
   constraint_type___2__0(A,B,_).
constraint_type___2__0(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',D),
   !,
   C=suspension(E,not_stored_yet,_,A,B),
   'chr gen_id'(E),
   constraint_type___2__0__0__2(D,A,B,C).
constraint_type___2__0__0__2([],A,B,C) :-
   constraint_type___2__1(A,B,C).
constraint_type___2__0__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,_) ->
     arg(2,C,F),
     setarg(2,C,active),
     ( F==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',G),
       H=[C|G],
       b_setval('$chr_store_global_ground_chr_translate____constraint_type___2',H),
       ( G=[I|_] ->
         setarg(3,I,H)
       ;
         true
       ),
       nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',J),
       insert_ht(J,A,C)
     ;
       true
     ),
     forall((member(K,B),sub_term(K,L)),(get_type_definition(L,_)->true;chr_error(type_error,'Undefined type "~w" used in type declaration of "~w".\n',[L,A]))),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       constraint_type___2__0__0__2(E,A,B,C)
     ;
       true
     )
   ;
     constraint_type___2__0__0__2(E,A,B,C)
   ).
constraint_type___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,_,A,B),
   'chr gen_id'(D),
   constraint_type___2__1(A,B,C).
constraint_type___2__1(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',D),
     E=[B|D],
     b_setval('$chr_store_global_ground_chr_translate____constraint_type___2',E),
     ( D=[F|_] ->
       setarg(3,F,E)
     ;
       true
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',G),
     insert_ht(G,A,B)
   ;
     true
   ).
get_type_definition(A,_) :-
   \+ground(A),
   !,
   chr_error(type_error,'Non-ground type in constraint definition: "~w".\n',[A]).
get_type_definition(A,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,F),
   functor(E,G,H),
   functor(A,G,H),
   copy_term_nat((E,F),(I,J)),
   I=A,
   !,
   ( get_type_definition(J,B) ->
     true
   ;
     chr_error(type_error,'Could not find type definition for "~w" (accessed via alias "~w").\n',[J,I]),
     fail
   ).
get_type_definition(A,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,F),
   nonvar(E),
   functor(E,G,H),
   functor(A,G,H),
   copy_term_nat((E,F),(I,J)),
   I=A,
   !,
   B=J.
get_type_definition(A,B) :-
   atomic_builtin_type(A,_,_),
   !,
   B=[A].
get_type_definition(A,B) :-
   compound_builtin_type(A,_,_,_),
   !,
   B=[A].
get_type_definition(_,_) :-
   fail.
get_constraint_type(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,F),
   !,
   B=F.
get_constraint_type(_,_) :-
   fail.
unalias_type(A,B) :-
   unalias_type___2__0(A,B,_).
unalias_type___2__0(A,B,C) :-
   var(A),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,_,_,D,_),
     setarg(2,C,removed),
     term_variables(D,E),
     arg(3,C,F),
     ( var(F) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',G),
       G=[_|H],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',H),
       ( H=[I|_] ->
         setarg(3,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(3,I,F)
       ;
         true
       )
     ),
     detach_unalias_type___2(E,C)
   ),
   B=A.
unalias_type___2__0(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F,G),
   functor(F,H,I),
   functor(A,H,I),
   copy_term_nat((F,G),(J,K)),
   A=J,
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,_,_,L,_),
     setarg(2,C,removed),
     term_variables(L,M),
     arg(3,C,N),
     ( var(N) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',O),
       O=[_|P],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',P),
       ( P=[Q|_] ->
         setarg(3,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(3,Q,N)
       ;
         true
       )
     ),
     detach_unalias_type___2(M,C)
   ),
   unalias_type(K,B).
unalias_type___2__0(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F,_),
   nonvar(F),
   functor(F,G,H),
   functor(A,G,H),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,_,_,I,_),
     setarg(2,C,removed),
     term_variables(I,J),
     arg(3,C,K),
     ( var(K) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',L),
       L=[_|M],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',M),
       ( M=[N|_] ->
         setarg(3,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(3,N,K)
       ;
         true
       )
     ),
     detach_unalias_type___2(J,C)
   ),
   B=A.
unalias_type___2__0(A,B,C) :-
   atomic_builtin_type(A,_,_),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,_,_,D,_),
     setarg(2,C,removed),
     term_variables(D,E),
     arg(3,C,F),
     ( var(F) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',G),
       G=[_|H],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',H),
       ( H=[I|_] ->
         setarg(3,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(3,I,F)
       ;
         true
       )
     ),
     detach_unalias_type___2(E,C)
   ),
   B=A.
unalias_type___2__0(A,B,C) :-
   compound_builtin_type(A,_,_,_),
   !,
   ( var(C) ->
     true
   ;
     C=suspension(_,_,_,D,_),
     setarg(2,C,removed),
     term_variables(D,E),
     arg(3,C,F),
     ( var(F) ->
       nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',G),
       G=[_|H],
       b_setval('$chr_store_global_list_chr_translate____unalias_type___2',H),
       ( H=[I|_] ->
         setarg(3,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(3,I,F)
       ;
         true
       )
     ),
     detach_unalias_type___2(E,C)
   ),
   B=A.
unalias_type___2__0(A,B,C) :-
   ( var(C) ->
     C=suspension(D,active,_,A,B),
     term_variables(A,E),
     'chr gen_id'(D),
     nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',F),
     G=[C|F],
     b_setval('$chr_store_global_list_chr_translate____unalias_type___2',G),
     ( F=[H|_] ->
       setarg(3,H,G)
     ;
       true
     ),
     attach_unalias_type___2(E,C)
   ;
     setarg(2,C,active)
   ).
types_modes_condition([],[],A) :-
   !,
   A=true.
types_modes_condition([B|C],[D|E],A) :-
   nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,H,I),
   H=J/K,
   functor(B,J,K),
   !,
   B=..[_|L],
   A= (M,N,O),
   modes_condition(I,L,M),
   get_constraint_type_det(J/K,P),
   D=..[_|Q],
   types_condition(P,L,Q,I,N),
   types_modes_condition(C,E,O).
types_modes_condition([A|_],_,_) :-
   !,
   functor(A,B,C),
   chr_error(internal,'Mode information missing for ~w.\n',[B/C]).
types_modes_condition(A,B,C) :-
   D=suspension(E,active,_,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',F),
   G=[D|F],
   b_setval('$chr_store_global_ground_chr_translate____types_modes_condition___3',G),
   ( F=[H|_] ->
     setarg(3,H,G)
   ;
     true
   ).
static_type_check(A,B) :-
   static_type_check___2__0(A,B,_).
static_type_check___2__0(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',D),
   !,
   C=suspension(E,not_stored_yet,_,A,B),
   'chr gen_id'(E),
   static_type_check___2__0__0__1(D,A,B,C).
static_type_check___2__0__0__1([],A,B,C) :-
   static_type_check___2__1(A,B,C).
static_type_check___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G) ->
     arg(2,C,H),
     setarg(2,C,active),
     ( H==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',I),
       J=[C|I],
       b_setval('$chr_store_global_ground_chr_translate____static_type_check___2',J),
       ( I=[K|_] ->
         setarg(3,K,J)
       ;
         true
       )
     ;
       true
     ),
     forall((member(L,G),sub_term(L,M)),(get_type_definition(M,_)->true;chr_error(type_error,'Undefined type "~w" used in type declaration of "~w".\n',[M,F]))),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       static_type_check___2__0__0__1(E,A,B,C)
     ;
       true
     )
   ;
     static_type_check___2__0__0__1(E,A,B,C)
   ).
static_type_check___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,_,A,B),
   'chr gen_id'(D),
   static_type_check___2__1(A,B,C).
static_type_check___2__1(A,B,C) :-
   ( var(C) ->
     true
   ;
     arg(2,C,D),
     setarg(2,C,removed),
     ( D==not_stored_yet ->
       true
     ;
       arg(3,C,E),
       ( var(E) ->
         nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',F),
         F=[_|G],
         b_setval('$chr_store_global_ground_chr_translate____static_type_check___2',G),
         ( G=[H|_] ->
           setarg(3,H,_)
         ;
           true
         )
       ;
         E=[_,_|G],
         setarg(2,E,G),
         ( G=[H|_] ->
           setarg(3,H,E)
         ;
           true
         )
       )
     )
   ),
   maplist(static_type_check_rule,A,B).
ast_static_type_check_term(_,_,A) :-
   A==any,
   !.
ast_static_type_check_term(A,B,C) :-
   nonvar(B),
   B=var(D,E),
   !,
   ast_static_type_check_var(D,var(D,E),C,A).
ast_static_type_check_term(A,B,C) :-
   ast_atomic_builtin_type(C,B,D),
   !,
   ( call(D) ->
     true
   ;
     throw(type_error(invalid_functor(A,B,C)))
   ).
ast_static_type_check_term(A,B,C) :-
   ast_compound_builtin_type(C,B,D),
   !,
   ( call(D) ->
     true
   ;
     throw(type_error(invalid_functor(A,B,C)))
   ).
ast_static_type_check_term(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F,G),
   functor(C,H,I),
   functor(F,H,I),
   !,
   copy_term_nat(F-G,C-J),
   ast_static_type_check_term(A,B,J).
ast_static_type_check_term(A,B,C) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F,G),
   functor(C,H,I),
   functor(F,H,I),
   !,
   copy_term_nat(F-G,C-J),
   ast_functor(B,K,L),
   ( member(M,J),
     functor(M,K,L) ->
     ast_args(B,N),
     M=..[_|O],
     maplist(ast_static_type_check_term(A),N,O)
   ;
     throw(type_error(invalid_functor(A,B,C)))
   ).
ast_static_type_check_term(A,B,C) :-
   chr_error(internal,'Undefined type ~w while type checking term ~w in ~@.\n',[C,B,chr_translate:format_src(A)]).
ast_static_type_check_var(A,B,C,D) :-
   ast_static_type_check_var___4__0(A,B,C,D,_).
ast_static_type_check_var___4__0(A,B,C,D,E) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,_,H,I),
   functor(H,J,K),
   functor(C,J,K),
   !,
   ( var(E) ->
     true
   ;
     E=suspension(_,_,_,_,_,L,_),
     setarg(2,E,removed),
     term_variables(L,M),
     arg(3,E,N),
     ( var(N) ->
       nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',O),
       O=[_|P],
       b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',P),
       ( P=[Q|_] ->
         setarg(3,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(3,Q,N)
       ;
         true
       )
     ),
     detach_ast_static_type_check_var___4(M,E)
   ),
   copy_term_nat(H-I,C-R),
   ast_static_type_check_var(A,B,R,D).
ast_static_type_check_var___4__0(A,B,C,D,E) :-
   atomic_builtin_type(C,_,_),
   !,
   ( var(E) ->
     true
   ;
     E=suspension(_,_,_,_,_,F,_),
     setarg(2,E,removed),
     term_variables(F,G),
     arg(3,E,H),
     ( var(H) ->
       nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',I),
       I=[_|J],
       b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',J),
       ( J=[K|_] ->
         setarg(3,K,_)
       ;
         true
       )
     ;
       H=[_,_|J],
       setarg(2,H,J),
       ( J=[K|_] ->
         setarg(3,K,H)
       ;
         true
       )
     ),
     detach_ast_static_type_check_var___4(G,E)
   ),
   ast_static_atomic_builtin_type_check_var(A,B,C,D).
ast_static_type_check_var___4__0(_,_,A,_,B) :-
   compound_builtin_type(A,_,_,_),
   !,
   ( var(B) ->
     true
   ;
     B=suspension(_,_,_,_,_,C,_),
     setarg(2,B,removed),
     term_variables(C,D),
     arg(3,B,E),
     ( var(E) ->
       nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',F),
       F=[_|G],
       b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',G),
       ( G=[H|_] ->
         setarg(3,H,_)
       ;
         true
       )
     ;
       E=[_,_|G],
       setarg(2,E,G),
       ( G=[H|_] ->
         setarg(3,H,E)
       ;
         true
       )
     ),
     detach_ast_static_type_check_var___4(D,B)
   ).
ast_static_type_check_var___4__0(A,B,C,D,E) :-
   nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,H,I,J,K),
   H=A,
   (
     C\==J,
     !,
     G=suspension(_,_,_,_,_,L,_),
     setarg(2,G,removed),
     term_variables(L,M),
     arg(3,G,N),
     ( var(N) ->
       nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',O),
       O=[_|P],
       b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',P),
       ( P=[Q|_] ->
         setarg(3,Q,_)
       ;
         true
       )
     ;
       N=[_,_|P],
       setarg(2,N,P),
       ( P=[Q|_] ->
         setarg(3,Q,N)
       ;
         true
       )
     ),
     detach_ast_static_type_check_var___4(M,G),
     ( var(E) ->
       true
     ;
       E=suspension(_,_,_,_,_,R,_),
       setarg(2,E,removed),
       term_variables(R,S),
       arg(3,E,T),
       ( var(T) ->
         nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',U),
         U=[_|V],
         b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',V),
         ( V=[W|_] ->
           setarg(3,W,_)
         ;
           true
         )
       ;
         T=[_,_|V],
         setarg(2,T,V),
         ( V=[W|_] ->
           setarg(3,W,T)
         ;
           true
         )
       ),
       detach_ast_static_type_check_var___4(S,E)
     ),
     throw(type_error(type_clash(B,D,K,C,J)))
   ;
     J\==C,
     !,
     G=suspension(_,_,_,_,_,X,_),
     setarg(2,G,removed),
     term_variables(X,Y),
     arg(3,G,Z),
     ( var(Z) ->
       nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',A1),
       A1=[_|B1],
       b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',B1),
       ( B1=[C1|_] ->
         setarg(3,C1,_)
       ;
         true
       )
     ;
       Z=[_,_|B1],
       setarg(2,Z,B1),
       ( B1=[C1|_] ->
         setarg(3,C1,Z)
       ;
         true
       )
     ),
     detach_ast_static_type_check_var___4(Y,G),
     ( var(E) ->
       true
     ;
       E=suspension(_,_,_,_,_,D1,_),
       setarg(2,E,removed),
       term_variables(D1,E1),
       arg(3,E,F1),
       ( var(F1) ->
         nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',G1),
         G1=[_|H1],
         b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',H1),
         ( H1=[I1|_] ->
           setarg(3,I1,_)
         ;
           true
         )
       ;
         F1=[_,_|H1],
         setarg(2,F1,H1),
         ( H1=[I1|_] ->
           setarg(3,I1,F1)
         ;
           true
         )
       ),
       detach_ast_static_type_check_var___4(E1,E)
     ),
     throw(type_error(type_clash(I,K,D,J,C)))
   ).
ast_static_type_check_var___4__0(A,B,C,D,E) :-
   ( var(E) ->
     E=suspension(F,active,_,A,B,C,D),
     term_variables(C,G),
     'chr gen_id'(F),
     nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',H),
     I=[E|H],
     b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',I),
     ( H=[J|_] ->
       setarg(3,J,I)
     ;
       true
     ),
     attach_ast_static_type_check_var___4(G,E)
   ;
     setarg(2,E,active)
   ).
ast_static_atomic_builtin_type_check_var(_,_,any,_) :-
   !.
ast_static_atomic_builtin_type_check_var(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',E),
   lookup_ht(E,k(A,C),F),
   (
     'chr sbag_member'(G,F),
     G=suspension(_,active,_,_,_,_),
     !
   ;
     !,
     ast_static_atomic_builtin_type_check_var___4__0__0__3(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__0__0__3([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__1(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__0__0__3([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H==C ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,C),E),
     ast_static_atomic_builtin_type_check_var___4__0__0__3(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__0__0__3(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__1(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__1(A,_,number,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,float),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__1(A,B,float,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,number),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__1__0__5(E,A,B,float,C).
ast_static_atomic_builtin_type_check_var___4__1__0__5([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__8(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__1__0__5([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=number ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,number),E),
     ast_static_atomic_builtin_type_check_var___4__1__0__5(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__1__0__5(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__1(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__2(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__2(A,_,number,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,int),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__2(A,B,int,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,number),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__2__0__7(E,A,B,int,C).
ast_static_atomic_builtin_type_check_var___4__2__0__7([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__5(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__2__0__7([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=number ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,number),E),
     ast_static_atomic_builtin_type_check_var___4__2__0__7(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__2__0__7(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__2(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__3(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__3(A,_,number,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,natural),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__3(A,B,natural,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,number),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__3__0__9(E,A,B,natural,C).
ast_static_atomic_builtin_type_check_var___4__3__0__9([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__5(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__3__0__9([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=number ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,number),E),
     ast_static_atomic_builtin_type_check_var___4__3__0__9(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__3__0__9(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__3(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__4(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__4(A,_,number,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,dense_int),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__4(A,B,dense_int,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,number),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__4__0__11(E,A,B,dense_int,C).
ast_static_atomic_builtin_type_check_var___4__4__0__11([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__6(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__4__0__11([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=number ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,number),E),
     ast_static_atomic_builtin_type_check_var___4__4__0__11(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__4__0__11(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__4(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__5(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__5(A,_,int,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,natural),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__5(A,B,natural,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,int),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__5__0__13(E,A,B,natural,C).
ast_static_atomic_builtin_type_check_var___4__5__0__13([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__7(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__5__0__13([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=int ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,int),E),
     ast_static_atomic_builtin_type_check_var___4__5__0__13(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__5__0__13(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__5(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__6(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__6(A,_,int,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,dense_int),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__6(A,B,dense_int,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,int),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__6__0__15(E,A,B,dense_int,C).
ast_static_atomic_builtin_type_check_var___4__6__0__15([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__7(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__6__0__15([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=int ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,int),E),
     ast_static_atomic_builtin_type_check_var___4__6__0__15(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__6__0__15(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__6(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__7(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__7(A,_,natural,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',B),
   lookup_ht(B,k(A,dense_int),C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,_),
   !.
ast_static_atomic_builtin_type_check_var___4__7(A,B,dense_int,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',D),
   lookup_ht(D,k(A,natural),E),
   !,
   ast_static_atomic_builtin_type_check_var___4__7__0__17(E,A,B,dense_int,C).
ast_static_atomic_builtin_type_check_var___4__7__0__17([],A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__8(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__7__0__17([E|F],A,B,C,D) :-
   ( E=suspension(_,active,G,_,H,_),
     G==A,
     H=natural ->
     setarg(2,E,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',I),
     delete_ht(I,A,E),
     nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',J),
     delete_ht(J,k(A,natural),E),
     ast_static_atomic_builtin_type_check_var___4__7__0__17(F,A,B,C,D)
   ;
     ast_static_atomic_builtin_type_check_var___4__7__0__17(F,A,B,C,D)
   ).
ast_static_atomic_builtin_type_check_var___4__7(A,B,C,D) :-
   ast_static_atomic_builtin_type_check_var___4__8(A,B,C,D).
ast_static_atomic_builtin_type_check_var___4__8(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',E),
   lookup_ht(E,A,F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,H,I),
   !,
   setarg(2,G,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',J),
   delete_ht(J,A,G),
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',K),
   delete_ht(K,k(A,H),G),
   throw(type_error(type_clash(B,D,I,C,H))).
ast_static_atomic_builtin_type_check_var___4__8(A,B,C,D) :-
   E=suspension(F,active,A,B,C,D),
   'chr gen_id'(F),
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',G),
   insert_ht(G,A,E),
   nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',H),
   insert_ht(H,k(A,C),E).
dynamic_type_check :-
   dynamic_type_check___0__0(_).
dynamic_type_check___0__0(A) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',B),
   !,
   A=suspension(C,not_stored_yet,t,_),
   'chr gen_id'(C),
   dynamic_type_check___0__0__0__1(B,A).
dynamic_type_check___0__0__0__1([],A) :-
   dynamic_type_check___0__1(A).
dynamic_type_check___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,_,_,D,E),
     F=t(235,B,A),
     '$novel_production'(B,F),
     '$novel_production'(A,F) ->
     '$extend_history'(A,F),
     arg(2,A,G),
     setarg(2,A,active),
     ( G==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',H),
       I=[A|H],
       b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',I),
       ( H=[J|_] ->
         setarg(4,J,I)
       ;
         true
       )
     ;
       true
     ),
     copy_term_nat(D-E,K-L),
     maplist(dynamic_type_check_clause(K),L,M),
     dynamic_type_check_clauses(M),
     ( A=suspension(_,active,_,_) ->
       setarg(2,A,inactive),
       dynamic_type_check___0__0__0__1(C,A)
     ;
       true
     )
   ;
     dynamic_type_check___0__0__0__1(C,A)
   ).
dynamic_type_check___0__0(A) :-
   A=suspension(B,not_stored_yet,t,_),
   'chr gen_id'(B),
   dynamic_type_check___0__1(A).
dynamic_type_check___0__1(A) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',B),
   !,
   dynamic_type_check___0__1__0__2(B,A).
dynamic_type_check___0__1__0__2([],A) :-
   dynamic_type_check___0__2(A).
dynamic_type_check___0__1__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_,_,D,E),
     F=t(236,B,A),
     '$novel_production'(B,F),
     '$novel_production'(A,F) ->
     '$extend_history'(A,F),
     arg(2,A,G),
     setarg(2,A,active),
     ( G==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',H),
       I=[A|H],
       b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',I),
       ( H=[J|_] ->
         setarg(4,J,I)
       ;
         true
       )
     ;
       true
     ),
     copy_term_nat(D-E,K-L),
     dynamic_type_check_alias_clause(K,L,M),
     dynamic_type_check_clauses([M]),
     ( A=suspension(_,active,_,_) ->
       setarg(2,A,inactive),
       dynamic_type_check___0__1__0__2(C,A)
     ;
       true
     )
   ;
     dynamic_type_check___0__1__0__2(C,A)
   ).
dynamic_type_check___0__1(A) :-
   dynamic_type_check___0__2(A).
dynamic_type_check___0__2(A) :-
   ( var(A) ->
     true
   ;
     arg(2,A,B),
     setarg(2,A,removed),
     ( B==not_stored_yet ->
       true
     ;
       arg(4,A,C),
       ( var(C) ->
         nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',D),
         D=[_|E],
         b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',E),
         ( E=[F|_] ->
           setarg(4,F,_)
         ;
           true
         )
       ;
         C=[_,_|E],
         setarg(2,C,E),
         ( E=[F|_] ->
           setarg(4,F,C)
         ;
           true
         )
       )
     )
   ),
   findall(('$dynamic_type_check'(I,J):-H),(atomic_builtin_type(I,J,H);compound_builtin_type(I,J,H,_)),G),
   dynamic_type_check_clauses(G).
dynamic_type_check_clauses(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   append(A,D,I),
   dynamic_type_check_clauses(I).
dynamic_type_check_clauses(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
get_dynamic_type_check_clauses(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   A=D.
get_dynamic_type_check_clauses([]).
atomic_type(A) :-
   atomic_type___1__0(A,_).
atomic_type___1__0(A,B) :-
   atomic_builtin_type(A,_,_),
   !,
   ( var(B) ->
     true
   ;
     B=suspension(_,_,_,C),
     setarg(2,B,removed),
     term_variables(C,D),
     arg(3,B,E),
     ( var(E) ->
       nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',F),
       F=[_|G],
       b_setval('$chr_store_global_list_chr_translate____atomic_type___1',G),
       ( G=[H|_] ->
         setarg(3,H,_)
       ;
         true
       )
     ;
       E=[_,_|G],
       setarg(2,E,G),
       ( G=[H|_] ->
         setarg(3,H,E)
       ;
         true
       )
     ),
     detach_atomic_type___1(D,B)
   ),
   A\==any.
atomic_type___1__0(A,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,F),
   functor(A,G,H),
   functor(E,G,H),
   !,
   ( var(B) ->
     true
   ;
     B=suspension(_,_,_,I),
     setarg(2,B,removed),
     term_variables(I,J),
     arg(3,B,K),
     ( var(K) ->
       nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',L),
       L=[_|M],
       b_setval('$chr_store_global_list_chr_translate____atomic_type___1',M),
       ( M=[N|_] ->
         setarg(3,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(3,N,K)
       ;
         true
       )
     ),
     detach_atomic_type___1(J,B)
   ),
   maplist(atomic,F).
atomic_type___1__0(A,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,F),
   functor(A,G,H),
   functor(E,G,H),
   !,
   ( var(B) ->
     true
   ;
     B=suspension(_,_,_,I),
     setarg(2,B,removed),
     term_variables(I,J),
     arg(3,B,K),
     ( var(K) ->
       nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',L),
       L=[_|M],
       b_setval('$chr_store_global_list_chr_translate____atomic_type___1',M),
       ( M=[N|_] ->
         setarg(3,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(3,N,K)
       ;
         true
       )
     ),
     detach_atomic_type___1(J,B)
   ),
   atomic(F),
   copy_term_nat(E-F,A-O),
   atomic_type(O).
atomic_type___1__0(A,B) :-
   ( var(B) ->
     B=suspension(C,active,_,A),
     term_variables(A,D),
     'chr gen_id'(C),
     nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',E),
     F=[B|E],
     b_setval('$chr_store_global_list_chr_translate____atomic_type___1',F),
     ( E=[G|_] ->
       setarg(3,G,F)
     ;
       true
     ),
     attach_atomic_type___1(D,B)
   ;
     setarg(2,B,active)
   ).
enumerated_atomic_type(A,_) :-
   atomic_builtin_type(A,_,_),
   !,
   fail.
enumerated_atomic_type(A,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_definition___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,F),
   functor(A,G,H),
   functor(E,G,H),
   !,
   maplist(atomic,F),
   B=F.
enumerated_atomic_type(A,B) :-
   nb_getval('$chr_store_global_list_chr_translate____type_alias___2',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E,F),
   functor(A,G,H),
   functor(E,G,H),
   !,
   atomic(F),
   copy_term_nat(E-F,A-I),
   enumerated_atomic_type(I,B).
enumerated_atomic_type(_,_) :-
   fail.
stored(A,B,yes) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,_,F,G,_),
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',H),
   lookup_ht(H,k(F,G),I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_,_,_),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',K),
   lookup_ht(K,A,L),
   'chr sbag_member'(M,L),
   M=suspension(_,active,_,_,N,O),
   B<N,
   !,
   setarg(2,M,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',P),
   delete_ht(P,k(A,O),M),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',Q),
   delete_ht(Q,A,M),
   R is O-1,
   stored(A,B,maybe),
   stored_complete(A,N,R).
stored(A,B,yes) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,F,G),
   B<F,
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',H),
   lookup_ht(H,k(A,B),I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_,_),
   !,
   setarg(2,E,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',K),
   delete_ht(K,k(A,G),E),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',L),
   delete_ht(L,A,E),
   M is G-1,
   stored(A,B,maybe),
   stored_complete(A,F,M).
stored(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',F),
   insert_ht(F,k(A,C),D),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',G),
   insert_ht(G,k(A,B,C),D).
stored_completing(A,B,C) :-
   ground(A),
   ground(B),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',D),
   (
     (
       lookup_ht(D,k(A,B,yes),E),
       'chr sbag_member'(F,E),
       F=suspension(_,active,_,_,_),
       !,
       G is B+1,
       H is C+1,
       stored_completing(A,G,H)
     ;
       lookup_ht(D,k(A,B,maybe),I),
       'chr sbag_member'(J,I),
       J=suspension(_,active,_,_,_),
       !,
       K is B+1,
       stored_completing(A,K,C)
     )
   ;
     lookup_ht(D,k(A,B,no),L),
     'chr sbag_member'(M,L),
     M=suspension(_,active,_,_,_),
     !,
     stored_complete(A,B,C)
   ).
stored_completing(A,B,C) :-
   stored_complete(A,B,C).
stored_complete(A,B,C) :-
   stored_complete___3__0(A,B,C,_).
stored_complete___3__0(A,B,C,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',D),
   lookup_ht(D,A,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,G,H,I,_),
   G<B,
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',J),
   lookup_ht(J,k(H,I),K),
   'chr sbag_member'(L,K),
   L=suspension(_,active,_,_,_),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',M),
   lookup_ht(M,k(A,G,yes),N),
   'chr sbag_member'(O,N),
   O=suspension(_,active,_,_,_),
   !,
   setarg(2,O,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',P),
   delete_ht(P,k(A,yes),O),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',Q),
   delete_ht(Q,k(A,G,yes),O),
   R is C-1,
   stored(A,G,maybe),
   stored_complete(A,B,R).
stored_complete___3__0(A,B,C,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',D),
   lookup_ht(D,k(A,yes),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,G,_),
   G<B,
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',H),
   lookup_ht(H,k(A,G),I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_,_),
   !,
   setarg(2,F,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',K),
   delete_ht(K,k(A,yes),F),
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',L),
   delete_ht(L,k(A,G,yes),F),
   M is C-1,
   stored(A,G,maybe),
   stored_complete(A,B,M).
stored_complete___3__0(A,B,0,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',D),
   lookup_ht(D,A,E),
   !,
   C=suspension(F,not_stored_yet,t,A,B,0),
   'chr gen_id'(F),
   stored_complete___3__0__0__3(E,A,B,0,C).
stored_complete___3__0__0__3([],A,B,C,D) :-
   stored_complete___3__1(A,B,C,D).
stored_complete___3__0__0__3([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,G,H),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',I),
     lookup_ht(I,A,J) ->
     stored_complete___3__0__1__3(J,H,E,F,A,B,C,D)
   ;
     stored_complete___3__0__0__3(F,A,B,C,D)
   ).
stored_complete___3__0__1__3([],_,_,A,B,C,D,E) :-
   stored_complete___3__0__0__3(A,B,C,D,E).
stored_complete___3__0__1__3([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,_,K,_,_),
     J==D,
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',L),
     lookup_ht(L,K,M) ->
     stored_complete___3__0__2__3(M,K,H,I,A,B,C,D,E,F,G)
   ;
     stored_complete___3__0__1__3(I,A,B,C,D,E,F,G)
   ).
stored_complete___3__0__2__3([],_,_,A,B,C,D,E,F,G,H) :-
   stored_complete___3__0__1__3(A,B,C,D,E,F,G,H).
stored_complete___3__0__2__3([K|L],A,B,C,D,E,F,G,H,I,J) :-
   ( K=suspension(_,active,_,_,_,_,M,N,_),
     K\==B,
     M==A,
     O=t(250,K,B,J,E),
     '$novel_production'(K,O),
     '$novel_production'(B,O),
     '$novel_production'(J,O),
     '$novel_production'(E,O),
     H=<D ->
     '$extend_history'(J,O),
     arg(2,J,P),
     setarg(2,J,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',Q),
       insert_ht(Q,k(G,I),J),
       nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',R),
       insert_ht(R,G,J)
     ;
       true
     ),
     passive(A,N),
     ( J=suspension(_,active,_,_,_,_) ->
       setarg(2,J,inactive),
       stored_complete___3__0__2__3(L,A,B,C,D,E,F,G,H,I,J)
     ;
       true
     )
   ;
     stored_complete___3__0__2__3(L,A,B,C,D,E,F,G,H,I,J)
   ).
stored_complete___3__0(A,B,C,D) :-
   D=suspension(E,not_stored_yet,t,A,B,C),
   'chr gen_id'(E),
   stored_complete___3__1(A,B,C,D).
stored_complete___3__1(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',E),
   lookup_ht(E,A,F),
   !,
   stored_complete___3__1__0__4(F,A,B,C,D).
stored_complete___3__1__0__4([],A,B,C,D) :-
   stored_complete___3__2(A,B,C,D).
stored_complete___3__1__0__4([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,_,G,H,I,J,_),
     G==A,
     K=t(259,D,E),
     '$novel_production'(D,K),
     '$novel_production'(E,K),
     H>B ->
     '$extend_history'(D,K),
     arg(2,D,L),
     setarg(2,D,active),
     ( L==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',M),
       insert_ht(M,k(A,C),D),
       nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',N),
       insert_ht(N,A,D)
     ;
       true
     ),
     passive(I,J),
     ( D=suspension(_,active,_,_,_,_) ->
       setarg(2,D,inactive),
       stored_complete___3__1__0__4(F,A,B,C,D)
     ;
       true
     )
   ;
     stored_complete___3__1__0__4(F,A,B,C,D)
   ).
stored_complete___3__1(A,B,C,D) :-
   stored_complete___3__2(A,B,C,D).
stored_complete___3__2(A,_,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',E),
     insert_ht(E,k(A,B),C),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',F),
     insert_ht(F,A,C)
   ;
     true
   ).
is_stored(A) :-
   ground(A),
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,E),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',F),
   lookup_ht(F,k(A,0),G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,_,I,_),
   I=<E,
   !,
   fail.
is_stored(_).
is_finally_stored(A) :-
   ground(A),
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,E),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',F),
   lookup_ht(F,A,G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,_,I,_),
   I=<E,
   !,
   fail.
is_finally_stored(_).
check_all_passive(A,[B|C]) :-
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_),
   !,
   check_all_passive(A,C).
check_all_passive(A,[]) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_,_,E),
   !,
   chr_warning(weird_program,'All heads passive in ~@.\n\tThis rule never fires. Please check your program.\n',[format_rule(E)]).
check_all_passive(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',E),
   insert_ht(E,k(A,B),C),
   nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',F),
   insert_ht(F,A,C).
constraints_code1([],A,B) :-
   !,
   A=B.
constraints_code1([C|D],A,B) :-
   !,
   constraint_code(C,A,E),
   constraints_code1(D,E,B).
constraints_code1(A,B,C) :-
   D=suspension(E,active,_,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_global_ground_chr_translate____constraints_code1___3',F),
   G=[D|F],
   b_setval('$chr_store_global_ground_chr_translate____constraints_code1___3',G),
   ( F=[H|_] ->
     setarg(3,H,G)
   ;
     true
   ).
constraint_code(A,B,C) :-
   (
     (
       chr_pp_flag(debugable,on)
     ;
       is_stored(A),
       (
         has_active_occurrence(A)
       ;
         chr_pp_flag(late_allocation,off)
       ),
       (
         may_trigger(A)
       ;
         get_allocation_occurrence(A,D),
         get_max_occurrence(A,E),
         E>=D
       )
     ) ->
     constraint_prelude(A,F),
     add_dummy_location(F,G),
     B=[G|H]
   ;
     B=H
   ),
   I=[0],
   occurrences_code(A,1,I,J,H,K),
   gen_cond_attach_clause(A,J,K,C).
has_active_occurrence(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
has_active_occurrence(A) :-
   has_active_occurrence(A,1),
   memo_has_active_occurrence(A).
has_active_occurrence(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,F),
   B>F,
   !,
   fail.
has_active_occurrence(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,_,F,G,_),
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',H),
   lookup_ht(H,k(F,G),I),
   'chr sbag_member'(J,I),
   J=suspension(_,active,_,_,_),
   !,
   K is B+1,
   has_active_occurrence(A,K).
has_active_occurrence(_,_).
memo_has_active_occurrence(A) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',D),
   insert_ht(D,A,B).
use_auxiliary_predicate(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
use_auxiliary_predicate(A) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',D),
   insert_ht(D,A,B).
use_auxiliary_predicate(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
use_auxiliary_predicate(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',E),
   insert_ht(E,A,C),
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',F),
   insert_ht(F,k(A,B),C).
is_used_auxiliary_predicate(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
is_used_auxiliary_predicate(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !.
is_used_auxiliary_predicate(_) :-
   fail.
is_used_auxiliary_predicate(A,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
is_used_auxiliary_predicate(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
is_used_auxiliary_predicate(_,_) :-
   fail.
use_auxiliary_module(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
use_auxiliary_module(A) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',D),
   insert_ht(D,A,B).
is_used_auxiliary_module(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
is_used_auxiliary_module(_) :-
   fail.
occurrences_code(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',G),
   lookup_ht(G,A,H),
   'chr sbag_member'(I,H),
   I=suspension(_,active,_,_,J),
   B>J,
   !,
   D=C,
   E=F.
occurrences_code(A,B,C,D,E,F) :-
   occurrence_code(A,B,C,G,E,H),
   I is B+1,
   occurrences_code(A,I,G,D,H,F).
occurrence_code(A,B,C,D,E,F) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',G),
   lookup_ht(G,k(A,B),H),
   'chr sbag_member'(I,H),
   I=suspension(_,active,_,_,_,_,J,K,_),
   (
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',L),
     lookup_ht(L,k(J,K),M),
     'chr sbag_member'(N,M),
     N=suspension(_,active,_,_,_),
     !,
     ( named_history(J,_,_) ->
       does_use_history(A,B)
     ;
       true
     ),
     D=C,
     E=F
   ;
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',O),
     lookup_ht(O,J,P),
     'chr sbag_member'(Q,P),
     Q=suspension(_,active,_,_,_,R),
     !,
     R=pragma(rule(S,T,_,_),ids(U,V),_,_,_),
     ( select2(K,W,U,S,X,Y) ->
       D=C,
       head1_code(W,K,Y,X,R,A,B,C,E,F)
     ;
       ( select2(K,Z,V,T,A1,B1) ->
         head2_code(Z,K,B1,A1,R,A,B,C,E,C1),
         ( should_skip_to_next_id(A,B) ->
           inc_id(C,D),
           ( unconditional_occurrence(A,B) ->
             C1=F
           ;
             gen_alloc_inc_clause(A,B,C,C1,F)
           )
         ;
           D=C,
           C1=F
         )
       )
     )
   ).
occurrence_code(A,B,_,_,_,_) :-
   chr_error(internal,'occurrence_code/6: missing information to compile ~w:~w\n',[A,B]).
functional_dependency(A,B,C,D) :-
   B>1,
   nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',E),
   lookup_ht(E,A,F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_,H),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',I),
   lookup_ht(I,k(A,B),J),
   'chr sbag_member'(K,J),
   K=suspension(_,active,_,_,_,L,_,_,_),
   H>L,
   !,
   functional_dependency(A,1,C,D).
functional_dependency(A,B,C,D) :-
   E=suspension(F,active,A,B,C,D),
   'chr gen_id'(F),
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',G),
   insert_ht(G,A,E),
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',H),
   insert_ht(H,k(A,B),E).
get_functional_dependency(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',E),
   lookup_ht(E,A,F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,H,I,J),
   B>=H,
   !,
   C=I,
   D=J.
get_functional_dependency(_,_,_,_) :-
   fail.
initial_call_pattern(A) :-
   initial_call_pattern___1__0(A,_).
initial_call_pattern___1__0(A,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !.
initial_call_pattern___1__0(A,B) :-
   B=suspension(C,active,t,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',D),
   insert_ht(D,A,B),
   call_pattern(A),
   ( B=suspension(_,active,_,_) ->
     setarg(2,B,inactive),
     initial_call_pattern___1__1(A,B)
   ;
     true
   ).
initial_call_pattern___1__1(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',C),
   lookup_ht(C,A,D),
   !,
   initial_call_pattern___1__1__0__4(D,A,B).
initial_call_pattern___1__1__0__4([],A,B) :-
   initial_call_pattern___1__2(A,B).
initial_call_pattern___1__1__0__4([C|D],A,B) :-
   ( C=suspension(_,active,_,E,F),
     E==A,
     nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',G) ->
     initial_call_pattern___1__1__1__4(G,F,C,D,A,B)
   ;
     initial_call_pattern___1__1__0__4(D,A,B)
   ).
initial_call_pattern___1__1__1__4([],_,_,A,B,C) :-
   initial_call_pattern___1__1__0__4(A,B,C).
initial_call_pattern___1__1__1__4([F|G],A,B,C,D,E) :-
   ( F=suspension(_,active,_,H),
     I=t(303,E,B,F),
     '$novel_production'(E,I),
     '$novel_production'(B,I) ->
     '$extend_history'(E,I),
     setarg(2,E,active),
     ai_observation_schedule_new_calls(H,A),
     ( E=suspension(_,active,_,_) ->
       setarg(2,E,inactive),
       initial_call_pattern___1__1__1__4(G,A,B,C,D,E)
     ;
       true
     )
   ;
     initial_call_pattern___1__1__1__4(G,A,B,C,D,E)
   ).
initial_call_pattern___1__1(A,B) :-
   initial_call_pattern___1__2(A,B).
initial_call_pattern___1__2(_,A) :-
   setarg(2,A,active).
call_pattern(A) :-
   call_pattern___1__0(A,_).
call_pattern___1__0(A,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
call_pattern___1__0(A,B) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',D),
   insert_ht(D,A,B),
   call_pattern_worker(A),
   ( B=suspension(_,active,_) ->
     setarg(2,B,inactive),
     call_pattern___1__1(A,B)
   ;
     true
   ).
call_pattern___1__1(_,A) :-
   setarg(2,A,active).
call_pattern_worker(odom([],A)) :-
   !,
   final_answer_pattern(odom([],A),odom([],A)).
call_pattern_worker(odom([B|C],A)) :-
   !,
   D=odom(B,A),
   depends_on_goal(odom([B|C],A),D),
   call_pattern(D).
call_pattern_worker(odom((B;C),A)) :-
   !,
   D=odom((B;C),A),
   E=odom([],A),
   final_answer_pattern(D,E),
   F=odom(B,A),
   G=odom(C,A),
   call_pattern(F),
   call_pattern(G),
   depends_on_as(D,F,G).
call_pattern_worker(odom(builtin,A)) :-
   !,
   ord_empty(B),
   final_answer_pattern(odom(builtin,A),odom([],B)).
call_pattern_worker(odom(occ(B,C),A)) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',D),
   lookup_ht(D,B,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   C>G,
   !,
   final_answer_pattern(odom(occ(B,C),A),odom([],A)).
call_pattern_worker(odom(A,B)) :-
   A=_/_,
   !,
   C=odom(occ(A,1),B),
   call_pattern(C),
   depends_on(odom(A,B),C).
call_pattern_worker(odom(occ(B,C),A)) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(B,C),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,G,H,_),
   is_passive(G,H),
   !,
   I is C+1,
   J=odom(occ(B,I),A),
   call_pattern(J),
   final_answer_pattern(odom(occ(B,C),A),odom([],A)),
   depends_on(odom(occ(B,C),A),J).
call_pattern_worker(odom(occ(B,C),A)) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',D),
   (
     lookup_ht(D,k(B,C,simplification),E),
     'chr sbag_member'(F,E),
     F=suspension(_,active,_,_,_,_,G,H,_),
     \+is_passive(G,H),
     !,
     ai_observation_memo_simplification_rest_heads(B,C,I),
     ai_observation_observe_set(A,I,J),
     ai_observation_memo_abstract_goal(G,K),
     call_pattern(odom(K,J)),
     L is C+1,
     M=odom(occ(B,L),A),
     call_pattern(M),
     depends_on_as(odom(occ(B,C),A),odom(K,J),M),
     final_answer_pattern(odom(occ(B,C),A),odom([],A))
   ;
     lookup_ht(D,k(B,C,propagation),N),
     'chr sbag_member'(O,N),
     O=suspension(_,active,_,_,_,_,P,Q,_),
     \+is_passive(P,Q),
     !,
     ai_observation_memo_propagation_rest_heads(B,C,R),
     ai_observation_observe_set(A,R,S),
     ord_add_element(S,B,T),
     ai_observation_memo_abstract_goal(P,U),
     call_pattern(odom(U,T)),
     ( ord_memberchk(B,S) ->
       V=no
     ;
       V=yes
     ),
     W is C+1,
     X=odom(occ(B,W),A),
     call_pattern(X),
     depends_on_ap(odom(occ(B,C),A),odom(U,T),X,V)
   ).
call_pattern_worker(A) :-
   chr_error(internal,'AI observation analysis: unexpected abstract state ~w\n',[A]).
final_answer_pattern(A,B) :-
   final_answer_pattern___2__0(A,B,_).
final_answer_pattern___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',D),
   lookup_ht(D,A,E),
   (
     'chr sbag_member'(F,E),
     F=suspension(_,active,_,_,G),
     ai_observation_leq(B,G),
     !
   ;
     !,
     final_answer_pattern___2__0__0__2(E,A,B,C)
   ).
final_answer_pattern___2__0__0__2([],A,B,C) :-
   final_answer_pattern___2__1(A,B,C).
final_answer_pattern___2__0__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==A,
     ai_observation_leq(G,B) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',H),
     delete_ht(H,A,D),
     final_answer_pattern___2__0__0__2(E,A,B,C)
   ;
     final_answer_pattern___2__0__0__2(E,A,B,C)
   ).
final_answer_pattern___2__0(A,B,C) :-
   final_answer_pattern___2__1(A,B,C).
final_answer_pattern___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',D),
   lookup_ht(D,A,E),
   !,
   C=suspension(F,not_stored_yet,t,A,B),
   'chr gen_id'(F),
   final_answer_pattern___2__1__0__3(E,A,B,C).
final_answer_pattern___2__1__0__3([],A,B,C) :-
   final_answer_pattern___2__2(A,B,C).
final_answer_pattern___2__1__0__3([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F),
     F==A,
     nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',G) ->
     final_answer_pattern___2__1__1__3(G,D,E,A,B,C)
   ;
     final_answer_pattern___2__1__0__3(E,A,B,C)
   ).
final_answer_pattern___2__1__1__3([],_,A,B,C,D) :-
   final_answer_pattern___2__1__0__3(A,B,C,D).
final_answer_pattern___2__1__1__3([F|G],A,B,C,D,E) :-
   ( F=suspension(_,active,_,H),
     I=t(303,A,E,F),
     '$novel_production'(A,I),
     '$novel_production'(E,I) ->
     '$extend_history'(E,I),
     arg(2,E,J),
     setarg(2,E,active),
     ( J==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',K),
       insert_ht(K,C,E)
     ;
       true
     ),
     ai_observation_schedule_new_calls(H,D),
     ( E=suspension(_,active,_,_,_) ->
       setarg(2,E,inactive),
       final_answer_pattern___2__1__1__3(G,A,B,C,D,E)
     ;
       true
     )
   ;
     final_answer_pattern___2__1__1__3(G,A,B,C,D,E)
   ).
final_answer_pattern___2__1(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   final_answer_pattern___2__2(A,B,C).
final_answer_pattern___2__2(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__2__0__4(E,A,B,C).
final_answer_pattern___2__2__0__4([],A,B,C) :-
   final_answer_pattern___2__3(A,B,C).
final_answer_pattern___2__2__0__4([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     G==A,
     H=t(305,D,C),
     '$novel_production'(D,H),
     '$novel_production'(C,H) ->
     '$extend_history'(C,H),
     arg(2,C,I),
     setarg(2,C,active),
     ( I==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',J),
       insert_ht(J,A,C)
     ;
       true
     ),
     final_answer_pattern(F,B),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       final_answer_pattern___2__2__0__4(E,A,B,C)
     ;
       true
     )
   ;
     final_answer_pattern___2__2__0__4(E,A,B,C)
   ).
final_answer_pattern___2__2(A,B,C) :-
   final_answer_pattern___2__3(A,B,C).
final_answer_pattern___2__3(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__3__0__5(E,A,B,C).
final_answer_pattern___2__3__0__5([],A,B,C) :-
   final_answer_pattern___2__4(A,B,C).
final_answer_pattern___2__3__0__5([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',H),
     lookup_ht(H,F,I) ->
     final_answer_pattern___2__3__1__5(I,F,D,E,A,B,C)
   ;
     final_answer_pattern___2__3__0__5(E,A,B,C)
   ).
final_answer_pattern___2__3__1__5([],_,_,A,B,C,D) :-
   final_answer_pattern___2__3__0__5(A,B,C,D).
final_answer_pattern___2__3__1__5([G|H],A,B,C,D,E,F) :-
   ( G=suspension(_,active,_,I,J),
     I==A ->
     setarg(2,G,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',K),
     delete_ht(K,A,G),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',L),
     delete_ht(L,J,G),
     final_answer_pattern___2__3__1__5(H,A,B,C,D,E,F)
   ;
     final_answer_pattern___2__3__1__5(H,A,B,C,D,E,F)
   ).
final_answer_pattern___2__3(A,B,C) :-
   final_answer_pattern___2__4(A,B,C).
final_answer_pattern___2__4(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__4__0__6(E,A,B,C).
final_answer_pattern___2__4__0__6([],A,B,C) :-
   final_answer_pattern___2__5(A,B,C).
final_answer_pattern___2__4__0__6([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     G==A,
     H=t(310,D,C),
     '$novel_production'(D,H),
     '$novel_production'(C,H) ->
     '$extend_history'(C,H),
     arg(2,C,I),
     setarg(2,C,active),
     ( I==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',J),
       insert_ht(J,A,C)
     ;
       true
     ),
     F=odom([_|K],_),
     B=odom([],L),
     M=odom(K,L),
     call_pattern(M),
     depends_on(F,M),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       final_answer_pattern___2__4__0__6(E,A,B,C)
     ;
       true
     )
   ;
     final_answer_pattern___2__4__0__6(E,A,B,C)
   ).
final_answer_pattern___2__4(A,B,C) :-
   final_answer_pattern___2__5(A,B,C).
final_answer_pattern___2__5(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__5__0__7(E,A,B,C).
final_answer_pattern___2__5__0__7([],A,B,C) :-
   final_answer_pattern___2__6(A,B,C).
final_answer_pattern___2__5__0__7([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G,H),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',I),
     lookup_ht(I,H,J) ->
     final_answer_pattern___2__5__1__7(J,F,H,D,E,A,B,C)
   ;
     final_answer_pattern___2__5__0__7(E,A,B,C)
   ).
final_answer_pattern___2__5__1__7([],_,_,_,A,B,C,D) :-
   final_answer_pattern___2__5__0__7(A,B,C,D).
final_answer_pattern___2__5__1__7([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,J,K),
     J==B,
     L=t(317,C,G,H),
     '$novel_production'(C,L),
     '$novel_production'(G,L),
     '$novel_production'(H,L) ->
     '$extend_history'(G,L),
     arg(2,G,M),
     setarg(2,G,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',N),
       insert_ht(N,E,G)
     ;
       true
     ),
     ai_observation_lub(F,K,O),
     final_answer_pattern(A,O),
     ( G=suspension(_,active,_,_,_) ->
       setarg(2,G,inactive),
       final_answer_pattern___2__5__1__7(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     final_answer_pattern___2__5__1__7(I,A,B,C,D,E,F,G)
   ).
final_answer_pattern___2__5(A,B,C) :-
   final_answer_pattern___2__6(A,B,C).
final_answer_pattern___2__6(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__6__0__8(E,A,B,C).
final_answer_pattern___2__6__0__8([],A,B,C) :-
   final_answer_pattern___2__7(A,B,C).
final_answer_pattern___2__6__0__8([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G,H),
     H==A,
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',I),
     lookup_ht(I,G,J) ->
     final_answer_pattern___2__6__1__8(J,F,G,D,E,A,B,C)
   ;
     final_answer_pattern___2__6__0__8(E,A,B,C)
   ).
final_answer_pattern___2__6__1__8([],_,_,_,A,B,C,D) :-
   final_answer_pattern___2__6__0__8(A,B,C,D).
final_answer_pattern___2__6__1__8([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,J,K),
     J==B,
     L=t(317,C,H,G),
     '$novel_production'(C,L),
     '$novel_production'(H,L),
     '$novel_production'(G,L) ->
     '$extend_history'(G,L),
     arg(2,G,M),
     setarg(2,G,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',N),
       insert_ht(N,E,G)
     ;
       true
     ),
     ai_observation_lub(K,F,O),
     final_answer_pattern(A,O),
     ( G=suspension(_,active,_,_,_) ->
       setarg(2,G,inactive),
       final_answer_pattern___2__6__1__8(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     final_answer_pattern___2__6__1__8(I,A,B,C,D,E,F,G)
   ).
final_answer_pattern___2__6(A,B,C) :-
   final_answer_pattern___2__7(A,B,C).
final_answer_pattern___2__7(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__7__0__9(E,A,B,C).
final_answer_pattern___2__7__0__9([],A,B,C) :-
   final_answer_pattern___2__8(A,B,C).
final_answer_pattern___2__7__0__9([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,_,G,_),
     G==A,
     H=t(325,D,C),
     '$novel_production'(D,H),
     '$novel_production'(C,H) ->
     '$extend_history'(C,H),
     arg(2,C,I),
     setarg(2,C,active),
     ( I==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',J),
       insert_ht(J,A,C)
     ;
       true
     ),
     final_answer_pattern(F,B),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       final_answer_pattern___2__7__0__9(E,A,B,C)
     ;
       true
     )
   ;
     final_answer_pattern___2__7__0__9(E,A,B,C)
   ).
final_answer_pattern___2__7(A,B,C) :-
   final_answer_pattern___2__8(A,B,C).
final_answer_pattern___2__8(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__8__0__10(E,A,B,C).
final_answer_pattern___2__8__0__10([],A,B,C) :-
   final_answer_pattern___2__9(A,B,C).
final_answer_pattern___2__8__0__10([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G,H,I),
     G==A,
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',J),
     lookup_ht(J,H,K) ->
     final_answer_pattern___2__8__1__10(K,F,H,I,D,E,A,B,C)
   ;
     final_answer_pattern___2__8__0__10(E,A,B,C)
   ).
final_answer_pattern___2__8__1__10([],_,_,_,_,A,B,C,D) :-
   final_answer_pattern___2__8__0__10(A,B,C,D).
final_answer_pattern___2__8__1__10([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,K,L),
     K==B,
     M=t(326,D,H,I),
     '$novel_production'(D,M),
     '$novel_production'(H,M),
     '$novel_production'(I,M) ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',O),
       insert_ht(O,F,H)
     ;
       true
     ),
     A=odom(occ(P,Q),_),
     ( ai_observation_is_observed(G,P) ->
       ai_observed_internal(P,Q)
     ;
       ai_not_observed_internal(P,Q)
     ),
     ( C==yes ->
       G=odom([],R),
       ord_del_element(R,P,S),
       T=odom([],S)
     ;
       T=G
     ),
     ai_observation_lub(T,L,U),
     final_answer_pattern(A,U),
     ( H=suspension(_,active,_,_,_) ->
       setarg(2,H,inactive),
       final_answer_pattern___2__8__1__10(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     final_answer_pattern___2__8__1__10(J,A,B,C,D,E,F,G,H)
   ).
final_answer_pattern___2__8(A,B,C) :-
   final_answer_pattern___2__9(A,B,C).
final_answer_pattern___2__9(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',D),
   lookup_ht(D,A,E),
   !,
   final_answer_pattern___2__9__0__11(E,A,B,C).
final_answer_pattern___2__9__0__11([],A,B,C) :-
   final_answer_pattern___2__10(A,B,C).
final_answer_pattern___2__9__0__11([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G,H,I),
     H==A,
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',J),
     lookup_ht(J,G,K) ->
     final_answer_pattern___2__9__1__11(K,F,G,I,D,E,A,B,C)
   ;
     final_answer_pattern___2__9__0__11(E,A,B,C)
   ).
final_answer_pattern___2__9__1__11([],_,_,_,_,A,B,C,D) :-
   final_answer_pattern___2__9__0__11(A,B,C,D).
final_answer_pattern___2__9__1__11([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,K,L),
     K==B,
     M=t(326,D,I,H),
     '$novel_production'(D,M),
     '$novel_production'(I,M),
     '$novel_production'(H,M) ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',O),
       insert_ht(O,F,H)
     ;
       true
     ),
     A=odom(occ(P,Q),_),
     ( ai_observation_is_observed(L,P) ->
       ai_observed_internal(P,Q)
     ;
       ai_not_observed_internal(P,Q)
     ),
     ( C==yes ->
       L=odom([],R),
       ord_del_element(R,P,S),
       T=odom([],S)
     ;
       T=L
     ),
     ai_observation_lub(T,G,U),
     final_answer_pattern(A,U),
     ( H=suspension(_,active,_,_,_) ->
       setarg(2,H,inactive),
       final_answer_pattern___2__9__1__11(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     final_answer_pattern___2__9__1__11(J,A,B,C,D,E,F,G,H)
   ).
final_answer_pattern___2__9(A,B,C) :-
   final_answer_pattern___2__10(A,B,C).
final_answer_pattern___2__10(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',D),
     insert_ht(D,A,B)
   ;
     true
   ).
abstract_constraints(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',B),
   (
     'chr sbag_member'(C,B),
     C=suspension(_,active,_,_),
     !
   ;
     !,
     abstract_constraints___1__0__0__2(B,A)
   ).
abstract_constraints___1__0__0__2([],A) :-
   abstract_constraints___1__1(A).
abstract_constraints___1__0__0__2([B|C],A) :-
   ( B=suspension(_,active,_,_) ->
     setarg(2,B,removed),
     arg(3,B,D),
     ( var(D) ->
       nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',E),
       E=[_|F],
       b_setval('$chr_store_global_ground_chr_translate____abstract_constraints___1',F),
       ( F=[G|_] ->
         setarg(3,G,_)
       ;
         true
       )
     ;
       D=[_,_|F],
       setarg(2,D,F),
       ( F=[G|_] ->
         setarg(3,G,D)
       ;
         true
       )
     ),
     abstract_constraints___1__0__0__2(C,A)
   ;
     abstract_constraints___1__0__0__2(C,A)
   ).
abstract_constraints(A) :-
   abstract_constraints___1__1(A).
abstract_constraints___1__1(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____abstract_constraints___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
depends_on(A,B) :-
   depends_on___2__0(A,B,_).
depends_on___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',D),
   lookup_ht(D,B,E),
   !,
   C=suspension(F,not_stored_yet,t,A,B),
   'chr gen_id'(F),
   depends_on___2__0__0__1(E,A,B,C).
depends_on___2__0__0__1([],A,B,C) :-
   depends_on___2__1(A,B,C).
depends_on___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==B,
     H=t(305,C,D),
     '$novel_production'(C,H),
     '$novel_production'(D,H) ->
     '$extend_history'(C,H),
     arg(2,C,I),
     setarg(2,C,active),
     ( I==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',J),
       insert_ht(J,A,C),
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',K),
       insert_ht(K,B,C)
     ;
       true
     ),
     final_answer_pattern(A,G),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       depends_on___2__0__0__1(E,A,B,C)
     ;
       true
     )
   ;
     depends_on___2__0__0__1(E,A,B,C)
   ).
depends_on___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   depends_on___2__1(A,B,C).
depends_on___2__1(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',E),
     insert_ht(E,A,C),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',F),
     insert_ht(F,B,C)
   ;
     true
   ).
depends_on_ap(A,B,C,D) :-
   depends_on_ap___4__0(A,B,C,D,_).
depends_on_ap___4__0(A,B,C,D,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',F),
   lookup_ht(F,C,G),
   !,
   E=suspension(H,not_stored_yet,t,A,B,C,D),
   'chr gen_id'(H),
   depends_on_ap___4__0__0__1(G,A,B,C,D,E).
depends_on_ap___4__0__0__1([],A,B,C,D,E) :-
   depends_on_ap___4__1(A,B,C,D,E).
depends_on_ap___4__0__0__1([F|G],A,B,C,D,E) :-
   ( F=suspension(_,active,_,H,I),
     H==C,
     J=t(325,E,F),
     '$novel_production'(E,J),
     '$novel_production'(F,J) ->
     '$extend_history'(E,J),
     arg(2,E,K),
     setarg(2,E,active),
     ( K==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',L),
       insert_ht(L,B,E),
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',M),
       insert_ht(M,C,E)
     ;
       true
     ),
     final_answer_pattern(A,I),
     ( E=suspension(_,active,_,_,_,_,_) ->
       setarg(2,E,inactive),
       depends_on_ap___4__0__0__1(G,A,B,C,D,E)
     ;
       true
     )
   ;
     depends_on_ap___4__0__0__1(G,A,B,C,D,E)
   ).
depends_on_ap___4__0(A,B,C,D,E) :-
   E=suspension(F,not_stored_yet,t,A,B,C,D),
   'chr gen_id'(F),
   depends_on_ap___4__1(A,B,C,D,E).
depends_on_ap___4__1(A,B,C,D,E) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',F),
   lookup_ht(F,B,G),
   !,
   depends_on_ap___4__1__0__2(G,A,B,C,D,E).
depends_on_ap___4__1__0__2([],A,B,C,D,E) :-
   depends_on_ap___4__2(A,B,C,D,E).
depends_on_ap___4__1__0__2([F|G],A,B,C,D,E) :-
   ( F=suspension(_,active,_,H,I),
     H==B,
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',J),
     lookup_ht(J,C,K) ->
     depends_on_ap___4__1__1__2(K,I,F,G,A,B,C,D,E)
   ;
     depends_on_ap___4__1__0__2(G,A,B,C,D,E)
   ).
depends_on_ap___4__1__1__2([],_,_,A,B,C,D,E,F) :-
   depends_on_ap___4__1__0__2(A,B,C,D,E,F).
depends_on_ap___4__1__1__2([I|J],A,B,C,D,E,F,G,H) :-
   ( I=suspension(_,active,_,K,L),
     I\==B,
     K==F,
     M=t(326,H,B,I),
     '$novel_production'(H,M),
     '$novel_production'(B,M),
     '$novel_production'(I,M) ->
     '$extend_history'(H,M),
     arg(2,H,N),
     setarg(2,H,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',O),
       insert_ht(O,E,H),
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',P),
       insert_ht(P,F,H)
     ;
       true
     ),
     D=odom(occ(Q,R),_),
     ( ai_observation_is_observed(A,Q) ->
       ai_observed_internal(Q,R)
     ;
       ai_not_observed_internal(Q,R)
     ),
     ( G==yes ->
       A=odom([],S),
       ord_del_element(S,Q,T),
       U=odom([],T)
     ;
       U=A
     ),
     ai_observation_lub(U,L,V),
     final_answer_pattern(D,V),
     ( H=suspension(_,active,_,_,_,_,_) ->
       setarg(2,H,inactive),
       depends_on_ap___4__1__1__2(J,A,B,C,D,E,F,G,H)
     ;
       true
     )
   ;
     depends_on_ap___4__1__1__2(J,A,B,C,D,E,F,G,H)
   ).
depends_on_ap___4__1(A,B,C,D,E) :-
   depends_on_ap___4__2(A,B,C,D,E).
depends_on_ap___4__2(_,A,B,_,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',E),
     insert_ht(E,A,C),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',F),
     insert_ht(F,B,C)
   ;
     true
   ).
depends_on_goal(A,B) :-
   depends_on_goal___2__0(A,B,_).
depends_on_goal___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',D),
   lookup_ht(D,A,E),
   !,
   depends_on_goal___2__0__0__1(E,A,B,C).
depends_on_goal___2__0__0__1([],A,B,C) :-
   depends_on_goal___2__1(A,B,C).
depends_on_goal___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==A,
     ground(B),
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',H),
     lookup_ht(H,B,I),
     'chr sbag_member'(J,I),
     J=suspension(_,active,_,_,_) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',K),
     delete_ht(K,A,D),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',L),
     delete_ht(L,G,D),
     depends_on_goal___2__0__0__1(E,A,B,C)
   ;
     depends_on_goal___2__0__0__1(E,A,B,C)
   ).
depends_on_goal___2__0(A,B,C) :-
   depends_on_goal___2__1(A,B,C).
depends_on_goal___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',D),
   lookup_ht(D,B,E),
   !,
   C=suspension(F,not_stored_yet,t,A,B),
   'chr gen_id'(F),
   depends_on_goal___2__1__0__2(E,A,B,C).
depends_on_goal___2__1__0__2([],A,B,C) :-
   depends_on_goal___2__2(A,B,C).
depends_on_goal___2__1__0__2([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F==B,
     H=t(310,C,D),
     '$novel_production'(C,H),
     '$novel_production'(D,H) ->
     '$extend_history'(C,H),
     arg(2,C,I),
     setarg(2,C,active),
     ( I==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',J),
       insert_ht(J,B,C)
     ;
       true
     ),
     A=odom([_|K],_),
     G=odom([],L),
     M=odom(K,L),
     call_pattern(M),
     depends_on(A,M),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       depends_on_goal___2__1__0__2(E,A,B,C)
     ;
       true
     )
   ;
     depends_on_goal___2__1__0__2(E,A,B,C)
   ).
depends_on_goal___2__1(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   depends_on_goal___2__2(A,B,C).
depends_on_goal___2__2(_,A,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',D),
     insert_ht(D,A,B)
   ;
     true
   ).
ai_observed_internal(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',C),
   lookup_ht(C,k(A,B),D),
   !,
   ai_observed_internal___2__0__0__1(D,A,B).
ai_observed_internal___2__0__0__1([],A,B) :-
   ai_observed_internal___2__1(A,B).
ai_observed_internal___2__0__0__1([C|D],A,B) :-
   ( C=suspension(_,active,_,E,F),
     E==A,
     F==B ->
     setarg(2,C,removed),
     arg(3,C,G),
     ( var(G) ->
       nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',H),
       H=[_|I],
       b_setval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',I),
       ( I=[J|_] ->
         setarg(3,J,_)
       ;
         true
       )
     ;
       G=[_,_|I],
       setarg(2,G,I),
       ( I=[J|_] ->
         setarg(3,J,G)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',K),
     delete_ht(K,k(A,B),C),
     ai_observed_internal___2__0__0__1(D,A,B)
   ;
     ai_observed_internal___2__0__0__1(D,A,B)
   ).
ai_observed_internal(A,B) :-
   ai_observed_internal___2__1(A,B).
ai_observed_internal___2__1(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
ai_observed_internal___2__1(_,_) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',A),
   'chr sbag_member'(B,A),
   B=suspension(_,active,_),
   !.
ai_observed_internal___2__1(A,B) :-
   C=suspension(D,active,_,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',E),
   F=[C|E],
   b_setval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',F),
   ( E=[G|_] ->
     setarg(3,G,F)
   ;
     true
   ),
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',H),
   insert_ht(H,k(A,B),C).
ai_not_observed_internal(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
ai_not_observed_internal(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
ai_not_observed_internal(A,B) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !,
   ai_not_observed(A,B).
ai_not_observed_internal(A,B) :-
   C=suspension(D,active,_,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',E),
   F=[C|E],
   b_setval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',F),
   ( E=[G|_] ->
     setarg(3,G,F)
   ;
     true
   ),
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',H),
   insert_ht(H,k(A,B),C).
ai_not_observed(A,B) :-
   ai_not_observed___2__0(A,B,_).
ai_not_observed___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',D),
   lookup_ht(D,k(A,B,yes),E),
   !,
   C=suspension(F,not_stored_yet,A,B),
   'chr gen_id'(F),
   ai_not_observed___2__0__0__1(E,A,B,C).
ai_not_observed___2__0__0__1([],A,B,C) :-
   ai_not_observed___2__1(A,B,C).
ai_not_observed___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G,H),
     F==A,
     G==B,
     H=yes,
     ground(A),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',I),
     lookup_ht(I,A,J),
     'chr sbag_member'(K,J),
     K=suspension(_,active,_,_,L,M),
     B<L ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',N),
     delete_ht(N,k(A,yes),D),
     nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',O),
     delete_ht(O,k(A,B,yes),D),
     setarg(2,K,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',P),
     delete_ht(P,k(A,M),K),
     nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',Q),
     delete_ht(Q,A,K),
     arg(2,C,R),
     setarg(2,C,active),
     ( R==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',S),
       insert_ht(S,k(A,B),C)
     ;
       true
     ),
     T is M-1,
     stored(A,B,maybe),
     stored_complete(A,L,T),
     ( C=suspension(_,active,_,_) ->
       setarg(2,C,inactive),
       ai_not_observed___2__0__0__1(E,A,B,C)
     ;
       true
     )
   ;
     ai_not_observed___2__0__0__1(E,A,B,C)
   ).
ai_not_observed___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,A,B),
   'chr gen_id'(D),
   ai_not_observed___2__1(A,B,C).
ai_not_observed___2__1(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',E),
     insert_ht(E,k(A,B),C)
   ;
     true
   ).
ai_is_observed(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !,
   fail.
ai_is_observed(_,_).
depends_on_as(A,B,C) :-
   depends_on_as___3__0(A,B,C,_).
depends_on_as___3__0(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',E),
   lookup_ht(E,B,F),
   !,
   D=suspension(G,not_stored_yet,t,A,B,C),
   'chr gen_id'(G),
   depends_on_as___3__0__0__1(F,A,B,C,D).
depends_on_as___3__0__0__1([],A,B,C,D) :-
   depends_on_as___3__1(A,B,C,D).
depends_on_as___3__0__0__1([E|F],A,B,C,D) :-
   ( E=suspension(_,active,_,G,H),
     G==B,
     nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',I),
     lookup_ht(I,C,J) ->
     depends_on_as___3__0__1__1(J,H,E,F,A,B,C,D)
   ;
     depends_on_as___3__0__0__1(F,A,B,C,D)
   ).
depends_on_as___3__0__1__1([],_,_,A,B,C,D,E) :-
   depends_on_as___3__0__0__1(A,B,C,D,E).
depends_on_as___3__0__1__1([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,J,K),
     H\==B,
     J==F,
     L=t(317,G,B,H),
     '$novel_production'(G,L),
     '$novel_production'(B,L),
     '$novel_production'(H,L) ->
     '$extend_history'(G,L),
     arg(2,G,M),
     setarg(2,G,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',N),
       insert_ht(N,F,G),
       nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',O),
       insert_ht(O,E,G)
     ;
       true
     ),
     ai_observation_lub(A,K,P),
     final_answer_pattern(D,P),
     ( G=suspension(_,active,_,_,_,_) ->
       setarg(2,G,inactive),
       depends_on_as___3__0__1__1(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     depends_on_as___3__0__1__1(I,A,B,C,D,E,F,G)
   ).
depends_on_as___3__0(A,B,C,D) :-
   D=suspension(E,not_stored_yet,t,A,B,C),
   'chr gen_id'(E),
   depends_on_as___3__1(A,B,C,D).
depends_on_as___3__1(_,A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',E),
     insert_ht(E,B,C),
     nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',F),
     insert_ht(F,A,C)
   ;
     true
   ).
ai_observation_gather_results :-
   ai_observation_gather_results___0__0(_).
ai_observation_gather_results___0__0(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',B),
   !,
   ai_observation_gather_results___0__0__0__1(B,A).
ai_observation_gather_results___0__0__0__1([],A) :-
   ai_observation_gather_results___0__1(A).
ai_observation_gather_results___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,D,E) ->
     setarg(2,B,removed),
     arg(3,B,F),
     ( var(F) ->
       nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',G),
       G=[_|H],
       b_setval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',H),
       ( H=[I|_] ->
         setarg(3,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(3,I,F)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',J),
     delete_ht(J,k(D,E),B),
     ai_observation_gather_results___0__0__0__1(C,A)
   ;
     ai_observation_gather_results___0__0__0__1(C,A)
   ).
ai_observation_gather_results___0__0(A) :-
   ai_observation_gather_results___0__1(A).
ai_observation_gather_results___0__1(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',B),
   !,
   A=suspension(C,not_stored_yet,_),
   'chr gen_id'(C),
   ai_observation_gather_results___0__1__0__2(B,A).
ai_observation_gather_results___0__1__0__2([],A) :-
   ai_observation_gather_results___0__2(A).
ai_observation_gather_results___0__1__0__2([B|C],A) :-
   ( B=suspension(_,active,_,D,E) ->
     setarg(2,B,removed),
     arg(3,B,F),
     ( var(F) ->
       nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',G),
       G=[_|H],
       b_setval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',H),
       ( H=[I|_] ->
         setarg(3,I,_)
       ;
         true
       )
     ;
       F=[_,_|H],
       setarg(2,F,H),
       ( H=[I|_] ->
         setarg(3,I,F)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',J),
     delete_ht(J,k(D,E),B),
     arg(2,A,K),
     setarg(2,A,active),
     ( K==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',L),
       M=[A|L],
       b_setval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',M),
       ( L=[N|_] ->
         setarg(3,N,M)
       ;
         true
       )
     ;
       true
     ),
     ai_not_observed(D,E),
     ( A=suspension(_,active,_) ->
       setarg(2,A,inactive),
       ai_observation_gather_results___0__1__0__2(C,A)
     ;
       true
     )
   ;
     ai_observation_gather_results___0__1__0__2(C,A)
   ).
ai_observation_gather_results___0__1(A) :-
   A=suspension(B,not_stored_yet,_),
   'chr gen_id'(B),
   ai_observation_gather_results___0__2(A).
ai_observation_gather_results___0__2(A) :-
   ( var(A) ->
     true
   ;
     arg(2,A,B),
     setarg(2,A,removed),
     ( B==not_stored_yet ->
       true
     ;
       arg(3,A,C),
       ( var(C) ->
         nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',D),
         D=[_|E],
         b_setval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',E),
         ( E=[F|_] ->
           setarg(3,F,_)
         ;
           true
         )
       ;
         C=[_,_|E],
         setarg(2,C,E),
         ( E=[F|_] ->
           setarg(3,F,C)
         ;
           true
         )
       )
     )
   ).
ai_observation_memo_simplification_rest_heads(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   C=G.
ai_observation_memo_simplification_rest_heads(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,G,H,_),
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',I),
   lookup_ht(I,G,J),
   'chr sbag_member'(K,J),
   K=suspension(_,active,_,_,_,L),
   nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',M),
   'chr sbag_member'(N,M),
   N=suspension(_,active,_,O),
   !,
   L=pragma(rule(P,Q,_,_),ids(R,_),_,_,_),
   once(select2(H,_,R,P,_,S)),
   ai_observation_abstract_constraints(S,O,T),
   ai_observation_abstract_constraints(Q,O,U),
   append(T,U,V),
   sort(V,C),
   ai_observation_memoed_simplification_rest_heads(A,B,C).
ai_observation_memo_simplification_rest_heads(_,_,_) :-
   fail.
ai_observation_memoed_simplification_rest_heads(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',F),
   insert_ht(F,k(A,B),D).
ai_observation_memo_propagation_rest_heads(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   C=G.
ai_observation_memo_propagation_rest_heads(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,G,H,_),
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',I),
   lookup_ht(I,G,J),
   'chr sbag_member'(K,J),
   K=suspension(_,active,_,_,_,L),
   nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',M),
   'chr sbag_member'(N,M),
   N=suspension(_,active,_,O),
   !,
   L=pragma(rule(P,Q,_,_),ids(_,R),_,_,_),
   once(select2(H,_,R,Q,_,S)),
   ai_observation_abstract_constraints(S,O,T),
   ai_observation_abstract_constraints(P,O,U),
   append(T,U,V),
   sort(V,C),
   ai_observation_memoed_propagation_rest_heads(A,B,C).
ai_observation_memo_propagation_rest_heads(_,_,_) :-
   fail.
ai_observation_memoed_propagation_rest_heads(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',F),
   insert_ht(F,k(A,B),D).
ai_observation_memoed_abstract_goal(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',E),
   insert_ht(E,A,C).
ai_observation_memo_abstract_goal(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,F),
   !,
   B=F.
ai_observation_memo_abstract_goal(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F),
   nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',G),
   'chr sbag_member'(H,G),
   H=suspension(_,active,_,I),
   !,
   F=pragma(rule(J,K,L,M),_,_,_,_),
   ai_observation_abstract_goal_(J,K,L,M,I,N),
   B=N,
   ai_observation_memoed_abstract_goal(A,N).
ai_observation_memo_abstract_goal(A,B) :-
   C=suspension(D,active,_,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2',E),
   F=[C|E],
   b_setval('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2',F),
   ( E=[G|_] ->
     setarg(3,G,F)
   ;
     true
   ).
partial_wake_analysis :-
   partial_wake_analysis___0__0(_).
partial_wake_analysis___0__0(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',B),
   !,
   A=suspension(C,not_stored_yet,t,_),
   'chr gen_id'(C),
   partial_wake_analysis___0__0__0__1(B,A).
partial_wake_analysis___0__0__0__1([],A) :-
   partial_wake_analysis___0__1(A).
partial_wake_analysis___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,_,D,_,E,F,G),
     nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',H),
     lookup_ht(H,D,I) ->
     partial_wake_analysis___0__0__1__1(I,D,E,F,G,B,C,A)
   ;
     partial_wake_analysis___0__0__0__1(C,A)
   ).
partial_wake_analysis___0__0__1__1([],_,_,_,_,_,A,B) :-
   partial_wake_analysis___0__0__0__1(A,B).
partial_wake_analysis___0__0__1__1([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,_,J,K),
     J==A,
     nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',L),
     lookup_ht(L,B,M) ->
     partial_wake_analysis___0__0__2__1(M,K,H,I,A,B,C,D,E,F,G)
   ;
     partial_wake_analysis___0__0__1__1(I,A,B,C,D,E,F,G)
   ).
partial_wake_analysis___0__0__2__1([],_,_,A,B,C,D,E,F,G,H) :-
   partial_wake_analysis___0__0__1__1(A,B,C,D,E,F,G,H).
partial_wake_analysis___0__0__2__1([K|L],A,B,C,D,E,F,G,H,I,J) :-
   ( K=suspension(_,active,_,_,M,N),
     M==E,
     O=t(330,J,H,K,B),
     '$novel_production'(J,O),
     '$novel_production'(H,O),
     '$novel_production'(K,O),
     '$novel_production'(B,O) ->
     '$extend_history'(J,O),
     arg(2,J,P),
     setarg(2,J,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',Q),
       R=[J|Q],
       b_setval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',R),
       ( Q=[S|_] ->
         setarg(4,S,R)
       ;
         true
       )
     ;
       true
     ),
     N=pragma(rule(T,U,V,_),_,_,_,_),
     ( is_passive(E,F) ->
       true
     ;
       ( G==simplification ->
         select(W,T,_),
         W=..[_|X],
         term_variables(V,Y),
         partial_wake_args(X,A,Y,D)
       )
     ;
       select(W,U,_),
       W=..[_|X],
       term_variables(V,Y),
       partial_wake_args(X,A,Y,D)
     ),
     ( J=suspension(_,active,_,_) ->
       setarg(2,J,inactive),
       partial_wake_analysis___0__0__2__1(L,A,B,C,D,E,F,G,H,I,J)
     ;
       true
     )
   ;
     partial_wake_analysis___0__0__2__1(L,A,B,C,D,E,F,G,H,I,J)
   ).
partial_wake_analysis___0__0(A) :-
   A=suspension(B,not_stored_yet,t,_),
   'chr gen_id'(B),
   partial_wake_analysis___0__1(A).
partial_wake_analysis___0__1(A) :-
   arg(2,A,B),
   setarg(2,A,active),
   ( B==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',C),
     D=[A|C],
     b_setval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',D),
     ( C=[E|_] ->
       setarg(4,E,D)
     ;
       true
     )
   ;
     true
   ).
no_partial_wake(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !.
no_partial_wake(A) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',D),
   insert_ht(D,A,B).
wakes_partially(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !,
   fail.
wakes_partially(_).
phase_end(A) :-
   phase_end___1__0(A,_).
phase_end___1__0(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',C),
   lookup_ht(C,A,D),
   !,
   B=suspension(E,not_stored_yet,A),
   'chr gen_id'(E),
   phase_end___1__0__0__1(D,A,B).
phase_end___1__0__0__1([],A,B) :-
   phase_end___1__1(A,B).
phase_end___1__0__0__1([C|D],A,B) :-
   ( C=suspension(_,active,E,F),
     E==A ->
     setarg(2,C,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',G),
     delete_ht(G,A,C),
     arg(2,B,H),
     setarg(2,B,active),
     ( H==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',I),
       insert_ht(I,A,B)
     ;
       true
     ),
     call(F),
     ( B=suspension(_,active,_) ->
       setarg(2,B,inactive),
       phase_end___1__0__0__1(D,A,B)
     ;
       true
     )
   ;
     phase_end___1__0__0__1(D,A,B)
   ).
phase_end___1__0(A,B) :-
   B=suspension(C,not_stored_yet,A),
   'chr gen_id'(C),
   phase_end___1__1(A,B).
phase_end___1__1(A,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',D),
     insert_ht(D,A,B)
   ;
     true
   ).
delay_phase_end(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_),
   !,
   call(B).
delay_phase_end(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',E),
   insert_ht(E,A,C).
does_use_history(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
does_use_history(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',E),
   insert_ht(E,A,C),
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',F),
   insert_ht(F,k(A,B),C).
uses_history(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !.
uses_history(_) :-
   fail.
novel_production_call(A,B,C,D) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',E),
   lookup_ht(E,k(A,B),F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_,_),
   !,
   D=C.
novel_production_call(_,_,_,true).
does_use_field(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
does_use_field(A,B) :-
   C=suspension(D,active,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',E),
   insert_ht(E,k(A,B),C).
uses_field(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
uses_field(_,_) :-
   fail.
uses_state(A,B) :-
   uses_state___2__0(A,B,_).
uses_state___2__0(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_),
   !.
uses_state___2__0(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',D),
   !,
   C=suspension(E,not_stored_yet,A,B),
   'chr gen_id'(E),
   uses_state___2__0__0__3(D,A,B,C).
uses_state___2__0__0__3([],A,B,C) :-
   uses_state___2__1(A,B,C).
uses_state___2__0__0__3([D|E],A,B,C) :-
   ( D=suspension(_,active,_),
     nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',F),
     lookup_ht(F,k(A,B),G) ->
     uses_state___2__0__1__3(G,D,E,A,B,C)
   ;
     uses_state___2__0__0__3(E,A,B,C)
   ).
uses_state___2__0__1__3([],_,A,B,C,D) :-
   uses_state___2__0__0__3(A,B,C,D).
uses_state___2__0__1__3([F|G],A,B,C,D,E) :-
   ( F=suspension(_,active,_,H,I,J,_,K),
     H==C,
     I==D ->
     setarg(2,F,removed),
     arg(3,F,L),
     ( var(L) ->
       nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',M),
       M=[_|N],
       b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',N),
       ( N=[O|_] ->
         setarg(3,O,_)
       ;
         true
       )
     ;
       L=[_,_|N],
       setarg(2,L,N),
       ( N=[O|_] ->
         setarg(3,O,L)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',P),
     delete_ht(P,k(C,D),F),
     arg(2,E,Q),
     setarg(2,E,active),
     ( Q==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',R),
       insert_ht(R,k(C,D),E)
     ;
       true
     ),
     K=J,
     ( E=suspension(_,active,_,_) ->
       setarg(2,E,inactive),
       uses_state___2__0__1__3(G,A,B,C,D,E)
     ;
       true
     )
   ;
     uses_state___2__0__1__3(G,A,B,C,D,E)
   ).
uses_state___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,A,B),
   'chr gen_id'(D),
   uses_state___2__1(A,B,C).
uses_state___2__1(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',E),
     insert_ht(E,k(A,B),C)
   ;
     true
   ).
if_used_state(A,B,C,D,E) :-
   nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',F),
   'chr sbag_member'(G,F),
   G=suspension(_,active,_),
   (
     nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',H),
     lookup_ht(H,k(A,B),I),
     'chr sbag_member'(J,I),
     J=suspension(_,active,_,_),
     !,
     E=C
   ;
     !,
     E=D
   ).
if_used_state(A,B,C,D,E) :-
   F=suspension(G,active,_,A,B,C,D,E),
   'chr gen_id'(G),
   nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',H),
   I=[F|H],
   b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',I),
   ( H=[J|_] ->
     setarg(3,J,I)
   ;
     true
   ),
   nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',K),
   insert_ht(K,k(A,B),F).
used_states_known :-
   used_states_known___0__0(_).
used_states_known___0__0(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',B),
   !,
   A=suspension(C,not_stored_yet,_),
   'chr gen_id'(C),
   used_states_known___0__0__0__1(B,A).
used_states_known___0__0__0__1([],A) :-
   used_states_known___0__1(A).
used_states_known___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,D,E,F,_,G),
     ground(D),
     ground(E),
     nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',H),
     lookup_ht(H,k(D,E),I),
     'chr sbag_member'(J,I),
     J=suspension(_,active,_,_) ->
     setarg(2,B,removed),
     arg(3,B,K),
     ( var(K) ->
       nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',L),
       L=[_|M],
       b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',M),
       ( M=[N|_] ->
         setarg(3,N,_)
       ;
         true
       )
     ;
       K=[_,_|M],
       setarg(2,K,M),
       ( M=[N|_] ->
         setarg(3,N,K)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',O),
     delete_ht(O,k(D,E),B),
     arg(2,A,P),
     setarg(2,A,active),
     ( P==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',Q),
       R=[A|Q],
       b_setval('$chr_store_global_ground_chr_translate____used_states_known___0',R),
       ( Q=[S|_] ->
         setarg(3,S,R)
       ;
         true
       )
     ;
       true
     ),
     G=F,
     ( A=suspension(_,active,_) ->
       setarg(2,A,inactive),
       used_states_known___0__0__0__1(C,A)
     ;
       true
     )
   ;
     used_states_known___0__0__0__1(C,A)
   ).
used_states_known___0__0(A) :-
   A=suspension(B,not_stored_yet,_),
   'chr gen_id'(B),
   used_states_known___0__1(A).
used_states_known___0__1(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',B),
   !,
   used_states_known___0__1__0__2(B,A).
used_states_known___0__1__0__2([],A) :-
   used_states_known___0__2(A).
used_states_known___0__1__0__2([B|C],A) :-
   ( B=suspension(_,active,_,D,E,_,F,G) ->
     setarg(2,B,removed),
     arg(3,B,H),
     ( var(H) ->
       nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',I),
       I=[_|J],
       b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',J),
       ( J=[K|_] ->
         setarg(3,K,_)
       ;
         true
       )
     ;
       H=[_,_|J],
       setarg(2,H,J),
       ( J=[K|_] ->
         setarg(3,K,H)
       ;
         true
       )
     ),
     nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',L),
     delete_ht(L,k(D,E),B),
     arg(2,A,M),
     setarg(2,A,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',N),
       O=[A|N],
       b_setval('$chr_store_global_ground_chr_translate____used_states_known___0',O),
       ( N=[P|_] ->
         setarg(3,P,O)
       ;
         true
       )
     ;
       true
     ),
     G=F,
     ( A=suspension(_,active,_) ->
       setarg(2,A,inactive),
       used_states_known___0__1__0__2(C,A)
     ;
       true
     )
   ;
     used_states_known___0__1__0__2(C,A)
   ).
used_states_known___0__1(A) :-
   used_states_known___0__2(A).
used_states_known___0__2(A) :-
   arg(2,A,B),
   setarg(2,A,active),
   ( B==not_stored_yet ->
     nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',C),
     D=[A|C],
     b_setval('$chr_store_global_ground_chr_translate____used_states_known___0',D),
     ( C=[E|_] ->
       setarg(3,E,D)
     ;
       true
     )
   ;
     true
   ).
stored_assertion(A) :-
   B=suspension(C,active,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',D),
   insert_ht(D,A,B).
never_stored_default(A,B) :-
   never_stored_default___2__0(A,B,_).
never_stored_default___2__0(A,B,C) :-
   nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',D),
   !,
   C=suspension(E,not_stored_yet,A,B),
   'chr gen_id'(E),
   never_stored_default___2__0__0__1(D,A,B,C).
never_stored_default___2__0__0__1([],A,B,C) :-
   never_stored_default___2__1(A,B,C).
never_stored_default___2__0__0__1([D|E],A,B,C) :-
   ( D=suspension(_,active,_,F,G),
     F=[H|I],
     H==A ->
     setarg(2,D,removed),
     arg(3,D,J),
     ( var(J) ->
       nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',K),
       K=[_|L],
       b_setval('$chr_store_global_ground_chr_translate____never_stored_rules___2',L),
       ( L=[M|_] ->
         setarg(3,M,_)
       ;
         true
       )
     ;
       J=[_,_|L],
       setarg(2,J,L),
       ( L=[M|_] ->
         setarg(3,M,J)
       ;
         true
       )
     ),
     arg(2,C,N),
     setarg(2,C,active),
     ( N==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',O),
       insert_ht(O,A,C)
     ;
       true
     ),
     A=P/Q,
     functor(R,P,Q),
     inc_rule_count(S),
     T=pragma(rule([R],[],true,B),ids([0],[]),[],no,S),
     G=[T|U],
     never_stored_rules(I,U),
     ( C=suspension(_,active,_,_) ->
       setarg(2,C,inactive),
       never_stored_default___2__0__0__1(E,A,B,C)
     ;
       true
     )
   ;
     never_stored_default___2__0__0__1(E,A,B,C)
   ).
never_stored_default___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,A,B),
   'chr gen_id'(D),
   never_stored_default___2__1(A,B,C).
never_stored_default___2__1(A,_,B) :-
   arg(2,B,C),
   setarg(2,B,active),
   ( C==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',D),
     insert_ht(D,A,B)
   ;
     true
   ).
never_stored_rules([],A) :-
   !,
   A=[].
never_stored_rules([B|C],A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',D),
   lookup_ht(D,B,E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,G),
   !,
   B=H/I,
   functor(J,H,I),
   inc_rule_count(K),
   L=pragma(rule([J],[],true,G),ids([0],[]),[],no,K),
   A=[L|M],
   never_stored_rules(C,M).
never_stored_rules([_|B],A) :-
   !,
   never_stored_rules(B,A).
never_stored_rules(A,B) :-
   C=suspension(D,active,_,A,B),
   'chr gen_id'(D),
   nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',E),
   F=[C|E],
   b_setval('$chr_store_global_ground_chr_translate____never_stored_rules___2',F),
   ( E=[G|_] ->
     setarg(3,G,F)
   ;
     true
   ).
check_storedness_assertion(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_),
   !,
   setarg(2,D,removed),
   nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',E),
   delete_ht(E,A,D),
   ( is_stored(A) ->
     true
   ;
     chr_warning(assertion_failed,'Constraint ~w is not stored. However, it was asserted to be stored.\n',[A])
   ).
check_storedness_assertion(A) :-
   nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',B),
   lookup_ht(B,A,C),
   'chr sbag_member'(D,C),
   D=suspension(_,active,_,_),
   !,
   ( is_finally_stored(A) ->
     chr_warning(assertion_failed,'Constraint ~w is stored. However, it was asserted not to be stored.\n',[A])
   ;
     ( is_stored(A) ->
       chr_warning(assertion_failed,'Constraint ~w is temporarily stored. However, it was asserted not to be stored.\n',[A])
     )
   ;
     true
   ).
check_storedness_assertion(A) :-
   ( is_finally_stored(A) ->
     chr_warning(assertion_failed,'Constraint ~w is stored. However, it was asserted not to be stored.\n',[A])
   ;
     ( is_stored(A) ->
       chr_warning(assertion_failed,'Constraint ~w is temporarily stored. However, it was asserted not to be stored.\n',[A])
     )
   ;
     true
   ).
continuation_occurrence(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',F),
   insert_ht(F,k(A,B),D).
get_success_continuation_occurrence(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   C=G.
get_success_continuation_occurrence(A,B,_) :-
   chr_error(internal,'Success continuation not found for ~w.\n',[A:B]).
skip_to_next_id(A,B) :-
   skip_to_next_id___2__0(A,B,_).
skip_to_next_id___2__0(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
skip_to_next_id___2__0(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(A,B),E),
   !,
   C=suspension(F,not_stored_yet,t,A,B),
   'chr gen_id'(F),
   skip_to_next_id___2__0__0__4(E,A,B,C).
skip_to_next_id___2__0__0__4([],A,B,C) :-
   skip_to_next_id___2__1(A,B,C).
skip_to_next_id___2__0__0__4([D|E],A,B,C) :-
   ( D=suspension(_,active,_,_,F,G,H,I,_),
     F==A,
     G==B,
     nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',J),
     lookup_ht(J,k(H,I),K) ->
     skip_to_next_id___2__0__1__4(K,H,I,D,E,A,B,C)
   ;
     skip_to_next_id___2__0__0__4(E,A,B,C)
   ).
skip_to_next_id___2__0__1__4([],_,_,_,A,B,C,D) :-
   skip_to_next_id___2__0__0__4(A,B,C,D).
skip_to_next_id___2__0__1__4([H|I],A,B,C,D,E,F,G) :-
   ( H=suspension(_,active,_,J,K),
     J==A,
     K==B,
     L=t(362,C,H,G),
     '$novel_production'(C,L),
     '$novel_production'(H,L),
     '$novel_production'(G,L),
     F>1 ->
     '$extend_history'(G,L),
     arg(2,G,M),
     setarg(2,G,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',N),
       insert_ht(N,k(E,F),G)
     ;
       true
     ),
     O is F-1,
     skip_to_next_id(E,O),
     ( G=suspension(_,active,_,_,_) ->
       setarg(2,G,inactive),
       skip_to_next_id___2__0__1__4(I,A,B,C,D,E,F,G)
     ;
       true
     )
   ;
     skip_to_next_id___2__0__1__4(I,A,B,C,D,E,F,G)
   ).
skip_to_next_id___2__0(A,B,C) :-
   C=suspension(D,not_stored_yet,t,A,B),
   'chr gen_id'(D),
   skip_to_next_id___2__1(A,B,C).
skip_to_next_id___2__1(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',D),
   lookup_ht(D,k(A,B),E),
   !,
   skip_to_next_id___2__1__0__5(E,A,B,C).
skip_to_next_id___2__1__0__5([],A,B,C) :-
   skip_to_next_id___2__2(A,B,C).
skip_to_next_id___2__1__0__5([D|E],A,B,C) :-
   ( D=suspension(_,active,F,G,H),
     F==A,
     G==B,
     ground(A),
     ground(B),
     nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',I),
     lookup_ht(I,k(A,B,propagation),J),
     'chr sbag_member'(K,J),
     K=suspension(_,active,_,_,_,_,_,_,_) ->
     setarg(2,D,removed),
     nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',L),
     delete_ht(L,k(A,B),D),
     arg(2,C,M),
     setarg(2,C,active),
     ( M==not_stored_yet ->
       nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',N),
       insert_ht(N,k(A,B),C)
     ;
       true
     ),
     occurrence_code_id(A,B,H),
     O is B+1,
     P is H+1,
     set_occurrence_code_id(A,O,P),
     ( C=suspension(_,active,_,_,_) ->
       setarg(2,C,inactive),
       skip_to_next_id___2__1__0__5(E,A,B,C)
     ;
       true
     )
   ;
     skip_to_next_id___2__1__0__5(E,A,B,C)
   ).
skip_to_next_id___2__1(A,B,C) :-
   skip_to_next_id___2__2(A,B,C).
skip_to_next_id___2__2(A,B,C) :-
   arg(2,C,D),
   setarg(2,C,active),
   ( D==not_stored_yet ->
     nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',E),
     insert_ht(E,k(A,B),C)
   ;
     true
   ).
should_skip_to_next_id(A,B) :-
   nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',C),
   lookup_ht(C,k(A,B),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_),
   !.
should_skip_to_next_id(_,_) :-
   fail.
bulk_propagation(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',C),
   lookup_ht(C,A,D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,F),
   B>=F,
   !,
   skip_to_next_id(A,B).
bulk_propagation(A,B,C) :-
   C=:=B+1,
   !,
   skip_to_next_id(A,B),
   get_max_occurrence(A,D),
   E is D+1,
   bulk_propagation(A,C,E).
bulk_propagation(A,B,_) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',C),
   lookup_ht(C,k(A,simplification),D),
   'chr sbag_member'(E,D),
   E=suspension(_,active,_,_,_,F,_,_,_),
   F=:=B+1,
   !,
   skip_to_next_id(A,B),
   get_max_occurrence(A,G),
   H is G+1,
   bulk_propagation(A,F,H).
bulk_propagation(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   G>B+1,
   !,
   H is min(C,G),
   I is B+1,
   bulk_propagation(A,I,H).
bulk_propagation(A,B,_) :-
   skip_to_next_id(A,B),
   get_max_occurrence(A,C),
   D is C+1,
   E is B+1,
   bulk_propagation(A,E,D).
set_occurrence_code_id(A,B,C) :-
   get_max_occurrence(A,D),
   B>D,
   !,
   occurrence_code_id(A,B,C).
set_occurrence_code_id(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,_,_,G,H,_),
   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',I),
   lookup_ht(I,k(G,H),J),
   'chr sbag_member'(K,J),
   K=suspension(_,active,_,_,_),
   !,
   occurrence_code_id(A,B,C),
   L is B+1,
   set_occurrence_code_id(A,L,C).
set_occurrence_code_id(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',D),
   (
     (
       lookup_ht(D,k(A,B,simplification),E),
       'chr sbag_member'(F,E),
       F=suspension(_,active,_,_,_,_,_,_,_),
       !,
       occurrence_code_id(A,B,C),
       G is B+1,
       set_occurrence_code_id(A,G,C)
     ;
       lookup_ht(D,k(A,B,propagation),H),
       'chr sbag_member'(I,H),
       I=suspension(_,active,_,_,_,_,_,_,_),
       nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',J),
       lookup_ht(J,k(A,B),K),
       'chr sbag_member'(L,K),
       L=suspension(_,active,_,_,_),
       !,
       occurrence_code_id(A,B,C),
       M is B+1,
       N is C+1,
       set_occurrence_code_id(A,M,N)
     )
   ;
     lookup_ht(D,k(A,B,propagation),O),
     'chr sbag_member'(P,O),
     P=suspension(_,active,_,_,_,_,_,_,_),
     !,
     occurrence_code_id(A,B,C),
     Q is B+1,
     set_occurrence_code_id(A,Q,C)
   ).
set_occurrence_code_id(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',F),
   insert_ht(F,k(A,B),D).
occurrence_code_id(A,B,C) :-
   D=suspension(E,active,A,B,C),
   'chr gen_id'(E),
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',F),
   insert_ht(F,k(A,B),D).
get_occurrence_code_id(A,B,C) :-
   nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',D),
   lookup_ht(D,k(A,B),E),
   'chr sbag_member'(F,E),
   F=suspension(_,active,_,_,G),
   !,
   C=G.
get_occurrence_code_id(A,B,_) :-
   ( B==0 ->
     true
   ;
     format('no occurrence code for ~w!\n',[A:B])
   ).
chr_constants(A) :-
   B=suspension(C,active,_,A),
   'chr gen_id'(C),
   nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',D),
   E=[B|D],
   b_setval('$chr_store_global_ground_chr_translate____chr_constants___1',E),
   ( D=[F|_] ->
     setarg(3,F,E)
   ;
     true
   ).
get_chr_constants(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   A=D.
get_chr_constants(A) :-
   chr_warning(internal,'No constants found for key ~w.\n',[_]),
   A=[].
add_chr_constants_(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',B),
   'chr sbag_member'(C,B),
   C=suspension(_,active,_,D),
   !,
   setarg(2,C,removed),
   arg(3,C,E),
   ( var(E) ->
     nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',F),
     F=[_|G],
     b_setval('$chr_store_global_ground_chr_translate____chr_constants___1',G),
     ( G=[H|_] ->
       setarg(3,H,_)
     ;
       true
     )
   ;
     E=[_,_|G],
     setarg(2,E,G),
     ( G=[H|_] ->
       setarg(3,H,E)
     ;
       true
     )
   ),
   sort([A|D],I),
   chr_constants(I).
add_chr_constants_(A) :-
   chr_constants([A]).
print_chr_constants :-
   print_chr_constants___0__0(_).
print_chr_constants___0__0(A) :-
   nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',B),
   !,
   A=suspension(C,not_stored_yet,_),
   'chr gen_id'(C),
   print_chr_constants___0__0__0__1(B,A).
print_chr_constants___0__0__0__1([],A) :-
   print_chr_constants___0__1(A).
print_chr_constants___0__0__0__1([B|C],A) :-
   ( B=suspension(_,active,_,D) ->
     format('\t* chr_constants : ~w.\n',[D]),
     print_chr_constants___0__0__0__1(C,A)
   ;
     print_chr_constants___0__0__0__1(C,A)
   ).
print_chr_constants___0__0(A) :-
   A=suspension(B,not_stored_yet,_),
   'chr gen_id'(B),
   print_chr_constants___0__1(A).
print_chr_constants___0__1(A) :-
   ( var(A) ->
     true
   ;
     arg(2,A,B),
     setarg(2,A,removed),
     ( B==not_stored_yet ->
       true
     ;
       arg(3,A,C),
       ( var(C) ->
         nb_getval('$chr_store_global_ground_chr_translate____print_chr_constants___0',D),
         D=[_|E],
         b_setval('$chr_store_global_ground_chr_translate____print_chr_constants___0',E),
         ( E=[F|_] ->
           setarg(3,F,_)
         ;
           true
         )
       ;
         C=[_,_|E],
         setarg(2,C,E),
         ( E=[F|_] ->
           setarg(3,F,C)
         ;
           true
         )
       )
     )
   ).
end_of_file.
