/*  Generated by CHR bootstrap compiler
    From: chr_translate.chr
    Date: Tue Jan 16 15:06:24 2018

    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)).
:- style_check(-singleton).
:- style_check(-no_effect).
:- 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, E) :-
	get_constraint_type(A, C),
	nth1(B, C, D),
	unalias_type(D, E).
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(B, A) :-
	C is A+1,
	late_allocation(B, C).
stored_in_guard_before_next_kept_occurrence(B, A) :-
	chr_pp_flag(store_in_guards, on),
	C is A+1,
	stored_in_guard_lookahead(B, 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([A|C], B) :-
	(   (   chr_pp_flag(debugable, on)
	    ;   \+ only_ground_indexed_arguments(A),
		is_stored(A)
	    ;   is_stored(A),
		get_store_type(A, default)
	    ;   get_store_type(A, var_assoc_store(_, _))
	    )
	->  constraint_index(A, B),
	    D is B+1,
	    set_constraint_indices(C, D)
	;   set_constraint_indices(C, B)
	).
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, C, D) :-
	(   atom(A)
	->  B=A
	;   term_to_atom(A, B)
	),
	atom_concat_list([C, '_', B], D).
chr_translate(A, B) :-
	chr_translate_line_info(A, bootstrap, B).
chr_translate_line_info(A, B, Q) :-
	chr_banner,
	restart_after_flattening(A, C),
	init_chr_pp_flags,
	chr_source_file(B),
	partition_clauses(C, D, E, J),
	chr_compiler_options:sanity_check,
	dump_code(C),
	check_declared_constraints(D),
	generate_show_constraint(D, F, E, G),
	add_constraints(F),
	add_rules(G),
	generate_never_stored_rules(F, H),
	add_rules(H),
	append(G, H, I),
	chr_analysis(I, F, C),
	time('constraint code generation',
	     chr_translate:constraints_code(F, L)),
	time('validate store assumptions',
	     chr_translate:validate_store_type_assumptions(F)),
	phase_end(validate_store_type_assumptions),
	used_states_known,
	time('store code generation',
	     chr_translate:store_management_preds(F, K)),
	insert_declarations(J, O),
	chr_module_declaration(M),
	append([K, L, M, [end_of_file]], N),
	clean_clauses(N, P),
	append([O, P], Q),
	dump_code(Q), !.
chr_analysis(A, C, D) :-
	maplist(pragma_rule_to_ast_rule, A, B),
	check_rules(A, B, C),
	time('type checking', chr_translate:static_type_check(A, B)),
	collect_constants(A, B, C, D),
	add_occurrences(A, B),
	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(C)),
	time(observation, chr_translate:observation_analysis(C)),
	time('ai observation', chr_translate:ai_observation_analysis(C)),
	time('late allocation', chr_translate:late_allocation_analysis(C)),
	partial_wake_analysis,
	time('assume constraint stores',
	     chr_translate:assume_constraint_stores(C)),
	time('default constraint indices',
	     chr_translate:set_constraint_indices(C)),
	time('check storedness assertions',
	     chr_translate:check_storedness_assertions(C)),
	time('continuation analysis',
	     chr_translate:continuation_analysis(C)).
store_management_preds(A, J) :-
	generate_attach_detach_a_constraint_all(A, B),
	generate_attr_unify_hook(D),
	generate_attach_increment(C),
	generate_extra_clauses(A, E),
	generate_insert_delete_constraints(A, F),
	generate_attach_code(A, G),
	generate_counter_code(H),
	generate_dynamic_type_check_clauses(I),
	append(
	       [ B,
		 C,
		 D,
		 E,
		 F,
		 G,
		 H,
		 I
	       ],
	       J).
insert_declarations(B, D) :-
	findall((:-use_module(chr(A))),
		( auxiliary_module(A),
		  is_used_auxiliary_module(A)
		),
		C),
	append(B, [(:-use_module(chr(chr_runtime)))|C], D).
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([]) :-
	tmp_module, !.
chr_module_declaration(B) :-
	get_target_module(A),
	(   A\==chr_translate,
	    chr_pp_flag(toplevel_show_store, on)
	->  B=[(:-multifile chr:'$chr_module'/1), chr:'$chr_module'(A)]
	;   B=[]
	).
partition_clauses([], [], [], []).
partition_clauses([A|M], B, C, E) :-
	(   parse_rule(A, D)
	->  B=G,
	    C=[D|H],
	    E=I
	;   is_declaration(A, F)
	->  append(F, G, B),
	    C=H,
	    E=I
	;   is_module_declaration(A, J)
	->  target_module(J),
	    B=G,
	    C=H,
	    E=[A|I]
	;   is_type_definition(A)
	->  B=G,
	    C=H,
	    E=I
	;   is_chr_declaration(A)
	->  B=G,
	    C=H,
	    E=I
	;   A=handler(_)
	->  chr_warning(deprecated(A),
			'Backward compatibility: ignoring handler/1 declaration.\n',
			[]),
	    B=G,
	    C=H,
	    E=I
	;   A=rules(_)
	->  chr_warning(deprecated(A),
			'Backward compatibility: ignoring rules/1 declaration.\n',
			[]),
	    B=G,
	    C=H,
	    E=I
	;   A=option(K, L)
	->  chr_warning(deprecated(A),
			'Instead use `:-chr_option(~w,~w).\'\n',
			[K, L]),
	    handle_option(K, L),
	    B=G,
	    C=H,
	    E=I
	;   A=(:-chr_option(K, L))
	->  handle_option(K, L),
	    B=G,
	    C=H,
	    E=I
	;   A='$chr_compiled_with_version'(_)
	->  B=G,
	    C=H,
	    E=['$chr_compiled_with_version'(3)|I]
	;   B=G,
	    C=H,
	    E=[A|I]
	),
	partition_clauses(M, G, H, I).
'$chr_compiled_with_version'(3).
is_declaration(A, F) :-
	(   A=(:-B),
	    B=..[C, D],
	    C==(chr_constraint)
	->  conj2list(D, E)
	;   (   A=(:-B)
	    ->  B=..[constraints, D]
	    ;   A=..[constraints, D]
	    ),
	    conj2list(D, E),
	    chr_warning(deprecated(A),
			'Instead use :- chr_constraint ~w.\n',
			[D])
	),
	extract_type_mode(E, F).
extract_type_mode([], []).
extract_type_mode([A/B|C], [A/B|D]) :- !,
	extract_type_mode(C, D).
extract_type_mode([A|J], [F|K]) :-
	(   A= #(B, C)
	->  functor(B, D, E),
	    extract_annotation(C, D/E)
	;   A=B,
	    functor(B, D, E)
	),
	F=D/E,
	B=..[_|G],
	extract_types_and_modes(G, H, I),
	assert_constraint_type(F, H),
	constraint_mode(F, I),
	extract_type_mode(J, K).
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|D], [B|E], [C|F]) :-
	extract_type_and_mode(A, B, C),
	extract_types_and_modes(D, E, 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, E) :-
	(   A=(:-B)
	->  true
	;   A=B
	),
	B=..[chr_type, C],
	(   C=(F--->D)
	->  tdisj2list(D, G),
	    E=typedef(F, G)
	;   C=(H==F)
	->  E=alias(H, F)
	;   E=typedef(C, []),
	    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, C, F) :-
	A=(B;D), !,
	tdisj2list(B, C, E),
	tdisj2list(D, E, F).
tdisj2list(A, [A|B], B).
parse_rule(A, D) :-
	A= @(C, B), !,
	rule(B, yes(C), D).
parse_rule(A, B) :-
	rule(A, no, B).
rule(A, E, D) :-
	A=pragma(G, B), !,
	(   var(B)
	->  C=[_]
	;   conj2list(B, C)
	),
	inc_rule_count(F),
	D=pragma(H, I, C, E, F),
	is_rule(G, H, I, D).
rule(D, B, A) :-
	inc_rule_count(C),
	A=pragma(E, F, [], B, C),
	is_rule(D, E, F, A).
is_rule(A, H, E, D) :-
	A= ==>(B, G), !,
	conj2list(B, C),
	get_ids(C, F, I, D),
	E=ids([], F),
	(   G=(J| K)
	->  H=rule([], I, J, K)
	;   H=rule([], I, true, G)
	).
is_rule(A, S, N, K) :-
	A= <=>(G, B), !,
	(   B=(C| D)
	->  E=C,
	    F=D
	;   E=true,
	    F=B
	),
	(   G= \(H, I)
	->  conj2list(H, J),
	    conj2list(I, L),
	    get_ids(J, P, Q, 0, M, K),
	    get_ids(L, O, R, M, _, K),
	    N=ids(O, P)
	;   conj2list(G, L),
	    Q=[],
	    get_ids(L, O, R, K),
	    N=ids(O, [])
	),
	S=rule(R, Q, E, F).
get_ids(A, B, C, D) :-
	get_ids(A, B, C, 0, _, D).
get_ids([], [], [], A, A, _).
get_ids([B|F], [A|G], [C|H], A, J, E) :-
	(   B= #(C, D)
	->  (   var(D)
	    ->  D=A
	    ;   check_direct_pragma(D, A, E)
	    )
	;   C=B
	),
	I is A+1,
	get_ids(F, G, H, I, J, E).
check_direct_pragma(passive, C, A) :- !,
	A=pragma(_, _, _, _, B),
	passive(B, C).
check_direct_pragma(A, _, C) :-
	(   direct_pragma(B),
	    atom_concat(A, _, B)
	->  chr_warning(problem_pragma(A, C),
			'completed `~w\' to `~w\'\n',
			[A, B])
	;   chr_warning(unsupported_pragma(A, C), '', [])
	).
direct_pragma(passive).
is_module_declaration((:-module(A)), A).
is_module_declaration((:-module(A, _)), A).
add_constraints([]).
add_constraints([A|D]) :-
	max_occurrence(A, 0),
	A=_/B,
	length(C, B),
	set_elems(C, ?),
	constraint_mode(A, C),
	add_constraints(D).
add_rules([]).
add_rules([A|C]) :-
	A=pragma(_, _, _, _, B),
	rule(B, A),
	add_rules(C).
check_declared_constraints(A) :-
	tree_set_empty(B),
	check_declared_constraints(A, B).
check_declared_constraints([], _).
check_declared_constraints([A|C], B) :-
	(   tree_set_memberchk(A, B)
	->  chr_error(syntax(A),
		      'Constraint multiply defined: ~w.\n\tRemove redundant declaration!\n',
		      [A])
	;   true
	),
	tree_set_add(B, A, D),
	check_declared_constraints(C, D).
check_rules(B, C, A) :-
	maplist(check_rule(A), B, C).
check_rule(C, A, B) :-
	A=pragma(_, _, D, _, _),
	check_ast_rule_indexing(B, A),
	check_ast_trivial_propagation_rule(B, A),
	check_ast_head_constraints(B, C, A),
	check_pragmas(D, A).
check_ast_trivial_propagation_rule(A, D) :-
	A=ast_rule(B, _, _, C, _),
	(   B=propagation(_),
	    C==[]
	->  chr_warning(weird_program,
			'Ignoring propagation rule with empty body: ~@.\n\t\n',
			[format_rule(D)]),
	    set_rule_passive(D)
	;   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(A, _, _, _, _), B, C) :-
	check_ast_head_constraints_(A, B, C).
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(B, D, chr_constraint(A, _, C)) :-
	(   memberchk(A, B)
	->  true
	;   chr_error(syntax(C),
		      'Undeclared constraint ~w in head of ~@.\n\tConstraint should be one of ~w.\n',
		      [_/_, format_rule(D), B])
	).
check_head_constraints([], _, _).
check_head_constraints([A|E], D, F) :-
	functor(A, B, C),
	(   memberchk(B/C, D)
	->  check_head_constraints(E, D, F)
	;   chr_error(syntax(A),
		      'Undeclared constraint ~w in head of ~@.\n\tConstraint should be one of ~w.\n',
		      [B/C, format_rule(F), D])
	).
check_pragmas([], _).
check_pragmas([A|C], B) :-
	check_pragma(A, B),
	check_pragmas(C, B).
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(C, D), _, _, E),
	(   memberchk_eq(B, C)
	->  true
	;   memberchk_eq(B, D)
	->  true
	;   chr_error(syntax(B),
		      'Invalid identifier ~w in pragma passive in ~@.\n',
		      [B, format_rule(A)])
	),
	passive(E, 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(D, F), !,
	B=pragma(_, ids(C, G), _, _, E),
	chr_warning(experimental,
		    'Experimental pragma ~w. Use with care!\n',
		    [A]),
	(   C\==[]
	->  chr_error(syntax(A),
		      'Pragma history only implemented for propagation rules.\n',
		      [])
	;   \+ atom(D)
	->  chr_error(syntax(A),
		      'Illegal argument for pragma history: ~w is not an atom (rule number ~w).\n',
		      [D, E])
	;   \+ is_set(F)
	->  chr_error(syntax(A),
		      'Illegal argument for pragma history: ~w is not a set (rule number ~w).\n',
		      [F, E])
	;   check_history_pragma_ids(F, C, G)
	->  history(E, D, F)
	;   chr_error(syntax(A),
		      'Invalid identifier(s) in pragma ~w of rule number ~w.\n',
		      [A, E])
	).
check_pragma(A, B) :-
	A=line_number(D), !,
	B=pragma(_, _, _, _, C),
	line_number(C, D).
check_history_pragma_ids([], _, _).
check_history_pragma_ids([A|D], C, B) :-
	(   memberchk_eq(A, B)
	;   memberchk_eq(A, C)
	),
	check_history_pragma_ids(D, C, 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, [B|E], C, [D|F]) :-
	test_named_history_id_pair(A, B, C, D),
	test_named_history_id_pairs(A, E, C, F).
format_rule(A) :-
	A=pragma(_, _, _, B, D),
	(   B=yes(C)
	->  write('rule '),
	    write(C)
	;   write('rule number '),
	    write(D)
	),
	get_line_number(D, E),
	write(' (line '),
	write(E),
	write(')').
check_ast_rule_indexing(A, H) :-
	A=ast_rule(B, D, _, _, _),
	tree_set_empty(C),
	ast_head_variables(B, C, E),
	ast_remove_anti_monotonic_guards(D, E, F),
	ast_term_list_variables(F, C, G),
	check_ast_head_indexing(B, G),
	(   chr_pp_flag(term_indexing, on)
	->  H=pragma(I, _, _, _, _),
	    I=rule(J, K, L, _),
	    term_variables(J-K, M),
	    remove_anti_monotonic_guards(L, M, N),
	    term_variables(N, P),
	    append(J, K, O),
	    check_specs_indexing(O, P, _)
	;   true
	).
check_ast_head_indexing(simplification(A), B) :-
	check_ast_indexing(A, B).
check_ast_head_indexing(propagation(A), B) :-
	check_ast_indexing(A, B).
check_ast_head_indexing(simpagation(C, A), B) :-
	ast_constraint_list_variables(A, B, D),
	check_ast_indexing(C, D),
	ast_constraint_list_variables(C, B, E),
	check_ast_indexing(A, 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, I),
	    append(C, D, H),
	    check_specs_indexing(H, I, _)
	;   true
	).
remove_anti_monotonic_guards(A, C, E) :-
	conj2list(A, B),
	remove_anti_monotonic_guard_list(B, C, D),
	list2conj(D, E).
remove_anti_monotonic_guard_list([], _, []).
remove_anti_monotonic_guard_list([A|F], C, D) :-
	(   A=var(B),
	    memberchk_eq(B, C)
	->  D=E
	;   D=[A|E]
	),
	remove_anti_monotonic_guard_list(F, C, E).
ast_remove_anti_monotonic_guards([], _, []).
ast_remove_anti_monotonic_guards([A|F], C, D) :-
	(   A=compound(var, 1, [B], _),
	    ast_var_memberchk(B, C)
	->  D=E
	;   D=[A|E]
	),
	ast_remove_anti_monotonic_guards(F, C, E).
check_ast_indexing([], _).
check_ast_indexing([A|B], C) :-
	A=chr_constraint(E, D, _),
	ast_constraint_list_variables(B, C, F),
	check_ast_indexing(D, 1, E, F),
	ast_constraint_variables(A, C, G),
	check_ast_indexing(B, G).
check_ast_indexing([], _, _, _).
check_ast_indexing([C|D], B, A, E) :-
	(   is_indexed_argument(A, B)
	->  true
	;   ast_nonvar(C)
	->  indexed_argument(A, B)
	;   ast_term_list_variables(D, E, F),
	    (   ast_var_memberchk(C, F)
	    ->  indexed_argument(A, B)
	    ;   true
	    )
	),
	G is B+1,
	ast_term_variables(C, E, H),
	check_ast_indexing(D, G, A, H).
check_indexing([], _).
check_indexing([A|B], C) :-
	functor(A, E, F),
	A=..[_|D],
	term_variables(B-C, G),
	check_indexing(D, 1, E/F, G),
	check_indexing(B, [A|C]).
check_indexing([], _, _, _).
check_indexing([C|D], B, A, F) :-
	(   is_indexed_argument(A, B)
	->  true
	;   nonvar(C)
	->  indexed_argument(A, B)
	;   term_variables(D, E),
	    append(E, F, G),
	    (   memberchk_eq(C, G)
	    ->  indexed_argument(A, B)
	    ;   true
	    )
	),
	I is B+1,
	term_variables(C, H),
	append(H, F, J),
	check_indexing(D, I, A, J).
check_specs_indexing([], _, []).
check_specs_indexing([D|B], C, A) :-
	A=[F|H],
	term_variables(B, E, C),
	check_spec_indexing(D, E, F),
	term_variables(D, G, C),
	check_specs_indexing(B, G, H).
check_spec_indexing(A, F, B) :-
	functor(A, C, D),
	B=spec(C, D, G),
	A=..[_|E],
	check_args_spec_indexing(E, 1, F, G),
	indexing_spec(C/D, [G]).
check_args_spec_indexing([], _, _, []).
check_args_spec_indexing([C|A], D, B, F) :-
	term_variables(A, E, B),
	(   check_arg_spec_indexing(C, D, E, G)
	->  F=[G|H]
	;   F=H
	),
	I is D+1,
	term_variables(C, J, B),
	check_args_spec_indexing(A, I, J, H).
check_arg_spec_indexing(A, D, B, C) :-
	(   var(A)
	->  memberchk_eq(A, B),
	    C=specinfo(D, any, [])
	;   functor(A, E, F),
	    C=specinfo(D, E/F, [H]),
	    A=..[_|G],
	    check_args_spec_indexing(G, 1, B, H)
	).
add_occurrences(A, B) :-
	maplist(add_rule_occurrences, A, B).
add_rule_occurrences(A, B) :-
	A=pragma(_, D, _, _, E),
	B=ast_rule(C, _, _, _, _),
	add_head_occurrences(C, D, E).
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, D), ids(C, E), A) :-
	maplist(add_constraint_occurrence(A, simplification),
		B,
		C),
	maplist(add_constraint_occurrence(A, propagation),
		D,
		E).
add_constraint_occurrence(C, E, A, D) :-
	A=chr_constraint(B, _, _),
	new_occurrence(B, C, D, E).
observation_analysis(A, C, B, E) :-
	(   all_spawned(A, B)
	->  true
	;   var(C)
	->  spawns_all(A, B)
	;   C=true
	->  true
	;   C=fail
	->  true
	;   C=!
	->  true
	;   C=(D, F)
	->  observation_analysis(A, D, B, E),
	    observation_analysis(A, F, B, E)
	;   C=(D;F)
	->  observation_analysis(A, D, B, E),
	    observation_analysis(A, F, B, E)
	;   C=(D->F)
	->  observation_analysis(A, D, B, E),
	    observation_analysis(A, F, B, E)
	;   C=(\+G)
	->  observation_analysis(A, G, B, E)
	;   functor(C, H, I),
	    memberchk(H/I, E)
	->  spawns(A, B, H/I)
	;   C=(_=_)
	->  spawns_all_triggers(A, B)
	;   C=(_ is _)
	->  spawns_all_triggers(A, B)
	;   builtin_binds_b(C, J)
	->  (   J==[]
	    ->  true
	    ;   spawns_all_triggers(A, B)
	    )
	;   spawns_all(A, B)
	).
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([A|D], F) :-
	(   (   chr_pp_flag(debugable, on)
	    ;   is_stored(A),
		\+ only_ground_indexed_arguments(A),
		\+ get_store_type(A, var_assoc_store(_, _))
	    )
	->  generate_attach_a_constraint(A, B),
	    generate_detach_a_constraint(A, C)
	;   B=[],
	    C=[]
	),
	generate_attach_detach_a_constraint_all(D, E),
	append([B, C, E], F).
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, D, E, B) :-
	make_name(attach_, A, C),
	B=..[C, D, E].
generate_attach_a_constraint_nil(B, A) :-
	A=(C:-true),
	attach_constraint_atom(B, [], _, C).
generate_attach_a_constraint_cons(B, A) :-
	A=(C:-F),
	attach_constraint_atom(B, [I|D], E, C),
	attach_constraint_atom(B, D, E, G),
	F=(J, L, G),
	get_max_constraint_index(H),
	(   H==1
	->  generate_attach_body_1(B, I, E, J)
	;   generate_attach_body_n(B, I, E, J)
	),
	chr_pp_flag(solver_events, K),
	(   K\==none
	->  _=[[I|_], E],
	    get_target_module(M),
	    use_auxiliary_predicate(run_suspensions),
	    L=clp_events:subscribe(I, K, M, M:'$run_suspensions'([E]))
	;   L=true
	).
generate_attach_body_1(_, B, D, A) :-
	get_target_module(C),
	A=(get_attr(B, C, E)->put_attr(B, C, [D|E]);put_attr(B, C, [D])).
generate_attach_body_n(A/B, G, D, F) :-
	chr_pp_flag(experiment, off), !,
	get_constraint_index(A/B, E),
	get_max_constraint_index(C),
	get_target_module(H),
	add_attr(C, D, E, I, J, K),
	singleton_attr(C, D, E, L),
	F=(get_attr(G, H, I)->J, put_attr(G, H, K);put_attr(G, H, L)), !.
generate_attach_body_n(A/B, G, E, F) :-
	chr_pp_flag(experiment, on), !,
	get_constraint_index(A/B, C),
	or_pattern(C, L),
	J is C+1,
	get_max_constraint_index(D),
	get_target_module(H),
	singleton_attr(D, E, C, O),
	F=(get_attr(G, H, I)->arg(1, I, K), arg(J, I, N), M is K\/L, setarg(1, I, M), setarg(J, I, [E|N]);put_attr(G, H, O)), !.
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, D, E, B) :-
	make_name(detach_, A, C),
	B=..[C, D, E].
generate_detach_a_constraint_nil(B, A) :-
	A=(C:-true),
	detach_constraint_atom(B, [], _, C).
generate_detach_a_constraint_cons(B, A) :-
	A=(C:-F),
	detach_constraint_atom(B, [I|D], E, C),
	detach_constraint_atom(B, D, E, G),
	F=(J, G),
	get_max_constraint_index(H),
	(   H==1
	->  generate_detach_body_1(B, I, E, J)
	;   generate_detach_body_n(B, I, E, J)
	).
generate_detach_body_1(_, B, E, A) :-
	get_target_module(C),
	A=(get_attr(B, C, D)->'chr sbag_del_element'(D, E, F), (F==[]->del_attr(B, C);put_attr(B, C, F));true).
generate_detach_body_n(A/B, D, E, G) :-
	get_constraint_index(A/B, F),
	get_max_constraint_index(C),
	rem_attr(C, D, E, F, I, J),
	get_target_module(H),
	G=(get_attr(D, H, I)->J;true), !.
create_indexed_variables_body([], [], [], _, _, _, empty, 0).
create_indexed_variables_body([J|B], [G|C], [H|D], K, A, F, I, O) :-
	E is A+1,
	create_indexed_variables_body(B,
				      C,
				      D,
				      L,
				      E,
				      F,
				      M,
				      P),
	(   G==(?),
	    is_indexed_argument(F, A)
	->  (   atomic_type(H)
	    ->  I=((var(J)->K=[J|L];K=L), N),
		(   M==empty
		->  N=true,
		    L=[]
		;   N=M
		)
	    ;   M==empty
	    ->  I=term_variables(J, K)
	    ;   I=(term_variables(J, K, L), M)
	    ),
	    O=P
	;   G==(-),
	    is_indexed_argument(F, A)
	->  (   M==empty
	    ->  I=(K=[J])
	    ;   I=(K=[J|L], M)
	    ),
	    O is P+1
	;   K=L,
	    I=M,
	    O is P+1
	).
spectermvars(B, A, C, D, F, E) :-
	spectermvars(A, 1, B, C, D, E, [], F).
spectermvars([], B, _, _, C, A, A, true) :-
	B>C, !.
spectermvars([F|I], C, B, L, M, H, O, A) :-
	A=(G, P),
	argspecs(B, C, D, K),
	merge_argspecs(D, E),
	arggoal(E, F, G, H, N),
	J is C+1,
	spectermvars(I,
		     J,
		     K,
		     L,
		     M,
		     N,
		     O,
		     P).
argspecs([], _, [], []).
argspecs([[]|A], B, C, D) :-
	argspecs(A, B, C, D).
argspecs([[specinfo(B, D, E)|F]|J], A, C, G) :-
	(   A==B
	->  C=[specinfo(B, D, E)|I],
	    (   F=[]
	    ->  H=G
	    ;   G=[F|H]
	    )
	;   C=I,
	    G=[[specinfo(B, D, E)|F]|H]
	),
	argspecs(J, A, I, H).
merge_argspecs(A, C) :-
	sort(A, B),
	merge_argspecs_(B, C).
merge_argspecs_([], []).
merge_argspecs_([B], A) :- !,
	A=[B].
merge_argspecs_([specinfo(A, B, F), specinfo(A, C, G)|D], E) :-
	(   (   B==any
	    ;   C==any
	    )
	->  merge_argspecs_([specinfo(A, any, [])|D], E)
	;   B==C
	->  append(F, G, H),
	    merge_argspecs_([specinfo(A, B, H)|D],
			    E)
	;   E=[specinfo(A, B, F)|I],
	    merge_argspecs_([specinfo(A, C, G)|D],
			    I)
	).
arggoal(A, E, D, B, C) :-
	(   A==[]
	->  B=C,
	    D=true
	;   A=[specinfo(_, any, _)]
	->  D=term_variables(E, B, C)
	;   D=(var(E)->B=[E|C];F),
	    arggoal_cases(A, E, B, C, F)
	).
arggoal_cases([], _, A, B, A=B).
arggoal_cases([specinfo(_, D, A)|N], I, K, L, B) :-
	(   A==[]
	->  B=C
	;   A==[[]]
	->  B=C
	;   D=E/F
	->  B=(H;C),
	    functor(G, E, F),
	    G=..[_|J],
	    H=(I=G->M),
	    spectermvars(J,
			 1,
			 A,
			 E,
			 F,
			 K,
			 L,
			 M)
	),
	arggoal_cases(N, I, K, L, C).
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([A|C], B, E) :-
	generate_remove_clause(A, B, D),
	generate_remove_clauses(C, D, E).
remove_constraint_goal(A, E, F, D, C, I, B) :-
	uses_state(A, removed),
	(   chr_pp_flag(inline_insertremove, off)
	->  use_auxiliary_predicate(remove_constraint_internal, A),
	    B=(H, (G==yes->C;D)),
	    remove_constraint_atom(A, E, F, G, H)
	;   delay_phase_end(validate_store_type_assumptions,
			    generate_remove_body(A,
						 E,
						 F,
						 D,
						 C,
						 I,
						 B))
	).
remove_constraint_atom(A, D, F, E, B) :-
	make_name('$remove_constraint_internal_', A, C),
	(   chr_pp_flag(debugable, off),
	    (   only_ground_indexed_arguments(A)
	    ;   get_store_type(A, var_assoc_store(_, _))
	    )
	->  B=..[C, D, E]
	;   B=..[C, D, F, E]
	).
generate_remove_clause(A, B, C) :-
	(   is_used_auxiliary_predicate(remove_constraint_internal, A)
	->  B=[D|C],
	    D=(E:-I),
	    remove_constraint_atom(A, F, G, H, E),
	    generate_remove_body(A,
				 F,
				 G,
				 H=no,
				 H=yes,
				 active,
				 I)
	;   B=C
	).
generate_remove_body(A, C, O, F, G, B, L) :-
	(   chr_pp_flag(debugable, off),
	    (   only_ground_indexed_arguments(A)
	    ;   get_store_type(A, var_assoc_store(_, _))
	    )
	->  (   B==active
	    ->  get_update_suspension_field(A,
					    C,
					    state,
					    E,
					    removed,
					    H,
					    D,
					    I),
		if_used_state(A, not_stored_yet, D, true, J),
		if_used_state(A,
			      not_stored_yet,
			      (E==not_stored_yet->F;G),
			      G,
			      K)
	    ;   B==partner
	    ->  get_update_suspension_field(A,
					    C,
					    state,
					    E,
					    removed,
					    H,
					    _,
					    I),
		J=true,
		K=G
	    ),
	    L=(H, J, I, K)
	;   static_suspension_term(A, M),
	    get_static_suspension_term_field(arguments,
					     A,
					     M,
					     N),
	    generate_indexed_variables_body(A,
					    N,
					    Q,
					    O),
	    (   chr_pp_flag(debugable, on)
	    ->  A=P/_,
		get_static_suspension_term_field(functor,
						 A,
						 M,
						 P)
	    ;   true
	    ),
	    (   B==active
	    ->  get_update_static_suspension_field(A,
						   C,
						   M,
						   state,
						   E,
						   removed,
						   D,
						   I),
		if_used_state(A, not_stored_yet, D, true, J),
		if_used_state(A,
			      not_stored_yet,
			      (E==not_stored_yet->O=[], F;Q, G),
			      (Q, G),
			      K)
	    ;   B==partner
	    ->  get_update_static_suspension_field(A,
						   C,
						   M,
						   state,
						   E,
						   removed,
						   _,
						   I),
		J=true,
		K=(Q, G)
	    ),
	    L=(C=M, J, I, K)
	).
generate_activate_clauses([], A, A).
generate_activate_clauses([A|C], B, E) :-
	generate_activate_clause(A, B, D),
	generate_activate_clauses(C, D, E).
activate_constraint_goal(A, C, E, F, G, B) :-
	(   chr_pp_flag(inline_insertremove, off)
	->  use_auxiliary_predicate(activate_constraint, A),
	    B=(H, (D==yes->C;true)),
	    activate_constraint_atom(A,
				     D,
				     E,
				     F,
				     G,
				     H)
	;   delay_phase_end(validate_store_type_assumptions,
			    activate_constraint_body(A,
						     C,
						     true,
						     E,
						     F,
						     G,
						     B))
	).
activate_constraint_atom(A, D, G, E, F, B) :-
	make_name('$activate_constraint_', A, C),
	(   chr_pp_flag(debugable, off),
	    only_ground_indexed_arguments(A)
	->  B=..[C, D, E]
	;   chr_pp_flag(debugable, off),
	    may_trigger(A),
	    get_store_type(A, var_assoc_store(_, _))
	->  B=..[C, D, E, F]
	;   chr_pp_flag(debugable, off),
	    may_trigger(A),
	    get_store_type(A, var_assoc_store(_, _))
	->  B=..[C, D, G, E, F]
	;   B=..[C, D, G, E]
	).
generate_activate_clause(A, B, C) :-
	(   is_used_auxiliary_predicate(activate_constraint, A)
	->  B=[D|C],
	    D=(E:-J),
	    activate_constraint_atom(A,
				     F,
				     G,
				     H,
				     I,
				     E),
	    activate_constraint_body(A,
				     F=yes,
				     F=no,
				     G,
				     H,
				     I,
				     J)
	;   B=C
	).
activate_constraint_body(A, K, L, N, B, C, S) :-
	(   chr_pp_flag(debugable, off),
	    may_trigger(A),
	    uses_field(A, generation)
	->  get_update_suspension_field(A,
					B,
					generation,
					F,
					C,
					D,
					E,
					G),
	    H=(D, E, C is F+1, G)
	;   H=true
	),
	get_update_suspension_field(A,
				    B,
				    state,
				    J,
				    active,
				    T,
				    I,
				    V),
	if_used_state(A, not_stored_yet, I, true, U),
	(   chr_pp_flag(debugable, off),
	    (   only_ground_indexed_arguments(A)
	    ;   get_store_type(A, var_assoc_store(_, _))
	    )
	->  if_used_state(A,
			  not_stored_yet,
			  (J==not_stored_yet->K;L),
			  L,
			  R)
	;   get_dynamic_suspension_term_field(arguments,
					      A,
					      B,
					      M,
					      O),
	    generate_indexed_variables_body(A,
					    M,
					    P,
					    N),
	    chr_none_locked(N, Q),
	    if_used_state(A,
			  not_stored_yet,
			  (J==not_stored_yet->O, P, Q, K;L),
			  L,
			  R)
	),
	S=(T, U, V, H, R).
generate_allocate_clauses([], A, A).
generate_allocate_clauses([A|C], B, E) :-
	generate_allocate_clause(A, B, D),
	generate_allocate_clauses(C, D, E).
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=E, F),
	    delay_phase_end(validate_store_type_assumptions,
			    allocate_constraint_body(A,
						     E,
						     C,
						     F))
	).
allocate_constraint_atom(A, D, E, B) :-
	make_name('$allocate_constraint_', A, C),
	B=..[C, D|E].
generate_allocate_clause(A, B, C) :-
	(   is_used_auxiliary_predicate(allocate_constraint, A)
	->  B=[D|C],
	    D=(G:-I),
	    A=_/E,
	    length(F, E),
	    allocate_constraint_atom(A, H, F, G),
	    allocate_constraint_body(A, H, F, I)
	;   B=C
	).
allocate_constraint_body(A, E, C, P) :-
	static_suspension_term(A, B),
	get_static_suspension_term_field(arguments, A, B, C),
	(   chr_pp_flag(debugable, on)
	->  A=D/_,
	    get_static_suspension_term_field(functor, A, B, D)
	;   true
	),
	(   chr_pp_flag(debugable, on)
	->  (   may_trigger(A)
	    ->  append(C, [E], F),
		build_head(_, _, [0], F, H),
		get_target_module(G),
		I=G:H
	    ;   I=true
	    ),
	    K=(E=B),
	    create_static_suspension_field(A,
					   B,
					   continuation,
					   I,
					   L),
	    create_static_suspension_field(A,
					   B,
					   generation,
					   0,
					   J)
	;   may_trigger(A),
	    uses_field(A, generation)
	->  create_static_suspension_field(A,
					   B,
					   generation,
					   0,
					   J),
	    E=B,
	    K=true,
	    L=true
	;   J=true,
	    E=B,
	    K=true,
	    L=true
	),
	(   uses_history(A)
	->  create_static_suspension_field(A, B, history, t, M)
	;   M=true
	),
	create_static_suspension_field(A,
				       B,
				       state,
				       not_stored_yet,
				       Q),
	(   has_suspension_field(A, id)
	->  get_static_suspension_term_field(id, A, B, N),
	    gen_id(N, O)
	;   O=true
	),
	P=(K, L, J, M, Q, O).
gen_id(A, 'chr gen_id'(A)).
generate_insert_constraint_internal_clauses([], A, A).
generate_insert_constraint_internal_clauses([A|C], B, E) :-
	generate_insert_constraint_internal_clause(A, B, D),
	generate_insert_constraint_internal_clauses(C, D, E).
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, D, E, F, G, B) :-
	insert_constraint_internal_constraint_name(A, C),
	(   chr_pp_flag(debugable, on)
	->  B=..[C, D, E, F|G]
	;   (   only_ground_indexed_arguments(A)
	    ;   get_store_type(A, var_assoc_store(_, _))
	    )
	->  B=..[C, E|G]
	;   B=..[C, D, E|G]
	).
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=(G:-K),
	    A=_/E,
	    length(F, E),
	    insert_constraint_internal_constraint_atom(A,
						       J,
						       H,
						       I,
						       F,
						       G),
	    generate_insert_constraint_internal_body(A,
						     H,
						     I,
						     F,
						     J,
						     K)
	;   B=C
	).
generate_insert_constraint_internal_body(A, K, C, G, M, J) :-
	static_suspension_term(A, B),
	create_static_suspension_field(A, B, state, active, L),
	(   chr_pp_flag(debugable, on)
	->  get_static_suspension_term_field(continuation,
					     A,
					     B,
					     C),
	    create_static_suspension_field(A,
					   B,
					   generation,
					   0,
					   D)
	;   may_trigger(A),
	    uses_field(A, generation)
	->  create_static_suspension_field(A,
					   B,
					   generation,
					   0,
					   D)
	;   D=true
	),
	(   chr_pp_flag(debugable, on)
	->  A=E/_,
	    get_static_suspension_term_field(functor, A, B, E)
	;   true
	),
	(   uses_history(A)
	->  create_static_suspension_field(A, B, history, t, F)
	;   F=true
	),
	get_static_suspension_term_field(arguments, A, B, G),
	_=[_|_],
	(   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, B, H),
		gen_id(H, I)
	    ;   I=true
	    ),
	    J=(K=B, L, D, F, I)
	;   (   has_suspension_field(A, id)
	    ->  get_static_suspension_term_field(id, A, B, H),
		gen_id(H, I)
	    ;   I=true
	    ),
	    generate_indexed_variables_body(A, G, N, M),
	    chr_none_locked(M, O),
	    J=(K=B, N, O, L, D, F, I)
	).
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([A|C], B, E) :-
	generate_run_suspensions_clause(A, B, D),
	generate_run_suspensions_clauses(C, D, E).
run_suspensions_goal(A, D, B) :-
	make_name('$run_suspensions_', A, C),
	B=..[C, D].
generate_run_suspensions_clause(A, B, C) :-
	(   is_used_auxiliary_predicate(run_suspensions, A)
	->  B=[D, G|C],
	    run_suspensions_goal(A, [], D),
	    (   chr_pp_flag(debugable, on)
	    ->  run_suspensions_goal(A, [E|F], H),
		get_update_suspension_field(A,
					    E,
					    state,
					    K,
					    triggered,
					    I,
					    J,
					    L),
		get_update_suspension_field(A,
					    E,
					    state,
					    V,
					    active,
					    T,
					    U,
					    W),
		get_update_suspension_field(A,
					    E,
					    generation,
					    P,
					    O,
					    M,
					    N,
					    Q),
		get_dynamic_suspension_term_field(continuation,
						  A,
						  E,
						  S,
						  R),
		run_suspensions_goal(A, F, X),
		G=(H:-I, J, (K==active->L, M, N, O is P+1, Q, R, ('chr debugging'->('chr debug_event'(wake(E)), call(S);'chr debug_event'(fail(E)), !, fail), ('chr debug_event'(exit(E));'chr debug_event'(redo(E)), fail);call(S)), T, U, (V==triggered->W;true);true), X)
	    ;   run_suspensions_goal(A, [E|F], H),
		static_suspension_term(A, Y),
		get_static_suspension_term_field(arguments,
						 A,
						 Y,
						 Z),
		append(Z, [E], A1),
		make_suspension_continuation_goal(A, A1, S),
		run_suspensions_goal(A, F, X),
		(   uses_field(A, generation)
		->  get_update_static_suspension_field(A,
						       E,
						       Y,
						       generation,
						       P,
						       O,
						       M,
						       Q),
		    B1=(M, O is P+1, Q)
		;   B1=true
		),
		get_update_static_suspension_field(A,
						   E,
						   Y,
						   state,
						   K,
						   triggered,
						   I,
						   L),
		get_update_static_suspension_field(A,
						   E,
						   Y,
						   state,
						   V,
						   active,
						   D1,
						   E1),
		if_used_state(A,
			      removed,
			      (I, (K==active->C1;true)),
			      C1,
			      F1),
		C1=(L, B1, S, D1, (V==triggered->E1;true)),
		G=(H:-E=Y, F1, X)
	    )
	;   B=C
	).
generate_attach_increment(B) :-
	get_max_constraint_index(A),
	(   is_used_auxiliary_predicate(attach_increment),
	    A>0
	->  B=[C, D],
	    generate_attach_increment_empty(C),
	    (   A==1
	    ->  generate_attach_increment_one(D)
	    ;   generate_attach_increment_many(A, D)
	    )
	;   B=[]
	).
generate_attach_increment_empty((attach_increment([], _):-true)).
generate_attach_increment_one(I) :-
	J=attach_increment([A|H], E),
	get_target_module(C),
	chr_not_locked(A, B),
	K=(B, (get_attr(A, C, D)->sort(D, F), 'chr merge_attributes'(E, F, G), put_attr(A, C, G);put_attr(A, C, E)), attach_increment(H, E)),
	I=(J:-K).
generate_attach_increment_many(A, J) :-
	K=attach_increment([C|I], B),
	merge_attributes(A, B, F, G, H),
	get_target_module(E),
	chr_not_locked(C, D),
	L=(D, (get_attr(C, E, F)->G, put_attr(C, E, H);put_attr(C, E, B)), attach_increment(I, B)),
	J=(K:-L).
generate_attr_unify_hook(B) :-
	get_max_constraint_index(A),
	(   A==0
	->  B=[]
	;   B=[C|E],
	    C=attribute_goals(_, D, D),
	    (   A==1
	    ->  generate_attr_unify_hook_one(E)
	    ;   generate_attr_unify_hook_many(A, E)
	    )
	).
generate_attr_unify_hook_one([S]) :-
	T=attr_unify_hook(E, N),
	get_target_module(P),
	get_indexed_constraint(1, A),
	(   get_store_type(A, B),
	    (   B=default
	    ;   B=multi_store(C),
		memberchk(default, C)
	    )
	->  make_run_suspensions(H, D, Q),
	    make_run_suspensions(D, D, R),
	    (   atomic_types_suspended_constraint(A)
	    ->  I=true,
		D=E,
		J=true,
		K=F,
		L=(append(E, F, G), sort(G, H)),
		M=true
	    ;   I=sort(E, D),
		J=sort(F, K),
		L='chr merge_attributes'(D, K, H),
		use_auxiliary_predicate(attach_increment),
		M=(compound(N)->term_variables(N, O), attach_increment(O, D);true)
	    ),
	    U=(I, (var(N)->(get_attr(N, P, F)->J, L, put_attr(N, P, H), Q;put_attr(N, P, D), R);M, R)),
	    S=(T:-U)
	;   get_store_type(A, var_assoc_store(_, _))
	->  make_run_suspensions(G, G, Q),
	    L=merge_into_assoc_store(E, F, G),
	    U=(get_attr(N, P, F)->L, Q;put_attr(N, P, E)),
	    S=(T:-U)
	).
generate_attr_unify_hook_many(A, [X]) :-
	chr_pp_flag(dynattr, off), !,
	Y=attr_unify_hook(B, O),
	get_target_module(S),
	make_attr(A, H, D, B),
	bagof(E,
	      C^F^(member(C, D), E=sort(C, F)),
	      G),
	list2conj(G, R),
	bagof(F, C^member(sort(C, F), G), I),
	merge_attributes2(A, H, I, T, U, J),
	get_all_suspensions2(A, J, K),
	make_attr(A, H, I, Q),
	make_run_suspensions_loop(K, I, V),
	make_run_suspensions_loop(I, I, W),
	(   forall(( between(1, A, L),
		     get_indexed_constraint(L, M)
		   ),
		   atomic_types_suspended_constraint(M))
	->  N=true
	;   use_auxiliary_predicate(attach_increment),
	    N=(compound(O)->term_variables(O, P), attach_increment(P, Q);true)
	),
	Z=(R, (var(O)->(get_attr(O, S, T)->U, put_attr(O, S, J), V;put_attr(O, S, Q), W);N, W)),
	X=(Y:-Z).
generate_attr_unify_hook_many(B, R) :-
	P=attr_unify_hook(A, H),
	get_target_module(K),
	normalize_attr(A, J, C),
	normalize_attr(L, M, D),
	merge_attributes(B, C, D, N, O),
	make_run_suspensions(B),
	(   forall(( between(1, B, E),
		     get_indexed_constraint(E, F)
		   ),
		   atomic_types_suspended_constraint(F))
	->  G=true
	;   use_auxiliary_predicate(attach_increment),
	    G=(compound(H)->term_variables(H, I), attach_increment(I, C);true)
	),
	Q=(J, (var(H)->(get_attr(H, K, L)->M, N, put_attr(H, K, O), '$dispatch_run_suspensions'(O);put_attr(H, K, C), '$dispatch_run_suspensions'(C));G, '$dispatch_run_suspensions'(C))),
	S=(P:-Q),
	R=[S, T, U|Y],
	T='$dispatch_run_suspensions'([]),
	U=('$dispatch_run_suspensions'([V-W|X]):-'$dispatch_run_suspensions'(V, W), '$dispatch_run_suspensions'(X)),
	run_suspensions_dispatchers(B, [], Y).
run_suspensions_dispatchers(A, B, H) :-
	(   A>0
	->  get_indexed_constraint(A, C),
	    G=[('$dispatch_run_suspensions'(A, D):-E)|B],
	    (   may_trigger(C)
	    ->  run_suspensions_goal(C, D, E)
	    ;   E=true
	    ),
	    F is A-1,
	    run_suspensions_dispatchers(F, G, H)
	;   H=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, E, C, D) :-
	(   get_indexed_constraint(A, B),
	    may_trigger(B)
	->  use_auxiliary_predicate(run_suspensions, B),
	    (   wakes_partially(B)
	    ->  run_suspensions_goal(B, C, D)
	    ;   run_suspensions_goal(B, E, 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|E], [C|F], A,  (D, H)) :-
	make_run_suspensions(A, B, C, D),
	G is A+1,
	make_run_suspensions_loop(E, F, G, H).
generate_insert_delete_constraints([], []).
generate_insert_delete_constraints([A|D], B) :-
	(   is_stored(A)
	->  generate_insert_delete_constraint(A, B, C)
	;   B=C
	),
	generate_insert_delete_constraints(D, C).
generate_insert_delete_constraint(A, B, D) :-
	insert_constraint_clause(A, B, C),
	delete_constraint_clause(A, C, D).
insert_constraint_goal(A, B, E, C) :-
	(   chr_pp_flag(inline_insertremove, off)
	->  use_auxiliary_predicate(insert_in_store, A),
	    insert_constraint_atom(A, B, C)
	;   delay_phase_end(validate_store_type_assumptions,
			    (insert_constraint_body(A, B, D, C), insert_constraint_direct_used_vars(D, E)))
	).
insert_constraint_direct_used_vars([], _).
insert_constraint_direct_used_vars([A-C|D], B) :-
	nth1(A, B, C),
	insert_constraint_direct_used_vars(D, B).
insert_constraint_atom(A, D, B) :-
	make_name('$insert_in_store_', A, C),
	B=..[C, D].
insert_constraint_clause(A, B, C) :-
	(   is_used_auxiliary_predicate(insert_in_store, A)
	->  B=[D|C],
	    D=(E:-J, I, G),
	    insert_constraint_atom(A, F, E),
	    insert_constraint_body(A, F, H, G),
	    insert_constraint_used_vars(H, A, F, I),
	    (   chr_pp_flag(store_counter, on)
	    ->  J='$insert_counter_inc'
	    ;   J=true
	    )
	;   B=C
	).
insert_constraint_used_vars([], _, _, true).
insert_constraint_used_vars([A-D|F], B, C,  (E, G)) :-
	get_dynamic_suspension_term_field(argument(A),
					  B,
					  C,
					  D,
					  E),
	insert_constraint_used_vars(F, B, C, G).
insert_constraint_body(A, C, D, E) :-
	get_store_type(A, B),
	insert_constraint_body(B, A, C, D, E).
insert_constraint_body(default, A, D, [], F) :-
	global_list_store_name(A, B),
	make_get_store_goal(B, E, G),
	make_update_store_goal(B, C, H),
	(   chr_pp_flag(debugable, on)
	->  C=[D|E],
	    F=(G, H)
	;   set_dynamic_suspension_term_field(global_list_prev,
					      A,
					      I,
					      C,
					      J),
	    F=(G, C=[D|E], H, (E=[I|_]->J;true))
	).
insert_constraint_body(multi_inthash(A), B, C, [], D) :-
	generate_multi_inthash_insert_constraint_bodies(A,
							B,
							C,
							D).
insert_constraint_body(multi_hash(A), B, C, E, D) :-
	generate_multi_hash_insert_constraint_bodies(A,
						     B,
						     C,
						     D,
						     E),
	sort_out_used_vars(E, _).
insert_constraint_body(atomic_constants(B, _, _), A, C, D, G) :-
	multi_hash_key_direct(A, B, C, F, D),
	constants_store_index_name(A, B, E),
	H=..[E, F, I],
	G=(H->nb_getval(I, J), b_setval(I, [C|J]);true).
insert_constraint_body(ground_constants(B, _, _), A, C, D, G) :-
	multi_hash_key_direct(A, B, C, F, D),
	constants_store_index_name(A, B, E),
	H=..[E, F, I],
	G=(H->nb_getval(I, J), b_setval(I, [C|J]);true).
insert_constraint_body(global_ground, A, D, [], F) :-
	global_ground_store_name(A, B),
	make_get_store_goal(B, E, G),
	make_update_store_goal(B, C, H),
	(   chr_pp_flag(debugable, on)
	->  C=[D|E],
	    F=(G, H)
	;   set_dynamic_suspension_term_field(global_list_prev,
					      A,
					      I,
					      C,
					      J),
	    F=(G, C=[D|E], H, (E=[I|_]->J;true))
	).
insert_constraint_body(var_assoc_store(A, B), _, H, [A-D, B-G], C) :-
	get_target_module(E),
	C=(get_attr(D, E, F)->insert_assoc_store(F, G, H);new_assoc_store(F), put_attr(D, E, F), insert_assoc_store(F, G, H)).
insert_constraint_body(global_singleton, A, C, [], D) :-
	global_singleton_store_name(A, B),
	make_update_store_goal(B, C, E),
	D=E.
insert_constraint_body(multi_store(C), A, B, G, E) :-
	maplist(insert_constraint_body1(A, B),
		C,
		F,
		D),
	list2conj(D, E),
	sort_out_used_vars(F, G).
insert_constraint_body1(B, C, A, D, E) :-
	insert_constraint_body(A, B, C, D, E).
insert_constraint_body(identifier_store(B), D, I, A, G) :-
	A=[B-H],
	get_identifier_size(C),
	functor(F, struct, C),
	get_identifier_index(D, B, E),
	arg(E, F, J),
	G=(H=F, setarg(E, H, [I|J])).
insert_constraint_body(type_indexed_identifier_store(B, C), D, I, A, G) :-
	A=[B-H],
	type_indexed_identifier_structure(C, F),
	get_type_indexed_identifier_index(C, D, B, E),
	arg(E, F, J),
	G=(H=F, setarg(E, H, [I|J])).
sort_out_used_vars(A, D) :-
	flatten(A, B),
	sort(B, C),
	sort_out_used_vars1(C, D).
sort_out_used_vars1([], []).
sort_out_used_vars1([B-C], A) :- !,
	A=[B-C].
sort_out_used_vars1([A-C, B-D|E], F) :-
	(   A==B
	->  C=D,
	    sort_out_used_vars1([A-C|E], F)
	;   F=[A-C|G],
	    sort_out_used_vars1([B-D|E], G)
	).
generate_multi_inthash_insert_constraint_bodies([], _, _, true).
generate_multi_inthash_insert_constraint_bodies([B|I], A, C,  (D, J)) :-
	multi_hash_store_name(A, B, F),
	multi_hash_key(A, B, C, E, H),
	D=(E, nb_getval(F, G), insert_iht(G, H, C)),
	generate_multi_inthash_insert_constraint_bodies(I,
							A,
							C,
							J).
generate_multi_hash_insert_constraint_bodies([], _, _, true, []).
generate_multi_hash_insert_constraint_bodies([B|N], A, C,  (G, O), [D|P]) :-
	multi_hash_store_name(A, B, E),
	multi_hash_key_direct(A, B, C, J, D),
	make_get_store_goal(E, I, H),
	(   chr_pp_flag(ht_removal, on)
	->  ht_prev_field(B, F),
	    set_dynamic_suspension_term_field(F,
					      A,
					      L,
					      K,
					      M),
	    G=(H, insert_ht(I, J, C, K), (K=[_, L|_]->M;true))
	;   G=(H, insert_ht(I, J, C))
	),
	generate_multi_hash_insert_constraint_bodies(N,
						     A,
						     C,
						     O,
						     P).
delete_constraint_clause(A, B, C) :-
	(   is_used_auxiliary_predicate(delete_from_store, A)
	->  B=[D|C],
	    D=(E:-I),
	    delete_constraint_atom(A, H, E),
	    A=F/G,
	    functor(E, F, G),
	    delete_constraint_body(A, E, H, [], I)
	;   B=C
	).
delete_constraint_goal(A, E, G, F) :-
	functor(A, B, C),
	D=B/C,
	(   chr_pp_flag(inline_insertremove, off)
	->  use_auxiliary_predicate(delete_from_store, D),
	    delete_constraint_atom(D, E, F)
	;   delay_phase_end(validate_store_type_assumptions,
			    delete_constraint_body(D,
						   A,
						   E,
						   G,
						   F))
	).
delete_constraint_atom(A, D, B) :-
	make_name('$delete_from_store_', A, C),
	B=..[C, D].
delete_constraint_body(C, E, F, G, A) :-
	A=(B, H),
	(   chr_pp_flag(store_counter, on)
	->  B='$delete_counter_inc'
	;   B=true
	),
	get_store_type(C, D),
	delete_constraint_body(D,
			       C,
			       E,
			       F,
			       G,
			       H).
delete_constraint_body(default, A, _, F, _, C) :-
	(   chr_pp_flag(debugable, on)
	->  global_list_store_name(A, B),
	    make_get_store_goal(B, E, D),
	    make_update_store_goal(B, G, H),
	    C=(D, 'chr sbag_del_element'(E, F, G), H)
	;   get_dynamic_suspension_term_field(global_list_prev,
					      A,
					      F,
					      J,
					      K),
	    global_list_store_name(A, B),
	    make_get_store_goal(B, E, D),
	    make_update_store_goal(B, L, H),
	    set_dynamic_suspension_term_field(global_list_prev,
					      A,
					      I,
					      _,
					      M),
	    set_dynamic_suspension_term_field(global_list_prev,
					      A,
					      I,
					      J,
					      N),
	    C=(K, (var(J)->D, E=[_|L], H, (L=[I|_]->M;true);J=[_, _|L], setarg(2, J, L), (L=[I|_]->N;true)))
	).
delete_constraint_body(multi_inthash(A), B, _, C, _, D) :-
	generate_multi_inthash_delete_constraint_bodies(A,
							B,
							C,
							D).
delete_constraint_body(multi_hash(A), B, C, D, E, F) :-
	generate_multi_hash_delete_constraint_bodies(A,
						     B,
						     C,
						     D,
						     E,
						     F).
delete_constraint_body(atomic_constants(C, _, _), A, B, D, E, H) :-
	multi_hash_key(A,
		       B,
		       C,
		       D,
		       E,
		       I,
		       G),
	constants_store_index_name(A, C, F),
	J=..[F, G, K],
	H=(I, (J->nb_getval(K, L), 'chr sbag_del_element'(L, D, M), b_setval(K, M);true)).
delete_constraint_body(ground_constants(C, _, _), A, B, D, E, H) :-
	multi_hash_key(A,
		       B,
		       C,
		       D,
		       E,
		       I,
		       G),
	constants_store_index_name(A, C, F),
	J=..[F, G, K],
	H=(I, (J->nb_getval(K, L), 'chr sbag_del_element'(L, D, M), b_setval(K, M);true)).
delete_constraint_body(global_ground, A, _, F, _, C) :-
	(   chr_pp_flag(debugable, on)
	->  global_ground_store_name(A, B),
	    make_get_store_goal(B, E, D),
	    make_update_store_goal(B, G, H),
	    C=(D, 'chr sbag_del_element'(E, F, G), H)
	;   get_dynamic_suspension_term_field(global_list_prev,
					      A,
					      F,
					      J,
					      K),
	    global_ground_store_name(A, B),
	    make_get_store_goal(B, E, D),
	    make_update_store_goal(B, L, H),
	    set_dynamic_suspension_term_field(global_list_prev,
					      A,
					      I,
					      _,
					      M),
	    set_dynamic_suspension_term_field(global_list_prev,
					      A,
					      I,
					      J,
					      N),
	    C=(K, (var(J)->D, E=[_|L], H, (L=[I|_]->M;true);J=[_, _|L], setarg(2, J, L), (L=[I|_]->N;true)))
	).
delete_constraint_body(var_assoc_store(A, D), B, _, C, _, E) :-
	get_target_module(H),
	get_dynamic_suspension_term_field(argument(A),
					  B,
					  C,
					  G,
					  F),
	get_dynamic_suspension_term_field(argument(D),
					  B,
					  C,
					  K,
					  I),
	E=(F, get_attr(G, H, J), I, delete_assoc_store(J, K, C)).
delete_constraint_body(global_singleton, A, _, _, _, C) :-
	global_singleton_store_name(A, B),
	make_update_store_goal(B, [], D),
	C=D.
delete_constraint_body(multi_store(E), A, B, C, D, G) :-
	maplist(delete_constraint_body1(A, B, C, D),
		E,
		F),
	list2conj(F, G).
delete_constraint_body1(B, C, D, E, A, F) :-
	delete_constraint_body(A,
			       B,
			       C,
			       D,
			       E,
			       F).
delete_constraint_body(identifier_store(D), F, A, C, B, I) :-
	get_suspension_argument_possibly_in_scope(A,
						  B,
						  C,
						  D,
						  K,
						  J),
	get_identifier_size(E),
	functor(H, struct, E),
	get_identifier_index(F, D, G),
	arg(G, H, L),
	I=(J, K=H, 'chr sbag_del_element'(L, C, M), setarg(G, K, M)).
delete_constraint_body(type_indexed_identifier_store(D, E), F, A, C, B, I) :-
	get_suspension_argument_possibly_in_scope(A,
						  B,
						  C,
						  D,
						  K,
						  J),
	type_indexed_identifier_structure(E, H),
	get_type_indexed_identifier_index(E, F, D, G),
	arg(G, H, L),
	I=(J, K=H, 'chr sbag_del_element'(L, C, M), setarg(G, K, M)).
generate_multi_inthash_delete_constraint_bodies([], _, _, true).
generate_multi_inthash_delete_constraint_bodies([B|I], A, C,  (D, J)) :-
	multi_hash_store_name(A, B, F),
	multi_hash_key(A, B, C, E, H),
	D=(E, nb_getval(F, G), delete_iht(G, H, C)),
	generate_multi_inthash_delete_constraint_bodies(I,
							A,
							C,
							J).
generate_multi_hash_delete_constraint_bodies([], _, _, _, _, true).
generate_multi_hash_delete_constraint_bodies([B|S], A, C, D, E,  (J, T)) :-
	multi_hash_store_name(A, B, F),
	multi_hash_key(A,
		       C,
		       B,
		       D,
		       E,
		       M,
		       O),
	make_get_store_goal(F, N, L),
	(   chr_pp_flag(ht_removal, on)
	->  ht_prev_field(B, G),
	    get_dynamic_suspension_term_field(G,
					      A,
					      D,
					      I,
					      K),
	    set_dynamic_suspension_term_field(G,
					      A,
					      H,
					      _,
					      Q),
	    set_dynamic_suspension_term_field(G,
					      A,
					      H,
					      I,
					      R),
	    J=(K, (var(I)->L, M, delete_first_ht(N, O, P), (P=[H|_]->Q;true);I=[_, _|P], setarg(2, I, P), (P=[H|_]->R;true)))
	;   J=(M, L, delete_ht(N, O, D))
	),
	generate_multi_hash_delete_constraint_bodies(S,
						     _,
						     C,
						     D,
						     E,
						     T).
generate_attach_code(A, C) :-
	enumerate_stores_code(A, B),
	append(B, D, C),
	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([A|D], C, F) :-
	get_store_type(A, B),
	generate_attach_code(B, A, C, E),
	generate_attach_code(D, E, F).
generate_attach_code(default, A, B, C) :-
	global_list_store_initialisation(A, B, C).
generate_attach_code(multi_inthash(A), B, C, E) :-
	multi_inthash_store_initialisations(A, B, C, D),
	multi_inthash_via_lookups(A, B, D, E).
generate_attach_code(multi_hash(A), B, C, E) :-
	multi_hash_store_initialisations(A, B, C, D),
	multi_hash_lookups(A, B, D, E).
generate_attach_code(atomic_constants(B, C, _), A, D, E) :-
	constants_initializers(A, B, C),
	atomic_constants_code(A, B, C, D, E).
generate_attach_code(ground_constants(B, C, _), A, D, E) :-
	constants_initializers(A, B, C),
	ground_constants_code(A, B, C, D, E).
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(A), B, C, D) :-
	multi_store_generate_attach_code(A, B, C, D).
generate_attach_code(identifier_store(B), A, L, P) :-
	get_identifier_index(A, B, C),
	(   C==2
	->  get_identifier_size(D),
	    functor(E, struct, D),
	    E=..[_, G|F],
	    set_elems(F, []),
	    M=new_identifier(G, E),
	    functor(H, struct, D),
	    arg(1, H, I),
	    N=(user:portray(H):-write('<id:'), print(I), write(>)),
	    functor(J, struct, D),
	    arg(1, J, K),
	    O=identifier_label(J, K),
	    L=[M, N, O|P]
	;   L=P
	).
generate_attach_code(type_indexed_identifier_store(C, A), B, E, S1) :-
	get_type_indexed_identifier_index(A, B, C, D),
	(   D==2
	->  identifier_store_initialization(A, E, K1),
	    get_type_indexed_identifier_size(A, _),
	    type_indexed_identifier_structure(A, F),
	    F=..[_, I|G],
	    set_elems(G, []),
	    type_indexed_identifier_name(A, new_identifier, H),
	    L1=..[H, I, F],
	    N=..[H, K, M],
	    type_indexed_identifier_structure(A, J),
	    J=..[_, K|L],
	    set_elems(L, []),
	    O=(M=J),
	    M1=user:goal_expansion(N, O),
	    type_indexed_identifier_structure(A, P),
	    arg(1, P, Q),
	    N1=(user:portray(P):-write('<id:'), print(Q), write(>)),
	    type_indexed_identifier_structure(A, R),
	    arg(1, R, T),
	    type_indexed_identifier_name(A, identifier_label, S),
	    O1=..[S, R, T],
	    X=..[S, W, V],
	    type_indexed_identifier_structure(A, U),
	    arg(1, U, V),
	    Y=(W=U),
	    P1=(user:goal_expansion(X, Y):-writeln(expanding)),
	    identifier_store_name(A, D1),
	    lookup_identifier_atom(A, A1, B1, C1),
	    type_indexed_identifier_name(A, new_identifier, Z),
	    F1=..[Z, A1, B1],
	    Q1=(C1:-nb_getval(D1, E1), (lookup_ht(E1, A1, [B1])->true;F1, insert_ht(E1, A1, B1))),
	    lookup_only_identifier_atom(A, I1, J1, G1),
	    R1=(G1:-nb_getval(D1, H1), lookup_ht(H1, I1, [J1])),
	    K1=[(:-multifile goal_expansion/2),  (:-dynamic goal_expansion/2), L1, M1, N1, O1, P1, Q1, R1|S1]
	;   E=S1
	).
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, D, E, B) :-
	atom_concat(lookup_identifier_, A, C),
	B=..[C, D, E].
lookup_only_identifier_atom(A, D, E, B) :-
	atom_concat(lookup_only_identifier_, A, C),
	B=..[C, D, E].
identifier_label_atom(A, D, E, B) :-
	type_indexed_identifier_name(A, identifier_label, C),
	B=..[C, D, E].
multi_store_generate_attach_code([], _, A, A).
multi_store_generate_attach_code([A|D], B, C, F) :-
	generate_attach_code(A, B, C, E),
	multi_store_generate_attach_code(D, B, E, F).
multi_inthash_store_initialisations([], _, A, A).
multi_inthash_store_initialisations([B|F], A, E, H) :-
	use_auxiliary_module(chr_integertable_store),
	multi_hash_store_name(A, B, C),
	module_initializer((new_iht(D), nb_setval(C, D))),
	G=E,
	multi_inthash_store_initialisations(F, A, G, H).
multi_hash_store_initialisations([], _, A, A).
multi_hash_store_initialisations([B|G], A, F, I) :-
	use_auxiliary_module(chr_hashtable_store),
	multi_hash_store_name(A, B, C),
	prolog_global_variable(C),
	make_init_store_goal(C, D, E),
	module_initializer((new_ht(D), E)),
	H=F,
	multi_hash_store_initialisations(G, A, H, I).
global_list_store_initialisation(A, D, E) :-
	(   is_stored(A)
	->  global_list_store_name(A, B),
	    prolog_global_variable(B),
	    make_init_store_goal(B, [], C),
	    module_initializer(C)
	;   true
	),
	D=E.
global_ground_store_initialisation(A, D, E) :-
	global_ground_store_name(A, B),
	prolog_global_variable(B),
	make_init_store_goal(B, [], C),
	module_initializer(C),
	D=E.
global_singleton_store_initialisation(A, D, E) :-
	global_singleton_store_name(A, B),
	prolog_global_variable(B),
	make_init_store_goal(B, [], C),
	module_initializer(C),
	D=E.
identifier_store_initialization(A, E, F) :-
	use_auxiliary_module(chr_hashtable_store),
	identifier_store_name(A, B),
	prolog_global_variable(B),
	make_init_store_goal(B, C, D),
	module_initializer((new_ht(C), D)),
	E=F.
multi_inthash_via_lookups([], _, A, A).
multi_inthash_via_lookups([B|H], A, E, J) :-
	multi_hash_lookup_head(A, B, C, D, F),
	multi_hash_lookup_body(A,
			       inthash,
			       B,
			       C,
			       D,
			       G),
	E=[(F:-G)|I],
	multi_inthash_via_lookups(H, A, I, J).
multi_hash_lookups([], _, A, A).
multi_hash_lookups([B|H], A, E, J) :-
	multi_hash_lookup_head(A, B, C, D, F),
	multi_hash_lookup_body(A, hash, B, C, D, G),
	E=[(F:-G)|I],
	multi_hash_lookups(H, A, I, J).
multi_hash_lookup_head(A, B, E, F, C) :-
	multi_hash_lookup_name(A, B, D),
	C=..[D, E, F].
multi_hash_lookup_body(A, K, B, D, G, E) :-
	get_store_type(A, multi_store(C)),
	(   memberchk(atomic_constants(B, J, _), C)
	->  (   ground(D)
	    ->  constants_store_name(A, B, D, F),
		E=nb_getval(F, G)
	    ;   constants_store_index_name(A, B, H),
		I=..[H, D, F],
		E=(I, nb_getval(F, G))
	    )
	;   memberchk(ground_constants(B, J, _), C)
	->  (   ground(D)
	    ->  constants_store_name(A, B, D, F),
		E=nb_getval(F, G)
	    ;   constants_store_index_name(A, B, H),
		I=..[H, D, F],
		E=(I, nb_getval(F, G))
	    )
	;   memberchk(multi_hash([B]), C)
	->  multi_hash_store_name(A, B, F),
	    make_get_store_goal(F, N, L),
	    (   K==hash,
		specialized_hash_term_call(A,
					   B,
					   D,
					   O,
					   M)
	    ->  E=(L, M, lookup_ht1(N, O, D, G))
	    ;   lookup_hash_call(K, N, D, G, I),
		E=(L, I)
	    )
	;   K==inthash
	->  multi_hash_store_name(A, B, F),
	    make_get_store_goal(F, N, L),
	    lookup_hash_call(K, N, D, G, I),
	    E=(L, I)
	).
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)
	->  term_hash(A, B),
	    C=true
	).
multi_hash_lookup_goal(B, F, C, A, G, H) :-
	(   atomic(A)
	->  actual_atomic_multi_hash_keys(B, C, [A])
	;   ground(A)
	->  actual_ground_multi_hash_keys(B, C, [A])
	;   C=[D],
	    get_constraint_arg_type(B, D, E),
	    is_chr_constants_type(E, _, _)
	->  true
	;   actual_non_ground_multi_hash_key(B, C)
	),
	delay_phase_end(validate_store_type_assumptions,
			multi_hash_lookup_body(B,
					       F,
					       C,
					       A,
					       G,
					       H)).
multi_hash_lookup_name(B/C, A, E) :-
	atom_concat_list(A, D),
	atom_concat_list(['$via1_multi_hash_', B, '___', C, -, D],
			 E).
multi_hash_store_name(C/D, A, F) :-
	get_target_module(B),
	atom_concat_list(A, E),
	atom_concat_list(
			 [ '$chr_store_multi_hash_',
			   B,
			   '____',
			   C,
			   '___',
			   D,
			   (-),
			   E
			 ],
			 F).
multi_hash_key(C, A, D, F, E) :-
	(   A=[B]
	->  get_dynamic_suspension_term_field(argument(B),
					      C,
					      D,
					      E,
					      F)
	;   maplist(get_dynamic_suspension_term_field1(C, D),
		    A,
		    G,
		    H),
	    E=..[k|G],
	    list2conj(H, F)
	).
get_dynamic_suspension_term_field1(B, C, A, D, E) :-
	get_dynamic_suspension_term_field(argument(A),
					  B,
					  C,
					  D,
					  E).
multi_hash_key(_, B, A, D, C, G, F) :-
	(   A=[E]
	->  get_suspension_argument_possibly_in_scope(B,
						      C,
						      D,
						      E,
						      F,
						      G)
	;   maplist(get_suspension_argument_possibly_in_scope(B,
							      C,
							      D),
		    A,
		    H,
		    I),
	    F=..[k|H],
	    list2conj(I, G)
	).
get_suspension_argument_possibly_in_scope(B, I, N, A, F, G) :-
	arg(A, B, C),
	(   ground(C),
	    C='$chr_identifier_match'(E, D)
	->  functor(B, K, L),
	    lookup_identifier_atom(D, E, F, G)
	;   term_variables(C, H),
	    copy_term_nat(C-H, F-J),
	    translate(H, I, J)
	->  G=true
	;   functor(B, K, L),
	    M=K/L,
	    get_dynamic_suspension_term_field(argument(A),
					      M,
					      N,
					      F,
					      G)
	).
multi_hash_key_direct(_, A, _, D, B) :-
	(   A=[C]
	->  B=[C-D]
	;   pairup(A, E, B),
	    D=..[k|E]
	).
args(B, A, C) :-
	maplist(arg1(A), B, C).
split_args(A, B, C, D) :-
	split_args(A, B, 1, C, D).
split_args([], A, _, [], A).
split_args([B|E], [D|F], A, C, I) :-
	G is A+1,
	(   B==A
	->  C=[D|H],
	    split_args(E, F, G, H, I)
	;   I=[D|H],
	    split_args([B|E], F, G, C, H)
	).
atomic_constants_code(A, B, D, G, F) :-
	constants_store_index_name(A, B, C),
	maplist(atomic_constant_code(A, B, C), D, E),
	append(E, F, G).
atomic_constant_code(A, B, E, C, D) :-
	constants_store_name(A, B, C, F),
	D=..[E, C, F].
ground_constants_code(A, B, C, H, I) :-
	constants_store_index_name(A, B, G),
	maplist(constants_store_name(A, B), C, F),
	length(C, D),
	replicate(D, [], E),
	trie_index([C|E], F, G, H, I).
constants_store_name(D/E, B, A, H) :-
	get_target_module(C),
	term_to_atom(A, G),
	term_to_atom(B, F),
	atom_concat_list(
			 [ '$chr_store_constants_',
			   C,
			   '____',
			   D,
			   '___',
			   E,
			   '___',
			   F,
			   '___',
			   G
			 ],
			 H).
constants_store_index_name(C/D, A, F) :-
	get_target_module(B),
	term_to_atom(A, E),
	atom_concat_list(
			 [ '$chr_store_constants_',
			   B,
			   '____',
			   C,
			   '___',
			   D,
			   '___',
			   E
			 ],
			 F).
trie_index([A|C], D, B, E, F) :-
	trie_step(A, B, B, C, D, E, F).
trie_step([], _, _, [], [], A, A) :- !.
trie_step(C, K, L, A, J, M, N) :-
	A=[B|_],
	length(B, G),
	aggregate_all(set(E/F),
		      ( member(D, C),
			functor(D, E, F)
		      ),
		      H),
	I is G+1,
	trie_step_cases(H,
			I,
			C,
			A,
			J,
			K,
			L,
			M,
			N).
trie_step_cases([], _, _, _, _, _, _, A, A).
trie_step_cases([A|I], B, C, D, E, F, G, H, K) :-
	trie_step_case(A,
		       B,
		       C,
		       D,
		       E,
		       F,
		       G,
		       H,
		       J),
	trie_step_cases(I,
			B,
			C,
			D,
			E,
			F,
			G,
			J,
			K).
trie_step_case(H/I, B, P, S, Q, D, B1, [A|M], N) :-
	A=(C:-O),
	E is B+1,
	functor(C, D, E),
	arg(1, C, G),
	C=..[_, _|F],
	once(append(X, [L], F)),
	functor(G, H, I),
	G=..[_|J],
	append(J, F, K),
	(   K==[L]
	->  M=N,
	    O=true,
	    rec_cases(P,
		      _,
		      Q,
		      H/I,
		      _,
		      _,
		      R),
	    R=[L]
	;   rec_cases(P,
		      S,
		      Q,
		      H/I,
		      U,
		      T,
		      R),
	    (   T=[V]
	    ->  M=N,
		O=true,
		append([U, V, R], K)
	    ;   pairup(U, T, W),
		common_pattern(W, A1, C1, F1),
		append(J, X, [Y|Z]),
		Y-Z=A1,
		fresh_symbol(B1, D1),
		append(C1, [L], E1),
		O=..[D1|E1],
		maplist(head_tail, F1, G1, H1),
		trie_step(G1,
			  D1,
			  B1,
			  H1,
			  R,
			  M,
			  N)
	    )
	).
head_tail([A|B], A, B).
rec_cases([], [], [], _, [], [], []).
rec_cases([A|L], [E|M], [K|N], B/C, F, H, J) :-
	(   functor(A, B, C),
	    A=..[_|D],
	    append(D, E, [G|I])
	->  F=[G|O],
	    H=[I|P],
	    J=[K|Q],
	    rec_cases(L,
		      M,
		      N,
		      B/C,
		      O,
		      P,
		      Q)
	;   rec_cases(L,
		      M,
		      N,
		      B/C,
		      F,
		      H,
		      J)
	).
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, G, K, L) :-
	(   nonvar(A),
	    nonvar(B),
	    functor(A, C, E),
	    functor(B, D, F),
	    C==D,
	    E==F
	->  functor(G, C, E),
	    A=..[_|H],
	    B=..[_|I],
	    G=..[_|J],
	    maplist_dcg(chr_translate:gct_,
			H,
			I,
			J,
			K,
			L)
	;   lookup_eq(K, A+B, G)
	->  L=K
	;   L=[A+B-G|K]
	).
global_list_store_name(B/C, D) :-
	get_target_module(A),
	atom_concat_list(
			 [ '$chr_store_global_list_',
			   A,
			   '____',
			   B,
			   '___',
			   C
			 ],
			 D).
global_ground_store_name(B/C, D) :-
	get_target_module(A),
	atom_concat_list(
			 [ '$chr_store_global_ground_',
			   A,
			   '____',
			   B,
			   '___',
			   C
			 ],
			 D).
global_singleton_store_name(B/C, D) :-
	get_target_module(A),
	atom_concat_list(
			 [ '$chr_store_global_singleton_',
			   A,
			   '____',
			   B,
			   '___',
			   C
			 ],
			 D).
identifier_store_name(B, C) :-
	get_target_module(A),
	atom_concat_list(['$chr_identifier_lookup_', A, '____', B],
			 C).
:- if(current_predicate(user:exception/3)).
prolog_global_variables_code([]) :-
	tmp_module, !.
prolog_global_variables_code(B) :-
	prolog_global_variables(A),
	(   A==[]
	->  B=[]
	;   maplist(wrap_in_functor('$chr_prolog_global_variable'),
		    A,
		    D),
	    B=[(:-dynamic user:exception/3),  (:-multifile user:exception/3),  (user:exception(undefined_global_variable, C, retry):-'$chr_prolog_global_variable'(C), '$chr_initialization')|D]
	).
tmp_module :-
	prolog_load_context(module, A),
	module_property(A, class(temporary)).
:- else.
prolog_global_variables_code([]).
:- endif.
sbag_member_call(A, B, member(A, B)).
update_mutable_call(A, B, 'chr update_mutable'(A, B)).
create_mutable_call(B, A, true) :-
	A=mutable(B).
get_suspension_field(B, C, A, D, E) :-
	get_dynamic_suspension_term_field(A,
					  B,
					  C,
					  D,
					  E).
update_suspension_field(B, C, A, D, E) :-
	set_dynamic_suspension_term_field(A,
					  B,
					  C,
					  D,
					  E).
get_update_suspension_field(B, C, A, D, F, true, E, G) :-
	get_dynamic_suspension_term_field(A,
					  B,
					  C,
					  D,
					  E),
	set_dynamic_suspension_term_field(A,
					  B,
					  C,
					  F,
					  G).
create_static_suspension_field(B, C, A, D, true) :-
	get_static_suspension_term_field(A, B, C, D).
get_static_suspension_field(B, C, A, D, true) :-
	get_static_suspension_term_field(A, B, C, D).
get_update_static_suspension_field(B, E, C, A, D, F, true, G) :-
	get_static_suspension_term_field(A, B, C, D),
	set_dynamic_suspension_term_field(A,
					  B,
					  E,
					  F,
					  G).
enumerate_stores_code(C, [A|E]) :-
	B='$enumerate_constraints'(D),
	A=(B:-F),
	enumerate_store_bodies(C, D, E),
	(   E=[]
	->  F=fail
	;   F=(nonvar(D)->functor(D, G, _), '$enumerate_constraints'(G, D);'$enumerate_constraints'(_, D))
	).
enumerate_store_bodies([], _, []).
enumerate_store_bodies([A|N], F, J) :-
	(   is_stored(A)
	->  get_store_type(A, B),
	    (   enumerate_store_body(B, A, C, G)
	    ->  true
	    ;   chr_error(internal,
			  'Could not generate enumeration code for constraint ~w.\n',
			  [A])
	    ),
	    get_dynamic_suspension_term_field(arguments,
					      A,
					      C,
					      E,
					      H),
	    A=D/_,
	    I=..[D|E],
	    K='$enumerate_constraints'(D, F),
	    L=(G, H, F=I),
	    J=[(K:-L)|M]
	;   J=M
	),
	enumerate_store_bodies(N, F, M).
enumerate_store_body(default, A, B, E) :-
	global_list_store_name(A, C),
	sbag_member_call(B, D, G),
	make_get_store_goal_no_error(C, D, F),
	E=(F, G).
enumerate_store_body(multi_inthash([A|_]), B, C, D) :-
	multi_inthash_enumerate_store_body(A, B, C, D).
enumerate_store_body(multi_hash([A|_]), B, C, D) :-
	multi_hash_enumerate_store_body(A, B, C, D).
enumerate_store_body(atomic_constants(C, D, A), B, H, F) :-
	A==complete,
	maplist(enumerate_constant_store_body(B, C, I),
		D,
		E),
	list2disj(E, G),
	F=(G, member(H, I)).
enumerate_constant_store_body(B, C, A, D, nb_getval(E, A)) :-
	constants_store_name(B, C, D, E).
enumerate_store_body(ground_constants(A, B, C), D, E, F) :-
	enumerate_store_body(atomic_constants(A, B, C),
			     D,
			     E,
			     F).
enumerate_store_body(global_ground, A, B, E) :-
	global_ground_store_name(A, C),
	sbag_member_call(B, D, G),
	make_get_store_goal(C, D, F),
	E=(F, G).
enumerate_store_body(var_assoc_store(_, _), _, _, A) :-
	A=fail.
enumerate_store_body(global_singleton, A, C, D) :-
	global_singleton_store_name(A, B),
	make_get_store_goal(B, C, E),
	D=(E, C\==[]).
enumerate_store_body(multi_store(A), B, C, D) :-
	(   memberchk(global_ground, A)
	->  enumerate_store_body(global_ground, B, C, D)
	;   once(( member(E, A),
		   enumerate_store_body(E, B, C, D)
		 ))
	).
enumerate_store_body(identifier_store(_), _, _, A) :-
	A=fail.
enumerate_store_body(type_indexed_identifier_store(_, _), _, _, A) :-
	A=fail.
multi_inthash_enumerate_store_body(B, A, F, C) :-
	multi_hash_store_name(A, B, D),
	C=(nb_getval(D, E), value_iht(E, F)).
multi_hash_enumerate_store_body(B, A, G, D) :-
	multi_hash_store_name(A, B, C),
	make_get_store_goal(C, F, E),
	D=(E, value_ht(F, G)).
guard_simplification :-
	(   chr_pp_flag(guard_simplification, on)
	->  precompute_head_matchings,
	    simplify_guards(1)
	;   true
	).
next_prev_rule(A, C, D) :-
	(   find_min_q(A, _-B)
	->  B=(-C),
	    normalize_heap(A, B, D)
	;   C=0,
	    D=A
	).
normalize_heap(A, B, I) :-
	(   find_min_q(A, _-B)
	->  delete_min_q(A,
			 F,
			 tuple(D, C, _)-_),
	    (   C>1
	    ->  E is C-1,
		get_occurrence(D, E, G, _),
		insert_q(F,
			 tuple(D, E, G)-(-G),
			 H)
	    ;   H=F
	    ),
	    normalize_heap(H, B, I)
	;   I=A
	).
head_types_modes_condition([], _, true).
head_types_modes_condition([B|D], A,  (C, E)) :-
	types_modes_condition(A, B, C),
	head_types_modes_condition(D, A, E).
add_background_info(A, D) :-
	get_bg_info(B),
	add_background_info2(A, C),
	append(B, C, D).
add_background_info2(A, []) :-
	var(A), !.
add_background_info2([], []) :- !.
add_background_info2([A|B], E) :- !,
	add_background_info2(A, C),
	add_background_info2(B, D),
	append(C, D, E).
add_background_info2(A, F) :-
	(   functor(A, _, B),
	    B>0
	->  A=..[_|C],
	    add_background_info2(C, D)
	;   D=[]
	),
	get_bg_info(A, E),
	append(E, D, F).
normalize_conj_list(A, C) :-
	list2conj(A, B),
	conj2list(B, C).
compute_derived_info([], _, _, _, _, _, _, _, [], []).
compute_derived_info([D|Z], A, H, G, B, A1, U, B1, [R|C1], [Y|D1]) :-
	copy_term(A-B, C),
	variable_replacement(A-B, C, E),
	append(D, E, J),
	list2conj(A, F),
	negate_b(F, N),
	make_head_matchings_explicit_not_negated2(G, H, I),
	list2conj(I, P),
	term_variables(J, L),
	term_variables(A-B-I, K),
	new_vars(K, L, M),
	append(J, M, S),
	(   B==true
	->  O=N
	;   negate_b(B, Q),
	    O=(N;P, Q)
	),
	copy_with_variable_replacement(O, R, S),
	copy_with_variable_replacement(B, V, S),
	copy_with_variable_replacement(A, T, S),
	list2conj(T, X),
	apply_guard_wrt_term(U, V, W),
	apply_guard_wrt_term(W, X, Y),
	compute_derived_info(Z,
			     A,
			     H,
			     G,
			     B,
			     A1,
			     U,
			     B1,
			     C1,
			     D1).
simplify_guard(A, C, B, G, E) :-
	conj2list(A, D),
	guard_entailment:simplify_guards(B, C, D, F, E),
	list2conj(F, G).
new_vars([], _, []).
new_vars([A|C], B, D) :-
	(   memberchk_eq(A, B)
	->  new_vars(C, B, D)
	;   D=[A-E, E-A|F],
	    new_vars(C, B, F)
	).
head_subset(A, B, C) :-
	head_subset(A, B, C, [], _).
head_subset([], B, A, A, B).
head_subset([B|D], A, F, C, H) :-
	head_member(A, B, G, C, E),
	head_subset(D, E, F, G, H).
head_member([B|F], A, D, C, E) :-
	(   variable_replacement(A, B, C, D),
	    E=F
	;   E=[B|G],
	    head_member(F, A, D, C, G)
	).
make_head_matchings_explicit(A, D, E) :-
	make_head_matchings_explicit_memo_lookup(A, B, C),
	copy_term_nat(B-C, D-E).
make_head_matchings_explicit_(A, E, C) :-
	extract_arguments(A, B),
	make_matchings_explicit(B, D, [], [], _, C),
	substitute_arguments(A, D, E).
make_head_matchings_explicit_not_negated(A, E, C) :-
	extract_arguments(A, B),
	make_matchings_explicit_not_negated(B, D, C),
	substitute_arguments(A, D, E).
make_head_matchings_explicit_not_negated2(A, B, E) :-
	extract_arguments(A, C),
	extract_arguments(B, D),
	make_matchings_explicit_not_negated(C, D, E).
extract_arguments([], []).
extract_arguments([A|D], C) :-
	A=..[_|B],
	append(B, E, C),
	extract_arguments(D, E).
substitute_arguments([], [], []).
substitute_arguments([A|G], C, [D|I]) :-
	functor(A, E, B),
	split_at(B, C, F, H),
	D=..[E|F],
	substitute_arguments(G, H, I).
make_matchings_explicit([], [], _, A, A, []).
make_matchings_explicit([A|S], [F|U], B, C, V, D) :-
	(   var(A)
	->  (   memberchk_eq(A, B)
	    ->  list2disj(C, E),
		D=[(E;F==A)|G],
		H=B
	    ;   D=G,
		F=A,
		H=[A|B]
	    ),
	    Q=C
	;   functor(A, I, M),
	    A=..[I|J],
	    make_matchings_explicit(J,
				    K,
				    B,
				    C,
				    R,
				    L),
	    N=..[I|K],
	    (   L==[]
	    ->  D=[functor(F, I, M)|G]
	    ;   list2conj(L, O),
		list2disj(C, E),
		P=(F\=N;E;O),
		D=[functor(F, I, M), P|G]
	    ),
	    Q=[F\=N|R],
	    term_variables(S, T),
	    append(T, B, H)
	),
	make_matchings_explicit(S,
				U,
				H,
				Q,
				V,
				G).
make_matchings_explicit_not_negated([], [], []).
make_matchings_explicit_not_negated([C|D], [B|E], A) :-
	A=[B=C|F],
	make_matchings_explicit_not_negated(D, E, F).
apply_guard_wrt_term([], _, []).
apply_guard_wrt_term([A|G], B, [C|H]) :-
	(   var(A)
	->  apply_guard_wrt_variable(B, A, C)
	;   A=..[E|D],
	    apply_guard_wrt_term(D, B, F),
	    C=..[E|F]
	),
	apply_guard_wrt_term(G, B, H).
apply_guard_wrt_variable((A, C), B, E) :- !,
	apply_guard_wrt_variable(A, B, D),
	apply_guard_wrt_variable(C, D, E).
apply_guard_wrt_variable(A, B, D) :-
	(   A=(C=E),
	    B==C
	->  D=E
	;   A=functor(F, G, H),
	    B==F,
	    ground(G),
	    ground(H)
	->  functor(D, G, H)
	;   D=B
	).
replace_some_heads(A, B, _, [], A, B, _, _, []) :- !.
replace_some_heads([], [M|D], [A|E], [B|F], [], [C|G], H, I, J) :- !,
	(   A==B
	->  C=B,
	    replace_some_heads([],
			       D,
			       E,
			       F,
			       [],
			       G,
			       H,
			       I,
			       J)
	;   B=functor(K, N, L),
	    A==K
	->  length(O, L),
	    (   var(M)
	    ->  Q=[],
		C=..[N|O]
	    ;   M=..[N|P],
		use_same_args(P,
			      O,
			      R,
			      H,
			      I,
			      Q),
		C=..[N|R]
	    ),
	    replace_some_heads([],
			       D,
			       E,
			       F,
			       [],
			       G,
			       H,
			       I,
			       S),
	    append(Q, S, J)
	;   C=M,
	    replace_some_heads([],
			       D,
			       E,
			       [B|F],
			       [],
			       G,
			       H,
			       I,
			       J)
	).
replace_some_heads([O|D], E, [A|F], [B|G], [C|H], I, J, K, L) :- !,
	(   A==B
	->  C=B,
	    replace_some_heads(D,
			       E,
			       F,
			       G,
			       H,
			       I,
			       J,
			       K,
			       L)
	;   B=functor(M, P, N),
	    A==M
	->  length(Q, N),
	    (   var(O)
	    ->  S=[],
		C=..[P|Q]
	    ;   O=..[P|R],
		use_same_args(R,
			      Q,
			      T,
			      J,
			      K,
			      S),
		C=..[P|T]
	    ),
	    replace_some_heads(D,
			       E,
			       F,
			       G,
			       H,
			       I,
			       J,
			       K,
			       U),
	    append(S, U, L)
	;   C=O,
	    replace_some_heads(D,
			       E,
			       F,
			       [B|G],
			       H,
			       I,
			       J,
			       K,
			       L)
	).
use_same_args([], [], [], _, _, []).
use_same_args([A|C], [_|D], [B|E], F, G, H) :-
	var(A), !,
	B=A,
	use_same_args(C, D, E, F, G, H).
use_same_args([A|G], [D|H], [F|I], J, B, C) :-
	nonvar(A), !,
	(   common_variables(A, B)
	->  C=[D=A|E]
	;   C=E
	),
	F=D,
	use_same_args(G, H, I, J, B, E).
simplify_heads([], _, _, _, [], []).
simplify_heads([A|C], D, F, I, H, G) :-
	A=(E=B),
	(   (   nonvar(B)
	    ;   common_variables(B, C-D)
	    ),
	    guard_entailment:entails_guard(D, E=B)
	->  (   common_variables(B, F-C-D)
	    ->  G=J,
		H=K
	    ;   (   common_variables(B, I)
		->  G=[E=B|J]
		;   G=J
		),
		H=[E|K]
	    )
	;   nonvar(B),
	    functor(B, L, M),
	    guard_entailment:entails_guard([functor(E, L, M)|D], E=B)
	->  G=J,
	    (   common_variables(B, F-C-D)
	    ->  H=K
	    ;   H=[functor(E, L, M)|K]
	    )
	;   H=K,
	    G=J
	),
	simplify_heads(C,
		       [A|D],
		       F,
		       I,
		       K,
		       J).
common_variables(A, B) :-
	term_variables(A, C),
	term_variables(B, D),
	intersect_eq(C, D, E),
	E\==[].
add_failing_occ(A, D, E, G, S, R, _, H, M) :-
	A=pragma(rule(_, _, N, _), ids(C, B), _, _, _),
	append(B, C, F),
	missing_partner_cond(D,
			     E,
			     F,
			     G,
			     Q,
			     I,
			     H),
	copy_term((I, D, E),  (J, K, L)),
	variable_replacement((I, D, E),
			     (J, K, L),
			     M),
	copy_with_variable_replacement(N, O, M),
	extract_explicit_matchings(O, P),
	negate_b(P, T),
	copy_with_variable_replacement(Q, U, M),
	(   subsumes_term(R, J),
	    R=J
	->  S=[(T;U)]
	;   S=[chr_pp_void_info]
	).
missing_partner_cond([], [], [], _, fail, _, _).
missing_partner_cond([B|C], [_|D], [A|E], A, F, B, G) :- !,
	missing_partner_cond(C,
			     D,
			     E,
			     A,
			     F,
			     B,
			     G).
missing_partner_cond([B|C], [_|D], [_|E], F, A, H, I/J) :-
	A=(chr_pp_not_in_store(B);G),
	missing_partner_cond(C,
			     D,
			     E,
			     F,
			     G,
			     H,
			     I/J).
extract_explicit_matchings((A, B), C) :- !,
	(   extract_explicit_matchings(A)
	->  extract_explicit_matchings(B, C)
	;   C=(A, D),
	    extract_explicit_matchings(B, 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(B, A) :-
	(   ground(A)
	->  constraint_type(B, A)
	;   chr_error(type_error,
		      'Declared argument types "~w" for constraint "~w" must be ground!\n',
		      [A, B])
	).
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([A|E], [C|F], B) :-
	(   A==(+)
	->  B=(ground(C), D)
	;   A==(-)
	->  B=(var(C), D)
	;   B=D
	),
	modes_condition(E, F, D).
types_condition([], [], [], [], true).
types_condition([B|I], [D|J], [E|K], [A|L],  (H, M)) :-
	(   A==(-)
	->  F=[true]
	;   get_type_definition_det(B, C),
	    type_condition(C, D, E, A, G),
	    (   A==(+)
	    ->  F=G
	    ;   F=[\+ground(D)|G]
	    )
	),
	list2disj(F, H),
	types_condition(I, J, K, L, M).
type_condition([], _, _, _, []).
type_condition([A|F], B, D, E, [C|G]) :-
	(   var(A)
	->  chr_error(type, 'Unexpected variable type in type definition!\n', [])
	;   atomic_builtin_type(A, B, C)
	->  true
	;   compound_builtin_type(A, B, C, _)
	->  true
	;   type_def_case_condition(A, B, D, E, C)
	),
	type_condition(F, B, D, E, G).
ast_atomic_builtin_type(B, A, D) :-
	ast_term_to_term(A, C),
	atomic_builtin_type(B, C, D).
ast_compound_builtin_type(B, A, D) :-
	ast_term_to_term(A, C),
	compound_builtin_type(B, C, _, D).
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, D, E, H, C) :-
	(   nonvar(A)
	->  functor(A, F, B),
	    (   B==0
	    ->  C=(D=A)
	    ;   var(E)
	    ->  C=functor(D, F, B)
	    ;   functor(E, F, B)
	    ->  C=(functor(D, F, B), D=G, M),
		A=..[_|I],
		E=..[_|K],
		functor(G, F, B),
		G=..[_|J],
		replicate(B, H, L),
		types_condition(I, J, K, L, M)
	    ;   C=functor(D, F, B)
	    )
	;   chr_error(internal, 'Illegal type definition (must be nonvar).\n', [])
	).
static_type_check_rule(F, A) :-
	A=ast_rule(B, _, _, C, _),
	(   catch(( ast_static_type_check_head(B),
		    ast_static_type_check_body(C)
		  ),
		  type_error(D),
		  (   D=invalid_functor(E, G, H)
		  ->  chr_error(type_error,
				'Invalid functor in ~@ of ~@:\n\t\tfound `~w\',\n\t\texpected type `~w\'!\n',
				
				[ chr_translate:format_src(E),
				  format_rule(F),
				  G,
				  H
				])
		  ;   D=type_clash(I, K, M, J, L)
		  ->  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(F),
				  J,
				  chr_translate:format_src(K),
				  L,
				  chr_translate:format_src(M)
				])
		  )),
	    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|E]) :-
	ast_symbol(A, B),
	get_constraint_type_det(B, D),
	ast_args(A, C),
	maplist(ast_static_type_check_term(body(A)), C, D),
	ast_static_type_check_body(E).
format_src(head(A)) :-
	format('head ~w', [A]).
format_src(body(A)) :-
	format('body goal ~w', [A]).
generate_dynamic_type_check_clauses(D) :-
	(   chr_pp_flag(debugable, on)
	->  dynamic_type_check,
	    get_dynamic_type_check_clauses(A),
	    append(A,
		   
		   [ ('$dynamic_type_check'(B, C):-throw(error(type_error(B, C), context(_, 'CHR Runtime Type Error'))))
		   ],
		   D)
	;   D=[]
	).
dynamic_type_check_clause(A, B, J) :-
	copy_term(A-B, K-C),
	functor(C, D, E),
	functor(F, D, E),
	C=..[_|G],
	F=..[_|H],
	maplist(dynamic_type_check_call, G, H, I),
	list2conj(I, L),
	J=('$dynamic_type_check'(K, F):-L).
dynamic_type_check_alias_clause(B, C, A) :-
	A=('$dynamic_type_check'(B, D):-'$dynamic_type_check'(C, D)).
dynamic_type_check_call(A, C, B) :-
	(   A==any
	->  B=true
	;   B=when(nonvar(C), once('$dynamic_type_check'(A, C)))
	).
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, D, C, B) :-
	(   is_indexed_argument(A, B)
	->  (   C==(?)
	    ->  atomic_type(D)
	    ;   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(C, A, B) :-
	(   A>B
	->  stored_completing(C, 1, 0)
	;   check_occurrence_storage(C, A),
	    D is A+1,
	    check_occurrences_storage(C, D, B)
	).
check_occurrence_storage(A, B) :-
	get_occurrence(A, B, C, D, F),
	(   is_passive(C, D)
	->  stored(A, B, maybe)
	;   get_rule(C, E),
	    E=pragma(rule(H, J, K, N), ids(G, L), _, _, _),
	    (   F==simplification,
		select2(D, I, G, H, _, _)
	    ->  check_storage_head1(I, B, H, J, K)
	    ;   F==propagation,
		select2(D, M, L, J, _, _)
	    ->  check_storage_head2(M, B, H, N)
	    )
	).
check_storage_head1(A, I, D, E, F) :-
	functor(A, B, C),
	H=B/C,
	(   D==[A],
	    E==[],
	    guard_entailment:entails_guard([chr_pp_headvariables(A)], F),
	    A=..[_|G],
	    no_matching(G, [])
	->  stored(H, I, no)
	;   stored(H, I, maybe)
	).
no_matching([], _).
no_matching([A|C], B) :-
	var(A),
	\+ memberchk_eq(A, B),
	no_matching(C, [A|B]).
check_storage_head2(A, G, D, E) :-
	functor(A, B, C),
	F=B/C,
	(   D\==[],
	    E==true
	->  stored(F, G, maybe)
	;   stored(F, G, yes)
	).
constraints_code(A, C) :-
	(   chr_pp_flag(reduced_indexing, on),
	    forall(B,
		   A,
		   chr_translate:only_ground_indexed_arguments(B))
	->  none_suspended_on_variables
	;   true
	),
	constraints_code1(A, C, []).
constraint_prelude(B/A, K) :-
	vars_susp(A, C, E, D),
	L=..[B|C],
	make_suspension_continuation_goal(B/A, D, G),
	build_head(B, A, [0], D, Q),
	(   chr_pp_flag(debugable, on)
	->  insert_constraint_goal(B/A, E, C, N),
	    attach_constraint_atom(B/A, F, E, O),
	    delay_phase_end(validate_store_type_assumptions,
			    chr_translate:update_suspension_field(B/A, E, state, inactive, P)),
	    insert_constraint_internal_constraint_goal(B/A,
						       F,
						       E,
						       G,
						       C,
						       M),
	    (   get_constraint_type(B/A, H)
	    ->  maplist(dynamic_type_check_call, H, C, I),
		list2conj(I, J)
	    ;   J=true
	    ),
	    K=(L:-J, M, N, O, P, 'chr debug_event'(insert(#(L, E))), ('chr debugging'->('chr debug_event'(call(E)), Q;'chr debug_event'(fail(E)), !, fail), ('chr debug_event'(exit(E));'chr debug_event'(redo(E)), fail);Q))
	;   get_allocation_occurrence(B/A, 0)
	->  gen_insert_constraint_internal_goal(B/A,
						R,
						D,
						C,
						E),
	    delay_phase_end(validate_store_type_assumptions,
			    chr_translate:update_suspension_field(B/A, E, state, inactive, P)),
	    K=(L:-R, P, Q)
	;   K=(L:-Q)
	).
make_suspension_continuation_goal(A/B, C, D) :-
	(   may_trigger(A/B)
	->  build_head(A, B, [0], C, E),
	    (   chr_pp_flag(debugable, off)
	    ->  D=E
	    ;   get_target_module(F),
		D=F:E
	    )
	;   D=true
	).
gen_cond_attach_clause(A/B, I, L, N) :-
	(   is_finally_stored(A/B)
	->  get_allocation_occurrence(A/B, D),
	    get_max_occurrence(A/B, C),
	    (   chr_pp_flag(debugable, off),
		C<D
	    ->  (   only_ground_indexed_arguments(A/B)
		->  gen_insert_constraint_internal_goal(A/B,
							E,
							F,
							G,
							H)
		;   gen_cond_attach_goal(A/B,
					 E,
					 F,
					 G,
					 H)
		)
	    ;   vars_susp(B, G, H, F),
		gen_uncond_attach_goal(A/B,
				       H,
				       G,
				       E,
				       _)
	    ),
	    build_head(A, B, I, F, J),
	    K=(J:-E),
	    add_dummy_location(K, M),
	    L=[M|N]
	;   L=N
	).
gen_cond_attach_goal(E/A, J, D, B, C) :-
	vars_susp(A, B, C, D),
	make_suspension_continuation_goal(E/A, D, H),
	(   get_store_type(E/A, var_assoc_store(_, _))
	->  F=true
	;   attach_constraint_atom(E/A, G, C, F)
	),
	_=..[E|B],
	insert_constraint_goal(E/A, C, B, I),
	insert_constraint_internal_constraint_goal(E/A,
						   G,
						   C,
						   H,
						   B,
						   K),
	(   may_trigger(E/A)
	->  activate_constraint_goal(E/A,
				     (I, F),
				     G,
				     C,
				     _,
				     L),
	    J=(var(C)->K, I, F;L)
	;   J=(K, I, F)
	).
gen_insert_constraint_internal_goal(E/A, I, D, B, C) :-
	vars_susp(A, B, C, D),
	make_suspension_continuation_goal(E/A, D, H),
	(   \+ only_ground_indexed_arguments(E/A),
	    \+ get_store_type(E/A,
			      var_assoc_store(_, _))
	->  attach_constraint_atom(E/A, G, C, F)
	;   F=true
	),
	_=..[E|B],
	insert_constraint_goal(E/A, C, B, K),
	insert_constraint_internal_constraint_goal(E/A,
						   G,
						   C,
						   H,
						   B,
						   J),
	(   only_ground_indexed_arguments(E/A),
	    chr_pp_flag(debugable, off)
	->  I=(J, K)
	;   I=(J, K, F)
	).
gen_uncond_attach_goal(A, B, D, H, G) :-
	(   \+ only_ground_indexed_arguments(A),
	    \+ get_store_type(A, var_assoc_store(_, _))
	->  attach_constraint_atom(A, F, B, C)
	;   C=true
	),
	insert_constraint_goal(A, B, D, E),
	(   chr_pp_flag(late_allocation, on)
	->  activate_constraint_goal(A,
				     (E, C),
				     F,
				     B,
				     G,
				     H)
	;   activate_constraint_goal(A,
				     true,
				     F,
				     B,
				     G,
				     H)
	).
head1_code(E, H, F, G, A, K, L, M, N, O) :-
	A=pragma(B, _, _, _, D),
	B=rule(_, C, _, _),
	(   C==[]
	->  reorder_heads(D, E, F, G, I, J),
	    simplification_code(E,
				H,
				I,
				J,
				A,
				K,
				L,
				M,
				N,
				O)
	;   simpagation_head1_code(E,
				   H,
				   F,
				   G,
				   A,
				   K,
				   L,
				   M,
				   N,
				   O)
	).
head2_code(E, H, F, G, A, K, L, M, N, O) :-
	A=pragma(B, _, _, _, D),
	B=rule(C, _, _, _),
	(   C==[]
	->  reorder_heads(D, E, F, G, I, J),
	    propagation_code(E,
			     H,
			     I,
			     J,
			     B,
			     D,
			     K,
			     L,
			     M,
			     N,
			     O)
	;   simpagation_head2_code(E,
				   H,
				   F,
				   G,
				   A,
				   K,
				   L,
				   M,
				   N,
				   O)
	).
gen_alloc_inc_clause(B/A, F, C, M, O) :-
	vars_susp(A, G, H, D),
	build_head(B, A, C, D, I),
	inc_id(C, E),
	build_head(B, A, E, D, K),
	gen_occ_allocation(B/A, F, G, H, J),
	L=(I:-J, K),
	add_dummy_location(L, N),
	M=[N|O].
gen_occ_allocation(A, C, G, F, H) :-
	get_allocation_occurrence(A, B),
	get_occurrence_code_id(A, B, E),
	get_occurrence_code_id(A, C, D),
	(   chr_pp_flag(debugable, off),
	    D==E
	->  allocate_constraint_goal(A, F, G, I),
	    (   may_trigger(A)
	    ->  H=(var(F)->I;true)
	    ;   H=I
	    )
	;   H=true
	).
gen_occ_allocation_in_guard(A, B, E, D, F) :-
	get_allocation_occurrence(A, C),
	(   chr_pp_flag(debugable, off),
	    B<C
	->  allocate_constraint_goal(A, D, E, G),
	    (   may_trigger(A)
	    ->  F=(var(D)->G;true)
	    ;   F=G
	    )
	;   F=true
	).
guard_via_reschedule_new(A, B, C, D, E, G) :-
	(   chr_pp_flag(guard_via_reschedule, on)
	->  guard_via_reschedule_main_new(A,
					  B,
					  C,
					  D,
					  E,
					  F),
	    list2conj(F, G)
	;   length(A, H),
	    length(E, H),
	    length(B, I),
	    length(D, I),
	    append(E, D, J),
	    list2conj(J, G)
	).
guard_via_reschedule_main_new(B, C, A, M, I, J) :-
	initialize_unit_dictionary(A, F),
	maplist(wrap_in_functor(lookup), B, D),
	maplist(wrap_in_functor(guard), C, E),
	build_units(D, E, F, G),
	dependency_reorder(G, H),
	wrappedunits2lists(H, K, I, J),
	sort(K, L),
	snd_of_pairs(L, M).
wrappedunits2lists([], [], [], []).
wrappedunits2lists([unit(G, B, _, _)|J], E, C, A) :-
	A=[D|K],
	(   B=lookup(F)
	->  C=[D|I],
	    E=H
	;   B=guard(F)
	->  E=[G-D|H],
	    C=I
	),
	wrappedunits2lists(J, H, I, K).
guard_splitting(A, I) :-
	A=rule(B, C, D, _),
	append(B, C, E),
	conj2list(D, F),
	term_variables(E, G),
	split_off_simple_guard_new(F, G, H, J),
	append(H, [Q], I),
	term_variables(J, M),
	ground_vars(E, K),
	list_difference_eq(G, K, L),
	intersect_eq(L, M, N),
	maplist(chr_lock, N, O),
	maplist(chr_unlock, N, P),
	list2conj(O, R),
	list2conj(P, T),
	list2conj(J, S),
	Q=(R, S, T).
guard_body_copies3(A, B, C, D, G) :-
	A=rule(_, _, _, E),
	my_term_copy(B, C, F, D),
	my_term_copy(E, F, G).
split_off_simple_guard_new([], _, [], []).
split_off_simple_guard_new([A|D], B, C, F) :-
	(   simple_guard_new(A, B)
	->  C=[A|E],
	    split_off_simple_guard_new(D, B, E, F)
	;   C=[],
	    F=[A|D]
	).
simple_guard_new(A, D) :-
	builtin_binds_b(A, B),
	not(( member(C, B),
	      memberchk_eq(C, D)
	    )).
dependency_reorder(A, B) :-
	dependency_reorder(A, [], B).
dependency_reorder([], A, B) :-
	reverse(A, B).
dependency_reorder([A|F], C, G) :-
	A=unit(_, _, B, D),
	(   B==fixed
	->  E=[A|C]
	;   dependency_insert(C, A, D, E)
	),
	dependency_reorder(F, E, G).
dependency_insert([], A, _, [A]).
dependency_insert([A|F], E, C, D) :-
	A=unit(B, _, _, _),
	(   memberchk(B, C)
	->  D=[E, A|F]
	;   D=[A|G],
	    dependency_insert(F, E, C, G)
	).
build_units(A, D, B, C) :-
	build_retrieval_units(A,
			      1,
			      E,
			      B,
			      F,
			      C,
			      G),
	build_guard_units(D, E, F, G).
build_retrieval_units([], A, A, B, B, C, C).
build_retrieval_units([A|G], C, I, D, K, E, M) :-
	term_variables(A, B),
	update_unit_dictionary(B, C, D, J, [], F),
	E=[unit(C, A, fixed, F)|L],
	H is C+1,
	build_retrieval_units(G,
			      H,
			      I,
			      J,
			      K,
			      L,
			      M).
initialize_unit_dictionary(A, C) :-
	term_variables(A, B),
	pair_all_with(B, 0, C).
update_unit_dictionary([], _, A, A, B, B).
update_unit_dictionary([B|H], D, A, I, E, J) :-
	(   lookup_eq(A, B, C)
	->  (   (   C==D
		;   memberchk(C, E)
		)
	    ->  F=E
	    ;   F=[C|E]
	    ),
	    G=A
	;   G=[B-D|A],
	    F=E
	),
	update_unit_dictionary(H,
			       D,
			       G,
			       I,
			       F,
			       J).
build_guard_units(A, C, F, B) :-
	(   A=[D]
	->  B=[unit(C, D, fixed, [])]
	;   A=[D|H]
	->  term_variables(D, E),
	    update_unit_dictionary2(E,
				    C,
				    F,
				    J,
				    [],
				    G),
	    B=[unit(C, D, movable, G)|K],
	    I is C+1,
	    build_guard_units(H, I, J, K)
	).
update_unit_dictionary2([], _, A, A, B, B).
update_unit_dictionary2([B|H], D, A, I, E, J) :-
	(   lookup_eq(A, B, C)
	->  (   (   C==D
		;   memberchk(C, E)
		)
	    ->  F=E
	    ;   F=[C|E]
	    ),
	    G=[B-D|A]
	;   G=[B-D|A],
	    F=E
	),
	update_unit_dictionary2(H,
				D,
				G,
				I,
				F,
				J).
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|F]) :-
	(   discover_unique_pattern(A, B, C, D, E)
	->  functional_dependency(B, C, D, E)
	;   true
	),
	functional_dependency_analysis_main(F).
discover_unique_pattern(A, P/Q, B, N, O) :-
	A=pragma(C, _, _, _, B),
	C=rule(D, E, H, _),
	(   D=[F],
	    E=[G]
	->  true
	;   D=[F, G],
	    E==[]
	->  true
	),
	check_unique_constraints(F, G, H, B, J),
	term_variables(F, I),
	\+ ( member(K, I),
	     lookup_eq(J, K, L),
	     memberchk_eq(L, I)
	   ),
	select_pragma_unique_variables(I, J, M),
	copy_term_nat(F-M, N-O),
	functor(F, P, Q).
select_pragma_unique_variables([], _, []).
select_pragma_unique_variables([B|E], A, C) :-
	(   lookup_eq(A, B, _)
	->  C=D
	;   C=[B|D]
	),
	select_pragma_unique_variables(E, A, D).
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([F], [K], true, _),
	    C=ids([E], [N]),
	    \+ is_passive(D, E),
	    functor(F, G, H),
	    get_functional_dependency(G/H,
				      D,
				      I,
				      J),
	    copy_term_nat(I-J, F-L),
	    copy_term_nat(I-J, K-M),
	    L==M
	->  passive(D, N)
	;   true
	).
check_unique_constraints(B, C, E, A, D) :-
	\+ any_passive_head(A),
	variable_replacement(B-C, C-B, D),
	copy_with_variable_replacement(E, G, D),
	negate_b(E, F),
	once(entails_b(F, G)).
symmetry_analysis(A) :-
	(   chr_pp_flag(check_unnecessary_active, off)
	->  true
	;   symmetry_analysis_main(A)
	).
symmetry_analysis_main([]).
symmetry_analysis_main([A|H]) :-
	A=pragma(B, ids(E, G), _, _, F),
	B=rule(D, C, _, _),
	(   (   \+ chr_pp_flag(check_unnecessary_active, simplification)
	    ;   C==[]
	    ),
	    D\==[]
	->  symmetry_analysis_heads_simplification(D,
						   E,
						   [],
						   [],
						   B,
						   F),
	    symmetry_analysis_heads_propagation(C,
						G,
						[],
						[],
						B,
						F)
	;   true
	),
	symmetry_analysis_main(H).
symmetry_analysis_heads_simplification([], [], _, _, _, _).
symmetry_analysis_heads_simplification([G|K], [B|L], C, D, H, A) :-
	(   \+ is_passive(A, B),
	    member2(C, D, F-E),
	    \+ is_passive(A, E),
	    variable_replacement(F, G, I),
	    copy_with_variable_replacement(H, J, I),
	    identical_guarded_rules(H, J)
	->  passive(A, B)
	;   true
	),
	symmetry_analysis_heads_simplification(K,
					       L,
					       [G|C],
					       [B|D],
					       H,
					       A).
symmetry_analysis_heads_propagation([], [], _, _, _, _).
symmetry_analysis_heads_propagation([G|K], [B|L], C, D, H, A) :-
	(   \+ is_passive(A, B),
	    member2(C, D, F-E),
	    \+ is_passive(A, E),
	    variable_replacement(F, G, I),
	    copy_with_variable_replacement(H, J, I),
	    identical_rules(H, J)
	->  passive(A, B)
	;   true
	),
	symmetry_analysis_heads_propagation(K,
					    L,
					    [G|C],
					    [B|D],
					    H,
					    A).
simplification_code(B, B1, L, M, A, C, S, D, Q1, S1) :-
	A=pragma(H, _, _, _, I),
	head_info1(B, C, _, T, E, F),
	build_head(C, D, E, J1),
	get_constraint_mode(C, G),
	head_arg_matches(F, G, [], K1, O, [], P),
	guard_splitting(H, J),
	(   is_stored_in_guard(C, I)
	->  K=[_|J]
	;   K=J
	),
	guard_via_reschedule_new(L,
				 K,
				 B,
				 R,
				 N,
				 L1),
	rest_heads_retrieval_and_matching(L,
					  M,
					  B,
					  N,
					  Y,
					  O,
					  Q,
					  [],
					  [],
					  [],
					  P,
					  _),
	guard_body_copies3(H, K, Q, R, O1),
	(   is_stored_in_guard(C, I)
	->  gen_occ_allocation_in_guard(C,
					S,
					U,
					T,
					W),
	    gen_uncond_attach_goal(C, T, U, X, _),
	    R=[V|_],
	    V=(W, X)
	;   true
	),
	partner_constraint_detachments(Y, L, Q, M1),
	active_constraint_detachment(D,
				     T,
				     B,
				     Q,
				     N1),
	(   chr_pp_flag(debugable, on)
	->  H=rule(_, _, Z, A1),
	    my_term_copy(Z-A1, Q, D1-E1),
	    sort_by_key([T|Y], [B1|M], C1),
	    F1='chr debug_event'(try(C1, [], D1, E1)),
	    G1='chr debug_event'(apply(C1, [], D1, E1)),
	    instrument_goal(I1, F1, G1, H1)
	;   H1=I1
	),
	actual_cut(C, S, I1),
	P1=(J1:-K1, L1, H1, M1, N1, O1),
	add_location(P1, I, R1),
	Q1=[R1|S1].
actual_cut(A, B, C) :-
	(   unconditional_occurrence(A, B),
	    chr_pp_flag(late_allocation, on)
	->  C=true
	;   C=!
	).
add_location(E, A, B) :-
	(   chr_pp_flag(line_numbers, on)
	->  get_chr_source_file(C),
	    get_line_number(A, D),
	    B='$source_location'(C, D):E
	;   B=E
	).
add_dummy_location(C, A) :-
	(   chr_pp_flag(line_numbers, on)
	->  get_chr_source_file(B),
	    A='$source_location'(B, 1):C
	;   A=C
	).
head_arg_matches(A, B, C, D, E) :-
	head_arg_matches(A, B, C, D, E, [], _).
head_arg_matches(A, B, C, H, E, D, F) :-
	head_arg_matches_(A,
			  B,
			  C,
			  D,
			  G,
			  E,
			  F),
	list2conj(G, H).
head_arg_matches_([], [], A, B, [], A, B).
head_arg_matches_([silent(B-_)|D], [A|E], F, C, H, I, J) :- !,
	(   A==(+)
	->  term_variables(B, G, C),
	    head_arg_matches_(D,
			      E,
			      F,
			      G,
			      H,
			      I,
			      J)
	;   head_arg_matches_(D,
			      E,
			      F,
			      C,
			      H,
			      I,
			      J)
	).
head_arg_matches_([A-F|K], [C|L], B, D, E, Z, A1) :-
	(   var(A)
	->  (   lookup_eq(B, A, G)
	    ->  (   C=(+)
		->  (   memberchk_eq(A, D)
		    ->  E=[F=G|H],
			I=D
		    ;   E=[F==G|H],
			I=[A|D]
		    )
		;   E=[F==G|H],
		    I=D
		),
		J=B
	    ;   J=[A-F|B],
		E=H,
		(   C=(+)
		->  I=[A|D]
		;   I=D
		)
	    ),
	    P=K,
	    Q=L
	;   ground(A),
	    A='$chr_identifier_match'(N, M)
	->  identifier_label_atom(M, F, N, O),
	    E=[O|H],
	    B=J,
	    I=D,
	    P=K,
	    Q=L
	;   atomic(A)
	->  (   C=(+)
	    ->  E=[F=A|H]
	    ;   E=[F==A|H]
	    ),
	    B=J,
	    I=D,
	    P=K,
	    Q=L
	;   C==(+),
	    is_ground(D, A)
	->  copy_with_variable_replacement(A, R, B),
	    E=[F=R|H],
	    B=J,
	    I=D,
	    P=K,
	    Q=L
	;   C==(?),
	    is_ground(D, A)
	->  copy_with_variable_replacement(A, R, B),
	    E=[F==R|H],
	    B=J,
	    I=D,
	    P=K,
	    Q=L
	;   A=..[_|V],
	    functor(A, S, T),
	    functor(U, S, T),
	    U=..[_|W],
	    (   C=(+)
	    ->  E=[F=U|H]
	    ;   E=[nonvar(F), F=U|H]
	    ),
	    pairup(V, W, X),
	    append(X, K, P),
	    replicate(T, C, Y),
	    append(Y, L, Q),
	    J=B,
	    I=D
	),
	head_arg_matches_(P,
			  Q,
			  J,
			  I,
			  H,
			  Z,
			  A1).
add_heads_types([], A, A).
add_heads_types([A|C], B, E) :-
	add_head_types(A, B, D),
	add_heads_types(C, D, E).
add_head_types(A, F, G) :-
	functor(A, B, C),
	get_constraint_type_det(B/C, E),
	A=..[_|D],
	add_args_types(D, E, F, G).
add_args_types([], [], A, A).
add_args_types([A|D], [B|E], C, G) :-
	add_arg_types(A, B, C, F),
	add_args_types(D, E, F, G).
add_arg_types(D, A, C, B) :-
	(   A==any
	->  B=C
	;   var(D)
	->  (   lookup_eq(C, D, _)
	    ->  B=C
	    ;   B=[D-A|C]
	    )
	;   B=C
	).
add_heads_ground_variables([], A, A).
add_heads_ground_variables([A|C], B, E) :-
	add_head_ground_variables(A, B, D),
	add_heads_ground_variables(C, D, E).
add_head_ground_variables(A, F, G) :-
	functor(A, B, C),
	get_constraint_mode(B/C, E),
	A=..[_|D],
	add_arg_ground_variables(D, E, F, G).
add_arg_ground_variables([], [], A, A).
add_arg_ground_variables([B|F], [A|G], D, H) :-
	(   A==(+)
	->  term_variables(B, C),
	    add_var_ground_variables(C, D, E)
	;   D=E
	),
	add_arg_ground_variables(F, G, E, H).
add_var_ground_variables([], A, A).
add_var_ground_variables([A|D], B, E) :-
	(   memberchk_eq(A, B)
	->  C=B
	;   C=[A|B]
	),
	add_var_ground_variables(D, C, E).
is_ground(B, A) :-
	(   ground(A)
	->  true
	;   compound(A)
	->  A=..[_|C],
	    maplist(is_ground(B), C)
	;   memberchk_eq(A, B)
	).
check_ground(C, A, D) :-
	term_variables(A, B),
	check_ground_variables(B, C, D).
check_ground_variables([], _, true).
check_ground_variables([A|C], B, D) :-
	(   memberchk_eq(A, B)
	->  check_ground_variables(C, B, D)
	;   D=(ground(A), E),
	    check_ground_variables(C, B, 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, E, F, G, H, I, C, D, J, K, L) :-
	(   A=[_|_]
	->  rest_heads_retrieval_and_matching_n(A,
						B,
						C,
						D,
						E,
						F,
						G,
						H,
						I,
						J,
						K,
						L)
	;   F=[],
	    G=[],
	    H=I,
	    K=L
	).
rest_heads_retrieval_and_matching_n([], _, _, _, _, [], [], A, A, _, B, B).
rest_heads_retrieval_and_matching_n([A|E1], [_|F1], F, B1, E, [C1|G1], [M|H1], G, I1, _, L, J1) :-
	functor(A, C, B),
	head_info(A, B, I, _, _, J),
	get_store_type(C/B, D),
	(   D==default
	->  passive_head_via(A,
			     [E|F],
			     G,
			     O,
			     N),
	    delay_phase_end(validate_store_type_assumptions,
			    (static_suspension_term(C/B, H), get_static_suspension_term_field(arguments, C/B, H, I), get_static_suspension_field(C/B, H, state, active, Q))),
	    get_constraint_mode(C/B, K),
	    head_arg_matches(J,
			     K,
			     G,
			     R,
			     V,
			     L,
			     W),
	    T=J,
	    sbag_member_call(M, N, P),
	    S=(O, P, M=H, Q),
	    inline_matching_goal(R, Y)
	;   delay_phase_end(validate_store_type_assumptions,
			    (static_suspension_term(C/B, H), get_static_suspension_term_field(arguments, C/B, H, I))),
	    existential_lookup(D,
			       A,
			       [E|F],
			       G,
			       L,
			       H,
			       S,
			       M,
			       J,
			       T),
	    get_constraint_mode(C/B, K),
	    U=K,
	    head_arg_matches(T,
			     U,
			     G,
			     R,
			     V,
			     L,
			     W),
	    filter_append(T, V, X),
	    translate(W, X, Z),
	    translate(W, V, A1),
	    inline_matching_goal(R, Y, Z, A1)
	),
	different_from_other_susps(A, M, F, B1, D1),
	C1=(S, D1, Y),
	rest_heads_retrieval_and_matching_n(E1,
					    F1,
					    [A|F],
					    [M|B1],
					    E,
					    G1,
					    H1,
					    V,
					    I1,
					    _,
					    W,
					    J1).
inline_matching_goal(A, B) :-
	inline_matching_goal(A, B, [], []).
inline_matching_goal(A==C, true, B, D) :-
	memberchk_eq(A, B),
	memberchk_eq(C, D),
	A=C, !.
inline_matching_goal((A, E),  (B, F), C, D) :- !,
	inline_matching_goal(A, B, C, D),
	inline_matching_goal(E, F, C, D).
inline_matching_goal(A, A, _, _).
filter_mode([], _, _, []).
filter_mode([I-A|E], [_-B|F], [D|G], C) :-
	(   A==B
	->  C=[D|H],
	    filter_mode(E, F, G, H)
	;   filter_mode([I-A|E], F, G, C)
	).
filter_append([], A, A).
filter_append([A|B], C, D) :-
	(   A=silent(_)
	->  filter_append(B, C, D)
	;   D=[A|E],
	    filter_append(B, C, E)
	).
check_unique_keys([], _).
check_unique_keys([B|C], A) :-
	lookup_eq(A, B, _),
	check_unique_keys(C, A).
different_from_other_susps(C, D, A, B, F) :-
	different_from_other_susps_(A, B, C, D, E),
	list2conj(E, F).
different_from_other_susps_(_, [], _, _, []) :- !.
different_from_other_susps_([B|K], [I|L], A, H, G) :-
	(   functor(A, C, D),
	    functor(B, C, D),
	    copy_term_nat(B-A, E-F),
	    \+ \+ E=F
	->  G=[H\==I|J]
	;   G=J
	),
	different_from_other_susps_(K, L, A, H, J).
passive_head_via(A, D, P, I, H) :-
	functor(A, B, C),
	get_constraint_index(B/C, _),
	common_variables(A, D, E),
	ground_vars([A], F),
	list_difference_eq(E, F, K),
	global_list_store_name(B/C, G),
	J=nb_getval(G, H),
	get_constraint_mode(B/C, L),
	(   S==[]
	->  I=J
	;   member(O, K),
	    nth1(M, L, -),
	    arg(M, A, N),
	    N==O
	->  translate([O], P, [Q]),
	    gen_get_mod_constraints(B/C,
				    Q,
				    R,
				    H),
	    I=R
	;   translate(K, P, S),
	    add_heads_types(D, [], T),
	    my_term_copy(T, P, U),
	    gen_get_mod_constraints(B/C,
				    S,
				    U,
				    V,
				    R,
				    H),
	    I=(V->R;J)
	).
common_variables(A, B, E) :-
	term_variables(A, C),
	term_variables(B, D),
	intersect_eq(C, D, E).
gen_get_mod_constraints(K, A, B, C, D, I) :-
	via_goal(A, B, C, E),
	get_target_module(F),
	D=(get_attr(E, F, J), H),
	get_max_constraint_index(G),
	(   G==1
	->  H=true,
	    I=J
	;   get_constraint_index(K, L),
	    get_suspensions(G, L, J, H, I)
	).
via_goal(A, C, B, F) :-
	(   A=[]
	->  B=fail
	;   A=[D]
	->  lookup_type(C, D, E),
	    (   atomic_type(E)
	    ->  B=var(D),
		D=F
	    ;   B='chr newvia_1'(D, F)
	    )
	;   A=[D, G]
	->  B='chr newvia_2'(D, G, F)
	;   B='chr newvia'(A, F)
	).
lookup_type(A, B, C) :-
	(   lookup_eq(A, B, C)
	->  true
	;   C=any
	).
gen_get_mod_constraints(H, B, A, F) :-
	get_target_module(C),
	A=(get_attr(B, C, G), E),
	get_max_constraint_index(D),
	(   D==1
	->  E=true,
	    F=G
	;   get_constraint_index(H, I),
	    get_suspensions(D, I, G, E, F)
	).
guard_body_copies(A, B, E, C) :-
	guard_body_copies2(A, B, D, C),
	list2conj(D, E).
guard_body_copies2(A, D, H, B1) :-
	A=rule(_, J, B, Z),
	conj2list(B, C),
	split_off_simple_guard(C, D, E, F),
	my_term_copy(E-F, D, A1, G-I),
	append(G, [V], H),
	term_variables(F, K),
	term_variables(I, P),
	ground_vars(J, L),
	list_difference_eq(K, L, N),
	(   chr_pp_flag(guard_locks, off)
	->  S=[],
	    T=[]
	;   bagof(Q-R,
		  M^O^(lists:member(M, N), pairlist:lookup_eq(D, M, O), memberchk_eq(O, P), chr_lock(O, Q), chr_unlock(O, R)),
		  U)
	->  once(pairup(S, T, U))
	;   S=[],
	    T=[]
	),
	list2conj(S, W),
	list2conj(T, Y),
	list2conj(I, X),
	V=(W, X, Y),
	my_term_copy(Z, A1, B1).
split_off_simple_guard([], _, [], []).
split_off_simple_guard([A|D], B, C, F) :-
	(   simple_guard(A, B)
	->  C=[A|E],
	    split_off_simple_guard(D, B, E, F)
	;   C=[],
	    F=[A|D]
	).
simple_guard(A, C) :-
	binds_b(A, B),
	\+ ( member(D, B),
	     lookup_eq(C, D, _)
	   ).
active_constraint_detachment(E, I, A, J, H) :-
	functor(A, B, C),
	D=B/C,
	(   is_stored(D)
	->  (   (   E==[0],
		    chr_pp_flag(store_in_guards, off)
		;   get_allocation_occurrence(D, G),
		    get_max_occurrence(D, F),
		    F<G
		),
		only_ground_indexed_arguments(D),
		chr_pp_flag(late_allocation, on)
	    ->  H=true
	    ;   gen_uncond_susp_detachment(A,
					   I,
					   active,
					   J,
					   K),
		(   chr_pp_flag(late_allocation, on)
		->  H=(var(I)->true;K)
		;   H=K
		)
	    )
	;   H=true
	).
partner_constraint_detachments([], [], _, true).
partner_constraint_detachments([B|E], [A|F], C,  (D, G)) :-
	gen_uncond_susp_detachment(A, B, partner, C, D),
	partner_constraint_detachments(E, F, C, G).
gen_uncond_susp_detachment(A, G, H, J, E) :-
	functor(A, B, C),
	D=B/C,
	(   is_stored(D)
	->  E=(F, I),
	    (   chr_pp_flag(debugable, on)
	    ->  F='chr debug_event'(remove(G))
	    ;   F=true
	    ),
	    remove_constraint_goal(D,
				   G,
				   L,
				   true,
				   (K, M),
				   H,
				   I),
	    delete_constraint_goal(A, G, J, K),
	    (   \+ only_ground_indexed_arguments(D),
		\+ get_store_type(D, var_assoc_store(_, _))
	    ->  detach_constraint_atom(D, L, G, M)
	    ;   M=true
	    )
	;   E=true
	).
simpagation_head1_code(C, J1, J, L, A, E/D, _, H, A2, C2) :-
	A=pragma(B, ids(_, M), _, _, N),
	B=rule(_, K, H1, I1),
	head_info(C, D, B1, A1, I, F),
	get_constraint_mode(E/D, G),
	head_arg_matches(F, G, [], U1, V, [], W),
	build_head(E, D, H, I, T1),
	append(J, K, O),
	append(L, M, P),
	reorder_heads(N, C, O, P, S, T),
	guard_splitting(B, Q),
	(   is_stored_in_guard(E/D, N)
	->  R=[_|Q]
	;   R=Q
	),
	guard_via_reschedule_new(S,
				 R,
				 C,
				 Z,
				 U,
				 V1),
	rest_heads_retrieval_and_matching(S,
					  T,
					  C,
					  U,
					  X,
					  V,
					  Y,
					  [],
					  [],
					  [],
					  W,
					  _),
	split_by_ids(T,
		     X,
		     L,
		     E1,
		     F1,
		     K1,
		     L1),
	guard_body_copies3(B, R, Y, Z, Y1),
	(   is_stored_in_guard(E/D, N)
	->  gen_uncond_attach_goal(E/D,
				   A1,
				   B1,
				   D1,
				   _),
	    Z=[C1|_],
	    C1=D1
	;   true
	),
	sort_by_key(E1, F1, G1),
	partner_constraint_detachments(G1, J, Y, W1),
	active_constraint_detachment(H,
				     A1,
				     C,
				     Y,
				     X1),
	(   chr_pp_flag(debugable, on)
	->  my_term_copy(H1-I1, Y, O1-P1),
	    sort_by_key([A1|E1], [J1|F1], M1),
	    sort_by_key(K1, L1, N1),
	    Q1='chr debug_event'(try(M1, N1, O1, P1)),
	    R1='chr debug_event'(apply(M1, N1, O1, P1)),
	    instrument_goal(!, Q1, R1, S1)
	;   S1=!
	),
	Z1=(T1:-U1, V1, S1, W1, X1, Y1),
	add_location(Z1, N, B2),
	A2=[B2|C2].
split_by_ids([], [], _, [], []).
split_by_ids([A|H], [D|I], B, C, E) :-
	(   memberchk_eq(A, B)
	->  C=[D|F],
	    E=G
	;   C=F,
	    E=[D|G]
	),
	split_by_ids(H, I, B, F, G).
split_by_ids([], [], _, [], [], [], []).
split_by_ids([A|L], [D|M], B, C, E, F, G) :-
	(   memberchk_eq(A, B)
	->  C=[D|H],
	    E=[A|I],
	    F=J,
	    G=K
	;   C=H,
	    E=I,
	    F=[D|J],
	    G=[A|K]
	),
	split_by_ids(L,
		     M,
		     B,
		     H,
		     I,
		     J,
		     K).
simpagation_head2_code(H, C1, D, F, A, O, P, Q, R, E1) :-
	A=pragma(B, ids(E, T), _, _, G),
	B=rule(C, _, M, N),
	append(C, D, I),
	append(E, F, J),
	reorder_heads(G,
		      H,
		      I,
		      J,
		      [K|L],
		      [S|U]),
	simpagation_head2_prelude(H,
				  K,
				  [L, M, N],
				  O,
				  P,
				  Q,
				  R,
				  W),
	extend_id(Q, V),
	(   memberchk_eq(S, T)
	->  simpagation_universal_searches(L,
					   U,
					   T,
					   [K, H],
					   B,
					   O,
					   P,
					   Z,
					   A1,
					   B1,
					   V,
					   Y,
					   W,
					   X)
	;   W=X,
	    V=Y,
	    Z=L,
	    A1=[K, H],
	    B1=U
	),
	universal_search_iterator_end(A1,
				      Z,
				      B,
				      O,
				      P,
				      Y,
				      X,
				      D1),
	simpagation_head2_worker(A1,
				 Z,
				 B1,
				 C1,
				 A,
				 O,
				 P,
				 Y,
				 D1,
				 E1).
simpagation_universal_searches([], [], _, A, _, _, _, [], A, [], B, B, C, C).
simpagation_universal_searches(A, [I|L], J, C, D, E, F, N, O, P, B, R, G, T) :-
	A=[M|K],
	inc_id(B, Q),
	universal_search_iterator_end(C,
				      A,
				      D,
				      E,
				      F,
				      B,
				      G,
				      H),
	universal_search_iterator(A,
				  C,
				  D,
				  E,
				  F,
				  B,
				  H,
				  S),
	(   memberchk_eq(I, J)
	->  simpagation_universal_searches(K,
					   L,
					   J,
					   [M|C],
					   D,
					   E,
					   F,
					   N,
					   O,
					   P,
					   Q,
					   R,
					   S,
					   T)
	;   R=Q,
	    S=T,
	    N=K,
	    O=[M|C],
	    L=P
	).
simpagation_head2_prelude(A, H, N, C/B, K, D, Y, A1) :-
	head_info(A, B, L, M, E, F),
	build_head(C, B, D, E, S),
	get_constraint_mode(C/B, G),
	head_arg_matches(F, G, [], T, I, [], J),
	lookup_passive_head(H,
			    [A],
			    I,
			    J,
			    U,
			    O),
	gen_occ_allocation(C/B,
			   K,
			   L,
			   M,
			   V),
	extend_id(D, Q),
	extra_active_delegate_variables(A,
					[H|N],
					I,
					P),
	append([O|E], P, R),
	build_head(C, B, [K|Q], R, W),
	X=(S:-T, U, !, V, W),
	add_dummy_location(X, Z),
	Y=[Z|A1].
extra_active_delegate_variables(A, B, C, E) :-
	A=..[_|D],
	delegate_variables(A, B, C, D, E).
passive_delegate_variables(B, A, C, D, F) :-
	term_variables(A, E),
	delegate_variables(B, C, D, E, F).
delegate_variables(A, B, H, F, I) :-
	term_variables(A, C),
	term_variables(B, D),
	intersect_eq(C, D, E),
	list_difference_eq(E, F, G),
	translate(G, H, I).
simpagation_head2_worker([D|C], E, D1, _, A, V/W, X, Y, L2, N2) :-
	A=pragma(B, ids(H1, _), D2, _, A1),
	B=rule(_, _, F, G),
	get_prop_inner_loop_vars(C,
				 [D, E, F, G],
				 U,
				 N,
				 O1,
				 P1,
				 P),
	gen_var(J),
	gen_var(T),
	functor(D, K, H),
	gen_vars(H, I),
	head_info(D, H, I, J, _, L),
	get_constraint_mode(K/H, M),
	head_arg_matches(L,
			 M,
			 N,
			 S,
			 F1,
			 [],
			 _),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(K/H, O), get_static_suspension_field(K/H, O, state, active, Q), get_static_suspension_term_field(arguments, K/H, O, I))),
	different_from_other_susps(D, J, C, P, R),
	G2=(J=O, Q, R, S),
	Z=[[J|T]|U],
	build_head(V, W, [X|Y], Z, F2),
	guard_splitting(B, B1),
	(   is_stored_in_guard(V/W, A1)
	->  C1=[_|B1]
	;   C1=B1
	),
	guard_via_reschedule_new(E,
				 C1,
				 [D|C],
				 N1,
				 E1,
				 H2),
	rest_heads_retrieval_and_matching(E,
					  D1,
					  [D|C],
					  E1,
					  G1,
					  F1,
					  K1,
					  [D|C],
					  [J|P],
					  []),
	split_by_ids(D1, G1, H1, I1, W1),
	split_by_ids(D1, E, H1, J1, _),
	partner_constraint_detachments([J|I1],
				       [D|J1],
				       K1,
				       I2),
	L1=[T|U],
	build_head(V, W, [X|Y], L1, Q1),
	M1=[[]|U],
	build_head(V, W, [X|Y], M1, S1),
	guard_body_copies3(B, C1, K1, N1, J2),
	(   is_stored_in_guard(V/W, A1)
	->  N1=[B2|_]
	;   true
	),
	(   is_observed(V/W, X)
	->  gen_uncond_attach_goal(V/W,
				   O1,
				   P1,
				   T1,
				   R1),
	    gen_state_cond_call(O1,
				V/W,
				Q1,
				R1,
				U1),
	    gen_state_cond_call(O1,
				V/W,
				S1,
				R1,
				V1)
	;   T1=true,
	    U1=Q1,
	    V1=S1
	),
	(   chr_pp_flag(debugable, on)
	->  my_term_copy(F-G, N, X1-Y1),
	    Z1='chr debug_event'(try([J|I1], [O1|W1], X1, Y1)),
	    A2='chr debug_event'(apply([J|I1], [O1|W1], X1, Y1))
	;   Z1=true,
	    A2=true
	),
	(   is_stored_in_guard(V/W, A1)
	->  B2=T1,
	    C2=true
	;   B2=true,
	    C2=T1
	),
	(   member(unique(_, E2), D2),
	    check_unique_keys(E2, N)
	->  K2=(F2:-G2->(H2, Z1->A2, I2, C2, J2, V1;S1);Q1)
	;   K2=(F2:-G2, H2, Z1->A2, I2, C2, J2, U1;Q1)
	),
	add_location(K2, A1, M2),
	L2=[M2|N2].
gen_state_cond_call(B, A, J, D, I) :-
	(   may_trigger(A)
	->  does_use_field(A, generation),
	    delay_phase_end(validate_store_type_assumptions,
			    (static_suspension_term(A, C), get_update_static_suspension_field(A, B, C, state, active, inactive, E, F), get_static_suspension_field(A, C, generation, D, H), get_static_suspension_term_field(arguments, A, C, G)))
	;   delay_phase_end(validate_store_type_assumptions,
			    (static_suspension_term(A, C), get_update_static_suspension_field(A, B, C, state, active, inactive, E, F), get_static_suspension_term_field(arguments, A, C, G))),
	    H=true
	),
	I=(B=C, E, H->F, J;true).
propagation_code(B, C, A, K, D, E, F, G, H, I, J) :-
	(   A==[]
	->  propagation_single_headed(B,
				      C,
				      D,
				      E,
				      F,
				      G,
				      H,
				      I,
				      J)
	;   propagation_multi_headed(B,
				     A,
				     K,
				     D,
				     E,
				     F,
				     G,
				     H,
				     I,
				     J)
	).
propagation_single_headed(A, _, I, V, C/B, L, D, R1, T1) :-
	head_info(A, B, W, O, E, G),
	build_head(C, B, D, E, M1),
	inc_id(D, F),
	build_head(C, B, F, E, K),
	get_constraint_mode(C/B, H),
	head_arg_matches(G, H, [], N1, J, [], _),
	guard_body_copies(I, J, O1, P1),
	C1=K,
	actual_cut(C/B, L, R),
	I=rule(_, _, M, N),
	(   chr_pp_flag(debugable, on)
	->  my_term_copy(M-N, J, P-Q),
	    S='chr debug_event'(try([], [O], P, Q)),
	    T='chr debug_event'(apply([], [O], P, Q)),
	    instrument_goal(R, S, T, U)
	;   U=R
	),
	(   may_trigger(C/B),
	    \+ has_no_history(V)
	->  use_auxiliary_predicate(novel_production),
	    use_auxiliary_predicate(extend_history),
	    does_use_history(C/B, L),
	    gen_occ_allocation(C/B,
			       L,
			       W,
			       O,
			       G1),
	    (   named_history(V, Y, X)
	    ->  (   X==[]
		->  empty_named_history_novel_production(Y, A1),
		    empty_named_history_extend_history(Y, B1)
		;   Z=Y
		)
	    ;   Z=V
	    ),
	    (   var(A1)
	    ->  A1='$novel_production'(O, Z),
		B1='$extend_history'(O, Z)
	    ;   true
	    ),
	    (   is_observed(C/B, L)
	    ->  gen_uncond_attach_goal(C/B,
				       O,
				       W,
				       E1,
				       D1),
		gen_state_cond_call(O,
				    C/B,
				    C1,
				    D1,
				    F1)
	    ;   E1=true,
		F1=C1
	    )
	;   G1=true,
	    A1=true,
	    B1=true,
	    (   is_observed(C/B, L)
	    ->  get_allocation_occurrence(C/B, H1),
		(   L==H1
		->  gen_insert_constraint_internal_goal(C/B,
							E1,
							E,
							W,
							O),
		    D1=0
		;   E1=(I1, J1),
		    gen_occ_allocation(C/B,
				       L,
				       W,
				       O,
				       I1),
		    gen_uncond_attach_goal(C/B,
					   O,
					   W,
					   J1,
					   D1)
		),
		gen_state_cond_call(O,
				    C/B,
				    C1,
				    D1,
				    F1)
	    ;   gen_occ_allocation(C/B,
				   L,
				   W,
				   O,
				   E1),
		F1=C1
	    )
	),
	(   is_stored_in_guard(C/B, V)
	->  K1=E1,
	    L1=true
	;   K1=true,
	    L1=E1
	),
	Q1=(M1:-N1, G1, A1, K1, O1, U, B1, L1, P1, F1),
	add_location(Q1, V, S1),
	R1=[S1|T1].
propagation_multi_headed(B, A, J, C, K, D, E, F, G, N) :-
	A=[I|H],
	propagation_prelude(B,
			    A,
			    C,
			    D,
			    E,
			    F,
			    G,
			    M),
	extend_id(F, L),
	propagation_nested_code(H,
				[I, B],
				J,
				C,
				K,
				D,
				E,
				L,
				M,
				N).
propagation_prelude(A, [I|J], H, C/B, O, D, C1, E1) :-
	head_info(A, B, P, Q, E, F),
	build_head(C, B, D, E, W),
	get_constraint_mode(C/B, G),
	head_arg_matches(F, G, [], X, M, [], N),
	H=rule(_, _, K, L),
	extra_active_delegate_variables(A,
					[I, J, K, L],
					M,
					S),
	lookup_passive_head(I,
			    [A],
			    M,
			    N,
			    Y,
			    R),
	gen_occ_allocation(C/B,
			   O,
			   P,
			   Q,
			   Z),
	extend_id(D, T),
	append([R|E], S, U),
	build_head(C, B, [O|T], U, V),
	A1=V,
	B1=(W:-X, Y, !, Z, A1),
	add_dummy_location(B1, D1),
	C1=[D1|E1].
propagation_nested_code([], [A|B], H, C, I, D, E, F, G, K) :-
	universal_search_iterator_end([A|B],
				      [],
				      C,
				      D,
				      E,
				      F,
				      G,
				      J),
	propagation_body(A,
			 B,
			 H,
			 C,
			 I,
			 D,
			 E,
			 F,
			 J,
			 K).
propagation_nested_code([B|C], A, J, D, K, E, F, G, H, N) :-
	universal_search_iterator_end(A,
				      [B|C],
				      D,
				      E,
				      F,
				      G,
				      H,
				      I),
	universal_search_iterator([B|C],
				  A,
				  D,
				  E,
				  F,
				  G,
				  I,
				  M),
	inc_id(G, L),
	propagation_nested_code(C,
				[B|A],
				J,
				D,
				K,
				E,
				F,
				L,
				M,
				N).
check_fd_lookup_condition(A, B, _, _) :-
	get_store_type(A/B, global_singleton), !.
check_fd_lookup_condition(A, B, E, F) :-
	\+ may_trigger(A/B),
	get_functional_dependency(A/B, 1, C, D),
	copy_term(C-D, E-G),
	term_variables(F, H),
	intersect_eq(G, H, G), !.
propagation_body(C, B, O1, A, N1, P/Q, R, S, S2, U2) :-
	A=rule(_, Z1, D, E),
	gen_var_susp_list_for_b(B,
				[C, D, E],
				E1,
				F,
				U,
				G,
				V),
	flatten(F, O),
	init(G, F1),
	last(G, H1),
	gen_var(L),
	gen_var(N),
	functor(C, I, H),
	gen_vars(H, K),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(I/H, J), get_static_suspension_field(I/H, J, state, active, M), get_static_suspension_term_field(arguments, I/H, J, K))),
	M2=(L=J, M),
	T=[[L|N]|O],
	build_head(P, Q, [R|S], T, L2),
	(   check_fd_lookup_condition(I, H, C, B)
	->  universal_search_iterator_failure_vars(B,
						   S,
						   F,
						   U,
						   V,
						   W,
						   Y),
	    X=W
	;   X=[N|O],
	    Y=S
	),
	(   Y=[_]
	->  Z=Y
	;   Z=[R|Y]
	),
	build_head(P, Q, Z, X, A1),
	J1=A1,
	C=..[_|B1],
	pairup(B1, K, C1),
	get_constraint_mode(I/H, D1),
	head_arg_matches(C1, D1, E1, O2, G1),
	different_from_other_susps(C, L, B, F1, N2),
	guard_body_copies(A, G1, P2, Q2),
	get_occurrence(P/Q, R, _, R1),
	(   is_observed(P/Q, R)
	->  init(U, I1),
	    gen_uncond_attach_goal(P/Q,
				   H1,
				   I1,
				   L1,
				   K1),
	    gen_state_cond_call(H1,
				P/Q,
				J1,
				K1,
				M1)
	;   L1=true,
	    M1=J1
	),
	(   (   is_least_occurrence(N1)
	    ;   has_no_history(N1)
	    )
	->  P1=true,
	    Q1=true
	;   \+ may_trigger(P/Q),
	    maplist(is_passive(N1), O1)
	->  P1=true,
	    Q1=true
	;   get_occurrence(P/Q, R, _, R1),
	    use_auxiliary_predicate(novel_production),
	    use_auxiliary_predicate(extend_history),
	    does_use_history(P/Q, R),
	    (   named_history(N1, T1, S1)
	    ->  (   S1==[]
		->  empty_named_history_novel_production(T1, P1),
		    empty_named_history_extend_history(T1, Q1)
		;   reverse([L|F1], U1),
		    named_history_susps(S1,
					[R1|O1],
					[H1|U1],
					V1),
		    V1=[W1|_],
		    (   length(S1, 1)
		    ->  Q1='$extend_history'(W1, T1),
			P1='$novel_production'(W1, T1)
		    ;   findall(X1,
				( member(Y1, S1),
				  get_occurrence_from_id(X1,
							 _,
							 N1,
							 Y1)
				),
				A2),
			B2=..[t, T1|V1]
		    )
		)
	    ;   W1=H1,
		maplist(extract_symbol, Z1, A2),
		sort([R1|O1], S1),
		history_susps(O1,
			      [L|F1],
			      H1,
			      R1,
			      V1),
		B2=..[t, N1|V1]
	    ),
	    (   var(P1)
	    ->  novel_production_calls(A2,
				       S1,
				       V1,
				       N1,
				       C2,
				       D2),
		Q1='$extend_history'(W1, C2),
		P1=(C2=B2, D2)
	    ;   true
	    )
	),
	(   chr_pp_flag(debugable, on)
	->  A=rule(_, _, D, E),
	    my_term_copy(D-E, G1, F2-G2),
	    get_occurrence(P/Q, R, _, R1),
	    sort_by_key([H1, L|F1],
			[R1|O1],
			E2),
	    H2='chr debug_event'(try([], E2, F2, G2)),
	    I2='chr debug_event'(apply([], E2, F2, G2))
	;   H2=true,
	    I2=true
	),
	(   is_stored_in_guard(P/Q, N1)
	->  J2=L1,
	    K2=true
	;   J2=true,
	    K2=L1
	),
	R2=(L2:-M2, N2, O2, P1, J2, P2, H2->I2, Q1, K2, Q2, M1;J1),
	add_location(R2, N1, T2),
	S2=[T2|U2].
extract_symbol(A, B/C) :-
	functor(A, B, C).
novel_production_calls([], [], [], _, _, true).
novel_production_calls([A|H], [C|I], [E|J], B, F,  (G, K)) :-
	get_occurrence_from_id(A, D, B, C),
	delay_phase_end(validate_store_type_assumptions,
			novel_production_call(A,
					      D,
					      '$novel_production'(E,
								  F),
					      G)),
	novel_production_calls(H,
			       I,
			       J,
			       B,
			       F,
			       K).
history_susps(E, A, B, D, F) :-
	reverse(A, C),
	sort_by_key([B|C], [D|E], F).
named_history_susps([], _, _, []).
named_history_susps([A|E], C, D, [B|H]) :-
	select2(A, B, C, D, F, G), !,
	named_history_susps(E, F, G, H).
gen_var_susp_list_for([A], I, H, K, D, C) :- !,
	functor(A, E, B),
	head_info(A, B, _, C, D, F),
	get_constraint_mode(E/B, G),
	head_arg_matches(F, G, [], _, H),
	extra_active_delegate_variables(A, I, H, J),
	append(D, J, K).
gen_var_susp_list_for([B|A], C, K, N, D, E) :-
	gen_var_susp_list_for(A,
			      [B|C],
			      J,
			      D,
			      _,
			      _),
	functor(B, G, F),
	gen_var(E),
	head_info(B, F, _, M, _, H),
	get_constraint_mode(G/F, I),
	head_arg_matches(H, I, J, _, K),
	passive_delegate_variables(B, A, C, K, L),
	append(L, [M, E|D], N).
gen_var_susp_list_for_b([A], I, H, [K], D, [C], []) :- !,
	functor(A, E, B),
	head_info(A, B, _, C, D, F),
	get_constraint_mode(E/B, G),
	head_arg_matches(F, G, [], _, H),
	extra_active_delegate_variables(A, I, H, J),
	append(D, J, K).
gen_var_susp_list_for_b([B|A], C, O, [Q|D], E, [J|F], [H|G]) :-
	gen_var_susp_list_for_b(A,
				[B|C],
				N,
				D,
				E,
				F,
				G),
	functor(B, K, I),
	gen_var(H),
	head_info(B, I, _, J, _, L),
	get_constraint_mode(K/I, M),
	head_arg_matches(L, M, N, _, O),
	passive_delegate_variables(B, A, C, O, P),
	append(P, [J, H], Q).
get_prop_inner_loop_vars([A], I, L, H, D, C, []) :- !,
	functor(A, E, B),
	head_info(A, B, C, D, J, F),
	get_constraint_mode(E/B, G),
	head_arg_matches(F, G, [], _, H),
	extra_active_delegate_variables(A, I, H, K),
	append(J, K, L).
get_prop_inner_loop_vars([B|A], C, Q, M, D, E, [H|F]) :-
	get_prop_inner_loop_vars(A,
				 [B|C],
				 P,
				 L,
				 D,
				 E,
				 F),
	functor(B, I, G),
	gen_var(O),
	head_info(B, G, _, H, _, J),
	get_constraint_mode(I/G, K),
	head_arg_matches(J, K, L, _, M),
	passive_delegate_variables(B, A, C, M, N),
	append(N, [H, O|P], Q).
reorder_heads(C, D, A, E, F, G) :-
	(   chr_pp_flag(reorder_heads, on),
	    length(A, B),
	    B=<6
	->  reorder_heads_main(C,
			       D,
			       A,
			       E,
			       F,
			       G)
	;   F=A,
	    G=E
	).
reorder_heads_main(E, A, C, D, N, P) :-
	term_variables(A, B),
	F=entry([], [], B, C, D, E),
	copy_term_nat(F, G),
	a_star(G,
	       H^(chr_translate:final_data(H)),
	       I^J^K^(chr_translate:expand_data(I, J, K)),
	       L),
	G=F,
	L=entry(M, O, _, _, _, _),
	reverse(M, N),
	reverse(O, P).
final_data(A) :-
	A=entry(_, _, _, _, [], _).
expand_data(A, F, N) :-
	A=entry(G, I, E, B, C, M),
	select2(D, H, B, C, K, L),
	term_variables([D|E], J),
	F=entry([D|G], [H|I], J, K, L, M),
	order_score(D, H, E, K, M, N).
order_score(A, E, F, G, H, I) :-
	functor(A, B, C),
	get_store_type(B/C, D),
	order_score(D,
		    A,
		    E,
		    F,
		    G,
		    H,
		    99999,
		    I).
order_score(default, A, _, F, B, _, I, H) :-
	term_variables(A, C),
	term_variables(B, G),
	ground_vars([A], D),
	list_difference_eq(C, D, E),
	order_score_vars(E, F, G, J),
	H is min(I, J).
order_score(multi_inthash(C), D, _, E, _, _, A, B) :-
	(   A=<100
	->  B=A
	;   order_score_indexes(C, D, E, B)
	).
order_score(multi_hash(C), D, _, E, _, _, A, B) :-
	(   A=<100
	->  B=A
	;   order_score_indexes(C, D, E, B)
	).
order_score(global_ground, A, _, D, B, _, H, G) :-
	term_variables(A, C),
	term_variables(B, E),
	order_score_vars(C, D, E, F),
	I is F*200,
	G is min(H, I).
order_score(var_assoc_store(_, _), _, _, _, _, _, _, 1).
order_score(global_singleton, _, _, _, _, _, _, A) :-
	A=1.
order_score(multi_store(A), B, C, D, E, F, G, H) :-
	multi_order_score(A,
			  B,
			  C,
			  D,
			  E,
			  F,
			  G,
			  H).
multi_order_score([], _, _, _, _, _, A, A).
multi_order_score([A|I], B, C, D, E, F, G, J) :-
	(   order_score(A,
			B,
			C,
			D,
			E,
			F,
			G,
			H)
	->  true
	;   H=G
	),
	multi_order_score(I,
			  B,
			  C,
			  D,
			  E,
			  F,
			  H,
			  J).
order_score(identifier_store(A), B, _, D, _, _, F, E) :-
	arg(A, B, C),
	memberchk_eq(C, D),
	E is min(F, 10).
order_score(type_indexed_identifier_store(A, _), B, _, D, _, _, F, E) :-
	arg(A, B, C),
	memberchk_eq(C, D),
	E is min(F, 10).
order_score_indexes(D, A, B, F) :-
	copy_term_nat(A+B, E+C),
	numbervars(C, 0, _),
	order_score_indexes(D, E, F).
order_score_indexes([A|E], B, D) :-
	args(A, B, C),
	(   maplist(ground, C)
	->  D=100
	;   order_score_indexes(E, B, D)
	).
memberchk_eq_flip(B, A) :-
	memberchk_eq(A, B).
order_score_vars(A, B, C, G) :-
	order_score_count_vars(A,
			       B,
			       C,
			       D-E-F),
	(   D-E-F==0-0-0
	->  G=0
	;   D>0
	->  G is max(10-D, 0)
	;   E>0
	->  G is max(10-E, 1)*100
	;   G is max(10-F, 1)*1000
	).
order_score_count_vars([], _, _, 0-0-0).
order_score_count_vars([D|A], B, C, E-G-I) :-
	order_score_count_vars(A,
			       B,
			       C,
			       F-H-J),
	(   memberchk_eq(D, B)
	->  E is F+1,
	    G=H,
	    I=J
	;   memberchk_eq(D, C)
	->  G is H+1,
	    E=F,
	    I=J
	;   I is J+1,
	    E=F,
	    G=H
	).
create_get_mutable_ref(C, B, A) :-
	A=(B=mutable(C)).
create_get_mutable(B, A, C) :-
	A=mutable(B),
	C=true.
gen_var(_).
gen_vars(B, A) :-
	length(A, B).
ast_head_info1(A, C, D, E, G) :-
	A=chr_constraint(_/B, F, _),
	vars_susp(B, C, D, E),
	pairup(F, C, G).
head_info1(E, _/A, B, C, D, G) :-
	vars_susp(A, B, C, D),
	E=..[_|F],
	pairup(F, B, G).
head_info(E, A, B, C, D, G) :-
	vars_susp(A, B, C, D),
	E=..[_|F],
	pairup(F, B, G).
inc_id([C|A], [B|A]) :-
	B is C+1.
dec_id([C|A], [B|A]) :-
	B is C-1.
extend_id(A, [0|A]).
next_id([_, C|A], [B|A]) :-
	B is C+1.
build_head(A/B, C, D, E) :-
	build_head(A, B, C, D, E).
build_head(A, B, C, H, F) :-
	buildName(A, B, C, G),
	(   (   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, E),
		    get_max_occurrence(A/B, D),
		    D>=E
		)
	    )
	->  F=..[G|H]
	;   init(H, I),
	    F=..[G|I]
	).
buildName(A, B, E, H) :-
	(   (   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,
						       D),
			     get_max_occurrence(A/B, C),
			     C>=D
			 )
		     ;   E\=[0]
		     ))
	    )
	->  atom_concat(A, '___', F),
	    atomic_concat(F, B, G),
	    buildName_(E, G, H)
	;   H=A
	).
buildName_([], A, A).
buildName_([E|A], B, F) :-
	buildName_(A, B, C),
	atom_concat(C, '__', D),
	atomic_concat(D, E, F).
vars_susp(B, A, C, D) :-
	length(A, B),
	append(A, [C], D).
or_pattern(A, B) :-
	C is A-1,
	B is 1<<C.
and_pattern(A, C) :-
	B is A-1,
	D is 1<<B,
	C is -1*(D+1).
make_name(A, B/C, D) :-
	atom_concat_list([A, B, '___', C], D).
make_attr(B, D, A, C) :-
	length(A, B),
	C=..[v, D|A].
get_all_suspensions2(A, C, B) :-
	chr_pp_flag(dynattr, off), !,
	make_attr(A, _, B, C).
get_all_suspensions2(B, D, C, A) :-
	length(A, B),
	C='chr all_suspensions'(A, 1, D).
normalize_attr(B, A, C) :-
	A='chr normalize_attr'(B, C).
get_suspensions(B, D, A, A=C, F) :-
	chr_pp_flag(dynattr, off), !,
	make_attr(B, _, E, C),
	nth1(D, E, F).
get_suspensions(_, B, D, A, C) :-
	A=(memberchk(B-C, D)->true;C=[]).
singleton_attr(B, F, A, D) :-
	chr_pp_flag(dynattr, off), !,
	or_pattern(A, C),
	make_attr(B, C, E, D),
	nth1(A, E, [F], G),
	set_elems(G, []).
singleton_attr(_, C, B, A) :-
	A=[B-[C]].
add_attr(A, E, B, J, I, M) :-
	chr_pp_flag(dynattr, off), !,
	make_attr(A, F, C, K),
	or_pattern(B, L),
	nth1(B, C, D),
	substitute_eq(D, C, [E|D], G),
	make_attr(A, F, G, N),
	substitute_eq(D, C, [E], H),
	make_attr(A, O, H, P),
	I=(J=K, (F/\L=:=L->M=N;O is F\/L, M=P)), !.
add_attr(_, E, C, B, A, D) :-
	A=('chr select'(B, C-F, G)->D=[C-[E|F]|G];D=[C-[E]|B]).
rem_attr(B, P, L, A, I, H) :-
	chr_pp_flag(dynattr, off),
	chr_pp_flag(experiment, off), !,
	or_pattern(A, K),
	and_pattern(A, O),
	make_attr(B, F, C, J),
	nth1(A, C, D),
	substitute_eq(D, C, [], E),
	make_attr(B, N, E, R),
	substitute_eq(D, C, M, G),
	make_attr(B, F, G, S),
	get_target_module(Q),
	H=(I=J, (F/\K=:=K->'chr sbag_del_element'(D, L, M), (M==[]->N is F/\O, (N==0->del_attr(P, Q);put_attr(P, Q, R));put_attr(P, Q, S));true)), !.
rem_attr(_, L, H, A, C, B) :-
	chr_pp_flag(dynattr, off),
	chr_pp_flag(experiment, on), !,
	or_pattern(A, E),
	and_pattern(A, J),
	F is A+1,
	get_target_module(M),
	B=(arg(1, C, D), (D/\E=:=E->arg(F, C, G), 'chr sbag_del_element'(G, H, I), (I==[]->K is D/\J, (K==0->del_attr(L, M);setarg(1, C, K), setarg(F, C, I));setarg(F, C, I));true)), !.
rem_attr(_, H, E, C, B, A) :-
	get_target_module(I),
	A=('chr select'(B, C-D, G)->'chr sbag_del_element'(D, E, F), (F==[]->(G==[]->del_attr(H, I);put_attr(H, I, G));put_attr(H, I, [C-F|G]));true).
merge_attributes(A, G, D, F, E) :-
	chr_pp_flag(dynattr, off), !,
	make_attr(A, B, C, H),
	merge_attributes2(A, B, C, D, I, E),
	F=(G=H, I).
merge_attributes(_, B, C, A, F) :-
	A=(sort(B, D), sort(C, E), 'chr new_merge_attributes'(D, E, F)).
merge_attributes2(A, U, B, Q, P, O) :-
	make_attr(A, V, C, R),
	bagof(F,
	      D^E^G^H^(member2(B, C, D-E), F=(sort(E, G), 'chr merge_attributes'(D, G, H))),
	      I),
	list2conj(I, S),
	bagof(M,
	      J^K^L^member((J, 'chr merge_attributes'(K, L, M)), I),
	      N),
	make_attr(A, T, N, O),
	P=(Q=R, S, T is U\/V).
lookup_passive_head(A, E, F, G, H) :-
	functor(A, B, C),
	get_store_type(B/C, D),
	lookup_passive_head(D,
			    A,
			    E,
			    F,
			    [],
			    G,
			    H).
lookup_passive_head(A, E, F, G, H, I) :-
	functor(A, B, C),
	get_store_type(B/C, D),
	lookup_passive_head(D,
			    A,
			    E,
			    F,
			    G,
			    H,
			    I).
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(A), B, _, C, D, E, F) :-
	hash_lookup_passive_head(inthash,
				 A,
				 B,
				 C,
				 D,
				 E,
				 F,
				 _).
lookup_passive_head(multi_hash(A), B, _, C, D, E, F) :-
	hash_lookup_passive_head(hash,
				 A,
				 B,
				 C,
				 D,
				 E,
				 F,
				 _).
lookup_passive_head(global_ground, A, _, _, _, F, E) :-
	functor(A, B, C),
	global_ground_store_name(B/C, D),
	make_get_store_goal(D, E, F),
	update_store_type(B/C, global_ground).
lookup_passive_head(var_assoc_store(A, C), B, _, F, _, G, L) :-
	arg(A, B, D),
	arg(C, B, E),
	translate([D, E], F, [H, K]),
	get_target_module(I),
	G=(get_attr(H, I, J), lookup_assoc_store(J, K, L)).
lookup_passive_head(global_singleton, A, _, _, _, E, H) :-
	functor(A, B, C),
	global_singleton_store_name(B/C, D),
	make_get_store_goal(D, G, F),
	E=(F, G\==[], H=[G]),
	update_store_type(B/C, global_singleton).
lookup_passive_head(multi_store(A), C, D, E, F, G, H) :-
	once(( member(B, A),
	       lookup_passive_head(B,
				   C,
				   D,
				   E,
				   F,
				   G,
				   H)
	     )).
lookup_passive_head(identifier_store(B), A, _, D, _, I, G) :-
	functor(A, E, F),
	arg(B, A, C),
	translate([C], D, [H]),
	delay_phase_end(validate_store_type_assumptions,
			identifier_lookup(E/F,
					  B,
					  G,
					  H,
					  I)),
	update_store_type(E/F, identifier_store(B)),
	get_identifier_index(E/F, B, _).
lookup_passive_head(type_indexed_identifier_store(B, F), A, _, D, _, E, M) :-
	functor(A, K, L),
	arg(B, A, C),
	(   var(C)
	->  translate([C], D, [H]),
	    E=J
	;   ground(C),
	    C='$chr_identifier_match'(G, _)
	->  lookup_only_identifier_atom(F, G, H, I),
	    E=(I, J)
	),
	delay_phase_end(validate_store_type_assumptions,
			type_indexed_identifier_lookup(K/L,
						       B,
						       F,
						       M,
						       H,
						       J)),
	update_store_type(K/L,
			  type_indexed_identifier_store(B, F)),
	get_type_indexed_identifier_index(F,
					  K/L,
					  B,
					  _).
identifier_lookup(B, C, F, H, G) :-
	get_identifier_size(A),
	functor(E, struct, A),
	get_identifier_index(B, C, D),
	arg(D, E, F),
	G=(H=E).
type_indexed_identifier_lookup(B, C, A, F, H, G) :-
	type_indexed_identifier_structure(A, E),
	get_type_indexed_identifier_index(A, B, C, D),
	arg(D, E, F),
	G=(H=E).
hash_lookup_passive_head(I, A, B, C, K, N, J, D) :-
	pick_hash_index(A, B, C, D, L, E),
	(   E=[F]
	->  true
	;   F=..[k|E]
	),
	functor(B, G, H),
	multi_hash_lookup_goal(G/H,
			       I,
			       D,
			       F,
			       J,
			       P),
	check_ground(K, L, M),
	my_term_copy(M, C, O),
	N=(O, P),
	(   I==inthash
	->  update_store_type(G/H, multi_inthash([D]))
	;   update_store_type(G/H, multi_hash([D]))
	).
pick_hash_index(B, C, E, A, D, F) :-
	member(A, B),
	args(A, C, D),
	key_in_scope(D, E, F), !.
key_in_scope([], _, []).
key_in_scope([A|F], C, [D|G]) :-
	term_variables(A, B),
	translate(B, C, E),
	copy_term(A/B, D/E),
	key_in_scope(F, C, G).
existential_lookup(var_assoc_store(B, C), D, E, F, G, L, M, H, A, A) :- !,
	lookup_passive_head(var_assoc_store(B, C),
			    D,
			    E,
			    F,
			    G,
			    N,
			    I),
	sbag_member_call(H, I, O),
	functor(D, J, K),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(J/K, L), get_static_suspension_field(J/K, L, state, active, P))),
	M=(N, O, H=L, P).
existential_lookup(global_singleton, B, _, _, _, I, G, F, A, A) :- !,
	functor(B, C, D),
	global_singleton_store_name(C/D, E),
	make_get_store_goal(E, F, H),
	G=(H, F\==[], F=I),
	update_store_type(C/D, global_singleton).
existential_lookup(multi_store(A), C, D, E, F, G, H, I, J, K) :- !,
	once(( member(B, A),
	       existential_lookup(B,
				  C,
				  D,
				  E,
				  F,
				  G,
				  H,
				  I,
				  J,
				  K)
	     )).
existential_lookup(multi_inthash(A), B, _, C, D, E, F, G, H, I) :- !,
	existential_hash_lookup(inthash,
				A,
				B,
				C,
				D,
				E,
				F,
				G,
				H,
				I).
existential_lookup(multi_hash(A), B, _, C, D, E, F, G, H, I) :- !,
	existential_hash_lookup(hash,
				A,
				B,
				C,
				D,
				E,
				F,
				G,
				H,
				I).
existential_lookup(identifier_store(A), B, C, D, E, M, N, K, F, G) :- !,
	lookup_passive_head(identifier_store(A),
			    B,
			    C,
			    D,
			    E,
			    O,
			    J),
	hash_index_filter(F, [A], G),
	functor(B, H, I),
	(   check_fd_lookup_condition(H, I, B, _)
	->  L=(J=[K])
	;   sbag_member_call(K, J, L)
	),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(H/I, M), get_static_suspension_field(H/I, M, state, active, P))),
	N=(O, L, K=M, P).
existential_lookup(type_indexed_identifier_store(A, B), C, D, E, F, N, O, L, G, H) :- !,
	lookup_passive_head(type_indexed_identifier_store(A, B),
			    C,
			    D,
			    E,
			    F,
			    P,
			    K),
	hash_index_filter(G, [A], H),
	functor(C, I, J),
	(   check_fd_lookup_condition(I, J, C, _)
	->  M=(K=[L])
	;   sbag_member_call(L, K, M)
	),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(I/J, N), get_static_suspension_field(I/J, N, state, active, Q))),
	O=(P, M, L=N, Q).
existential_lookup(B, C, D, E, F, K, L, G, A, A) :-
	lookup_passive_head(B,
			    C,
			    D,
			    E,
			    F,
			    M,
			    H),
	sbag_member_call(G, H, N),
	functor(C, I, J),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(I/J, K), get_static_suspension_field(I/J, K, state, active, O))),
	L=(M, N, G=K, O).
existential_hash_lookup(A, B, C, D, E, N, O, L, F, H) :-
	hash_lookup_passive_head(A,
				 B,
				 C,
				 D,
				 E,
				 P,
				 K,
				 G),
	hash_index_filter(F, G, H),
	functor(C, I, J),
	(   check_fd_lookup_condition(I, J, C, _)
	->  M=(K=[L])
	;   sbag_member_call(L, K, M)
	),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(I/J, N), get_static_suspension_field(I/J, N, state, active, Q))),
	O=(P, M, L=N, Q).
hash_index_filter(A, B, C) :-
	hash_index_filter(A, B, 1, C).
hash_index_filter([], _, _, []).
hash_index_filter([E|F], A, B, D) :-
	(   A=[C|G]
	->  H is B+1,
	    (   C>B
	    ->  D=[E|I],
		hash_index_filter(F, [C|G], H, I)
	    ;   C==B
	    ->  D=[silent(E)|I],
		hash_index_filter(F, G, H, I)
	    )
	;   D=[E|F]
	).
assume_constraint_stores([]).
assume_constraint_stores([A|V]) :-
	(   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(B)-count,
			  ( member(B, C),
			    nth1(B, D, +)
			  ),
			  F-E),
	    (   E>10
	    ->  findall([B], member(B, F), H)
	    ;   findall(B,
			( sublist(B, F),
			  B\==[]
			),
			G),
		predsort(longer_list, G, H)
	    ),
	    (   get_functional_dependency(A, 1, I, J),
		all_distinct_var_args(I),
		J==[]
	    ->  assumed_store_type(A, global_singleton)
	    ;   (   only_ground_indexed_arguments(A)
		;   E>0
		)
	    ->  get_constraint_type_det(A, K),
		partition_indexes(H,
				  K,
				  O,
				  L,
				  Q,
				  T),
		(   L=[]
		->  M=N
		;   M=[multi_inthash(L)|N]
		),
		(   O=[]
		->  N=P
		;   N=[multi_hash(O)|P]
		),
		(   Q=[]
		->  P=S
		;   maplist(wrap_in_functor(identifier_store),
			    Q,
			    R),
		    append(R, S, P)
		),
		append(T, U, S),
		(   only_ground_indexed_arguments(A)
		->  U=[global_ground]
		;   U=[default]
		),
		assumed_store_type(A, multi_store(M))
	    ;   true
	    )
	;   true
	),
	assume_constraint_stores(V).
partition_indexes([], _, [], [], [], []).
partition_indexes([A|O], C, H, G, F, I) :-
	(   A=[B],
	    nth1(B, C, D),
	    unalias_type(D, E),
	    E==chr_identifier
	->  F=[B|L],
	    G=M,
	    H=N,
	    I=K
	;   A=[B],
	    nth1(B, C, D),
	    unalias_type(D, E),
	    nonvar(E),
	    E=chr_identifier(J)
	->  I=[type_indexed_identifier_store(B, J)|K],
	    F=L,
	    G=M,
	    H=N
	;   A=[B],
	    nth1(B, C, D),
	    unalias_type(D, E),
	    E==dense_int
	->  G=[A|M],
	    H=N,
	    F=L,
	    I=K
	;   member(B, A),
	    nth1(B, C, D),
	    unalias_type(D, E),
	    nonvar(E),
	    E=chr_identifier(_)
	->  G=M,
	    H=N,
	    F=L,
	    I=K
	;   G=M,
	    H=[A|N],
	    F=L,
	    I=K
	),
	partition_indexes(O,
			  C,
			  N,
			  M,
			  L,
			  K).
longer_list(F, A, B) :-
	length(A, D),
	length(B, C),
	compare(E, C, D),
	(   E==(=)
	->  compare(F, A, B)
	;   F=E
	).
all_distinct_var_args(A) :-
	copy_term_nat(A, E),
	functor(A, B, C),
	functor(D, B, C),
	D=@=E.
get_indexed_arguments(A, C) :-
	A=_/B,
	get_indexed_arguments(1, B, A, C).
get_indexed_arguments(A, B, D, C) :-
	(   A>B
	->  C=[]
	;   (   is_indexed_argument(D, A)
	    ->  C=[A|E]
	    ;   C=E
	    ),
	    F is A+1,
	    get_indexed_arguments(F, B, D, 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([C|B], D, A, L/M, N, G, W, Y) :-
	A=rule(_, _, E, F),
	gen_var_susp_list_for_b(B,
				[C, D, E, F],
				_,
				H,
				I,
				_,
				J),
	universal_search_iterator_failure_vars(B,
					       G,
					       H,
					       I,
					       J,
					       S,
					       P),
	flatten(H, K),
	O=[[]|K],
	build_head(L, M, [N|G], O, T),
	(   P=[_]
	->  get_success_continuation_code_id(L/M,
					     N,
					     Q),
	    R=[Q]
	;   R=[N|P]
	),
	build_head(L, M, R, S, U),
	V=(T:-U),
	add_dummy_location(V, X),
	W=[X|Y].
universal_search_iterator_failure_vars(F, A, E, D, K, C, B) :-
	(   A=[0|_]
	->  next_id(A, B),
	    C=D
	;   E=[_|M],
	    dec_id(A, L),
	    (   F=[G|J],
		functor(G, H, I),
		check_fd_lookup_condition(H, I, G, J)
	    ->  K=[_|N],
		universal_search_iterator_failure_vars(J,
						       L,
						       M,
						       D,
						       N,
						       C,
						       B)
	    ;   B=L,
		flatten(M, P),
		K=[O|_],
		C=[O|P]
	    )
	).
universal_search_iterator([D|E], [C|B], A, A1/B1, C1, X, U1, W1) :-
	A=rule(_, _, F, G),
	gen_var_susp_list_for_b(B,
				[C, D, E, F, G],
				O,
				I,
				I1,
				H,
				J1),
	init(H, R),
	flatten(I, Z),
	gen_var(Y),
	functor(C, L, J),
	gen_vars(J, K),
	head_info(C, J, K, Q, _, M),
	get_constraint_mode(L/J, N),
	head_arg_matches(M, N, O, U, V),
	delay_phase_end(validate_store_type_assumptions,
			(static_suspension_term(L/J, P), get_static_suspension_field(L/J, P, state, active, S), get_static_suspension_term_field(arguments, L/J, P, K))),
	different_from_other_susps(C, Q, B, R, T),
	P1=(Q=P, S, T, U),
	add_heads_ground_variables([C|B], [], W),
	lookup_passive_head(D,
			    [C|B],
			    V,
			    W,
			    Q1,
			    E1),
	inc_id(X, G1),
	D1=[[Q|Y]|Z],
	build_head(A1, B1, [C1|X], D1, O1),
	passive_delegate_variables(C,
				   B,
				   [D, E, F, G],
				   V,
				   F1),
	append([E1|F1], [Q, Y|Z], H1),
	build_head(A1, B1, [C1|G1], H1, R1),
	(   check_fd_lookup_condition(L, J, C, B)
	->  universal_search_iterator_failure_vars(B,
						   X,
						   I,
						   I1,
						   J1,
						   K1,
						   M1),
	    L1=K1
	;   L1=[Y|Z],
	    M1=X
	),
	(   M1=[_]
	->  N1=M1
	;   N1=[C1|M1]
	),
	build_head(A1, B1, N1, L1, S1),
	T1=(O1:-P1, Q1->R1;S1),
	add_dummy_location(T1, V1),
	U1=[V1|W1].
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([A|C], B) :-
	ai_observation_schedule_initial_call(A, B),
	ai_observation_schedule_initial_calls(C, B).
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|D], A) :-
	A=odom(_, C),
	initial_call_pattern(odom(B, C)),
	ai_observation_schedule_new_calls(D, 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, C), odom(A, B)) :-
	ord_subset(B, C).
ai_observation_observe_set(A, B, C) :-
	ord_subtract(A, B, C).
ai_observation_abstract_constraint(A, E, B) :-
	functor(A, C, D),
	B=C/D,
	memberchk(B, E).
ai_observation_abstract_constraints(A, C, E) :-
	findall(D,
		( member(B, A),
		  ai_observation_abstract_constraint(B, C, D)
		),
		E).
ai_observation_abstract_goal_(A, B, C, G, H, I) :-
	term_variables((A, B, C), E),
	append(A, B, D),
	ground_vars(D, F),
	list_difference_eq(E, F, J),
	ai_observation_abstract_goal(G, H, I, [], J), !.
ground_vars([], []).
ground_vars([A|F], I) :-
	functor(A, B, C),
	get_constraint_mode(B/C, E),
	head_info(A, C, _, _, _, D),
	head_arg_matches(D, E, [], _, _, [], G),
	ground_vars(F, H),
	append(G, H, I).
ai_observation_abstract_goal((A, E), B, C, G, D) :- !,
	ai_observation_abstract_goal(A, B, C, F, D),
	ai_observation_abstract_goal(E, B, F, G, D).
ai_observation_abstract_goal((B;F), C, [(D;G)|A], A, E) :- !,
	ai_observation_abstract_goal(B, C, D, [], E),
	ai_observation_abstract_goal(F, C, G, [], E).
ai_observation_abstract_goal((A->E), B, C, G, D) :- !,
	ai_observation_abstract_goal(A, B, C, F, D),
	ai_observation_abstract_goal(E, B, F, G, D).
ai_observation_abstract_goal(B, C, [D|A], A, _) :-
	ai_observation_abstract_constraint(B, C, D), !.
ai_observation_abstract_goal(true, _, A, A, _) :- !.
ai_observation_abstract_goal(writeln(_), _, A, A, _) :- !.
ai_observation_abstract_goal(B, _, A, A, D) :-
	builtin_binds_b(B, C),
	intersect_eq(C, D, []), !.
ai_observation_abstract_goal(_, _, [B|A], A, _) :-
	B=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([B|E], [A|F], D, C) :-
	(   A\==(+)
	->  (   nonvar(B)
	    ->  no_partial_wake(C)
	    ;   memberchk_eq(B, D)
	    ->  no_partial_wake(C)
	    ;   true
	    )
	;   true
	),
	partial_wake_args(E, F, D, C).
generate_show_constraint(B, A, D, C) :-
	(   chr_pp_flag(show, on)
	->  A=['$show'/0|B],
	    generate_show_rules(B, C, [E|D]),
	    inc_rule_count(F),
	    E=pragma(rule(['$show'], [], true, true), ids([0], []), [], no, F)
	;   A=B,
	    C=D
	).
generate_show_rules([], A, A).
generate_show_rules([A/B|F], [C|G], H) :-
	functor(D, A, B),
	inc_rule_count(E),
	C=pragma(rule([], ['$show', D], true, writeln(D)), ids([], [0, 1]), [passive(1)], no, E),
	generate_show_rules(F, G, H).
static_suspension_term(A/B, D) :-
	suspension_term_base(A/B, C),
	E is C+B,
	functor(D, suspension, E).
has_suspension_field(A, B) :-
	suspension_term_base_fields(A, C),
	memberchk(B, C).
suspension_term_base(A, C) :-
	suspension_term_base_fields(A, B),
	length(B, C).
suspension_term_base_fields(B, A) :-
	(   chr_pp_flag(debugable, on)
	->  A=[id, state, history, generation, continuation, functor]
	;   (   uses_history(B)
	    ->  A=[id, state, history|C]
	    ;   only_ground_indexed_arguments(B),
		get_functional_dependency(B, 1, _, _)
	    ->  A=[state|C]
	    ;   A=[id, state|C]
	    ),
	    (   only_ground_indexed_arguments(B)
	    ->  get_store_type(B, 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(B)
	    ->  (   uses_field(B, 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(B, 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(B, D),
		    basic_store_types(D, E),
		    ht_prev_fields(E, F)
		;   F=[]
		)
	    )
	).
ht_prev_fields(A, C) :-
	ht_prev_fields_int(A, B),
	append(B, C).
ht_prev_fields_int([], []).
ht_prev_fields_int([A|F], C) :-
	(   A=multi_hash(B)
	->  maplist(ht_prev_field, B, D),
	    C=[D|E]
	;   C=E
	),
	ht_prev_fields_int(F, E).
ht_prev_field(A, B) :-
	atomic_list_concat(['multi_hash_prev-'|A], B).
get_static_suspension_term_field(C, A, E, F) :-
	suspension_term_base_fields(A, B),
	nth1(D, B, C), !,
	arg(D, E, F).
get_static_suspension_term_field(arguments, A, B, E) :- !,
	suspension_term_base(A, C),
	B=..[_|D],
	drop(C, D, E).
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(C, A, F, G, D) :-
	suspension_term_base_fields(A, B),
	nth1(E, B, C), !,
	D=arg(E, F, G).
get_dynamic_suspension_term_field(arguments, A, E, C, D) :- !,
	static_suspension_term(A, B),
	get_static_suspension_term_field(arguments, A, B, C),
	D=(E=B).
get_dynamic_suspension_term_field(argument(B), A, F, G, D) :- !,
	suspension_term_base(A, C),
	E is B+C,
	D=arg(E, F, G).
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(C, A, F, G, D) :-
	suspension_term_base_fields(A, B),
	nth1(E, B, C), !,
	D=setarg(E, F, G).
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, D, E) :-
	(   get_occurrence_head(A, B, F)
	->  C is B+1,
	    (   between(C, D, E),
		get_occurrence_head(A, E, G),
		unifiable(F, G, _)
	    ->  true
	    ;   E is D+1
	    )
	;   E=D
	).
get_occurrence_head(A, B, F) :-
	get_occurrence(A, B, C, D),
	\+ is_passive(C, D),
	get_rule(C, E),
	E=pragma(rule(H, J, _, _), ids(G, I), _, _, _),
	(   select2(D, F, G, H, _, _)
	->  true
	;   select2(D, F, I, J, _, _)
	).
get_success_continuation_code_id(A, B, D) :-
	get_success_continuation_occurrence(A, B, C),
	get_occurrence_code_id(A, C, D).
collect_constants(_, F, E, A) :-
	(   not_restarted,
	    chr_pp_flag(experiment, on)
	->  (   chr_pp_flag(sss, on)
	    ->  C=[fep/4-[2, 3]-[[a, b]-fep1, [c, d]-fep2]-no],
		copy_term_nat(A, B),
		flatten_clauses(B, C, D),
		install_new_declarations_and_restart(D)
	    ;   maplist(collect_rule_constants(E), F),
		(   chr_pp_flag(verbose, on)
		->  print_chr_constants
		;   true
		),
		(   chr_pp_flag(experiment, on)
		->  flattening_dictionary(E, C),
		    copy_term_nat(A, B),
		    flatten_clauses(B, C, D),
		    install_new_declarations_and_restart(D)
		;   true
		)
	    )
	;   true
	).
collect_rule_constants(D, A) :-
	A=ast_rule(B, _, _, C, _),
	collect_head_constants(B),
	collect_body_constants(C, D).
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(B, A) :-
	maplist(collect_goal_constants(A), B).
collect_goal_constants(C, A) :-
	(   ast_nonvar(A)
	->  ast_symbol(A, B),
	    (   memberchk(B, C)
	    ->  ast_term_to_term(A, E),
		ast_args(A, D),
		collect_constraint_constants(chr_constraint(B,
							    D,
							    E))
	    ;   B==(:)/2,
		ast_args(A, [F, I]),
		F=atomic(G),
		get_target_module(H),
		G==H,
		ast_nonvar(I),
		ast_symbol(I, J),
		memberchk(J, C)
	    ->  ast_term_to_term(I, L),
		ast_args(I, K),
		collect_constraint_constants(chr_constraint(J,
							    K,
							    L))
	    ;   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([C|D], [A|E], H) :-
	unalias_type(A, B),
	(   is_chr_constants_type(B, F, _)
	->  (   ast_ground(C)
	    ->  ast_term_to_term(C, G),
		collect_all_arg_constants(D,
					  E,
					  [F-G|H])
	    ;   true
	    )
	;   collect_all_arg_constants(D, E, H)
	).
add_chr_constants(A) :-
	keysort(A, B),
	add_chr_constants_(B).
flattening_dictionary([], []).
flattening_dictionary([A|E], B) :-
	(   flattening_dictionary_entry(A, C)
	->  B=[C|D]
	;   B=D
	),
	flattening_dictionary(E, D).
flattening_dictionary_entry(A, F) :-
	get_constraint_type_det(A, B),
	constant_positions(B, 1, C, D, G, M),
	(   C\==[]
	->  pairup(D, J, E),
	    keysort(E, H),
	    F=A-C-L-G,
	    get_chr_constants(I),
	    findall(K,
		    ( member(H, I),
		      flat_spec(A, C, J, K)
		    ),
		    L)
	;   M==yes
	->  enum_positions(B, 1, N, P, O),
	    F=A-N-L-O,
	    findall(K,
		    ( cartesian_product(Q, P),
		      flat_spec(A, N, Q, K)
		    ),
		    L)
	).
constant_positions([], _, [], [], no, no).
constant_positions([A|N], F, E, G, D, I) :-
	unalias_type(A, B),
	(   is_chr_constants_type(B, H, C)
	->  compose_error_handlers(C, M, D),
	    E=[F|K],
	    G=[H|L],
	    I=J
	;   (   is_chr_enum_type(B, _, _)
	    ->  I=yes
	    ;   I=J
	    ),
	    K=E,
	    L=G,
	    M=D
	),
	O is F+1,
	constant_positions(N,
			   O,
			   K,
			   L,
			   M,
			   J).
compose_error_handlers(no, A, A).
compose_error_handlers(yes(A), _, yes(A)).
enum_positions([], _, [], [], no).
enum_positions([A|L], F, E, G, D) :-
	unalias_type(A, B),
	(   is_chr_enum_type(B, H, C)
	->  compose_error_handlers(C, K, D),
	    E=[F|I],
	    G=[H|J]
	;   E=I,
	    G=J,
	    D=K
	),
	M is F+1,
	enum_positions(L, M, I, J, K).
cartesian_product([], []).
cartesian_product([A|C], [B|D]) :-
	member(A, B),
	cartesian_product(C, D).
flat_spec(D/E, C, B, A) :-
	A=B-H,
	term_to_atom(B, G),
	term_to_atom(C, F),
	atom_concat_list(['$flat_', D, /, E, '___', F, '___', G],
			 H).
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, H) :-
	flatten_readcontent(A,
			    C,
			    E,
			    F,
			    _,
			    G,
			    D),
	flatten_clauses_(B,
			 C,
			 D,
			 E,
			 F,
			 G,
			 H).
flatten_clauses_(A, E, F, D, B, C, K) :-
	auxiliary_constraints_declarations(A, B, C, G),
	dispatching_rules(A, H),
	declarations(D, A, B, C, I),
	flatten_rules(E, A, J),
	append([F, G, H, I, J], K).
declarations(B, C, D, E, H) :-
	findall(A,
		( member(A, B),
		  \+ memberchk(A-_-_-_, C)
		),
		F),
	maplist(declaration(D, E), F, G),
	flatten(G, H).
declaration(E, H, A, [(:-chr_constraint A),  (:-chr_option(mode, B)),  (:-chr_option(type_declaration, G))]) :-
	A=C/D,
	functor(B, C, D),
	(   memberchk(B, E)
	->  true
	;   replicate(D, ?, F),
	    B=..[_|F]
	),
	functor(G, C, D),
	(   memberchk(G, H)
	->  true
	;   replicate(D, any, I),
	    G=..[_|I]
	).
flatten_readcontent([], [], [], [], [], [], []).
flatten_readcontent([A|H], B, C, D, F, E, G) :-
	(   A==end_of_file
	->  B=[],
	    C=[],
	    D=[],
	    E=[],
	    F=[],
	    G=[]
	;   crude_is_rule(A)
	->  B=[A|I],
	    flatten_readcontent(H,
				I,
				C,
				D,
				F,
				E,
				G)
	;   pure_is_declaration(A, J, K, L)
	->  append(J, M, C),
	    append(K, N, D),
	    append(L, O, E),
	    flatten_readcontent(H,
				B,
				M,
				N,
				F,
				O,
				G)
	;   is_mode_declaration(A, P)
	->  D=[P|N],
	    flatten_readcontent(H,
				B,
				C,
				N,
				F,
				E,
				G)
	;   is_type_declaration(A, Q)
	->  E=[Q|O],
	    flatten_readcontent(H,
				B,
				C,
				D,
				F,
				O,
				G)
	;   is_type_definition(A, R)
	->  G=[A|T],
	    F=[R|S],
	    flatten_readcontent(H,
				B,
				C,
				D,
				S,
				E,
				T)
	;   (   A=(:-op(U, V, W))
	    ->  op(U, V, W)
	    ;   true
	    ),
	    G=[A|T],
	    flatten_readcontent(H,
				B,
				C,
				D,
				F,
				E,
				T)
	).
crude_is_rule(@(_, _)).
crude_is_rule(pragma(_, _)).
crude_is_rule(==>(_, _)).
crude_is_rule(<=>(_, _)).
pure_is_declaration(A, F, G, H) :-
	A=(:-B),
	B=..[C, D],
	C==(chr_constraint),
	conj2list(D, E),
	pure_extract_type_mode(E, F, G, H).
pure_extract_type_mode([], [], [], []).
pure_extract_type_mode([A/B|C], [A/B|D], E, F) :- !,
	pure_extract_type_mode(C, D, E, F).
pure_extract_type_mode([A|M], [B|N], [F|O], J) :-
	functor(A, C, D),
	B=C/D,
	A=..[_|E],
	extract_types_and_modes(E, H, G),
	F=..[C|G],
	(   forall(member(I, H), I==any)
	->  J=K
	;   J=[L|K],
	    L=..[C|H]
	),
	pure_extract_type_mode(M, N, O, K).
is_mode_declaration((:-chr_option(mode, A)), A).
is_type_declaration((:-chr_option(type_declaration, A)), A).
auxiliary_constraints_declarations(A, B, C, F) :-
	findall(D,
		auxiliary_constraints_declaration(A,
						  B,
						  C,
						  D),
		E),
	flatten(E, F).
auxiliary_constraints_declaration(A, D, G, [(:-chr_constraint K),  (:-chr_option(mode, N)),  (:-chr_option(type_declaration, P))]) :-
	member(B/C-F-J-_, A),
	arg_modes(B, C, D, E),
	specialize_modes(E, F, O),
	arg_types(B, C, G, H),
	specialize_types(H, F, Q),
	length(F, I),
	M is C-I,
	member(_-L, J),
	K=L/M,
	N=..[L|O],
	P=..[L|Q].
arg_modes(A, B, D, E) :-
	functor(C, A, B),
	(   memberchk(C, D)
	->  C=..[_|E]
	;   replicate(B, ?, E)
	).
specialize_modes(B, A, C) :-
	split_args(A, B, _, C).
arg_types(A, B, D, E) :-
	functor(C, A, B),
	(   memberchk(C, D)
	->  C=..[_|E]
	;   replicate(B, any, E)
	).
specialize_types(B, A, C) :-
	split_args(A, B, _, C).
dispatching_rules([], []).
dispatching_rules([B-C-A-D|F], E) :-
	constraint_dispatching_rule(A,
				    B,
				    C,
				    D,
				    E,
				    G),
	dispatching_rules(F, G).
constraint_dispatching_rule(N, C/D, A, O, B, Q) :-
	(   increasing_numbers(A, 1)
	->  L=B,
	    M=C/D
	;   functor(E, C, D),
	    E=..[_|F],
	    split_args(A, F, G, H),
	    append(G, H, J),
	    atom_concat(C, '_$shuffled', I),
	    K=..[I|J],
	    [(E:-K)|L]=B,
	    M=I/D
	),
	P=swap(C, A),
	dispatching_rule_term_cases(N,
				    A,
				    M,
				    O,
				    P,
				    L,
				    Q).
increasing_numbers([], _).
increasing_numbers([A|B], A) :-
	C is A+1,
	increasing_numbers(B, C).
dispatching_rule_term_cases(B, A, M/D, J, K, N, O) :-
	length(A, E),
	once(pairup(C, F, B)),
	maplist(head_tail, C, G, H),
	I is D-E,
	maplist(wrap_in_functor(dispatching_action), F, L),
	dispatch_trie_index(G,
			    H,
			    I,
			    J,
			    K,
			    L,
			    M,
			    N,
			    O).
dispatching_action(B, C, A) :-
	A=..[B|C].
dispatch_trie_index(A, C, D, E, F, G, B, H, I) :-
	dispatch_trie_step(A,
			   B,
			   B,
			   C,
			   D,
			   E,
			   F,
			   G,
			   H,
			   I).
dispatch_trie_step([], _, _, _, [], _, _, [], A, A) :- !.
dispatch_trie_step(C, N, O, A, J, K, L, M, P, Q) :-
	A=[B|_],
	length(B, G),
	aggregate_all(set(E/F),
		      ( member(D, C),
			functor(D, E, F)
		      ),
		      H),
	I is G+1,
	dispatch_trie_step_cases(H,
				 I,
				 C,
				 A,
				 J,
				 K,
				 L,
				 M,
				 N,
				 O,
				 P,
				 Q).
dispatch_trie_step_cases([], E, _, _, F, A, J, _, H, _, B, C) :-
	(   A=yes(L)
	->  B=[D|C],
	    D=(G:-K),
	    I is E+F,
	    functor(G, H, I),
	    reconstruct_original_term(J, G, M),
	    K=..[L, M]
	;   B=C
	).
dispatch_trie_step_cases([A|L], B, C, D, E, F, G, H, I, J, K, N) :-
	dispatch_trie_step_case(A,
				B,
				C,
				D,
				E,
				F,
				G,
				H,
				I,
				J,
				K,
				M),
	dispatch_trie_step_cases(L,
				 B,
				 C,
				 D,
				 E,
				 F,
				 G,
				 H,
				 I,
				 J,
				 M,
				 N).
dispatch_trie_step_case(L/M, D, S, X, E, B, N, T, G, I1, [A|Q], R) :-
	A=(F:-C, W),
	(   B=yes(_)
	->  C=!
	;   C=true
	),
	H is D+E,
	functor(F, G, H),
	arg(1, F, K),
	F=..[_, _|J],
	length(I, E),
	once(append(D1, I, J)),
	functor(K, L, M),
	H1=index_functor(L, M, N),
	K=..[_|O],
	append(O, J, P),
	(   P==I
	->  Q=R,
	    rec_cases(S,
		      _,
		      T,
		      L/M,
		      _,
		      _,
		      U),
	    U=[V],
	    call(V, I, W)
	;   rec_cases(S,
		      X,
		      T,
		      L/M,
		      Z,
		      Y,
		      U),
	    (   U=[B1]
	    ->  Y=[A1],
		append([Z, A1, I], P),
		Q=R,
		call(B1, I, W)
	    ;   pairup(Z, Y, C1),
		common_pattern(C1, G1, J1, O1),
		append(O, D1, [E1|F1]),
		E1-F1=G1,
		S1=gct([E1|F1], H1),
		fresh_symbol(I1, K1),
		append(J1, I, L1),
		W=..[K1|L1],
		findall(M1-N1,
			member([M1|N1], O1),
			P1),
		once(pairup(Q1, R1, P1)),
		dispatch_trie_step(Q1,
				   K1,
				   I1,
				   R1,
				   E,
				   B,
				   S1,
				   U,
				   Q,
				   R)
	    )
	).
split([D|F], A, B, C, E) :-
	(   A==1
	->  B=[],
	    C=D,
	    E=F
	;   G is A-1,
	    B=[D|H],
	    split(F, G, H, C, E)
	).
reconstruct_original_term(swap(C, E), A, B) :-
	functor(A, _, D),
	functor(B, C, D),
	B=..[_|F],
	split_args(E, F, G, H),
	A=..[_|I],
	append(G, H, I).
reconstruct_original_term(index_functor(D, B, I), A, K) :-
	A=..[F|C],
	split_at(B, C, E, H),
	G=..[D|E],
	J=..[F, G|H],
	reconstruct_original_term(I, J, K).
reconstruct_original_term(gct(A, I), C, K) :-
	copy_term_nat(A, B),
	term_variables(B, D),
	C=..[G|E],
	append(D, F, E),
	append(B, F, H),
	J=..[G|H],
	reconstruct_original_term(I, J, K).
flatten_rules(A, B, D) :-
	flatten_rules1(A, B, C),
	flatten(C, D).
flatten_rules1([], _, []).
flatten_rules1([A|E], B, [D|F]) :-
	findall(C, flatten_rule(A, B, C), D),
	flatten_rules1(E, B, F).
flatten_rule(@(A, B), C, @(A, D)) :- !,
	flatten_rule(B, C, D).
flatten_rule(pragma(B, A), C, pragma(D, A)) :- !,
	flatten_rule(B, C, D).
flatten_rule(==>(A, D), B, ==>(C, E)) :- !,
	flatten_heads(A, B, C),
	flatten_body(D, B, E).
flatten_rule(<=>(\(A, B), F), C, <=>(\(D, E), G)) :- !,
	flatten_heads((A, B), C,  (D, E)),
	flatten_body(F, C, G).
flatten_rule(<=>(A, D), B, <=>(C, E)) :-
	flatten_heads(A, B, C),
	flatten_body(D, B, E).
flatten_heads((A, D), B,  (C, E)) :- !,
	flatten_heads(A, B, C),
	flatten_heads(D, B, E).
flatten_heads(#(B, A), C, #(D, A)) :- !,
	flatten_heads(B, C, D).
flatten_heads(A, D, I) :-
	(   functor(A, B, C),
	    memberchk(B/C-E-H-_, D)
	->  A=..[_|F],
	    split_args(E, F, G, K),
	    member(G-J, H),
	    I=..[J|K]
	;   I=A
	).
flatten_body((A| F), B,  (E| I)) :- !,
	conj2list(A, C),
	maplist(flatten_goal(B), C, D),
	list2conj(D, E),
	conj2list(F, G),
	maplist(flatten_goal(B), G, H),
	list2conj(H, I).
flatten_body(A, B, E) :-
	conj2list(A, C),
	maplist(flatten_goal(B), C, D),
	list2conj(D, E).
flatten_goal(_, A, B) :-
	var(A), !,
	B=A.
flatten_goal(B, A, D) :-
	(   is_specializable_goal(A, B, C)
	->  specialize_goal(A, C, D)
	;   A=E:G,
	    get_target_module(F),
	    E==F,
	    nonvar(G),
	    is_specializable_goal(G, B, C)
	->  specialize_goal(G, C, H),
	    D=E:H
	;   partial_eval(A, D)
	->  true
	;   D=A
	).
is_specializable_goal(A, E, D) :-
	functor(A, B, C),
	memberchk(B/C-D-_-_, E),
	args(D, A, F),
	ground(F).
specialize_goal(A, B, G) :-
	functor(A, D, E),
	A=..[_|C],
	split_args(B, C, F, I),
	flat_spec(D/E, B, F, _-H),
	G=..[H|I].
partial_eval(append(A, D, C), B) :-
	(   A==[]
	->  B=(C=D)
	;   D==[]
	->  B=(C=A)
	).
partial_eval(flatten_path(A, D), C) :-
	(   nonvar(A),
	    flatten(A, B),
	    B\==A
	->  C=flatten_path(B, D)
	).
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(C, B) :-
	chr_pp_flag(guard_locks, A),
	(   A==off
	->  B=true
	;   A==on
	->  B='chr none_locked'(C)
	;   A==error
	->  B='chr none_error_locked'(C)
	).
chr_not_locked(C, B) :-
	chr_pp_flag(guard_locks, A),
	(   A==off
	->  B=true
	;   A==on
	->  B='chr not_locked'(C)
	;   A==error
	->  B='chr not_error_locked'(C)
	).
chr_lock(C, B) :-
	chr_pp_flag(guard_locks, A),
	(   A==off
	->  B=true
	;   A==on
	->  B='chr lock'(C)
	;   A==error
	->  B='chr error_lock'(C)
	).
chr_unlock(C, B) :-
	chr_pp_flag(guard_locks, A),
	(   A==off
	->  B=true
	;   A==on
	->  B='chr unlock'(C)
	;   A==error
	->  B='chr unerror_lock'(C)
	).
term_to_ast_term(A, B, D, C) :-
	(   atomic(A)
	->  B=atomic(A),
	    C=D
	;   compound(A)
	->  functor(A, E, F),
	    B=compound(E, F, H, A),
	    A=..[_|G],
	    maplist_dcg(chr_translate:term_to_ast_term,
			G,
			H,
			D,
			C)
	;   var(A)
	->  var_to_ast_term(A, D, B, C)
	).
var_to_ast_term(C, A, D, E) :-
	A=B-F,
	(   lookup_eq(B, C, D)
	->  E=A
	;   D=var(F, C),
	    H is F+1,
	    G=[C-D|B],
	    E=G-H
	).
chr_constraint_to_ast_constraint(B, A, G, H) :-
	A=chr_constraint(C/D, F, B),
	functor(B, C, D),
	B=..[_|E],
	maplist_dcg(chr_translate:term_to_ast_term,
		    E,
		    F,
		    G,
		    H).
rule_to_ast_rule(B, A) :-
	A=ast_rule(F, O, C, Q, D),
	B=rule(E, G, C, D),
	I=[]-1,
	(   E==[]
	->  F=propagation(H),
	    maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,
			G,
			H,
			I,
			J)
	;   G==[]
	->  F=simplification(H),
	    maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,
			E,
			H,
			I,
			J)
	;   F=simpagation(K, L),
	    maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,
			E,
			K,
			I,
			M),
	    maplist_dcg(chr_translate:chr_constraint_to_ast_constraint,
			G,
			L,
			M,
			J)
	),
	conj2list(C, N),
	maplist_dcg(chr_translate:term_to_ast_term,
		    N,
		    O,
		    J,
		    R),
	conj2list(D, P),
	maplist_dcg(chr_translate:term_to_ast_term,
		    P,
		    Q,
		    R,
		    _).
pragma_rule_to_ast_rule(pragma(A, _, _, _, _), B) :-
	rule_to_ast_rule(A, B).
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(B, A) :-
	ast_is_ground_(A, B).
ast_is_ground_(var(A, _), B) :-
	tree_set_memberchk(A, B).
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(_, _, A, _), B, C) :-
	ast_term_list_variables(A, B, C).
ast_term_variables(var(B, _), A, C) :-
	tree_set_add(A, B, C).
ast_term_list_variables(A, B, C) :-
	fold(A, chr_translate:ast_term_variables, B, C).
ast_constraint_variables(chr_constraint(_, A, _), B, C) :-
	ast_term_list_variables(A, B, C).
ast_constraint_list_variables(A, B, C) :-
	fold(A, chr_translate:ast_constraint_variables, B, C).
ast_head_variables(simplification(A), B, C) :-
	ast_constraint_list_variables(A, B, C).
ast_head_variables(propagation(A), B, C) :-
	ast_constraint_list_variables(A, B, C).
ast_head_variables(simpagation(A, C), B, E) :-
	ast_constraint_list_variables(A, B, D),
	ast_constraint_list_variables(C, D, E).
ast_var_memberchk(var(A, _), B) :-
	tree_set_memberchk(A, B).
ast_instantiate(B, A, C) :-
	ast_instantiate_(A, B, C).
ast_instantiate_(var(A, _), B, C) :-
	get_assoc(A, B, C).
ast_instantiate_(atomic(A), _, A).
ast_instantiate_(compound(B, C, E, _), D, A) :-
	functor(A, B, C),
	A=..[_|F],
	maplist(ast_instantiate(D), E, F).
ast_head_arg_matches_([], [], A, B, [], A, B).
ast_head_arg_matches_([silent(B-_)|D], [A|E], F, C, H, I, J) :- !,
	(   A==(+)
	->  ast_term_variables(B, G, C),
	    ast_head_arg_matches_(D,
				  E,
				  F,
				  G,
				  H,
				  I,
				  J)
	;   ast_head_arg_matches_(D,
				  E,
				  F,
				  C,
				  H,
				  I,
				  J)
	).
ast_head_arg_matches_([A-G|L], [D|M], C, E, F, B1, C1) :-
	(   A=var(B, _)
	->  (   get_assoc(B, C, H)
	    ->  (   D=(+)
		->  (   tree_set_memberchk(B, E)
		    ->  F=[G=H|I],
			J=E
		    ;   F=[G==H|I],
			tree_set_add(E, B, J)
		    )
		;   F=[G==H|I],
		    J=E
		),
		K=C
	    ;   put_assoc(B, C, G, K),
		F=I,
		(   D=(+)
		->  tree_set_add(E, B, J)
		;   J=E
		)
	    ),
	    Q=L,
	    R=M
	;   ground(A),
	    A='$chr_identifier_match'(O, N)
	->  identifier_label_atom(N, G, O, P),
	    F=[P|I],
	    C=K,
	    J=E,
	    Q=L,
	    R=M
	;   A=atomic(S)
	->  (   D=(+)
	    ->  F=[G=S|I]
	    ;   F=[G==S|I]
	    ),
	    C=K,
	    J=E,
	    Q=L,
	    R=M
	;   D==(+),
	    ast_is_ground(E, A)
	->  ast_instantiate(C, A, T),
	    F=[G=T|I],
	    C=K,
	    J=E,
	    Q=L,
	    R=M
	;   D==(?),
	    ast_is_ground(E, A)
	->  ast_instantiate(C, A, T),
	    F=[G==T|I],
	    C=K,
	    J=E,
	    Q=L,
	    R=M
	;   A=compound(U, V, X, _),
	    functor(W, U, V),
	    W=..[_|Y],
	    (   D=(+)
	    ->  F=[G=W|I]
	    ;   F=[nonvar(G), G=W|I]
	    ),
	    pairup(X, Y, Z),
	    append(Z, L, Q),
	    replicate(_, D, A1),
	    append(A1, M, R),
	    K=C,
	    J=E
	),
	ast_head_arg_matches_(Q,
			      R,
			      K,
			      J,
			      I,
			      B1,
			      C1).
:- 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([A|Q], D) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, E, F, G, H, I, J, K, L, M, N),
	      (   C/\1=:=1
	      ->  O=v(C, [D|E], F, G, H, I, J, K, L, M, N)
	      ;   P is C\/1,
		  O=v(P, [D], F, G, H, I, J, K, L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(1, [D], [], [], [], [], [], [], [], [], []))
	),
	attach_generate_empty_named_history_initialisation___1(Q,
							       D).
detach_generate_empty_named_history_initialisation___1([], _).
detach_generate_empty_named_history_initialisation___1([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, D, H, I, J, K, L, M, N, O, P),
	    (   C/\1=:=1
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -2,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   [],
				   H,
				   I,
				   J,
				   K,
				   L,
				   M,
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       F,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_generate_empty_named_history_initialisation___1(Q,
							       E).
attach_symbol_count___2([], _).
attach_symbol_count___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, F, G, H, I, J, K, L, M, N),
	      (   C/\2=:=2
	      ->  O=v(C, D, [E|F], G, H, I, J, K, L, M, N)
	      ;   P is C\/2,
		  O=v(P, D, [E], G, H, I, J, K, L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(2, [], [E], [], [], [], [], [], [], [], []))
	),
	attach_symbol_count___2(Q, E).
detach_symbol_count___2([], _).
detach_symbol_count___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, D, I, J, K, L, M, N, O, P),
	    (   C/\2=:=2
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -3,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   [],
				   I,
				   J,
				   K,
				   L,
				   M,
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       F,
			       I,
			       J,
			       K,
			       L,
			       M,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_symbol_count___2(Q, E).
attach_fresh_symbol___2([], _).
attach_fresh_symbol___2([A|Q], F) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, G, H, I, J, K, L, M, N),
	      (   C/\4=:=4
	      ->  O=v(C, D, E, [F|G], H, I, J, K, L, M, N)
	      ;   P is C\/4,
		  O=v(P, D, E, [F], H, I, J, K, L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(4, [], [], [F], [], [], [], [], [], [], []))
	),
	attach_fresh_symbol___2(Q, F).
detach_fresh_symbol___2([], _).
detach_fresh_symbol___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, D, J, K, L, M, N, O, P),
	    (   C/\4=:=4
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -5,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   [],
				   J,
				   K,
				   L,
				   M,
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       F,
			       J,
			       K,
			       L,
			       M,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_fresh_symbol___2(Q, E).
attach_background_info___2([], _).
attach_background_info___2([A|Q], G) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, H, I, J, K, L, M, N),
	      (   C/\8=:=8
	      ->  O=v(C, D, E, F, [G|H], I, J, K, L, M, N)
	      ;   P is C\/8,
		  O=v(P, D, E, F, [G], I, J, K, L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(8, [], [], [], [G], [], [], [], [], [], []))
	),
	attach_background_info___2(Q, G).
detach_background_info___2([], _).
detach_background_info___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, D, K, L, M, N, O, P),
	    (   C/\8=:=8
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -9,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   [],
				   K,
				   L,
				   M,
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       F,
			       K,
			       L,
			       M,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_background_info___2(Q, E).
attach_get_bg_info___2([], _).
attach_get_bg_info___2([A|Q], H) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, G, I, J, K, L, M, N),
	      (   C/\16=:=16
	      ->  O=v(C, D, E, F, G, [H|I], J, K, L, M, N)
	      ;   P is C\/16,
		  O=v(P, D, E, F, G, [H], J, K, L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(16, [], [], [], [], [H], [], [], [], [], []))
	),
	attach_get_bg_info___2(Q, H).
detach_get_bg_info___2([], _).
detach_get_bg_info___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, K, D, L, M, N, O, P),
	    (   C/\16=:=16
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -17,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   K,
				   [],
				   L,
				   M,
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       K,
			       F,
			       L,
			       M,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_get_bg_info___2(Q, E).
attach_type_definition___2([], _).
attach_type_definition___2([A|Q], I) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, G, H, J, K, L, M, N),
	      (   C/\32=:=32
	      ->  O=v(C, D, E, F, G, H, [I|J], K, L, M, N)
	      ;   P is C\/32,
		  O=v(P, D, E, F, G, H, [I], K, L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(32, [], [], [], [], [], [I], [], [], [], []))
	),
	attach_type_definition___2(Q, I).
detach_type_definition___2([], _).
detach_type_definition___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, K, L, D, M, N, O, P),
	    (   C/\32=:=32
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -33,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   K,
				   L,
				   [],
				   M,
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       K,
			       L,
			       F,
			       M,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_type_definition___2(Q, E).
attach_type_alias___2([], _).
attach_type_alias___2([A|Q], J) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, G, H, I, K, L, M, N),
	      (   C/\64=:=64
	      ->  O=v(C, D, E, F, G, H, I, [J|K], L, M, N)
	      ;   P is C\/64,
		  O=v(P, D, E, F, G, H, I, [J], L, M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(64, [], [], [], [], [], [], [J], [], [], []))
	),
	attach_type_alias___2(Q, J).
detach_type_alias___2([], _).
detach_type_alias___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, K, L, M, D, N, O, P),
	    (   C/\64=:=64
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -65,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   K,
				   L,
				   M,
				   [],
				   N,
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       F,
			       N,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_type_alias___2(Q, E).
attach_unalias_type___2([], _).
attach_unalias_type___2([A|Q], K) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, G, H, I, J, L, M, N),
	      (   C/\128=:=128
	      ->  O=v(C, D, E, F, G, H, I, J, [K|L], M, N)
	      ;   P is C\/128,
		  O=v(P, D, E, F, G, H, I, J, [K], M, N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(128, [], [], [], [], [], [], [], [K], [], []))
	),
	attach_unalias_type___2(Q, K).
detach_unalias_type___2([], _).
detach_unalias_type___2([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, K, L, M, N, D, O, P),
	    (   C/\128=:=128
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -129,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   K,
				   L,
				   M,
				   N,
				   [],
				   O,
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       N,
			       F,
			       O,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_unalias_type___2(Q, E).
attach_ast_static_type_check_var___4([], _).
attach_ast_static_type_check_var___4([A|Q], L) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, G, H, I, J, K, M, N),
	      (   C/\256=:=256
	      ->  O=v(C, D, E, F, G, H, I, J, K, [L|M], N)
	      ;   P is C\/256,
		  O=v(P, D, E, F, G, H, I, J, K, [L], N)
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(256, [], [], [], [], [], [], [], [], [L], []))
	),
	attach_ast_static_type_check_var___4(Q, L).
detach_ast_static_type_check_var___4([], _).
detach_ast_static_type_check_var___4([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, K, L, M, N, O, D, P),
	    (   C/\256=:=256
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -257,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   K,
				   L,
				   M,
				   N,
				   O,
				   [],
				   P))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       N,
			       O,
			       F,
			       P))
		)
	    ;   true
	    )
	;   true
	),
	detach_ast_static_type_check_var___4(Q, E).
attach_atomic_type___1([], _).
attach_atomic_type___1([A|Q], M) :-
	(   get_attr(A, chr_translate, B)
	->  ( B=v(C, D, E, F, G, H, I, J, K, L, N),
	      (   C/\512=:=512
	      ->  O=v(C, D, E, F, G, H, I, J, K, L, [M|N])
	      ;   P is C\/512,
		  O=v(P, D, E, F, G, H, I, J, K, L, [M])
	      )
	    ),
	    put_attr(A, chr_translate, O)
	;   put_attr(A,
		     chr_translate,
		     v(512, [], [], [], [], [], [], [], [], [], [M]))
	),
	attach_atomic_type___1(Q, M).
detach_atomic_type___1([], _).
detach_atomic_type___1([A|Q], E) :-
	(   get_attr(A, chr_translate, B)
	->  B=v(C, H, I, J, K, L, M, N, O, P, D),
	    (   C/\512=:=512
	    ->  'chr sbag_del_element'(D, E, F),
		(   F==[]
		->  G is C/\ -513,
		    (   G==0
		    ->  del_attr(A, chr_translate)
		    ;   put_attr(A,
				 chr_translate,
				 v(G,
				   H,
				   I,
				   J,
				   K,
				   L,
				   M,
				   N,
				   O,
				   P,
				   []))
		    )
		;   put_attr(A,
			     chr_translate,
			     v(C,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       N,
			       O,
			       P,
			       F))
		)
	    ;   true
	    )
	;   true
	),
	detach_atomic_type___1(Q, E).
attach_increment([], _).
attach_increment([A|U1], B) :-
	(   get_attr(A, chr_translate, C)
	->  ( B=v(H1, E, H, K, N, Q, T, W, Z, C1, F1),
	      C=v(I1, D, G, J, M, P, S, V, Y, B1, E1),
	      ( ( sort(D, F),
		  'chr merge_attributes'(E, F, K1)
		),
		( sort(G, I),
		  'chr merge_attributes'(H, I, L1)
		),
		( sort(J, L),
		  'chr merge_attributes'(K, L, M1)
		),
		( sort(M, O),
		  'chr merge_attributes'(N, O, N1)
		),
		( sort(P, R),
		  'chr merge_attributes'(Q, R, O1)
		),
		( sort(S, U),
		  'chr merge_attributes'(T, U, P1)
		),
		( sort(V, X),
		  'chr merge_attributes'(W, X, Q1)
		),
		( sort(Y, A1),
		  'chr merge_attributes'(Z, A1, R1)
		),
		( sort(B1, D1),
		  'chr merge_attributes'(C1, D1, S1)
		),
		sort(E1, G1),
		'chr merge_attributes'(F1, G1, T1)
	      ),
	      J1 is H1\/I1
	    ),
	    put_attr(A,
		     chr_translate,
		     v(J1,
		       K1,
		       L1,
		       M1,
		       N1,
		       O1,
		       P1,
		       Q1,
		       R1,
		       S1,
		       T1))
	;   put_attr(A, chr_translate, B)
	),
	attach_increment(U1, B).
attribute_goals(_, A, A).
attr_unify_hook(v(Q1, A, B, C, D, E, F, G, H, I, J), K) :-
	sort(A, N),
	sort(B, Q),
	sort(C, T),
	sort(D, W),
	sort(E, Z),
	sort(F, C1),
	sort(G, F1),
	sort(H, I1),
	sort(I, L1),
	sort(J, O1),
	(   var(K)
	->  (   get_attr(K, chr_translate, L)
	    ->  ( L=v(R1, M, P, S, V, Y, B1, E1, H1, K1, N1),
		  ( ( sort(M, O),
		      'chr merge_attributes'(N, O, T1)
		    ),
		    ( sort(P, R),
		      'chr merge_attributes'(Q, R, U1)
		    ),
		    ( sort(S, U),
		      'chr merge_attributes'(T, U, V1)
		    ),
		    ( sort(V, X),
		      'chr merge_attributes'(W, X, W1)
		    ),
		    ( sort(Y, A1),
		      'chr merge_attributes'(Z, A1, X1)
		    ),
		    ( sort(B1, D1),
		      'chr merge_attributes'(C1, D1, Y1)
		    ),
		    ( sort(E1, G1),
		      'chr merge_attributes'(F1, G1, Z1)
		    ),
		    ( sort(H1, J1),
		      'chr merge_attributes'(I1, J1, A2)
		    ),
		    ( sort(K1, M1),
		      'chr merge_attributes'(L1, M1, B2)
		    ),
		    sort(N1, P1),
		    'chr merge_attributes'(O1, P1, C2)
		  ),
		  S1 is Q1\/R1
		),
		put_attr(K,
			 chr_translate,
			 v(S1,
			   T1,
			   U1,
			   V1,
			   W1,
			   X1,
			   Y1,
			   Z1,
			   A2,
			   B2,
			   C2)),
		'$run_suspensions_generate_empty_named_history_initialisation___1'(N),
		'$run_suspensions_symbol_count___2'(Q),
		'$run_suspensions_fresh_symbol___2'(T),
		'$run_suspensions_background_info___2'(W1),
		'$run_suspensions_get_bg_info___2'(X1),
		'$run_suspensions_type_definition___2'(Y1),
		'$run_suspensions_type_alias___2'(Z1),
		'$run_suspensions_unalias_type___2'(A2),
		'$run_suspensions_ast_static_type_check_var___4'(B2),
		'$run_suspensions_atomic_type___1'(C2)
	    ;   put_attr(K,
			 chr_translate,
			 v(Q1,
			   N,
			   Q,
			   T,
			   W,
			   Z,
			   C1,
			   F1,
			   I1,
			   L1,
			   O1)),
		'$run_suspensions_generate_empty_named_history_initialisation___1'(N),
		'$run_suspensions_symbol_count___2'(Q),
		'$run_suspensions_fresh_symbol___2'(T),
		'$run_suspensions_background_info___2'(W),
		'$run_suspensions_get_bg_info___2'(Z),
		'$run_suspensions_type_definition___2'(C1),
		'$run_suspensions_type_alias___2'(F1),
		'$run_suspensions_unalias_type___2'(I1),
		'$run_suspensions_ast_static_type_check_var___4'(L1),
		'$run_suspensions_atomic_type___1'(O1)
	    )
	;   (   compound(K)
	    ->  term_variables(K, D2),
		attach_increment(D2,
				 v(Q1,
				   N,
				   Q,
				   T,
				   W,
				   Z,
				   C1,
				   F1,
				   I1,
				   L1,
				   O1))
	    ;   true
	    ),
	    '$run_suspensions_generate_empty_named_history_initialisation___1'(N),
	    '$run_suspensions_symbol_count___2'(Q),
	    '$run_suspensions_fresh_symbol___2'(T),
	    '$run_suspensions_background_info___2'(W),
	    '$run_suspensions_get_bg_info___2'(Z),
	    '$run_suspensions_type_definition___2'(C1),
	    '$run_suspensions_type_alias___2'(F1),
	    '$run_suspensions_unalias_type___2'(I1),
	    '$run_suspensions_ast_static_type_check_var___4'(L1),
	    '$run_suspensions_atomic_type___1'(O1)
	).
'$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|F]) :-
	A=suspension(_, B, C, _, E),
	(   B==active
	->  setarg(2, A, triggered),
	    ( D is C+1,
	      setarg(3, A, D)
	    ),
	    generate_empty_named_history_initialisation___1__0(E,
							       A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_generate_empty_named_history_initialisation___1'(F).
'$run_suspensions_symbol_count___2'([]).
'$run_suspensions_symbol_count___2'([A|E]) :-
	A=suspension(_, B, _, C, D),
	(   B==active
	->  setarg(2, A, triggered),
	    symbol_count___2__0(C, D, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_symbol_count___2'(E).
'$run_suspensions_fresh_symbol___2'([]).
'$run_suspensions_fresh_symbol___2'([A|G]) :-
	A=suspension(_, B, _, C, _, E, F),
	(   B==active
	->  setarg(2, A, triggered),
	    ( D is C+1,
	      setarg(4, A, D)
	    ),
	    fresh_symbol___2__0(E, F, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_fresh_symbol___2'(G).
'$run_suspensions_background_info___2'([]).
'$run_suspensions_background_info___2'([A|G]) :-
	A=suspension(_, F, _, B, _, D, E),
	setarg(2, A, triggered),
	C is B+1,
	setarg(4, A, C),
	background_info___2__0(D, E, A),
	(   F==triggered
	->  setarg(2, A, active)
	;   true
	),
	'$run_suspensions_background_info___2'(G).
'$run_suspensions_get_bg_info___2'([]).
'$run_suspensions_get_bg_info___2'([A|G]) :-
	A=suspension(_, B, _, C, _, E, F),
	(   B==active
	->  setarg(2, A, triggered),
	    ( D is C+1,
	      setarg(4, A, D)
	    ),
	    get_bg_info___2__0(E, F, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_get_bg_info___2'(G).
'$run_suspensions_type_definition___2'([]).
'$run_suspensions_type_definition___2'([A|G]) :-
	A=suspension(_, B, _, C, _, E, F),
	(   B==active
	->  setarg(2, A, triggered),
	    ( D is C+1,
	      setarg(4, A, D)
	    ),
	    type_definition___2__0(E, F, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_type_definition___2'(G).
'$run_suspensions_type_alias___2'([]).
'$run_suspensions_type_alias___2'([A|G]) :-
	A=suspension(_, B, _, C, _, E, F),
	(   B==active
	->  setarg(2, A, triggered),
	    ( D is C+1,
	      setarg(4, A, D)
	    ),
	    type_alias___2__0(E, F, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_type_alias___2'(G).
'$run_suspensions_unalias_type___2'([]).
'$run_suspensions_unalias_type___2'([A|E]) :-
	A=suspension(_, B, _, C, D),
	(   B==active
	->  setarg(2, A, triggered),
	    unalias_type___2__0(C, D, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_unalias_type___2'(E).
'$run_suspensions_ast_static_type_check_var___4'([]).
'$run_suspensions_ast_static_type_check_var___4'([A|G]) :-
	A=suspension(_, B, _, C, D, E, F),
	(   B==active
	->  setarg(2, A, triggered),
	    ast_static_type_check_var___4__0(C,
					     D,
					     E,
					     F,
					     A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_ast_static_type_check_var___4'(G).
'$run_suspensions_atomic_type___1'([]).
'$run_suspensions_atomic_type___1'([A|D]) :-
	A=suspension(_, B, _, C),
	(   B==active
	->  setarg(2, A, triggered),
	    atomic_type___1__0(C, A),
	    (   B==triggered
	    ->  setarg(2, A, active)
	    ;   true
	    )
	;   true
	),
	'$run_suspensions_atomic_type___1'(D).
'$enumerate_constraints'(A) :-
	(   nonvar(A)
	->  functor(A, B, _),
	    '$enumerate_constraints'(B, A)
	;   '$enumerate_constraints'(_, A)
	).
'$enumerate_constraints'(chr_source_file, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=chr_source_file(D).
'$enumerate_constraints'(target_module, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____target_module___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=target_module(D).
'$enumerate_constraints'(line_number, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=line_number(D, E).
'$enumerate_constraints'(indexed_argument, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=indexed_argument(D, E).
'$enumerate_constraints'(constraint_mode, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, _, D, E),
	C=constraint_mode(D, E).
'$enumerate_constraints'(none_suspended_on_variables, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',
		  A),
	member(B, A),
	B=suspension(_, _, _),
	C=none_suspended_on_variables.
'$enumerate_constraints'(store_type, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=store_type(D, E).
'$enumerate_constraints'(actual_store_types, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=actual_store_types(D, E).
'$enumerate_constraints'(assumed_store_type, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=assumed_store_type(D, E).
'$enumerate_constraints'(validate_store_type_assumption, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=validate_store_type_assumption(D).
'$enumerate_constraints'(rule_count, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=rule_count(D).
'$enumerate_constraints'(passive, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=passive(D, E).
'$enumerate_constraints'(occurrence, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
		  A),
	member(B, A),
	B=suspension(_, _, _, _, D, E, F, G, H),
	C=occurrence(D, E, F, G, H).
'$enumerate_constraints'(max_occurrence, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=max_occurrence(D, E).
'$enumerate_constraints'(allocation_occurrence, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=allocation_occurrence(D, E).
'$enumerate_constraints'(rule, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____rule___2', A),
	member(B, A),
	B=suspension(_, _, _, _, D, E),
	C=rule(D, E).
'$enumerate_constraints'(least_occurrence, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=least_occurrence(D, E).
'$enumerate_constraints'(constraint_index, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=constraint_index(D, E).
'$enumerate_constraints'(max_constraint_index, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____max_constraint_index___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=max_constraint_index(D).
'$enumerate_constraints'(identifier_size, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=identifier_size(D).
'$enumerate_constraints'(identifier_index, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=identifier_index(D, E, F).
'$enumerate_constraints'(type_indexed_identifier_size, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=type_indexed_identifier_size(D, E).
'$enumerate_constraints'(type_indexed_identifier_index, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F, G),
	C=type_indexed_identifier_index(D, E, F, G).
'$enumerate_constraints'(no_history, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=no_history(D).
'$enumerate_constraints'(history, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E, F),
	C=history(D, E, F).
'$enumerate_constraints'(indexing_spec, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=indexing_spec(D, E).
'$enumerate_constraints'(observation_analysis, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____observation_analysis___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=observation_analysis(D).
'$enumerate_constraints'(spawns, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
		  A),
	member(B, A),
	B=suspension(_, _, _, _, D, E, F),
	C=spawns(D, E, F).
'$enumerate_constraints'(spawns_all, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=spawns_all(D, E).
'$enumerate_constraints'(spawns_all_triggers, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, _, D, E),
	C=spawns_all_triggers(D, E).
'$enumerate_constraints'(spawns_all_triggers_implies_spawns_all, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',
		  A),
	member(B, A),
	B=suspension(_, _, _),
	C=spawns_all_triggers_implies_spawns_all.
'$enumerate_constraints'(empty_named_history_initialisations, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=empty_named_history_initialisations(D, E).
'$enumerate_constraints'(generate_empty_named_history_initialisation, C) :-
	nb_current('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
		   A),
	member(B, A),
	B=suspension(_, _, _, _, D),
	C=generate_empty_named_history_initialisation(D).
'$enumerate_constraints'(find_empty_named_histories, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',
		  A),
	member(B, A),
	B=suspension(_, _, _, _),
	C=find_empty_named_histories.
'$enumerate_constraints'(module_initializer, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=module_initializer(D).
'$enumerate_constraints'(actual_atomic_multi_hash_keys, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=actual_atomic_multi_hash_keys(D, E, F).
'$enumerate_constraints'(actual_ground_multi_hash_keys, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=actual_ground_multi_hash_keys(D, E, F).
'$enumerate_constraints'(actual_non_ground_multi_hash_key, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=actual_non_ground_multi_hash_key(D, E).
'$enumerate_constraints'(symbol_count, C) :-
	nb_current('$chr_store_global_list_chr_translate____symbol_count___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=symbol_count(D, E).
'$enumerate_constraints'(fresh_symbol, C) :-
	nb_current('$chr_store_global_list_chr_translate____fresh_symbol___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, _, _, D, E),
	C=fresh_symbol(D, E).
'$enumerate_constraints'(prolog_global_variable, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=prolog_global_variable(D).
'$enumerate_constraints'(background_info, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____background_info___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=background_info(D).
'$enumerate_constraints'(background_info, C) :-
	nb_current('$chr_store_global_list_chr_translate____background_info___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, _, _, D, E),
	C=background_info(D, E).
'$enumerate_constraints'(get_bg_info, C) :-
	nb_current('$chr_store_global_list_chr_translate____get_bg_info___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, _, _, D, E),
	C=get_bg_info(D, E).
'$enumerate_constraints'(get_bg_info_answer, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=get_bg_info_answer(D).
'$enumerate_constraints'(prev_guard_list, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
		  A),
	member(B, A),
	B=suspension(_, _, _, _, D, E, F, G, H, I),
	C=prev_guard_list(D, E, F, G, H, I).
'$enumerate_constraints'(set_all_passive, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D),
	C=set_all_passive(D).
'$enumerate_constraints'(precompute_head_matchings, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',
		  A),
	member(B, A),
	B=suspension(_, _, _, _),
	C=precompute_head_matchings.
'$enumerate_constraints'(make_head_matchings_explicit_memo_table, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=make_head_matchings_explicit_memo_table(D, E, F).
'$enumerate_constraints'(multiple_occ_constraints_checked, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=multiple_occ_constraints_checked(D).
'$enumerate_constraints'(type_definition, C) :-
	nb_current('$chr_store_global_list_chr_translate____type_definition___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, _, _, D, E),
	C=type_definition(D, E).
'$enumerate_constraints'(type_alias, C) :-
	nb_current('$chr_store_global_list_chr_translate____type_alias___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, _, _, D, E),
	C=type_alias(D, E).
'$enumerate_constraints'(constraint_type, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=constraint_type(D, E).
'$enumerate_constraints'(unalias_type, C) :-
	nb_current('$chr_store_global_list_chr_translate____unalias_type___2',
		   A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=unalias_type(D, E).
'$enumerate_constraints'(types_modes_condition, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E, F),
	C=types_modes_condition(D, E, F).
'$enumerate_constraints'(static_type_check, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=static_type_check(D, E).
'$enumerate_constraints'(ast_static_type_check_var, C) :-
	nb_current('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
		   A),
	member(B, A),
	B=suspension(_, _, _, D, E, F, G),
	C=ast_static_type_check_var(D, E, F, G).
'$enumerate_constraints'(ast_static_atomic_builtin_type_check_var, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F, G),
	C=ast_static_atomic_builtin_type_check_var(D, E, F, G).
'$enumerate_constraints'(dynamic_type_check, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
		  A),
	member(B, A),
	B=suspension(_, _, _, _),
	C=dynamic_type_check.
'$enumerate_constraints'(dynamic_type_check_clauses, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=dynamic_type_check_clauses(D).
'$enumerate_constraints'(atomic_type, C) :-
	nb_current('$chr_store_global_list_chr_translate____atomic_type___1',
		   A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=atomic_type(D).
'$enumerate_constraints'(stored, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=stored(D, E, F).
'$enumerate_constraints'(stored_complete, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E, F),
	C=stored_complete(D, E, F).
'$enumerate_constraints'(check_all_passive, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=check_all_passive(D, E).
'$enumerate_constraints'(constraints_code1, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____constraints_code1___3',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E, F),
	C=constraints_code1(D, E, F).
'$enumerate_constraints'(memo_has_active_occurrence, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=memo_has_active_occurrence(D).
'$enumerate_constraints'(use_auxiliary_predicate, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=use_auxiliary_predicate(D).
'$enumerate_constraints'(use_auxiliary_predicate, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=use_auxiliary_predicate(D, E).
'$enumerate_constraints'(use_auxiliary_module, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=use_auxiliary_module(D).
'$enumerate_constraints'(functional_dependency, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F, G),
	C=functional_dependency(D, E, F, G).
'$enumerate_constraints'(initial_call_pattern, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D),
	C=initial_call_pattern(D).
'$enumerate_constraints'(call_pattern, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=call_pattern(D).
'$enumerate_constraints'(final_answer_pattern, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=final_answer_pattern(D, E).
'$enumerate_constraints'(abstract_constraints, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=abstract_constraints(D).
'$enumerate_constraints'(depends_on, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=depends_on(D, E).
'$enumerate_constraints'(depends_on_ap, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E, F, G),
	C=depends_on_ap(D, E, F, G).
'$enumerate_constraints'(depends_on_goal, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=depends_on_goal(D, E).
'$enumerate_constraints'(ai_observed_internal, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=ai_observed_internal(D, E).
'$enumerate_constraints'(ai_not_observed_internal, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=ai_not_observed_internal(D, E).
'$enumerate_constraints'(ai_not_observed, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=ai_not_observed(D, E).
'$enumerate_constraints'(depends_on_as, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E, F),
	C=depends_on_as(D, E, F).
'$enumerate_constraints'(ai_observation_gather_results, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',
		  A),
	member(B, A),
	B=suspension(_, _, _),
	C=ai_observation_gather_results.
'$enumerate_constraints'(ai_observation_memoed_simplification_rest_heads, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=ai_observation_memoed_simplification_rest_heads(D, E, F).
'$enumerate_constraints'(ai_observation_memoed_propagation_rest_heads, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=ai_observation_memoed_propagation_rest_heads(D, E, F).
'$enumerate_constraints'(ai_observation_memoed_abstract_goal, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=ai_observation_memoed_abstract_goal(D, E).
'$enumerate_constraints'(ai_observation_memo_abstract_goal, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=ai_observation_memo_abstract_goal(D, E).
'$enumerate_constraints'(partial_wake_analysis, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',
		  A),
	member(B, A),
	B=suspension(_, _, _, _),
	C=partial_wake_analysis.
'$enumerate_constraints'(no_partial_wake, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=no_partial_wake(D).
'$enumerate_constraints'(phase_end, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=phase_end(D).
'$enumerate_constraints'(delay_phase_end, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=delay_phase_end(D, E).
'$enumerate_constraints'(does_use_history, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=does_use_history(D, E).
'$enumerate_constraints'(does_use_field, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=does_use_field(D, E).
'$enumerate_constraints'(uses_state, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=uses_state(D, E).
'$enumerate_constraints'(if_used_state, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E, F, G, H),
	C=if_used_state(D, E, F, G, H).
'$enumerate_constraints'(used_states_known, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',
		  A),
	member(B, A),
	B=suspension(_, _, _),
	C=used_states_known.
'$enumerate_constraints'(stored_assertion, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D),
	C=stored_assertion(D).
'$enumerate_constraints'(never_stored_default, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E),
	C=never_stored_default(D, E).
'$enumerate_constraints'(never_stored_rules, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',
		  A),
	member(B, A),
	B=suspension(_, _, _, D, E),
	C=never_stored_rules(D, E).
'$enumerate_constraints'(continuation_occurrence, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=continuation_occurrence(D, E, F).
'$enumerate_constraints'(skip_to_next_id, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, _, D, E),
	C=skip_to_next_id(D, E).
'$enumerate_constraints'(set_occurrence_code_id, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=set_occurrence_code_id(D, E, F).
'$enumerate_constraints'(occurrence_code_id, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',
		  A),
	value_ht(A, B),
	B=suspension(_, _, D, E, F),
	C=occurrence_code_id(D, E, F).
'$enumerate_constraints'(chr_constants, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',
		  A),
	member(B, A),
	B=suspension(_, _, _, D),
	C=chr_constants(D).
'$enumerate_constraints'(print_chr_constants, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____print_chr_constants___0',
		  A),
	member(B, A),
	B=suspension(_, _, _),
	C=print_chr_constants.
'$via1_multi_hash_line_number___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_indexed_argument___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_indexed_argument___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_constraint_mode___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_store_type___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_actual_store_types___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_assumed_store_type___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_validate_store_type_assumption___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_passive___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_passive___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-15'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-125'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-134'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-3'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-13'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-34'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence___5-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_max_occurrence___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_allocation_occurrence___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_allocation_occurrence___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_rule___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C).
'$via1_multi_hash_least_occurrence___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_least_occurrence___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_constraint_index___2-2'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_constraint_index___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_identifier_index___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_type_indexed_identifier_size___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_type_indexed_identifier_index___4-123'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_type_indexed_identifier_index___4-23'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_no_history___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',
		  A),
	lookup_ht(A, B, C).
'$chr_store_constants_chr_translate____history___3___[3]'([], '$chr_store_constants_chr_translate____history___3___[3]___[]').
'$via1_multi_hash_history___3-2'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_history___3-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_indexing_spec___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns___3-13'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns___3-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1', A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns___3-3'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3', A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns___3-123'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns_all___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns_all___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns_all_triggers___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_spawns_all_triggers___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_actual_atomic_multi_hash_keys___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_actual_atomic_multi_hash_keys___3-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_actual_ground_multi_hash_keys___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_actual_ground_multi_hash_keys___3-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_actual_non_ground_multi_hash_key___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_prolog_global_variable___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_prev_guard_list___6-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_set_all_passive___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_make_head_matchings_explicit_memo_table___3-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_constraint_type___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ast_static_atomic_builtin_type_check_var___4-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ast_static_atomic_builtin_type_check_var___4-13'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_stored___3-13'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_stored___3-123'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_stored_complete___3-13'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_stored_complete___3-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_check_all_passive___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_check_all_passive___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_memo_has_active_occurrence___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_use_auxiliary_predicate___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_use_auxiliary_predicate___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_use_auxiliary_predicate___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_use_auxiliary_module___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_functional_dependency___4-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_functional_dependency___4-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_initial_call_pattern___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_call_pattern___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_final_answer_pattern___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on___2-2'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on_ap___4-2'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on_ap___4-3'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on_goal___2-2'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ai_observed_internal___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ai_not_observed_internal___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ai_not_observed___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on_as___3-3'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_depends_on_as___3-2'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ai_observation_memoed_simplification_rest_heads___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ai_observation_memoed_propagation_rest_heads___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_ai_observation_memoed_abstract_goal___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_no_partial_wake___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_phase_end___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_delay_phase_end___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_does_use_history___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_does_use_history___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_does_use_field___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_uses_state___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_if_used_state___5-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_stored_assertion___1-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_never_stored_default___2-1'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_continuation_occurrence___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_skip_to_next_id___2-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_set_occurrence_code_id___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	lookup_ht(A, B, C).
'$via1_multi_hash_occurrence_code_id___3-12'(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',
		  A),
	lookup_ht(A, B, C).
'$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(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',
		  A),
	(   member(B, A),
	    B=suspension(_, active, _, _), !
	;    !,
	    chr_source_file___1__0__0__2(A, C)
	).
chr_source_file___1__0__0__2([], A) :-
	chr_source_file___1__1(A).
chr_source_file___1__0__0__2([A|F], G) :-
	(   A=suspension(_, active, _, _)
	->  ( setarg(2, A, removed),
	      arg(3, A, B),
	      (   var(B)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',
			    C),
		  C=[_|D],
		  b_setval('$chr_store_global_ground_chr_translate____chr_source_file___1',
			   D),
		  (   D=[E|_]
		  ->  setarg(3, E, _)
		  ;   true
		  )
	      ;   B=[_, _|D],
		  setarg(2, B, D),
		  (   D=[E|_]
		  ->  setarg(3, E, B)
		  ;   true
		  )
	      )
	    ),
	    chr_source_file___1__0__0__2(F, G)
	;   chr_source_file___1__0__0__2(F, G)
	).
chr_source_file(A) :-
	chr_source_file___1__1(A).
chr_source_file___1__1(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',
		  D),
	E=[C|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(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____chr_source_file___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, D), !,
	C=D.
get_chr_source_file(user).
target_module(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____target_module___1',
		  A),
	(   member(B, A),
	    B=suspension(_, active, _, _), !
	;    !,
	    target_module___1__0__0__2(A, C)
	).
target_module___1__0__0__2([], A) :-
	target_module___1__1(A).
target_module___1__0__0__2([A|F], G) :-
	(   A=suspension(_, active, _, _)
	->  ( setarg(2, A, removed),
	      arg(3, A, B),
	      (   var(B)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____target_module___1',
			    C),
		  C=[_|D],
		  b_setval('$chr_store_global_ground_chr_translate____target_module___1',
			   D),
		  (   D=[E|_]
		  ->  setarg(3, E, _)
		  ;   true
		  )
	      ;   B=[_, _|D],
		  setarg(2, B, D),
		  (   D=[E|_]
		  ->  setarg(3, E, B)
		  ;   true
		  )
	      )
	    ),
	    target_module___1__0__0__2(F, G)
	;   target_module___1__0__0__2(F, G)
	).
target_module(A) :-
	target_module___1__1(A).
target_module___1__1(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____target_module___1',
		  D),
	E=[C|D],
	b_setval('$chr_store_global_ground_chr_translate____target_module___1',
		 E),
	(   D=[F|_]
	->  setarg(3, F, E)
	;   true
	).
get_target_module(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____target_module___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, D), !,
	C=D.
get_target_module(user).
line_number(B, E) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',
		    A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _), !
	;    !,
	    line_number___2__0__0__2(C, B, E)
	).
line_number___2__0__0__2([], A, B) :-
	line_number___2__1(A, B).
line_number___2__0__0__2([A|E], C, F) :-
	(   A=suspension(_, active, B, _),
	    B==C
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',
			D),
	      delete_ht(D, C, A)
	    ),
	    line_number___2__0__0__2(E, C, F)
	;   line_number___2__0__0__2(E, C, F)
	).
line_number(A, B) :-
	line_number___2__1(A, B).
line_number___2__1(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',
		  D),
	insert_ht(D, A, E).
get_line_number(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____line_number___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
get_line_number(_, 0).
indexed_argument(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
indexed_argument(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',
		  D),
	insert_ht(D, A, E),
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',
		  F),
	insert_ht(F, k(A, B), E).
is_indexed_argument(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
is_indexed_argument(_, _) :-
	fail.
constraint_mode(A, B) :-
	constraint_mode___2__0(A, B, _).
constraint_mode___2__0(B, E, F) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		    A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _, _, _), !
	;    !,
	    constraint_mode___2__0__0__2(C, B, E, F)
	).
constraint_mode___2__0__0__2([], A, B, C) :-
	constraint_mode___2__1(A, B, C).
constraint_mode___2__0__0__2([A|I], C, J, K) :-
	(   A=suspension(_, active, _, _, B, _),
	    B==C
	->  ( setarg(2, A, removed),
	      ( arg(4, A, D),
		(   var(D)
		->  nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			      E),
		    E=[_|F],
		    b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			     F),
		    (   F=[G|_]
		    ->  setarg(4, G, _)
		    ;   true
		    )
		;   D=[_, _|F],
		    setarg(2, D, F),
		    (   F=[G|_]
		    ->  setarg(4, G, D)
		    ;   true
		    )
		)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
			H),
	      delete_ht(H, C, A)
	    ),
	    constraint_mode___2__0__0__2(I, C, J, K)
	;   constraint_mode___2__0__0__2(I, C, J, K)
	).
constraint_mode___2__0(A, B, C) :-
	constraint_mode___2__1(A, B, C).
constraint_mode___2__1(A, C, B) :-
	A=F/G,
	nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',
		  E), !,
	B=suspension(D, not_stored_yet, t, _, A, C),
	'chr gen_id'(D),
	constraint_mode___2__1__0__7(E,
				     A,
				     C,
				     B,
				     F,
				     G).
constraint_mode___2__1__0__7([], A, B, C, _, _) :-
	constraint_mode___2__2(A, B, C).
constraint_mode___2__1__0__7([A|C1], Q, S, K, E, F) :-
	(   ( A=suspension(_, active, _, B, C, R),
	      B=[D|Z],
	      C=[V|A1]
	    ),
	    functor(D, E, F)
	->  ( setarg(2, A, removed),
	      arg(3, A, G),
	      (   var(G)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',
			    H),
		  H=[_|I],
		  b_setval('$chr_store_global_ground_chr_translate____types_modes_condition___3',
			   I),
		  (   I=[J|_]
		  ->  setarg(3, J, _)
		  ;   true
		  )
	      ;   G=[_, _|I],
		  setarg(2, G, I),
		  (   I=[J|_]
		  ->  setarg(3, J, G)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, K, L),
	      setarg(2, K, active),
	      (   L==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			      M),
		    N=[K|M],
		    b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			     N),
		    (   M=[O|_]
		    ->  setarg(4, O, N)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
			    P),
		  insert_ht(P, Q, K)
	      ;   true
	      )
	    ),
	    ( D=..[_|T],
	      R=(U, Y, B1),
	      modes_condition(S, T, U),
	      get_constraint_type_det(E/F, W),
	      V=..[_|X],
	      types_condition(W, T, X, S, Y),
	      types_modes_condition(Z, A1, B1)
	    ),
	    (   K=suspension(_, active, _, _, _, _)
	    ->  setarg(2, K, inactive),
		constraint_mode___2__1__0__7(C1,
					     Q,
					     S,
					     K,
					     E,
					     F)
	    ;   true
	    )
	;   constraint_mode___2__1__0__7(C1,
					 Q,
					 S,
					 K,
					 E,
					 F)
	).
constraint_mode___2__1(B, C, A) :-
	A=suspension(D, not_stored_yet, t, _, B, C),
	'chr gen_id'(D),
	constraint_mode___2__2(B, C, A).
constraint_mode___2__2(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		  A),
	lookup_ht(A, B, C), !,
	constraint_mode___2__2__0__8(C, B, D, E).
constraint_mode___2__2__0__8([], A, B, C) :-
	constraint_mode___2__3(A, B, C).
constraint_mode___2__2__0__8([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, _, B, _, E, F, G),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',
		      D)
	->  constraint_mode___2__2__1__8(D,
					 E,
					 F,
					 G,
					 A,
					 H,
					 C,
					 I,
					 J)
	;   constraint_mode___2__2__0__8(H, C, I, J)
	).
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([A|E], C, F, G, H, I, J, K, L) :-
	(   A=suspension(_, active, _, _),
	    nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      B),
	    lookup_ht(B, C, D)
	->  constraint_mode___2__2__2__8(D,
					 A,
					 E,
					 C,
					 F,
					 G,
					 H,
					 I,
					 J,
					 K,
					 L)
	;   constraint_mode___2__2__1__8(E,
					 C,
					 F,
					 G,
					 H,
					 I,
					 J,
					 K,
					 L)
	).
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([A|X], D, Y, C, O, P, E, Z, M, U, F) :-
	(   A=suspension(_, active, _, _, B, N),
	    B==C,
	    G=t(330, D, E, A, F),
	    '$novel_production'(D, G),
	    '$novel_production'(E, G),
	    '$novel_production'(A, G),
	    '$novel_production'(F, G)
	->  '$extend_history'(F, G),
	    ( arg(2, F, H),
	      setarg(2, F, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			      I),
		    J=[F|I],
		    b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(4, K, J)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
			    L),
		  insert_ht(L, M, F)
	      ;   true
	      )
	    ),
	    ( N=pragma(rule(Q, W, S, _), _, _, _, _),
	      (   is_passive(C, O)
	      ->  true
	      ;   P==simplification
	      ->  select(R, Q, _),
		  R=..[_|T],
		  term_variables(S, V),
		  partial_wake_args(T, U, V, M)
	      ;   select(R, W, _),
		  R=..[_|T],
		  term_variables(S, V),
		  partial_wake_args(T, U, V, M)
	      )
	    ),
	    (   F=suspension(_, active, _, _, _, _)
	    ->  setarg(2, F, inactive),
		constraint_mode___2__2__2__8(X,
					     D,
					     Y,
					     C,
					     O,
					     P,
					     E,
					     Z,
					     M,
					     U,
					     F)
	    ;   true
	    )
	;   constraint_mode___2__2__2__8(X,
					 D,
					 Y,
					 C,
					 O,
					 P,
					 E,
					 Z,
					 M,
					 U,
					 F)
	).
constraint_mode___2__2(A, B, C) :-
	constraint_mode___2__3(A, B, C).
constraint_mode___2__3(G, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',
			C),
	      D=[A|C],
	      b_setval('$chr_store_global_ground_chr_translate____constraint_mode___2',
		       D),
	      (   C=[E|_]
	      ->  setarg(4, E, D)
	      ;   true
	      )
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		      F),
	    insert_ht(F, G, A)
	;   true
	).
get_constraint_mode(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, F), !,
	E=F.
get_constraint_mode(_/A, B) :-
	replicate(A, ?, B).
may_trigger(A) :-
	\+ has_active_occurrence(A), !,
	fail.
may_trigger(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, I),
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _, H),
	nth1(H, I, J),
	J\==(+), !,
	is_stored(B).
may_trigger(_) :-
	chr_pp_flag(debugable, on).
only_ground_indexed_arguments(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, I),
	nb_getval('$chr_store_multi_hash_chr_translate____indexed_argument___2-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _, H),
	nth1(H, I, 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),
	member(B, A),
	B=suspension(_, active, _), !.
none_suspended_on_variables :-
	B=suspension(A, active, _),
	'chr gen_id'(A),
	nb_getval('$chr_store_global_ground_chr_translate____none_suspended_on_variables___0',
		  C),
	D=[B|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),
	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(B, C, A) :-
	chr_pp_flag(verbose, on), !,
	A=suspension(D, active, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		  E),
	insert_ht(E, B, A),
	format('The indexes for ~w are:\n', [B]),
	format_storetype(C),
	(   A=suspension(_, active, _, _)
	->  setarg(2, A, inactive),
	    store_type___2__1(B, C, A)
	;   true
	).
store_type___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	store_type___2__1(B, C, A).
store_type___2__1(B, _, J) :-
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _, M), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  H),
	delete_ht(H, B, D),
	setarg(2, G, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  I),
	delete_ht(I, B, G),
	(   var(J)
	->  true
	;   arg(2, J, K),
	    setarg(2, J, removed),
	    (   K==not_stored_yet
	    ->  true
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
			  L),
		delete_ht(L, B, J)
	    )
	),
	store_type(B, multi_store(M)).
store_type___2__1(D, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		      C),
	    insert_ht(C, D, A)
	;   true
	).
get_store_type(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
get_store_type(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
get_store_type(_, default).
update_store_type(B, E) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _, F)
	),
	(   memberchk(E, F), !
	;    !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		      G),
	    delete_ht(G, B, D),
	    actual_store_types(B, [E|F])
	).
update_store_type(A, B) :-
	actual_store_types(A, [B]).
actual_store_types(B, K) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, I, P),
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  H),
	delete_ht(H, k(B, I), D),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
		  J),
	delete_ht(J, B, D),
	selectchk(multi_hash([I]), K, R),
	I=[L],
	(   get_constraint_arg_type(B, L, M),
	    enumerated_atomic_type(M, N)
	->  O=N,
	    Q=complete
	;   O=P,
	    Q=incomplete
	),
	actual_store_types(B,
			   
			   [ atomic_constants(I, O, Q)
			   | R
			   ]).
actual_store_types(B, P) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, I, N),
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  H),
	delete_ht(H, k(B, I), D),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
		  J),
	delete_ht(J, B, D),
	(   I=[K],
	    get_constraint_arg_type(B, K, L),
	    L=chr_enum(M)
	->  O=complete
	;   M=N,
	    O=incomplete
	),
	selectchk(multi_hash([I]), P, Q),
	actual_store_types(B,
			   
			   [ ground_constants(I, M, O)
			   | Q
			   ]).
actual_store_types(B, E) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _)
	),
	(   (   memberchk(multi_hash([[F]]), E),
		(   get_constraint_type(B, G),
		    nth1(F, G, H),
		    enumerated_atomic_type(H, I), !,
		    selectchk(multi_hash([[F]]), E, J),
		    actual_store_types(B,
				       
				       [ atomic_constants([F],
							  I,
							  complete)
				       | J
				       ])
		;   get_constraint_arg_type(B, F, K),
		    K=chr_enum(L), !,
		    selectchk(multi_hash([[F]]), E, M),
		    actual_store_types(B,
				       
				       [ ground_constants([F],
							  L,
							  complete)
				       | M
				       ])
		)
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
			  N),
		lookup_ht(N, B, O),
		member(P, O),
		P=suspension(_, active, _, _), !,
		setarg(2, D, removed),
		nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			  Q),
		delete_ht(Q, B, D),
		setarg(2, P, removed),
		nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
			  R),
		delete_ht(R, B, P),
		(   maplist(partial_store, E)
		->  S=[global_ground|E]
		;   S=E
		),
		store_type(B, multi_store(S))
	    )
	;   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		      T),
	    lookup_ht(T, B, U),
	    member(V, U),
	    V=suspension(_, active, _, _), !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		      W),
	    delete_ht(W, B, D),
	    setarg(2, V, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		      X),
	    delete_ht(X, B, V),
	    store_type(B, multi_store(E))
	).
actual_store_types(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  D),
	insert_ht(D, A, E).
assumed_store_type(B, _) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _)
	),
	(   (   nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
			  E),
		lookup_ht(E, B, F),
		member(G, F),
		G=suspension(_, active, _, J), !,
		setarg(2, D, removed),
		nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			  H),
		delete_ht(H, B, D),
		setarg(2, G, removed),
		nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
			  I),
		delete_ht(I, B, G),
		(   maplist(partial_store, J)
		->  K=[global_ground|J]
		;   K=J
		),
		store_type(B, 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, B, D),
		store_type(B, default)
	    )
	;    !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		      M),
	    delete_ht(M, B, D),
	    store_type(B, global_ground)
	).
assumed_store_type(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		  D),
	insert_ht(D, A, E).
validate_store_type_assumption(A) :-
	validate_store_type_assumption___1__0(A, _).
validate_store_type_assumption___1__0(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, E), !,
	C=suspension(D, not_stored_yet, B),
	'chr gen_id'(D),
	validate_store_type_assumption___1__0__0__1(E, B, C).
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([A|V], C, K) :-
	(   ( A=suspension(_, active, B, N),
	      B==C
	    ),
	    ( ground(C),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
			D),
	      lookup_ht(D, C, E)
	    ),
	    member(F, E),
	    F=suspension(_, active, _, I, S)
	->  ( ( setarg(2, A, removed),
		nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
			  G),
		delete_ht(G, C, A)
	      ),
	      setarg(2, F, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
			  H),
		delete_ht(H, k(C, I), F)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
			J),
	      delete_ht(J, C, F)
	    ),
	    ( arg(2, K, L),
	      setarg(2, K, active),
	      (   L==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			    M),
		  insert_ht(M, C, K)
	      ;   true
	      )
	    ),
	    ( selectchk(multi_hash([I]), N, U),
	      I=[O],
	      (   get_constraint_arg_type(C, O, P),
		  enumerated_atomic_type(P, Q)
	      ->  R=Q,
		  T=complete
	      ;   R=S,
		  T=incomplete
	      ),
	      actual_store_types(C,
				 
				 [ atomic_constants(I, R, T)
				 | U
				 ])
	    ),
	    (   K=suspension(_, active, _)
	    ->  setarg(2, K, inactive),
		validate_store_type_assumption___1__0__0__1(V,
							    C,
							    K)
	    ;   true
	    )
	;   validate_store_type_assumption___1__0__0__1(V,
							C,
							K)
	).
validate_store_type_assumption___1__0(B, A) :-
	A=suspension(C, not_stored_yet, B),
	'chr gen_id'(C),
	validate_store_type_assumption___1__1(B, A).
validate_store_type_assumption___1__1(B, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, C), !,
	validate_store_type_assumption___1__1__0__2(C, B, D).
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([A|U], C, K) :-
	(   ( A=suspension(_, active, B, S),
	      B==C
	    ),
	    ( ground(C),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
			D),
	      lookup_ht(D, C, E)
	    ),
	    member(F, E),
	    F=suspension(_, active, _, I, Q)
	->  ( ( setarg(2, A, removed),
		nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
			  G),
		delete_ht(G, C, A)
	      ),
	      setarg(2, F, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
			  H),
		delete_ht(H, k(C, I), F)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
			J),
	      delete_ht(J, C, F)
	    ),
	    ( arg(2, K, L),
	      setarg(2, K, active),
	      (   L==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			    M),
		  insert_ht(M, C, K)
	      ;   true
	      )
	    ),
	    ( (   I=[N],
		  get_constraint_arg_type(C, N, O),
		  O=chr_enum(P)
	      ->  R=complete
	      ;   P=Q,
		  R=incomplete
	      ),
	      selectchk(multi_hash([I]), S, T),
	      actual_store_types(C,
				 
				 [ ground_constants(I, P, R)
				 | T
				 ])
	    ),
	    (   K=suspension(_, active, _)
	    ->  setarg(2, K, inactive),
		validate_store_type_assumption___1__1__0__2(U,
							    C,
							    K)
	    ;   true
	    )
	;   validate_store_type_assumption___1__1__0__2(U,
							C,
							K)
	).
validate_store_type_assumption___1__1(A, B) :-
	validate_store_type_assumption___1__2(A, B).
validate_store_type_assumption___1__2(B, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, C), !,
	validate_store_type_assumption___1__2__0__3(C, B, D).
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([A|N], C, I) :-
	(   ( A=suspension(_, active, B, D),
	      B==C
	    ),
	    memberchk(multi_hash([[E]]), D),
	    get_constraint_type(C, F),
	    nth1(E, F, G),
	    enumerated_atomic_type(G, L)
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
			H),
	      delete_ht(H, C, A)
	    ),
	    ( arg(2, I, J),
	      setarg(2, I, active),
	      (   J==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			    K),
		  insert_ht(K, C, I)
	      ;   true
	      )
	    ),
	    ( selectchk(multi_hash([[E]]), D, M),
	      actual_store_types(C,
				 
				 [ atomic_constants([E],
						    L,
						    complete)
				 | M
				 ])
	    ),
	    (   I=suspension(_, active, _)
	    ->  setarg(2, I, inactive),
		validate_store_type_assumption___1__2__0__3(N,
							    C,
							    I)
	    ;   true
	    )
	;   validate_store_type_assumption___1__2__0__3(N,
							C,
							I)
	).
validate_store_type_assumption___1__2(A, B) :-
	validate_store_type_assumption___1__3(A, B).
validate_store_type_assumption___1__3(B, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, C), !,
	validate_store_type_assumption___1__3__0__4(C, B, D).
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([A|M], C, H) :-
	(   ( A=suspension(_, active, B, D),
	      B==C
	    ),
	    memberchk(multi_hash([[E]]), D),
	    get_constraint_arg_type(C, E, F),
	    F=chr_enum(K)
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
			G),
	      delete_ht(G, C, A)
	    ),
	    ( arg(2, H, I),
	      setarg(2, H, active),
	      (   I==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			    J),
		  insert_ht(J, C, H)
	      ;   true
	      )
	    ),
	    ( selectchk(multi_hash([[E]]), D, L),
	      actual_store_types(C,
				 
				 [ ground_constants([E],
						    K,
						    complete)
				 | L
				 ])
	    ),
	    (   H=suspension(_, active, _)
	    ->  setarg(2, H, inactive),
		validate_store_type_assumption___1__3__0__4(M,
							    C,
							    H)
	    ;   true
	    )
	;   validate_store_type_assumption___1__3__0__4(M,
							C,
							H)
	).
validate_store_type_assumption___1__3(A, B) :-
	validate_store_type_assumption___1__4(A, B).
validate_store_type_assumption___1__4(B, J) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _, M)
	),
	(   nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		      E),
	    lookup_ht(E, B, F),
	    member(G, F),
	    G=suspension(_, active, _, _), !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		      H),
	    delete_ht(H, B, D),
	    setarg(2, G, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		      I),
	    delete_ht(I, B, G),
	    (   var(J)
	    ->  true
	    ;   arg(2, J, K),
		setarg(2, J, removed),
		(   K==not_stored_yet
		->  true
		;   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			      L),
		    delete_ht(L, B, J)
		)
	    ),
	    (   maplist(partial_store, M)
	    ->  N=[global_ground|M]
	    ;   N=M
	    ),
	    store_type(B, multi_store(N))
	;   nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		      O),
	    lookup_ht(O, B, P),
	    member(Q, P),
	    Q=suspension(_, active, _, _), !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		      R),
	    delete_ht(R, B, D),
	    setarg(2, Q, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____store_type___2-1',
		      S),
	    delete_ht(S, B, Q),
	    (   var(J)
	    ->  true
	    ;   arg(2, J, T),
		setarg(2, J, removed),
		(   T==not_stored_yet
		->  true
		;   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			      U),
		    delete_ht(U, B, J)
		)
	    ),
	    store_type(B, multi_store(M))
	).
validate_store_type_assumption___1__4(B, F) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _, _)
	),
	(   chr_pp_flag(debugable, on), !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		      E),
	    delete_ht(E, B, D),
	    (   var(F)
	    ->  true
	    ;   arg(2, F, G),
		setarg(2, F, removed),
		(   G==not_stored_yet
		->  true
		;   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			      H),
		    delete_ht(H, B, F)
		)
	    ),
	    store_type(B, default)
	;    !,
	    setarg(2, D, removed),
	    nb_getval('$chr_store_multi_hash_chr_translate____assumed_store_type___2-1',
		      I),
	    delete_ht(I, B, D),
	    (   var(F)
	    ->  true
	    ;   arg(2, F, J),
		setarg(2, F, removed),
		(   J==not_stored_yet
		->  true
		;   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			      K),
		    delete_ht(K, B, F)
		)
	    ),
	    store_type(B, global_ground)
	).
validate_store_type_assumption___1__4(D, A) :-
	(   var(A)
	->  true
	;   arg(2, A, B),
	    setarg(2, A, removed),
	    (   B==not_stored_yet
	    ->  true
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
			  C),
		delete_ht(C, D, A)
	    )
	).
rule_count(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',
		  A),
	(   member(B, A),
	    B=suspension(_, active, _, _), !
	;    !,
	    rule_count___1__0__0__2(A, C)
	).
rule_count___1__0__0__2([], A) :-
	rule_count___1__1(A).
rule_count___1__0__0__2([A|F], G) :-
	(   A=suspension(_, active, _, _)
	->  ( setarg(2, A, removed),
	      arg(3, A, B),
	      (   var(B)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',
			    C),
		  C=[_|D],
		  b_setval('$chr_store_global_ground_chr_translate____rule_count___1',
			   D),
		  (   D=[E|_]
		  ->  setarg(3, E, _)
		  ;   true
		  )
	      ;   B=[_, _|D],
		  setarg(2, B, D),
		  (   D=[E|_]
		  ->  setarg(3, E, B)
		  ;   true
		  )
	      )
	    ),
	    rule_count___1__0__0__2(F, G)
	;   rule_count___1__0__0__2(F, G)
	).
rule_count(A) :-
	rule_count___1__1(A).
rule_count___1__1(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',
		  D),
	E=[C|D],
	b_setval('$chr_store_global_ground_chr_translate____rule_count___1',
		 E),
	(   D=[F|_]
	->  setarg(3, F, E)
	;   true
	).
inc_rule_count(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____rule_count___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____rule_count___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	G is H+1,
	rule_count(G).
inc_rule_count(1) :-
	rule_count(1).
passive(A, B) :-
	passive___2__0(A, B, _).
passive___2__0(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !.
passive___2__0(B, D, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, B, D),
	'chr gen_id'(E),
	passive___2__0__0__6(F, B, D, C).
passive___2__0__0__6([], A, B, C) :-
	passive___2__1(A, B, C).
passive___2__0__0__6([A|Q], C, F, M) :-
	(   ( A=suspension(_, active, B, D),
	      B==C,
	      D=[E|K],
	      E==F
	    ),
	    ( ground(C),
	      nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			G),
	      lookup_ht(G, C, H)
	    ),
	    member(I, H),
	    I=suspension(_, active, _, _, _, _)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
			  J),
		delete_ht(J, k(C, [F|K]), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
			L),
	      delete_ht(L, C, A)
	    ),
	    ( arg(2, M, N),
	      setarg(2, M, active),
	      (   N==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      O),
		    insert_ht(O, C, M)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    P),
		  insert_ht(P, k(C, F), M)
	      ;   true
	      )
	    ),
	    least_occurrence(C, K),
	    (   M=suspension(_, active, _, _, _)
	    ->  setarg(2, M, inactive),
		passive___2__0__0__6(Q, C, F, M)
	    ;   true
	    )
	;   passive___2__0__0__6(Q, C, F, M)
	).
passive___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	passive___2__1(B, C, A).
passive___2__1(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		  A),
	lookup_ht(A, k(B, C), D), !,
	passive___2__1__0__8(D, B, C, E).
passive___2__1__0__8([], A, B, C) :-
	passive___2__2(A, B, C).
passive___2__1__0__8([A|J], C, E, K) :-
	(   ( A=suspension(_, active, _, _, G, I, B, D, _),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		      F),
	    lookup_ht(F, G, H)
	->  passive___2__1__1__8(H,
				 G,
				 I,
				 A,
				 J,
				 C,
				 E,
				 K)
	;   passive___2__1__0__8(J, C, E, K)
	).
passive___2__1__1__8([], _, _, _, A, B, C, D) :-
	passive___2__1__0__8(A, B, C, D).
passive___2__1__1__8([A|U], C, D, V, W, Q, S, N) :-
	(   ( A=suspension(_, active, _, B, E, J),
	      B==C
	    ),
	    D<E,
	    ( ( ground(C),
		ground(D)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
			F),
	      lookup_ht(F, k(C, D, yes), G)
	    ),
	    member(H, G),
	    H=suspension(_, active, _, _, _)
	->  ( ( setarg(2, A, removed),
		( nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
			    I),
		  delete_ht(I, k(C, J), A)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			  K),
		delete_ht(K, C, A)
	      ),
	      setarg(2, H, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
			  L),
		delete_ht(L, k(C, yes), H)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
			M),
	      delete_ht(M, k(C, D, yes), H)
	    ),
	    ( arg(2, N, O),
	      setarg(2, N, active),
	      (   O==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      P),
		    insert_ht(P, Q, N)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    R),
		  insert_ht(R, k(Q, S), N)
	      ;   true
	      )
	    ),
	    ( T is J-1,
	      stored(C, D, maybe),
	      stored_complete(C, E, T)
	    ),
	    (   N=suspension(_, active, _, _, _)
	    ->  setarg(2, N, inactive),
		passive___2__1__1__8(U,
				     C,
				     D,
				     V,
				     W,
				     Q,
				     S,
				     N)
	    ;   true
	    )
	;   passive___2__1__1__8(U,
				 C,
				 D,
				 V,
				 W,
				 Q,
				 S,
				 N)
	).
passive___2__1(A, B, C) :-
	passive___2__2(A, B, C).
passive___2__2(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C), !,
	passive___2__2__0__9(C, B, D, E).
passive___2__2__0__9([], A, B, C) :-
	passive___2__3(A, B, C).
passive___2__2__0__9([A|N], C, G, D) :-
	(   A=suspension(_, active, _, _, B, F),
	    B==C,
	    ( E=t(251, A, D),
	      '$novel_production'(A, E),
	      '$novel_production'(D, E)
	    ),
	    F=pragma(rule(_, _, _, _), ids([G|K], L), _, _, C)
	->  '$extend_history'(D, E),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      I),
		    insert_ht(I, C, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    J),
		  insert_ht(J, k(C, G), D)
	      ;   true
	      )
	    ),
	    ( append(K, L, M),
	      check_all_passive(C, M)
	    ),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		passive___2__2__0__9(N, C, G, D)
	    ;   true
	    )
	;   passive___2__2__0__9(N, C, G, D)
	).
passive___2__2(A, B, C) :-
	passive___2__3(A, B, C).
passive___2__3(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C), !,
	passive___2__3__0__10(C, B, D, E).
passive___2__3__0__10([], A, B, C) :-
	passive___2__4(A, B, C).
passive___2__3__0__10([A|L], C, G, D) :-
	(   A=suspension(_, active, _, _, B, F),
	    B==C,
	    ( E=t(252, A, D),
	      '$novel_production'(A, E),
	      '$novel_production'(D, E)
	    ),
	    F=pragma(rule(_, _, _, _), ids([], [G|K]), _, _, C)
	->  '$extend_history'(D, E),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      I),
		    insert_ht(I, C, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    J),
		  insert_ht(J, k(C, G), D)
	      ;   true
	      )
	    ),
	    check_all_passive(C, K),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		passive___2__3__0__10(L, C, G, D)
	    ;   true
	    )
	;   passive___2__3__0__10(L, C, G, D)
	).
passive___2__3(A, B, C) :-
	passive___2__4(A, B, C).
passive___2__4(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',
		  A),
	lookup_ht(A, B, C), !,
	passive___2__4__0__11(C, B, D, E).
passive___2__4__0__11([], A, B, C) :-
	passive___2__5(A, B, C).
passive___2__4__0__11([A|N], C, F, J) :-
	(   A=suspension(_, active, B, D),
	    B==C,
	    D=[E|H],
	    E==F
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',
			  G),
		delete_ht(G, k(C, [F|H]), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',
			I),
	      delete_ht(I, C, A)
	    ),
	    ( arg(2, J, K),
	      setarg(2, J, active),
	      (   K==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      L),
		    insert_ht(L, C, J)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    M),
		  insert_ht(M, k(C, F), J)
	      ;   true
	      )
	    ),
	    check_all_passive(C, H),
	    (   J=suspension(_, active, _, _, _)
	    ->  setarg(2, J, inactive),
		passive___2__4__0__11(N, C, F, J)
	    ;   true
	    )
	;   passive___2__4__0__11(N, C, F, J)
	).
passive___2__4(A, B, C) :-
	passive___2__5(A, B, C).
passive___2__5(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		  A),
	lookup_ht(A, k(B, C), D), !,
	passive___2__5__0__14(D, B, C, E).
passive___2__5__0__14([], A, B, C) :-
	passive___2__6(A, B, C).
passive___2__5__0__14([A|J], C, E, K) :-
	(   ( A=suspension(_, active, _, _, G, H, B, D, _),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		      F),
	    lookup_ht(F, k(G, H), I)
	->  passive___2__5__1__14(I,
				  G,
				  H,
				  A,
				  J,
				  C,
				  E,
				  K)
	;   passive___2__5__0__14(J, C, E, K)
	).
passive___2__5__1__14([], _, _, _, A, B, C, D) :-
	passive___2__5__0__14(A, B, C, D).
passive___2__5__1__14([A|O], C, E, F, P, K, M, G) :-
	(   A=suspension(_, active, _, B, D),
	    ( B==C,
	      D==E
	    ),
	    ( H=t(362, F, G, A),
	      '$novel_production'(F, H),
	      '$novel_production'(G, H),
	      '$novel_production'(A, H)
	    ),
	    E>1
	->  '$extend_history'(G, H),
	    ( arg(2, G, I),
	      setarg(2, G, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      J),
		    insert_ht(J, K, G)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    L),
		  insert_ht(L, k(K, M), G)
	      ;   true
	      )
	    ),
	    ( N is E-1,
	      skip_to_next_id(C, N)
	    ),
	    (   G=suspension(_, active, _, _, _)
	    ->  setarg(2, G, inactive),
		passive___2__5__1__14(O,
				      C,
				      E,
				      F,
				      P,
				      K,
				      M,
				      G)
	    ;   true
	    )
	;   passive___2__5__1__14(O,
				  C,
				  E,
				  F,
				  P,
				  K,
				  M,
				  G)
	).
passive___2__5(A, B, C) :-
	passive___2__6(A, B, C).
passive___2__6(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		  A),
	lookup_ht(A, k(B, C), D), !,
	passive___2__6__0__15(D, B, C, E).
passive___2__6__0__15([], A, B, C) :-
	passive___2__7(A, B, C).
passive___2__6__0__15([A|J], C, E, K) :-
	(   ( A=suspension(_, active, _, _, G, H, B, D, _),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		      F),
	    lookup_ht(F, k(G, H), I)
	->  passive___2__6__1__15(I,
				  G,
				  H,
				  A,
				  J,
				  C,
				  E,
				  K)
	;   passive___2__6__0__15(J, C, E, K)
	).
passive___2__6__1__15([], _, _, _, A, B, C, D) :-
	passive___2__6__0__15(A, B, C, D).
passive___2__6__1__15([A|O], C, E, P, Q, J, L, G) :-
	(   A=suspension(_, active, B, D, M),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
			F),
	      delete_ht(F, k(C, E), A)
	    ),
	    ( arg(2, G, H),
	      setarg(2, G, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			      I),
		    insert_ht(I, J, G)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			    K),
		  insert_ht(K, k(J, L), G)
	      ;   true
	      )
	    ),
	    ( occurrence_code_id(C, E, M),
	      N is E+1,
	      set_occurrence_code_id(C, N, M)
	    ),
	    (   G=suspension(_, active, _, _, _)
	    ->  setarg(2, G, inactive),
		passive___2__6__1__15(O,
				      C,
				      E,
				      P,
				      Q,
				      J,
				      L,
				      G)
	    ;   true
	    )
	;   passive___2__6__1__15(O,
				  C,
				  E,
				  P,
				  Q,
				  J,
				  L,
				  G)
	).
passive___2__6(A, B, C) :-
	passive___2__7(A, B, C).
passive___2__7(D, F, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
			C),
	      insert_ht(C, D, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		      E),
	    insert_ht(E, k(D, F), A)
	;   true
	).
is_passive(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !.
is_passive(_, _) :-
	fail.
any_passive_head(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _), !.
any_passive_head(_) :-
	fail.
new_occurrence(B, H, I, J) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  E),
	delete_ht(E, B, D),
	G is F+1,
	occurrence(B, G, H, I, J),
	max_occurrence(B, G).
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(D, E, B, F, G, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, I), !,
	C=suspension(H, not_stored_yet, t, _, D, E, B, F, G),
	'chr gen_id'(H),
	occurrence___5__0__0__4(I,
				D,
				E,
				B,
				F,
				G,
				C).
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([A|I], E, F, C, J, K, L) :-
	(   ( A=suspension(_, active, _, _, B, H),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
		      D),
	    lookup_ht(D, k(E, F), G)
	->  occurrence___5__0__1__4(G,
				    H,
				    A,
				    I,
				    E,
				    F,
				    C,
				    J,
				    K,
				    L)
	;   occurrence___5__0__0__4(I,
				    E,
				    F,
				    C,
				    J,
				    K,
				    L)
	).
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([A|Y], X, F, Z, C, E, Q, R, K, G) :-
	(   A=suspension(_, active, _, B, D),
	    ( B==C,
	      D==E
	    ),
	    H=t(60, F, G, A),
	    '$novel_production'(F, H),
	    '$novel_production'(G, H),
	    '$novel_production'(A, H)
	->  '$extend_history'(G, H),
	    ( arg(2, G, I),
	      setarg(2, G, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      J),
		    insert_ht(J, k(C, K), G)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      L),
		    M=[G|L],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     M),
		    (   L=[N|_]
		    ->  setarg(4, N, M)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      O),
		    insert_ht(O, k(C, E, K), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      P),
		    insert_ht(P, k(C, Q, R), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      S),
		    insert_ht(S, k(C, E), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      T),
		    insert_ht(T, Q, G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      U),
		    insert_ht(U, k(C, Q), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      V),
		    insert_ht(V, k(Q, R), G)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    W),
		  insert_ht(W, C, G)
	      ;   true
	      )
	    ),
	    ( \+ is_passive(Q, R),
	      K==propagation,
	      (   stored_in_guard_before_next_kept_occurrence(C, E)
	      ->  true
	      ;   X=pragma(rule([_|_], _, _, _), _, _, _, _)
	      ->  is_observed(C, E)
	      ;   is_least_occurrence(Q)
	      ->  is_observed(C, E)
	      ;   true
	      )
	    ),
	    (   G=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, G, inactive),
		occurrence___5__0__1__4(Y,
					X,
					F,
					Z,
					C,
					E,
					Q,
					R,
					K,
					G)
	    ;   true
	    )
	;   occurrence___5__0__1__4(Y,
				    X,
				    F,
				    Z,
				    C,
				    E,
				    Q,
				    R,
				    K,
				    G)
	).
occurrence___5__0(B, C, D, E, F, A) :-
	A=suspension(G, not_stored_yet, t, _, B, C, D, E, F),
	'chr gen_id'(G),
	occurrence___5__1(B, C, D, E, F, A).
occurrence___5__1(D, E, B, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		  A),
	lookup_ht(A, B, C), !,
	occurrence___5__1__0__7(C,
				D,
				E,
				B,
				F,
				G,
				H).
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([A|G1], G, L, C, F, V, S) :-
	(   ( A=suspension(_, active, B, D),
	      B==C,
	      D=[E|Q],
	      E==F
	    ),
	    ( ( ground(G),
		nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			  H),
		lookup_ht(H, G, I)
	      ),
	      member(J, I),
	      J=suspension(_, active, _, _, K)
	    ),
	    K>=L,
	    ( ( ground(C),
		nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			  M),
		lookup_ht(M, C, N)
	      ),
	      member(O, N),
	      O=suspension(_, active, _, _, _, _)
	    ),
	    \+ may_trigger(G)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
			  P),
		delete_ht(P, k(C, [F|Q]), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
			R),
	      delete_ht(R, C, A)
	    ),
	    ( arg(2, S, T),
	      setarg(2, S, active),
	      (   T==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      U),
		    insert_ht(U, k(G, V), S)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      W),
		    X=[S|W],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     X),
		    (   W=[Y|_]
		    ->  setarg(4, Y, X)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      Z),
		    insert_ht(Z, k(G, L, V), S)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      A1),
		    insert_ht(A1, k(G, C, F), S)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      B1),
		    insert_ht(B1, k(G, L), S)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      C1),
		    insert_ht(C1, C, S)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      D1),
		    insert_ht(D1, k(G, C), S)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      E1),
		    insert_ht(E1, k(C, F), S)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    F1),
		  insert_ht(F1, G, S)
	      ;   true
	      )
	    ),
	    least_occurrence(C, Q),
	    (   S=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, S, inactive),
		occurrence___5__1__0__7(G1,
					G,
					L,
					C,
					F,
					V,
					S)
	    ;   true
	    )
	;   occurrence___5__1__0__7(G1,
				    G,
				    L,
				    C,
				    F,
				    V,
				    S)
	).
occurrence___5__1(A, B, C, D, E, F) :-
	occurrence___5__2(A, B, C, D, E, F).
occurrence___5__2(D, E, B, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',
		  A),
	lookup_ht(A, B, C), !,
	occurrence___5__2__0__29(C,
				 D,
				 E,
				 B,
				 F,
				 G,
				 H).
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([A|V], H, N, C, P, I, D) :-
	(   A=suspension(_, active, _, B),
	    B==C,
	    E=t(180, A, D),
	    '$novel_production'(A, E),
	    '$novel_production'(D, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      G),
		    insert_ht(G, k(H, I), D)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      J),
		    K=[D|J],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     K),
		    (   J=[L|_]
		    ->  setarg(4, L, K)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      M),
		    insert_ht(M, k(H, N, I), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      O),
		    insert_ht(O, k(H, C, P), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      Q),
		    insert_ht(Q, k(H, N), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      R),
		    insert_ht(R, C, D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      S),
		    insert_ht(S, k(H, C), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      T),
		    insert_ht(T, k(C, P), D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    U),
		  insert_ht(U, H, D)
	      ;   true
	      )
	    ),
	    passive(C, P),
	    (   D=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, D, inactive),
		occurrence___5__2__0__29(V,
					 H,
					 N,
					 C,
					 P,
					 I,
					 D)
	    ;   true
	    )
	;   occurrence___5__2__0__29(V,
				     H,
				     N,
				     C,
				     P,
				     I,
				     D)
	).
occurrence___5__2(A, B, C, D, E, F) :-
	occurrence___5__3(A, B, C, D, E, F).
occurrence___5__3(D, E, B, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C), !,
	occurrence___5__3__0__30(C,
				 D,
				 E,
				 B,
				 F,
				 G,
				 H).
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([A|H], E, I, C, J, K, L) :-
	(   ( A=suspension(_, active, _, _, B, G),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		      D),
	    lookup_ht(D, k(E, C), F)
	->  occurrence___5__3__1__30(F,
				     G,
				     A,
				     H,
				     E,
				     I,
				     C,
				     J,
				     K,
				     L)
	;   occurrence___5__3__0__30(H,
				     E,
				     I,
				     C,
				     J,
				     K,
				     L)
	).
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([A|I], J, K, L, C, M, E, N, O, P) :-
	(   ( A=suspension(_, active, _, _, B, H, D, _, _),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		      F),
	    lookup_ht(F, E, G)
	->  occurrence___5__3__2__30(G,
				     H,
				     A,
				     I,
				     J,
				     K,
				     L,
				     C,
				     M,
				     E,
				     N,
				     O,
				     P)
	;   occurrence___5__3__1__30(I,
				     J,
				     K,
				     L,
				     C,
				     M,
				     E,
				     N,
				     O,
				     P)
	).
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([A|E], F, G, H, I, J, K, L, M, C, N, O, P) :-
	(   ( A=suspension(_, active, _, _, B, _, _, _, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		      D)
	->  occurrence___5__3__3__30(D,
				     A,
				     E,
				     F,
				     G,
				     H,
				     I,
				     J,
				     K,
				     L,
				     M,
				     C,
				     N,
				     O,
				     P)
	;   occurrence___5__3__2__30(E,
				     F,
				     G,
				     H,
				     I,
				     J,
				     K,
				     L,
				     M,
				     C,
				     N,
				     O,
				     P)
	).
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([A|C1], D1, E1, C, F1, G1, D, H1, I1, F, B, U, V, O, L) :-
	(   A=suspension(_, active, _, G),
	    B<C,
	    chr_pp_flag(occurrence_subsumption, on),
	    D=pragma(rule(E, _, _, _), _, _, _, _),
	    E\==[],
	    \+ tree_set_memberchk(F, G)
	->  ( setarg(2, A, removed),
	      arg(3, A, H),
	      (   var(H)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			    I),
		  I=[_|J],
		  b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			   J),
		  (   J=[K|_]
		  ->  setarg(3, K, _)
		  ;   true
		  )
	      ;   H=[_, _|J],
		  setarg(2, H, J),
		  (   J=[K|_]
		  ->  setarg(3, K, H)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      N),
		    insert_ht(N, k(F, O), L)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      P),
		    Q=[L|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(F, B, O), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      T),
		    insert_ht(T, k(F, U, V), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      W),
		    insert_ht(W, k(F, B), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      X),
		    insert_ht(X, U, L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      Y),
		    insert_ht(Y, k(F, U), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      Z),
		    insert_ht(Z, k(U, V), L)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    A1),
		  insert_ht(A1, F, L)
	      ;   true
	      )
	    ),
	    ( first_occ_in_rule(U, F, B, V),
	      tree_set_add(G, F, B1),
	      multiple_occ_constraints_checked(B1)
	    ),
	    (   L=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, L, inactive),
		occurrence___5__3__3__30(C1,
					 D1,
					 E1,
					 C,
					 F1,
					 G1,
					 D,
					 H1,
					 I1,
					 F,
					 B,
					 U,
					 V,
					 O,
					 L)
	    ;   true
	    )
	;   occurrence___5__3__3__30(C1,
				     D1,
				     E1,
				     C,
				     F1,
				     G1,
				     D,
				     H1,
				     I1,
				     F,
				     B,
				     U,
				     V,
				     O,
				     L)
	).
occurrence___5__3(A, B, C, D, E, F) :-
	occurrence___5__4(A, B, C, D, E, F).
occurrence___5__4(D, E, B, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C), !,
	occurrence___5__4__0__31(C,
				 D,
				 E,
				 B,
				 F,
				 G,
				 H).
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([A|H], E, I, C, J, K, L) :-
	(   ( A=suspension(_, active, _, _, B, G),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		      D),
	    lookup_ht(D, k(E, C), F)
	->  occurrence___5__4__1__31(F,
				     G,
				     A,
				     H,
				     E,
				     I,
				     C,
				     J,
				     K,
				     L)
	;   occurrence___5__4__0__31(H,
				     E,
				     I,
				     C,
				     J,
				     K,
				     L)
	).
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([A|J], K, L, M, C, N, E, O, P, Q) :-
	(   ( A=suspension(_, active, _, _, B, H, D, I, _),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		      F),
	    lookup_ht(F, E, G)
	->  occurrence___5__4__2__31(G,
				     H,
				     I,
				     A,
				     J,
				     K,
				     L,
				     M,
				     C,
				     N,
				     E,
				     O,
				     P,
				     Q)
	;   occurrence___5__4__1__31(J,
				     K,
				     L,
				     M,
				     C,
				     N,
				     E,
				     O,
				     P,
				     Q)
	).
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([A|E], F, G, H, I, J, K, L, M, N, C, O, P, Q) :-
	(   ( A=suspension(_, active, _, _, B, _, _, _, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		      D)
	->  occurrence___5__4__3__31(D,
				     A,
				     E,
				     F,
				     G,
				     H,
				     I,
				     J,
				     K,
				     L,
				     M,
				     N,
				     C,
				     O,
				     P,
				     Q)
	;   occurrence___5__4__2__31(E,
				     F,
				     G,
				     H,
				     I,
				     J,
				     K,
				     L,
				     M,
				     N,
				     C,
				     O,
				     P,
				     Q)
	).
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([A|D1], E1, F1, B, B1, G1, H1, D, I1, J1, F, C, U, V, O, L) :-
	(   A=suspension(_, active, _, G),
	    B<C,
	    chr_pp_flag(occurrence_subsumption, on),
	    D=pragma(rule(E, _, _, _), _, _, _, _),
	    E\==[],
	    \+ tree_set_memberchk(F, G)
	->  ( setarg(2, A, removed),
	      arg(3, A, H),
	      (   var(H)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			    I),
		  I=[_|J],
		  b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			   J),
		  (   J=[K|_]
		  ->  setarg(3, K, _)
		  ;   true
		  )
	      ;   H=[_, _|J],
		  setarg(2, H, J),
		  (   J=[K|_]
		  ->  setarg(3, K, H)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      N),
		    insert_ht(N, k(F, O), L)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      P),
		    Q=[L|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(F, C, O), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      T),
		    insert_ht(T, k(F, U, V), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      W),
		    insert_ht(W, k(F, C), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      X),
		    insert_ht(X, U, L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      Y),
		    insert_ht(Y, k(F, U), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      Z),
		    insert_ht(Z, k(U, V), L)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    A1),
		  insert_ht(A1, F, L)
	      ;   true
	      )
	    ),
	    ( first_occ_in_rule(U, F, B, B1),
	      tree_set_add(G, F, C1),
	      multiple_occ_constraints_checked(C1)
	    ),
	    (   L=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, L, inactive),
		occurrence___5__4__3__31(D1,
					 E1,
					 F1,
					 B,
					 B1,
					 G1,
					 H1,
					 D,
					 I1,
					 J1,
					 F,
					 C,
					 U,
					 V,
					 O,
					 L)
	    ;   true
	    )
	;   occurrence___5__4__3__31(D1,
				     E1,
				     F1,
				     B,
				     B1,
				     G1,
				     H1,
				     D,
				     I1,
				     J1,
				     F,
				     C,
				     U,
				     V,
				     O,
				     L)
	).
occurrence___5__4(A, B, C, D, E, F) :-
	occurrence___5__5(A, B, C, D, E, F).
occurrence___5__5(B, C, E, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  A),
	lookup_ht(A, k(B, C, yes), D), !,
	occurrence___5__5__0__35(D,
				 B,
				 C,
				 E,
				 F,
				 G,
				 H).
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([A|J1], C, E, G, H, X, U) :-
	(   ( A=suspension(_, active, B, D, F),
	      B==C,
	      D==E,
	      F=yes
	    ),
	    ( ( ( ground(G),
		  ground(H)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			  I),
		lookup_ht(I, k(G, H), J)
	      ),
	      member(K, J),
	      K=suspension(_, active, _, _, _)
	    ),
	    ( ( ground(C),
		nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			  L),
		lookup_ht(L, C, M)
	      ),
	      member(N, M),
	      N=suspension(_, active, _, _, O, S)
	    ),
	    E<O
	->  ( ( setarg(2, A, removed),
		( nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
			    P),
		  delete_ht(P, k(C, yes), A)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
			  Q),
		delete_ht(Q, k(C, E, yes), A)
	      ),
	      setarg(2, N, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
			  R),
		delete_ht(R, k(C, S), N)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			T),
	      delete_ht(T, C, N)
	    ),
	    ( arg(2, U, V),
	      setarg(2, U, active),
	      (   V==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      W),
		    insert_ht(W, k(C, X), U)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      Y),
		    Z=[U|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(C, E, X), U)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      C1),
		    insert_ht(C1, k(C, G, H), U)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      D1),
		    insert_ht(D1, k(C, E), U)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      E1),
		    insert_ht(E1, G, U)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      F1),
		    insert_ht(F1, k(C, G), U)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      G1),
		    insert_ht(G1, k(G, H), U)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    H1),
		  insert_ht(H1, C, U)
	      ;   true
	      )
	    ),
	    ( I1 is S-1,
	      stored(C, E, maybe),
	      stored_complete(C, O, I1)
	    ),
	    (   U=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, U, inactive),
		occurrence___5__5__0__35(J1,
					 C,
					 E,
					 G,
					 H,
					 X,
					 U)
	    ;   true
	    )
	;   occurrence___5__5__0__35(J1,
				     C,
				     E,
				     G,
				     H,
				     X,
				     U)
	).
occurrence___5__5(A, B, C, D, E, F) :-
	occurrence___5__6(A, B, C, D, E, F).
occurrence___5__6(D, E, B, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	occurrence___5__6__0__36(C,
				 D,
				 E,
				 B,
				 F,
				 G,
				 H).
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([A|G], H, I, C, J, K, L) :-
	(   ( A=suspension(_, active, _, _, E, _, B, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  occurrence___5__6__1__36(F,
				     E,
				     A,
				     G,
				     H,
				     I,
				     C,
				     J,
				     K,
				     L)
	;   occurrence___5__6__0__36(G,
				     H,
				     I,
				     C,
				     J,
				     K,
				     L)
	).
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([A|G], C, H, I, J, K, L, M, N, O) :-
	(   ( A=suspension(_, active, _, B, F),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		      D),
	    lookup_ht(D, k(C, 0), E)
	->  occurrence___5__6__2__36(E,
				     F,
				     A,
				     G,
				     C,
				     H,
				     I,
				     J,
				     K,
				     L,
				     M,
				     N,
				     O)
	;   occurrence___5__6__1__36(G,
				     C,
				     H,
				     I,
				     J,
				     K,
				     L,
				     M,
				     N,
				     O)
	).
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([A|B1], J, G, C1, C, F, D1, M, S, U, V, N, E) :-
	(   A=suspension(_, active, _, B, I, D),
	    ( B==C,
	      D=0
	    ),
	    ( H=t(250, E, F, A, G),
	      '$novel_production'(E, H),
	      '$novel_production'(F, H),
	      '$novel_production'(A, H),
	      '$novel_production'(G, H)
	    ),
	    I=<J
	->  '$extend_history'(E, H),
	    ( arg(2, E, K),
	      setarg(2, E, active),
	      (   K==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      L),
		    insert_ht(L, k(M, N), E)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      O),
		    P=[E|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(M, S, N), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      T),
		    insert_ht(T, k(M, U, V), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      W),
		    insert_ht(W, k(M, S), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      X),
		    insert_ht(X, U, E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      Y),
		    insert_ht(Y, k(M, U), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      Z),
		    insert_ht(Z, k(U, V), E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    A1),
		  insert_ht(A1, M, E)
	      ;   true
	      )
	    ),
	    passive(U, V),
	    (   E=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, E, inactive),
		occurrence___5__6__2__36(B1,
					 J,
					 G,
					 C1,
					 C,
					 F,
					 D1,
					 M,
					 S,
					 U,
					 V,
					 N,
					 E)
	    ;   true
	    )
	;   occurrence___5__6__2__36(B1,
				     J,
				     G,
				     C1,
				     C,
				     F,
				     D1,
				     M,
				     S,
				     U,
				     V,
				     N,
				     E)
	).
occurrence___5__6(A, B, C, D, E, F) :-
	occurrence___5__7(A, B, C, D, E, F).
occurrence___5__7(D, E, B, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	occurrence___5__7__0__37(C,
				 D,
				 E,
				 B,
				 F,
				 G,
				 H).
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([A|H], E, I, C, J, K, L) :-
	(   ( A=suspension(_, active, _, _, _, _, B, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  occurrence___5__7__1__37(F,
				     G,
				     A,
				     H,
				     E,
				     I,
				     C,
				     J,
				     K,
				     L)
	;   occurrence___5__7__0__37(H,
				     E,
				     I,
				     C,
				     J,
				     K,
				     L)
	).
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([A|G], H, I, J, C, K, L, M, N, O) :-
	(   ( A=suspension(_, active, _, B, F),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		      D),
	    lookup_ht(D, k(C, 0), E)
	->  occurrence___5__7__2__37(E,
				     F,
				     A,
				     G,
				     H,
				     I,
				     J,
				     C,
				     K,
				     L,
				     M,
				     N,
				     O)
	;   occurrence___5__7__1__37(G,
				     H,
				     I,
				     J,
				     C,
				     K,
				     L,
				     M,
				     N,
				     O)
	).
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([A|B1], J, G, C1, A1, E, D1, C, R, T, U, M, F) :-
	(   A=suspension(_, active, _, B, I, D),
	    ( B==C,
	      D=0
	    ),
	    ( H=t(250, E, F, A, G),
	      '$novel_production'(E, H),
	      '$novel_production'(F, H),
	      '$novel_production'(A, H),
	      '$novel_production'(G, H)
	    ),
	    I=<J
	->  '$extend_history'(F, H),
	    ( 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(C, M), 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(C, R, M), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      S),
		    insert_ht(S, k(C, T, U), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      V),
		    insert_ht(V, k(C, R), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      W),
		    insert_ht(W, T, F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      X),
		    insert_ht(X, k(C, T), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      Y),
		    insert_ht(Y, k(T, U), F)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    Z),
		  insert_ht(Z, C, F)
	      ;   true
	      )
	    ),
	    passive(T, A1),
	    (   F=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, F, inactive),
		occurrence___5__7__2__37(B1,
					 J,
					 G,
					 C1,
					 A1,
					 E,
					 D1,
					 C,
					 R,
					 T,
					 U,
					 M,
					 F)
	    ;   true
	    )
	;   occurrence___5__7__2__37(B1,
				     J,
				     G,
				     C1,
				     A1,
				     E,
				     D1,
				     C,
				     R,
				     T,
				     U,
				     M,
				     F)
	).
occurrence___5__7(A, B, C, D, E, F) :-
	occurrence___5__8(A, B, C, D, E, F).
occurrence___5__8(B, D, E, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  A),
	lookup_ht(A, B, C), !,
	occurrence___5__8__0__38(C,
				 B,
				 D,
				 E,
				 F,
				 G,
				 H).
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([A|W], C, F, P, Q, J, D) :-
	(   A=suspension(_, active, _, B, G, _),
	    B==C,
	    ( E=t(259, A, D),
	      '$novel_production'(A, E),
	      '$novel_production'(D, E)
	    ),
	    F>G
	->  '$extend_history'(D, E),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      I),
		    insert_ht(I, k(C, J), D)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      K),
		    L=[D|K],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     L),
		    (   K=[M|_]
		    ->  setarg(4, M, L)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      N),
		    insert_ht(N, k(C, F, J), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      O),
		    insert_ht(O, k(C, P, Q), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      R),
		    insert_ht(R, k(C, F), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      S),
		    insert_ht(S, P, D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      T),
		    insert_ht(T, k(C, P), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      U),
		    insert_ht(U, k(P, Q), D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    V),
		  insert_ht(V, C, D)
	      ;   true
	      )
	    ),
	    passive(P, Q),
	    (   D=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, D, inactive),
		occurrence___5__8__0__38(W,
					 C,
					 F,
					 P,
					 Q,
					 J,
					 D)
	    ;   true
	    )
	;   occurrence___5__8__0__38(W,
				     C,
				     F,
				     P,
				     Q,
				     J,
				     D)
	).
occurrence___5__8(A, B, C, D, E, F) :-
	occurrence___5__9(A, B, C, D, E, F).
occurrence___5__9(B, E, C, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	occurrence___5__9__0__42(D,
				 B,
				 E,
				 C,
				 F,
				 G,
				 H).
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([A|D1], C, J, E, V, P, M) :-
	(   ( A=suspension(_, active, B, D, B1, C1),
	      B==C,
	      D==E
	    ),
	    E>1,
	    ( ( ground(C),
		nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			  F),
		lookup_ht(F, C, G)
	      ),
	      member(H, G),
	      H=suspension(_, active, _, _, I)
	    ),
	    I>J
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
			  K),
		delete_ht(K, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',
			L),
	      delete_ht(L, k(C, E), A)
	    ),
	    ( arg(2, M, N),
	      setarg(2, M, active),
	      (   N==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      O),
		    insert_ht(O, k(C, P), M)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      Q),
		    R=[M|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(C, J, P), M)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      U),
		    insert_ht(U, k(C, E, V), M)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      W),
		    insert_ht(W, k(C, J), M)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      X),
		    insert_ht(X, E, M)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      Y),
		    insert_ht(Y, k(C, E), M)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      Z),
		    insert_ht(Z, k(E, V), M)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    A1),
		  insert_ht(A1, C, M)
	      ;   true
	      )
	    ),
	    functional_dependency(C, 1, B1, C1),
	    (   M=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, M, inactive),
		occurrence___5__9__0__42(D1,
					 C,
					 J,
					 E,
					 V,
					 P,
					 M)
	    ;   true
	    )
	;   occurrence___5__9__0__42(D1,
				     C,
				     J,
				     E,
				     V,
				     P,
				     M)
	).
occurrence___5__9(A, B, C, D, E, F) :-
	occurrence___5__10(A, B, C, D, E, F).
occurrence___5__10(B, D, E, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		  A),
	lookup_ht(A, B, C), !,
	occurrence___5__10__0__48(C,
				  B,
				  D,
				  E,
				  F,
				  G,
				  H).
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([A|F], C, G, H, I, J, K) :-
	(   ( A=suspension(_, active, _, _, B, E),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',
		      D)
	->  occurrence___5__10__1__48(D,
				      E,
				      A,
				      F,
				      C,
				      G,
				      H,
				      I,
				      J,
				      K)
	;   occurrence___5__10__0__48(F,
				      C,
				      G,
				      H,
				      I,
				      J,
				      K)
	).
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([A|E], F, G, H, I, J, C, K, L, M) :-
	(   A=suspension(_, active, _, _),
	    nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      B),
	    lookup_ht(B, C, D)
	->  occurrence___5__10__2__48(D,
				      A,
				      E,
				      F,
				      G,
				      H,
				      I,
				      J,
				      C,
				      K,
				      L,
				      M)
	;   occurrence___5__10__1__48(E,
				      F,
				      G,
				      H,
				      I,
				      J,
				      C,
				      K,
				      L,
				      M)
	).
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([A|F1], D, G1, C1, F, H1, J, P, C, R, K, E) :-
	(   A=suspension(_, active, _, _, B, X),
	    B==C,
	    G=t(330, D, E, A, F),
	    '$novel_production'(D, G),
	    '$novel_production'(E, G),
	    '$novel_production'(A, G),
	    '$novel_production'(F, G)
	->  '$extend_history'(E, G),
	    ( arg(2, E, H),
	      setarg(2, E, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      I),
		    insert_ht(I, k(J, K), E)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      L),
		    M=[E|L],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     M),
		    (   L=[N|_]
		    ->  setarg(4, N, M)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      O),
		    insert_ht(O, k(J, P, K), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      Q),
		    insert_ht(Q, k(J, C, R), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      S),
		    insert_ht(S, k(J, P), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      T),
		    insert_ht(T, C, E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      U),
		    insert_ht(U, k(J, C), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      V),
		    insert_ht(V, k(C, R), E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    W),
		  insert_ht(W, J, E)
	      ;   true
	      )
	    ),
	    ( X=pragma(rule(Y, E1, A1, _), _, _, _, _),
	      (   is_passive(C, R)
	      ->  true
	      ;   K==simplification
	      ->  select(Z, Y, _),
		  Z=..[_|B1],
		  term_variables(A1, D1),
		  partial_wake_args(B1, C1, D1, J)
	      ;   select(Z, E1, _),
		  Z=..[_|B1],
		  term_variables(A1, D1),
		  partial_wake_args(B1, C1, D1, J)
	      )
	    ),
	    (   E=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, E, inactive),
		occurrence___5__10__2__48(F1,
					  D,
					  G1,
					  C1,
					  F,
					  H1,
					  J,
					  P,
					  C,
					  R,
					  K,
					  E)
	    ;   true
	    )
	;   occurrence___5__10__2__48(F1,
				      D,
				      G1,
				      C1,
				      F,
				      H1,
				      J,
				      P,
				      C,
				      R,
				      K,
				      E)
	).
occurrence___5__10(A, B, C, D, E, F) :-
	occurrence___5__11(A, B, C, D, E, F).
occurrence___5__11(E, F, B, C, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	occurrence___5__11__0__50(D,
				  E,
				  F,
				  B,
				  C,
				  G,
				  H).
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([A|J], G, H, C, E, K, L) :-
	(   ( A=suspension(_, active, _, B, D),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		      F),
	    lookup_ht(F, k(G, H), I)
	->  occurrence___5__11__1__50(I,
				      A,
				      J,
				      G,
				      H,
				      C,
				      E,
				      K,
				      L)
	;   occurrence___5__11__0__50(J,
				      G,
				      H,
				      C,
				      E,
				      K,
				      L)
	).
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([A|Y], G, Z, C, E, Q, R, K, F) :-
	(   A=suspension(_, active, _, B, D),
	    ( B==C,
	      D==E
	    ),
	    ( H=t(362, F, G, A),
	      '$novel_production'(F, H),
	      '$novel_production'(G, H),
	      '$novel_production'(A, H)
	    ),
	    E>1
	->  '$extend_history'(F, H),
	    ( arg(2, F, I),
	      setarg(2, F, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      J),
		    insert_ht(J, k(C, K), F)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      L),
		    M=[F|L],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     M),
		    (   L=[N|_]
		    ->  setarg(4, N, M)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      O),
		    insert_ht(O, k(C, E, K), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      P),
		    insert_ht(P, k(C, Q, R), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      S),
		    insert_ht(S, k(C, E), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      T),
		    insert_ht(T, Q, F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      U),
		    insert_ht(U, k(C, Q), F)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      V),
		    insert_ht(V, k(Q, R), F)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    W),
		  insert_ht(W, C, F)
	      ;   true
	      )
	    ),
	    ( X is E-1,
	      skip_to_next_id(C, X)
	    ),
	    (   F=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, F, inactive),
		occurrence___5__11__1__50(Y,
					  G,
					  Z,
					  C,
					  E,
					  Q,
					  R,
					  K,
					  F)
	    ;   true
	    )
	;   occurrence___5__11__1__50(Y,
				      G,
				      Z,
				      C,
				      E,
				      Q,
				      R,
				      K,
				      F)
	).
occurrence___5__11(A, B, C, D, E, F) :-
	occurrence___5__12(A, B, C, D, E, F).
occurrence___5__12(B, C, E, F, G, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	occurrence___5__12__0__51(D,
				  B,
				  C,
				  E,
				  F,
				  G,
				  H).
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([A|B1], C, E, F, G, O, L) :-
	(   ( A=suspension(_, active, B, D, Z),
	      B==C,
	      D==E
	    ),
	    ( ( ground(F),
		ground(G)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			H),
	      lookup_ht(H, k(F, G), I)
	    ),
	    member(J, I),
	    J=suspension(_, active, _, _, _)
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
			K),
	      delete_ht(K, k(C, E), A)
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      N),
		    insert_ht(N, k(C, O), L)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      P),
		    Q=[L|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, E, O), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      T),
		    insert_ht(T, k(C, F, G), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      U),
		    insert_ht(U, k(C, E), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      V),
		    insert_ht(V, F, L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      W),
		    insert_ht(W, k(C, F), L)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      X),
		    insert_ht(X, k(F, G), L)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    Y),
		  insert_ht(Y, C, L)
	      ;   true
	      )
	    ),
	    ( occurrence_code_id(C, E, Z),
	      A1 is E+1,
	      set_occurrence_code_id(C, A1, Z)
	    ),
	    (   L=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, L, inactive),
		occurrence___5__12__0__51(B1,
					  C,
					  E,
					  F,
					  G,
					  O,
					  L)
	    ;   true
	    )
	;   occurrence___5__12__0__51(B1,
				      C,
				      E,
				      F,
				      G,
				      O,
				      L)
	).
occurrence___5__12(A, B, C, D, E, F) :-
	occurrence___5__13(A, B, C, D, E, F).
occurrence___5__13(B, C, E, F, simplification, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	occurrence___5__13__0__52(D,
				  B,
				  C,
				  E,
				  F,
				  simplification,
				  G).
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([A|Y], C, E, P, Q, J, G) :-
	(   A=suspension(_, active, B, D, W),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
			F),
	      delete_ht(F, k(C, E), A)
	    ),
	    ( arg(2, G, H),
	      setarg(2, G, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      I),
		    insert_ht(I, k(C, J), G)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      K),
		    L=[G|K],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     L),
		    (   K=[M|_]
		    ->  setarg(4, M, L)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      N),
		    insert_ht(N, k(C, E, J), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      O),
		    insert_ht(O, k(C, P, Q), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      R),
		    insert_ht(R, k(C, E), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      S),
		    insert_ht(S, P, G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      T),
		    insert_ht(T, k(C, P), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      U),
		    insert_ht(U, k(P, Q), G)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    V),
		  insert_ht(V, C, G)
	      ;   true
	      )
	    ),
	    ( occurrence_code_id(C, E, W),
	      X is E+1,
	      set_occurrence_code_id(C, X, W)
	    ),
	    (   G=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, G, inactive),
		occurrence___5__13__0__52(Y,
					  C,
					  E,
					  P,
					  Q,
					  J,
					  G)
	    ;   true
	    )
	;   occurrence___5__13__0__52(Y,
				      C,
				      E,
				      P,
				      Q,
				      J,
				      G)
	).
occurrence___5__13(B, C, E, F, propagation, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	occurrence___5__13__0__53(D,
				  B,
				  C,
				  E,
				  F,
				  propagation,
				  G).
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([A|C1], C, E, S, T, M, J) :-
	(   ( A=suspension(_, active, B, D, Z),
	      B==C,
	      D==E
	    ),
	    ( ( ground(C),
		ground(E)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
			F),
	      lookup_ht(F, k(C, E), G)
	    ),
	    member(H, G),
	    H=suspension(_, active, _, _, _)
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
			I),
	      delete_ht(I, k(C, E), A)
	    ),
	    ( arg(2, J, K),
	      setarg(2, J, active),
	      (   K==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      L),
		    insert_ht(L, k(C, M), J)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      N),
		    O=[J|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(C, E, M), J)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      R),
		    insert_ht(R, k(C, S, T), J)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      U),
		    insert_ht(U, k(C, E), J)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      V),
		    insert_ht(V, S, J)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      W),
		    insert_ht(W, k(C, S), J)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      X),
		    insert_ht(X, k(S, T), J)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    Y),
		  insert_ht(Y, C, J)
	      ;   true
	      )
	    ),
	    ( occurrence_code_id(C, E, Z),
	      A1 is E+1,
	      B1 is Z+1,
	      set_occurrence_code_id(C, A1, B1)
	    ),
	    (   J=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, J, inactive),
		occurrence___5__13__0__53(C1,
					  C,
					  E,
					  S,
					  T,
					  M,
					  J)
	    ;   true
	    )
	;   occurrence___5__13__0__53(C1,
				      C,
				      E,
				      S,
				      T,
				      M,
				      J)
	).
occurrence___5__13(A, B, C, D, E, F) :-
	occurrence___5__14(A, B, C, D, E, F).
occurrence___5__14(B, C, E, F, propagation, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	occurrence___5__14__0__54(D,
				  B,
				  C,
				  E,
				  F,
				  propagation,
				  G).
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([A|Y], C, E, P, Q, J, G) :-
	(   A=suspension(_, active, B, D, W),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
			F),
	      delete_ht(F, k(C, E), A)
	    ),
	    ( arg(2, G, H),
	      setarg(2, G, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			      I),
		    insert_ht(I, k(C, J), G)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			      K),
		    L=[G|K],
		    b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
			     L),
		    (   K=[M|_]
		    ->  setarg(4, M, L)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			      N),
		    insert_ht(N, k(C, E, J), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			      O),
		    insert_ht(O, k(C, P, Q), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			      R),
		    insert_ht(R, k(C, E), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			      S),
		    insert_ht(S, P, G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			      T),
		    insert_ht(T, k(C, P), G)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			      U),
		    insert_ht(U, k(P, Q), G)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
			    V),
		  insert_ht(V, C, G)
	      ;   true
	      )
	    ),
	    ( occurrence_code_id(C, E, W),
	      X is E+1,
	      set_occurrence_code_id(C, X, W)
	    ),
	    (   G=suspension(_, active, _, _, _, _, _, _, _)
	    ->  setarg(2, G, inactive),
		occurrence___5__14__0__54(Y,
					  C,
					  E,
					  P,
					  Q,
					  J,
					  G)
	    ;   true
	    )
	;   occurrence___5__14__0__54(Y,
				      C,
				      E,
				      P,
				      Q,
				      J,
				      G)
	).
occurrence___5__14(A, B, C, D, E, F) :-
	occurrence___5__15(A, B, C, D, E, F).
occurrence___5__15(D, J, L, M, E, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
			C),
	      insert_ht(C, k(D, E), A)
	    ),
	    ( nb_getval('$chr_store_global_ground_chr_translate____occurrence___5',
			F),
	      G=[A|F],
	      b_setval('$chr_store_global_ground_chr_translate____occurrence___5',
		       G),
	      (   F=[H|_]
	      ->  setarg(4, H, G)
	      ;   true
	      )
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			I),
	      insert_ht(I, k(D, J, E), A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
			K),
	      insert_ht(K, k(D, L, M), A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
			N),
	      insert_ht(N, k(D, J), A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
			O),
	      insert_ht(O, L, A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			P),
	      insert_ht(P, k(D, L), A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			Q),
	      insert_ht(Q, k(L, M), A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		      R),
	    insert_ht(R, D, A)
	;   true
	).
get_occurrence(B, C, G, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, F, H, _), !,
	F=G,
	H=I.
get_occurrence(A, B, _, _) :-
	chr_error(internal,
		  'get_occurrence: missing occurrence ~w:~w\n',
		  [A, B]).
get_occurrence(B, C, G, I, K) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, F, H, J), !,
	F=G,
	H=I,
	J=K.
get_occurrence(A, B, _, _, _) :-
	chr_error(internal,
		  'get_occurrence: missing occurrence ~w:~w\n',
		  [A, B]).
get_occurrence_from_id(F, H, B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G, I, _, _, _), !,
	F=G,
	H=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(B, F, G) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		    A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _, E),
	    E>=F, !
	;    !,
	    max_occurrence___2__0__0__2(C, B, F, G)
	).
max_occurrence___2__0__0__2([], A, B, C) :-
	max_occurrence___2__1(A, B, C).
max_occurrence___2__0__0__2([A|G], C, D, H) :-
	(   ( A=suspension(_, active, _, B, E),
	      B==C
	    ),
	    D>=E
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
			F),
	      delete_ht(F, C, A)
	    ),
	    max_occurrence___2__0__0__2(G, C, D, H)
	;   max_occurrence___2__0__0__2(G, C, D, H)
	).
max_occurrence___2__0(A, B, C) :-
	max_occurrence___2__1(A, B, C).
max_occurrence___2__1(B, D, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		  A),
	lookup_ht(A, k(B, 0), F), !,
	C=suspension(E, not_stored_yet, t, B, D),
	'chr gen_id'(E),
	max_occurrence___2__1__0__5(F, B, D, C).
max_occurrence___2__1__0__5([], A, B, C) :-
	max_occurrence___2__2(A, B, C).
max_occurrence___2__1__0__5([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, B, G, D),
	      B==C,
	      D=0
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		      E),
	    lookup_ht(E, C, F)
	->  max_occurrence___2__1__1__5(F,
					G,
					A,
					H,
					C,
					I,
					J)
	;   max_occurrence___2__1__0__5(H, C, I, J)
	).
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([A|G], H, I, J, C, K, L) :-
	(   ( A=suspension(_, active, _, _, B, _, E, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		      D),
	    lookup_ht(D, E, F)
	->  max_occurrence___2__1__2__5(F,
					E,
					A,
					G,
					H,
					I,
					J,
					C,
					K,
					L)
	;   max_occurrence___2__1__1__5(G,
					H,
					I,
					J,
					C,
					K,
					L)
	).
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([A|N], D, B, O, H, E, P, L, I, F) :-
	(   A=suspension(_, active, _, _, _, _, C, M, _),
	    A\==B,
	    C==D,
	    ( G=t(250, A, B, E, F),
	      '$novel_production'(A, G),
	      '$novel_production'(B, G),
	      '$novel_production'(E, G),
	      '$novel_production'(F, G)
	    ),
	    H=<I
	->  '$extend_history'(F, G),
	    ( arg(2, F, J),
	      setarg(2, F, active),
	      (   J==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
			    K),
		  insert_ht(K, L, F)
	      ;   true
	      )
	    ),
	    passive(D, M),
	    (   F=suspension(_, active, _, _, _)
	    ->  setarg(2, F, inactive),
		max_occurrence___2__1__2__5(N,
					    D,
					    B,
					    O,
					    H,
					    E,
					    P,
					    L,
					    I,
					    F)
	    ;   true
	    )
	;   max_occurrence___2__1__2__5(N,
					D,
					B,
					O,
					H,
					E,
					P,
					L,
					I,
					F)
	).
max_occurrence___2__1(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	max_occurrence___2__2(B, C, A).
max_occurrence___2__2(D, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		      C),
	    insert_ht(C, D, A)
	;   true
	).
get_max_occurrence(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F), !,
	E=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(B, 0, A) :- !,
	A=suspension(C, active, t, B, 0),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
		  D),
	insert_ht(D, B, A),
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
		  E),
	insert_ht(E, k(B, 0), A),
	stored_in_guard_before_next_kept_occurrence(B, 0),
	(   A=suspension(_, active, _, _, _)
	->  setarg(2, A, inactive),
	    allocation_occurrence___2__1(B, 0, A)
	;   true
	).
allocation_occurrence___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	allocation_occurrence___2__1(B, C, A).
allocation_occurrence___2__1(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	allocation_occurrence___2__1__0__2(D, B, C, E).
allocation_occurrence___2__1__0__2([], A, B, C) :-
	allocation_occurrence___2__2(A, B, C).
allocation_occurrence___2__1__0__2([A|K], C, E, L) :-
	(   ( A=suspension(_, active, _, _, B, D, G, I, J),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      F),
	    lookup_ht(F, G, H)
	->  allocation_occurrence___2__1__1__2(H,
					       G,
					       I,
					       J,
					       A,
					       K,
					       C,
					       E,
					       L)
	;   allocation_occurrence___2__1__0__2(K,
					       C,
					       E,
					       L)
	).
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([A|O], C, L, M, D, P, I, K, E) :-
	(   A=suspension(_, active, _, _, B, N),
	    B==C,
	    F=t(60, A, D, E),
	    '$novel_production'(A, F),
	    '$novel_production'(D, F),
	    '$novel_production'(E, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			      H),
		    insert_ht(H, I, E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
			    J),
		  insert_ht(J, k(I, K), E)
	      ;   true
	      )
	    ),
	    ( \+ is_passive(C, L),
	      M==propagation,
	      (   stored_in_guard_before_next_kept_occurrence(I,
							      K)
	      ->  true
	      ;   N=pragma(rule([_|_], _, _, _), _, _, _, _)
	      ->  is_observed(I, K)
	      ;   is_least_occurrence(C)
	      ->  is_observed(I, K)
	      ;   true
	      )
	    ),
	    (   E=suspension(_, active, _, _, _)
	    ->  setarg(2, E, inactive),
		allocation_occurrence___2__1__1__2(O,
						   C,
						   L,
						   M,
						   D,
						   P,
						   I,
						   K,
						   E)
	    ;   true
	    )
	;   allocation_occurrence___2__1__1__2(O,
					       C,
					       L,
					       M,
					       D,
					       P,
					       I,
					       K,
					       E)
	).
allocation_occurrence___2__1(A, B, C) :-
	allocation_occurrence___2__2(A, B, C).
allocation_occurrence___2__2(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		  A),
	lookup_ht(A, B, C), !,
	allocation_occurrence___2__2__0__3(C, B, D, E).
allocation_occurrence___2__2__0__3([], A, B, C) :-
	allocation_occurrence___2__3(A, B, C).
allocation_occurrence___2__2__0__3([A|I], C, J, K) :-
	(   ( A=suspension(_, active, _, _, B, G, E, H, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  allocation_occurrence___2__2__1__3(F,
					       G,
					       E,
					       H,
					       A,
					       I,
					       C,
					       J,
					       K)
	;   allocation_occurrence___2__2__0__3(I,
					       C,
					       J,
					       K)
	).
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([A|T], H, C, F, U, V, L, G, P) :-
	(   ( A=suspension(_, active, B, D),
	      B==C,
	      D=[E|N],
	      E==F
	    ),
	    G>=H,
	    ( ( ground(C),
		nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			  I),
		lookup_ht(I, C, J)
	      ),
	      member(K, J),
	      K=suspension(_, active, _, _, _, _)
	    ),
	    \+ may_trigger(L)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
			  M),
		delete_ht(M, k(C, [F|N]), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
			O),
	      delete_ht(O, C, A)
	    ),
	    ( arg(2, P, Q),
	      setarg(2, P, active),
	      (   Q==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			      R),
		    insert_ht(R, L, P)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
			    S),
		  insert_ht(S, k(L, G), P)
	      ;   true
	      )
	    ),
	    least_occurrence(C, N),
	    (   P=suspension(_, active, _, _, _)
	    ->  setarg(2, P, inactive),
		allocation_occurrence___2__2__1__3(T,
						   H,
						   C,
						   F,
						   U,
						   V,
						   L,
						   G,
						   P)
	    ;   true
	    )
	;   allocation_occurrence___2__2__1__3(T,
					       H,
					       C,
					       F,
					       U,
					       V,
					       L,
					       G,
					       P)
	).
allocation_occurrence___2__2(A, B, C) :-
	allocation_occurrence___2__3(A, B, C).
allocation_occurrence___2__3(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
		  A),
	lookup_ht(A, B, C), !,
	allocation_occurrence___2__3__0__5(C, B, D, E).
allocation_occurrence___2__3__0__5([], A, B, C) :-
	allocation_occurrence___2__4(A, B, C).
allocation_occurrence___2__3__0__5([A|R], C, H, L) :-
	(   ( A=suspension(_, active, B, D, P, Q),
	      B==C
	    ),
	    D>1,
	    ( ( ( ground(C),
		  ground(D)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
			  E),
		lookup_ht(E, k(C, D), F)
	      ),
	      member(G, F),
	      G=suspension(_, active, _, _, _, I, _, _, _)
	    ),
	    H>I
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
			  J),
		delete_ht(J, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',
			K),
	      delete_ht(K, k(C, D), A)
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			      N),
		    insert_ht(N, C, L)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
			    O),
		  insert_ht(O, k(C, H), L)
	      ;   true
	      )
	    ),
	    functional_dependency(C, 1, P, Q),
	    (   L=suspension(_, active, _, _, _)
	    ->  setarg(2, L, inactive),
		allocation_occurrence___2__3__0__5(R,
						   C,
						   H,
						   L)
	    ;   true
	    )
	;   allocation_occurrence___2__3__0__5(R,
					       C,
					       H,
					       L)
	).
allocation_occurrence___2__3(A, B, C) :-
	allocation_occurrence___2__4(A, B, C).
allocation_occurrence___2__4(D, F, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			C),
	      insert_ht(C, D, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
		      E),
	    insert_ht(E, k(D, F), A)
	;   true
	).
get_allocation_occurrence(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F), !,
	E=F.
get_allocation_occurrence(_, A) :-
	chr_pp_flag(late_allocation, off),
	A=0.
rule(A, B) :-
	rule___2__0(A, B, _).
rule___2__0(B, D, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, _, B, D),
	'chr gen_id'(E),
	rule___2__0__0__1(F, B, D, C).
rule___2__0__0__1([], A, B, C) :-
	rule___2__1(A, B, C).
rule___2__0__0__1([A|J], C, K, L) :-
	(   ( A=suspension(_, active, _, _, E, F, B, H, I),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-12',
		      D),
	    lookup_ht(D, k(E, F), G)
	->  rule___2__0__1__1(G,
			      E,
			      F,
			      H,
			      I,
			      A,
			      J,
			      C,
			      K,
			      L)
	;   rule___2__0__0__1(J, C, K, L)
	).
rule___2__0__1__1([], _, _, _, _, _, A, B, C, D) :-
	rule___2__0__0__1(A, B, C, D).
rule___2__0__1__1([A|R], C, E, O, P, G, S, N, Q, F) :-
	(   A=suspension(_, active, _, B, D),
	    ( B==C,
	      D==E
	    ),
	    H=t(60, F, G, A),
	    '$novel_production'(F, H),
	    '$novel_production'(G, H),
	    '$novel_production'(A, H)
	->  '$extend_history'(F, H),
	    ( arg(2, F, I),
	      setarg(2, F, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      J),
		    K=[F|J],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     K),
		    (   J=[L|_]
		    ->  setarg(4, L, K)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    M),
		  insert_ht(M, N, F)
	      ;   true
	      )
	    ),
	    ( \+ is_passive(N, O),
	      P==propagation,
	      (   stored_in_guard_before_next_kept_occurrence(C, E)
	      ->  true
	      ;   Q=pragma(rule([_|_], _, _, _), _, _, _, _)
	      ->  is_observed(C, E)
	      ;   is_least_occurrence(N)
	      ->  is_observed(C, E)
	      ;   true
	      )
	    ),
	    (   F=suspension(_, active, _, _, _, _)
	    ->  setarg(2, F, inactive),
		rule___2__0__1__1(R,
				  C,
				  E,
				  O,
				  P,
				  G,
				  S,
				  N,
				  Q,
				  F)
	    ;   true
	    )
	;   rule___2__0__1__1(R,
			      C,
			      E,
			      O,
			      P,
			      G,
			      S,
			      N,
			      Q,
			      F)
	).
rule___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, t, _, B, C),
	'chr gen_id'(D),
	rule___2__1(B, C, A).
rule___2__1(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__1__0__2(C, B, D, E).
rule___2__1__0__2([], A, B, C) :-
	rule___2__2(A, B, C).
rule___2__1__0__2([A|X], C, Y, R) :-
	(   ( A=suspension(_, active, B, D),
	      B==C,
	      D=[E|P]
	    ),
	    ( ( ( ground(C),
		  ground(E)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
			  F),
		lookup_ht(F, k(C, E), G)
	      ),
	      member(H, G),
	      H=suspension(_, active, _, _, J, N, _, _, _)
	    ),
	    ( ( nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
			  I),
		lookup_ht(I, J, K)
	      ),
	      member(L, K),
	      L=suspension(_, active, _, _, M)
	    ),
	    M>=N,
	    \+ may_trigger(J)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
			  O),
		delete_ht(O, k(C, [E|P]), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
			Q),
	      delete_ht(Q, C, A)
	    ),
	    ( arg(2, R, S),
	      setarg(2, R, active),
	      (   S==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      T),
		    U=[R|T],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     U),
		    (   T=[V|_]
		    ->  setarg(4, V, U)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    W),
		  insert_ht(W, C, R)
	      ;   true
	      )
	    ),
	    least_occurrence(C, P),
	    (   R=suspension(_, active, _, _, _, _)
	    ->  setarg(2, R, inactive),
		rule___2__1__0__2(X, C, Y, R)
	    ;   true
	    )
	;   rule___2__1__0__2(X, C, Y, R)
	).
rule___2__1(A, B, C) :-
	rule___2__2(A, B, C).
rule___2__2(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__2__0__3(C, B, D, E).
rule___2__2__0__3([], A, B, C) :-
	rule___2__3(A, B, C).
rule___2__2__0__3([A|R], C, S, L) :-
	(   ( A=suspension(_, active, B, D),
	      B==C,
	      D=[E|J]
	    ),
	    ( ( ground(C),
		ground(E)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
			F),
	      lookup_ht(F, k(C, E), G)
	    ),
	    member(H, G),
	    H=suspension(_, active, _, _, _)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
			  I),
		delete_ht(I, k(C, [E|J]), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
			K),
	      delete_ht(K, C, A)
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      N),
		    O=[L|N],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     O),
		    (   N=[P|_]
		    ->  setarg(4, P, O)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    Q),
		  insert_ht(Q, C, L)
	      ;   true
	      )
	    ),
	    least_occurrence(C, J),
	    (   L=suspension(_, active, _, _, _, _)
	    ->  setarg(2, L, inactive),
		rule___2__2__0__3(R, C, S, L)
	    ;   true
	    )
	;   rule___2__2__0__3(R, C, S, L)
	).
rule___2__2(A, B, C) :-
	rule___2__3(A, B, C).
rule___2__3(H, A, B) :-
	A=pragma(rule([], _, _, _), ids([], I), _, _, _), !,
	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, H, B)
	;   true
	),
	least_occurrence(H, I),
	(   B=suspension(_, active, _, _, _, _)
	->  setarg(2, B, inactive),
	    rule___2__4(H, A, B)
	;   true
	).
rule___2__3(A, B, C) :-
	rule___2__4(A, B, C).
rule___2__4(B, E, S) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, F1, F, H, G, _),
	E=pragma(rule(Z, A1, F, L), C1, D1, E1, B),
	F\==true,
	append(G, H, I),
	(   conj2list(F, J),
	    append(I, J, K),
	    guard_entailment:entails_guard(K, fail)
	->  M=fail
	;   simplify_guard(F, L, I, M, B1)
	),
	F\==M, !,
	setarg(2, D, removed),
	arg(4, D, N),
	(   var(N)
	->  nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
		      O),
	    O=[_|P],
	    b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
		     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____prev_guard_list___6-1',
		  R),
	delete_ht(R, B, D),
	(   var(S)
	->  true
	;   arg(2, S, T),
	    setarg(2, S, removed),
	    (   T==not_stored_yet
	    ->  true
	    ;   ( arg(4, S, U),
		  (   var(U)
		  ->  nb_getval('$chr_store_global_ground_chr_translate____rule___2',
				V),
		      V=[_|W],
		      b_setval('$chr_store_global_ground_chr_translate____rule___2',
			       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____rule___2-1',
			  Y),
		delete_ht(Y, B, S)
	    )
	),
	rule(B,
	     pragma(rule(Z, A1, M, B1),
		    C1,
		    D1,
		    E1,
		    B)),
	prev_guard_list(B, F1, M, H, G, []).
rule___2__4(B, C, D) :-
	nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',
		  A), !,
	rule___2__4__0__10(A, B, C, D).
rule___2__4__0__10([], A, B, C) :-
	rule___2__5(A, B, C).
rule___2__4__0__10([A|R], I, J, B) :-
	(   A=suspension(_, active, _, _),
	    C=t(174, B, A),
	    '$novel_production'(B, C),
	    '$novel_production'(A, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, D),
	      setarg(2, B, active),
	      (   D==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      E),
		    F=[B|E],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     F),
		    (   E=[G|_]
		    ->  setarg(4, G, F)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    H),
		  insert_ht(H, I, B)
	      ;   true
	      )
	    ),
	    ( J=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(I,
						      P,
						      Q)
	    ),
	    (   B=suspension(_, active, _, _, _, _)
	    ->  setarg(2, B, inactive),
		rule___2__4__0__10(R, I, J, B)
	    ;   true
	    )
	;   rule___2__4__0__10(R, I, J, B)
	).
rule___2__4(A, B, C) :-
	rule___2__5(A, B, C).
rule___2__5(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__5__0__11(C, B, D, E).
rule___2__5__0__11([], A, B, C) :-
	rule___2__6(A, B, C).
rule___2__5__0__11([A|R], C, F, D) :-
	(   A=suspension(_, active, _, _, B, _, G, I, H, _),
	    B==C,
	    ( E=t(178, A, D),
	      '$novel_production'(A, E),
	      '$novel_production'(D, E)
	    ),
	    chr_pp_flag(check_impossible_rules, on),
	    F=pragma(rule(_, _, G, _), _, _, _, C),
	    conj2list(G, K),
	    append(H, I, J),
	    append(J, K, L),
	    guard_entailment:entails_guard(L, fail)
	->  '$extend_history'(D, E),
	    ( arg(2, D, M),
	      setarg(2, D, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      N),
		    O=[D|N],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     O),
		    (   N=[P|_]
		    ->  setarg(4, P, O)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    Q),
		  insert_ht(Q, C, D)
	      ;   true
	      )
	    ),
	    ( chr_warning(weird_program,
			  'Heads will never match or guard will always fail in ~@.\n\tThis rule will never fire!\n',
			  [format_rule(F)]),
	      set_all_passive(C)
	    ),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		rule___2__5__0__11(R, C, F, D)
	    ;   true
	    )
	;   rule___2__5__0__11(R, C, F, D)
	).
rule___2__5(A, B, C) :-
	rule___2__6(A, B, C).
rule___2__6(B, E, B1) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, M, F, H, G, _),
	E=pragma(rule(K, L, F, I), Y, Z, A1, B),
	simplify_heads(G, H, F, I, J, S),
	J\==[],
	extract_arguments(K, N),
	extract_arguments(L, O),
	extract_arguments(M, P),
	replace_some_heads(N,
			   O,
			   P,
			   J,
			   Q,
			   R,
			   F,
			   I,
			   T),
	substitute_arguments(K, Q, V),
	substitute_arguments(L, R, W),
	append(S, T, U),
	list2conj(U, X),
	I1=pragma(rule(V, W, F,  (X, I)), Y, Z, A1, B),
	(   K\==V
	;   L\==W
	), !,
	(   var(B1)
	->  true
	;   arg(2, B1, C1),
	    setarg(2, B1, removed),
	    (   C1==not_stored_yet
	    ->  true
	    ;   ( arg(4, B1, D1),
		  (   var(D1)
		  ->  nb_getval('$chr_store_global_ground_chr_translate____rule___2',
				E1),
		      E1=[_|F1],
		      b_setval('$chr_store_global_ground_chr_translate____rule___2',
			       F1),
		      (   F1=[G1|_]
		      ->  setarg(4, G1, _)
		      ;   true
		      )
		  ;   D1=[_, _|F1],
		      setarg(2, D1, F1),
		      (   F1=[G1|_]
		      ->  setarg(4, G1, D1)
		      ;   true
		      )
		  )
		),
		nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			  H1),
		delete_ht(H1, B, B1)
	    )
	),
	rule(B, I1).
rule___2__6(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__6__0__13(C, B, D, E).
rule___2__6__0__13([], A, B, C) :-
	rule___2__7(A, B, C).
rule___2__6__0__13([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, _, E, G, B, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		      D),
	    lookup_ht(D, k(E, C), F)
	->  rule___2__6__1__13(F,
			       E,
			       G,
			       A,
			       H,
			       C,
			       I,
			       J)
	;   rule___2__6__0__13(H, C, I, J)
	).
rule___2__6__1__13([], _, _, _, A, B, C, D) :-
	rule___2__6__0__13(A, B, C, D).
rule___2__6__1__13([A|K], D, L, B, M, F, N, O) :-
	(   ( A=suspension(_, active, _, _, C, I, E, J, _),
	      A\==B,
	      C==D,
	      E==F
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		      G),
	    lookup_ht(G, F, H)
	->  rule___2__6__2__13(H,
			       I,
			       J,
			       A,
			       K,
			       D,
			       L,
			       B,
			       M,
			       F,
			       N,
			       O)
	;   rule___2__6__1__13(K,
			       D,
			       L,
			       B,
			       M,
			       F,
			       N,
			       O)
	).
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([A|E], F, G, H, I, J, K, L, M, C, N, O) :-
	(   ( A=suspension(_, active, _, _, B, _, _, _, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		      D)
	->  rule___2__6__3__13(D,
			       A,
			       E,
			       F,
			       G,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       C,
			       N,
			       O)
	;   rule___2__6__2__13(E,
			       F,
			       G,
			       H,
			       I,
			       J,
			       K,
			       L,
			       M,
			       C,
			       N,
			       O)
	).
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([A|U], V, W, B, S, X, Y, F, C, Z, A1, R, D, L) :-
	(   A=suspension(_, active, _, G),
	    B<C,
	    chr_pp_flag(occurrence_subsumption, on),
	    D=pragma(rule(E, _, _, _), _, _, _, _),
	    E\==[],
	    \+ tree_set_memberchk(F, G)
	->  ( setarg(2, A, removed),
	      arg(3, A, H),
	      (   var(H)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			    I),
		  I=[_|J],
		  b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			   J),
		  (   J=[K|_]
		  ->  setarg(3, K, _)
		  ;   true
		  )
	      ;   H=[_, _|J],
		  setarg(2, H, J),
		  (   J=[K|_]
		  ->  setarg(3, K, H)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      N),
		    O=[L|N],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     O),
		    (   N=[P|_]
		    ->  setarg(4, P, O)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    Q),
		  insert_ht(Q, R, L)
	      ;   true
	      )
	    ),
	    ( first_occ_in_rule(R, F, B, S),
	      tree_set_add(G, F, T),
	      multiple_occ_constraints_checked(T)
	    ),
	    (   L=suspension(_, active, _, _, _, _)
	    ->  setarg(2, L, inactive),
		rule___2__6__3__13(U,
				   V,
				   W,
				   B,
				   S,
				   X,
				   Y,
				   F,
				   C,
				   Z,
				   A1,
				   R,
				   D,
				   L)
	    ;   true
	    )
	;   rule___2__6__3__13(U,
			       V,
			       W,
			       B,
			       S,
			       X,
			       Y,
			       F,
			       C,
			       Z,
			       A1,
			       R,
			       D,
			       L)
	).
rule___2__6(A, B, C) :-
	rule___2__7(A, B, C).
rule___2__7(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__7__0__15(C, B, D, E).
rule___2__7__0__15([], A, B, C) :-
	rule___2__8(A, B, C).
rule___2__7__0__15([A|P], C, F, D) :-
	(   A=suspension(_, active, _, B, G),
	    B==C,
	    ( E=t(251, D, A),
	      '$novel_production'(D, E),
	      '$novel_production'(A, E)
	    ),
	    F=pragma(rule(_, _, _, _), ids([G|M], N), _, _, C)
	->  '$extend_history'(D, E),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      I),
		    J=[D|I],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(4, K, J)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    L),
		  insert_ht(L, C, D)
	      ;   true
	      )
	    ),
	    ( append(M, N, O),
	      check_all_passive(C, O)
	    ),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		rule___2__7__0__15(P, C, F, D)
	    ;   true
	    )
	;   rule___2__7__0__15(P, C, F, D)
	).
rule___2__7(A, B, C) :-
	rule___2__8(A, B, C).
rule___2__8(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__8__0__16(C, B, D, E).
rule___2__8__0__16([], A, B, C) :-
	rule___2__9(A, B, C).
rule___2__8__0__16([A|N], C, F, D) :-
	(   A=suspension(_, active, _, B, G),
	    B==C,
	    ( E=t(252, D, A),
	      '$novel_production'(D, E),
	      '$novel_production'(A, E)
	    ),
	    F=pragma(rule(_, _, _, _), ids([], [G|M]), _, _, C)
	->  '$extend_history'(D, E),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      I),
		    J=[D|I],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(4, K, J)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    L),
		  insert_ht(L, C, D)
	      ;   true
	      )
	    ),
	    check_all_passive(C, M),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		rule___2__8__0__16(N, C, F, D)
	    ;   true
	    )
	;   rule___2__8__0__16(N, C, F, D)
	).
rule___2__8(A, B, C) :-
	rule___2__9(A, B, C).
rule___2__9(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',
		  A),
	lookup_ht(A, k(B, []), C), !,
	rule___2__9__0__17(C, B, D, E).
rule___2__9__0__17([], A, B, C) :-
	rule___2__10(A, B, C).
rule___2__9__0__17([A|N], C, M, G) :-
	(   A=suspension(_, active, B, D),
	    B==C,
	    D=[]
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',
			  E),
		delete_ht(E, k(C, []), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',
			F),
	      delete_ht(F, C, A)
	    ),
	    ( arg(2, G, H),
	      setarg(2, G, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      I),
		    J=[G|I],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(4, K, J)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    L),
		  insert_ht(L, C, G)
	      ;   true
	      )
	    ),
	    chr_warning(weird_program,
			'All heads passive in ~@.\n\tThis rule never fires. Please check your program.\n',
			[format_rule(M)]),
	    (   G=suspension(_, active, _, _, _, _)
	    ->  setarg(2, G, inactive),
		rule___2__9__0__17(N, C, M, G)
	    ;   true
	    )
	;   rule___2__9__0__17(N, C, M, G)
	).
rule___2__9(A, B, C) :-
	rule___2__10(A, B, C).
rule___2__10(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	rule___2__10__0__22(C, B, D, E).
rule___2__10__0__22([], A, B, C) :-
	rule___2__11(A, B, C).
rule___2__10__0__22([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, _, E, _, B, F, G),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',
		      D)
	->  rule___2__10__1__22(D,
				E,
				F,
				G,
				A,
				H,
				C,
				I,
				J)
	;   rule___2__10__0__22(H, C, I, J)
	).
rule___2__10__1__22([], _, _, _, _, A, B, C, D) :-
	rule___2__10__0__22(A, B, C, D).
rule___2__10__1__22([A|E], C, F, G, H, I, J, K, L) :-
	(   A=suspension(_, active, _, _),
	    nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		      B),
	    lookup_ht(B, C, D)
	->  rule___2__10__2__22(D,
				A,
				E,
				C,
				F,
				G,
				H,
				I,
				J,
				K,
				L)
	;   rule___2__10__1__22(E,
				C,
				F,
				G,
				H,
				I,
				J,
				K,
				L)
	).
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([A|X], D, Y, C, O, P, E, Z, M, N, F) :-
	(   A=suspension(_, active, _, _, B, U),
	    B==C,
	    G=t(330, D, E, F, A),
	    '$novel_production'(D, G),
	    '$novel_production'(E, G),
	    '$novel_production'(F, G),
	    '$novel_production'(A, G)
	->  '$extend_history'(F, G),
	    ( arg(2, F, H),
	      setarg(2, F, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      I),
		    J=[F|I],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(4, K, J)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			    L),
		  insert_ht(L, M, F)
	      ;   true
	      )
	    ),
	    ( N=pragma(rule(Q, W, S, _), _, _, _, _),
	      (   is_passive(M, O)
	      ->  true
	      ;   P==simplification
	      ->  select(R, Q, _),
		  R=..[_|T],
		  term_variables(S, V),
		  partial_wake_args(T, U, V, C)
	      ;   select(R, W, _),
		  R=..[_|T],
		  term_variables(S, V),
		  partial_wake_args(T, U, V, C)
	      )
	    ),
	    (   F=suspension(_, active, _, _, _, _)
	    ->  setarg(2, F, inactive),
		rule___2__10__2__22(X,
				    D,
				    Y,
				    C,
				    O,
				    P,
				    E,
				    Z,
				    M,
				    N,
				    F)
	    ;   true
	    )
	;   rule___2__10__2__22(X,
				D,
				Y,
				C,
				O,
				P,
				E,
				Z,
				M,
				N,
				F)
	).
rule___2__10(A, B, C) :-
	rule___2__11(A, B, C).
rule___2__11(G, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			C),
	      D=[A|C],
	      b_setval('$chr_store_global_ground_chr_translate____rule___2',
		       D),
	      (   C=[E|_]
	      ->  setarg(4, E, D)
	      ;   true
	      )
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      F),
	    insert_ht(F, G, A)
	;   true
	).
get_rule(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, F), !,
	E=F.
get_rule(_, _) :-
	fail.
least_occurrence(B, [F|O]) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _, _, _, _)
	),
	(   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		      E),
	    lookup_ht(E, k(B, F), G),
	    member(H, G),
	    H=suspension(_, active, _, _, J, N, _, _, _),
	    nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
		      I),
	    lookup_ht(I, J, K),
	    member(L, K),
	    L=suspension(_, active, _, _, M),
	    M>=N,
	    \+ may_trigger(J), !,
	    least_occurrence(B, O)
	;   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		      P),
	    lookup_ht(P, k(B, F), Q),
	    member(R, Q),
	    R=suspension(_, active, _, _, _), !,
	    least_occurrence(B, O)
	).
least_occurrence(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
		  D),
	insert_ht(D, k(A, B), E),
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-1',
		  F),
	insert_ht(F, A, E).
is_least_occurrence(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____least_occurrence___2-12',
		  A),
	lookup_ht(A, k(B, []), C),
	member(D, C),
	D=suspension(_, active, _, _), !.
is_least_occurrence(_) :-
	fail.
stored_in_guard_lookahead(B, C) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		    A),
	  lookup_ht(A, k(B, C), D),
	  member(E, D),
	  E=suspension(_, active, _, _, _, _, G, H, L)
	),
	(   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		      F),
	    lookup_ht(F, k(G, H), I),
	    member(J, I),
	    J=suspension(_, active, _, _, _), !,
	    K is C+1,
	    stored_in_guard_lookahead(B, K)
	;    !,
	    L==simplification,
	    (   is_stored_in_guard(B, G)
	    ->  true
	    ;   M is C+1,
		stored_in_guard_lookahead(B, M)
	    )
	).
stored_in_guard_lookahead(_, _) :-
	fail.
constraint_index(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',
		  D),
	insert_ht(D, B, E),
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',
		  F),
	insert_ht(F, A, E).
get_constraint_index(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
get_constraint_index(_, _) :-
	fail.
get_indexed_constraint(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_index___2-2',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, F, _), !,
	E=F.
get_indexed_constraint(_, _) :-
	fail.
max_constraint_index(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____max_constraint_index___1',
		  D),
	E=[C|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(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____max_constraint_index___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, D), !,
	C=D.
get_max_constraint_index(0).
identifier_size(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
		  A),
	(   member(B, A),
	    B=suspension(_, active, _, _), !
	;    !,
	    identifier_size___1__0__0__2(A, C)
	).
identifier_size___1__0__0__2([], A) :-
	identifier_size___1__1(A).
identifier_size___1__0__0__2([A|F], G) :-
	(   A=suspension(_, active, _, _)
	->  ( setarg(2, A, removed),
	      arg(3, A, B),
	      (   var(B)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
			    C),
		  C=[_|D],
		  b_setval('$chr_store_global_ground_chr_translate____identifier_size___1',
			   D),
		  (   D=[E|_]
		  ->  setarg(3, E, _)
		  ;   true
		  )
	      ;   B=[_, _|D],
		  setarg(2, B, D),
		  (   D=[E|_]
		  ->  setarg(3, E, B)
		  ;   true
		  )
	      )
	    ),
	    identifier_size___1__0__0__2(F, G)
	;   identifier_size___1__0__0__2(F, G)
	).
identifier_size(A) :-
	identifier_size___1__1(A).
identifier_size___1__1(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
		  D),
	E=[C|D],
	b_setval('$chr_store_global_ground_chr_translate____identifier_size___1',
		 E),
	(   D=[F|_]
	->  setarg(3, F, E)
	;   true
	).
get_identifier_size(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, D), !,
	C=D.
get_identifier_size(1).
identifier_index(B, C, F) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',
		    A),
	  lookup_ht(A, k(B, C), D)
	),
	(   member(E, D),
	    E=suspension(_, active, _, _, _), !
	;    !,
	    identifier_index___3__0__0__2(D, B, C, F)
	).
identifier_index___3__0__0__2([], A, B, C) :-
	identifier_index___3__1(A, B, C).
identifier_index___3__0__0__2([A|G], C, E, H) :-
	(   A=suspension(_, active, B, D, _),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',
			F),
	      delete_ht(F, k(C, E), A)
	    ),
	    identifier_index___3__0__0__2(G, C, E, H)
	;   identifier_index___3__0__0__2(G, C, E, H)
	).
identifier_index(A, B, C) :-
	identifier_index___3__1(A, B, C).
identifier_index___3__1(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',
		  E),
	insert_ht(E, k(A, B), F).
get_identifier_index(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____identifier_index___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G), !,
	F=G.
get_identifier_index(H, I, K) :-
	nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, G), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____identifier_size___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____identifier_size___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	J is G+1,
	identifier_index(H, I, J),
	identifier_size(J),
	K=J.
get_identifier_index(A, B, C) :-
	identifier_index(A, B, 2),
	identifier_size(2),
	C=2.
type_indexed_identifier_size(B, E) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		    A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _), !
	;    !,
	    type_indexed_identifier_size___2__0__0__2(C, B, E)
	).
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([A|E], C, F) :-
	(   A=suspension(_, active, B, _),
	    B==C
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
			D),
	      delete_ht(D, C, A)
	    ),
	    type_indexed_identifier_size___2__0__0__2(E, C, F)
	;   type_indexed_identifier_size___2__0__0__2(E, C, F)
	).
type_indexed_identifier_size(A, B) :-
	type_indexed_identifier_size___2__1(A, B).
type_indexed_identifier_size___2__1(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		  D),
	insert_ht(D, A, E).
get_type_indexed_identifier_size(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
get_type_indexed_identifier_size(_, 1).
type_indexed_identifier_index(F, B, C, G) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',
		    A),
	  lookup_ht(A, k(B, C), D)
	),
	(   member(E, D),
	    E=suspension(_, active, _, _, _, _), !
	;    !,
	    type_indexed_identifier_index___4__0__0__2(D,
						       F,
						       B,
						       C,
						       G)
	).
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([A|I], J, C, E, K) :-
	(   A=suspension(_, active, G, B, D, _),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',
			  F),
		delete_ht(F, k(G, C, E), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',
			H),
	      delete_ht(H, k(C, E), A)
	    ),
	    type_indexed_identifier_index___4__0__0__2(I,
						       J,
						       C,
						       E,
						       K)
	;   type_indexed_identifier_index___4__0__0__2(I,
						       J,
						       C,
						       E,
						       K)
	).
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) :-
	G=suspension(E, active, A, B, C, D),
	'chr gen_id'(E),
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',
		  F),
	insert_ht(F, k(A, B, C), G),
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-23',
		  H),
	insert_ht(H, k(B, C), G).
get_type_indexed_identifier_index(B, C, D, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_index___4-123',
		  A),
	lookup_ht(A, k(B, C, D), E),
	member(F, E),
	F=suspension(_, active, _, _, _, H), !,
	G=H.
get_type_indexed_identifier_index(B, G, H, J) :-
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____type_indexed_identifier_size___2-1',
		  E),
	delete_ht(E, B, D),
	I is F+1,
	type_indexed_identifier_index(B, G, H, I),
	type_indexed_identifier_size(B, I),
	J=I.
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) :-
	D=suspension(B, active, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',
		  C),
	insert_ht(C, A, D).
has_no_history(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_history___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
has_no_history(_) :-
	fail.
history(A, B, C) :-
	history___3__0(A, B, C, _).
history___3__0(B, D, E, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
		  A),
	lookup_ht(A, B, G), !,
	C=suspension(F, not_stored_yet, t, B, D, E),
	'chr gen_id'(F),
	history___3__0__0__1(G, B, D, E, C).
history___3__0__0__1([], A, B, C, D) :-
	history___3__1(A, B, C, D).
history___3__0__0__1([A|M], C, K, G, D) :-
	(   A=suspension(_, active, _, B, _, _),
	    B==C,
	    E=t(95, D, A),
	    '$novel_production'(D, E),
	    '$novel_production'(A, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  (   '$chr_store_constants_chr_translate____history___3___[3]'(G,
										H)
		  ->  nb_getval(H, I),
		      b_setval(H, [D|I])
		  ;   true
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
			      J),
		    insert_ht(J, K, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
			    L),
		  insert_ht(L, C, D)
	      ;   true
	      )
	    ),
	    chr_error(syntax,
		      'Only one pragma history allowed per rule (rule number ~w)\n',
		      [C]),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		history___3__0__0__1(M,
				     C,
				     K,
				     G,
				     D)
	    ;   true
	    )
	;   history___3__0__0__1(M, C, K, G, D)
	).
history___3__0(B, C, D, A) :-
	A=suspension(E, not_stored_yet, t, B, C, D),
	'chr gen_id'(E),
	history___3__1(B, C, D, A).
history___3__1(B, D, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
		  A),
	lookup_ht(A, B, C), !,
	history___3__1__0__2(C, B, D, E, F).
history___3__1__0__2([], A, B, C, D) :-
	history___3__2(A, B, C, D).
history___3__1__0__2([A|M], C, K, G, D) :-
	(   A=suspension(_, active, _, B, _, _),
	    B==C,
	    E=t(95, A, D),
	    '$novel_production'(A, E),
	    '$novel_production'(D, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  (   '$chr_store_constants_chr_translate____history___3___[3]'(G,
										H)
		  ->  nb_getval(H, I),
		      b_setval(H, [D|I])
		  ;   true
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
			      J),
		    insert_ht(J, K, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
			    L),
		  insert_ht(L, C, D)
	      ;   true
	      )
	    ),
	    chr_error(syntax,
		      'Only one pragma history allowed per rule (rule number ~w)\n',
		      [C]),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		history___3__1__0__2(M,
				     C,
				     K,
				     G,
				     D)
	    ;   true
	    )
	;   history___3__1__0__2(M, C, K, G, D)
	).
history___3__1(A, B, C, D) :-
	history___3__2(A, B, C, D).
history___3__2(D, B, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
		  A),
	lookup_ht(A, B, C), !,
	history___3__2__0__3(C, D, B, E, F).
history___3__2__0__3([], A, B, C, D) :-
	history___3__3(A, B, C, D).
history___3__2__0__3([A|Q], L, C, G, D) :-
	(   A=suspension(_, active, _, P, B, M),
	    B==C,
	    E=t(96, D, A),
	    '$novel_production'(D, E),
	    '$novel_production'(A, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  (   '$chr_store_constants_chr_translate____history___3___[3]'(G,
										H)
		  ->  nb_getval(H, I),
		      b_setval(H, [D|I])
		  ;   true
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
			      J),
		    insert_ht(J, C, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
			    K),
		  insert_ht(K, L, D)
	      ;   true
	      )
	    ),
	    ( length(G, N),
	      length(M, O),
	      (   N\==O
	      ->  chr_error(syntax,
			    'The history named ~w does not always range over an equal amount of occurrences.\n',
			    [C])
	      ;   test_named_history_id_pairs(L,
					      G,
					      P,
					      M)
	      )
	    ),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		history___3__2__0__3(Q,
				     L,
				     C,
				     G,
				     D)
	    ;   true
	    )
	;   history___3__2__0__3(Q, L, C, G, D)
	).
history___3__2(A, B, C, D) :-
	history___3__3(A, B, C, D).
history___3__3(D, B, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
		  A),
	lookup_ht(A, B, C), !,
	history___3__3__0__4(C, D, B, E, F).
history___3__3__0__4([], A, B, C, D) :-
	history___3__4(A, B, C, D).
history___3__3__0__4([A|Q], L, C, G, D) :-
	(   A=suspension(_, active, _, P, B, M),
	    B==C,
	    E=t(96, A, D),
	    '$novel_production'(A, E),
	    '$novel_production'(D, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  (   '$chr_store_constants_chr_translate____history___3___[3]'(G,
										H)
		  ->  nb_getval(H, I),
		      b_setval(H, [D|I])
		  ;   true
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
			      J),
		    insert_ht(J, C, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
			    K),
		  insert_ht(K, L, D)
	      ;   true
	      )
	    ),
	    ( length(M, N),
	      length(G, O),
	      (   N\==O
	      ->  chr_error(syntax,
			    'The history named ~w does not always range over an equal amount of occurrences.\n',
			    [C])
	      ;   test_named_history_id_pairs(P,
					      M,
					      L,
					      G)
	      )
	    ),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		history___3__3__0__4(Q,
				     L,
				     C,
				     G,
				     D)
	    ;   true
	    )
	;   history___3__3__0__4(Q, L, C, G, D)
	).
history___3__3(A, B, C, D) :-
	history___3__4(A, B, C, D).
history___3__4(B, C, [], D) :-
	nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',
		  A), !,
	history___3__4__0__6(A, B, C, [], D).
history___3__4__0__6([], A, B, C, D) :-
	history___3__5(A, B, C, D).
history___3__4__0__6([A|L], K, I, E, B) :-
	(   A=suspension(_, active, _, _),
	    C=t(142, A, B),
	    '$novel_production'(A, C),
	    '$novel_production'(B, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, D),
	      setarg(2, B, active),
	      (   D==not_stored_yet
	      ->  (   '$chr_store_constants_chr_translate____history___3___[3]'(E,
										F)
		  ->  nb_getval(F, G),
		      b_setval(F, [B|G])
		  ;   true
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
			      H),
		    insert_ht(H, I, B)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
			    J),
		  insert_ht(J, K, B)
	      ;   true
	      )
	    ),
	    generate_empty_named_history_initialisation(I),
	    (   B=suspension(_, active, _, _, _, _)
	    ->  setarg(2, B, inactive),
		history___3__4__0__6(L,
				     K,
				     I,
				     E,
				     B)
	    ;   true
	    )
	;   history___3__4__0__6(L, K, I, E, B)
	).
history___3__4(A, B, C, D) :-
	history___3__5(A, B, C, D).
history___3__5(I, G, C, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  (   '$chr_store_constants_chr_translate____history___3___[3]'(C,
									  D)
	    ->  nb_getval(D, E),
		b_setval(D, [A|E])
	    ;   true
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____history___3-2',
			F),
	      insert_ht(F, G, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
		      H),
	    insert_ht(H, I, A)
	;   true
	).
named_history(A, E, G) :-
	ground(A),
	nb_getval('$chr_store_multi_hash_chr_translate____history___3-1',
		  B),
	lookup_ht(B, A, C),
	member(D, C),
	D=suspension(_, active, _, _, F, H), !,
	E=F,
	G=H.
named_history(_, _, _) :-
	fail.
test_named_history_id_pair(B, C, H, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-34',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G, _, _, _, _),
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
		  F),
	lookup_ht(F, k(G, H, I), J),
	member(K, J),
	K=suspension(_, active, _, _, _, _, _, _, _),
	K\==E, !.
test_named_history_id_pair(B, _, A, _) :-
	chr_error(syntax,
		  'Occurrences of shared history in rules number ~w and ~w do not correspond\n',
		  [A, B]).
indexing_spec(B, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, G), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',
		  E),
	delete_ht(E, B, D),
	append(F, G, H),
	indexing_spec(B, H).
indexing_spec(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',
		  D),
	insert_ht(D, A, E).
get_indexing_spec(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____indexing_spec___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
get_indexing_spec(_, []).
observation_analysis(A) :-
	observation_analysis___1__0(A, _).
observation_analysis___1__0(B, A) :-
	nb_getval('$chr_store_global_ground_chr_translate____rule___2', D), !,
	A=suspension(C, not_stored_yet, _, B),
	'chr gen_id'(C),
	observation_analysis___1__0__0__1(D, B, A).
observation_analysis___1__0__0__1([], A, B) :-
	observation_analysis___1__1(A, B).
observation_analysis___1__0__0__1([A|G], E, H) :-
	(   A=suspension(_, active, _, _, C, B)
	->  ( B=pragma(rule(_, _, D, F), _, _, _, _),
	      (   chr_pp_flag(store_in_guards, on)
	      ->  observation_analysis(C, D, guard, E)
	      ;   true
	      ),
	      observation_analysis(C, F, body, E)
	    ),
	    observation_analysis___1__0__0__1(G, E, H)
	;   observation_analysis___1__0__0__1(G, E, H)
	).
observation_analysis___1__0(B, A) :-
	A=suspension(C, not_stored_yet, _, B),
	'chr gen_id'(C),
	observation_analysis___1__1(B, A).
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(B, C, D, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
		  A),
	lookup_ht(A, k(B, C, D), E),
	member(F, E),
	F=suspension(_, active, _, _, _, _, _), !.
spawns___3__0(B, body, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
		  A),
	lookup_ht(A, k(B, guard, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, _), !.
spawns___3__0(B, guard, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
		  A),
	lookup_ht(A, k(B, body, C), D), !,
	spawns___3__0__0__4(D, B, guard, C, E).
spawns___3__0__0__4([], A, B, C, D) :-
	spawns___3__1(A, B, C, D).
spawns___3__0__0__4([A|P], C, Q, F, R) :-
	(   A=suspension(_, active, _, _, B, D, E),
	    B==C,
	    D=body,
	    E==F
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  G),
		delete_ht(G, k(C, F), A)
	      ),
	      ( arg(4, A, H),
		(   var(H)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      I),
		    I=[_|J],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  L),
		delete_ht(L, k(C, body), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  M),
		delete_ht(M, C, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  N),
		delete_ht(N, F, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			O),
	      delete_ht(O, k(C, body, F), A)
	    ),
	    spawns___3__0__0__4(P, C, Q, F, R)
	;   spawns___3__0__0__4(P, C, Q, F, R)
	).
spawns___3__0(A, B, C, D) :-
	spawns___3__1(A, B, C, D).
spawns___3__1(B, C, I, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !,
	(   var(F)
	->  true
	;   arg(2, F, G),
	    setarg(2, F, removed),
	    (   G==not_stored_yet
	    ->  true
	    ;   ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			    H),
		  delete_ht(H, k(B, I), F)
		),
		( arg(4, F, 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(B, C), F)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			    O),
		  delete_ht(O, B, F)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			    P),
		  delete_ht(P, I, F)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			  Q),
		delete_ht(Q, k(B, C, I), F)
	    )
	).
spawns___3__1(B, body, H, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, guard), C),
	member(D, C),
	D=suspension(_, active, _, _), !,
	(   var(E)
	->  true
	;   arg(2, E, F),
	    setarg(2, E, removed),
	    (   F==not_stored_yet
	    ->  true
	    ;   ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			    G),
		  delete_ht(G, k(B, H), E)
		),
		( arg(4, E, 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(B, body), E)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			    N),
		  delete_ht(N, B, E)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			    O),
		  delete_ht(O, H, E)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			  P),
		delete_ht(P, k(B, body, H), E)
	    )
	).
spawns___3__1(B, C, F, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _),
	may_trigger(F), !,
	(   var(G)
	->  true
	;   arg(2, G, H),
	    setarg(2, G, removed),
	    (   H==not_stored_yet
	    ->  true
	    ;   ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			    I),
		  delete_ht(I, k(B, F), G)
		),
		( arg(4, G, 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(B, C), G)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			    O),
		  delete_ht(O, B, G)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			    P),
		  delete_ht(P, F, G)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			  Q),
		delete_ht(Q, k(B, C, F), G)
	    )
	).
spawns___3__1(B, body, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, guard), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _),
	may_trigger(E), !,
	(   var(F)
	->  true
	;   arg(2, F, G),
	    setarg(2, F, removed),
	    (   G==not_stored_yet
	    ->  true
	    ;   ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			    H),
		  delete_ht(H, k(B, E), F)
		),
		( arg(4, F, 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(B, body), F)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			    N),
		  delete_ht(N, B, F)
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			    O),
		  delete_ht(O, E, F)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			  P),
		delete_ht(P, k(B, body, E), F)
	    )
	).
spawns___3__1(M, S, B, J) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		    A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _, _, _, F, I, _),
	    (   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
			  E),
		lookup_ht(E, F, G),
		member(H, G),
		H=suspension(_, active, _, _),
		\+ is_passive(F, I), !,
		(   var(J)
		->  true
		;   arg(2, J, K),
		    setarg(2, J, removed),
		    (   K==not_stored_yet
		    ->  true
		    ;   ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
				    L),
			  delete_ht(L, k(M, B), J)
			),
			( arg(4, J, 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(M, S), J)
			),
			( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
				    T),
			  delete_ht(T, M, J)
			),
			( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
				    U),
			  delete_ht(U, B, J)
			),
			nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
				  V),
			delete_ht(V,
				  k(M, S, B),
				  J)
		    )
		),
		spawns_all(M, S)
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			  W),
		lookup_ht(W, F, X),
		member(Y, X),
		Y=suspension(_, active, _, _, _, _),
		may_trigger(B),
		\+ is_passive(F, I), !,
		(   var(J)
		->  true
		;   arg(2, J, Z),
		    setarg(2, J, removed),
		    (   Z==not_stored_yet
		    ->  true
		    ;   ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
				    A1),
			  delete_ht(A1, k(M, B), J)
			),
			( arg(4, J, 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(M, S), J)
			),
			( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
				    G1),
			  delete_ht(G1, M, J)
			),
			( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
				    H1),
			  delete_ht(H1, B, J)
			),
			nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
				  I1),
			delete_ht(I1,
				  k(M, S, B),
				  J)
		    )
		),
		spawns_all_triggers(M, S)
	    )
	;    !,
	    J=suspension(J1, not_stored_yet, t, _, M, S, B),
	    'chr gen_id'(J1),
	    spawns___3__1__0__11(C, M, S, B, J)
	).
spawns___3__1__0__11([], A, B, C, D) :-
	spawns___3__2(A, B, C, D).
spawns___3__1__0__11([A|H], I, J, C, K) :-
	(   ( A=suspension(_, active, _, _, B, _, E, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  spawns___3__1__1__11(F,
				 E,
				 G,
				 A,
				 H,
				 I,
				 J,
				 C,
				 K)
	;   spawns___3__1__0__11(H, I, J, C, K)
	).
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([A|T], C, H, D, U, K, P, G, E) :-
	(   A=suspension(_, active, _, _, B, _),
	    B==C,
	    ( F=t(123, A, D, E),
	      '$novel_production'(A, F),
	      '$novel_production'(E, F)
	    ),
	    \+ may_trigger(G),
	    \+ is_passive(C, H)
	->  '$extend_history'(E, F),
	    ( arg(2, E, I),
	      setarg(2, E, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			      J),
		    insert_ht(J, k(K, G), E)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      L),
		    M=[E|L],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     M),
		    (   L=[N|_]
		    ->  setarg(4, N, M)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
			      O),
		    insert_ht(O, k(K, P), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			      Q),
		    insert_ht(Q, K, E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			      R),
		    insert_ht(R, G, E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			    S),
		  insert_ht(S, k(K, P, G), E)
	      ;   true
	      )
	    ),
	    spawns_all_triggers(K, P),
	    (   E=suspension(_, active, _, _, _, _, _)
	    ->  setarg(2, E, inactive),
		spawns___3__1__1__11(T,
				     C,
				     H,
				     D,
				     U,
				     K,
				     P,
				     G,
				     E)
	    ;   true
	    )
	;   spawns___3__1__1__11(T,
				 C,
				 H,
				 D,
				 U,
				 K,
				 P,
				 G,
				 E)
	).
spawns___3__1(B, C, D, A) :-
	A=suspension(E, not_stored_yet, t, _, B, C, D),
	'chr gen_id'(E),
	spawns___3__2(B, C, D, A).
spawns___3__2(B, D, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	spawns___3__2__0__12(C, B, D, E, F).
spawns___3__2__0__12([], A, B, C, D) :-
	spawns___3__3(A, B, C, D).
spawns___3__2__0__12([A|H], C, I, J, K) :-
	(   ( A=suspension(_, active, _, _, E, _, B, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
		      D),
	    lookup_ht(D, E, F)
	->  spawns___3__2__1__12(F,
				 E,
				 G,
				 A,
				 H,
				 C,
				 I,
				 J,
				 K)
	;   spawns___3__2__0__12(H, C, I, J, K)
	).
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([A|V], C, J, E, W, H, Q, I, D) :-
	(   A=suspension(_, active, _, _, G, U, B),
	    B==C,
	    ( F=t(124, D, E, A),
	      '$novel_production'(D, F),
	      '$novel_production'(A, F)
	    ),
	    G\==H,
	    C\==I,
	    \+ is_passive(H, J)
	->  '$extend_history'(D, F),
	    ( arg(2, D, K),
	      setarg(2, D, active),
	      (   K==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			      L),
		    insert_ht(L, k(H, I), D)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      M),
		    N=[D|M],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     N),
		    (   M=[O|_]
		    ->  setarg(4, O, N)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
			      P),
		    insert_ht(P, k(H, Q), D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			      R),
		    insert_ht(R, H, D)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			      S),
		    insert_ht(S, I, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			    T),
		  insert_ht(T, k(H, Q, I), D)
	      ;   true
	      )
	    ),
	    spawns(G, U, I),
	    (   D=suspension(_, active, _, _, _, _, _)
	    ->  setarg(2, D, inactive),
		spawns___3__2__1__12(V,
				     C,
				     J,
				     E,
				     W,
				     H,
				     Q,
				     I,
				     D)
	    ;   true
	    )
	;   spawns___3__2__1__12(V,
				 C,
				 J,
				 E,
				 W,
				 H,
				 Q,
				 I,
				 D)
	).
spawns___3__2(A, B, C, D) :-
	spawns___3__3(A, B, C, D).
spawns___3__3(D, E, B, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		  A),
	lookup_ht(A, B, C), !,
	spawns___3__3__0__13(C, D, E, B, F).
spawns___3__3__0__13([], A, B, C, D) :-
	spawns___3__4(A, B, C, D).
spawns___3__3__0__13([A|H], I, J, C, K) :-
	(   ( A=suspension(_, active, _, _, B, _, E, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
		      D),
	    lookup_ht(D, E, F)
	->  spawns___3__3__1__13(F,
				 E,
				 G,
				 A,
				 H,
				 I,
				 J,
				 C,
				 K)
	;   spawns___3__3__0__13(H, I, J, C, K)
	).
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([A|U], C, J, D, V, G, Q, H, E) :-
	(   A=suspension(_, active, _, _, B, _, I),
	    B==C,
	    ( F=t(124, A, D, E),
	      '$novel_production'(A, F),
	      '$novel_production'(E, F)
	    ),
	    G\==C,
	    H\==I,
	    \+ is_passive(C, J)
	->  '$extend_history'(E, F),
	    ( arg(2, E, K),
	      setarg(2, E, active),
	      (   K==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			      L),
		    insert_ht(L, k(G, H), E)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      M),
		    N=[E|M],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     N),
		    (   M=[O|_]
		    ->  setarg(4, O, N)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
			      P),
		    insert_ht(P, k(G, Q), E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			      R),
		    insert_ht(R, G, E)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			      S),
		    insert_ht(S, H, E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			    T),
		  insert_ht(T, k(G, Q, H), E)
	      ;   true
	      )
	    ),
	    spawns(G, Q, I),
	    (   E=suspension(_, active, _, _, _, _, _)
	    ->  setarg(2, E, inactive),
		spawns___3__3__1__13(U,
				     C,
				     J,
				     D,
				     V,
				     G,
				     Q,
				     H,
				     E)
	    ;   true
	    )
	;   spawns___3__3__1__13(U,
				 C,
				 J,
				 D,
				 V,
				 G,
				 Q,
				 H,
				 E)
	).
spawns___3__3(A, B, C, D) :-
	spawns___3__4(A, B, C, D).
spawns___3__4(B, D, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	spawns___3__4__0__14(C, B, D, E, F).
spawns___3__4__0__14([], A, B, C, D) :-
	spawns___3__5(A, B, C, D).
spawns___3__4__0__14([A|G], C, H, I, J) :-
	(   ( A=suspension(_, active, _, _, E, _, B, F, _),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
		      D)
	->  spawns___3__4__1__14(D,
				 E,
				 F,
				 A,
				 G,
				 C,
				 H,
				 I,
				 J)
	;   spawns___3__4__0__14(G, C, H, I, J)
	).
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([A|U], G, F, C, V, E, O, H, B) :-
	(   A=suspension(_, active, _, _, S, T),
	    ( D=t(125, B, C, A),
	      '$novel_production'(B, D),
	      '$novel_production'(A, D)
	    ),
	    \+ is_passive(E, F),
	    may_trigger(G),
	    \+ may_trigger(H)
	->  '$extend_history'(B, D),
	    ( arg(2, B, I),
	      setarg(2, B, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			      J),
		    insert_ht(J, k(E, H), B)
		  ),
		  ( nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      K),
		    L=[B|K],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     L),
		    (   K=[M|_]
		    ->  setarg(4, M, L)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
			      N),
		    insert_ht(N, k(E, O), B)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			      P),
		    insert_ht(P, E, B)
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			      Q),
		    insert_ht(Q, H, B)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			    R),
		  insert_ht(R, k(E, O, H), B)
	      ;   true
	      )
	    ),
	    spawns(S, T, H),
	    (   B=suspension(_, active, _, _, _, _, _)
	    ->  setarg(2, B, inactive),
		spawns___3__4__1__14(U,
				     G,
				     F,
				     C,
				     V,
				     E,
				     O,
				     H,
				     B)
	    ;   true
	    )
	;   spawns___3__4__1__14(U,
				 G,
				 F,
				 C,
				 V,
				 E,
				 O,
				 H,
				 B)
	).
spawns___3__4(A, B, C, D) :-
	spawns___3__5(A, B, C, D).
spawns___3__5(D, J, E, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			C),
	      insert_ht(C, k(D, E), A)
	    ),
	    ( nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			F),
	      G=[A|F],
	      b_setval('$chr_store_global_ground_chr_translate____spawns___3',
		       G),
	      (   F=[H|_]
	      ->  setarg(4, H, G)
	      ;   true
	      )
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
			I),
	      insert_ht(I, k(D, J), A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			K),
	      insert_ht(K, D, A)
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			L),
	      insert_ht(L, E, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
		      M),
	    insert_ht(M, k(D, J, E), A)
	;   true
	).
spawns_all(A, B) :-
	spawns_all___2__0(A, B, _).
spawns_all___2__0(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
spawns_all___2__0(B, body, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, guard), C),
	member(D, C),
	D=suspension(_, active, _, _), !.
spawns_all___2__0(B, guard, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, body), C), !,
	spawns_all___2__0__0__4(C, B, guard, D).
spawns_all___2__0__0__4([], A, B, C) :-
	spawns_all___2__1(A, B, C).
spawns_all___2__0__0__4([A|G], C, H, I) :-
	(   A=suspension(_, active, B, D),
	    B==C,
	    D=body
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
			F),
	      delete_ht(F, k(C, body), A)
	    ),
	    spawns_all___2__0__0__4(G, C, H, I)
	;   spawns_all___2__0__0__4(G, C, H, I)
	).
spawns_all___2__0(A, B, C) :-
	spawns_all___2__1(A, B, C).
spawns_all___2__1(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	spawns_all___2__1__0__5(D, B, C, E).
spawns_all___2__1__0__5([], A, B, C) :-
	spawns_all___2__2(A, B, C).
spawns_all___2__1__0__5([A|P], C, E, Q) :-
	(   A=suspension(_, active, _, _, B, D, G),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  F),
		delete_ht(F, k(C, G), A)
	      ),
	      ( arg(4, A, H),
		(   var(H)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      I),
		    I=[_|J],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  L),
		delete_ht(L, k(C, E), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  M),
		delete_ht(M, C, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  N),
		delete_ht(N, G, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			O),
	      delete_ht(O, k(C, E, G), A)
	    ),
	    spawns_all___2__1__0__5(P, C, E, Q)
	;   spawns_all___2__1__0__5(P, C, E, Q)
	).
spawns_all___2__1(A, B, C) :-
	spawns_all___2__2(A, B, C).
spawns_all___2__2(B, guard, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
		  A),
	lookup_ht(A, k(B, body), C), !,
	spawns_all___2__2__0__6(C, B, guard, D).
spawns_all___2__2__0__6([], A, B, C) :-
	spawns_all___2__3(A, B, C).
spawns_all___2__2__0__6([A|O], C, P, Q) :-
	(   A=suspension(_, active, _, _, B, D, F),
	    B==C,
	    D=body
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  E),
		delete_ht(E, k(C, F), A)
	      ),
	      ( arg(4, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  K),
		delete_ht(K, k(C, body), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  L),
		delete_ht(L, C, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  M),
		delete_ht(M, F, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			N),
	      delete_ht(N, k(C, body, F), A)
	    ),
	    spawns_all___2__2__0__6(O, C, P, Q)
	;   spawns_all___2__2__0__6(O, C, P, Q)
	).
spawns_all___2__2(A, B, C) :-
	spawns_all___2__3(A, B, C).
spawns_all___2__3(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	spawns_all___2__3__0__7(D, B, C, E).
spawns_all___2__3__0__7([], A, B, C) :-
	spawns_all___2__4(A, B, C).
spawns_all___2__3__0__7([A|L], C, E, M) :-
	(   A=suspension(_, active, _, _, B, D),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( arg(4, A, 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, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			K),
	      delete_ht(K, k(C, E), A)
	    ),
	    spawns_all___2__3__0__7(L, C, E, M)
	;   spawns_all___2__3__0__7(L, C, E, M)
	).
spawns_all___2__3(A, B, C) :-
	spawns_all___2__4(A, B, C).
spawns_all___2__4(B, guard, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, body), C), !,
	spawns_all___2__4__0__8(C, B, guard, D).
spawns_all___2__4__0__8([], A, B, C) :-
	spawns_all___2__5(A, B, C).
spawns_all___2__4__0__8([A|K], C, L, M) :-
	(   A=suspension(_, active, _, _, B, D),
	    B==C,
	    D=body
	->  ( setarg(2, A, removed),
	      ( arg(4, A, E),
		(   var(E)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			      F),
		    F=[_|G],
		    b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			     G),
		    (   G=[H|_]
		    ->  setarg(4, H, _)
		    ;   true
		    )
		;   E=[_, _|G],
		    setarg(2, E, G),
		    (   G=[H|_]
		    ->  setarg(4, H, E)
		    ;   true
		    )
		)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			  I),
		delete_ht(I, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			J),
	      delete_ht(J, k(C, body), A)
	    ),
	    spawns_all___2__4__0__8(K, C, L, M)
	;   spawns_all___2__4__0__8(K, C, L, M)
	).
spawns_all___2__4(A, B, C) :-
	spawns_all___2__5(A, B, C).
spawns_all___2__5(B, D, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, B, D),
	'chr gen_id'(E),
	spawns_all___2__5__0__9(F, B, D, C).
spawns_all___2__5__0__9([], A, B, C) :-
	spawns_all___2__6(A, B, C).
spawns_all___2__5__0__9([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, _, E, _, B, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
		      D),
	    lookup_ht(D, E, F)
	->  spawns_all___2__5__1__9(F,
				    E,
				    G,
				    A,
				    H,
				    C,
				    I,
				    J)
	;   spawns_all___2__5__0__9(H, C, I, J)
	).
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([A|V], C, E, W, X, D, U, Q) :-
	(   ( A=suspension(_, active, _, _, G, M, B),
	      B==C
	    ),
	    \+ is_passive(D, E)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  F),
		delete_ht(F, k(G, C), A)
	      ),
	      ( arg(4, A, H),
		(   var(H)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      I),
		    I=[_|J],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  L),
		delete_ht(L, k(G, M), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  N),
		delete_ht(N, G, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  O),
		delete_ht(O, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			P),
	      delete_ht(P, k(G, M, C), A)
	    ),
	    ( arg(2, Q, R),
	      setarg(2, Q, active),
	      (   R==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
			      S),
		    insert_ht(S, D, Q)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
			    T),
		  insert_ht(T, k(D, U), Q)
	      ;   true
	      )
	    ),
	    spawns_all(G, M),
	    (   Q=suspension(_, active, _, _)
	    ->  setarg(2, Q, inactive),
		spawns_all___2__5__1__9(V,
					C,
					E,
					W,
					X,
					D,
					U,
					Q)
	    ;   true
	    )
	;   spawns_all___2__5__1__9(V,
				    C,
				    E,
				    W,
				    X,
				    D,
				    U,
				    Q)
	).
spawns_all___2__5(B, C, A) :-
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	spawns_all___2__6(B, C, A).
spawns_all___2__6(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	spawns_all___2__6__0__10(C, B, D, E).
spawns_all___2__6__0__10([], A, B, C) :-
	spawns_all___2__7(A, B, C).
spawns_all___2__6__0__10([A|K], C, J, F) :-
	(   A=suspension(_, active, _, _, E, _, B, D, _),
	    B==C,
	    \+ \+ spawns_all_triggers_implies_spawns_all,
	    \+ is_passive(C, D),
	    may_trigger(E)
	->  ( arg(2, F, G),
	      setarg(2, F, active),
	      (   G==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
			      H),
		    insert_ht(H, C, F)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
			    I),
		  insert_ht(I, k(C, J), F)
	      ;   true
	      )
	    ),
	    spawns_all_triggers_implies_spawns_all,
	    (   F=suspension(_, active, _, _)
	    ->  setarg(2, F, inactive),
		spawns_all___2__6__0__10(K, C, J, F)
	    ;   true
	    )
	;   spawns_all___2__6__0__10(K, C, J, F)
	).
spawns_all___2__6(A, B, C) :-
	spawns_all___2__7(A, B, C).
spawns_all___2__7(D, F, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
			C),
	      insert_ht(C, D, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		      E),
	    insert_ht(E, k(D, F), A)
	;   true
	).
spawns_all_triggers(A, B) :-
	spawns_all_triggers___2__0(A, B, _).
spawns_all_triggers___2__0(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _), !.
spawns_all_triggers___2__0(B, body, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, guard), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
spawns_all_triggers___2__0(B, guard, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		  A),
	lookup_ht(A, k(B, body), C), !,
	spawns_all_triggers___2__0__0__4(C, B, guard, D).
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([A|K], C, L, M) :-
	(   A=suspension(_, active, _, _, B, D),
	    B==C,
	    D=body
	->  ( setarg(2, A, removed),
	      ( arg(4, A, E),
		(   var(E)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			      F),
		    F=[_|G],
		    b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			     G),
		    (   G=[H|_]
		    ->  setarg(4, H, _)
		    ;   true
		    )
		;   E=[_, _|G],
		    setarg(2, E, G),
		    (   G=[H|_]
		    ->  setarg(4, H, E)
		    ;   true
		    )
		)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			  I),
		delete_ht(I, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			J),
	      delete_ht(J, k(C, body), A)
	    ),
	    spawns_all_triggers___2__0__0__4(K,
					     C,
					     L,
					     M)
	;   spawns_all_triggers___2__0__0__4(K,
					     C,
					     L,
					     M)
	).
spawns_all_triggers___2__0(A, B, C) :-
	spawns_all_triggers___2__1(A, B, C).
spawns_all_triggers___2__1(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !,
	(   var(F)
	->  true
	;   arg(2, F, G),
	    setarg(2, F, removed),
	    (   G==not_stored_yet
	    ->  true
	    ;   ( arg(4, F, 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, B, F)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			  M),
		delete_ht(M, k(B, C), F)
	    )
	).
spawns_all_triggers___2__1(B, body, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	lookup_ht(A, k(B, guard), C),
	member(D, C),
	D=suspension(_, active, _, _), !,
	(   var(E)
	->  true
	;   arg(2, E, F),
	    setarg(2, E, removed),
	    (   F==not_stored_yet
	    ->  true
	    ;   ( arg(4, E, 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, B, E)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			  L),
		delete_ht(L, k(B, body), E)
	    )
	).
spawns_all_triggers___2__1(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	spawns_all_triggers___2__1__0__7(D, B, C, E).
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([A|P], C, E, Q) :-
	(   ( A=suspension(_, active, _, _, B, D, F),
	      B==C,
	      D==E
	    ),
	    may_trigger(F)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  G),
		delete_ht(G, k(C, F), A)
	      ),
	      ( arg(4, A, H),
		(   var(H)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      I),
		    I=[_|J],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  L),
		delete_ht(L, k(C, E), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  M),
		delete_ht(M, C, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  N),
		delete_ht(N, F, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			O),
	      delete_ht(O, k(C, E, F), A)
	    ),
	    spawns_all_triggers___2__1__0__7(P,
					     C,
					     E,
					     Q)
	;   spawns_all_triggers___2__1__0__7(P,
					     C,
					     E,
					     Q)
	).
spawns_all_triggers___2__1(A, B, C) :-
	spawns_all_triggers___2__2(A, B, C).
spawns_all_triggers___2__2(B, guard, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-12',
		  A),
	lookup_ht(A, k(B, body), C), !,
	spawns_all_triggers___2__2__0__8(C, B, guard, D).
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([A|O], C, P, Q) :-
	(   ( A=suspension(_, active, _, _, B, D, E),
	      B==C,
	      D=body
	    ),
	    may_trigger(E)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  F),
		delete_ht(F, k(C, E), A)
	      ),
	      ( arg(4, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  K),
		delete_ht(K, k(C, body), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  L),
		delete_ht(L, C, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  M),
		delete_ht(M, E, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			N),
	      delete_ht(N, k(C, body, E), A)
	    ),
	    spawns_all_triggers___2__2__0__8(O,
					     C,
					     P,
					     Q)
	;   spawns_all_triggers___2__2__0__8(O,
					     C,
					     P,
					     Q)
	).
spawns_all_triggers___2__2(A, B, C) :-
	spawns_all_triggers___2__3(A, B, C).
spawns_all_triggers___2__3(J, L, C) :-
	nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',
		  A),
	member(B, A),
	B=suspension(_, active, _), !,
	(   var(C)
	->  true
	;   arg(2, C, D),
	    setarg(2, C, removed),
	    (   D==not_stored_yet
	    ->  true
	    ;   ( arg(4, C, E),
		  (   var(E)
		  ->  nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
				F),
		      F=[_|G],
		      b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			       G),
		      (   G=[H|_]
		      ->  setarg(4, H, _)
		      ;   true
		      )
		  ;   E=[_, _|G],
		      setarg(2, E, G),
		      (   G=[H|_]
		      ->  setarg(4, H, E)
		      ;   true
		      )
		  )
		),
		( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			    I),
		  delete_ht(I, J, C)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			  K),
		delete_ht(K, k(J, L), C)
	    )
	),
	spawns_all(J, L).
spawns_all_triggers___2__3(B, D, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, _, B, D),
	'chr gen_id'(E),
	spawns_all_triggers___2__3__0__10(F, B, D, 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([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, _, E, _, B, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
		      D),
	    lookup_ht(D, E, F)
	->  spawns_all_triggers___2__3__1__10(F,
					      E,
					      G,
					      A,
					      H,
					      C,
					      I,
					      J)
	;   spawns_all_triggers___2__3__0__10(H, C, I, J)
	).
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([A|Y], C, E, Z, A1, D, X, Q) :-
	(   ( A=suspension(_, active, _, _, G, M, B),
	      B==C
	    ),
	    may_trigger(C),
	    \+ is_passive(D, E)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  F),
		delete_ht(F, k(G, C), A)
	      ),
	      ( arg(4, A, H),
		(   var(H)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
			      I),
		    I=[_|J],
		    b_setval('$chr_store_global_ground_chr_translate____spawns___3',
			     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___3-12',
			  L),
		delete_ht(L, k(G, M), A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-1',
			  N),
		delete_ht(N, G, A)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
			  O),
		delete_ht(O, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			P),
	      delete_ht(P, k(G, M, C), A)
	    ),
	    ( arg(2, Q, R),
	      setarg(2, Q, active),
	      (   R==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			      S),
		    T=[Q|S],
		    b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			     T),
		    (   S=[U|_]
		    ->  setarg(4, U, T)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			      V),
		    insert_ht(V, D, Q)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			    W),
		  insert_ht(W, k(D, X), Q)
	      ;   true
	      )
	    ),
	    spawns_all_triggers(G, M),
	    (   Q=suspension(_, active, _, _, _, _)
	    ->  setarg(2, Q, inactive),
		spawns_all_triggers___2__3__1__10(Y,
						  C,
						  E,
						  Z,
						  A1,
						  D,
						  X,
						  Q)
	    ;   true
	    )
	;   spawns_all_triggers___2__3__1__10(Y,
					      C,
					      E,
					      Z,
					      A1,
					      D,
					      X,
					      Q)
	).
spawns_all_triggers___2__3(B, C, A) :-
	A=suspension(D, not_stored_yet, t, _, B, C),
	'chr gen_id'(D),
	spawns_all_triggers___2__4(B, C, A).
spawns_all_triggers___2__4(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, C), !,
	spawns_all_triggers___2__4__0__11(C, B, D, E).
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([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, _, E, _, B, G, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-3',
		      D),
	    lookup_ht(D, E, F)
	->  spawns_all_triggers___2__4__1__11(F,
					      E,
					      G,
					      A,
					      H,
					      C,
					      I,
					      J)
	;   spawns_all_triggers___2__4__0__11(H, C, I, J)
	).
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([A|R], C, H, E, S, G, O, D) :-
	(   A=suspension(_, active, _, _, P, Q, B),
	    B==C,
	    ( F=t(123, D, E, A),
	      '$novel_production'(D, F),
	      '$novel_production'(A, F)
	    ),
	    \+ may_trigger(C),
	    \+ is_passive(G, H)
	->  '$extend_history'(D, F),
	    ( arg(2, D, I),
	      setarg(2, D, active),
	      (   I==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			      J),
		    K=[D|J],
		    b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			     K),
		    (   J=[L|_]
		    ->  setarg(4, L, K)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			      M),
		    insert_ht(M, G, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			    N),
		  insert_ht(N, k(G, O), D)
	      ;   true
	      )
	    ),
	    spawns_all_triggers(P, Q),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		spawns_all_triggers___2__4__1__11(R,
						  C,
						  H,
						  E,
						  S,
						  G,
						  O,
						  D)
	    ;   true
	    )
	;   spawns_all_triggers___2__4__1__11(R,
					      C,
					      H,
					      E,
					      S,
					      G,
					      O,
					      D)
	).
spawns_all_triggers___2__4(A, B, C) :-
	spawns_all_triggers___2__5(A, B, C).
spawns_all_triggers___2__5(B, C, D) :-
	nb_getval('$chr_store_global_ground_chr_translate____spawns___3',
		  A), !,
	spawns_all_triggers___2__5__0__12(A, B, C, D).
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([A|F], G, H, I) :-
	(   A=suspension(_, active, _, _, C, _, E),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		      B),
	    lookup_ht(B, C, D)
	->  spawns_all_triggers___2__5__1__12(D,
					      C,
					      E,
					      A,
					      F,
					      G,
					      H,
					      I)
	;   spawns_all_triggers___2__5__0__12(F, G, H, I)
	).
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([A|R], C, I, D, S, O, Q, E) :-
	(   A=suspension(_, active, _, _, H, _, B, G, _),
	    B==C,
	    ( F=t(125, D, A, E),
	      '$novel_production'(D, F),
	      '$novel_production'(E, F)
	    ),
	    \+ is_passive(C, G),
	    may_trigger(H),
	    \+ may_trigger(I)
	->  '$extend_history'(E, F),
	    ( arg(2, E, J),
	      setarg(2, E, active),
	      (   J==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			      K),
		    L=[E|K],
		    b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			     L),
		    (   K=[M|_]
		    ->  setarg(4, M, L)
		    ;   true
		    )
		  ),
		  ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			      N),
		    insert_ht(N, O, E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			    P),
		  insert_ht(P, k(O, Q), E)
	      ;   true
	      )
	    ),
	    spawns(O, Q, I),
	    (   E=suspension(_, active, _, _, _, _)
	    ->  setarg(2, E, inactive),
		spawns_all_triggers___2__5__1__12(R,
						  C,
						  I,
						  D,
						  S,
						  O,
						  Q,
						  E)
	    ;   true
	    )
	;   spawns_all_triggers___2__5__1__12(R,
					      C,
					      I,
					      D,
					      S,
					      O,
					      Q,
					      E)
	).
spawns_all_triggers___2__5(A, B, C) :-
	spawns_all_triggers___2__6(A, B, C).
spawns_all_triggers___2__6(G, I, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			C),
	      D=[A|C],
	      b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
		       D),
	      (   C=[E|_]
	      ->  setarg(4, E, D)
	      ;   true
	      )
	    ),
	    ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			F),
	      insert_ht(F, G, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		      H),
	    insert_ht(H, k(G, I), A)
	;   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),
	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',
		  C), !,
	A=suspension(B, not_stored_yet, _),
	'chr gen_id'(B),
	spawns_all_triggers_implies_spawns_all___0__0__0__3(C, 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([A|O], J) :-
	(   A=suspension(_, active, _, _, G, I)
	->  ( setarg(2, A, removed),
	      ( arg(4, A, B),
		(   var(B)
		->  nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			      C),
		    C=[_|D],
		    b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers___2',
			     D),
		    (   D=[E|_]
		    ->  setarg(4, E, _)
		    ;   true
		    )
		;   B=[_, _|D],
		    setarg(2, B, D),
		    (   D=[E|_]
		    ->  setarg(4, E, B)
		    ;   true
		    )
		)
	      ),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
			  F),
		delete_ht(F, G, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
			H),
	      delete_ht(H, k(G, I), A)
	    ),
	    ( arg(2, J, K),
	      setarg(2, J, active),
	      (   K==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',
			    L),
		  M=[J|L],
		  b_setval('$chr_store_global_ground_chr_translate____spawns_all_triggers_implies_spawns_all___0',
			   M),
		  (   L=[N|_]
		  ->  setarg(3, N, M)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    spawns_all(G, I),
	    (   J=suspension(_, active, _)
	    ->  setarg(2, J, inactive),
		spawns_all_triggers_implies_spawns_all___0__0__0__3(O,
								    J)
	    ;   true
	    )
	;   spawns_all_triggers_implies_spawns_all___0__0__0__3(O,
								J)
	).
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(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
		  A),
	(   lookup_ht(A, k(B, guard), C),
	    member(D, C),
	    D=suspension(_, active, _, _), !
	;   lookup_ht(A, k(B, E), F),
	    member(G, F),
	    G=suspension(_, active, _, _), !
	).
all_spawned(_, _) :-
	fail.
is_observed(B, C, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, F, _, _), !,
	do_is_observed(B, F, G).
is_observed(_, _, _) :-
	fail.
do_is_observed(B, C, A) :-
	var(A), !,
	do_is_observed(B, C).
do_is_observed(B, K, I) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _, _, _, _, F, _, _),
	  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		    E),
	  lookup_ht(E, F, G),
	  member(H, G),
	  H=suspension(_, active, _, _, P, _, _, N, _),
	  H\==D,
	  ground(I)
	),
	(   (   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-12',
			  J),
		lookup_ht(J, k(K, I), L),
		member(M, L),
		M=suspension(_, active, _, _),
		\+ is_passive(F, N), !
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-123',
			  O),
		lookup_ht(O, k(K, I, P), Q),
		member(R, Q),
		R=suspension(_, active, _, _, _, _, _),
		\+ is_passive(F, N), !
	    )
	;   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-12',
		      S),
	    lookup_ht(S, k(K, I), T),
	    member(U, T),
	    U=suspension(_, active, _, _, _, _),
	    \+ is_passive(F, N),
	    may_trigger(P), !
	).
do_is_observed(_, _, _) :-
	chr_pp_flag(observation_analysis, off).
do_is_observed(B, J) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		    A),
	  lookup_ht(A, B, C),
	  member(D, C),
	  D=suspension(_, active, _, _, _, _, F, _, _),
	  nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		    E),
	  lookup_ht(E, F, G),
	  member(H, G),
	  H=suspension(_, active, _, _, O, _, _, M, _),
	  H\==D
	),
	(   (   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all___2-1',
			  I),
		lookup_ht(I, J, K),
		member(L, K),
		L=suspension(_, active, _, _),
		\+ is_passive(F, M), !
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____spawns___3-13',
			  N),
		lookup_ht(N, k(J, O), P),
		member(Q, P),
		Q=suspension(_, active, _, _, _, _, _),
		\+ is_passive(F, M), !
	    )
	;   nb_getval('$chr_store_multi_hash_chr_translate____spawns_all_triggers___2-1',
		      R),
	    lookup_ht(R, J, S),
	    member(T, S),
	    T=suspension(_, active, _, _, _, _),
	    \+ is_passive(F, M),
	    may_trigger(O), !
	).
do_is_observed(_, _) :-
	chr_pp_flag(observation_analysis, off).
generate_indexed_variables_body(B/C, G, H, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		  A),
	lookup_ht(A, B/C, D),
	member(E, D),
	E=suspension(_, active, _, _, _, J), !,
	get_indexing_spec(B/C, F),
	(   chr_pp_flag(term_indexing, on)
	->  spectermvars(F, G, B, C, H, I)
	;   get_constraint_type_det(B/C, K),
	    create_indexed_variables_body(G,
					  J,
					  K,
					  I,
					  1,
					  B/C,
					  L,
					  M),
	    (   L==empty
	    ->  H=true,
		I=[]
	    ;   M==0
	    ->  (   G=[N]
		->  true
		;   N=..[term|G]
		),
		H=term_variables(N, I)
	    ;   L=H
	    )
	).
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) :-
	D=suspension(C, active, _, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
		  E),
	F=[D|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, G) :-
	(   'chr newvia_1'(A, B)
	->  get_attr(B, chr_translate, C),
	    C=v(_, D, _, _, _, _, _, _, _, _, _)
	;   nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
		      D)
	),
	member(E, D),
	E=suspension(_, active, _, _, F),
	F==A, !,
	(   var(G)
	->  true
	;   G=suspension(_, H, _, _, I),
	    setarg(2, G, removed),
	    (   H==not_stored_yet
	    ->  J=[]
	    ;   term_variables(I, J),
		( arg(4, G, 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,
								       G)
	    )
	).
generate_empty_named_history_initialisation___1__0(B, A) :-
	nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
		  D), !,
	(   var(A)
	->  A=suspension(C, not_stored_yet, 0, _, B),
	    'chr gen_id'(C)
	;   true
	),
	generate_empty_named_history_initialisation___1__0__0__3(D,
								 B,
								 A).
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([A|T], O, F) :-
	(   A=suspension(_, active, _, P, S)
	->  ( setarg(2, A, removed),
	      arg(3, A, B),
	      (   var(B)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
			    C),
		  C=[_|D],
		  b_setval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
			   D),
		  (   D=[E|_]
		  ->  setarg(3, E, _)
		  ;   true
		  )
	      ;   B=[_, _|D],
		  setarg(2, B, D),
		  (   D=[E|_]
		  ->  setarg(3, E, B)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, F, I),
	      setarg(2, F, active),
	      ( arg(3, F, G),
		H is G+1,
		setarg(3, F, H)
	      ),
	      (   I==not_stored_yet
	      ->  F=suspension(_, _, _, _, J),
		  term_variables(J, N),
		  ( nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
			      K),
		    L=[F|K],
		    b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
			     L),
		    (   K=[M|_]
		    ->  setarg(4, M, L)
		    ;   true
		    )
		  ),
		  attach_generate_empty_named_history_initialisation___1(N,
									 F)
	      ;   true
	      )
	    ),
	    ( empty_named_history_global_variable(O, Q),
	      P=[(:-nb_setval(Q, 0))|R],
	      empty_named_history_initialisations(R, S)
	    ),
	    (   F=suspension(_, active, H, _, _)
	    ->  setarg(2, F, inactive),
		generate_empty_named_history_initialisation___1__0__0__3(T,
									 O,
									 F)
	    ;   true
	    )
	;   generate_empty_named_history_initialisation___1__0__0__3(T,
								     O,
								     F)
	).
generate_empty_named_history_initialisation___1__0(B, A) :-
	(   var(A)
	->  A=suspension(C, not_stored_yet, 0, _, B),
	    'chr gen_id'(C)
	;   true
	),
	generate_empty_named_history_initialisation___1__1(B, A).
generate_empty_named_history_initialisation___1__1(_, A) :-
	arg(2, A, D),
	setarg(2, A, active),
	arg(3, A, B),
	C is B+1,
	setarg(3, A, C),
	(   D==not_stored_yet
	->  A=suspension(_, _, _, _, E),
	    term_variables(E, I),
	    ( nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
			F),
	      G=[A|F],
	      b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
		       G),
	      (   F=[H|_]
	      ->  setarg(4, H, G)
	      ;   true
	      )
	    ),
	    attach_generate_empty_named_history_initialisation___1(I,
								   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]___[]',
		  C), !,
	A=suspension(B, not_stored_yet, t, _),
	'chr gen_id'(B),
	find_empty_named_histories___0__0__0__1(C, 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([A|J], C) :-
	(   A=suspension(_, active, _, _, I, B),
	    B=[],
	    D=t(142, C, A),
	    '$novel_production'(C, D),
	    '$novel_production'(A, D)
	->  '$extend_history'(C, D),
	    ( arg(2, C, E),
	      setarg(2, C, active),
	      (   E==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',
			    F),
		  G=[C|F],
		  b_setval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',
			   G),
		  (   F=[H|_]
		  ->  setarg(4, H, G)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    generate_empty_named_history_initialisation(I),
	    (   C=suspension(_, active, _, _)
	    ->  setarg(2, C, inactive),
		find_empty_named_histories___0__0__0__1(J, C)
	    ;   true
	    )
	;   find_empty_named_histories___0__0__0__1(J, C)
	).
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(B) :-
	nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
		  A), !,
	find_empty_named_histories___0__1__0__2(A, B).
find_empty_named_histories___0__1__0__2([], A) :-
	find_empty_named_histories___0__2(A).
find_empty_named_histories___0__1__0__2([A|H], I) :-
	(   A=suspension(_, active, _, _, _)
	->  ( A=suspension(_, _, _, _, B),
	      setarg(2, A, removed),
	      term_variables(B, G),
	      ( arg(4, A, C),
		(   var(C)
		->  nb_getval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
			      D),
		    D=[_|E],
		    b_setval('$chr_store_global_list_chr_translate____generate_empty_named_history_initialisation___1',
			     E),
		    (   E=[F|_]
		    ->  setarg(4, F, _)
		    ;   true
		    )
		;   C=[_, _|E],
		    setarg(2, C, E),
		    (   E=[F|_]
		    ->  setarg(4, F, C)
		    ;   true
		    )
		)
	      ),
	      detach_generate_empty_named_history_initialisation___1(G,
								     A)
	    ),
	    find_empty_named_histories___0__1__0__2(H, I)
	;   find_empty_named_histories___0__1__0__2(H, I)
	).
find_empty_named_histories___0__1(A) :-
	find_empty_named_histories___0__2(A).
find_empty_named_histories___0__2(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, M, N), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____empty_named_history_initialisations___2',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	(   var(G)
	->  true
	;   arg(2, G, H),
	    setarg(2, G, removed),
	    (   H==not_stored_yet
	    ->  true
	    ;   arg(4, G, I),
		(   var(I)
		->  nb_getval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',
			      J),
		    J=[_|K],
		    b_setval('$chr_store_global_ground_chr_translate____find_empty_named_histories___0',
			     K),
		    (   K=[L|_]
		    ->  setarg(4, L, _)
		    ;   true
		    )
		;   I=[_, _|K],
		    setarg(2, I, K),
		    (   K=[L|_]
		    ->  setarg(4, L, I)
		    ;   true
		    )
		)
	    )
	),
	M=N.
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) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',
		  D),
	E=[C|D],
	b_setval('$chr_store_global_ground_chr_translate____module_initializer___1',
		 E),
	(   D=[F|_]
	->  setarg(3, F, E)
	;   true
	).
module_initializers(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____module_initializer___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____module_initializer___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	G=(H, I),
	module_initializers(I).
module_initializers(true).
actual_atomic_multi_hash_keys(B, I, O) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, J),
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  H),
	delete_ht(H, B, D),
	selectchk(multi_hash([I]), J, Q),
	I=[K],
	(   get_constraint_arg_type(B, K, L),
	    enumerated_atomic_type(L, M)
	->  N=M,
	    P=complete
	;   N=O,
	    P=incomplete
	),
	actual_store_types(B,
			   
			   [ atomic_constants(I, N, P)
			   | Q
			   ]).
actual_atomic_multi_hash_keys(B, C, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, I), !,
	setarg(2, E, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  F),
	delete_ht(F, k(B, C), E),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
		  G),
	delete_ht(G, B, E),
	append(H, I, J),
	sort(J, K),
	actual_atomic_multi_hash_keys(B, C, K).
actual_atomic_multi_hash_keys(B, C, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, H), !,
	setarg(2, E, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  F),
	delete_ht(F, k(B, C), E),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
		  G),
	delete_ht(G, B, E),
	append(H, I, J),
	sort(J, K),
	actual_ground_multi_hash_keys(B, C, K).
actual_atomic_multi_hash_keys(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
actual_atomic_multi_hash_keys(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  E),
	insert_ht(E, k(A, B), F),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
		  G),
	insert_ht(G, A, F).
actual_ground_multi_hash_keys(B, I, M) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, O),
	nb_getval('$chr_store_multi_hash_chr_translate____validate_store_type_assumption___1-1',
		  E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_store_types___2-1',
		  H),
	delete_ht(H, B, D),
	(   I=[J],
	    get_constraint_arg_type(B, J, K),
	    K=chr_enum(L)
	->  N=complete
	;   L=M,
	    N=incomplete
	),
	selectchk(multi_hash([I]), O, P),
	actual_store_types(B,
			   
			   [ ground_constants(I, L, N)
			   | P
			   ]).
actual_ground_multi_hash_keys(B, C, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, I), !,
	setarg(2, E, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  F),
	delete_ht(F, k(B, C), E),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
		  G),
	delete_ht(G, B, E),
	append(H, I, J),
	sort(J, K),
	actual_ground_multi_hash_keys(B, C, K).
actual_ground_multi_hash_keys(B, C, H) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, I), !,
	setarg(2, E, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  F),
	delete_ht(F, k(B, C), E),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
		  G),
	delete_ht(G, B, E),
	append(H, I, J),
	sort(J, K),
	actual_ground_multi_hash_keys(B, C, K).
actual_ground_multi_hash_keys(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
actual_ground_multi_hash_keys(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  E),
	insert_ht(E, k(A, B), F),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
		  G),
	insert_ht(G, A, F).
actual_non_ground_multi_hash_key(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
actual_non_ground_multi_hash_key(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	actual_non_ground_multi_hash_key___2__0__0__3(D, B, C).
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([A|H], C, E) :-
	(   A=suspension(_, active, B, D, _),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-12',
			  F),
		delete_ht(F, k(C, E), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_atomic_multi_hash_keys___3-1',
			G),
	      delete_ht(G, C, A)
	    ),
	    actual_non_ground_multi_hash_key___2__0__0__3(H,
							  C,
							  E)
	;   actual_non_ground_multi_hash_key___2__0__0__3(H,
							  C,
							  E)
	).
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(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	actual_non_ground_multi_hash_key___2__1__0__4(D, B, C).
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([A|H], C, E) :-
	(   A=suspension(_, active, B, D, _),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-12',
			  F),
		delete_ht(F, k(C, E), A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____actual_ground_multi_hash_keys___3-1',
			G),
	      delete_ht(G, C, A)
	    ),
	    actual_non_ground_multi_hash_key___2__1__0__4(H,
							  C,
							  E)
	;   actual_non_ground_multi_hash_key___2__1__0__4(H,
							  C,
							  E)
	).
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) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____actual_non_ground_multi_hash_key___2-12',
		  D),
	insert_ht(D, k(A, B), E).
symbol_count(A, B) :-
	symbol_count___2__0(A, B, _).
symbol_count___2__0(A, T, M) :-
	(   'chr newvia_1'(A, B)
	->  get_attr(B, chr_translate, C),
	    C=v(_, _, _, D, _, _, _, _, _, _, _)
	;   nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',
		      D)
	),
	member(E, D),
	E=suspension(_, active, _, _, _, F, U),
	F==A, !,
	E=suspension(_, _, _, _, _, G, _),
	setarg(2, E, removed),
	term_variables(G, L),
	arg(5, E, H),
	(   var(H)
	->  nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',
		      I),
	    I=[_|J],
	    b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',
		     J),
	    (   J=[K|_]
	    ->  setarg(5, K, _)
	    ;   true
	    )
	;   H=[_, _|J],
	    setarg(2, H, J),
	    (   J=[K|_]
	    ->  setarg(5, K, H)
	    ;   true
	    )
	),
	detach_fresh_symbol___2(L, E),
	(   var(M)
	->  true
	;   M=suspension(_, _, _, N, _),
	    setarg(2, M, removed),
	    term_variables(N, S),
	    ( arg(3, M, O),
	      (   var(O)
	      ->  nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',
			    P),
		  P=[_|Q],
		  b_setval('$chr_store_global_list_chr_translate____symbol_count___2',
			   Q),
		  (   Q=[R|_]
		  ->  setarg(3, R, _)
		  ;   true
		  )
	      ;   O=[_, _|Q],
		  setarg(2, O, Q),
		  (   Q=[R|_]
		  ->  setarg(3, R, O)
		  ;   true
		  )
	      )
	    ),
	    detach_symbol_count___2(S, M)
	),
	atom_concat(A, T, U),
	V is T+1,
	symbol_count(A, V).
symbol_count___2__0(B, C, A) :-
	(   var(A)
	->  ( A=suspension(D, active, _, B, C),
	      term_variables(B, H),
	      'chr gen_id'(D)
	    ),
	    ( nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',
			E),
	      F=[A|E],
	      b_setval('$chr_store_global_list_chr_translate____symbol_count___2',
		       F),
	      (   E=[G|_]
	      ->  setarg(3, G, F)
	      ;   true
	      )
	    ),
	    attach_symbol_count___2(H, A)
	;   setarg(2, A, active)
	).
fresh_symbol(A, B) :-
	fresh_symbol___2__0(A, B, _).
fresh_symbol___2__0(A, V, M) :-
	(   'chr newvia_1'(A, B)
	->  get_attr(B, chr_translate, C),
	    C=v(_, _, D, _, _, _, _, _, _, _, _)
	;   nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',
		      D)
	),
	member(E, D),
	E=suspension(_, active, _, F, U),
	F==A, !,
	E=suspension(_, _, _, G, _),
	setarg(2, E, removed),
	term_variables(G, L),
	arg(3, E, H),
	(   var(H)
	->  nb_getval('$chr_store_global_list_chr_translate____symbol_count___2',
		      I),
	    I=[_|J],
	    b_setval('$chr_store_global_list_chr_translate____symbol_count___2',
		     J),
	    (   J=[K|_]
	    ->  setarg(3, K, _)
	    ;   true
	    )
	;   H=[_, _|J],
	    setarg(2, H, J),
	    (   J=[K|_]
	    ->  setarg(3, K, H)
	    ;   true
	    )
	),
	detach_symbol_count___2(L, E),
	(   var(M)
	->  true
	;   M=suspension(_, N, _, _, _, O, _),
	    setarg(2, M, removed),
	    (   N==not_stored_yet
	    ->  P=[]
	    ;   term_variables(O, P),
		( arg(5, M, Q),
		  (   var(Q)
		  ->  nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',
				R),
		      R=[_|S],
		      b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',
			       S),
		      (   S=[T|_]
		      ->  setarg(5, T, _)
		      ;   true
		      )
		  ;   Q=[_, _|S],
		      setarg(2, Q, S),
		      (   S=[T|_]
		      ->  setarg(5, T, Q)
		      ;   true
		      )
		  )
		),
		detach_fresh_symbol___2(P, M)
	    )
	),
	atom_concat(A, U, V),
	W is U+1,
	symbol_count(A, W).
fresh_symbol___2__0(B, C, A) :-
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	(   '$novel_production'(A, 157), !,
	    '$extend_history'(A, 157),
	    arg(2, A, G),
	    setarg(2, A, active),
	    arg(4, A, E),
	    F is E+1,
	    setarg(4, A, F),
	    (   G==not_stored_yet
	    ->  A=suspension(_, _, _, _, _, H, _),
		term_variables(H, L),
		( nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',
			    I),
		  J=[A|I],
		  b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',
			   J),
		  (   I=[K|_]
		  ->  setarg(5, K, J)
		  ;   true
		  )
		),
		attach_fresh_symbol___2(L, A)
	    ;   true
	    ),
	    symbol_count(B, 0),
	    (   A=suspension(_, active, _, F, _, _, _)
	    ->  setarg(2, A, inactive),
		fresh_symbol___2__1(B, C, A)
	    ;   true
	    )
	;   fresh_symbol___2__1(B, C, A)
	).
fresh_symbol___2__1(_, _, A) :-
	arg(2, A, D),
	setarg(2, A, active),
	arg(4, A, B),
	C is B+1,
	setarg(4, A, C),
	(   D==not_stored_yet
	->  A=suspension(_, _, _, _, _, E, _),
	    term_variables(E, I),
	    ( nb_getval('$chr_store_global_list_chr_translate____fresh_symbol___2',
			F),
	      G=[A|F],
	      b_setval('$chr_store_global_list_chr_translate____fresh_symbol___2',
		       G),
	      (   F=[H|_]
	      ->  setarg(5, H, G)
	      ;   true
	      )
	    ),
	    attach_fresh_symbol___2(I, A)
	;   true
	).
prolog_global_variable(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _), !.
prolog_global_variable(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',
		  D),
	E=[C|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, C).
prolog_global_variables(I) :-
	nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____prolog_global_variable___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	nb_getval('$chr_store_multi_hash_chr_translate____prolog_global_variable___1-1',
		  G),
	delete_ht(G, H, B),
	I=[H|J],
	prolog_global_variables(J).
prolog_global_variables([]).
background_info(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____background_info___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____background_info___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____background_info___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	append(G, H, I),
	background_info(I).
background_info(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____background_info___1',
		  D),
	E=[C|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(B, C, A) :-
	nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',
		  E), !,
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	background_info___2__0__0__1(E, B, C, A).
background_info___2__0__0__1([], A, B, C) :-
	background_info___2__1(A, B, C).
background_info___2__0__0__1([A|Q], D, O, B) :-
	(   A=suspension(_, active, _, _, _, F, _),
	    ( C=t(164, B, A),
	      '$novel_production'(B, C),
	      '$novel_production'(A, C)
	    ),
	    copy_term_nat(D, E),
	    subsumes_term(E, F)
	->  '$extend_history'(B, C),
	    ( arg(2, B, I),
	      setarg(2, B, active),
	      ( arg(4, B, G),
		H is G+1,
		setarg(4, B, H)
	      ),
	      (   I==not_stored_yet
	      ->  B=suspension(_, _, _, _, _, J, _),
		  term_variables(J, N),
		  ( nb_getval('$chr_store_global_list_chr_translate____background_info___2',
			      K),
		    L=[B|K],
		    b_setval('$chr_store_global_list_chr_translate____background_info___2',
			     L),
		    (   K=[M|_]
		    ->  setarg(5, M, L)
		    ;   true
		    )
		  ),
		  attach_background_info___2(N, B)
	      ;   true
	      )
	    ),
	    ( copy_term_nat(D-O, F-P),
	      get_bg_info_answer([P])
	    ),
	    (   B=suspension(_, active, _, H, _, _, _)
	    ->  setarg(2, B, inactive),
		background_info___2__0__0__1(Q,
					     D,
					     O,
					     B)
	    ;   true
	    )
	;   background_info___2__0__0__1(Q, D, O, B)
	).
background_info___2__0(B, C, A) :-
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	background_info___2__1(B, C, A).
background_info___2__1(_, _, A) :-
	arg(2, A, D),
	setarg(2, A, active),
	arg(4, A, B),
	C is B+1,
	setarg(4, A, C),
	(   D==not_stored_yet
	->  A=suspension(_, _, _, _, _, E, _),
	    term_variables(E, I),
	    ( nb_getval('$chr_store_global_list_chr_translate____background_info___2',
			F),
	      G=[A|F],
	      b_setval('$chr_store_global_list_chr_translate____background_info___2',
		       G),
	      (   F=[H|_]
	      ->  setarg(5, H, G)
	      ;   true
	      )
	    ),
	    attach_background_info___2(I, A)
	;   true
	).
get_bg_info(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____background_info___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, D), !,
	C=D.
get_bg_info([]).
get_bg_info(A, B) :-
	get_bg_info___2__0(A, B, _).
get_bg_info___2__0(B, C, A) :-
	nb_getval('$chr_store_global_list_chr_translate____background_info___2',
		  E), !,
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	get_bg_info___2__0__0__1(E, B, C, A).
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([A|Q], F, R, B) :-
	(   A=suspension(_, active, _, _, _, D, O),
	    ( C=t(164, A, B),
	      '$novel_production'(A, C),
	      '$novel_production'(B, C)
	    ),
	    copy_term_nat(D, E),
	    subsumes_term(E, F)
	->  '$extend_history'(B, C),
	    ( arg(2, B, I),
	      setarg(2, B, active),
	      ( arg(4, B, G),
		H is G+1,
		setarg(4, B, H)
	      ),
	      (   I==not_stored_yet
	      ->  B=suspension(_, _, _, _, _, J, _),
		  term_variables(J, N),
		  ( nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',
			      K),
		    L=[B|K],
		    b_setval('$chr_store_global_list_chr_translate____get_bg_info___2',
			     L),
		    (   K=[M|_]
		    ->  setarg(5, M, L)
		    ;   true
		    )
		  ),
		  attach_get_bg_info___2(N, B)
	      ;   true
	      )
	    ),
	    ( copy_term_nat(D-O, F-P),
	      get_bg_info_answer([P])
	    ),
	    (   B=suspension(_, active, _, H, _, _, _)
	    ->  setarg(2, B, inactive),
		get_bg_info___2__0__0__1(Q, F, R, B)
	    ;   true
	    )
	;   get_bg_info___2__0__0__1(Q, F, R, B)
	).
get_bg_info___2__0(B, C, A) :-
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	get_bg_info___2__1(B, C, A).
get_bg_info___2__1(_, O, G) :-
	nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, P), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	(   var(G)
	->  true
	;   G=suspension(_, H, _, _, _, I, _),
	    setarg(2, G, removed),
	    (   H==not_stored_yet
	    ->  J=[]
	    ;   term_variables(I, J),
		( arg(5, G, K),
		  (   var(K)
		  ->  nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',
				L),
		      L=[_|M],
		      b_setval('$chr_store_global_list_chr_translate____get_bg_info___2',
			       M),
		      (   M=[N|_]
		      ->  setarg(5, N, _)
		      ;   true
		      )
		  ;   K=[_, _|M],
		      setarg(2, K, M),
		      (   M=[N|_]
		      ->  setarg(5, N, K)
		      ;   true
		      )
		  )
		),
		detach_get_bg_info___2(J, G)
	    )
	),
	O=P.
get_bg_info___2__1(_, I, A) :-
	(   var(A)
	->  true
	;   A=suspension(_, B, _, _, _, C, _),
	    setarg(2, A, removed),
	    (   B==not_stored_yet
	    ->  D=[]
	    ;   term_variables(C, D),
		( arg(5, A, E),
		  (   var(E)
		  ->  nb_getval('$chr_store_global_list_chr_translate____get_bg_info___2',
				F),
		      F=[_|G],
		      b_setval('$chr_store_global_list_chr_translate____get_bg_info___2',
			       G),
		      (   G=[H|_]
		      ->  setarg(5, H, _)
		      ;   true
		      )
		  ;   E=[_, _|G],
		      setarg(2, E, G),
		      (   G=[H|_]
		      ->  setarg(5, H, E)
		      ;   true
		      )
		  )
		),
		detach_get_bg_info___2(D, A)
	    )
	),
	I=[].
get_bg_info_answer(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	append(G, H, I),
	get_bg_info_answer(I).
get_bg_info_answer(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____get_bg_info_answer___1',
		  D),
	E=[C|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(W, B, V, H, Z, Q, O, P) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, E),
	E=pragma(rule(F, J, N, _), _, _, _, _),
	F\==[],
	make_head_matchings_explicit(B, G, L),
	setof(I,
	      chr_translate:head_subset(G, H, I),
	      K), !,
	append(F, J, M),
	compute_derived_info(K,
			     L,
			     G,
			     M,
			     N,
			     O,
			     H,
			     P,
			     R,
			     T),
	append(Q, R, S),
	normalize_conj_list(S, A1),
	append(T, P, U),
	normalize_conj_list(U, B1),
	next_prev_rule(V, X, Y),
	prev_guard_list(W,
			X,
			Y,
			H,
			Z,
			A1,
			O,
			B1).
prev_guard_list(C, A, B, F, G, H, I, J) :-
	(   A>0
	->  next_prev_rule(B, D, E),
	    prev_guard_list(C,
			    D,
			    E,
			    F,
			    G,
			    H,
			    I,
			    J)
	;   prev_guard_list(C, F, G, H, I, J)
	).
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(M, B, I, F, O, A, _) :-
	A\==[], !,
	head_types_modes_condition(A, B, C),
	conj2list(C, E),
	term_variables(B, D),
	append([chr_pp_headvariables(D)|E], F, G),
	normalize_conj_list(G, H),
	append(B, H, J),
	add_background_info([I|J], K),
	append(H, K, L),
	normalize_conj_list(L, N),
	prev_guard_list(M, B, I, N, O, []).
prev_guard_list___6__0(B, Y, F, H, G, A1, Z) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _, _, E),
	    E=pragma(rule(S, T, F, L), V, W, X, B),
	    F\==true,
	    append(G, H, I),
	    (   conj2list(F, J),
		append(I, J, K),
		guard_entailment:entails_guard(K, fail)
	    ->  M=fail
	    ;   simplify_guard(F, L, I, M, U)
	    ),
	    F\==M, !,
	    setarg(2, D, removed),
	    arg(4, D, N),
	    (   var(N)
	    ->  nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			  O),
		O=[_|P],
		b_setval('$chr_store_global_ground_chr_translate____rule___2',
			 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____rule___2-1',
		      R),
	    delete_ht(R, B, D),
	    rule(B,
		 pragma(rule(S, T, M, U),
			V,
			W,
			X,
			B)),
	    prev_guard_list(B, Y, M, H, G, [])
	;    !,
	    Z=suspension(B1, not_stored_yet, t, _, B, Y, F, H, G, A1),
	    'chr gen_id'(B1),
	    prev_guard_list___6__0__0__3(C,
					 B,
					 Y,
					 F,
					 H,
					 G,
					 A1,
					 Z)
	).
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([A|R], C, S, G, I, H, T, D) :-
	(   A=suspension(_, active, _, _, B, F),
	    B==C,
	    ( E=t(178, D, A),
	      '$novel_production'(D, E),
	      '$novel_production'(A, E)
	    ),
	    chr_pp_flag(check_impossible_rules, on),
	    F=pragma(rule(_, _, G, _), _, _, _, C),
	    conj2list(G, K),
	    append(H, I, J),
	    append(J, K, L),
	    guard_entailment:entails_guard(L, fail)
	->  '$extend_history'(D, E),
	    ( arg(2, D, M),
	      setarg(2, D, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			      N),
		    O=[D|N],
		    b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			     O),
		    (   N=[P|_]
		    ->  setarg(4, P, O)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
			    Q),
		  insert_ht(Q, C, D)
	      ;   true
	      )
	    ),
	    ( chr_warning(weird_program,
			  'Heads will never match or guard will always fail in ~@.\n\tThis rule will never fire!\n',
			  [format_rule(F)]),
	      set_all_passive(C)
	    ),
	    (   D=suspension(_, active, _, _, _, _, _, _, _, _)
	    ->  setarg(2, D, inactive),
		prev_guard_list___6__0__0__3(R,
					     C,
					     S,
					     G,
					     I,
					     H,
					     T,
					     D)
	    ;   true
	    )
	;   prev_guard_list___6__0__0__3(R,
					 C,
					 S,
					 G,
					 I,
					 H,
					 T,
					 D)
	).
prev_guard_list___6__0(B, C, D, E, F, G, A) :-
	A=suspension(H, not_stored_yet, t, _, B, C, D, E, F, G),
	'chr gen_id'(H),
	prev_guard_list___6__1(B,
			       C,
			       D,
			       E,
			       F,
			       G,
			       A).
prev_guard_list___6__1(B, D, E, F, G, H, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C), !,
	prev_guard_list___6__1__0__4(C,
				     B,
				     D,
				     E,
				     F,
				     G,
				     H,
				     I).
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([A|M1], C, L, E, G, F, N1, F1) :-
	(   ( A=suspension(_, active, _, _, B, D),
	      B==C
	    ),
	    D=pragma(rule(J, K, E, H), X, Y, Z, C),
	    simplify_heads(F, G, E, H, I, R),
	    I\==[],
	    extract_arguments(J, M),
	    extract_arguments(K, N),
	    extract_arguments(L, O),
	    replace_some_heads(M,
			       N,
			       O,
			       I,
			       P,
			       Q,
			       E,
			       H,
			       S),
	    substitute_arguments(J, P, U),
	    substitute_arguments(K, Q, V),
	    append(R, S, T),
	    list2conj(T, W),
	    L1=pragma(rule(U, V, E,  (W, H)), X, Y, Z, C),
	    (   J\==U
	    ;   K\==V
	    )
	->  ( setarg(2, A, removed),
	      ( arg(4, A, A1),
		(   var(A1)
		->  nb_getval('$chr_store_global_ground_chr_translate____rule___2',
			      B1),
		    B1=[_|C1],
		    b_setval('$chr_store_global_ground_chr_translate____rule___2',
			     C1),
		    (   C1=[D1|_]
		    ->  setarg(4, D1, _)
		    ;   true
		    )
		;   A1=[_, _|C1],
		    setarg(2, A1, C1),
		    (   C1=[D1|_]
		    ->  setarg(4, D1, A1)
		    ;   true
		    )
		)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
			E1),
	      delete_ht(E1, C, A)
	    ),
	    ( arg(2, F1, G1),
	      setarg(2, F1, active),
	      (   G1==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			      H1),
		    I1=[F1|H1],
		    b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			     I1),
		    (   H1=[J1|_]
		    ->  setarg(4, J1, I1)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
			    K1),
		  insert_ht(K1, C, F1)
	      ;   true
	      )
	    ),
	    rule(C, L1),
	    (   F1=suspension(_, active, _, _, _, _, _, _, _, _)
	    ->  setarg(2, F1, inactive),
		prev_guard_list___6__1__0__4(M1,
					     C,
					     L,
					     E,
					     G,
					     F,
					     N1,
					     F1)
	    ;   true
	    )
	;   prev_guard_list___6__1__0__4(M1,
					 C,
					 L,
					 E,
					 G,
					 F,
					 N1,
					 F1)
	).
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(B, D, E, F, G, H, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C), !,
	prev_guard_list___6__2__0__5(C,
				     B,
				     D,
				     E,
				     F,
				     G,
				     H,
				     I).
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([A|G], C, H, I, J, K, L, M) :-
	(   ( A=suspension(_, active, _, _, B, F),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		      D),
	    lookup_ht(D, C, E)
	->  prev_guard_list___6__2__1__5(E,
					 F,
					 A,
					 G,
					 C,
					 H,
					 I,
					 J,
					 K,
					 L,
					 M)
	;   prev_guard_list___6__2__0__5(G,
					 C,
					 H,
					 I,
					 J,
					 K,
					 L,
					 M)
	).
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([A|H], I, J, K, C, L, M, N, O, P, Q) :-
	(   ( A=suspension(_, active, _, _, E, G, B, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		      D),
	    lookup_ht(D, k(E, C), F)
	->  prev_guard_list___6__2__2__5(F,
					 E,
					 G,
					 A,
					 H,
					 I,
					 J,
					 K,
					 C,
					 L,
					 M,
					 N,
					 O,
					 P,
					 Q)
	;   prev_guard_list___6__2__1__5(H,
					 I,
					 J,
					 K,
					 C,
					 L,
					 M,
					 N,
					 O,
					 P,
					 Q)
	).
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([A|J], D, K, B, L, M, N, O, F, P, Q, R, S, T, U) :-
	(   ( A=suspension(_, active, _, _, C, H, E, I, _),
	      A\==B,
	      C==D,
	      E==F
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		      G)
	->  prev_guard_list___6__2__3__5(G,
					 H,
					 I,
					 A,
					 J,
					 D,
					 K,
					 B,
					 L,
					 M,
					 N,
					 O,
					 F,
					 P,
					 Q,
					 R,
					 S,
					 T,
					 U)
	;   prev_guard_list___6__2__2__5(J,
					 D,
					 K,
					 B,
					 L,
					 M,
					 N,
					 O,
					 F,
					 P,
					 Q,
					 R,
					 S,
					 T,
					 U)
	).
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([A|U], B, S, V, W, F, C, X, Y, D, Z, A1, R, B1, C1, D1, E1, F1, L) :-
	(   A=suspension(_, active, _, G),
	    B<C,
	    chr_pp_flag(occurrence_subsumption, on),
	    D=pragma(rule(E, _, _, _), _, _, _, _),
	    E\==[],
	    \+ tree_set_memberchk(F, G)
	->  ( setarg(2, A, removed),
	      arg(3, A, H),
	      (   var(H)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			    I),
		  I=[_|J],
		  b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
			   J),
		  (   J=[K|_]
		  ->  setarg(3, K, _)
		  ;   true
		  )
	      ;   H=[_, _|J],
		  setarg(2, H, J),
		  (   J=[K|_]
		  ->  setarg(3, K, H)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  ( nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			      N),
		    O=[L|N],
		    b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			     O),
		    (   N=[P|_]
		    ->  setarg(4, P, O)
		    ;   true
		    )
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
			    Q),
		  insert_ht(Q, R, L)
	      ;   true
	      )
	    ),
	    ( first_occ_in_rule(R, F, B, S),
	      tree_set_add(G, F, T),
	      multiple_occ_constraints_checked(T)
	    ),
	    (   L=suspension(_, active, _, _, _, _, _, _, _, _)
	    ->  setarg(2, L, inactive),
		prev_guard_list___6__2__3__5(U,
					     B,
					     S,
					     V,
					     W,
					     F,
					     C,
					     X,
					     Y,
					     D,
					     Z,
					     A1,
					     R,
					     B1,
					     C1,
					     D1,
					     E1,
					     F1,
					     L)
	    ;   true
	    )
	;   prev_guard_list___6__2__3__5(U,
					 B,
					 S,
					 V,
					 W,
					 F,
					 C,
					 X,
					 Y,
					 D,
					 Z,
					 A1,
					 R,
					 B1,
					 C1,
					 D1,
					 E1,
					 F1,
					 L)
	).
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(N, _, _, _, _, _, G) :-
	nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, _), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	(   var(G)
	->  true
	;   arg(2, G, H),
	    setarg(2, G, removed),
	    (   H==not_stored_yet
	    ->  true
	    ;   ( arg(4, G, I),
		  (   var(I)
		  ->  nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
				J),
		      J=[_|K],
		      b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			       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____prev_guard_list___6-1',
			  M),
		delete_ht(M, N, G)
	    )
	).
prev_guard_list___6__3(G, _, _, _, _, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
			C),
	      D=[A|C],
	      b_setval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
		       D),
	      (   C=[E|_]
	      ->  setarg(4, E, D)
	      ;   true
	      )
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		      F),
	    insert_ht(F, G, A)
	;   true
	).
simplify_guards(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, E), !,
	E=pragma(rule(F, G, J, _), ids(K, L), _, _, B),
	append(F, G, H),
	make_head_matchings_explicit_not_negated(H, W, X),
	tree_set_empty(I),
	multiple_occ_constraints_checked(I),
	apply_guard_wrt_term(H, J, Y),
	append(K, L, M),
	findall(tuple(N, O, B)-(-B),
		( member(P, M),
		  get_occurrence_from_id(N, O, B, P)
		),
		Q),
	empty_q(R),
	insert_list_q(Q, R, S),
	next_prev_rule(S, _, T),
	next_prev_rule(T, U, V),
	prev_guard_list(B,
			U,
			V,
			W,
			J,
			[],
			X,
			[Y]),
	Z is B+1,
	simplify_guards(Z).
simplify_guards(_).
set_all_passive(A) :-
	set_all_passive___1__0(A, _).
set_all_passive___1__0(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		  A),
	lookup_ht(A, B, E), !,
	C=suspension(D, not_stored_yet, t, B),
	'chr gen_id'(D),
	set_all_passive___1__0__0__1(E, B, C).
set_all_passive___1__0__0__1([], A, B) :-
	set_all_passive___1__1(A, B).
set_all_passive___1__0__0__1([A|I], C, D) :-
	(   A=suspension(_, active, _, _, _, _, B, H, _),
	    B==C,
	    E=t(180, D, A),
	    '$novel_production'(D, E),
	    '$novel_production'(A, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',
			    G),
		  insert_ht(G, C, D)
	      ;   true
	      )
	    ),
	    passive(C, H),
	    (   D=suspension(_, active, _, _)
	    ->  setarg(2, D, inactive),
		set_all_passive___1__0__0__1(I, C, D)
	    ;   true
	    )
	;   set_all_passive___1__0__0__1(I, C, D)
	).
set_all_passive___1__0(B, A) :-
	A=suspension(C, not_stored_yet, t, B),
	'chr gen_id'(C),
	set_all_passive___1__1(B, A).
set_all_passive___1__1(D, A) :-
	(   var(A)
	->  true
	;   arg(2, A, B),
	    setarg(2, A, removed),
	    (   B==not_stored_yet
	    ->  true
	    ;   nb_getval('$chr_store_multi_hash_chr_translate____set_all_passive___1-1',
			  C),
		delete_ht(C, D, A)
	    )
	).
precompute_head_matchings :-
	precompute_head_matchings___0__0(_).
precompute_head_matchings___0__0(A) :-
	nb_getval('$chr_store_global_ground_chr_translate____rule___2', C), !,
	A=suspension(B, not_stored_yet, t, _),
	'chr gen_id'(B),
	precompute_head_matchings___0__0__0__1(C, A).
precompute_head_matchings___0__0__0__1([], A) :-
	precompute_head_matchings___0__1(A).
precompute_head_matchings___0__0__0__1([A|Q], B) :-
	(   A=suspension(_, active, _, _, N, H),
	    C=t(174, A, B),
	    '$novel_production'(A, C),
	    '$novel_production'(B, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, D),
	      setarg(2, B, active),
	      (   D==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',
			    E),
		  F=[B|E],
		  b_setval('$chr_store_global_ground_chr_translate____precompute_head_matchings___0',
			   F),
		  (   E=[G|_]
		  ->  setarg(4, G, F)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    ( H=pragma(rule(I, J, _, _), _, _, _, _),
	      append(I, J, K),
	      make_head_matchings_explicit_(K, L, M),
	      copy_term_nat(L-M, O-P),
	      make_head_matchings_explicit_memo_table(N,
						      O,
						      P)
	    ),
	    (   B=suspension(_, active, _, _)
	    ->  setarg(2, B, inactive),
		precompute_head_matchings___0__0__0__1(Q, B)
	    ;   true
	    )
	;   precompute_head_matchings___0__0__0__1(Q, B)
	).
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) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',
		  E),
	insert_ht(E, A, F).
make_head_matchings_explicit_memo_lookup(B, E, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____make_head_matchings_explicit_memo_table___3-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F, H), !,
	E=F,
	G=H.
make_head_matchings_explicit_memo_lookup(_, _, _) :-
	fail.
first_occ_in_rule(C, B, G, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, F, _, H, _),
	F<G, !,
	first_occ_in_rule(C, B, F, H).
first_occ_in_rule(D, A, E, F) :-
	A=B/C,
	functor(G, B, C),
	next_occ_in_rule(D, A, E, F, [], G).
next_occ_in_rule(B, F, K, L, _, M) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, G),
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-134',
		  E),
	lookup_ht(E, k(F, B, G), H),
	member(I, H),
	I=suspension(_, active, _, _, _, J, _, _, _),
	J is K+1, !,
	next_occ_in_rule(B, F, J, L, _, M).
next_occ_in_rule(B, I, M, T, Y, U) :-
	nb_getval('$chr_store_multi_hash_chr_translate____prev_guard_list___6-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, S, O, Z, V, _),
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', E),
	lookup_ht(E, B, F),
	member(G, F),
	G=suspension(_, active, _, _, _, N),
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		  H),
	lookup_ht(H, k(I, B), J),
	member(K, J),
	K=suspension(_, active, _, _, _, L, _, X, _),
	L is M+1,
	N=pragma(rule(P, Q, O, _), ids(_, _), _, _, B), !,
	append(P, Q, R),
	add_failing_occ(N,
			R,
			S,
			T,
			W,
			U,
			V,
			I,
			B1),
	(   W==[chr_pp_void_info]
	->  next_occ_in_rule(B,
			     I,
			     L,
			     X,
			     Y,
			     U)
	;   append(W, Y, F1),
	    add_failing_occ(N,
			    R,
			    S,
			    X,
			    N1,
			    U,
			    V,
			    I,
			    C1),
	    copy_term(Z, A1),
	    variable_replacement(Z, A1, E1),
	    copy_with_variable_replacement(Z, G1, B1),
	    copy_with_variable_replacement(Z, D1, C1),
	    copy_with_variable_replacement(D1, I1, E1),
	    append(F1, G1, H1),
	    append(H1, I1, K1),
	    copy_with_variable_replacement(V, L1, B1),
	    copy_with_variable_replacement(V, J1, C1),
	    append(J1, K1, M1),
	    append([chr_pp_active_constraint(U)|L1],
		   M1,
		   O1),
	    list2conj(N1, P1),
	    copy_term((F1, K1, O1, P1, U),
		      (_, _, Q1, R1, _)),
	    (   P1\=chr_pp_void_info
	    ->  (   guard_entailment:entails_guard(Q1, R1)
		->  passive(B, X)
		;   true
		)
	    ;   true
	    ), !,
	    next_occ_in_rule(B,
			     I,
			     L,
			     X,
			     F1,
			     U)
	).
next_occ_in_rule(_, _, _, _, _, _).
multiple_occ_constraints_checked(R) :-
	( nb_getval('$chr_store_global_ground_chr_translate____prev_guard_list___6',
		    A),
	  member(B, A),
	  B=suspension(_, active, _, _, D, _, _, _, _, _)
	),
	(   nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		      C),
	    lookup_ht(C, D, E),
	    member(F, E),
	    F=suspension(_, active, _, _, K, O, _, _, _),
	    nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      G),
	    lookup_ht(G, D, H),
	    member(I, H),
	    I=suspension(_, active, _, _, _, P),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		      J),
	    lookup_ht(J, k(K, D), L),
	    member(M, L),
	    M=suspension(_, active, _, _, _, N, _, S, _),
	    M\==F,
	    N<O,
	    chr_pp_flag(occurrence_subsumption, on),
	    P=pragma(rule(Q, _, _, _), _, _, _, _),
	    Q\==[],
	    \+ tree_set_memberchk(K, R), !,
	    first_occ_in_rule(D, K, N, S),
	    tree_set_add(R, K, T),
	    multiple_occ_constraints_checked(T)
	;    !,
	    setarg(2, B, removed),
	    arg(4, B, 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, B)
	).
multiple_occ_constraints_checked(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____multiple_occ_constraints_checked___1',
		  D),
	E=[C|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(C, _, N) :-
	( nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		    A),
	  member(B, A),
	  B=suspension(_, active, _, _, _, D, _)
	),
	(   functor(C, E, F),
	    functor(D, E, F), !,
	    B=suspension(_, _, _, _, _, G, H),
	    setarg(2, B, removed),
	    term_variables(term(G, H), M),
	    arg(5, B, I),
	    (   var(I)
	    ->  nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
			  J),
		J=[_|K],
		b_setval('$chr_store_global_list_chr_translate____type_definition___2',
			 K),
		(   K=[L|_]
		->  setarg(5, L, _)
		;   true
		)
	    ;   I=[_, _|K],
		setarg(2, I, K),
		(   K=[L|_]
		->  setarg(5, L, I)
		;   true
		)
	    ),
	    detach_type_definition___2(M, B),
	    (   var(N)
	    ->  true
	    ;   N=suspension(_, O, _, _, _, P, Q),
		setarg(2, N, removed),
		(   O==not_stored_yet
		->  R=[]
		;   term_variables(term(P, Q), R),
		    ( arg(5, N, 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, N)
		)
	    ),
	    chr_error(type_error,
		      'Multiple definitions for type: ~w/~w.\n',
		      [E, F])
	;   functor(D, W, X),
	    functor(C, W, X), !,
	    B=suspension(_, _, _, _, _, Y, Z),
	    setarg(2, B, removed),
	    term_variables(term(Y, Z), E1),
	    arg(5, B, A1),
	    (   var(A1)
	    ->  nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
			  B1),
		B1=[_|C1],
		b_setval('$chr_store_global_list_chr_translate____type_definition___2',
			 C1),
		(   C1=[D1|_]
		->  setarg(5, D1, _)
		;   true
		)
	    ;   A1=[_, _|C1],
		setarg(2, A1, C1),
		(   C1=[D1|_]
		->  setarg(5, D1, A1)
		;   true
		)
	    ),
	    detach_type_definition___2(E1, B),
	    (   var(N)
	    ->  true
	    ;   N=suspension(_, F1, _, _, _, G1, H1),
		setarg(2, N, removed),
		(   F1==not_stored_yet
		->  I1=[]
		;   term_variables(term(G1, H1), I1),
		    ( arg(5, N, 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, N)
		)
	    ),
	    chr_error(type_error,
		      'Multiple definitions for type: ~w/~w.\n',
		      [W, X])
	).
type_definition___2__0(C, _, N) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, _),
	functor(C, E, F),
	functor(D, E, F), !,
	B=suspension(_, _, _, _, _, G, H),
	setarg(2, B, removed),
	term_variables(term(G, H), M),
	arg(5, B, I),
	(   var(I)
	->  nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		      J),
	    J=[_|K],
	    b_setval('$chr_store_global_list_chr_translate____type_alias___2',
		     K),
	    (   K=[L|_]
	    ->  setarg(5, L, _)
	    ;   true
	    )
	;   I=[_, _|K],
	    setarg(2, I, K),
	    (   K=[L|_]
	    ->  setarg(5, L, I)
	    ;   true
	    )
	),
	detach_type_alias___2(M, B),
	(   var(N)
	->  true
	;   N=suspension(_, O, _, _, _, P, Q),
	    setarg(2, N, removed),
	    (   O==not_stored_yet
	    ->  R=[]
	    ;   term_variables(term(P, Q), R),
		( arg(5, N, 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, N)
	    )
	),
	chr_error(type_error,
		  'Multiple definitions for type, once in a type definition and once as a type alias: ~w/~w.\n',
		  [E, F]).
type_definition___2__0(B, C, A) :-
	nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
		  E), !,
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	type_definition___2__0__0__5(E, B, C, A).
type_definition___2__0__0__5([], A, B, C) :-
	type_definition___2__1(A, B, C).
type_definition___2__0__0__5([A|W], B, X, L) :-
	(   A=suspension(_, active, _, C, V),
	    nonvar(B),
	    functor(B, D, E),
	    functor(C, D, E)
	->  ( A=suspension(_, _, _, F, _),
	      setarg(2, A, removed),
	      term_variables(F, K),
	      ( arg(3, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
			     I),
		    (   I=[J|_]
		    ->  setarg(3, J, _)
		    ;   true
		    )
		;   G=[_, _|I],
		    setarg(2, G, I),
		    (   I=[J|_]
		    ->  setarg(3, J, G)
		    ;   true
		    )
		)
	      ),
	      detach_unalias_type___2(K, A)
	    ),
	    ( arg(2, L, O),
	      setarg(2, L, active),
	      ( arg(4, L, M),
		N is M+1,
		setarg(4, L, N)
	      ),
	      (   O==not_stored_yet
	      ->  L=suspension(_, _, _, _, _, P, Q),
		  term_variables(term(P, Q), U),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
			      R),
		    S=[L|R],
		    b_setval('$chr_store_global_list_chr_translate____type_definition___2',
			     S),
		    (   R=[T|_]
		    ->  setarg(5, T, S)
		    ;   true
		    )
		  ),
		  attach_type_definition___2(U, L)
	      ;   true
	      )
	    ),
	    V=C,
	    (   L=suspension(_, active, _, N, _, _, _)
	    ->  setarg(2, L, inactive),
		type_definition___2__0__0__5(W,
					     B,
					     X,
					     L)
	    ;   true
	    )
	;   type_definition___2__0__0__5(W, B, X, L)
	).
type_definition___2__0(B, C, A) :-
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	type_definition___2__1(B, C, A).
type_definition___2__1(B, C, D) :-
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
		  A), !,
	type_definition___2__1__0__7(A, B, C, D).
type_definition___2__1__0__7([], A, B, C) :-
	type_definition___2__2(A, B, C).
type_definition___2__1__0__7([A|R], M, N, B) :-
	(   A=suspension(_, active, _, _),
	    C=t(235, B, A),
	    '$novel_production'(B, C),
	    '$novel_production'(A, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, F),
	      setarg(2, B, active),
	      ( arg(4, B, D),
		E is D+1,
		setarg(4, B, E)
	      ),
	      (   F==not_stored_yet
	      ->  B=suspension(_, _, _, _, _, G, H),
		  term_variables(term(G, H), L),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
			      I),
		    J=[B|I],
		    b_setval('$chr_store_global_list_chr_translate____type_definition___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(5, K, J)
		    ;   true
		    )
		  ),
		  attach_type_definition___2(L, B)
	      ;   true
	      )
	    ),
	    ( copy_term_nat(M-N, O-P),
	      maplist(dynamic_type_check_clause(O), P, Q),
	      dynamic_type_check_clauses(Q)
	    ),
	    (   B=suspension(_, active, _, E, _, _, _)
	    ->  setarg(2, B, inactive),
		type_definition___2__1__0__7(R,
					     M,
					     N,
					     B)
	    ;   true
	    )
	;   type_definition___2__1__0__7(R, M, N, B)
	).
type_definition___2__1(A, B, C) :-
	type_definition___2__2(A, B, C).
type_definition___2__2(B, C, D) :-
	nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
		  A), !,
	type_definition___2__2__0__8(A, B, C, D).
type_definition___2__2__0__8([], A, B, C) :-
	type_definition___2__3(A, B, C).
type_definition___2__2__0__8([A|W], C, V, L) :-
	(   A=suspension(_, active, _, B),
	    functor(B, D, E),
	    functor(C, D, E)
	->  ( A=suspension(_, _, _, F),
	      setarg(2, A, removed),
	      term_variables(F, K),
	      ( arg(3, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_list_chr_translate____atomic_type___1',
			     I),
		    (   I=[J|_]
		    ->  setarg(3, J, _)
		    ;   true
		    )
		;   G=[_, _|I],
		    setarg(2, G, I),
		    (   I=[J|_]
		    ->  setarg(3, J, G)
		    ;   true
		    )
		)
	      ),
	      detach_atomic_type___1(K, A)
	    ),
	    ( arg(2, L, O),
	      setarg(2, L, active),
	      ( arg(4, L, M),
		N is M+1,
		setarg(4, L, N)
	      ),
	      (   O==not_stored_yet
	      ->  L=suspension(_, _, _, _, _, P, Q),
		  term_variables(term(P, Q), U),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
			      R),
		    S=[L|R],
		    b_setval('$chr_store_global_list_chr_translate____type_definition___2',
			     S),
		    (   R=[T|_]
		    ->  setarg(5, T, S)
		    ;   true
		    )
		  ),
		  attach_type_definition___2(U, L)
	      ;   true
	      )
	    ),
	    maplist(atomic, V),
	    (   L=suspension(_, active, _, N, _, _, _)
	    ->  setarg(2, L, inactive),
		type_definition___2__2__0__8(W,
					     C,
					     V,
					     L)
	    ;   true
	    )
	;   type_definition___2__2__0__8(W, C, V, L)
	).
type_definition___2__2(A, B, C) :-
	type_definition___2__3(A, B, C).
type_definition___2__3(_, _, A) :-
	arg(2, A, D),
	setarg(2, A, active),
	arg(4, A, B),
	C is B+1,
	setarg(4, A, C),
	(   D==not_stored_yet
	->  A=suspension(_, _, _, _, _, E, F),
	    term_variables(term(E, F), J),
	    ( nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
			G),
	      H=[A|G],
	      b_setval('$chr_store_global_list_chr_translate____type_definition___2',
		       H),
	      (   G=[I|_]
	      ->  setarg(5, I, H)
	      ;   true
	      )
	    ),
	    attach_type_definition___2(J, A)
	;   true
	).
type_alias(A, B) :-
	type_alias___2__0(A, B, _).
type_alias___2__0(A, K, B) :-
	var(A), !,
	(   var(B)
	->  true
	;   B=suspension(_, C, _, _, _, D, E),
	    setarg(2, B, removed),
	    (   C==not_stored_yet
	    ->  F=[]
	    ;   term_variables(term(D, E), F),
		( arg(5, B, G),
		  (   var(G)
		  ->  nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
				H),
		      H=[_|I],
		      b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			       I),
		      (   I=[J|_]
		      ->  setarg(5, J, _)
		      ;   true
		      )
		  ;   G=[_, _|I],
		      setarg(2, G, I),
		      (   I=[J|_]
		      ->  setarg(5, J, G)
		      ;   true
		      )
		  )
		),
		detach_type_alias___2(F, B)
	    )
	),
	chr_error(type_error,
		  'Variable alias definition: "~w".\n',
		  [(:-chr_type A==K)]).
type_alias___2__0(K, A, B) :-
	var(A), !,
	(   var(B)
	->  true
	;   B=suspension(_, C, _, _, _, D, E),
	    setarg(2, B, removed),
	    (   C==not_stored_yet
	    ->  F=[]
	    ;   term_variables(term(D, E), F),
		( arg(5, B, G),
		  (   var(G)
		  ->  nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
				H),
		      H=[_|I],
		      b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			       I),
		      (   I=[J|_]
		      ->  setarg(5, J, _)
		      ;   true
		      )
		  ;   G=[_, _|I],
		      setarg(2, G, I),
		      (   I=[J|_]
		      ->  setarg(5, J, G)
		      ;   true
		      )
		  )
		),
		detach_type_alias___2(F, B)
	    )
	),
	chr_error(type_error,
		  'Variable alias definition: "~w".\n',
		  [(:-chr_type K==A)]).
type_alias___2__0(A, B, C) :-
	subsumes_term(A, 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,
		  'Cyclic alias definition: "~w".\n',
		  [A==B]).
type_alias___2__0(C, Y, N) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	(   member(B, A),
	    B=suspension(_, active, _, _, _, D, Z),
	    (   (   functor(C, E, F),
		    functor(D, E, F),
		    \+ C\=D, !,
		    B=suspension(_, _, _, _, _, G, H),
		    setarg(2, B, removed),
		    term_variables(term(G, H), M),
		    arg(5, B, I),
		    (   var(I)
		    ->  nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
				  J),
			J=[_|K],
			b_setval('$chr_store_global_list_chr_translate____type_alias___2',
				 K),
			(   K=[L|_]
			->  setarg(5, L, _)
			;   true
			)
		    ;   I=[_, _|K],
			setarg(2, I, K),
			(   K=[L|_]
			->  setarg(5, L, I)
			;   true
			)
		    ),
		    detach_type_alias___2(M, B),
		    (   var(N)
		    ->  true
		    ;   N=suspension(_, O, _, _, _, P, Q),
			setarg(2, N, removed),
			(   O==not_stored_yet
			->  R=[]
			;   term_variables(term(P, Q), R),
			    ( arg(5, N, 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, N)
			)
		    ),
		    copy_term_nat(C, W),
		    copy_term_nat(D, X),
		    W=X,
		    chr_error(type_error,
			      'Ambiguous type aliases: you have defined \n\t`~w\'\n\t`~w\'\n\tresulting in two definitions for "~w".\n',
			      [C==Y, D==Z, W])
		;   functor(D, A1, B1),
		    functor(C, A1, B1),
		    \+ D\=C, !,
		    B=suspension(_, _, _, _, _, C1, D1),
		    setarg(2, B, removed),
		    term_variables(term(C1, D1), I1),
		    arg(5, B, E1),
		    (   var(E1)
		    ->  nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
				  F1),
			F1=[_|G1],
			b_setval('$chr_store_global_list_chr_translate____type_alias___2',
				 G1),
			(   G1=[H1|_]
			->  setarg(5, H1, _)
			;   true
			)
		    ;   E1=[_, _|G1],
			setarg(2, E1, G1),
			(   G1=[H1|_]
			->  setarg(5, H1, E1)
			;   true
			)
		    ),
		    detach_type_alias___2(I1, B),
		    (   var(N)
		    ->  true
		    ;   N=suspension(_, J1, _, _, _, K1, L1),
			setarg(2, N, removed),
			(   J1==not_stored_yet
			->  M1=[]
			;   term_variables(term(K1, L1), M1),
			    ( arg(5, N, 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, N)
			)
		    ),
		    copy_term_nat(D, R1),
		    copy_term_nat(C, 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',
			      [D==Z, C==Y, R1])
		)
	    ;   functor(D, T1, U1),
		functor(Y, T1, U1),
		copy_term_nat((C, Y, D, Z),
			      (F2, W1, V1, G2)),
		subsumes_term(V1, W1), !,
		(   var(N)
		->  true
		;   N=suspension(_, X1, _, _, _, Y1, Z1),
		    setarg(2, N, removed),
		    (   X1==not_stored_yet
		    ->  A2=[]
		    ;   term_variables(term(Y1, Z1), A2),
			( arg(5, N, B2),
			  (   var(B2)
			  ->  nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
					C2),
			      C2=[_|D2],
			      b_setval('$chr_store_global_list_chr_translate____type_alias___2',
				       D2),
			      (   D2=[E2|_]
			      ->  setarg(5, E2, _)
			      ;   true
			      )
			  ;   B2=[_, _|D2],
			      setarg(2, B2, D2),
			      (   D2=[E2|_]
			      ->  setarg(5, E2, B2)
			      ;   true
			      )
			  )
			),
			detach_type_alias___2(A2, N)
		    )
		),
		type_alias(F2, G2)
	    )
	;    !,
	    (   var(N)
	    ->  N=suspension(H2, not_stored_yet, t, 0, _, C, Y),
		'chr gen_id'(H2)
	    ;   true
	    ),
	    type_alias___2__0__0__7(A, C, Y, N)
	).
type_alias___2__0__0__7([], A, B, C) :-
	type_alias___2__1(A, B, C).
type_alias___2__0__0__7([A|C1], B, G, Q) :-
	(   A=suspension(_, active, _, _, _, F, C),
	    functor(B, D, E),
	    functor(C, D, E),
	    copy_term_nat((F, C, B, G),
			  (A1, I, H, B1)),
	    subsumes_term(H, I)
	->  ( A=suspension(_, _, _, _, _, J, K),
	      setarg(2, A, removed),
	      term_variables(term(J, K), P),
	      ( arg(5, A, 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(P, A)
	    ),
	    ( arg(2, Q, T),
	      setarg(2, Q, active),
	      ( arg(4, Q, R),
		S is R+1,
		setarg(4, Q, S)
	      ),
	      (   T==not_stored_yet
	      ->  Q=suspension(_, _, _, _, _, U, V),
		  term_variables(term(U, V), Z),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
			      W),
		    X=[Q|W],
		    b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			     X),
		    (   W=[Y|_]
		    ->  setarg(5, Y, X)
		    ;   true
		    )
		  ),
		  attach_type_alias___2(Z, Q)
	      ;   true
	      )
	    ),
	    type_alias(A1, B1),
	    (   Q=suspension(_, active, _, S, _, _, _)
	    ->  setarg(2, Q, inactive),
		type_alias___2__0__0__7(C1, B, G, Q)
	    ;   true
	    )
	;   type_alias___2__0__0__7(C1, B, G, Q)
	).
type_alias___2__0(B, C, A) :-
	(   var(A)
	->  A=suspension(D, not_stored_yet, t, 0, _, B, C),
	    'chr gen_id'(D)
	;   true
	),
	type_alias___2__1(B, C, A).
type_alias___2__1(D, _, N) :-
	nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, C, _),
	functor(C, E, F),
	functor(D, E, F), !,
	B=suspension(_, _, _, _, _, G, H),
	setarg(2, B, removed),
	term_variables(term(G, H), M),
	arg(5, B, I),
	(   var(I)
	->  nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		      J),
	    J=[_|K],
	    b_setval('$chr_store_global_list_chr_translate____type_definition___2',
		     K),
	    (   K=[L|_]
	    ->  setarg(5, L, _)
	    ;   true
	    )
	;   I=[_, _|K],
	    setarg(2, I, K),
	    (   K=[L|_]
	    ->  setarg(5, L, I)
	    ;   true
	    )
	),
	detach_type_definition___2(M, B),
	(   var(N)
	->  true
	;   N=suspension(_, O, _, _, _, P, Q),
	    setarg(2, N, removed),
	    (   O==not_stored_yet
	    ->  R=[]
	    ;   term_variables(term(P, Q), R),
		( arg(5, N, 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, N)
	    )
	),
	chr_error(type_error,
		  'Multiple definitions for type, once in a type definition and once as a type alias: ~w/~w.\n',
		  [E, F]).
type_alias___2__1(B, C, D) :-
	nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
		  A), !,
	type_alias___2__1__0__10(A, B, C, D).
type_alias___2__1__0__10([], A, B, C) :-
	type_alias___2__2(A, B, C).
type_alias___2__1__0__10([A|Z], B, F, N) :-
	(   A=suspension(_, active, _, C, Y),
	    functor(B, D, E),
	    functor(C, D, E),
	    copy_term_nat((B, F),  (G, X)),
	    C=G
	->  ( A=suspension(_, _, _, H, _),
	      setarg(2, A, removed),
	      term_variables(H, M),
	      ( arg(3, A, I),
		(   var(I)
		->  nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			      J),
		    J=[_|K],
		    b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
			     K),
		    (   K=[L|_]
		    ->  setarg(3, L, _)
		    ;   true
		    )
		;   I=[_, _|K],
		    setarg(2, I, K),
		    (   K=[L|_]
		    ->  setarg(3, L, I)
		    ;   true
		    )
		)
	      ),
	      detach_unalias_type___2(M, A)
	    ),
	    ( arg(2, N, Q),
	      setarg(2, N, active),
	      ( arg(4, N, O),
		P is O+1,
		setarg(4, N, P)
	      ),
	      (   Q==not_stored_yet
	      ->  N=suspension(_, _, _, _, _, R, S),
		  term_variables(term(R, S), W),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
			      T),
		    U=[N|T],
		    b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			     U),
		    (   T=[V|_]
		    ->  setarg(5, V, U)
		    ;   true
		    )
		  ),
		  attach_type_alias___2(W, N)
	      ;   true
	      )
	    ),
	    unalias_type(X, Y),
	    (   N=suspension(_, active, _, P, _, _, _)
	    ->  setarg(2, N, inactive),
		type_alias___2__1__0__10(Z, B, F, N)
	    ;   true
	    )
	;   type_alias___2__1__0__10(Z, B, F, N)
	).
type_alias___2__1(A, B, C) :-
	type_alias___2__2(A, B, C).
type_alias___2__2(B, C, D) :-
	nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
		  A), !,
	type_alias___2__2__0__12(A, B, C, D).
type_alias___2__2__0__12([], A, B, C) :-
	type_alias___2__3(A, B, C).
type_alias___2__2__0__12([A|A1], B, V, L) :-
	(   A=suspension(_, active, _, W, X, C, Z),
	    functor(B, D, E),
	    functor(C, D, E)
	->  ( A=suspension(_, _, _, _, _, F, _),
	      setarg(2, A, removed),
	      term_variables(F, K),
	      ( arg(3, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			     I),
		    (   I=[J|_]
		    ->  setarg(3, J, _)
		    ;   true
		    )
		;   G=[_, _|I],
		    setarg(2, G, I),
		    (   I=[J|_]
		    ->  setarg(3, J, G)
		    ;   true
		    )
		)
	      ),
	      detach_ast_static_type_check_var___4(K, A)
	    ),
	    ( arg(2, L, O),
	      setarg(2, L, active),
	      ( arg(4, L, M),
		N is M+1,
		setarg(4, L, N)
	      ),
	      (   O==not_stored_yet
	      ->  L=suspension(_, _, _, _, _, P, Q),
		  term_variables(term(P, Q), U),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
			      R),
		    S=[L|R],
		    b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			     S),
		    (   R=[T|_]
		    ->  setarg(5, T, S)
		    ;   true
		    )
		  ),
		  attach_type_alias___2(U, L)
	      ;   true
	      )
	    ),
	    ( copy_term_nat(B-V, C-Y),
	      ast_static_type_check_var(W, X, Y, Z)
	    ),
	    (   L=suspension(_, active, _, N, _, _, _)
	    ->  setarg(2, L, inactive),
		type_alias___2__2__0__12(A1, B, V, L)
	    ;   true
	    )
	;   type_alias___2__2__0__12(A1, B, V, L)
	).
type_alias___2__2(A, B, C) :-
	type_alias___2__3(A, B, C).
type_alias___2__3(B, C, D) :-
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
		  A), !,
	type_alias___2__3__0__13(A, B, C, D).
type_alias___2__3__0__13([], A, B, C) :-
	type_alias___2__4(A, B, C).
type_alias___2__3__0__13([A|R], M, N, B) :-
	(   A=suspension(_, active, _, _),
	    C=t(236, B, A),
	    '$novel_production'(B, C),
	    '$novel_production'(A, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, F),
	      setarg(2, B, active),
	      ( arg(4, B, D),
		E is D+1,
		setarg(4, B, E)
	      ),
	      (   F==not_stored_yet
	      ->  B=suspension(_, _, _, _, _, G, H),
		  term_variables(term(G, H), L),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
			      I),
		    J=[B|I],
		    b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			     J),
		    (   I=[K|_]
		    ->  setarg(5, K, J)
		    ;   true
		    )
		  ),
		  attach_type_alias___2(L, B)
	      ;   true
	      )
	    ),
	    ( copy_term_nat(M-N, O-P),
	      dynamic_type_check_alias_clause(O, P, Q),
	      dynamic_type_check_clauses([Q])
	    ),
	    (   B=suspension(_, active, _, E, _, _, _)
	    ->  setarg(2, B, inactive),
		type_alias___2__3__0__13(R, M, N, B)
	    ;   true
	    )
	;   type_alias___2__3__0__13(R, M, N, B)
	).
type_alias___2__3(A, B, C) :-
	type_alias___2__4(A, B, C).
type_alias___2__4(B, C, D) :-
	nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
		  A), !,
	type_alias___2__4__0__14(A, B, C, D).
type_alias___2__4__0__14([], A, B, C) :-
	type_alias___2__5(A, B, C).
type_alias___2__4__0__14([A|X], C, V, L) :-
	(   A=suspension(_, active, _, B),
	    functor(B, D, E),
	    functor(C, D, E)
	->  ( A=suspension(_, _, _, F),
	      setarg(2, A, removed),
	      term_variables(F, K),
	      ( arg(3, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_list_chr_translate____atomic_type___1',
			     I),
		    (   I=[J|_]
		    ->  setarg(3, J, _)
		    ;   true
		    )
		;   G=[_, _|I],
		    setarg(2, G, I),
		    (   I=[J|_]
		    ->  setarg(3, J, G)
		    ;   true
		    )
		)
	      ),
	      detach_atomic_type___1(K, A)
	    ),
	    ( arg(2, L, O),
	      setarg(2, L, active),
	      ( arg(4, L, M),
		N is M+1,
		setarg(4, L, N)
	      ),
	      (   O==not_stored_yet
	      ->  L=suspension(_, _, _, _, _, P, Q),
		  term_variables(term(P, Q), U),
		  ( nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
			      R),
		    S=[L|R],
		    b_setval('$chr_store_global_list_chr_translate____type_alias___2',
			     S),
		    (   R=[T|_]
		    ->  setarg(5, T, S)
		    ;   true
		    )
		  ),
		  attach_type_alias___2(U, L)
	      ;   true
	      )
	    ),
	    ( atomic(V),
	      copy_term_nat(C-V, B-W),
	      atomic_type(W)
	    ),
	    (   L=suspension(_, active, _, N, _, _, _)
	    ->  setarg(2, L, inactive),
		type_alias___2__4__0__14(X, C, V, L)
	    ;   true
	    )
	;   type_alias___2__4__0__14(X, C, V, L)
	).
type_alias___2__4(A, B, C) :-
	type_alias___2__5(A, B, C).
type_alias___2__5(_, _, A) :-
	arg(2, A, D),
	setarg(2, A, active),
	arg(4, A, B),
	C is B+1,
	setarg(4, A, C),
	(   D==not_stored_yet
	->  A=suspension(_, _, _, _, _, E, F),
	    term_variables(term(E, F), J),
	    ( nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
			G),
	      H=[A|G],
	      b_setval('$chr_store_global_list_chr_translate____type_alias___2',
		       H),
	      (   G=[I|_]
	      ->  setarg(5, I, H)
	      ;   true
	      )
	    ),
	    attach_type_alias___2(J, A)
	;   true
	).
constraint_type(A, B) :-
	constraint_type___2__0(A, B, _).
constraint_type___2__0(B, C, A) :-
	nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',
		  E), !,
	A=suspension(D, not_stored_yet, _, B, C),
	'chr gen_id'(D),
	constraint_type___2__0__0__2(E, B, C, A).
constraint_type___2__0__0__2([], A, B, C) :-
	constraint_type___2__1(A, B, C).
constraint_type___2__0__0__2([A|L], H, I, B) :-
	(   A=suspension(_, active, _, _, _)
	->  ( 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, H, B)
	      ;   true
	      )
	    ),
	    forall(( member(J, I),
		     sub_term(J, K)
		   ),
		   (   get_type_definition(K, _)
		   ->  true
		   ;   chr_error(type_error,
				 'Undefined type "~w" used in type declaration of "~w".\n',
				 [K, H])
		   )),
	    (   B=suspension(_, active, _, _, _)
	    ->  setarg(2, B, inactive),
		constraint_type___2__0__0__2(L, H, I, B)
	    ;   true
	    )
	;   constraint_type___2__0__0__2(L, H, I, B)
	).
constraint_type___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, _, B, C),
	'chr gen_id'(D),
	constraint_type___2__1(B, C, A).
constraint_type___2__1(G, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',
			C),
	      D=[A|C],
	      b_setval('$chr_store_global_ground_chr_translate____constraint_type___2',
		       D),
	      (   C=[E|_]
	      ->  setarg(3, E, D)
	      ;   true
	      )
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',
		      F),
	    insert_ht(F, G, A)
	;   true
	).
get_type_definition(A, _) :-
	\+ ground(A), !,
	chr_error(type_error,
		  'Non-ground type in constraint definition: "~w".\n',
		  [A]).
get_type_definition(D, J) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, C, G),
	functor(C, E, F),
	functor(D, E, F),
	copy_term_nat((C, G),  (H, I)),
	H=D, !,
	(   get_type_definition(I, J)
	->  true
	;   chr_error(type_error,
		      'Could not find type definition for "~w" (accessed via alias "~w").\n',
		      [I, H]),
	    fail
	).
get_type_definition(D, I) :-
	nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, C, G),
	nonvar(C),
	functor(C, E, F),
	functor(D, E, F),
	copy_term_nat((C, G),  (H, J)),
	H=D, !,
	I=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(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____constraint_type___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F), !,
	E=F.
get_constraint_type(_, _) :-
	fail.
unalias_type(A, B) :-
	unalias_type___2__0(A, B, _).
unalias_type___2__0(A, I, B) :-
	var(A), !,
	(   var(B)
	->  true
	;   B=suspension(_, _, _, C, _),
	    setarg(2, B, removed),
	    term_variables(C, H),
	    ( arg(3, B, D),
	      (   var(D)
	      ->  nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			    E),
		  E=[_|F],
		  b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
			   F),
		  (   F=[G|_]
		  ->  setarg(3, G, _)
		  ;   true
		  )
	      ;   D=[_, _|F],
		  setarg(2, D, F),
		  (   F=[G|_]
		  ->  setarg(3, G, D)
		  ;   true
		  )
	      )
	    ),
	    detach_unalias_type___2(H, B)
	),
	I=A.
unalias_type___2__0(D, Q, I) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, C, G),
	functor(C, E, F),
	functor(D, E, F),
	copy_term_nat((C, G),  (H, P)),
	D=H, !,
	(   var(I)
	->  true
	;   I=suspension(_, _, _, J, _),
	    setarg(2, I, removed),
	    term_variables(J, O),
	    ( arg(3, I, 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(O, I)
	),
	unalias_type(P, Q).
unalias_type___2__0(D, N, G) :-
	nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, C, _),
	nonvar(C),
	functor(C, E, F),
	functor(D, E, F), !,
	(   var(G)
	->  true
	;   G=suspension(_, _, _, H, _),
	    setarg(2, G, removed),
	    term_variables(H, M),
	    ( arg(3, G, I),
	      (   var(I)
	      ->  nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			    J),
		  J=[_|K],
		  b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
			   K),
		  (   K=[L|_]
		  ->  setarg(3, L, _)
		  ;   true
		  )
	      ;   I=[_, _|K],
		  setarg(2, I, K),
		  (   K=[L|_]
		  ->  setarg(3, L, I)
		  ;   true
		  )
	      )
	    ),
	    detach_unalias_type___2(M, G)
	),
	N=D.
unalias_type___2__0(A, I, B) :-
	atomic_builtin_type(A, _, _), !,
	(   var(B)
	->  true
	;   B=suspension(_, _, _, C, _),
	    setarg(2, B, removed),
	    term_variables(C, H),
	    ( arg(3, B, D),
	      (   var(D)
	      ->  nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			    E),
		  E=[_|F],
		  b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
			   F),
		  (   F=[G|_]
		  ->  setarg(3, G, _)
		  ;   true
		  )
	      ;   D=[_, _|F],
		  setarg(2, D, F),
		  (   F=[G|_]
		  ->  setarg(3, G, D)
		  ;   true
		  )
	      )
	    ),
	    detach_unalias_type___2(H, B)
	),
	I=A.
unalias_type___2__0(A, I, B) :-
	compound_builtin_type(A, _, _, _), !,
	(   var(B)
	->  true
	;   B=suspension(_, _, _, C, _),
	    setarg(2, B, removed),
	    term_variables(C, H),
	    ( arg(3, B, D),
	      (   var(D)
	      ->  nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			    E),
		  E=[_|F],
		  b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
			   F),
		  (   F=[G|_]
		  ->  setarg(3, G, _)
		  ;   true
		  )
	      ;   D=[_, _|F],
		  setarg(2, D, F),
		  (   F=[G|_]
		  ->  setarg(3, G, D)
		  ;   true
		  )
	      )
	    ),
	    detach_unalias_type___2(H, B)
	),
	I=A.
unalias_type___2__0(B, C, A) :-
	(   var(A)
	->  ( A=suspension(D, active, _, B, C),
	      term_variables(B, H),
	      'chr gen_id'(D)
	    ),
	    ( nb_getval('$chr_store_global_list_chr_translate____unalias_type___2',
			E),
	      F=[A|E],
	      b_setval('$chr_store_global_list_chr_translate____unalias_type___2',
		       F),
	      (   E=[G|_]
	      ->  setarg(3, G, F)
	      ;   true
	      )
	    ),
	    attach_unalias_type___2(H, A)
	;   setarg(2, A, active)
	).
types_modes_condition([], [], A) :- !,
	A=true.
types_modes_condition([D|O], [K|P], G) :-
	nb_getval('$chr_store_global_ground_chr_translate____constraint_mode___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, C, H),
	C=E/F,
	functor(D, E, F), !,
	D=..[_|I],
	G=(J, N, Q),
	modes_condition(H, I, J),
	get_constraint_type_det(E/F, L),
	K=..[_|M],
	types_condition(L, I, M, H, N),
	types_modes_condition(O, P, Q).
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) :-
	E=suspension(D, active, _, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_global_ground_chr_translate____types_modes_condition___3',
		  F),
	G=[E|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(B, C, A) :-
	nb_getval('$chr_store_global_ground_chr_translate____constraint_type___2',
		  E), !,
	A=suspension(D, not_stored_yet, _, B, C),
	'chr gen_id'(D),
	static_type_check___2__0__0__1(E, B, C, A).
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([A|K], L, M, B) :-
	(   A=suspension(_, active, _, J, G)
	->  ( arg(2, B, C),
	      setarg(2, B, active),
	      (   C==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____static_type_check___2',
			    D),
		  E=[B|D],
		  b_setval('$chr_store_global_ground_chr_translate____static_type_check___2',
			   E),
		  (   D=[F|_]
		  ->  setarg(3, F, E)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    forall(( member(H, G),
		     sub_term(H, I)
		   ),
		   (   get_type_definition(I, _)
		   ->  true
		   ;   chr_error(type_error,
				 'Undefined type "~w" used in type declaration of "~w".\n',
				 [I, J])
		   )),
	    (   B=suspension(_, active, _, _, _)
	    ->  setarg(2, B, inactive),
		static_type_check___2__0__0__1(K,
					       L,
					       M,
					       B)
	    ;   true
	    )
	;   static_type_check___2__0__0__1(K, L, M, B)
	).
static_type_check___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, _, B, C),
	'chr gen_id'(D),
	static_type_check___2__1(B, C, A).
static_type_check___2__1(G, H, 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____static_type_check___2',
			      D),
		    D=[_|E],
		    b_setval('$chr_store_global_ground_chr_translate____static_type_check___2',
			     E),
		    (   E=[F|_]
		    ->  setarg(3, F, _)
		    ;   true
		    )
		;   C=[_, _|E],
		    setarg(2, C, E),
		    (   E=[F|_]
		    ->  setarg(3, F, C)
		    ;   true
		    )
		)
	    )
	),
	maplist(static_type_check_rule, G, H).
ast_static_type_check_term(_, _, A) :-
	A==any, !.
ast_static_type_check_term(E, A, D) :-
	nonvar(A),
	A=var(B, C), !,
	ast_static_type_check_var(B,
				  var(B, C),
				  D,
				  E).
ast_static_type_check_term(D, B, A) :-
	ast_atomic_builtin_type(A, B, C), !,
	(   call(C)
	->  true
	;   throw(type_error(invalid_functor(D, B, A)))
	).
ast_static_type_check_term(D, B, A) :-
	ast_compound_builtin_type(A, B, C), !,
	(   call(C)
	->  true
	;   throw(type_error(invalid_functor(D, B, A)))
	).
ast_static_type_check_term(H, I, C) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, G),
	functor(C, E, F),
	functor(D, E, F), !,
	copy_term_nat(D-G, C-J),
	ast_static_type_check_term(H, I, J).
ast_static_type_check_term(M, H, C) :-
	nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, G),
	functor(C, E, F),
	functor(D, E, F), !,
	copy_term_nat(D-G, C-I),
	ast_functor(H, K, L),
	(   member(J, I),
	    functor(J, K, L)
	->  ast_args(H, N),
	    J=..[_|O],
	    maplist(ast_static_type_check_term(M), N, O)
	;   throw(type_error(invalid_functor(M, H, C)))
	).
ast_static_type_check_term(C, B, A) :-
	chr_error(internal,
		  'Undefined type ~w while type checking term ~w in ~@.\n',
		  [A, B, chr_translate:format_src(C)]).
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(O, P, D, R, G) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, C, N),
	functor(C, E, F),
	functor(D, E, F), !,
	(   var(G)
	->  true
	;   G=suspension(_, _, _, _, _, H, _),
	    setarg(2, G, removed),
	    term_variables(H, M),
	    ( arg(3, G, I),
	      (   var(I)
	      ->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			    J),
		  J=[_|K],
		  b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			   K),
		  (   K=[L|_]
		  ->  setarg(3, L, _)
		  ;   true
		  )
	      ;   I=[_, _|K],
		  setarg(2, I, K),
		  (   K=[L|_]
		  ->  setarg(3, L, I)
		  ;   true
		  )
	      )
	    ),
	    detach_ast_static_type_check_var___4(M, G)
	),
	copy_term_nat(C-N, D-Q),
	ast_static_type_check_var(O, P, Q, R).
ast_static_type_check_var___4__0(I, J, A, K, B) :-
	atomic_builtin_type(A, _, _), !,
	(   var(B)
	->  true
	;   B=suspension(_, _, _, _, _, C, _),
	    setarg(2, B, removed),
	    term_variables(C, H),
	    ( arg(3, B, D),
	      (   var(D)
	      ->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			    E),
		  E=[_|F],
		  b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			   F),
		  (   F=[G|_]
		  ->  setarg(3, G, _)
		  ;   true
		  )
	      ;   D=[_, _|F],
		  setarg(2, D, F),
		  (   F=[G|_]
		  ->  setarg(3, G, D)
		  ;   true
		  )
	      )
	    ),
	    detach_ast_static_type_check_var___4(H, B)
	),
	ast_static_atomic_builtin_type_check_var(I,
						 J,
						 A,
						 K).
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, H),
	    ( arg(3, B, D),
	      (   var(D)
	      ->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			    E),
		  E=[_|F],
		  b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			   F),
		  (   F=[G|_]
		  ->  setarg(3, G, _)
		  ;   true
		  )
	      ;   D=[_, _|F],
		  setarg(2, D, F),
		  (   F=[G|_]
		  ->  setarg(3, G, D)
		  ;   true
		  )
	      )
	    ),
	    detach_ast_static_type_check_var___4(H, B)
	).
ast_static_type_check_var___4__0(D, T, E, U, M) :-
	( nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
		    A),
	  member(B, A),
	  B=suspension(_, active, _, C, I1, F, V),
	  C=D
	),
	(   E\==F, !,
	    B=suspension(_, _, _, _, _, G, _),
	    setarg(2, B, removed),
	    term_variables(G, L),
	    arg(3, B, 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(L, B),
	    (   var(M)
	    ->  true
	    ;   M=suspension(_, _, _, _, _, N, _),
		setarg(2, M, removed),
		term_variables(N, S),
		( arg(3, M, O),
		  (   var(O)
		  ->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
				P),
		      P=[_|Q],
		      b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			       Q),
		      (   Q=[R|_]
		      ->  setarg(3, R, _)
		      ;   true
		      )
		  ;   O=[_, _|Q],
		      setarg(2, O, Q),
		      (   Q=[R|_]
		      ->  setarg(3, R, O)
		      ;   true
		      )
		  )
		),
		detach_ast_static_type_check_var___4(S, M)
	    ),
	    throw(type_error(type_clash(T,
					U,
					V,
					E,
					F)))
	;   F\==E, !,
	    B=suspension(_, _, _, _, _, W, _),
	    setarg(2, B, removed),
	    term_variables(W, B1),
	    arg(3, B, X),
	    (   var(X)
	    ->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			  Y),
		Y=[_|Z],
		b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			 Z),
		(   Z=[A1|_]
		->  setarg(3, A1, _)
		;   true
		)
	    ;   X=[_, _|Z],
		setarg(2, X, Z),
		(   Z=[A1|_]
		->  setarg(3, A1, X)
		;   true
		)
	    ),
	    detach_ast_static_type_check_var___4(B1, B),
	    (   var(M)
	    ->  true
	    ;   M=suspension(_, _, _, _, _, C1, _),
		setarg(2, M, removed),
		term_variables(C1, H1),
		( arg(3, M, D1),
		  (   var(D1)
		  ->  nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
				E1),
		      E1=[_|F1],
		      b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			       F1),
		      (   F1=[G1|_]
		      ->  setarg(3, G1, _)
		      ;   true
		      )
		  ;   D1=[_, _|F1],
		      setarg(2, D1, F1),
		      (   F1=[G1|_]
		      ->  setarg(3, G1, D1)
		      ;   true
		      )
		  )
		),
		detach_ast_static_type_check_var___4(H1, M)
	    ),
	    throw(type_error(type_clash(I1,
					V,
					U,
					F,
					E)))
	).
ast_static_type_check_var___4__0(B, C, D, E, A) :-
	(   var(A)
	->  ( A=suspension(F, active, _, B, C, D, E),
	      term_variables(D, J),
	      'chr gen_id'(F)
	    ),
	    ( nb_getval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
			G),
	      H=[A|G],
	      b_setval('$chr_store_global_list_chr_translate____ast_static_type_check_var___4',
		       H),
	      (   G=[I|_]
	      ->  setarg(3, I, H)
	      ;   true
	      )
	    ),
	    attach_ast_static_type_check_var___4(J, A)
	;   setarg(2, A, active)
	).
ast_static_atomic_builtin_type_check_var(_, _, any, _) :- !.
ast_static_atomic_builtin_type_check_var(B, F, C, G) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		    A),
	  lookup_ht(A, k(B, C), D)
	),
	(   member(E, D),
	    E=suspension(_, active, _, _, _, _), !
	;    !,
	    ast_static_atomic_builtin_type_check_var___4__0__0__3(D,
								  B,
								  F,
								  C,
								  G)
	).
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([A|H], C, I, E, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  F),
		delete_ht(F, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			G),
	      delete_ht(G, k(C, E), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__0__0__3(H,
								  C,
								  I,
								  E,
								  J)
	;   ast_static_atomic_builtin_type_check_var___4__0__0__3(H,
								  C,
								  I,
								  E,
								  J)
	).
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(B, _, number, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, float), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__1(B, D, float, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, number), C), !,
	ast_static_atomic_builtin_type_check_var___4__1__0__5(C,
							      B,
							      D,
							      float,
							      E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=number
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, number), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__1__0__5(G,
								  C,
								  H,
								  I,
								  J)
	;   ast_static_atomic_builtin_type_check_var___4__1__0__5(G,
								  C,
								  H,
								  I,
								  J)
	).
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(B, _, number, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, int), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__2(B, D, int, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, number), C), !,
	ast_static_atomic_builtin_type_check_var___4__2__0__7(C,
							      B,
							      D,
							      int,
							      E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=number
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, number), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__2__0__7(G,
								  C,
								  H,
								  I,
								  J)
	;   ast_static_atomic_builtin_type_check_var___4__2__0__7(G,
								  C,
								  H,
								  I,
								  J)
	).
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(B, _, number, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, natural), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__3(B, D, natural, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, number), C), !,
	ast_static_atomic_builtin_type_check_var___4__3__0__9(C,
							      B,
							      D,
							      natural,
							      E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=number
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, number), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__3__0__9(G,
								  C,
								  H,
								  I,
								  J)
	;   ast_static_atomic_builtin_type_check_var___4__3__0__9(G,
								  C,
								  H,
								  I,
								  J)
	).
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(B, _, number, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, dense_int), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__4(B, D, dense_int, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, number), C), !,
	ast_static_atomic_builtin_type_check_var___4__4__0__11(C,
							       B,
							       D,
							       dense_int,
							       E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=number
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, number), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__4__0__11(G,
								   C,
								   H,
								   I,
								   J)
	;   ast_static_atomic_builtin_type_check_var___4__4__0__11(G,
								   C,
								   H,
								   I,
								   J)
	).
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(B, _, int, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, natural), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__5(B, D, natural, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, int), C), !,
	ast_static_atomic_builtin_type_check_var___4__5__0__13(C,
							       B,
							       D,
							       natural,
							       E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=int
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, int), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__5__0__13(G,
								   C,
								   H,
								   I,
								   J)
	;   ast_static_atomic_builtin_type_check_var___4__5__0__13(G,
								   C,
								   H,
								   I,
								   J)
	).
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(B, _, int, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, dense_int), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__6(B, D, dense_int, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, int), C), !,
	ast_static_atomic_builtin_type_check_var___4__6__0__15(C,
							       B,
							       D,
							       dense_int,
							       E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=int
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, int), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__6__0__15(G,
								   C,
								   H,
								   I,
								   J)
	;   ast_static_atomic_builtin_type_check_var___4__6__0__15(G,
								   C,
								   H,
								   I,
								   J)
	).
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(B, _, natural, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, dense_int), C),
	member(D, C),
	D=suspension(_, active, _, _, _, _), !.
ast_static_atomic_builtin_type_check_var___4__7(B, D, dense_int, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  A),
	lookup_ht(A, k(B, natural), C), !,
	ast_static_atomic_builtin_type_check_var___4__7__0__17(C,
							       B,
							       D,
							       dense_int,
							       E).
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([A|G], C, H, I, J) :-
	(   A=suspension(_, active, B, _, D, _),
	    B==C,
	    D=natural
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
			  E),
		delete_ht(E, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
			F),
	      delete_ht(F, k(C, natural), A)
	    ),
	    ast_static_atomic_builtin_type_check_var___4__7__0__17(G,
								   C,
								   H,
								   I,
								   J)
	;   ast_static_atomic_builtin_type_check_var___4__7__0__17(G,
								   C,
								   H,
								   I,
								   J)
	).
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(B, H, K, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, G, J), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
		  E),
	delete_ht(E, B, D),
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  F),
	delete_ht(F, k(B, G), D),
	throw(type_error(type_clash(H, I, J, K, G))).
ast_static_atomic_builtin_type_check_var___4__8(A, B, C, D) :-
	G=suspension(E, active, A, B, C, D),
	'chr gen_id'(E),
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-1',
		  F),
	insert_ht(F, A, G),
	nb_getval('$chr_store_multi_hash_chr_translate____ast_static_atomic_builtin_type_check_var___4-13',
		  H),
	insert_ht(H, k(A, C), G).
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',
		  C), !,
	A=suspension(B, not_stored_yet, t, _),
	'chr gen_id'(B),
	dynamic_type_check___0__0__0__1(C, A).
dynamic_type_check___0__0__0__1([], A) :-
	dynamic_type_check___0__1(A).
dynamic_type_check___0__0__0__1([A|M], B) :-
	(   A=suspension(_, active, _, _, _, H, I),
	    C=t(235, A, B),
	    '$novel_production'(A, C),
	    '$novel_production'(B, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, D),
	      setarg(2, B, active),
	      (   D==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
			    E),
		  F=[B|E],
		  b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
			   F),
		  (   E=[G|_]
		  ->  setarg(4, G, F)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    ( copy_term_nat(H-I, J-K),
	      maplist(dynamic_type_check_clause(J), K, L),
	      dynamic_type_check_clauses(L)
	    ),
	    (   B=suspension(_, active, _, _)
	    ->  setarg(2, B, inactive),
		dynamic_type_check___0__0__0__1(M, B)
	    ;   true
	    )
	;   dynamic_type_check___0__0__0__1(M, B)
	).
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(B) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A), !,
	dynamic_type_check___0__1__0__2(A, B).
dynamic_type_check___0__1__0__2([], A) :-
	dynamic_type_check___0__2(A).
dynamic_type_check___0__1__0__2([A|M], B) :-
	(   A=suspension(_, active, _, _, _, H, I),
	    C=t(236, A, B),
	    '$novel_production'(A, C),
	    '$novel_production'(B, C)
	->  '$extend_history'(B, C),
	    ( arg(2, B, D),
	      setarg(2, B, active),
	      (   D==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
			    E),
		  F=[B|E],
		  b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check___0',
			   F),
		  (   E=[G|_]
		  ->  setarg(4, G, F)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    ( copy_term_nat(H-I, J-K),
	      dynamic_type_check_alias_clause(J, K, L),
	      dynamic_type_check_clauses([L])
	    ),
	    (   B=suspension(_, active, _, _)
	    ->  setarg(2, B, inactive),
		dynamic_type_check___0__1__0__2(M, B)
	    ;   true
	    )
	;   dynamic_type_check___0__1__0__2(M, B)
	).
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'(G, H):-I),
		(   atomic_builtin_type(G, H, I)
		;   compound_builtin_type(G, H, I, _)
		),
		J),
	dynamic_type_check_clauses(J).
dynamic_type_check_clauses(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	append(G, H, I),
	dynamic_type_check_clauses(I).
dynamic_type_check_clauses(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		  D),
	E=[C|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(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____dynamic_type_check_clauses___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	G=H.
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, H),
	    ( arg(3, B, D),
	      (   var(D)
	      ->  nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
			    E),
		  E=[_|F],
		  b_setval('$chr_store_global_list_chr_translate____atomic_type___1',
			   F),
		  (   F=[G|_]
		  ->  setarg(3, G, _)
		  ;   true
		  )
	      ;   D=[_, _|F],
		  setarg(2, D, F),
		  (   F=[G|_]
		  ->  setarg(3, G, D)
		  ;   true
		  )
	      )
	    ),
	    detach_atomic_type___1(H, B)
	),
	A\==any.
atomic_type___1__0(C, G) :-
	nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, N),
	functor(C, E, F),
	functor(D, E, F), !,
	(   var(G)
	->  true
	;   G=suspension(_, _, _, H),
	    setarg(2, G, removed),
	    term_variables(H, M),
	    ( arg(3, G, I),
	      (   var(I)
	      ->  nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
			    J),
		  J=[_|K],
		  b_setval('$chr_store_global_list_chr_translate____atomic_type___1',
			   K),
		  (   K=[L|_]
		  ->  setarg(3, L, _)
		  ;   true
		  )
	      ;   I=[_, _|K],
		  setarg(2, I, K),
		  (   K=[L|_]
		  ->  setarg(3, L, I)
		  ;   true
		  )
	      )
	    ),
	    detach_atomic_type___1(M, G)
	),
	maplist(atomic, N).
atomic_type___1__0(C, G) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, N),
	functor(C, E, F),
	functor(D, E, F), !,
	(   var(G)
	->  true
	;   G=suspension(_, _, _, H),
	    setarg(2, G, removed),
	    term_variables(H, M),
	    ( arg(3, G, I),
	      (   var(I)
	      ->  nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
			    J),
		  J=[_|K],
		  b_setval('$chr_store_global_list_chr_translate____atomic_type___1',
			   K),
		  (   K=[L|_]
		  ->  setarg(3, L, _)
		  ;   true
		  )
	      ;   I=[_, _|K],
		  setarg(2, I, K),
		  (   K=[L|_]
		  ->  setarg(3, L, I)
		  ;   true
		  )
	      )
	    ),
	    detach_atomic_type___1(M, G)
	),
	atomic(N),
	copy_term_nat(D-N, C-O),
	atomic_type(O).
atomic_type___1__0(B, A) :-
	(   var(A)
	->  ( A=suspension(C, active, _, B),
	      term_variables(B, G),
	      'chr gen_id'(C)
	    ),
	    ( nb_getval('$chr_store_global_list_chr_translate____atomic_type___1',
			D),
	      E=[A|D],
	      b_setval('$chr_store_global_list_chr_translate____atomic_type___1',
		       E),
	      (   D=[F|_]
	      ->  setarg(3, F, E)
	      ;   true
	      )
	    ),
	    attach_atomic_type___1(G, A)
	;   setarg(2, A, active)
	).
enumerated_atomic_type(A, _) :-
	atomic_builtin_type(A, _, _), !,
	fail.
enumerated_atomic_type(C, H) :-
	nb_getval('$chr_store_global_list_chr_translate____type_definition___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, G),
	functor(C, E, F),
	functor(D, E, F), !,
	maplist(atomic, G),
	H=G.
enumerated_atomic_type(C, I) :-
	nb_getval('$chr_store_global_list_chr_translate____type_alias___2',
		  A),
	member(B, A),
	B=suspension(_, active, _, _, _, D, G),
	functor(C, E, F),
	functor(D, E, F), !,
	atomic(G),
	copy_term_nat(D-G, C-H),
	enumerated_atomic_type(H, I).
enumerated_atomic_type(_, _) :-
	fail.
stored(B, C, yes) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, G, H, _),
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  F),
	lookup_ht(F, k(G, H), I),
	member(J, I),
	J=suspension(_, active, _, _, _),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  K),
	lookup_ht(K, B, L),
	member(M, L),
	M=suspension(_, active, _, _, N, P),
	C<N, !,
	setarg(2, M, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		  O),
	delete_ht(O, k(B, P), M),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  Q),
	delete_ht(Q, B, M),
	R is P-1,
	stored(B, C, maybe),
	stored_complete(B, N, R).
stored(B, E, yes) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F, K),
	E<F,
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
		  G),
	lookup_ht(G, k(B, E), H),
	member(I, H),
	I=suspension(_, active, _, _), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		  J),
	delete_ht(J, k(B, K), D),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  L),
	delete_ht(L, B, D),
	M is K-1,
	stored(B, E, maybe),
	stored_complete(B, F, M).
stored(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
		  E),
	insert_ht(E, k(A, C), F),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  G),
	insert_ht(G, k(A, B, C), F).
stored_completing(A, B, F) :-
	( ground(A),
	  ground(B),
	  nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		    C)
	),
	(   (   lookup_ht(C, k(A, B, yes), D),
		member(E, D),
		E=suspension(_, active, _, _, _), !,
		G is B+1,
		H is F+1,
		stored_completing(A, G, H)
	    ;   lookup_ht(C, k(A, B, maybe), I),
		member(J, I),
		J=suspension(_, active, _, _, _), !,
		K is B+1,
		stored_completing(A, K, F)
	    )
	;   lookup_ht(C, k(A, B, no), L),
	    member(M, L),
	    M=suspension(_, active, _, _, _), !,
	    stored_complete(A, B, F)
	).
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(B, F, Q, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, E, H, I, _),
	E<F,
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  G),
	lookup_ht(G, k(H, I), J),
	member(K, J),
	K=suspension(_, active, _, _, _),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  L),
	lookup_ht(L, k(B, E, yes), M),
	member(N, M),
	N=suspension(_, active, _, _, _), !,
	setarg(2, N, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
		  O),
	delete_ht(O, k(B, yes), N),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  P),
	delete_ht(P, k(B, E, yes), N),
	R is Q-1,
	stored(B, E, maybe),
	stored_complete(B, F, R).
stored_complete___3__0(B, F, L, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
		  A),
	lookup_ht(A, k(B, yes), C),
	member(D, C),
	D=suspension(_, active, _, E, _),
	E<F,
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
		  G),
	lookup_ht(G, k(B, E), H),
	member(I, H),
	I=suspension(_, active, _, _), !,
	setarg(2, D, removed),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
		  J),
	delete_ht(J, k(B, yes), D),
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  K),
	delete_ht(K, k(B, E, yes), D),
	M is L-1,
	stored(B, E, maybe),
	stored_complete(B, F, M).
stored_complete___3__0(B, D, 0, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, B, D, 0),
	'chr gen_id'(E),
	stored_complete___3__0__0__3(F, B, D, 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([A|G], C, H, I, J) :-
	(   ( A=suspension(_, active, _, B, F),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		      D),
	    lookup_ht(D, C, E)
	->  stored_complete___3__0__1__3(E,
					 F,
					 A,
					 G,
					 C,
					 H,
					 I,
					 J)
	;   stored_complete___3__0__0__3(G,
					 C,
					 H,
					 I,
					 J)
	).
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([A|G], H, I, J, C, K, L, M) :-
	(   ( A=suspension(_, active, _, _, B, _, E, _, _),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-3',
		      D),
	    lookup_ht(D, E, F)
	->  stored_complete___3__0__2__3(F,
					 E,
					 A,
					 G,
					 H,
					 I,
					 J,
					 C,
					 K,
					 L,
					 M)
	;   stored_complete___3__0__1__3(G,
					 H,
					 I,
					 J,
					 C,
					 K,
					 L,
					 M)
	).
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([A|P], D, B, Q, I, F, R, L, H, M, E) :-
	(   A=suspension(_, active, _, _, _, _, C, O, _),
	    A\==B,
	    C==D,
	    ( G=t(250, A, B, E, F),
	      '$novel_production'(A, G),
	      '$novel_production'(B, G),
	      '$novel_production'(E, G),
	      '$novel_production'(F, G)
	    ),
	    H=<I
	->  '$extend_history'(E, G),
	    ( arg(2, E, J),
	      setarg(2, E, active),
	      (   J==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
			      K),
		    insert_ht(K, k(L, M), E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			    N),
		  insert_ht(N, L, E)
	      ;   true
	      )
	    ),
	    passive(D, O),
	    (   E=suspension(_, active, _, _, _, _)
	    ->  setarg(2, E, inactive),
		stored_complete___3__0__2__3(P,
					     D,
					     B,
					     Q,
					     I,
					     F,
					     R,
					     L,
					     H,
					     M,
					     E)
	    ;   true
	    )
	;   stored_complete___3__0__2__3(P,
					 D,
					 B,
					 Q,
					 I,
					 F,
					 R,
					 L,
					 H,
					 M,
					 E)
	).
stored_complete___3__0(B, C, D, A) :-
	A=suspension(E, not_stored_yet, t, B, C, D),
	'chr gen_id'(E),
	stored_complete___3__1(B, C, D, A).
stored_complete___3__1(B, D, E, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-1',
		  A),
	lookup_ht(A, B, C), !,
	stored_complete___3__1__0__4(C, B, D, E, F).
stored_complete___3__1__0__4([], A, B, C, D) :-
	stored_complete___3__2(A, B, C, D).
stored_complete___3__1__0__4([A|N], C, G, J, D) :-
	(   A=suspension(_, active, _, _, B, F, L, M, _),
	    B==C,
	    ( E=t(259, D, A),
	      '$novel_production'(D, E),
	      '$novel_production'(A, E)
	    ),
	    F>G
	->  '$extend_history'(D, E),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
			      I),
		    insert_ht(I, k(C, J), D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			    K),
		  insert_ht(K, C, D)
	      ;   true
	      )
	    ),
	    passive(L, M),
	    (   D=suspension(_, active, _, _, _, _)
	    ->  setarg(2, D, inactive),
		stored_complete___3__1__0__4(N,
					     C,
					     G,
					     J,
					     D)
	    ;   true
	    )
	;   stored_complete___3__1__0__4(N,
					 C,
					 G,
					 J,
					 D)
	).
stored_complete___3__1(A, B, C, D) :-
	stored_complete___3__2(A, B, C, D).
stored_complete___3__2(D, _, E, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
			C),
	      insert_ht(C, k(D, E), A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		      F),
	    insert_ht(F, D, A)
	;   true
	).
is_stored(A) :-
	ground(A),
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  B),
	lookup_ht(B, A, C),
	member(D, C),
	D=suspension(_, active, _, _, I),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
		  E),
	lookup_ht(E, k(A, 0), F),
	member(G, F),
	G=suspension(_, active, _, _, H, _),
	H=<I, !,
	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),
	member(D, C),
	D=suspension(_, active, _, _, I),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
		  E),
	lookup_ht(E, A, F),
	member(G, F),
	G=suspension(_, active, _, _, H, _),
	H=<I, !,
	fail.
is_finally_stored(_).
check_all_passive(B, [C|F]) :-
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !,
	check_all_passive(B, F).
check_all_passive(B, []) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C),
	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) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-12',
		  D),
	insert_ht(D, k(A, B), E),
	nb_getval('$chr_store_multi_hash_chr_translate____check_all_passive___2-1',
		  F),
	insert_ht(F, A, E).
constraints_code1([], A, B) :- !,
	A=B.
constraints_code1([A|C], B, E) :- !,
	constraint_code(A, B, D),
	constraints_code1(C, D, E).
constraints_code1(A, B, C) :-
	E=suspension(D, active, _, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_global_ground_chr_translate____constraints_code1___3',
		  F),
	G=[E|F],
	b_setval('$chr_store_global_ground_chr_translate____constraints_code1___3',
		 G),
	(   F=[H|_]
	->  setarg(3, H, G)
	;   true
	).
constraint_code(A, E, K) :-
	(   (   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, C),
		    get_max_occurrence(A, B),
		    B>=C
		)
	    )
	->  constraint_prelude(A, D),
	    add_dummy_location(D, F),
	    E=[F|G]
	;   E=G
	),
	H=[0],
	occurrences_code(A, 1, H, I, G, J),
	gen_cond_attach_clause(A, I, J, K).
has_active_occurrence(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
has_active_occurrence(A) :-
	has_active_occurrence(A, 1),
	memo_has_active_occurrence(A).
has_active_occurrence(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F),
	E>F, !,
	fail.
has_active_occurrence(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, G, H, _),
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  F),
	lookup_ht(F, k(G, H), I),
	member(J, I),
	J=suspension(_, active, _, _, _), !,
	K is C+1,
	has_active_occurrence(B, K).
has_active_occurrence(_, _).
memo_has_active_occurrence(A) :-
	D=suspension(B, active, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_multi_hash_chr_translate____memo_has_active_occurrence___1-1',
		  C),
	insert_ht(C, A, D).
use_auxiliary_predicate(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
use_auxiliary_predicate(A) :-
	D=suspension(B, active, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',
		  C),
	insert_ht(C, A, D).
use_auxiliary_predicate(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
use_auxiliary_predicate(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',
		  D),
	insert_ht(D, A, E),
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',
		  F),
	insert_ht(F, k(A, B), E).
is_used_auxiliary_predicate(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
is_used_auxiliary_predicate(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _), !.
is_used_auxiliary_predicate(_) :-
	fail.
is_used_auxiliary_predicate(B, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
is_used_auxiliary_predicate(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_predicate___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
is_used_auxiliary_predicate(_, _) :-
	fail.
use_auxiliary_module(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
use_auxiliary_module(A) :-
	D=suspension(B, active, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',
		  C),
	insert_ht(C, A, D).
is_used_auxiliary_module(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____use_auxiliary_module___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
is_used_auxiliary_module(_) :-
	fail.
occurrences_code(B, E, H, G, I, J) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F),
	E>F, !,
	G=H,
	I=J.
occurrences_code(A, B, C, G, D, I) :-
	occurrence_code(A, B, C, F, D, H),
	E is B+1,
	occurrences_code(A, E, F, G, H, I).
occurrence_code(B, C, L, K, M, N) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		    A),
	  lookup_ht(A, k(B, C), D),
	  member(E, D),
	  E=suspension(_, active, _, _, _, _, G, H, _)
	),
	(   nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		      F),
	    lookup_ht(F, k(G, H), I),
	    member(J, I),
	    J=suspension(_, active, _, _, _), !,
	    (   named_history(G, _, _)
	    ->  does_use_history(B, C)
	    ;   true
	    ),
	    K=L,
	    M=N
	;   nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      O),
	    lookup_ht(O, G, P),
	    member(Q, P),
	    Q=suspension(_, active, _, _, _, R), !,
	    R=pragma(rule(T, Y, _, _), ids(S, X), _, _, _),
	    (   select2(H, U, S, T, W, V)
	    ->  K=L,
		head1_code(U,
			   H,
			   V,
			   W,
			   R,
			   B,
			   C,
			   L,
			   M,
			   N)
	    ;   select2(H, Z, X, Y, B1, A1)
	    ->  head2_code(Z,
			   H,
			   A1,
			   B1,
			   R,
			   B,
			   C,
			   L,
			   M,
			   C1),
		(   should_skip_to_next_id(B, C)
		->  inc_id(L, K),
		    (   unconditional_occurrence(B, C)
		    ->  C1=N
		    ;   gen_alloc_inc_clause(B,
					     C,
					     L,
					     C1,
					     N)
		    )
		;   K=L,
		    C1=N
		)
	    )
	).
occurrence_code(A, B, _, _, _, _) :-
	chr_error(internal,
		  'occurrence_code/6: missing information to compile ~w:~w\n',
		  [A, B]).
functional_dependency(C, A, K, L) :-
	A>1,
	nb_getval('$chr_store_multi_hash_chr_translate____allocation_occurrence___2-1',
		  B),
	lookup_ht(B, C, D),
	member(E, D),
	E=suspension(_, active, _, _, I),
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-13',
		  F),
	lookup_ht(F, k(C, A), G),
	member(H, G),
	H=suspension(_, active, _, _, _, J, _, _, _),
	I>J, !,
	functional_dependency(C, 1, K, L).
functional_dependency(A, B, C, D) :-
	G=suspension(E, active, A, B, C, D),
	'chr gen_id'(E),
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
		  F),
	insert_ht(F, A, G),
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-12',
		  H),
	insert_ht(H, k(A, B), G).
get_functional_dependency(B, E, G, I) :-
	nb_getval('$chr_store_multi_hash_chr_translate____functional_dependency___4-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F, H, J),
	E>=F, !,
	G=H,
	I=J.
get_functional_dependency(_, _, _, _) :-
	fail.
initial_call_pattern(A) :-
	initial_call_pattern___1__0(A, _).
initial_call_pattern___1__0(B, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _), !.
initial_call_pattern___1__0(B, A) :-
	A=suspension(C, active, t, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',
		  D),
	insert_ht(D, B, A),
	call_pattern(B),
	(   A=suspension(_, active, _, _)
	->  setarg(2, A, inactive),
	    initial_call_pattern___1__1(B, A)
	;   true
	).
initial_call_pattern___1__1(B, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, C), !,
	initial_call_pattern___1__1__0__4(C, B, D).
initial_call_pattern___1__1__0__4([], A, B) :-
	initial_call_pattern___1__2(A, B).
initial_call_pattern___1__1__0__4([A|F], C, G) :-
	(   ( A=suspension(_, active, _, B, E),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		      D)
	->  initial_call_pattern___1__1__1__4(D,
					      E,
					      A,
					      F,
					      C,
					      G)
	;   initial_call_pattern___1__1__0__4(F, C, G)
	).
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([A|G], F, C, H, I, B) :-
	(   A=suspension(_, active, _, E),
	    D=t(303, B, C, A),
	    '$novel_production'(B, D),
	    '$novel_production'(C, D)
	->  '$extend_history'(B, D),
	    setarg(2, B, active),
	    ai_observation_schedule_new_calls(E, F),
	    (   B=suspension(_, active, _, _)
	    ->  setarg(2, B, inactive),
		initial_call_pattern___1__1__1__4(G,
						  F,
						  C,
						  H,
						  I,
						  B)
	    ;   true
	    )
	;   initial_call_pattern___1__1__1__4(G,
					      F,
					      C,
					      H,
					      I,
					      B)
	).
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(B, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
call_pattern___1__0(B, A) :-
	A=suspension(C, active, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____call_pattern___1-1',
		  D),
	insert_ht(D, B, A),
	call_pattern_worker(B),
	(   A=suspension(_, active, _)
	->  setarg(2, A, inactive),
	    call_pattern___1__1(B, A)
	;   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([A|C], B)) :- !,
	D=odom(A, B),
	depends_on_goal(odom([A|C], B), D),
	call_pattern(D).
call_pattern_worker(odom((A;B), C)) :- !,
	D=odom((A;B), C),
	E=odom([], C),
	final_answer_pattern(D, E),
	F=odom(A, C),
	G=odom(B, C),
	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, E), G)) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F),
	E>F, !,
	final_answer_pattern(odom(occ(B, E), G),
			     odom([], G)).
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), I)) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, F, G, _),
	is_passive(F, G), !,
	H is C+1,
	J=odom(occ(B, H), I),
	call_pattern(J),
	final_answer_pattern(odom(occ(B, C), I),
			     odom([], I)),
	depends_on(odom(occ(B, C), I), J).
call_pattern_worker(odom(occ(B, C), H)) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
		  A),
	(   lookup_ht(A, k(B, C, simplification), D),
	    member(E, D),
	    E=suspension(_, active, _, _, _, _, F, G, _),
	    \+ is_passive(F, G), !,
	    ai_observation_memo_simplification_rest_heads(B,
							  C,
							  I),
	    ai_observation_observe_set(H, I, K),
	    ai_observation_memo_abstract_goal(F, J),
	    call_pattern(odom(J, K)),
	    L is C+1,
	    M=odom(occ(B, L), H),
	    call_pattern(M),
	    depends_on_as(odom(occ(B, C), H),
			  odom(J, K),
			  M),
	    final_answer_pattern(odom(occ(B, C), H),
				 odom([], H))
	;   lookup_ht(A, k(B, C, propagation), N),
	    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(H, R, S),
	    ord_add_element(S, B, U),
	    ai_observation_memo_abstract_goal(P, T),
	    call_pattern(odom(T, U)),
	    (   ord_memberchk(B, S)
	    ->  V=no
	    ;   V=yes
	    ),
	    W is C+1,
	    X=odom(occ(B, W), H),
	    call_pattern(X),
	    depends_on_ap(odom(occ(B, C), H),
			  odom(T, U),
			  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(B, E, G) :-
	( nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		    A),
	  lookup_ht(A, B, C)
	),
	(   member(D, C),
	    D=suspension(_, active, _, _, F),
	    ai_observation_leq(E, F), !
	;    !,
	    final_answer_pattern___2__0__0__2(C, B, E, G)
	).
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([A|G], C, E, H) :-
	(   ( A=suspension(_, active, _, B, D),
	      B==C
	    ),
	    ai_observation_leq(D, E)
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			F),
	      delete_ht(F, C, A)
	    ),
	    final_answer_pattern___2__0__0__2(G, C, E, H)
	;   final_answer_pattern___2__0__0__2(G, C, E, H)
	).
final_answer_pattern___2__0(A, B, C) :-
	final_answer_pattern___2__1(A, B, C).
final_answer_pattern___2__1(B, D, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____initial_call_pattern___1-1',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, B, D),
	'chr gen_id'(E),
	final_answer_pattern___2__1__0__3(F, B, D, 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([A|E], C, F, G) :-
	(   ( A=suspension(_, active, _, B),
	      B==C
	    ),
	    nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		      D)
	->  final_answer_pattern___2__1__1__3(D,
					      A,
					      E,
					      C,
					      F,
					      G)
	;   final_answer_pattern___2__1__0__3(E, C, F, G)
	).
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([A|J], B, K, G, I, C) :-
	(   A=suspension(_, active, _, H),
	    D=t(303, B, C, A),
	    '$novel_production'(B, D),
	    '$novel_production'(C, D)
	->  '$extend_history'(C, D),
	    ( arg(2, C, E),
	      setarg(2, C, active),
	      (   E==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    F),
		  insert_ht(F, G, C)
	      ;   true
	      )
	    ),
	    ai_observation_schedule_new_calls(H, I),
	    (   C=suspension(_, active, _, _, _)
	    ->  setarg(2, C, inactive),
		final_answer_pattern___2__1__1__3(J,
						  B,
						  K,
						  G,
						  I,
						  C)
	    ;   true
	    )
	;   final_answer_pattern___2__1__1__3(J,
					      B,
					      K,
					      G,
					      I,
					      C)
	).
final_answer_pattern___2__1(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	final_answer_pattern___2__2(B, C, A).
final_answer_pattern___2__2(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__2__0__4(C, B, D, E).
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([A|J], C, I, D) :-
	(   A=suspension(_, active, _, H, B),
	    B==C,
	    E=t(305, A, D),
	    '$novel_production'(A, E),
	    '$novel_production'(D, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    G),
		  insert_ht(G, C, D)
	      ;   true
	      )
	    ),
	    final_answer_pattern(H, I),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		final_answer_pattern___2__2__0__4(J,
						  C,
						  I,
						  D)
	    ;   true
	    )
	;   final_answer_pattern___2__2__0__4(J, C, I, D)
	).
final_answer_pattern___2__2(A, B, C) :-
	final_answer_pattern___2__3(A, B, C).
final_answer_pattern___2__3(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__3__0__5(C, B, D, E).
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([A|G], C, H, I) :-
	(   ( A=suspension(_, active, _, E, B),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  final_answer_pattern___2__3__1__5(F,
					      E,
					      A,
					      G,
					      C,
					      H,
					      I)
	;   final_answer_pattern___2__3__0__5(G, C, H, I)
	).
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([A|G], C, H, I, J, K, L) :-
	(   A=suspension(_, active, _, B, F),
	    B==C
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
			  D),
		delete_ht(D, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',
			E),
	      delete_ht(E, F, A)
	    ),
	    final_answer_pattern___2__3__1__5(G,
					      C,
					      H,
					      I,
					      J,
					      K,
					      L)
	;   final_answer_pattern___2__3__1__5(G,
					      C,
					      H,
					      I,
					      J,
					      K,
					      L)
	).
final_answer_pattern___2__3(A, B, C) :-
	final_answer_pattern___2__4(A, B, C).
final_answer_pattern___2__4(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__4__0__6(C, B, D, E).
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([A|M], C, I, D) :-
	(   A=suspension(_, active, _, H, B),
	    B==C,
	    E=t(310, A, D),
	    '$novel_production'(A, E),
	    '$novel_production'(D, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    G),
		  insert_ht(G, C, D)
	      ;   true
	      )
	    ),
	    ( H=odom([_|J], _),
	      I=odom([], K),
	      L=odom(J, K),
	      call_pattern(L),
	      depends_on(H, L)
	    ),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		final_answer_pattern___2__4__0__6(M,
						  C,
						  I,
						  D)
	    ;   true
	    )
	;   final_answer_pattern___2__4__0__6(M,
					      C,
					      I,
					      D)
	).
final_answer_pattern___2__4(A, B, C) :-
	final_answer_pattern___2__5(A, B, C).
final_answer_pattern___2__5(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__5__0__7(C, B, D, E).
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([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, G, B, E),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  final_answer_pattern___2__5__1__7(F,
					      G,
					      E,
					      A,
					      H,
					      C,
					      I,
					      J)
	;   final_answer_pattern___2__5__0__7(H, C, I, J)
	).
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([A|N], L, C, D, O, I, J, E) :-
	(   A=suspension(_, active, _, B, K),
	    B==C,
	    F=t(317, D, E, A),
	    '$novel_production'(D, F),
	    '$novel_production'(E, F),
	    '$novel_production'(A, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    H),
		  insert_ht(H, I, E)
	      ;   true
	      )
	    ),
	    ( ai_observation_lub(J, K, M),
	      final_answer_pattern(L, M)
	    ),
	    (   E=suspension(_, active, _, _, _)
	    ->  setarg(2, E, inactive),
		final_answer_pattern___2__5__1__7(N,
						  L,
						  C,
						  D,
						  O,
						  I,
						  J,
						  E)
	    ;   true
	    )
	;   final_answer_pattern___2__5__1__7(N,
					      L,
					      C,
					      D,
					      O,
					      I,
					      J,
					      E)
	).
final_answer_pattern___2__5(A, B, C) :-
	final_answer_pattern___2__6(A, B, C).
final_answer_pattern___2__6(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__6__0__8(C, B, D, E).
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([A|H], C, I, J) :-
	(   ( A=suspension(_, active, _, G, E, B),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  final_answer_pattern___2__6__1__8(F,
					      G,
					      E,
					      A,
					      H,
					      C,
					      I,
					      J)
	;   final_answer_pattern___2__6__0__8(H, C, I, J)
	).
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([A|N], L, C, D, O, I, K, E) :-
	(   A=suspension(_, active, _, B, J),
	    B==C,
	    F=t(317, D, A, E),
	    '$novel_production'(D, F),
	    '$novel_production'(A, F),
	    '$novel_production'(E, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    H),
		  insert_ht(H, I, E)
	      ;   true
	      )
	    ),
	    ( ai_observation_lub(J, K, M),
	      final_answer_pattern(L, M)
	    ),
	    (   E=suspension(_, active, _, _, _)
	    ->  setarg(2, E, inactive),
		final_answer_pattern___2__6__1__8(N,
						  L,
						  C,
						  D,
						  O,
						  I,
						  K,
						  E)
	    ;   true
	    )
	;   final_answer_pattern___2__6__1__8(N,
					      L,
					      C,
					      D,
					      O,
					      I,
					      K,
					      E)
	).
final_answer_pattern___2__6(A, B, C) :-
	final_answer_pattern___2__7(A, B, C).
final_answer_pattern___2__7(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__7__0__9(C, B, D, E).
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([A|J], C, I, D) :-
	(   A=suspension(_, active, _, H, _, B, _),
	    B==C,
	    E=t(325, A, D),
	    '$novel_production'(A, E),
	    '$novel_production'(D, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    G),
		  insert_ht(G, C, D)
	      ;   true
	      )
	    ),
	    final_answer_pattern(H, I),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		final_answer_pattern___2__7__0__9(J,
						  C,
						  I,
						  D)
	    ;   true
	    )
	;   final_answer_pattern___2__7__0__9(J, C, I, D)
	).
final_answer_pattern___2__7(A, B, C) :-
	final_answer_pattern___2__8(A, B, C).
final_answer_pattern___2__8(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__8__0__10(C, B, D, E).
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([A|I], C, J, K) :-
	(   ( A=suspension(_, active, _, G, B, E, H),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  final_answer_pattern___2__8__1__10(F,
					       G,
					       E,
					       H,
					       A,
					       I,
					       C,
					       J,
					       K)
	;   final_answer_pattern___2__8__0__10(I,
					       C,
					       J,
					       K)
	).
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([A|T], J, C, N, D, U, I, K, E) :-
	(   A=suspension(_, active, _, B, R),
	    B==C,
	    F=t(326, D, E, A),
	    '$novel_production'(D, F),
	    '$novel_production'(E, F),
	    '$novel_production'(A, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    H),
		  insert_ht(H, I, E)
	      ;   true
	      )
	    ),
	    ( J=odom(occ(L, M), _),
	      (   ai_observation_is_observed(K, L)
	      ->  ai_observed_internal(L, M)
	      ;   ai_not_observed_internal(L, M)
	      ),
	      (   N==yes
	      ->  K=odom([], O),
		  ord_del_element(O, L, P),
		  Q=odom([], P)
	      ;   Q=K
	      ),
	      ai_observation_lub(Q, R, S),
	      final_answer_pattern(J, S)
	    ),
	    (   E=suspension(_, active, _, _, _)
	    ->  setarg(2, E, inactive),
		final_answer_pattern___2__8__1__10(T,
						   J,
						   C,
						   N,
						   D,
						   U,
						   I,
						   K,
						   E)
	    ;   true
	    )
	;   final_answer_pattern___2__8__1__10(T,
					       J,
					       C,
					       N,
					       D,
					       U,
					       I,
					       K,
					       E)
	).
final_answer_pattern___2__8(A, B, C) :-
	final_answer_pattern___2__9(A, B, C).
final_answer_pattern___2__9(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',
		  A),
	lookup_ht(A, B, C), !,
	final_answer_pattern___2__9__0__11(C, B, D, E).
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([A|I], C, J, K) :-
	(   ( A=suspension(_, active, _, G, E, B, H),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  final_answer_pattern___2__9__1__11(F,
					       G,
					       E,
					       H,
					       A,
					       I,
					       C,
					       J,
					       K)
	;   final_answer_pattern___2__9__0__11(I,
					       C,
					       J,
					       K)
	).
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([A|T], J, C, N, D, U, I, R, E) :-
	(   A=suspension(_, active, _, B, K),
	    B==C,
	    F=t(326, D, A, E),
	    '$novel_production'(D, F),
	    '$novel_production'(A, F),
	    '$novel_production'(E, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			    H),
		  insert_ht(H, I, E)
	      ;   true
	      )
	    ),
	    ( J=odom(occ(L, M), _),
	      (   ai_observation_is_observed(K, L)
	      ->  ai_observed_internal(L, M)
	      ;   ai_not_observed_internal(L, M)
	      ),
	      (   N==yes
	      ->  K=odom([], O),
		  ord_del_element(O, L, P),
		  Q=odom([], P)
	      ;   Q=K
	      ),
	      ai_observation_lub(Q, R, S),
	      final_answer_pattern(J, S)
	    ),
	    (   E=suspension(_, active, _, _, _)
	    ->  setarg(2, E, inactive),
		final_answer_pattern___2__9__1__11(T,
						   J,
						   C,
						   N,
						   D,
						   U,
						   I,
						   R,
						   E)
	    ;   true
	    )
	;   final_answer_pattern___2__9__1__11(T,
					       J,
					       C,
					       N,
					       D,
					       U,
					       I,
					       R,
					       E)
	).
final_answer_pattern___2__9(A, B, C) :-
	final_answer_pattern___2__10(A, B, C).
final_answer_pattern___2__10(D, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      C),
	    insert_ht(C, D, A)
	;   true
	).
abstract_constraints(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		  A),
	(   member(B, A),
	    B=suspension(_, active, _, _), !
	;    !,
	    abstract_constraints___1__0__0__2(A, C)
	).
abstract_constraints___1__0__0__2([], A) :-
	abstract_constraints___1__1(A).
abstract_constraints___1__0__0__2([A|F], G) :-
	(   A=suspension(_, active, _, _)
	->  ( setarg(2, A, removed),
	      arg(3, A, B),
	      (   var(B)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
			    C),
		  C=[_|D],
		  b_setval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
			   D),
		  (   D=[E|_]
		  ->  setarg(3, E, _)
		  ;   true
		  )
	      ;   B=[_, _|D],
		  setarg(2, B, D),
		  (   D=[E|_]
		  ->  setarg(3, E, B)
		  ;   true
		  )
	      )
	    ),
	    abstract_constraints___1__0__0__2(F, G)
	;   abstract_constraints___1__0__0__2(F, G)
	).
abstract_constraints(A) :-
	abstract_constraints___1__1(A).
abstract_constraints___1__1(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		  D),
	E=[C|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(D, B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, D, B),
	'chr gen_id'(E),
	depends_on___2__0__0__1(F, D, B, C).
depends_on___2__0__0__1([], A, B, C) :-
	depends_on___2__1(A, B, C).
depends_on___2__0__0__1([A|K], H, C, D) :-
	(   A=suspension(_, active, _, B, J),
	    B==C,
	    E=t(305, D, A),
	    '$novel_production'(D, E),
	    '$novel_production'(A, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
			      G),
		    insert_ht(G, H, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',
			    I),
		  insert_ht(I, C, D)
	      ;   true
	      )
	    ),
	    final_answer_pattern(H, J),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		depends_on___2__0__0__1(K, H, C, D)
	    ;   true
	    )
	;   depends_on___2__0__0__1(K, H, C, D)
	).
depends_on___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	depends_on___2__1(B, C, A).
depends_on___2__1(D, F, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
			C),
	      insert_ht(C, D, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',
		      E),
	    insert_ht(E, F, A)
	;   true
	).
depends_on_ap(A, B, C, D) :-
	depends_on_ap___4__0(A, B, C, D, _).
depends_on_ap___4__0(D, E, B, F, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, H), !,
	C=suspension(G, not_stored_yet, t, D, E, B, F),
	'chr gen_id'(G),
	depends_on_ap___4__0__0__1(H,
				   D,
				   E,
				   B,
				   F,
				   C).
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([A|L], J, H, C, M, D) :-
	(   A=suspension(_, active, _, B, K),
	    B==C,
	    E=t(325, D, A),
	    '$novel_production'(D, E),
	    '$novel_production'(A, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',
			      G),
		    insert_ht(G, H, D)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',
			    I),
		  insert_ht(I, C, D)
	      ;   true
	      )
	    ),
	    final_answer_pattern(J, K),
	    (   D=suspension(_, active, _, _, _, _, _)
	    ->  setarg(2, D, inactive),
		depends_on_ap___4__0__0__1(L,
					   J,
					   H,
					   C,
					   M,
					   D)
	    ;   true
	    )
	;   depends_on_ap___4__0__0__1(L,
				       J,
				       H,
				       C,
				       M,
				       D)
	).
depends_on_ap___4__0(B, C, D, E, A) :-
	A=suspension(F, not_stored_yet, t, B, C, D, E),
	'chr gen_id'(F),
	depends_on_ap___4__1(B, C, D, E, A).
depends_on_ap___4__1(D, B, E, F, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, C), !,
	depends_on_ap___4__1__0__2(C,
				   D,
				   B,
				   E,
				   F,
				   G).
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([A|H], I, C, E, J, K) :-
	(   ( A=suspension(_, active, _, B, G),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  depends_on_ap___4__1__1__2(F,
				       G,
				       A,
				       H,
				       I,
				       C,
				       E,
				       J,
				       K)
	;   depends_on_ap___4__1__0__2(H,
				       I,
				       C,
				       E,
				       J,
				       K)
	).
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([A|U], L, B, V, K, I, D, O, E) :-
	(   A=suspension(_, active, _, C, S),
	    A\==B,
	    C==D,
	    F=t(326, E, B, A),
	    '$novel_production'(E, F),
	    '$novel_production'(B, F),
	    '$novel_production'(A, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',
			      H),
		    insert_ht(H, I, E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',
			    J),
		  insert_ht(J, D, E)
	      ;   true
	      )
	    ),
	    ( K=odom(occ(M, N), _),
	      (   ai_observation_is_observed(L, M)
	      ->  ai_observed_internal(M, N)
	      ;   ai_not_observed_internal(M, N)
	      ),
	      (   O==yes
	      ->  L=odom([], P),
		  ord_del_element(P, M, Q),
		  R=odom([], Q)
	      ;   R=L
	      ),
	      ai_observation_lub(R, S, T),
	      final_answer_pattern(K, T)
	    ),
	    (   E=suspension(_, active, _, _, _, _, _)
	    ->  setarg(2, E, inactive),
		depends_on_ap___4__1__1__2(U,
					   L,
					   B,
					   V,
					   K,
					   I,
					   D,
					   O,
					   E)
	    ;   true
	    )
	;   depends_on_ap___4__1__1__2(U,
				       L,
				       B,
				       V,
				       K,
				       I,
				       D,
				       O,
				       E)
	).
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(_, D, F, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-2',
			C),
	      insert_ht(C, D, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____depends_on_ap___4-3',
		      E),
	    insert_ht(E, F, A)
	;   true
	).
depends_on_goal(A, B) :-
	depends_on_goal___2__0(A, B, _).
depends_on_goal___2__0(B, D, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
		  A),
	lookup_ht(A, B, C), !,
	depends_on_goal___2__0__0__1(C, B, D, E).
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([A|K], C, D, L) :-
	(   ( A=suspension(_, active, _, B, J),
	      B==C
	    ),
	    ( ground(D),
	      nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
			E),
	      lookup_ht(E, D, F)
	    ),
	    member(G, F),
	    G=suspension(_, active, _, _, _)
	->  ( setarg(2, A, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-1',
			  H),
		delete_ht(H, C, A)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____depends_on___2-2',
			I),
	      delete_ht(I, J, A)
	    ),
	    depends_on_goal___2__0__0__1(K, C, D, L)
	;   depends_on_goal___2__0__0__1(K, C, D, L)
	).
depends_on_goal___2__0(A, B, C) :-
	depends_on_goal___2__1(A, B, C).
depends_on_goal___2__1(D, B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, F), !,
	C=suspension(E, not_stored_yet, t, D, B),
	'chr gen_id'(E),
	depends_on_goal___2__1__0__2(F, D, 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([A|M], H, C, D) :-
	(   A=suspension(_, active, _, B, I),
	    B==C,
	    E=t(310, D, A),
	    '$novel_production'(D, E),
	    '$novel_production'(A, E)
	->  '$extend_history'(D, E),
	    ( arg(2, D, F),
	      setarg(2, D, active),
	      (   F==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',
			    G),
		  insert_ht(G, C, D)
	      ;   true
	      )
	    ),
	    ( H=odom([_|J], _),
	      I=odom([], K),
	      L=odom(J, K),
	      call_pattern(L),
	      depends_on(H, L)
	    ),
	    (   D=suspension(_, active, _, _, _)
	    ->  setarg(2, D, inactive),
		depends_on_goal___2__1__0__2(M, H, C, D)
	    ;   true
	    )
	;   depends_on_goal___2__1__0__2(M, H, C, D)
	).
depends_on_goal___2__1(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	depends_on_goal___2__2(B, C, A).
depends_on_goal___2__2(_, D, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____depends_on_goal___2-2',
		      C),
	    insert_ht(C, D, A)
	;   true
	).
ai_observed_internal(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	ai_observed_internal___2__0__0__1(D, B, C).
ai_observed_internal___2__0__0__1([], A, B) :-
	ai_observed_internal___2__1(A, B).
ai_observed_internal___2__0__0__1([A|K], C, E) :-
	(   A=suspension(_, active, _, B, D),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( arg(3, A, 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(C, E), A)
	    ),
	    ai_observed_internal___2__0__0__1(K, C, E)
	;   ai_observed_internal___2__0__0__1(K, C, E)
	).
ai_observed_internal(A, B) :-
	ai_observed_internal___2__1(A, B).
ai_observed_internal___2__1(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	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),
	member(B, A),
	B=suspension(_, active, _), !.
ai_observed_internal___2__1(A, B) :-
	D=suspension(C, active, _, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',
		  E),
	F=[D|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), D).
ai_not_observed_internal(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !.
ai_not_observed_internal(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !.
ai_not_observed_internal(C, D) :-
	nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',
		  A),
	member(B, A),
	B=suspension(_, active, _), !,
	ai_not_observed(C, D).
ai_not_observed_internal(A, B) :-
	D=suspension(C, active, _, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',
		  E),
	F=[D|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), D).
ai_not_observed(A, B) :-
	ai_not_observed___2__0(A, B, _).
ai_not_observed___2__0(B, C, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
		  A),
	lookup_ht(A, k(B, C, yes), F), !,
	D=suspension(E, not_stored_yet, B, C),
	'chr gen_id'(E),
	ai_not_observed___2__0__0__1(F, B, C, D).
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([A|T], C, E, P) :-
	(   ( A=suspension(_, active, B, D, F),
	      B==C,
	      D==E,
	      F=yes
	    ),
	    ( ( ground(C),
		nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			  G),
		lookup_ht(G, C, H)
	      ),
	      member(I, H),
	      I=suspension(_, active, _, _, J, N)
	    ),
	    E<J
	->  ( ( setarg(2, A, removed),
		( nb_getval('$chr_store_multi_hash_chr_translate____stored___3-13',
			    K),
		  delete_ht(K, k(C, yes), A)
		),
		nb_getval('$chr_store_multi_hash_chr_translate____stored___3-123',
			  L),
		delete_ht(L, k(C, E, yes), A)
	      ),
	      setarg(2, I, removed),
	      ( nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-13',
			  M),
		delete_ht(M, k(C, N), I)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____stored_complete___3-1',
			O),
	      delete_ht(O, C, I)
	    ),
	    ( arg(2, P, Q),
	      setarg(2, P, active),
	      (   Q==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
			    R),
		  insert_ht(R, k(C, E), P)
	      ;   true
	      )
	    ),
	    ( S is N-1,
	      stored(C, E, maybe),
	      stored_complete(C, J, S)
	    ),
	    (   P=suspension(_, active, _, _)
	    ->  setarg(2, P, inactive),
		ai_not_observed___2__0__0__1(T,
					     C,
					     E,
					     P)
	    ;   true
	    )
	;   ai_not_observed___2__0__0__1(T, C, E, P)
	).
ai_not_observed___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	ai_not_observed___2__1(B, C, A).
ai_not_observed___2__1(D, E, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
		      C),
	    insert_ht(C, k(D, E), A)
	;   true
	).
ai_is_observed(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	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(D, B, E, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		  A),
	lookup_ht(A, B, G), !,
	C=suspension(F, not_stored_yet, t, D, B, E),
	'chr gen_id'(F),
	depends_on_as___3__0__0__1(G, D, B, E, C).
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([A|H], I, C, E, J) :-
	(   ( A=suspension(_, active, _, B, G),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____final_answer_pattern___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  depends_on_as___3__0__1__1(F,
				       G,
				       A,
				       H,
				       I,
				       C,
				       E,
				       J)
	;   depends_on_as___3__0__0__1(H,
				       I,
				       C,
				       E,
				       J)
	).
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([A|O], K, B, P, M, J, D, E) :-
	(   A=suspension(_, active, _, C, L),
	    A\==B,
	    C==D,
	    F=t(317, E, B, A),
	    '$novel_production'(E, F),
	    '$novel_production'(B, F),
	    '$novel_production'(A, F)
	->  '$extend_history'(E, F),
	    ( arg(2, E, G),
	      setarg(2, E, active),
	      (   G==not_stored_yet
	      ->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',
			      H),
		    insert_ht(H, D, E)
		  ),
		  nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',
			    I),
		  insert_ht(I, J, E)
	      ;   true
	      )
	    ),
	    ( ai_observation_lub(K, L, N),
	      final_answer_pattern(M, N)
	    ),
	    (   E=suspension(_, active, _, _, _, _)
	    ->  setarg(2, E, inactive),
		depends_on_as___3__0__1__1(O,
					   K,
					   B,
					   P,
					   M,
					   J,
					   D,
					   E)
	    ;   true
	    )
	;   depends_on_as___3__0__1__1(O,
				       K,
				       B,
				       P,
				       M,
				       J,
				       D,
				       E)
	).
depends_on_as___3__0(B, C, D, A) :-
	A=suspension(E, not_stored_yet, t, B, C, D),
	'chr gen_id'(E),
	depends_on_as___3__1(B, C, D, A).
depends_on_as___3__1(_, F, D, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  ( nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-3',
			C),
	      insert_ht(C, D, A)
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____depends_on_as___3-2',
		      E),
	    insert_ht(E, F, A)
	;   true
	).
ai_observation_gather_results :-
	ai_observation_gather_results___0__0(_).
ai_observation_gather_results___0__0(B) :-
	nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',
		  A), !,
	ai_observation_gather_results___0__0__0__1(A, B).
ai_observation_gather_results___0__0__0__1([], A) :-
	ai_observation_gather_results___0__1(A).
ai_observation_gather_results___0__0__0__1([A|I], J) :-
	(   A=suspension(_, active, _, G, H)
	->  ( setarg(2, A, removed),
	      ( arg(3, A, B),
		(   var(B)
		->  nb_getval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',
			      C),
		    C=[_|D],
		    b_setval('$chr_store_global_ground_chr_translate____ai_observed_internal___2',
			     D),
		    (   D=[E|_]
		    ->  setarg(3, E, _)
		    ;   true
		    )
		;   B=[_, _|D],
		    setarg(2, B, D),
		    (   D=[E|_]
		    ->  setarg(3, E, B)
		    ;   true
		    )
		)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ai_observed_internal___2-12',
			F),
	      delete_ht(F, k(G, H), A)
	    ),
	    ai_observation_gather_results___0__0__0__1(I, J)
	;   ai_observation_gather_results___0__0__0__1(I, J)
	).
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',
		  C), !,
	A=suspension(B, not_stored_yet, _),
	'chr gen_id'(B),
	ai_observation_gather_results___0__1__0__2(C, 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([A|N], I) :-
	(   A=suspension(_, active, _, G, H)
	->  ( setarg(2, A, removed),
	      ( arg(3, A, B),
		(   var(B)
		->  nb_getval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',
			      C),
		    C=[_|D],
		    b_setval('$chr_store_global_ground_chr_translate____ai_not_observed_internal___2',
			     D),
		    (   D=[E|_]
		    ->  setarg(3, E, _)
		    ;   true
		    )
		;   B=[_, _|D],
		    setarg(2, B, D),
		    (   D=[E|_]
		    ->  setarg(3, E, B)
		    ;   true
		    )
		)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____ai_not_observed_internal___2-12',
			F),
	      delete_ht(F, k(G, H), A)
	    ),
	    ( arg(2, I, J),
	      setarg(2, I, active),
	      (   J==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',
			    K),
		  L=[I|K],
		  b_setval('$chr_store_global_ground_chr_translate____ai_observation_gather_results___0',
			   L),
		  (   K=[M|_]
		  ->  setarg(3, M, L)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    ai_not_observed(G, H),
	    (   I=suspension(_, active, _)
	    ->  setarg(2, I, inactive),
		ai_observation_gather_results___0__1__0__2(N, I)
	    ;   true
	    )
	;   ai_observation_gather_results___0__1__0__2(N, I)
	).
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(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G), !,
	F=G.
ai_observation_memo_simplification_rest_heads(B, C, V) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, G, M, _),
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', F),
	lookup_ht(F, G, H),
	member(I, H),
	I=suspension(_, active, _, _, _, L),
	nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		  J),
	member(K, J),
	K=suspension(_, active, _, Q), !,
	L=pragma(rule(O, R, _, _), ids(N, _), _, _, _),
	once(select2(M, _, N, O, _, P)),
	ai_observation_abstract_constraints(P, Q, S),
	ai_observation_abstract_constraints(R, Q, T),
	append(S, T, U),
	sort(U, V),
	ai_observation_memoed_simplification_rest_heads(B,
							C,
							V).
ai_observation_memo_simplification_rest_heads(_, _, _) :-
	fail.
ai_observation_memoed_simplification_rest_heads(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_simplification_rest_heads___3-12',
		  E),
	insert_ht(E, k(A, B), F).
ai_observation_memo_propagation_rest_heads(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G), !,
	F=G.
ai_observation_memo_propagation_rest_heads(B, C, V) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, G, M, _),
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', F),
	lookup_ht(F, G, H),
	member(I, H),
	I=suspension(_, active, _, _, _, L),
	nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		  J),
	member(K, J),
	K=suspension(_, active, _, Q), !,
	L=pragma(rule(R, O, _, _), ids(_, N), _, _, _),
	once(select2(M, _, N, O, _, P)),
	ai_observation_abstract_constraints(P, Q, S),
	ai_observation_abstract_constraints(R, Q, T),
	append(S, T, U),
	sort(U, V),
	ai_observation_memoed_propagation_rest_heads(B, C, V).
ai_observation_memo_propagation_rest_heads(_, _, _) :-
	fail.
ai_observation_memoed_propagation_rest_heads(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_propagation_rest_heads___3-12',
		  E),
	insert_ht(E, k(A, B), F).
ai_observation_memoed_abstract_goal(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',
		  D),
	insert_ht(D, A, E).
ai_observation_memo_abstract_goal(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____ai_observation_memoed_abstract_goal___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, F), !,
	E=F.
ai_observation_memo_abstract_goal(B, M) :-
	nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1', A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, _, G),
	nb_getval('$chr_store_global_ground_chr_translate____abstract_constraints___1',
		  E),
	member(F, E),
	F=suspension(_, active, _, L), !,
	G=pragma(rule(H, I, J, K), _, _, _, _),
	ai_observation_abstract_goal_(H,
				      I,
				      J,
				      K,
				      L,
				      N),
	M=N,
	ai_observation_memoed_abstract_goal(B, N).
ai_observation_memo_abstract_goal(A, B) :-
	D=suspension(C, active, _, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_global_ground_chr_translate____ai_observation_memo_abstract_goal___2',
		  E),
	F=[D|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',
		  C), !,
	A=suspension(B, not_stored_yet, t, _),
	'chr gen_id'(B),
	partial_wake_analysis___0__0__0__1(C, A).
partial_wake_analysis___0__0__0__1([], A) :-
	partial_wake_analysis___0__1(A).
partial_wake_analysis___0__0__0__1([A|H], I) :-
	(   A=suspension(_, active, _, _, C, _, E, F, G),
	    nb_getval('$chr_store_multi_hash_chr_translate____constraint_mode___2-1',
		      B),
	    lookup_ht(B, C, D)
	->  partial_wake_analysis___0__0__1__1(D,
					       C,
					       E,
					       F,
					       G,
					       A,
					       H,
					       I)
	;   partial_wake_analysis___0__0__0__1(H, I)
	).
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([A|H], C, E, I, J, K, L, M) :-
	(   ( A=suspension(_, active, _, _, B, G),
	      B==C
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____rule___2-1',
		      D),
	    lookup_ht(D, E, F)
	->  partial_wake_analysis___0__0__2__1(F,
					       G,
					       A,
					       H,
					       C,
					       E,
					       I,
					       J,
					       K,
					       L,
					       M)
	;   partial_wake_analysis___0__0__1__1(H,
					       C,
					       E,
					       I,
					       J,
					       K,
					       L,
					       M)
	).
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([A|W], S, F, X, U, C, M, N, E, Y, D) :-
	(   A=suspension(_, active, _, _, B, L),
	    B==C,
	    G=t(330, D, E, A, F),
	    '$novel_production'(D, G),
	    '$novel_production'(E, G),
	    '$novel_production'(A, G),
	    '$novel_production'(F, G)
	->  '$extend_history'(D, G),
	    ( arg(2, D, H),
	      setarg(2, D, active),
	      (   H==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',
			    I),
		  J=[D|I],
		  b_setval('$chr_store_global_ground_chr_translate____partial_wake_analysis___0',
			   J),
		  (   I=[K|_]
		  ->  setarg(4, K, J)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    ( L=pragma(rule(O, V, Q, _), _, _, _, _),
	      (   is_passive(C, M)
	      ->  true
	      ;   N==simplification
	      ->  select(P, O, _),
		  P=..[_|R],
		  term_variables(Q, T),
		  partial_wake_args(R, S, T, U)
	      ;   select(P, V, _),
		  P=..[_|R],
		  term_variables(Q, T),
		  partial_wake_args(R, S, T, U)
	      )
	    ),
	    (   D=suspension(_, active, _, _)
	    ->  setarg(2, D, inactive),
		partial_wake_analysis___0__0__2__1(W,
						   S,
						   F,
						   X,
						   U,
						   C,
						   M,
						   N,
						   E,
						   Y,
						   D)
	    ;   true
	    )
	;   partial_wake_analysis___0__0__2__1(W,
					       S,
					       F,
					       X,
					       U,
					       C,
					       M,
					       N,
					       E,
					       Y,
					       D)
	).
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(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !.
no_partial_wake(A) :-
	D=suspension(B, active, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',
		  C),
	insert_ht(C, A, D).
wakes_partially(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____no_partial_wake___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !,
	fail.
wakes_partially(_).
phase_end(A) :-
	phase_end___1__0(A, _).
phase_end___1__0(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',
		  A),
	lookup_ht(A, B, E), !,
	C=suspension(D, not_stored_yet, B),
	'chr gen_id'(D),
	phase_end___1__0__0__1(E, B, C).
phase_end___1__0__0__1([], A, B) :-
	phase_end___1__1(A, B).
phase_end___1__0__0__1([A|I], C, E) :-
	(   A=suspension(_, active, B, H),
	    B==C
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',
			D),
	      delete_ht(D, C, A)
	    ),
	    ( arg(2, E, F),
	      setarg(2, E, active),
	      (   F==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',
			    G),
		  insert_ht(G, C, E)
	      ;   true
	      )
	    ),
	    call(H),
	    (   E=suspension(_, active, _)
	    ->  setarg(2, E, inactive),
		phase_end___1__0__0__1(I, C, E)
	    ;   true
	    )
	;   phase_end___1__0__0__1(I, C, E)
	).
phase_end___1__0(B, A) :-
	A=suspension(C, not_stored_yet, B),
	'chr gen_id'(C),
	phase_end___1__1(B, A).
phase_end___1__1(D, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',
		      C),
	    insert_ht(C, D, A)
	;   true
	).
delay_phase_end(B, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____phase_end___1-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _), !,
	call(E).
delay_phase_end(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____delay_phase_end___2-1',
		  D),
	insert_ht(D, A, E).
does_use_history(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
does_use_history(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',
		  D),
	insert_ht(D, A, E),
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',
		  F),
	insert_ht(F, k(A, B), E).
uses_history(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _), !.
uses_history(_) :-
	fail.
novel_production_call(B, C, G, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_history___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !,
	F=G.
novel_production_call(_, _, _, true).
does_use_field(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
does_use_field(A, B) :-
	E=suspension(C, active, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',
		  D),
	insert_ht(D, k(A, B), E).
uses_field(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____does_use_field___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
uses_field(_, _) :-
	fail.
uses_state(A, B) :-
	uses_state___2__0(A, B, _).
uses_state___2__0(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _), !.
uses_state___2__0(B, C, A) :-
	nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',
		  E), !,
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	uses_state___2__0__0__3(E, B, C, A).
uses_state___2__0__0__3([], A, B, C) :-
	uses_state___2__1(A, B, C).
uses_state___2__0__0__3([A|F], C, D, G) :-
	(   A=suspension(_, active, _),
	    nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',
		      B),
	    lookup_ht(B, k(C, D), E)
	->  uses_state___2__0__1__3(E,
				    A,
				    F,
				    C,
				    D,
				    G)
	;   uses_state___2__0__0__3(F, C, D, G)
	).
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([A|P], Q, R, C, E, K) :-
	(   A=suspension(_, active, _, B, D, O, _, N),
	    B==C,
	    D==E
	->  ( setarg(2, A, removed),
	      ( arg(3, A, F),
		(   var(F)
		->  nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',
			      G),
		    G=[_|H],
		    b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',
			     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____if_used_state___5-12',
			J),
	      delete_ht(J, k(C, E), A)
	    ),
	    ( arg(2, K, L),
	      setarg(2, K, active),
	      (   L==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
			    M),
		  insert_ht(M, k(C, E), K)
	      ;   true
	      )
	    ),
	    N=O,
	    (   K=suspension(_, active, _, _)
	    ->  setarg(2, K, inactive),
		uses_state___2__0__1__3(P,
					Q,
					R,
					C,
					E,
					K)
	    ;   true
	    )
	;   uses_state___2__0__1__3(P,
				    Q,
				    R,
				    C,
				    E,
				    K)
	).
uses_state___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	uses_state___2__1(B, C, A).
uses_state___2__1(D, E, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
		      C),
	    insert_ht(C, k(D, E), A)
	;   true
	).
if_used_state(D, E, I, J, H) :-
	( nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',
		    A),
	  member(B, A),
	  B=suspension(_, active, _)
	),
	(   nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
		      C),
	    lookup_ht(C, k(D, E), F),
	    member(G, F),
	    G=suspension(_, active, _, _), !,
	    H=I
	;    !,
	    H=J
	).
if_used_state(A, B, C, D, E) :-
	G=suspension(F, active, _, A, B, C, D, E),
	'chr gen_id'(F),
	nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',
		  H),
	I=[G|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), G).
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',
		  C), !,
	A=suspension(B, not_stored_yet, _),
	'chr gen_id'(B),
	used_states_known___0__0__0__1(C, A).
used_states_known___0__0__0__1([], A) :-
	used_states_known___0__1(A).
used_states_known___0__0__0__1([A|S], L) :-
	(   A=suspension(_, active, _, B, C, R, _, Q),
	    ( ( ground(B),
		ground(C)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____uses_state___2-12',
			D),
	      lookup_ht(D, k(B, C), E)
	    ),
	    member(F, E),
	    F=suspension(_, active, _, _)
	->  ( setarg(2, A, removed),
	      ( arg(3, A, G),
		(   var(G)
		->  nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',
			      H),
		    H=[_|I],
		    b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',
			     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____if_used_state___5-12',
			K),
	      delete_ht(K, k(B, C), A)
	    ),
	    ( arg(2, L, M),
	      setarg(2, L, active),
	      (   M==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',
			    N),
		  O=[L|N],
		  b_setval('$chr_store_global_ground_chr_translate____used_states_known___0',
			   O),
		  (   N=[P|_]
		  ->  setarg(3, P, O)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    Q=R,
	    (   L=suspension(_, active, _)
	    ->  setarg(2, L, inactive),
		used_states_known___0__0__0__1(S, L)
	    ;   true
	    )
	;   used_states_known___0__0__0__1(S, L)
	).
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(B) :-
	nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',
		  A), !,
	used_states_known___0__1__0__2(A, B).
used_states_known___0__1__0__2([], A) :-
	used_states_known___0__2(A).
used_states_known___0__1__0__2([A|P], I) :-
	(   A=suspension(_, active, _, G, H, _, O, N)
	->  ( setarg(2, A, removed),
	      ( arg(3, A, B),
		(   var(B)
		->  nb_getval('$chr_store_global_ground_chr_translate____if_used_state___5',
			      C),
		    C=[_|D],
		    b_setval('$chr_store_global_ground_chr_translate____if_used_state___5',
			     D),
		    (   D=[E|_]
		    ->  setarg(3, E, _)
		    ;   true
		    )
		;   B=[_, _|D],
		    setarg(2, B, D),
		    (   D=[E|_]
		    ->  setarg(3, E, B)
		    ;   true
		    )
		)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____if_used_state___5-12',
			F),
	      delete_ht(F, k(G, H), A)
	    ),
	    ( arg(2, I, J),
	      setarg(2, I, active),
	      (   J==not_stored_yet
	      ->  nb_getval('$chr_store_global_ground_chr_translate____used_states_known___0',
			    K),
		  L=[I|K],
		  b_setval('$chr_store_global_ground_chr_translate____used_states_known___0',
			   L),
		  (   K=[M|_]
		  ->  setarg(3, M, L)
		  ;   true
		  )
	      ;   true
	      )
	    ),
	    N=O,
	    (   I=suspension(_, active, _)
	    ->  setarg(2, I, inactive),
		used_states_known___0__1__0__2(P, I)
	    ;   true
	    )
	;   used_states_known___0__1__0__2(P, I)
	).
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) :-
	D=suspension(B, active, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',
		  C),
	insert_ht(C, A, D).
never_stored_default(A, B) :-
	never_stored_default___2__0(A, B, _).
never_stored_default___2__0(B, C, A) :-
	nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',
		  E), !,
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	never_stored_default___2__0__0__1(E, B, C, A).
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([A|U], D, O, I) :-
	(   A=suspension(_, active, _, B, Q),
	    B=[C|S],
	    C==D
	->  ( setarg(2, A, removed),
	      arg(3, A, E),
	      (   var(E)
	      ->  nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',
			    F),
		  F=[_|G],
		  b_setval('$chr_store_global_ground_chr_translate____never_stored_rules___2',
			   G),
		  (   G=[H|_]
		  ->  setarg(3, H, _)
		  ;   true
		  )
	      ;   E=[_, _|G],
		  setarg(2, E, G),
		  (   G=[H|_]
		  ->  setarg(3, H, E)
		  ;   true
		  )
	      )
	    ),
	    ( arg(2, I, J),
	      setarg(2, I, active),
	      (   J==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',
			    K),
		  insert_ht(K, D, I)
	      ;   true
	      )
	    ),
	    ( D=L/M,
	      functor(N, L, M),
	      inc_rule_count(P),
	      R=pragma(rule([N], [], true, O), ids([0], []), [], no, P),
	      Q=[R|T],
	      never_stored_rules(S, T)
	    ),
	    (   I=suspension(_, active, _, _)
	    ->  setarg(2, I, inactive),
		never_stored_default___2__0__0__1(U,
						  D,
						  O,
						  I)
	    ;   true
	    )
	;   never_stored_default___2__0__0__1(U,
					      D,
					      O,
					      I)
	).
never_stored_default___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, B, C),
	'chr gen_id'(D),
	never_stored_default___2__1(B, C, A).
never_stored_default___2__1(D, _, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',
		      C),
	    insert_ht(C, D, A)
	;   true
	).
never_stored_rules([], A) :- !,
	A=[].
never_stored_rules([B|L], J) :-
	nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, H), !,
	B=E/F,
	functor(G, E, F),
	inc_rule_count(I),
	K=pragma(rule([G], [], true, H), ids([0], []), [], no, I),
	J=[K|M],
	never_stored_rules(L, M).
never_stored_rules([_|A], B) :- !,
	never_stored_rules(A, B).
never_stored_rules(A, B) :-
	D=suspension(C, active, _, A, B),
	'chr gen_id'(C),
	nb_getval('$chr_store_global_ground_chr_translate____never_stored_rules___2',
		  E),
	F=[D|E],
	b_setval('$chr_store_global_ground_chr_translate____never_stored_rules___2',
		 F),
	(   E=[G|_]
	->  setarg(3, G, F)
	;   true
	).
check_storedness_assertion(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____stored_assertion___1-1',
		  A),
	lookup_ht(A, B, C),
	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, B, D),
	(   is_stored(B)
	->  true
	;   chr_warning(assertion_failed,
			'Constraint ~w is not stored. However, it was asserted to be stored.\n',
			[B])
	).
check_storedness_assertion(B) :-
	nb_getval('$chr_store_multi_hash_chr_translate____never_stored_default___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _), !,
	(   is_finally_stored(B)
	->  chr_warning(assertion_failed,
			'Constraint ~w is stored. However, it was asserted not to be stored.\n',
			[B])
	;   is_stored(B)
	->  chr_warning(assertion_failed,
			'Constraint ~w is temporarily stored. However, it was asserted not to be stored.\n',
			[B])
	;   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) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',
		  E),
	insert_ht(E, k(A, B), F).
get_success_continuation_occurrence(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G), !,
	F=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(B, C, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !.
skip_to_next_id___2__0(B, C, D) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), F), !,
	D=suspension(E, not_stored_yet, t, B, C),
	'chr gen_id'(E),
	skip_to_next_id___2__0__0__4(F, B, C, D).
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([A|J], C, E, K) :-
	(   ( A=suspension(_, active, _, _, B, D, G, H, _),
	      B==C,
	      D==E
	    ),
	    nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		      F),
	    lookup_ht(F, k(G, H), I)
	->  skip_to_next_id___2__0__1__4(I,
					 G,
					 H,
					 A,
					 J,
					 C,
					 E,
					 K)
	;   skip_to_next_id___2__0__0__4(J, C, E, K)
	).
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([A|N], C, E, F, O, L, I, G) :-
	(   A=suspension(_, active, _, B, D),
	    ( B==C,
	      D==E
	    ),
	    ( H=t(362, F, A, G),
	      '$novel_production'(F, H),
	      '$novel_production'(A, H),
	      '$novel_production'(G, H)
	    ),
	    I>1
	->  '$extend_history'(G, H),
	    ( arg(2, G, J),
	      setarg(2, G, active),
	      (   J==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
			    K),
		  insert_ht(K, k(L, I), G)
	      ;   true
	      )
	    ),
	    ( M is I-1,
	      skip_to_next_id(L, M)
	    ),
	    (   G=suspension(_, active, _, _, _)
	    ->  setarg(2, G, inactive),
		skip_to_next_id___2__0__1__4(N,
					     C,
					     E,
					     F,
					     O,
					     L,
					     I,
					     G)
	    ;   true
	    )
	;   skip_to_next_id___2__0__1__4(N,
					 C,
					 E,
					 F,
					 O,
					 L,
					 I,
					 G)
	).
skip_to_next_id___2__0(B, C, A) :-
	A=suspension(D, not_stored_yet, t, B, C),
	'chr gen_id'(D),
	skip_to_next_id___2__1(B, C, A).
skip_to_next_id___2__1(B, C, E) :-
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  A),
	lookup_ht(A, k(B, C), D), !,
	skip_to_next_id___2__1__0__5(D, B, C, E).
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([A|P], C, E, J) :-
	(   ( A=suspension(_, active, B, D, M),
	      B==C,
	      D==E
	    ),
	    ( ( ground(C),
		ground(E)
	      ),
	      nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
			F),
	      lookup_ht(F, k(C, E, propagation), G)
	    ),
	    member(H, G),
	    H=suspension(_, active, _, _, _, _, _, _, _)
	->  ( setarg(2, A, removed),
	      nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
			I),
	      delete_ht(I, k(C, E), A)
	    ),
	    ( arg(2, J, K),
	      setarg(2, J, active),
	      (   K==not_stored_yet
	      ->  nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
			    L),
		  insert_ht(L, k(C, E), J)
	      ;   true
	      )
	    ),
	    ( occurrence_code_id(C, E, M),
	      N is E+1,
	      O is M+1,
	      set_occurrence_code_id(C, N, O)
	    ),
	    (   J=suspension(_, active, _, _, _)
	    ->  setarg(2, J, inactive),
		skip_to_next_id___2__1__0__5(P, C, E, J)
	    ;   true
	    )
	;   skip_to_next_id___2__1__0__5(P, C, E, J)
	).
skip_to_next_id___2__1(A, B, C) :-
	skip_to_next_id___2__2(A, B, C).
skip_to_next_id___2__2(D, E, A) :-
	arg(2, A, B),
	setarg(2, A, active),
	(   B==not_stored_yet
	->  nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		      C),
	    insert_ht(C, k(D, E), A)
	;   true
	).
should_skip_to_next_id(B, C) :-
	nb_getval('$chr_store_multi_hash_chr_translate____skip_to_next_id___2-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _), !.
should_skip_to_next_id(_, _) :-
	fail.
bulk_propagation(B, E, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____max_occurrence___2-1',
		  A),
	lookup_ht(A, B, C),
	member(D, C),
	D=suspension(_, active, _, _, F),
	E>=F, !,
	skip_to_next_id(B, E).
bulk_propagation(C, B, A) :-
	A=:=B+1, !,
	skip_to_next_id(C, B),
	get_max_occurrence(C, D),
	E is D+1,
	bulk_propagation(C, A, E).
bulk_propagation(B, F, _) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-15',
		  A),
	lookup_ht(A, k(B, simplification), C),
	member(D, C),
	D=suspension(_, active, _, _, _, E, _, _, _),
	E=:=F+1, !,
	skip_to_next_id(B, F),
	get_max_occurrence(B, G),
	H is G+1,
	bulk_propagation(B, E, H).
bulk_propagation(B, C, G) :-
	nb_getval('$chr_store_multi_hash_chr_translate____continuation_occurrence___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, F),
	F>C+1, !,
	I is min(G, F),
	H is C+1,
	bulk_propagation(B, H, I).
bulk_propagation(A, B, _) :-
	skip_to_next_id(A, B),
	get_max_occurrence(A, C),
	E is C+1,
	D is B+1,
	bulk_propagation(A, D, E).
set_occurrence_code_id(A, B, D) :-
	get_max_occurrence(A, C),
	B>C, !,
	occurrence_code_id(A, B, D).
set_occurrence_code_id(B, C, K) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, _, _, G, H, _),
	nb_getval('$chr_store_multi_hash_chr_translate____passive___2-12',
		  F),
	lookup_ht(F, k(G, H), I),
	member(J, I),
	J=suspension(_, active, _, _, _), !,
	occurrence_code_id(B, C, K),
	L is C+1,
	set_occurrence_code_id(B, L, K).
set_occurrence_code_id(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence___5-125',
		  A),
	(   (   lookup_ht(A, k(B, C, simplification), D),
		member(E, D),
		E=suspension(_, active, _, _, _, _, _, _, _), !,
		occurrence_code_id(B, C, F),
		G is C+1,
		set_occurrence_code_id(B, G, F)
	    ;   lookup_ht(A, k(B, C, propagation), H),
		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(B, C), K),
		member(L, K),
		L=suspension(_, active, _, _, _), !,
		occurrence_code_id(B, C, F),
		M is C+1,
		N is F+1,
		set_occurrence_code_id(B, M, N)
	    )
	;   lookup_ht(A, k(B, C, propagation), O),
	    member(P, O),
	    P=suspension(_, active, _, _, _, _, _, _, _), !,
	    occurrence_code_id(B, C, F),
	    Q is C+1,
	    set_occurrence_code_id(B, Q, F)
	).
set_occurrence_code_id(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____set_occurrence_code_id___3-12',
		  E),
	insert_ht(E, k(A, B), F).
occurrence_code_id(A, B, C) :-
	F=suspension(D, active, A, B, C),
	'chr gen_id'(D),
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',
		  E),
	insert_ht(E, k(A, B), F).
get_occurrence_code_id(B, C, F) :-
	nb_getval('$chr_store_multi_hash_chr_translate____occurrence_code_id___3-12',
		  A),
	lookup_ht(A, k(B, C), D),
	member(E, D),
	E=suspension(_, active, _, _, G), !,
	F=G.
get_occurrence_code_id(B, A, _) :-
	(   A==0
	->  true
	;   format('no occurrence code for ~w!\n', [B:A])
	).
chr_constants(A) :-
	C=suspension(B, active, _, A),
	'chr gen_id'(B),
	nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',
		  D),
	E=[C|D],
	b_setval('$chr_store_global_ground_chr_translate____chr_constants___1',
		 E),
	(   D=[F|_]
	->  setarg(3, F, E)
	;   true
	).
get_chr_constants(C) :-
	nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, D), !,
	C=D.
get_chr_constants(A) :-
	chr_warning(internal, 'No constants found for key ~w.\n', [_]),
	A=[].
add_chr_constants_(G) :-
	nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',
		  A),
	member(B, A),
	B=suspension(_, active, _, H), !,
	setarg(2, B, removed),
	arg(3, B, C),
	(   var(C)
	->  nb_getval('$chr_store_global_ground_chr_translate____chr_constants___1',
		      D),
	    D=[_|E],
	    b_setval('$chr_store_global_ground_chr_translate____chr_constants___1',
		     E),
	    (   E=[F|_]
	    ->  setarg(3, F, _)
	    ;   true
	    )
	;   C=[_, _|E],
	    setarg(2, C, E),
	    (   E=[F|_]
	    ->  setarg(3, F, C)
	    ;   true
	    )
	),
	sort([G|H], 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',
		  C), !,
	A=suspension(B, not_stored_yet, _),
	'chr gen_id'(B),
	print_chr_constants___0__0__0__1(C, A).
print_chr_constants___0__0__0__1([], A) :-
	print_chr_constants___0__1(A).
print_chr_constants___0__0__0__1([A|C], D) :-
	(   A=suspension(_, active, _, B)
	->  format('\t* chr_constants : ~w.\n', [B]),
	    print_chr_constants___0__0__0__1(C, D)
	;   print_chr_constants___0__0__0__1(C, D)
	).
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.
