Repository: Kappa-Dev/KappaTools (language: python)

Issue:
Default value for Inverted counters is not set properly. 
Check with: 

```ka
%agent: A(c{=0 / += 7})

. -> A() @1
A(c{<=6}) -> A(c{+=1}) @1
```

>> KaSim --compile 

First rule is compiled into: 
A(c{=0} c__inverted{=0})+ @ 1

instead of: 
A(c{=0} c__inverted{=7})+ @ 1


Default value for inverted counters is not set apropriately in initial states in KaDE. 
Check for instance: 

%agent: A(c{=0 / += 2})
'tick'   A(c{<=1}) -> A(c{+=1}) @ 1

%init: 1 A()



Discussion / hints:

Fix patch:
diff --git a/core/KaSa_rep/export/export.ml b/core/KaSa_rep/export/export.ml
index 6f1369e1b..993ef03ba 100644
--- a/core/KaSa_rep/export/export.ml
+++ b/core/KaSa_rep/export/export.ml
@@ -1732,7 +1732,7 @@ functor
                         {
                           Signature.internal_state = states';
                           links = Some binding';
-                          counters_info = None;
+                          counter_info = None;
                         } )
                       :: acc ))
                   (state, []) interface
diff --git a/core/KaSa_rep/frontend/ckappa_sig.ml b/core/KaSa_rep/frontend/ckappa_sig.ml
index f17b89eba..f6ec59e79 100644
--- a/core/KaSa_rep/frontend/ckappa_sig.ml
+++ b/core/KaSa_rep/frontend/ckappa_sig.ml
@@ -39,16 +39,19 @@ type mixture =
   | PLUS of c_agent_id * agent * mixture
   | EMPTY_MIX
 
-and agent = {
+and 'counter parametric_agent = {
   agent_name: string;
-  ag_intf: interface;
+  ag_intf: 'counter interface;
   agent_name_pos: position; (*; ag_pos:position*)
 }
 
-and interface =
+and agent = counter parametric_agent
+and agent_sig = counter_sig parametric_agent
+
+and 'counter interface =
   | EMPTY_INTF
-  | PORT_SEP of port * interface
-  | COUNTER_SEP of counter * interface
+  | PORT_SEP of port * 'counter interface
+  | COUNTER_SEP of 'counter * 'counter interface
 
 and port = {
   port_name: string;
@@ -64,6 +67,14 @@ and counter = {
   counter_delta: int option;
 }
 
+and counter_sig = {
+  counter_sig_name: string;
+  counter_sig_default: int;
+  counter_sig_min: int option option;
+  counter_sig_max: int option option;
+  counter_visible: bool;
+}
+
 and counter_test = CEQ of int | CGTE of int | CVAR of string | UNKNOWN
 and internal = string option list
 
@@ -112,8 +123,8 @@ type ('pattern, 'rule) modif_expr =
 
 type 'pattern variable = ('pattern, string) Ast.variable_def
 
-type ('agent, 'pattern, 'mixture, 'rule) compil =
-  ('agent, 'pattern, 'mixture, string, 'rule) Ast.compil
+type ('agent, 'agent_sig, 'pattern, 'mixture, 'rule) compil =
+  ('agent, 'agent_sig, 'pattern, 'mixture, string, 'rule) Ast.compil
 
 type ('a, 'b, 'c) site_type = Internal of 'a | Binding of 'b | Counter of 'c
 type site = (site_name, site_name, site_name) site_type
@@ -869,7 +880,7 @@ type enriched_init = {
 type c_compil = {
   c_variables: c_variable Int_storage.Nearly_inf_Imperatif.t;
   (*pattern declaration for reusing as variable in perturbations or kinetic rate*)
-  c_signatures: (agent * position) Int_storage.Nearly_inf_Imperatif.t;
+  c_signatures: (agent_sig * position) Int_storage.Nearly_inf_Imperatif.t;
   (*agent signature declaration*)
   c_rules: enriched_rule Int_storage.Nearly_inf_Imperatif.t;
   (*rules (possibly named)*)
diff --git a/core/KaSa_rep/frontend/ckappa_sig.mli b/core/KaSa_rep/frontend/ckappa_sig.mli
index 0b5272e80..5c7f29921 100644
--- a/core/KaSa_rep/frontend/ckappa_sig.mli
+++ b/core/KaSa_rep/frontend/ckappa_sig.mli
@@ -119,16 +119,19 @@ type mixture =
   | PLUS of c_agent_id * agent * mixture
   | EMPTY_MIX
 
-and agent = {
+and 'counter parametric_agent = {
   agent_name: string;
-  ag_intf: interface;
+  ag_intf: 'counter interface;
   agent_name_pos: position; (*; ag_pos:position*)
 }
 
-and interface =
+and agent_sig = counter_sig parametric_agent
+and agent = counter parametric_agent
+
+and 'counter interface =
   | EMPTY_INTF
-  | PORT_SEP of port * interface
-  | COUNTER_SEP of counter * interface
+  | PORT_SEP of port * 'counter interface
+  | COUNTER_SEP of 'counter * 'counter interface
 
 and port = {
   port_name: string;
@@ -143,6 +146,14 @@ and counter = {
   counter_delta: int option;
 }
 
+and counter_sig = {
+  counter_sig_name: string;
+  counter_sig_default: int;
+  counter_sig_min: int option option;
+  counter_sig_max: int option option;
+  counter_visible: bool;
+}
+
 and counter_test = CEQ of int | CGTE of int | CVAR of string | UNKNOWN
 and internal = string option list
 
@@ -187,8 +198,8 @@ type ('pattern, 'rule) modif_expr =
 
 type 'pattern variable = ('pattern, string) Ast.variable_def
 
-type ('agent, 'pattern, 'mixture, 'rule) compil =
-  ('agent, 'pattern, 'mixture, string, 'rule) Ast.compil
+type ('agent, 'agent_sig, 'pattern, 'mixture, 'rule) compil =
+  ('agent, 'agent_sig, 'pattern, 'mixture, string, 'rule) Ast.compil
 
 type ('a, 'b, 'c) site_type = Internal of 'a | Binding of 'b | Counter of 'c
 type site = (site_name, site_name, site_name) site_type
@@ -415,7 +426,7 @@ type enriched_init = {
 type c_compil = {
   c_variables: c_variable Int_storage.Nearly_inf_Imperatif.t;
   (*pattern declaration for reusing as variable in perturbations or kinetic rate*)
-  c_signatures: (agent * position) Int_storage.Nearly_inf_Imperatif.t;
+  c_signatures: (agent_sig * position) Int_storage.Nearly_inf_Imperatif.t;
   (*agent signature declaration*)
   c_rules: enriched_rule Int_storage.Nearly_inf_Imperatif.t;
   (*rules (possibly named)*)
diff --git a/core/KaSa_rep/frontend/list_tokens.ml b/core/KaSa_rep/frontend/list_tokens.ml
index bb0614bb6..077dc6e60 100644
--- a/core/KaSa_rep/frontend/list_tokens.ml
+++ b/core/KaSa_rep/frontend/list_tokens.ml
@@ -285,7 +285,7 @@ let declare_dual parameter error handler ag site state ag' site' state' =
   in
   error, { handler with Cckappa_sig.dual }
 
-let scan_agent parameters (error, handler) agent =
+let scan_agent ~get_counter_name parameters (error, handler) agent =
   let error, (handler, ag_id) =
     declare_agent parameters error handler agent.Ckappa_sig.agent_name
       (Some agent.Ckappa_sig.agent_name_pos)
@@ -296,7 +296,7 @@ let scan_agent parameters (error, handler) agent =
     | Ckappa_sig.COUNTER_SEP (counter, interface) ->
       let error, (handler, _, _c) =
         declare_site_with_counter parameters (error, handler) ag_id
-          counter.Ckappa_sig.counter_name
+          (get_counter_name counter)
       in
       aux error interface handler
     | Ckappa_sig.PORT_SEP (port, interface) ->
@@ -366,6 +366,11 @@ let scan_agent parameters (error, handler) agent =
   in
   aux error agent.Ckappa_sig.ag_intf handler
 
+let get_counter_name c = c.Ckappa_sig.counter_name
+let get_counter_name_sig c = c.Ckappa_sig.counter_sig_name
+let scan_agent_sig = scan_agent ~get_counter_name:get_counter_name_sig
+let scan_agent = scan_agent ~get_counter_name
+
 let rec scan_mixture parameters remanent mixture =
   match mixture with
   | Ckappa_sig.EMPTY_MIX -> remanent
@@ -401,7 +406,7 @@ let scan_initial_states parameters =
         List.fold_left (scan_token parameters) remanent tk_l)
 
 let scan_declarations parameters =
-  List.fold_left (fun remanent a -> scan_agent parameters remanent a)
+  List.fold_left (fun remanent a -> scan_agent_sig parameters remanent a)
 
 let scan_observables _scan_mixt _parameters remanent _variable =
   (*TODO*)
@@ -474,7 +479,10 @@ let scan_compil parameters error compil =
     remanent
   in
   let remanent = empty_handler parameters error in
-  let remanent = scan_declarations parameters remanent compil.Ast.signatures in
+  let remanent =
+    scan_declarations parameters remanent
+      (compil.Ast.signatures : Ckappa_sig.agent_sig list)
+  in
   let remanent = scan_initial_states parameters remanent compil.Ast.init in
   let remanent =
     scan_observables scan_tested_mixture parameters remanent
diff --git a/core/KaSa_rep/frontend/list_tokens.mli b/core/KaSa_rep/frontend/list_tokens.mli
index e2e4c846a..465988543 100644
--- a/core/KaSa_rep/frontend/list_tokens.mli
+++ b/core/KaSa_rep/frontend/list_tokens.mli
@@ -6,6 +6,7 @@ val scan_compil :
   Remanent_parameters_sig.parameters ->
   Exception_without_parameter.method_handler ->
   ( Ckappa_sig.agent,
+    Ckappa_sig.agent_sig,
     Ckappa_sig.mixture,
     Ckappa_sig.mixture,
     'a,
diff --git a/core/KaSa_rep/frontend/prepreprocess.ml b/core/KaSa_rep/frontend/prepreprocess.ml
index 98c968132..5ef29e880 100644
--- a/core/KaSa_rep/frontend/prepreprocess.ml
+++ b/core/KaSa_rep/frontend/prepreprocess.ml
@@ -109,24 +109,26 @@ let pop_entry parameters error id (map, set) =
     | None -> Exception.warn parameters error __POS__ Exit (None, map)
   )
 
-let rec scan_interface parameters k agent interface
+let get_counter_name counter = fst counter.Ast.counter_name
+let get_counter_name_sig counter = fst counter.Ast.counter_sig_name
+
+let rec scan_interface ~get_counter_name parameters k agent interface
     (((error, a), (set_sites, set_counters)) as remanent) =
   match interface with
   | [] -> remanent
   | Ast.Counter counter :: interface ->
     let error, set_counters =
-      check_freshness parameters error "Counter"
-        (fst counter.Ast.counter_name)
+      check_freshness parameters error "Counter" (get_counter_name counter)
         set_counters
     in
-    scan_interface parameters k agent interface
+    scan_interface ~get_counter_name parameters k agent interface
       ((error, a), (set_sites, set_counters))
   | Ast.Port port :: interface ->
     let error, set_sites =
       check_freshness parameters error "Site" (fst port.Ast.port_name) set_sites
     in
     let remanent = error, a in
-    scan_interface parameters k agent interface
+    scan_interface ~get_counter_name parameters k agent interface
       ( (match port.Ast.port_link with
         | [ (LKappa.LNK_VALUE (i, ()), _) ] ->
           add_entry_link parameters
@@ -141,14 +143,17 @@ let rec scan_interface parameters k agent interface
           remanent),
         (set_sites, set_counters) )
 
-let scan_agent parameters k ag remanent =
+let scan_agent ~get_counter_name parameters k ag remanent =
   match ag with
   | Ast.Absent _ -> remanent
   | Ast.Present ((name, _), intf, _modif) ->
     fst
-      (scan_interface parameters k name intf
+      (scan_interface ~get_counter_name parameters k name intf
          (remanent, (Mods.StringSet.empty, Mods.StringSet.empty)))
 
+let scan_agent_sig = scan_agent ~get_counter_name:get_counter_name_sig
+let scan_agent = scan_agent ~get_counter_name
+
 let rec collect_binding_label parameters mixture f k remanent =
   match mixture with
   | agent :: mixture (*| Ast.DOT (_,agent,mixture) | Ast.PLUS(_,agent,mixture)*)
@@ -282,8 +287,28 @@ let translate_counter parameters error int_set counter =
            Some a);
     } )
 
-let rec translate_interface parameters is_signature int_set_sites
-    int_set_counters interface remanent =
+let translate_counter_sig parameters error int_set (counter : Ast.counter_sig) =
+  let error, _ =
+    check_freshness parameters error "Counters"
+      (fst counter.Ast.counter_sig_name)
+      int_set
+  in
+  let fetch x =
+    match x with
+    | Some (x, _) -> Some x
+    | None -> None
+  in
+  ( error,
+    {
+      Ckappa_sig.counter_sig_name = fst counter.Ast.counter_sig_name;
+      Ckappa_sig.counter_sig_max = fetch counter.Ast.counter_sig_max;
+      Ckappa_sig.counter_sig_min = fetch counter.Ast.counter_sig_min;
+      Ckappa_sig.counter_sig_default = counter.Ast.counter_sig_default;
+      Ckappa_sig.counter_visible = counter.Ast.counter_sig_visible;
+    } )
+
+let rec translate_interface ~translate_counter parameters is_signature
+    int_set_sites int_set_counters interface remanent =
   match interface with
   | [] -> Ckappa_sig.EMPTY_INTF, remanent
   | Ast.Counter counter :: interface ->
@@ -292,8 +317,8 @@ let rec translate_interface parameters is_signature int_set_sites
       translate_counter parameters error int_set_counters counter
     in
     let interface, remanent =
-      translate_interface parameters is_signature int_set_sites int_set_counters
-        interface (error, a)
+      translate_interface ~translate_counter parameters is_signature
+        int_set_sites int_set_counters interface (error, a)
     in
     Ckappa_sig.COUNTER_SEP (counter, interface), remanent
   | Ast.Port port :: interface ->
@@ -301,21 +326,22 @@ let rec translate_interface parameters is_signature int_set_sites
       translate_port is_signature parameters int_set_sites port remanent
     in
     let interface, remanent =
-      translate_interface parameters is_signature int_set_sites int_set_counters
-        interface remanent
+      translate_interface ~translate_counter parameters is_signature
+        int_set_sites int_set_counters interface remanent
     in
     Ckappa_sig.PORT_SEP (port, interface), remanent
 
-let translate_interface parameters is_signature =
-  translate_interface parameters is_signature Mods.StringSet.empty
-    Mods.StringSet.empty
+let translate_interface ~translate_counter parameters is_signature =
+  translate_interface ~translate_counter parameters is_signature
+    Mods.StringSet.empty Mods.StringSet.empty
 
-let translate_agent parameters is_signature ag remanent =
+let translate_agent ~translate_counter parameters is_signature ag remanent =
   match ag with
   | Ast.Absent _pos -> None, remanent
   | Ast.Present ((agent_name, agent_name_pos), intf, _modif) ->
     let interface, remanent =
-      translate_interface parameters is_signature intf remanent
+      translate_interface ~translate_counter parameters is_signature intf
+        remanent
     in
     ( Some
         {
@@ -340,7 +366,9 @@ let rec translate_mixture_zero_zero parameters mixture remanent tail_size =
   match mixture with
   | [] -> build_skip tail_size Ckappa_sig.EMPTY_MIX, remanent
   | agent :: mixture ->
-    let agent_opt, remanent = translate_agent parameters false agent remanent in
+    let agent_opt, remanent =
+      translate_agent ~translate_counter parameters false agent remanent
+    in
     let mixture, remanent =
       translate_mixture_zero_zero parameters mixture remanent tail_size
     in
@@ -358,7 +386,7 @@ let rec translate_mixture_in_rule parameters mixture remanent prefix_size
     | [] -> Ckappa_sig.EMPTY_MIX, remanent
     | agent :: mixture ->
       let agent_opt, remanent =
-        translate_agent parameters false agent remanent
+        translate_agent ~translate_counter parameters false agent remanent
       in
       let mixture, remanent =
         translate_mixture_in_rule parameters mixture remanent (prefix_size - 1)
@@ -367,12 +395,16 @@ let rec translate_mixture_in_rule parameters mixture remanent prefix_size
       add_agent agent_opt mixture remanent
   )
 
-let rec translate_mixture parameters mixture remanent =
+let rec translate_mixture ~translate_counter parameters mixture remanent =
   match mixture with
   | [] -> Ckappa_sig.EMPTY_MIX, remanent
   | agent :: mixture ->
-    let agent_opt, remanent = translate_agent parameters false agent remanent in
-    let mixture, remanent = translate_mixture parameters mixture remanent in
+    let agent_opt, remanent =
+      translate_agent ~translate_counter parameters false agent remanent
+    in
+    let mixture, remanent =
+      translate_mixture ~translate_counter parameters mixture remanent
+    in
     add_agent agent_opt mixture remanent
 
 let support_agent = function
@@ -440,7 +472,8 @@ let refine_mixture_in_rule parameters error prefix_size empty_size tail_size
   in
   error, mixture
 
-let refine_mixture parameters error mixture =
+let refine_mixture ~collect_binding_label ~translate_counter parameters error
+    (mixture : Ast.agent list list) =
   let mixture = List.flatten mixture in
   let remanent =
     collect_binding_label parameters mixture
@@ -448,9 +481,14 @@ let refine_mixture parameters error mixture =
       Ckappa_sig.dummy_agent_id
       (error, Ckappa_sig.Lnk_id_map_and_set.Map.empty)
   in
-  let mixture, (error, _map) = translate_mixture parameters mixture remanent in
+  let mixture, (error, _map) =
+    translate_mixture ~translate_counter parameters mixture remanent
+  in
   error, mixture
 
+(*let refine_mixture_sig = refine_mixture ~collect_binding_label:collect_binding_label_sig ~translate_counter:translate_counter_sig*)
+let refine_mixture = refine_mixture ~collect_binding_label ~translate_counter
+
 let rec alg_map f error alg =
   match alg with
   | Alg_expr.BIN_ALG_OP (op, (m1, pos1), (m2, pos2)) ->
@@ -655,7 +693,7 @@ let refine_init_t parameters error = function
     in
     error, Ast.INIT_TOK tk_l'
 
-let refine_agent parameters error agent_set agent =
+let refine_agent_sig parameters error agent_set agent =
   let error, agent_set =
     match agent with
     | Ast.Absent _ -> error, agent_set
@@ -663,12 +701,13 @@ let refine_agent parameters error agent_set agent =
       check_freshness parameters error "Agent" name agent_set
   in
   let error, map =
-    scan_agent parameters Ckappa_sig.dummy_agent_id agent
+    scan_agent_sig parameters Ckappa_sig.dummy_agent_id agent
       (error, Ckappa_sig.Lnk_id_map_and_set.Map.empty)
   in
 
   let agent, (error, _map) =
-    translate_agent parameters true agent
+    translate_agent ~translate_counter:translate_counter_sig parameters true
+      agent
       (error, (map, Ckappa_sig.Lnk_id_map_and_set.Set.empty))
   in
   error, agent_set, agent
@@ -699,7 +738,15 @@ let dump_rule_no_rate rule =
   let () = Format.pp_print_flush fmt () in
   Buffer.contents buf
 
-let translate_compil parameters error compil =
+let translate_compil parameters error
+    (compil :
+      ( Ast.agent,
+        Ast.agent_sig,
+        Ast.mixture,
+        Ast.agent list list,
+        string,
+        Ast.rule )
+      Ast.compil) =
   let translate_rule error (rule, pos) =
     let (ast_lhs, ast_rhs), (prefix, tail_lhs, tail_rhs) =
       match rule.Ast.rewrite with
@@ -770,8 +817,11 @@ let translate_compil parameters error compil =
   let error, _agent_set, signatures_rev =
     List.fold_left
       (fun (error, agent_set, list) agent ->
-        let error, agent_set, agent =
-          refine_agent parameters error agent_set agent
+        let ( error,
+              agent_set,
+              (agent :
+                Ckappa_sig.counter_sig Ckappa_sig.parametric_agent option) ) =
+          refine_agent_sig parameters error agent_set agent
         in
         match agent with
         | None ->
diff --git a/core/KaSa_rep/frontend/prepreprocess.mli b/core/KaSa_rep/frontend/prepreprocess.mli
index 175261cff..284d8c7b2 100644
--- a/core/KaSa_rep/frontend/prepreprocess.mli
+++ b/core/KaSa_rep/frontend/prepreprocess.mli
@@ -3,9 +3,16 @@ val local_trace : bool
 val translate_compil :
   Remanent_parameters_sig.parameters ->
   Exception_without_parameter.method_handler ->
-  (Ast.agent, Ast.mixture, Ast.agent list list, string, Ast.rule) Ast.compil ->
+  ( Ast.agent,
+    Ast.agent_sig,
+    Ast.mixture,
+    Ast.agent list list,
+    string,
+    Ast.rule )
+  Ast.compil ->
   Exception_without_parameter.method_handler
   * ( Ckappa_sig.agent,
+      Ckappa_sig.agent_sig,
       Ckappa_sig.mixture,
       Ckappa_sig.mixture,
       string,
diff --git a/core/KaSa_rep/frontend/preprocess.ml b/core/KaSa_rep/frontend/preprocess.ml
index 944158123..5a2987e09 100644
--- a/core/KaSa_rep/frontend/preprocess.ml
+++ b/core/KaSa_rep/frontend/preprocess.ml
@@ -185,7 +185,7 @@ let translate_agent_sig parameters error handler agent
         let error, (bool, output) =
           Ckappa_sig.Dictionary_of_sites.allocate_bool parameters error
             Ckappa_sig.compare_unit_site_name
-            (Ckappa_sig.Counter counter.Ckappa_sig.counter_name) ()
+            (Ckappa_sig.Counter counter.Ckappa_sig.counter_sig_name) ()
             Misc_sa.const_unit site_dic
         in
         let error, counter_name =
@@ -194,19 +194,16 @@ let translate_agent_sig parameters error handler agent
             Exception.warn parameters error __POS__
               ~message:
                 (agent.Ckappa_sig.agent_name ^ " "
-               ^ counter.Ckappa_sig.counter_name)
+               ^ counter.Ckappa_sig.counter_sig_name)
               Exit Ckappa_sig.dummy_site_name
           | _, Some (i, _, _, _) -> error, i
         in
         let (error', c_interface), test =
           let test =
-            match counter.Ckappa_sig.counter_test with
-            | Some (Ckappa_sig.CEQ i) -> [ Ckappa_sig.state_index_of_int i ]
-            | Some (Ckappa_sig.CGTE _)
-            | Some (Ckappa_sig.CVAR _)
-            | Some Ckappa_sig.UNKNOWN
-            | None ->
-              []
+            [
+              Ckappa_sig.state_index_of_int
+                counter.Ckappa_sig.counter_sig_default;
+            ]
           in
           ( Ckappa_sig.Site_map_and_set.Map.add parameters error counter_name
               {
@@ -2221,12 +2218,13 @@ let translate_c_compil parameters error handler compil =
     List.fold_left
       (fun (error, list, map) agent ->
         let error, ag, map =
-          translate_agent_sig parameters error handler agent
+          translate_agent_sig parameters error handler
+            (agent : Ckappa_sig.agent_sig)
             Ckappa_sig.dummy_agent_id map
         in
         error, ag :: list, map)
       (error, [], Ckappa_sig.AgentSite_map_and_set.Map.empty)
-      compil.Ast.signatures
+      (compil.Ast.signatures : Ckappa_sig.agent_sig list)
   in
   let error, c_variables =
     List.fold_left
diff --git a/core/KaSa_rep/frontend/preprocess.mli b/core/KaSa_rep/frontend/preprocess.mli
index 8c72b6b86..4ae01f812 100644
--- a/core/KaSa_rep/frontend/preprocess.mli
+++ b/core/KaSa_rep/frontend/preprocess.mli
@@ -103,6 +103,7 @@ val translate_c_compil :
   Exception_without_parameter.method_handler ->
   Cckappa_sig.kappa_handler ->
   ( Ckappa_sig.agent,
+    Ckappa_sig.agent_sig,
     Ckappa_sig.mixture,
     Ckappa_sig.mixture,
     string,
diff --git a/core/KaSa_rep/remanent_state/remanent_state.ml b/core/KaSa_rep/remanent_state/remanent_state.ml
index be95f6286..b496d840a 100644
--- a/core/KaSa_rep/remanent_state/remanent_state.ml
+++ b/core/KaSa_rep/remanent_state/remanent_state.ml
@@ -21,6 +21,7 @@ type initial_state = (Primitives.alg_expr * Primitives.elementary_rule) list
 
 type refined_compilation =
   ( Ckappa_sig.agent,
+    Ckappa_sig.agent_sig,
     Ckappa_sig.mixture,
     Ckappa_sig.mixture,
     string,
diff --git a/core/KaSa_rep/remanent_state/remanent_state.mli b/core/KaSa_rep/remanent_state/remanent_state.mli
index 3ede63057..5ca251fef 100644
--- a/core/KaSa_rep/remanent_state/remanent_state.mli
+++ b/core/KaSa_rep/remanent_state/remanent_state.mli
@@ -43,6 +43,7 @@ type separating_transitions = Public_data.separating_transitions
 
 type refined_compilation =
   ( Ckappa_sig.agent,
+    Ckappa_sig.agent_sig,
     Ckappa_sig.mixture,
     Ckappa_sig.mixture,
     string,
diff --git a/core/cli/cli_init.ml b/core/cli/cli_init.ml
index d22d53fdf..b1d190dfe 100644
--- a/core/cli/cli_init.ml
+++ b/core/cli/cli_init.ml
@@ -30,7 +30,7 @@ type compilation_result = {
 }
 
 let preprocess_ast ~warning ~debug_mode ?kasim_args cli_args
-    (ast : (_, _, _, _, _) Ast.compil) : preprocessed_ast =
+    (ast : (_, _, _, _, _, _) Ast.compil) : preprocessed_ast =
   let () = Format.printf "+ simulation parameters@." in
   let conf, story_compression, formatCflow, cflowFile =
     Configuration.parse ast.Ast.configurations
@@ -89,7 +89,14 @@ let get_ast_from_cli_args cli_args =
 
 let get_preprocessed_ast_from_cli_args ~warning ~debug_mode
     ?(kasim_args = Kasim_args.default) cli_args =
-  let ast : (Ast.agent, Ast.mixture, Ast.mixture, string, Ast.rule) Ast.compil =
+  let ast :
+      ( Ast.agent,
+        Ast.agent_sig,
+        Ast.mixture,
+        Ast.mixture,
+        string,
+        Ast.rule )
+      Ast.compil =
     get_ast_from_list_of_files cli_args.Run_cli_args.syntaxVersion
       cli_args.Run_cli_args.inputKappaFileNames
   in
diff --git a/core/grammar/ast.ml b/core/grammar/ast.ml
index 221d0e191..5c4606c65 100644
--- a/core/grammar/ast.ml
+++ b/core/grammar/ast.ml
@@ -38,13 +38,62 @@ type counter = {
 }
 (** Counter syntax from AST, present in 3 contexts with different meanings: agent definition, species init declaration, rule *)
 
-type site = Port of port | Counter of counter
+type counter_sig = {
+  counter_sig_name: string Loc.annoted;
+  counter_sig_min: int option Loc.annoted option;
+  counter_sig_max: int option Loc.annoted option;
+  counter_sig_visible: bool;
+  counter_sig_default: int;
+}
+
+let counter_sig_of_counter (c : counter) : counter_sig =
+  let (counter_sig_min, counter_sig_default) : (int option * Loc.t) option * int
+      =
+    match c.counter_test with
+    | Some (CEQ i, loc) -> Some (Some i, loc), i
+    | None | Some ((CGTE _ | CLTE _ | CVAR _), _) -> None, 0
+  in
+  let counter_sig_max =
+    match c.counter_delta with
+    | i, loc -> Some (Some i, loc)
+  in
+  {
+    counter_sig_name = c.counter_name;
+    counter_sig_min;
+    counter_sig_max;
+    counter_sig_default;
+    counter_sig_visible = true;
+  }
+
+let make_inverted_counter_sig (counter : counter_sig)
+    (counter_sig_name : string Loc.annoted) : counter_sig =
+  {
+    counter with
+    counter_sig_name;
+    counter_sig_visible = false;
+    counter_sig_default =
+      (match counter.counter_sig_max, counter.counter_sig_min with
+      | Some (Some max, _), Some (Some min, _) ->
+        max - counter.counter_sig_default + min
+      | (None | Some (None, _)), _ | _, (None | Some (None, _)) ->
+        failwith "unbounded counters not implemented yet");
+  }
+
+type 'counter site = Port of port | Counter of 'counter
+
+let map_counters_in_site f = function
+  | Port _ as x -> x
+  | Counter co -> Counter (f co)
+
 type agent_mod = NoMod | Erase | Create
 
-type agent =
-  | Present of string Loc.annoted * site list * agent_mod
+type 'counter parametric_agent =
+  | Present of string Loc.annoted * 'counter site list * agent_mod
   | Absent of Loc.t
 
+type agent = counter parametric_agent
+type agent_sig = counter_sig parametric_agent
+
 (* TODO: document why list list *)
 type mixture = agent list list
 
@@ -124,8 +173,8 @@ type ('pattern, 'mixture, 'id) init_statement =
   (*  string Loc.annoted option * (*volume*)*)
   ('pattern, 'id) Alg_expr.e Loc.annoted * ('mixture, 'id) init_t
 
-type ('agent, 'pattern, 'mixture, 'id, 'rule) instruction =
-  | SIG of 'agent
+type ('agent, 'agent_id, 'pattern, 'mixture, 'id, 'rule) instruction =
+  | SIG of 'agent_id
   | TOKENSIG of string Loc.annoted
   | VOLSIG of string * float * string (* type, volume, parameter*)
   | INIT of ('pattern, 'mixture, 'id) init_statement
@@ -142,12 +191,12 @@ type ('pattern, 'mixture, 'id, 'rule) command =
   | MODIFY of ('pattern, 'mixture, 'id, 'rule) modif_expr list
   | QUIT
 
-type ('agent, 'pattern, 'mixture, 'id, 'rule) compil = {
+type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) compil = {
   filenames: string list;
   variables: ('pattern, 'id) variable_def list;
       (** pattern declaration for reusing as variable in perturbations
     or kinetic rate *)
-  signatures: 'agent list;  (** agent signature declaration *)
+  signatures: 'agent_sig list;  (** agent signature declaration *)
   rules: (string Loc.annoted option * 'rule Loc.annoted) list;
       (** rules (possibly named): [name_option * rule_definition] *)
   observables: ('pattern, 'id) Alg_expr.e Loc.annoted list;
@@ -160,8 +209,10 @@ type ('agent, 'pattern, 'mixture, 'id, 'rule) compil = {
   volumes: (string * float * string) list;
 }
 
-type parsing_compil = (agent, mixture, mixture, string, rule) compil
-type parsing_instruction = (agent, mixture, mixture, string, rule) instruction
+type parsing_compil = (agent, agent_sig, mixture, mixture, string, rule) compil
+
+type parsing_instruction =
+  (agent, agent_sig, mixture, mixture, string, rule) instruction
 
 let no_more_site_on_right error left right =
   List.for_all
@@ -252,6 +303,21 @@ let print_counter_test f = function
   | CLTE x, _ -> Format.fprintf f "<=%i" x
   | CVAR x, _ -> Format.fprintf f "=%s" x
 
+let print_counter_min f (x, _) =
+  match x with
+  | Some x -> Format.fprintf f "=%d" x
+  | None -> Format.fprintf f "=-oo"
+
+let print_counter_max f (x, _) =
+  match x with
+  | Some x -> Format.fprintf f "/%d" x
+  | None -> Format.fprintf f "/+oo"
+
+let print_counter_default min f x =
+  match min with
+  | Some (Some i, _) when i = x -> ()
+  | None | Some _ -> Format.fprintf f "(%d)" x
+
 let print_counter_delta test f (delta, _) =
   if delta <> 0 then
     Format.fprintf f "%a+=%d"
@@ -265,7 +331,16 @@ let print_counter f c =
     (print_counter_delta c.counter_test)
     c.counter_delta
 
-let print_ast_site f = function
+let print_counter_sig f c =
+  Format.fprintf f "%s{%a%a}%a" (fst c.counter_sig_name)
+    (Pp.option ~with_space:false print_counter_min)
+    c.counter_sig_min
+    (Pp.option ~with_space:false print_counter_max)
+    c.counter_sig_max
+    (print_counter_default c.counter_sig_min)
+    c.counter_sig_default
+
+let print_ast_site ~print_counter f = function
   | Port p -> print_ast_port f p
   | Counter c -> print_counter f c
 
@@ -396,6 +471,208 @@ let build_port_of_json filenames n i l =
       port_link_mod;
     }
 
+let site_sig_of_json filenames = function
+  | `Assoc
+      [
+        ("counter_sig_name", n);
+        ("counter_min", min);
+        ("counter_max", max);
+        ("counter_default", default);
+      ]
+  | `Assoc
+      [
+        ("counter_sig_name", n);
+        ("counter_min", min);
+        ("counter_default", default);
+        ("counter_max", max);
+      ]
+  | `Assoc
+      [
+        ("counter_sig_name", n);
+        ("counter_max", max);
+        ("counter_default", default);
+        ("counter_min", min);
+      ]
+  | `Assoc
+      [
+        ("counter_sig_name", n);
+        ("counter_max", max);
+        ("counter_min", min);
+        ("counter_default", default);
+      ]
+  | `Assoc
+      [
+        ("counter_sig_name", n);
+        ("counter_default", default);
+        ("counter_min", min);
+        ("counter_max", max);
+      ]
+  | `Assoc
+      [
+        ("counter_sig_name", n);
+        ("counter_default", default);
+        ("counter_max", max);
+        ("counter_min", min);
+      ]
+  | `Assoc
+      [
+        ("counter_min", min);
+        ("counter_sig_name", n);
+        ("counter_default", default);
+        ("counter_max", max);
+      ]
+  | `Assoc
+      [
+        ("counter_min", min);
+        ("counter_sig_name", n);
+        ("counter_max", max);
+        ("counter_default", default);
+      ]
+  | `Assoc
+      [
+        ("counter_min", min);
+        ("counter_max", max);
+        ("counter_default", default);
+        ("counter_sig_name", n);
+      ]
+  | `Assoc
+      [
+        ("counter_min", min);
+        ("counter_max", max);
+        ("counter_sig_name", n);
+        ("counter_default", default);
+      ]
+  | `Assoc
+      [
+        ("counter_min", min);
+        ("counter_default", default);
+        ("counter_max", max);
+        ("counter_sig_name", n);
+      ]
+  | `Assoc
+      [
+        ("counter_min", min);
+        ("counter_default", default);
+        ("counter_sig_name", n);
+        ("counter_max", max);
+      ]
+  | `Assoc
+      [
+        ("counter_max", max);
+        ("counter_sig_name", n);
+        ("counter_min", min);
+        ("counter_default", default);
+      ]
+  | `Assoc
+      [
+        ("counter_max", max);
+        ("counter_sig_name", n);
+        ("counter_default", default);
+        ("counter_min", min);
+      ]
+  | `Assoc
+      [
+        ("counter_max", max);
+        ("counter_min", min);
+        ("counter_sig_name", n);
+        ("counter_default", default);
+      ]
+  | `Assoc
+      [
+        ("counter_max", max);
+        ("counter_min", min);
+        ("counter_default", default);
+        ("counter_sig_name", n);
+      ]
+  | `Assoc
+      [
+        ("counter_max", max);
+        ("counter_default", default);
+        ("counter_min", min);
+        ("counter_sig_name", n);
+      ]
+  | `Assoc
+      [
+        ("counter_max", max);
+        ("counter_default", default);
+        ("counter_sig_name", n);
+        ("counter_min", min);
+      ]
+  | `Assoc
+      [
+        ("counter_default", default);
+        ("counter_max", max);
+        ("counter_sig_name", n);
+        ("counter_min", min);
+      ]
+  | `Assoc
+      [
+        ("counter_default", default);
+        ("counter_max", max);
+        ("counter_min", min);
+        ("counter_sig_name", n);
+      ]
+  | `Assoc
+      [
+        ("counter_default", default);
+        ("counter_min", min);
+        ("counter_sig_name", n);
+        ("counter_max", max);
+      ]
+  | `Assoc
+      [
+        ("counter_default", default);
+        ("counter_min", min);
+        ("counter_max", max);
+        ("counter_sig_name", n);
+      ]
+  | `Assoc
+      [
+        ("counter_default", default);
+        ("counter_sig_name", n);
+        ("counter_min", min);
+        ("counter_max", max);
+      ]
+  | `Assoc
+      [
+        ("counter_default", default);
+        ("counter_sig_name", n);
+        ("counter_max", max);
+        ("counter_min", min);
+      ] ->
+    Counter
+      {
+        counter_sig_name =
+          Loc.annoted_of_yojson ~filenames Yojson.Basic.Util.to_string n;
+        counter_sig_min =
+          Yojson.Basic.Util.to_option
+            (Loc.annoted_of_yojson ~filenames
+               (Yojson.Basic.Util.to_option Yojson.Basic.Util.to_int))
+            min;
+        counter_sig_max =
+          Yojson.Basic.Util.to_option
+            (Loc.annoted_of_yojson ~filenames
+               (Yojson.Basic.Util.to_option Yojson.Basic.Util.to_int))
+            max;
+        counter_sig_default = Yojson.Basic.Util.to_int default;
+        counter_sig_visible = true;
+      }
+  | `Assoc [ ("port_name", n); ("port_int", i); ("port_link", l) ]
+  | `Assoc [ ("port_name", n); ("port_link", l); ("port_int", i) ]
+  | `Assoc [ ("port_int", i); ("port_name", n); ("port_link", l) ]
+  | `Assoc [ ("port_link", l); ("port_name", n); ("port_int", i) ]
+  | `Assoc [ ("port_int", i); ("port_link", l); ("port_name", n) ]
+  | `Assoc [ ("port_link", l); ("port_int", i); ("port_name", n) ] ->
+    build_port_of_json filenames n i l
+  | `Assoc [ ("port_name", n); ("port_int", i) ]
+  | `Assoc [ ("port_int", i); ("port_name", n) ] ->
+    build_port_of_json filenames n i `Null
+  | `Assoc [ ("port_name", n); ("port_link", l) ]
+  | `Assoc [ ("port_link", l); ("port_name", n) ] ->
+    build_port_of_json filenames n `Null l
+  | `Assoc [ ("port_name", n) ] -> build_port_of_json filenames n `Null `Null
+  | x -> raise (Yojson.Basic.Util.Type_error ("Not an AST agent", x))
+
 let site_of_json filenames = function
   | `Assoc [ ("counter_name", n); ("counter_test", t); ("counter_delta", d) ]
   | `Assoc [ ("counter_name", n); ("counter_delta", d); ("counter_test", t) ]
@@ -430,31 +707,51 @@ let site_of_json filenames = function
   | `Assoc [ ("port_name", n) ] -> build_port_of_json filenames n `Null `Null
   | x -> raise (Yojson.Basic.Util.Type_error ("Not an AST agent", x))
 
-let site_to_json filenames = function
+let counter_to_json ~filenames c =
+  `Assoc
+    [
+      ( "counter_name",
+        Loc.yojson_of_annoted ~filenames JsonUtil.of_string c.counter_name );
+      ( "counter_test",
+        JsonUtil.of_option
+          (Loc.yojson_of_annoted ~filenames counter_test_to_json)
+          c.counter_test );
+      ( "counter_delta",
+        Loc.yojson_of_annoted ~filenames JsonUtil.of_int c.counter_delta );
+    ]
+
+let counter_sig_to_json ~filenames c =
+  `Assoc
+    [
+      ( "counter_sig_name",
+        Loc.yojson_of_annoted ~filenames JsonUtil.of_string c.counter_sig_name );
+      ( "counter_min",
+        JsonUtil.of_option
+          (Loc.yojson_of_annoted ~filenames
+             (JsonUtil.of_option JsonUtil.of_int))
+          c.counter_sig_min );
+      ( "counter_max",
+        JsonUtil.of_option
+          (Loc.yojson_of_annoted ~filenames
+             (JsonUtil.of_option JsonUtil.of_int))
+          c.counter_sig_max );
+      "counter_default", JsonUtil.of_int c.counter_sig_default;
+    ]
+
+let site_to_json ~counter_to_json filenames = function
   | Port p -> port_to_json filenames p
-  | Counter c ->
-    `Assoc
-      [
-        ( "counter_name",
-          Loc.yojson_of_annoted ~filenames JsonUtil.of_string c.counter_name );
-        ( "counter_test",
-          JsonUtil.of_option
-            (Loc.yojson_of_annoted ~filenames counter_test_to_json)
-            c.counter_test );
-        ( "counter_delta",
-          Loc.yojson_of_annoted ~filenames JsonUtil.of_int c.counter_delta );
-      ]
+  | Counter c -> counter_to_json ~filenames c
 
 let print_agent_mod f = function
   | Create -> Format.pp_print_string f "+"
   | Erase -> Format.pp_print_string f "-"
   | NoMod -> Format.pp_print_string f ""
 
-let print_ast_agent f = function
+let print_ast_agent ~print_counter f = function
   | Absent _ -> Format.pp_print_string f "."
   | Present ((agent_name, _), l, m) ->
     Format.fprintf f "%s(%a)%a" agent_name
-      (Pp.list (fun f -> Format.fprintf f " ") print_ast_site)
+      (Pp.list (fun f -> Format.fprintf f " ") (print_ast_site ~print_counter))
       l print_agent_mod m
 
 let agent_mod_to_yojson = function
@@ -469,17 +766,20 @@ let agent_mod_of_yojson = function
   | x ->
     raise (Yojson.Basic.Util.Type_error ("Incorrect agent modification", x))
 
-let agent_to_json filenames = function
+let agent_to_json ~counter_to_json ~filter filenames = function
   | Absent _ -> `Null
   | Present (na, l, m) ->
     JsonUtil.smart_assoc
       [
         "name", Loc.yojson_of_annoted ~filenames JsonUtil.of_string na;
-        "sig", JsonUtil.of_list (site_to_json filenames) l;
+        ( "sig",
+          JsonUtil.of_list
+            (site_to_json ~counter_to_json filenames)
+            (List.filter filter l) );
         "mod", agent_mod_to_yojson m;
       ]
 
-let agent_of_json filenames = function
+let agent_of_json ~site_of_json filenames = function
   | `Null -> Absent Loc.dummy
   | `Assoc [ ("name", n); ("sig", s); ("mod", m) ]
   | `Assoc [ ("sig", s); ("name", n); ("mod", m) ]
@@ -508,8 +808,21 @@ let agent_of_json filenames = function
         NoMod )
   | x -> raise (Yojson.Basic.Util.Type_error ("Not an AST agent", x))
 
-let print_ast_mix =
-  Pp.list (fun f -> Format.fprintf f "\\@ ") (Pp.list Pp.comma print_ast_agent)
+let agent_sig_of_json = agent_of_json ~site_of_json:site_sig_of_json
+
+let agent_sig_to_json =
+  agent_to_json ~counter_to_json:counter_sig_to_json ~filter:(fun c ->
+      match c with
+      | Counter c -> c.counter_sig_visible
+      | Port _ -> true)
+
+let agent_of_json = agent_of_json ~site_of_json
+let agent_to_json = agent_to_json ~counter_to_json ~filter:(fun _ -> true)
+
+let print_ast_mix ~print_counter =
+  Pp.list
+    (fun f -> Format.fprintf f "\\@ ")
+    (Pp.list Pp.comma (print_ast_agent ~print_counter))
 
 let to_erased_mixture =
   List.map
@@ -675,7 +988,9 @@ let print_tok pr_mix pr_tok pr_var f ((nb, _), (n, _)) =
   Format.fprintf f "%a %a" (Alg_expr.print pr_mix pr_tok pr_var) nb pr_tok n
 
 let print_one_size tk f mix =
-  Format.fprintf f "%a%t%a" print_ast_mix mix
+  Format.fprintf f "%a%t%a"
+    (print_ast_mix ~print_counter)
+    mix
     (fun f ->
       match tk with
       | [] -> ()
@@ -683,7 +998,7 @@ let print_one_size tk f mix =
     (Pp.list
        (fun f -> Format.pp_print_string f " + ")
        (print_tok
-          (fun f m -> Format.fprintf f "|%a|" print_ast_mix m)
+          (fun f m -> Format.fprintf f "|%a|" (print_ast_mix ~print_counter) m)
           Format.pp_print_string
           (fun f x -> Format.fprintf f "'%s'" x)))
     tk
@@ -704,14 +1019,14 @@ let print_raw_rate pr_mix pr_tok pr_var op f (def, _) =
 
 let print_ast_alg_expr =
   Alg_expr.print
-    (fun f m -> Format.fprintf f "|%a|" print_ast_mix m)
+    (fun f m -> Format.fprintf f "|%a|" (print_ast_mix ~print_counter) m)
     Format.pp_print_string
     (fun f x -> Format.fprintf f "'%s'" x)
 
 let print_rates_one_dir un f def =
   Format.fprintf f "%a%t"
     (print_raw_rate
-       (fun f m -> Format.fprintf f "|%a|" print_ast_mix m)
+       (fun f m -> Format.fprintf f "|%a|" (print_ast_mix ~print_counter) m)
        Format.pp_print_string
        (fun f x -> Format.fprintf f "'%s'" x)
        None)
@@ -754,7 +1069,8 @@ let print_configuration f ((n, _), l) =
 let print_init f = function
   | (n, _), INIT_MIX (m, _) ->
     Format.fprintf f "@[%%init: @[%a@]@ @[%a@]@]" print_ast_alg_expr n
-      print_ast_mix m
+      (print_ast_mix ~print_counter)
+      m
   | (n, _), INIT_TOK t ->
     Format.fprintf f "@[%%init: %a %a@]" print_ast_alg_expr n
       (Pp.list Pp.space (fun f (x, _) -> Format.pp_print_string f x))
@@ -762,7 +1078,7 @@ let print_init f = function
 
 let print_ast_bool_expr =
   Alg_expr.print_bool
-    (fun f m -> Format.fprintf f "|%a|" print_ast_mix m)
+    (fun f m -> Format.fprintf f "|%a|" (print_ast_mix ~print_counter) m)
     Format.pp_print_string
     (fun f x -> Format.fprintf f "'%s'" x)
 
@@ -801,7 +1117,9 @@ let print_modif f = function
        else
          "[false]")
   | CFLOWMIX (on, (p, _)) ->
-    Format.fprintf f "$TRACK @[%a@] %s;" print_ast_mix p
+    Format.fprintf f "$TRACK @[%a@] %s;"
+      (print_ast_mix ~print_counter)
+      p
       (if on then
          "[true]"
        else
@@ -814,7 +1132,9 @@ let print_modif f = function
         | Primitives.PROBABILITY -> Format.fprintf f "\"probability\" ")
   | DINOFF p -> Format.fprintf f "$DIN%a [false]" print_print_expr p
   | SPECIES_OF (on, p, (m, _)) ->
-    Format.fprintf f "$SPECIES_OF @[%a@] %s >%a;" print_ast_mix m
+    Format.fprintf f "$SPECIES_OF @[%a@] %s >%a;"
+      (print_ast_mix ~print_counter)
+      m
       (if on then
          "[true]"
        else
@@ -838,7 +1158,9 @@ let print_parsing_compil_kappa f c =
     (Pp.list Pp.space print_configuration)
     c.configurations
     (Pp.list Pp.space (fun f a ->
-         Format.fprintf f "@[%%agent:@ @[%a@]@]" print_ast_agent a))
+         Format.fprintf f "@[%%agent:@ @[%a@]@]"
+           (print_ast_agent ~print_counter:print_counter_sig)
+           a))
     c.signatures
     (Pp.list Pp.space (fun f (s, _) -> Format.fprintf f "%%token: %s" s))
     c.tokens
@@ -1176,7 +1498,9 @@ let merge_internals =
 
 let rec merge_sites_counter c = function
   | [] -> [ Counter c ]
-  | Counter c' :: _ as l when fst c.counter_name = fst c'.counter_name -> l
+  | Counter c' :: _ as l when fst c.counter_sig_name = fst c'.counter_sig_name
+    ->
+    l
   | ((Port _ | Counter _) as h) :: t -> h :: merge_sites_counter c t
 
 let rec merge_sites_port p = function
@@ -1196,13 +1520,13 @@ let rec merge_sites_port p = function
 let merge_sites =
   List.fold_left (fun acc -> function
     | Port p -> merge_sites_port p acc
-    | Counter c -> merge_sites_counter c acc)
+    | Counter c -> merge_sites_counter (counter_sig_of_counter c) acc)
 
 let merge_agents =
   List.fold_left
-    (List.fold_left (fun acc -> function
+    (List.fold_left (fun (acc : agent_sig list) -> function
        | Absent _ -> acc
-       | Present (((na, _) as x), s, _) ->
+       | Present (((na, _) as x), (s : counter site list), _) ->
          let rec aux = function
            | [] ->
              [
@@ -1211,7 +1535,8 @@ let merge_agents =
                    List.map
                      (function
                        | Port p -> Port { p with port_link = [] }
-                       | Counter _ as x -> x)
+                       | Counter _ as x ->
+                         map_counters_in_site counter_sig_of_counter x)
                      s,
                    NoMod );
              ]
@@ -1344,7 +1669,7 @@ let compil_to_json c =
   `Assoc
     [
       "filenames", JsonUtil.of_array JsonUtil.of_string files;
-      "signatures", JsonUtil.of_list (agent_to_json filenames) c.signatures;
+      "signatures", JsonUtil.of_list (agent_sig_to_json filenames) c.signatures;
       "tokens", JsonUtil.of_list (string_annot_to_json filenames) c.tokens;
       ( "variables",
         JsonUtil.of_list
@@ -1418,7 +1743,7 @@ let compil_of_json = function
          signatures =
            JsonUtil.to_list
              ~error_msg:(JsonUtil.build_msg "AST signature")
-             (agent_of_json filenames)
+             (agent_sig_of_json filenames)
              (List.assoc "signatures" l);
          tokens =
            JsonUtil.to_list
@@ -1492,3 +1817,4 @@ let compil_of_json = function
 
 let write_parsing_compil b ast = Yojson.Basic.write_json b (compil_to_json ast)
 let read_parsing_compil p lb = compil_of_json (Yojson.Basic.read_json p lb)
+let print_ast_mix = print_ast_mix ~print_counter
diff --git a/core/grammar/ast.mli b/core/grammar/ast.mli
index f6358a70a..850cad6b5 100644
--- a/core/grammar/ast.mli
+++ b/core/grammar/ast.mli
@@ -35,13 +35,26 @@ type counter = {
   counter_delta: int Loc.annoted;
 }
 
-type site = Port of port | Counter of counter
+type counter_sig = {
+  counter_sig_name: string Loc.annoted;
+  counter_sig_min: int option Loc.annoted option;
+  counter_sig_max: int option Loc.annoted option;
+  counter_sig_visible: bool;
+  counter_sig_default: int;
+}
+
+val make_inverted_counter_sig : counter_sig -> string Loc.annoted -> counter_sig
+
+(* Site type, with custom definition of counter type: used with `counter` and `counter_sig` *)
+type 'counter site = Port of port | Counter of 'counter
 type agent_mod = NoMod | Erase | Create
 
-type agent =
-  | Present of string Loc.annoted * site list * agent_mod
+type 'counter parametric_agent =
+  | Present of string Loc.annoted * 'counter site list * agent_mod
   | Absent of Loc.t
 
+type agent = counter parametric_agent
+type agent_sig = counter_sig parametric_agent
 type mixture = agent list list
 
 val mixture_to_user_graph : mixture -> User_graph.connected_component
@@ -125,8 +138,8 @@ type ('mixture, 'id) init_t =
 type ('pattern, 'mixture, 'id) init_statement =
   ('pattern, 'id) Alg_expr.e Loc.annoted * ('mixture, 'id) init_t
 
-type ('agent, 'pattern, 'mixture, 'id, 'rule) instruction =
-  | SIG of 'agent
+type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) instruction =
+  | SIG of 'agent_sig
   | TOKENSIG of string Loc.annoted
   | VOLSIG of string * float * string  (** type, volume, parameter *)
   | INIT of ('pattern, 'mixture, 'id) init_statement
@@ -142,11 +155,11 @@ type ('pattern, 'mixture, 'id, 'rule) command =
   | MODIFY of ('pattern, 'mixture, 'id, 'rule) modif_expr list
   | QUIT
 
-type ('agent, 'pattern, 'mixture, 'id, 'rule) compil = {
+type ('agent, 'agent_sig, 'pattern, 'mixture, 'id, 'rule) compil = {
   filenames: string list;
   variables: ('pattern, 'id) variable_def list;
       (** pattern declaration for reusing as variable in perturbations or kinetic rate *)
-  signatures: 'agent list;  (** agent signature declarations *)
+  signatures: 'agent_sig list;  (** agent signature declarations *)
   rules: (string Loc.annoted option * 'rule Loc.annoted) list;
       (**rules (possibly named)*)
   observables: ('pattern, 'id) Alg_expr.e Loc.annoted list;
@@ -159,11 +172,13 @@ type ('agent, 'pattern, 'mixture, 'id, 'rule) compil = {
   volumes: (string * float * string) list;
 }
 
-type parsing_compil = (agent, mixture, mixture, string, rule) compil
-type parsing_instruction = (agent, mixture, mixture, string, rule) instruction
+type parsing_compil = (agent, agent_sig, mixture, mixture, string, rule) compil
+
+type parsing_instruction =
+  (agent, agent_sig, mixture, mixture, string, rule) instruction
 
 val empty_compil : parsing_compil
-val no_more_site_on_right : bool -> site list -> site list -> bool
+val no_more_site_on_right : bool -> 'a site list -> 'a site list -> bool
 
 val split_mixture : mixture -> mixture * mixture
 (** @return (lhs,rhs) *)
diff --git a/core/grammar/counters_compiler.ml b/core/grammar/counters_compiler.ml
index 9aafe0b39..3759e5776 100644
--- a/core/grammar/counters_compiler.ml
+++ b/core/grammar/counters_compiler.ml
@@ -213,23 +213,20 @@ let counters_signature s agents =
 (** [split_cvar_counter_in_rules_per_value var_name annot counter_delta counter_def] translates a counter CVAR whose value acts upon the rate expression into a rule per possible value, that are selected by a CEQ expression.
  * *)
 let split_cvar_counter_in_rules_per_value (var_name : string) (annot : Loc.t)
-    (counter_delta : int Loc.annoted) (counter_def : Ast.counter) :
-    (Ast.site * (string * int) list) list =
-  let max_value : int = Loc.v counter_def.counter_delta in
-  let min_value : int =
-    match counter_def.counter_test with
-    | None | Some (Ast.CGTE _, _) | Some (Ast.CLTE _, _) | Some (Ast.CVAR _, _)
-      ->
+    (counter_delta : int Loc.annoted) (counter_def : Ast.counter_sig) :
+    (Ast.counter Ast.site * (string * int) list) list =
+  let (min_value, max_value) : int * int =
+    match counter_def.counter_sig_min, counter_def.counter_sig_max with
+    | Some (Some min_loc, _), Some (Some max_loc, _) -> min_loc, max_loc
+    | (None | Some (None, _)), _ | _, (None | Some (None, _)) ->
       raise
         (ExceptionDefn.Malformed_Decl
-           ( "Invalid counter signature - have to specify min bound",
-             Loc.get_annot counter_def.counter_name ))
-    | Some (Ast.CEQ min_value, _) -> min_value
+           ( "Invalid counter signature - have to specify min/max bound",
+             Loc.get_annot counter_def.counter_sig_name ))
   in
-
   (* Make CEQ counters with all possible values of variable *)
   let rec make_ceq_counters_from_var_values (value : int) :
-      (Ast.site * (string * int) list) list =
+      (Ast.counter Ast.site * (string * int) list) list =
     if value > max_value then
       []
     else if
@@ -238,7 +235,7 @@ let split_cvar_counter_in_rules_per_value (var_name : string) (annot : Loc.t)
     then
       ( Ast.Counter
           {
-            Ast.counter_name = counter_def.counter_name;
+            Ast.counter_name = counter_def.counter_sig_name;
             counter_test = Some (Ast.CEQ value, annot);
             counter_delta;
           },
@@ -266,7 +263,7 @@ let split_counter_variables_into_separate_rules ~warning rules signatures =
   let split_for_each_counter_var_value_site ids counter_defs = function
     | Ast.Port p -> [ Ast.Port p, [] ]
     | Ast.Counter c ->
-      let delta = Loc.v c.counter_delta in
+      let delta = Loc.v c.Ast.counter_delta in
       (match c.counter_test with
       | Some (Ast.CEQ value, _) ->
         if delta > 0 || abs delta <= value then
@@ -291,10 +288,10 @@ let split_counter_variables_into_separate_rules ~warning rules signatures =
         [ Ast.Counter c, [] ]
       | Some (Ast.CVAR var_name, annot) when Mods.StringSet.mem var_name ids ->
         (* If the variable is present in an rate definition expression *)
-        let counter_def : Ast.counter =
+        let counter_def : Ast.counter_sig =
           List.find
             (fun counter ->
-              name_match c.Ast.counter_name counter.Ast.counter_name)
+              name_match c.Ast.counter_name counter.Ast.counter_sig_name)
             counter_defs
         in
 
@@ -314,8 +311,9 @@ let split_counter_variables_into_separate_rules ~warning rules signatures =
   in
 
   let rec split_for_each_counter_var_value_sites (ids : Mods.StringSet.t)
-      (counter_defs : Ast.counter list) :
-      Ast.site list -> (Ast.site list * (string * int) list) list = function
+      (counter_defs : Ast.counter_sig list) :
+      Ast.counter Ast.site list ->
+      (Ast.counter Ast.site list * (string * int) list) list = function
     | [] -> [ [], [] ]
     | s :: t ->
       combinations_of_var_setup
@@ -815,7 +813,7 @@ let compile_counter_in_rule (sigs : Signature.s)
     ( List.rev_map (fun rule_agent_ -> rule_agent_.agent) (List.rev mix),
       List.rev_map (fun raw_agent_ -> raw_agent_.agent) (List.rev created) )
 
-let rule_agent_with_max_counter sigs c ((agent_name, _) as agent_type) :
+let rule_agent_with_max_counter sigs c ((agent_name, loc_ag) as agent_type) :
     LKappa.rule_mixture =
   let ag_id = Signature.num_of_agent agent_type sigs in
   let sign = Signature.get sigs ag_id in
@@ -824,9 +822,18 @@ let rule_agent_with_max_counter sigs c ((agent_name, _) as agent_type) :
     Array.make arity (Loc.annot_with_dummy LKappa.LNK_ANY, LKappa.Maintained)
   in
   let internals = Array.make arity LKappa.I_ANY in
-  let c_na = c.Ast.counter_name in
+  let c_na = c.Ast.counter_sig_name in
   let c_id = Signature.num_of_site ~agent_name c_na sign in
-  let max_val, loc = c.Ast.counter_delta in
+  let max_val, loc =
+    match c.Ast.counter_sig_max with
+    | Some (Some max, loc) -> max, loc
+    | None | Some (None, _) ->
+      raise
+        (ExceptionDefn.Internal_Error
+           ( "Counter " ^ fst c_na ^ " in " ^ agent_name
+             ^ " should have an upper bound",
+             loc_ag ))
+  in
   let max_val' = max_val + 1 in
   let incrs =
     link_incr sigs 0 (max_val' + 1) ((c_id, ag_id), false) false 1 loc (-1)
@@ -847,11 +854,12 @@ let rule_agent_with_max_counter sigs c ((agent_name, _) as agent_type) :
   ra :: incrs
 
 let counter_perturbation sigs c agent_type =
-  let annot = Loc.get_annot c.Ast.counter_name in
+  let annot = Loc.get_annot c.Ast.counter_sig_name in
   let filename = [ Primitives.Str_pexpr ("counter_perturbation.ka", annot) ] in
   let stop_message =
-    "Counter " ^ Loc.v c.Ast.counter_name ^ " of agent " ^ Loc.v agent_type
-    ^ " reached maximum"
+    "Counter "
+    ^ Loc.v c.Ast.counter_sig_name
+    ^ " of agent " ^ Loc.v agent_type ^ " reached maximum"
   in
   let mods =
     [
@@ -1024,18 +1032,12 @@ let annotate_created_counters sigs ((agent_name, _) as agent_type) counter_list
     Array.make arity None
   in
 
-  (* register all counters (specified or not) with min value *)
+  (* register all counters (specified or not) with default value *)
   Array.iteri
     (fun port_id _ ->
       match Signature.counter_of_site_id port_id agent_signature with
-      | Some (counter_min, counter_max) ->
+      | Some counter_info ->
         let counter_name = Signature.site_of_num port_id agent_signature in
-        let default_init_value =
-          if Signature.is_inverted_counter counter_name then
-            counter_max
-          else
-            counter_min
-        in
         (try
            (* find counter matching port *)
            let c : Ast.counter =
@@ -1056,9 +1058,11 @@ let annotate_created_counters sigs ((agent_name, _) as agent_type) counter_list
            ra_counters.(port_id) <-
              Some
                ( {
-                   Ast.counter_name = counter_name, Loc.dummy;
+                   Ast.counter_name = counter_name |> Loc.annot_with_dummy;
                    Ast.counter_test =
-                     Some (Ast.CEQ default_init_value, Loc.dummy);
+                     Some
+                       (Ast.CEQ counter_info.counter_default_value
+                      |> Loc.annot_with_dummy);
                    Ast.counter_delta = 0, Loc.dummy;
                  },
                  LKappa.Maintained ))
diff --git a/core/grammar/counters_compiler.mli b/core/grammar/counters_compiler.mli
index 66f6b5a0a..bddcd8a03 100644
--- a/core/grammar/counters_compiler.mli
+++ b/core/grammar/counters_compiler.mli
@@ -38,7 +38,7 @@ val compile_counter_in_rule :
 
 val counters_perturbations :
   Signature.s ->
-  Ast.mixture ->
+  Ast.agent_sig list list ->
   (LKappa.rule_mixture, Raw_mixture.t, int, LKappa.rule) Ast.perturbation list
 
 val annotate_dropped_counters :
diff --git a/core/grammar/eval.mli b/core/grammar/eval.mli
index 547b83b04..ba8321a57 100644
--- a/core/grammar/eval.mli
+++ b/core/grammar/eval.mli
@@ -61,7 +61,7 @@ val compile :
   Signature.s ->
   unit NamedDecls.t ->
   Contact_map.t ->
-  ('c, LKappa.rule_mixture, Raw_mixture.t, int, LKappa.rule) Ast.compil ->
+  ('c, 'd, LKappa.rule_mixture, Raw_mixture.t, int, LKappa.rule) Ast.compil ->
   'b
 
 val build_initial_state :
diff --git a/core/grammar/kappaLexer.mli b/core/grammar/kappaLexer.mli
index 05b5cb655..13a07e47e 100644
--- a/core/grammar/kappaLexer.mli
+++ b/core/grammar/kappaLexer.mli
@@ -1,6 +1,12 @@
 val compile :
   Format.formatter ->
-  (Ast.agent, Ast.mixture, Ast.mixture, string, Ast.rule) Ast.compil ->
+  ( Ast.agent,
+    Ast.agent_sig,
+    Ast.mixture,
+    Ast.mixture,
+    string,
+    Ast.rule )
+  Ast.compil ->
   string (** file *) ->
   Ast.parsing_compil
 
diff --git a/core/grammar/kappaParser.mly b/core/grammar/kappaParser.mly
index c370ee69b..081e85a2c 100644
--- a/core/grammar/kappaParser.mly
+++ b/core/grammar/kappaParser.mly
@@ -101,7 +101,7 @@ start_rule:
     ;
 
 instruction:
-    | SIGNATURE agent_expression {Ast.SIG $2}
+    | SIGNATURE agent_expression_sig {Ast.SIG $2}
     | TOKEN ID {Ast.TOKENSIG ($2,rhs_pos 2)}
     | SIGNATURE error {raise (ExceptionDefn.Syntax_Error
 				(add_pos "Malformed agent signature, I was expecting something of the form '%agent: A(x,y~u~v,z)'"))}
@@ -431,6 +431,11 @@ mod_agent:
 	| PLUS { Ast.Create }
 	| MINUS { Ast.Erase };
 
+agent_expression_sig:
+  | ID OP_PAR interface_expression_sig CL_PAR {Ast.Present (($1,rhs_pos 1), $3, Ast.NoMod)}
+  | ID error { raise (ExceptionDefn.Syntax_Error
+       (add_pos ("Malformed agent '"^$1^"'")))}
+
 agent_expression:
     | mod_agent ID OP_PAR interface_expression CL_PAR
 	 {Ast.Present (($2,rhs_pos 2), $4, $1)}
@@ -439,6 +444,12 @@ agent_expression:
 		    (add_pos ("Malformed agent '"^$2^"'")))}
     ;
 
+interface_expression_sig:
+    /*empty*/ {[]}
+    | port_expression_sig COMMA interface_expression_sig {$1::$3}
+    | port_expression_sig {[$1]}
+    ;
+
 interface_expression:
   /*empty*/ {[]}
     | port_expression COMMA interface_expression {$1::$3}
@@ -495,6 +506,77 @@ port_expression:
 	   Ast.counter_delta = Loc.annot_with_dummy 0} }
     ;
 
+port_expression_sig:
+   | ID internal_state link_state_mod
+    	 { Ast.Port
+    	   {Ast.port_name=($1,rhs_pos 1); Ast.port_int=$2; Ast.port_link=[];
+    	    Ast.port_int_mod = None; Ast.port_link_mod = $3; } }
+  | ID internal_state link_state link_state_mod
+    	 { Ast.Port
+    	   {Ast.port_name=($1,rhs_pos 1); Ast.port_int=$2; Ast.port_link=$3;
+    	    Ast.port_int_mod = None; Ast.port_link_mod = $4; } }
+  | ID internal_state DIV KAPPA_MRK link_state_mod
+    	 { Ast.Port
+    	   {Ast.port_name=($1,rhs_pos 1); Ast.port_int=$2; Ast.port_link=[];
+    	    Ast.port_int_mod = Some($4,rhs_pos 4); Ast.port_link_mod = $5; } }
+  | ID internal_state DIV KAPPA_MRK link_state link_state_mod
+    	 { Ast.Port
+    	   {Ast.port_name=($1,rhs_pos 1); Ast.port_int=$2; Ast.port_link=$5;
+    	    Ast.port_int_mod = Some($4,rhs_pos 4); Ast.port_link_mod = $6; } }
+  | ID PLUS EQUAL INT
+             { Ast.Counter
+    	   { Ast.counter_sig_name = ($1,rhs_pos 1);
+           Ast.counter_sig_min = None;
+           Ast.counter_sig_max = Some (Some $4, rhs_pos 4);
+           Ast.counter_sig_default = $4;
+           Ast.counter_sig_visible = true}}
+  | ID PLUS EQUAL MINUS INT
+        {Ast.Counter
+  { Ast.counter_sig_name = ($1,rhs_pos 1);
+    Ast.counter_sig_min = None;
+    Ast.counter_sig_max = Some (Some (-$5), rhs_pos 5);
+    Ast.counter_sig_default = -$5;
+    Ast.counter_sig_visible = true}}
+  | ID counter_test PLUS EQUAL INT
+       { let min =
+            match $2 with
+                      | Some (Ast.CEQ i,_) -> i
+                      | None | Some ((CGTE _|CLTE _|CVAR _), _) -> raise (ExceptionDefn.Syntax_Error
+                      (add_pos "Issue counters in signature"))
+        in Ast.Counter
+         { Ast.counter_sig_name = ($1,rhs_pos 1);
+           Ast.counter_sig_min = Some (Some min, rhs_pos 2);
+           Ast.counter_sig_max = Some (Some $5, rhs_pos 5);
+           Ast.counter_sig_default = min;
+           Ast.counter_sig_visible = true}}
+  | ID counter_test PLUS EQUAL MINUS INT
+      { let min =
+           match $2 with
+                     | Some (Ast.CEQ i,_) -> i
+                     | None | Some ((CGTE _|CLTE _|CVAR _), _) -> raise (ExceptionDefn.Syntax_Error
+                     (add_pos "Issue counters in signature"))
+       in
+        Ast.Counter
+        { Ast.counter_sig_name = ($1,rhs_pos 1);
+          Ast.counter_sig_min = Some (Some min, rhs_pos 2);
+          Ast.counter_sig_max = Some (Some (-$6), rhs_pos 6);
+          Ast.counter_sig_default = min ;
+          Ast.counter_sig_visible = true}}
+  | ID counter_test
+      { let min =
+           match $2 with
+                     | Some (Ast.CEQ i,_) -> i
+                     | None | Some ((CGTE _|CLTE _|CVAR _), _) -> raise (ExceptionDefn.Syntax_Error
+                     (add_pos "Issue counters in signature"))
+       in
+       Ast.Counter
+  { Ast.counter_sig_name = ($1,rhs_pos 1);
+    Ast.counter_sig_min = Some (Some min, rhs_pos 2);
+    Ast.counter_sig_max = None;
+    Ast.counter_sig_default = min;
+    Ast.counter_sig_visible = true}}
+
+
 internal_state:
   /*empty*/ {[]}
     | KAPPA_MRK internal_state {(Some $1,rhs_pos 1)::$2}
diff --git a/core/grammar/klexer4.mli b/core/grammar/klexer4.mli
index 45b3d89d7..d522428ab 100644
--- a/core/grammar/klexer4.mli
+++ b/core/grammar/klexer4.mli
@@ -3,7 +3,13 @@ val model :
 
 val compile :
   Format.formatter ->
-  (Ast.agent, Ast.mixture, Ast.mixture, string, Ast.rule) Ast.compil ->
+  ( Ast.agent,
+    Ast.agent_sig,
+    Ast.mixture,
+    Ast.mixture,
+    string,
+    Ast.rule )
+  Ast.compil ->
   string ->
   Ast.parsing_compil
 
diff --git a/core/grammar/kparser4.mly b/core/grammar/kparser4.mly
index 3bed553a1..3c40f6e1d 100644
--- a/core/grammar/kparser4.mly
+++ b/core/grammar/kparser4.mly
@@ -140,6 +140,54 @@ site_counter:
     { (Some $1,$5) }
   ;
 
+site_counter_sig:
+    | EQUAL annoted INT  annoted DIV annoted counter_modif annoted CL_CUR annoted
+      { Some (Some ($3),rhs_pos 3),match $7 with (a,loc) -> Some (Some (a),loc) }
+    | EQUAL annoted INT  annoted CL_CUR annoted
+        { Some (Some ($3),rhs_pos 3),None }
+    ;
+
+  site_sig:
+    | ID annoted OP_BRA site_link annoted OP_CUR annoted site_internal annoted
+      { let (port_link, port_link_mod) = $4 in
+        let (port_int, port_int_mod) = $8 in
+        Ast.Port
+          { Ast.port_name=($1,rhs_pos 1); Ast.port_int;
+            Ast.port_link; Ast.port_int_mod; Ast.port_link_mod; } }
+    | ID annoted OP_CUR annoted site_internal annoted OP_BRA site_link annoted
+      { let (port_int, port_int_mod) = $5 in
+        let (port_link, port_link_mod) = $8 in
+        Ast.Port
+          { Ast.port_name=($1,rhs_pos 1); Ast.port_int;
+            Ast.port_link; Ast.port_int_mod; Ast.port_link_mod; } }
+    | ID annoted OP_BRA site_link annoted
+      { let (port_link, port_link_mod) = $4 in
+        Ast.Port
+          { Ast.port_name=($1,rhs_pos 1); Ast.port_int=[];
+            Ast.port_link; Ast.port_int_mod=None; Ast.port_link_mod; } }
+    | ID annoted OP_CUR annoted site_internal annoted
+      { let (port_int, port_int_mod) = $5 in
+        Ast.Port
+          { Ast.port_name=($1,rhs_pos 1);Ast.port_link=[];
+            Ast.port_int; Ast.port_int_mod; Ast.port_link_mod=None; } }
+    | ID annoted OP_CUR annoted site_counter_sig
+      { let (counter_sig_min,counter_sig_max) = $5 in
+        Ast.Counter
+          { Ast.counter_sig_name=($1,rhs_pos 1);
+            Ast.counter_sig_min;
+            Ast.counter_sig_max;
+            Ast.counter_sig_default=
+                (match counter_sig_min with
+                  | None | Some (None, _)-> 0
+                  | Some (Some i,_) -> i );
+            Ast.counter_sig_visible=true;
+            } }
+    | ID annoted
+      { Ast.Port
+          { Ast.port_name=($1,rhs_pos 1);Ast.port_link=[]; Ast.port_int=[];
+            Ast.port_int_mod=None; Ast.port_link_mod=None; } }
+    ;
+
 site:
   | ID annoted OP_BRA site_link annoted OP_CUR annoted site_internal annoted
     { let (port_link, port_link_mod) = $4 in
@@ -182,6 +230,15 @@ interface:
   | site COMMA annoted interface { $1 :: $4 }
   ;
 
+interface_sig:
+    | { [] }
+    | error
+      { raise (ExceptionDefn.Syntax_Error
+                 (add_pos 1 ("Malformed site expression"))) }
+    | site_sig interface_sig { $1 :: $2 }
+    | site_sig COMMA annoted interface_sig { $1 :: $4 }
+    ;
+
 agent_modif:
   | annoted { Ast.NoMod,start_pos 1,$1 }
   | annoted PLUS annoted { Ast.Create,end_pos 2,$3 }
@@ -201,6 +258,18 @@ agent:
                (add_pos 3 ("Malformed agent '"^$1^"'"))) }
   ;
 
+agent_sig:
+    | DOT annoted { (Ast.Absent (rhs_pos 1),end_pos 1,$2) }
+    | ID annoted OP_PAR annoted interface_sig CL_PAR agent_modif
+      { let modif,pend,an = $7 in
+        (Ast.Present (($1,rhs_pos 1), $5, modif),pend,an) }
+    | ID annoted COLON annoted ID annoted OP_PAR annoted interface_sig CL_PAR agent_modif
+      { let modif,pend,an = $11 in
+        (Ast.Present (($5,rhs_pos 5), $9, modif),pend,an) }
+    | ID annoted error
+      { raise (ExceptionDefn.Syntax_Error
+                 (add_pos 3 ("Malformed agent '"^$1^"'"))) }
+    ;
 pattern:
   | agent COMMA annoted pattern
 { let (x,_,_) = $1 in
@@ -708,7 +777,7 @@ sentence:
   | LABEL annoted EQUAL annoted alg_expr
     { let (v,_,_) = $5 in add (Ast.DECLARE (($1,rhs_pos 1),v)) }
   | rule { add (Ast.RULE (None,$1)) }
-  | SIGNATURE annoted agent { let (a,_,_) = $3 in add (Ast.SIG a) }
+  | SIGNATURE annoted agent_sig { let (a,_,_) = $3 in add (Ast.SIG a) }
   | SIGNATURE annoted error
     { raise
         (ExceptionDefn.Syntax_Error (add_pos 3 "Malformed agent signature")) }
diff --git a/core/grammar/lKappa_compiler.ml b/core/grammar/lKappa_compiler.ml
index 48bed3f56..45dd0c3c9 100644
--- a/core/grammar/lKappa_compiler.ml
+++ b/core/grammar/lKappa_compiler.ml
@@ -1616,7 +1616,7 @@ type site_sig_with_links_as_lists =
 (** Temporary type to store site signature with list links instead of array array links *)
 
 (** [prepare_agent_sig ~sites evaluates to (site_sigs, counter_list) which describe data that can be used to create a Signature.t for a single agent*)
-let prepare_agent_sig ~(sites : Ast.site list) :
+let prepare_agent_sig ~(sites : Ast.counter_sig Ast.site list) :
     site_sig_with_links_as_lists NamedDecls.t * string Loc.annoted list =
   let ( (site_sigs_pre_nameddecls :
           (string Loc.annoted * site_sig_with_links_as_lists) list),
@@ -1655,47 +1655,38 @@ let prepare_agent_sig ~(sites : Ast.site list) :
                                   pos ))
                          | LKappa.LNK_TYPE (a, b), _ -> (a, b) :: acc_links')
                        [] p.port_link);
-                counters_info = None;
+                counter_info = None;
               } )
             :: acc_site_sigs,
             acc_counter_names )
         | Counter c ->
           (* We are reading here a signature, only CEQ tests are accepted *)
-          (match c.counter_test with
-          | None ->
-            let n, pos = c.counter_name in
-            raise
-              (ExceptionDefn.Internal_Error
-                 ("Counter " ^ n ^ " should have a test in signature", pos))
-          | Some (test, pos) ->
-            (match test with
-            | CVAR _ ->
-              raise
-                (ExceptionDefn.Internal_Error
-                   ("Counter should not have a var in signature", pos))
-            | CGTE _ ->
-              raise
-                (ExceptionDefn.Internal_Error
-                   ("Counter should not have >= in signature", pos))
-            | CLTE _ ->
-              raise
-                (ExceptionDefn.Internal_Error
-                   ("Counter should not have <= in signature", pos))
-            | CEQ j ->
-              ( ( c.counter_name,
-                  {
-                    internal_state = NamedDecls.create [||];
-                    (* Agent with counter can link to port [b] on counter agent [__counter_agent] *)
-                    links =
-                      Some
-                        [
-                          ( Loc.annot_with_dummy "b",
-                            Loc.annot_with_dummy "__counter_agent" );
-                        ];
-                    counters_info = Some (j, Loc.v c.counter_delta);
-                  } )
-                :: acc_site_sigs,
-                c.counter_name :: acc_counter_names ))))
+          ( ( c.Ast.counter_sig_name,
+              {
+                internal_state = NamedDecls.create [||];
+                (* Agent with counter can link to port [b] on counter agent [__counter_agent] *)
+                links =
+                  Some
+                    [
+                      ( Loc.annot_with_dummy "b",
+                        Loc.annot_with_dummy "__counter_agent" );
+                    ];
+                counter_info =
+                  Some
+                    {
+                      counter_info_min =
+                        (match c.Ast.counter_sig_min with
+                        | Some (Some i, _) -> Some i
+                        | None | Some (None, _) -> None);
+                      counter_info_max =
+                        (match c.Ast.counter_sig_max with
+                        | Some (Some i, _) -> Some i
+                        | None | Some (None, _) -> None);
+                      counter_default_value = c.Ast.counter_sig_default;
+                    };
+              } )
+            :: acc_site_sigs,
+            c.counter_sig_name :: acc_counter_names ))
       sites ([], [])
   in
   NamedDecls.create_from_list site_sigs_pre_nameddecls, counter_names
@@ -1721,7 +1712,7 @@ let make_counter_agent_site_sigs
     {
       Signature.internal_state = NamedDecls.create [||];
       links = Some [ b_port_name, counter_agent_name ];
-      counters_info = None;
+      counter_info = None;
     }
   in
   (* Port [b] can link to port a of agent of type counter agent
@@ -1741,7 +1732,7 @@ let make_counter_agent_site_sigs
     {
       Signature.internal_state = NamedDecls.create [||];
       links = Some b_links;
-      counters_info = None;
+      counter_info = None;
     }
   in
   let site_sigs_counter_agent =
@@ -1799,7 +1790,7 @@ let agent_sigs_of_agent_sigs_with_links_as_lists ~(build_contact_map : bool)
           )))
     agent_sigs_pre
 
-let create_sigs (l : Ast.agent list) : Signature.s =
+let create_sigs (l : Ast.agent_sig list) : Signature.s =
   (* Contact map should be built only if a specific link is described in the definition of signature *)
   let build_contact_map : bool =
     List.fold_left
@@ -1877,7 +1868,13 @@ type ast_compiled_data = {
   alg_vars_finder: int Mods.StringMap.t;
   updated_alg_vars: int list;
   result:
-    (Ast.agent, LKappa.rule_mixture, Raw_mixture.t, int, LKappa.rule) Ast.compil;
+    ( Ast.agent,
+      Ast.agent_sig,
+      LKappa.rule_mixture,
+      Raw_mixture.t,
+      int,
+      LKappa.rule )
+    Ast.compil;
       (** Compiled data where identifiers are i Ast.compil where identifiers
      * are integers and not string, syntactic sugar on rules are expansed
      * (syntactic sugar on mixture are not) *)
@@ -1945,7 +1942,7 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
   in
 
   (* Create opposite counters that have the same tests *)
-  let signatures : Ast.agent list =
+  let signatures : Ast.agent_sig list =
     List.map
       (fun agent ->
         match agent with
@@ -1959,17 +1956,18 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                 agent_name = agent_name_counter)
               counters_with_clte_tests
           in
-          let new_counter_sites : Ast.site list =
+          let new_counter_sites : Ast.counter_sig Ast.site list =
             List.fold_left
               (fun acc (_, counter_name, sum_bounds_ref) ->
                 (* Find counter to invert *)
-                let counter_orig : Ast.counter =
+                let counter_orig : Ast.counter_sig =
                   List.find_map
                     (fun site ->
                       match site with
                       | Ast.Port _ -> None
                       | Counter counter ->
-                        if Loc.v counter.counter_name = counter_name then
+                        if Loc.v counter.Ast.counter_sig_name = counter_name
+                        then
                           Some counter
                         else
                           None)
@@ -1978,31 +1976,37 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                 in
 
                 (* Make inverted counter declaration *)
-                let counter_name : string Loc.annoted =
+                let counter_sig_name : string Loc.annoted =
                   Loc.map_annot
                     (fun name -> inverted_counter_name name)
-                    counter_orig.counter_name
+                    counter_orig.counter_sig_name
                 in
-                let counter_test = counter_orig.counter_test in
-                let counter_delta = counter_orig.counter_delta in
-
-                (* Write in sum_bounds_ref the sum of the counter bounds above *)
-                let inf_bound =
-                  match
-                    counter_test |> Option_util.unsome_or_raise |> Loc.v
-                  with
-                  | CGTE _ | CLTE _ | CVAR _ ->
+                let counter_sig_min = counter_orig.counter_sig_min in
+                let counter_sig_max = counter_orig.counter_sig_max in
+                let counter_sig_default, inf_bound, sup_bound =
+                  match counter_sig_min, counter_sig_max with
+                  | Some (Some min, _), Some (Some max, _) ->
+                    max + min - counter_orig.counter_sig_default, min, max
+                  | (None | Some (None, _)), _ | _, (None | Some (None, _)) ->
                     raise
                       (ExceptionDefn.Malformed_Decl
-                         ( "Counter should have CEQ test value in signature \
-                            statement",
-                           Loc.get_annot counter_name ))
-                  | CEQ value -> value
+                         ( "Cannot take the opposite of an unbounded counters  ",
+                           Loc.get_annot counter_orig.counter_sig_name ))
                 in
-                let sup_bound = Loc.v counter_delta in
+
+                let counter_sig_visible = false in
+                (* Write in sum_bounds_ref the sum of the counter bounds above *)
                 sum_bounds_ref := inf_bound + sup_bound;
 
-                Ast.Counter { counter_name; counter_test; counter_delta } :: acc)
+                Ast.Counter
+                  {
+                    Ast.counter_sig_name;
+                    Ast.counter_sig_min;
+                    Ast.counter_sig_max;
+                    Ast.counter_sig_default;
+                    Ast.counter_sig_visible;
+                  }
+                :: acc)
               [] counters_with_clte_tests_from_agent
           in
 
@@ -2029,7 +2033,7 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
               in
               (* Add delta to counter as opposite deltas to counter_delta *)
               let (added_sites, site_list_with_opposite_deltas) :
-                  Ast.site list * Ast.site list =
+                  Ast.counter Ast.site list * Ast.counter Ast.site list =
                 List.fold_left_map
                   (fun acc site ->
                     match site with
@@ -2038,7 +2042,7 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                       (match
                          List.find_opt
                            (fun (_, name, _) ->
-                             String.equal (Loc.v counter.counter_name) name)
+                             String.equal (Loc.v counter.Ast.counter_name) name)
                            counters_with_clte_tests_from_agent
                        with
                       | None -> acc, site
@@ -2063,11 +2067,11 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                             let inverted_counter_site =
                               Ast.Counter
                                 {
-                                  counter_name =
+                                  Ast.counter_name =
                                     Loc.map_annot inverted_counter_name
                                       counter.counter_name;
-                                  counter_test = None;
-                                  counter_delta =
+                                  Ast.counter_test = None;
+                                  Ast.counter_delta =
                                     Loc.map_annot
                                       (fun delta -> -delta)
                                       counter.counter_delta;
@@ -2082,16 +2086,16 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                           let new_site =
                             Ast.Counter
                               {
-                                counter_name =
+                                Ast.counter_name =
                                   Loc.map_annot inverted_counter_name
                                     counter.counter_name;
-                                counter_test =
+                                Ast.counter_test =
                                   Some
                                     (Ast.CGTE (!sum_bounds_ref - value)
                                     |> Loc.copy_annot
                                          (Option_util.unsome_or_raise
                                             counter.counter_test));
-                                counter_delta =
+                                Ast.counter_delta =
                                   Loc.map_annot
                                     (fun delta -> -delta)
                                     counter.counter_delta;
@@ -2108,7 +2112,7 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                           ))))
                   [] site_list
               in
-              let new_site_list : Ast.site list =
+              let new_site_list : Ast.counter Ast.site list =
                 site_list_with_opposite_deltas @ added_sites
               in
               Ast.Present (agent_name_, new_site_list, agent_mod))
@@ -2156,7 +2160,7 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                   counters_with_clte_tests
               in
               (* Add delta to counter as opposite deltas to counter_delta *)
-              let added_sites : Ast.site list =
+              let added_sites : Ast.counter Ast.site list =
                 List.fold_left
                   (fun acc site ->
                     match site with
@@ -2165,7 +2169,7 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                       (match
                          List.find_opt
                            (fun (_, name, _) ->
-                             String.equal (Loc.v counter.counter_name) name)
+                             String.equal (Loc.v counter.Ast.counter_name) name)
                            counters_with_clte_tests_from_agent
                        with
                       | None -> acc
@@ -2196,21 +2200,23 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
                             else
                               Ast.Counter
                                 {
-                                  counter_name =
+                                  Ast.counter_name =
                                     Loc.map_annot inverted_counter_name
-                                      counter.counter_name;
-                                  counter_test =
+                                      counter.Ast.counter_name;
+                                  Ast.counter_test =
                                     Some
                                       (Loc.copy_annot test
                                          (Ast.CEQ (!sum_bounds_ref - value)));
-                                  counter_delta =
-                                    counter.counter_delta
+                                  Ast.counter_delta =
+                                    counter.Ast.counter_delta
                                     (* 0 with annot as tested above *);
                                 }
                               :: acc))))
                   [] site_list
               in
-              let new_site_list : Ast.site list = site_list @ added_sites in
+              let new_site_list : Ast.counter Ast.site list =
+                site_list @ added_sites
+              in
               Ast.Present (agent_name_, new_site_list, agent_mod))
           agent_list)
       mix
diff --git a/core/grammar/lKappa_compiler.mli b/core/grammar/lKappa_compiler.mli
index 2bda34161..b728dd10d 100644
--- a/core/grammar/lKappa_compiler.mli
+++ b/core/grammar/lKappa_compiler.mli
@@ -46,6 +46,7 @@ type ast_compiled_data = {
   updated_alg_vars: int list;  (** alg vars with forbidden constant prop *)
   result:
     ( Ast.agent,
+      Ast.agent_sig,
       LKappa.rule_agent list,
       Raw_mixture.t,
       int,
diff --git a/core/simulation/dune b/core/simulation/dune
index 5ec333eb1..5a0efe983 100644
--- a/core/simulation/dune
+++ b/core/simulation/dune
@@ -14,9 +14,13 @@
    Kappa_terms)))
 
 ; Generate resource_strings.ml with the content of some files
+
 (rule
  (targets resource_strings.ml)
- (deps ../../dev/load_files_into_ocaml_string_vars.sh ../../gui/shared/flux.js ../../gui/viz/common.js)
+ (deps
+  ../../dev/load_files_into_ocaml_string_vars.sh
+  ../../gui/shared/flux.js
+  ../../gui/viz/common.js)
  (action
   (with-stdout-to
    %{targets}
diff --git a/core/siteGraphs/signature.ml b/core/siteGraphs/signature.ml
index 1230c298a..62d39cd8f 100644
--- a/core/siteGraphs/signature.ml
+++ b/core/siteGraphs/signature.ml
@@ -6,11 +6,16 @@
 (* |_|\_\ * GNU Lesser General Public License Version 3                       *)
 (******************************************************************************)
 
+type counter_info = {
+  counter_info_min: int option;
+  counter_info_max: int option;
+  counter_default_value: int;
+}
+
 type 'links site_sig = {
   internal_state: unit NamedDecls.t;
   links: 'links option;
-  counters_info: (int * int) option;
-      (** If relevant: counter CEQ value * counter delta *)
+  counter_info: counter_info option;
 }
 
 type t = bool array array site_sig NamedDecls.t
@@ -44,7 +49,7 @@ let internal_state_of_site_id site_id val_id signature =
   with Invalid_argument _ -> raise Not_found
 
 let counter_of_site_id site_id signature =
-  try (NamedDecls.elt_val signature site_id).counters_info
+  try (NamedDecls.elt_val signature site_id).counter_info
   with Invalid_argument _ -> raise Not_found
 
 let has_counter signature =
@@ -52,7 +57,7 @@ let has_counter signature =
     (fun p_id _ ok ->
       try
         let site_sig = NamedDecls.elt_val signature p_id in
-        ok || not (site_sig.counters_info = None)
+        ok || not (site_sig.counter_info = None)
       with Invalid_argument _ -> raise Not_found)
     false signature
 
@@ -84,15 +89,23 @@ let one_to_json =
                        :: acc)
                      links []))
               signature.links );
-          ( "counters_info",
+          ( "counter_info",
             JsonUtil.of_option
-              (fun (c1, c2) -> `List [ `Int c1; `Int c2 ])
-              signature.counters_info );
+              (fun c ->
+                `Assoc
+                  [
+                    ( "min",
+                      JsonUtil.of_option (fun x -> `Int x) c.counter_info_min );
+                    ( "max",
+                      JsonUtil.of_option (fun x -> `Int x) c.counter_info_max );
+                    "default", `Int c.counter_default_value;
+                  ])
+              signature.counter_info );
         ])
 
 let one_of_json : Yojson.Basic.t -> bool array array site_sig NamedDecls.t =
   NamedDecls.of_json (function
-    | `Assoc [ ("internal_state", a); ("links", b); ("counters_info", c) ] ->
+    | `Assoc [ ("internal_state", a); ("links", b); ("counter_info", c) ] ->
       {
         internal_state =
           NamedDecls.of_json
@@ -128,10 +141,32 @@ let one_of_json : Yojson.Basic.t -> bool array array site_sig NamedDecls.t =
                   (Yojson.Basic.Util.Type_error
                      ("Problematic agent signature", x)))
             b;
-        counters_info =
+        counter_info =
           Yojson.Basic.Util.to_option
             (function
-              | `List [ `Int c1; `Int c2 ] -> c1, c2
+              | `Assoc
+                  [ ("min", c1_opt); ("max", c2_opt); ("default", `Int c3) ] ->
+                {
+                  counter_info_min =
+                    Yojson.Basic.Util.to_option
+                      (function
+                        | `Int c -> c
+                        | x ->
+                          raise
+                            (Yojson.Basic.Util.Type_error
+                               ("Problematic agent signature", x)))
+                      c1_opt;
+                  counter_info_max =
+                    Yojson.Basic.Util.to_option
+                      (function
+                        | `Int c -> c
+                        | x ->
+                          raise
+                            (Yojson.Basic.Util.Type_error
+                               ("Problematic agent signature", x)))
+                      c2_opt;
+                  counter_default_value = c3;
+                }
               | x ->
                 raise
                   (Yojson.Basic.Util.Type_error
@@ -257,10 +292,24 @@ let print_site_internal_state sigs ag_ty site f = function
       (site_of_id ag_ty site sigs)
       (internal_state_of_id ag_ty site id sigs)
 
-let print_counter sigs ag_ty f id =
-  match counter_of_site_id id (get sigs ag_ty) with
+let print_counter_info f = function
   | None -> ()
-  | Some (c1, c2) -> Format.fprintf f "{=%d/+=%d}" c1 c2
+  | Some c ->
+    (match c.counter_info_min, c.counter_info_max with
+    | Some i, Some j when i = c.counter_default_value ->
+      Format.fprintf f "{=%d/+=%d}" i j
+    | i_opt, j_opt ->
+      Format.fprintf f "{-=%s/=%d/+=%s}"
+        (match i_opt with
+        | None -> "-oo"
+        | Some i -> Format.sprintf "%d" i)
+        c.counter_default_value
+        (match j_opt with
+        | None -> "-oo"
+        | Some i -> Format.sprintf "%d" i))
+
+let print_counter sigs ag_ty f id =
+  print_counter_info f (counter_of_site_id id (get sigs ag_ty))
 
 let print_one ?(sigs : s option) (i : int) (f : Format.formatter)
     (signature : t) =
@@ -287,15 +336,11 @@ let print_one ?(sigs : s option) (i : int) (f : Format.formatter)
                          si (print_agent sigs) (i + ag))))
             links)
   in
-  let pp_counts f = function
-    | None -> ()
-    | Some (c1, c2) -> Format.fprintf f "{=%d/+=%d}" c1 c2
-  in
   (NamedDecls.print
      ~sep:(fun f -> Format.fprintf f ",@,")
      (fun _ name f site_sig ->
        Format.fprintf f "%s%a%a%a" name pp_int site_sig.internal_state
-         (pp_link i) site_sig.links pp_counts site_sig.counters_info))
+         (pp_link i) site_sig.links print_counter_info site_sig.counter_info))
     f signature
 
 let print f sigs =
diff --git a/core/siteGraphs/signature.mli b/core/siteGraphs/signature.mli
index 57400ec8a..b23d35746 100644
--- a/core/siteGraphs/signature.mli
+++ b/core/siteGraphs/signature.mli
@@ -12,10 +12,17 @@
 (* TODO document what is internal state *)
 
 (* TODO *)
+
+type counter_info = {
+  counter_info_min: int option;
+  counter_info_max: int option;
+  counter_default_value: int;
+}
+
 type 'links site_sig = {
   internal_state: unit NamedDecls.t;
   links: 'links option;
-  counters_info: (int * int) option;
+  counter_info: counter_info option;
       (** If relevant: counter CEQ value * counter delta *)
 }
 
@@ -33,7 +40,7 @@ val num_of_internal_state : int -> string Loc.annoted -> t -> int
 val internal_state_of_site_id : int -> int -> t -> string
 (**[internal_state_of_site_id site_id value_id signature] *)
 
-val counter_of_site_id : int -> t -> (int * int) option
+val counter_of_site_id : int -> t -> counter_info option
 val has_counter : t -> bool
 
 type s
diff --git a/core/siteGraphs/snapshot.ml b/core/siteGraphs/snapshot.ml
index 61218631b..70d908202 100644
--- a/core/siteGraphs/snapshot.ml
+++ b/core/siteGraphs/snapshot.ml
@@ -210,7 +210,7 @@ let cc_to_user_cc ?(keep_inverted_counters : bool = false) ~debug_mode ~raw sigs
             (* Remove inverted counters from user snapshot *)
             node_sites_all |> Array.to_list
             |> List.filter (fun (site : User_graph.cc_site) : bool ->
-                   not(Signature.is_inverted_counter site.site_name))
+                   not (Signature.is_inverted_counter site.site_name))
             |> Array.of_list
         in
 
diff --git a/gui/dune b/gui/dune
index 1747a7b83..c5844b67b 100644
--- a/gui/dune
+++ b/gui/dune
@@ -8,13 +8,23 @@
 
 ; Windows build only has access to 4.0.0, where --disable flags don't exist yet in jsoo
 ; TODO: better distinguish this, as this should depend on jsoo version and not OS
-(rule (with-stdout-to js_of_ocaml_flags.Unix (echo "(:standard --disable globaldeadcode --disable deadcode)")))
-(rule (with-stdout-to js_of_ocaml_flags.Win32 (echo ":standard")))
+
+(rule
+ (with-stdout-to
+  js_of_ocaml_flags.Unix
+  (echo "(:standard --disable globaldeadcode --disable deadcode)")))
+
+(rule
+ (with-stdout-to
+  js_of_ocaml_flags.Win32
+  (echo ":standard")))
 
 (executable
  (name KaSimWorker)
  (modes js)
- (js_of_ocaml (flags (:include js_of_ocaml_flags.%{os_type})))
+ (js_of_ocaml
+  (flags
+   (:include js_of_ocaml_flags.%{os_type})))
  (modules KaSimWorker)
  (libraries kappa_js_lib kappa_json_api)
  (preprocess
@@ -33,7 +43,9 @@
 (executable
  (name KaSaWorker)
  (modes js)
- (js_of_ocaml (flags (:include js_of_ocaml_flags.%{os_type})))
+ (js_of_ocaml
+  (flags
+   (:include js_of_ocaml_flags.%{os_type})))
  (modules KaSaWorker)
  (libraries kappa_js_lib kappa_kasa_export)
  (preprocess
@@ -52,7 +64,9 @@
 (executable
  (name KaStorWorker)
  (modes js)
- (js_of_ocaml (flags (:include js_of_ocaml_flags.%{os_type})))
+ (js_of_ocaml
+  (flags
+   (:include js_of_ocaml_flags.%{os_type})))
  (modules KaStorWorker)
  (libraries kappa_js_lib kappa_cflow)
  (preprocess
@@ -71,7 +85,9 @@
 (executable
  (name KaMoHaWorker)
  (modes js)
- (js_of_ocaml (flags (:include js_of_ocaml_flags.%{os_type})))
+ (js_of_ocaml
+  (flags
+   (:include js_of_ocaml_flags.%{os_type})))
  (modules KaMoHaWorker)
  (libraries kappa_js_lib kappa_grammar)
  (preprocess
@@ -81,7 +97,9 @@
 (executable
  (name JsSim)
  (modes js)
- (js_of_ocaml (flags (:include js_of_ocaml_flags.%{os_type})))
+ (js_of_ocaml
+  (flags
+   (:include js_of_ocaml_flags.%{os_type})))
  (modules
   :standard
   \
@@ -129,6 +147,4 @@
   -open
   Kappa_logging
   -open
-  Kappa_cflow
-  )
- )
+  Kappa_cflow))
diff --git a/gui/state_project.ml b/gui/state_project.ml
index 02e3da62b..68612dbb7 100644
--- a/gui/state_project.ml
+++ b/gui/state_project.ml
@@ -223,12 +223,13 @@ let update_state me project_catalog default_parameters project_parameters =
     let st = React.S.value state in
     let () =
       set_state
-      { st with
-        project_current = Some me;
-        project_version = (st.project_version + 1);
-      }
-  in
-  Lwt.return out
+        {
+          st with
+          project_current = Some me;
+          project_version = st.project_version + 1;
+        }
+    in
+    Lwt.return out
 
 let computing_watcher manager setter =
   let delay = 1. in
diff --git a/gui/tab_flux.ml b/gui/tab_flux.ml
index 3eaa1563f..51ab41a1d 100644
--- a/gui/tab_flux.ml
+++ b/gui/tab_flux.ml
@@ -50,7 +50,8 @@ let din_data =
             (Lwt_react.E.from (fun () ->
                  Lwt.map
                    (Result_util.fold ~ok:(fun x -> x) ~error:(fun _ -> None))
-                   (State_simulation.eval_with_sim_manager_and_info ~label:__LOC__
+                   (State_simulation.eval_with_sim_manager_and_info
+                      ~label:__LOC__
                       ~stopped:(fun _ -> Lwt.return (Result_util.ok None))
                       ~initializing:(fun _ -> Lwt.return (Result_util.ok None))
                       ~ready:(fun manager _ ->
diff --git a/gui/tab_influences.ml b/gui/tab_influences.ml
index 7e55db8e9..3fbc6a3e9 100644
--- a/gui/tab_influences.ml
+++ b/gui/tab_influences.ml
@@ -190,7 +190,8 @@ let export_config =
             (fun filename ->
               Lwt.ignore_result
                 ( State_error.wrap "influence_map_export"
-                    (State_project.eval_with_project ~label:__LOC__ (fun manager ->
+                    (State_project.eval_with_project ~label:__LOC__
+                       (fun manager ->
                          let { accuracy; _ } = React.S.value model in
                          manager#get_influence_map_raw accuracy
                          >|= Result_util.map (fun influences_string ->
diff --git a/gui/tab_stories.ml b/gui/tab_stories.ml
index cf8b668b9..4bba41749 100644
--- a/gui/tab_stories.ml
+++ b/gui/tab_stories.ml
@@ -218,7 +218,8 @@ let onload () =
     (Tyxml_js.To_dom.of_button launch_button)##.onclick
     := Dom_html.handler (fun _ ->
            let _ =
-             State_project.eval_with_project ~label:"Launch stories" (fun manager ->
+             State_project.eval_with_project ~label:"Launch stories"
+               (fun manager ->
                  if manager#story_is_computing then
                    Lwt.return (Result_util.ok ())
                  else


Test patch:
diff --git a/tests/integration/cflows/cflows_json/output/cflow_Weakly_env.json.ref b/tests/integration/cflows/cflows_json/output/cflow_Weakly_env.json.ref
index f7547a330..de542730e 100644
--- a/tests/integration/cflows/cflows_json/output/cflow_Weakly_env.json.ref
+++ b/tests/integration/cflows/cflows_json/output/cflow_Weakly_env.json.ref
@@ -1,1 +1,1 @@
-{"filenames":["","json.ka"],"update":{"signatures":[{"name":"A","decl":[{"name":"a","decl":{"internal_state":[{"name":"u","decl":null},{"name":"p","decl":null}],"links":null,"counters_info":null}}]},{"name":"B","decl":[{"name":"a","decl":{"internal_state":[{"name":"u","decl":null},{"name":"p","decl":null}],"links":null,"counters_info":null}},{"name":"b","decl":{"internal_state":[],"links":null,"counters_info":null}}]}],"single_agents":[null,null],"elementaries":[[[[[[[1,0],0],[[2,1],1]],12],[[[[1,0],0],[[2,1],0]],11],[[[[1,0],0],1],10],[[[[1,0],0],0],9],[[[[1,0],0],null],8]]],[[[[[[1,0],0],[[2,1],0]],11],[[[[2,1],0],1],15],[[[[2,1],0],0],14],[[[[2,1],0],null],13]],[[[[[1,0],0],[[2,1],1]],12],[[[[2,1],1],null],16]]]],"dag":[{"content":null,"roots":null,"deps":[],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,1]]]},"roots":[[1],0],"deps":[["MODIF",0],["RULE",4],["RULE",2],["ALG",0]],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,1],[false,null]]]},"roots":[[2],1],"deps":[["MODIF",0],["RULE",2],["ALG",0]],"sons":[{"dst":7,"inj":[[2,2]],"nav":[[[2,1],null]]}]},{"content":{"sorts":[null,0,1,0],"nodes":[null,[[{"node":2,"site":0},1]],[[{"node":1,"site":0},1],[{"node":3,"site":0},null]],[[{"node":2,"site":1},1]]]},"roots":[[1],0],"deps":[["MODIF",1],["ALG",1]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,0]]]},"roots":[[1],0],"deps":[["RULE",0]],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,0],[false,null]]]},"roots":[[2],1],"deps":[["RULE",1]],"sons":[]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},1]],[[{"node":1,"site":0},1],[false,null]]]},"roots":[[1],0],"deps":[["RULE",3]],"sons":[{"dst":3,"inj":[[3,3],[2,2],[1,1]],"nav":[[[2,1],[[3,0],0]],[[3,0],1]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,1],[true,null]]]},"roots":[[2],1],"deps":[["RULE",4]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,null]]]},"roots":null,"deps":[],"sons":[{"dst":1,"inj":[[1,1]],"nav":[[[1,0],1]]},{"dst":4,"inj":[[1,1]],"nav":[[[1,0],0]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,0]]]},"roots":null,"deps":[],"sons":[{"dst":4,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,1]]]},"roots":null,"deps":[],"sons":[{"dst":3,"inj":[[3,1],[2,2],[1,3]],"nav":[[[1,0],[[2,1],1]],[[2,0],[[3,0],0]],[[2,0],1],[[3,0],1]]},{"dst":6,"inj":[[2,2],[1,1]],"nav":[[[1,0],[[2,1],0]],[[2,0],1]]},{"dst":1,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},null]],[[{"node":1,"site":0},null],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":6,"inj":[[2,2],[1,1]],"nav":[[[2,0],1],[[1,0],1]]}]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":1},null]],[[false,null],[{"node":1,"site":0},null]]]},"roots":null,"deps":[],"sons":[{"dst":3,"inj":[[3,1],[2,2],[1,3]],"nav":[[[2,0],[[3,0],0]],[[1,0],1],[[2,0],1],[[3,0],1]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,null],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":2,"inj":[[2,2]],"nav":[[[2,0],1]]},{"dst":5,"inj":[[2,2]],"nav":[[[2,0],0]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,0],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":5,"inj":[[2,2]],"nav":[[[2,0],null]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,1],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":6,"inj":[[2,2],[1,1]],"nav":[[[2,0],[[1,0],0]],[[1,0],1]]},{"dst":2,"inj":[[2,2]],"nav":[[[2,0],null]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,null],[true,null]]]},"roots":null,"deps":[],"sons":[{"dst":7,"inj":[[2,2]],"nav":[[[2,0],null],[[2,0],1]]}]}],"id_by_type":[[1,3],[2]],"max_obs":17},"tokens":[],"algs":[{"name":"ApBp","decl":["MIX",[[1,2]]]},{"name":"ABA","decl":["MIX",[[3]]]}],"observables":["[T]",["VAR",0],["VAR",1]],"ast_rules":[["Ap",{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},"Maintained"]],"states":[[0,1]],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":4,"bchr":32,"echr":36}},"unary_rate":null,"edit_style":false}],["Bp",{"mixture":[{"type":1,"bindings":[[{"val":"FREE"},"Maintained"],[{"val":null},"Maintained"]],"states":[[0,1],null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":5,"bchr":32,"echr":36}},"unary_rate":null,"edit_style":false}],["A.B",{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[1,1]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1],[{"val":null},"Maintained"]],"states":[[1,1],null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":7,"bchr":57,"echr":61}},"unary_rate":null,"edit_style":false}],["A..B",{"mixture":[{"type":0,"bindings":[[{"val":[1,0,1],"loc":{"file":1,"bline":8,"bchr":14,"echr":15}},"Freed"]],"states":[[1,1]],"erased":false},{"type":1,"bindings":[[{"val":[1,0,0],"loc":{"file":1,"bline":8,"bchr":26,"echr":27}},"Freed"],[{"val":null},"Maintained"]],"states":[[1,1],null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":8,"bchr":58,"echr":62}},"unary_rate":null,"edit_style":false}],["A.B.A",{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[1,1]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1],[{"val":"FREE"},2]],"states":[[1,1],null],"erased":false},{"type":0,"bindings":[[{"val":"FREE"},2]],"states":[[1,1]],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":9,"bchr":93,"echr":97}},"unary_rate":null,"edit_style":false}]],"elementary_rules":[{"rate":{"val":0.01,"loc":{"file":1,"bline":4,"bchr":32,"echr":36}},"connected_components":[4],"removed":[{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"PositiveInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0,1]}],"syntactic_rule":1,"instantiations":[[[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],0],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":5,"bchr":32,"echr":36}},"connected_components":[5],"removed":[{"NegativeInternalized":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]}],"inserted":[{"PositiveInternalized":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,1]}],"syntactic_rule":2,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],0],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":7,"bchr":57,"echr":61}},"connected_components":[1,2],"removed":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":3,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":8,"bchr":58,"echr":62}},"connected_components":[6],"removed":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":4,"instantiations":[[[[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[4,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[4,[{"Existing":[{"agent":[2,1]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":9,"bchr":93,"echr":97}},"connected_components":[1,7,1],"removed":[{"Freed":[{"Existing":[{"agent":[1,0]},{"type":2}]},0]},{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},1]},{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[1,0]},{"type":2}]},0,{"Existing":[{"agent":[2,1]},{"type":1}]},1]},{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":5,"instantiations":[[[[2,[{"Existing":[{"agent":[1,0]},{"type":2}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":2}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":2}]}]],[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},1]],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[2,[{"Existing":[{"agent":[1,0]},{"type":2}]},0],[{"Existing":[{"agent":[2,1]},{"type":1}]},1]],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]}],"contact_map":[[[[1,0],[[1,1],[1,0]]]],[[[1,0],[[0,0]]],[[],[[0,0]]]]],"interventions":[{"alarm":null,"condition":{"val":true,"loc":{"file":1,"bline":14,"bchr":6,"echr":12}},"effect":[{"action":"CFLOW","name":"ApBp","pattern":[1,2],"tests":[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]]}],"repeat":{"val":false},"needs_backtrack":false},{"alarm":null,"condition":{"val":true,"loc":{"file":1,"bline":15,"bchr":6,"echr":12}},"effect":[{"action":"CFLOW","name":"ABA","pattern":[3],"tests":[[[5,[{"Existing":[{"agent":[3,0]},{"type":0}]},0],[{"Existing":[{"agent":[2,1]},{"type":0}]},1]],[1,[{"Existing":[{"agent":[3,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[3,0]},{"type":0}]}],[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]]}],"repeat":{"val":false},"needs_backtrack":false}],"dependencies_in_time":[],"dependencies_in_event":[],"algs_reverse_dependencies":[[],[]],"tokens_reverse_dependencies":[]}
+{"filenames":["","json.ka"],"update":{"signatures":[{"name":"A","decl":[{"name":"a","decl":{"internal_state":[{"name":"u","decl":null},{"name":"p","decl":null}],"links":null,"counter_info":null}}]},{"name":"B","decl":[{"name":"a","decl":{"internal_state":[{"name":"u","decl":null},{"name":"p","decl":null}],"links":null,"counter_info":null}},{"name":"b","decl":{"internal_state":[],"links":null,"counter_info":null}}]}],"single_agents":[null,null],"elementaries":[[[[[[[1,0],0],[[2,1],1]],12],[[[[1,0],0],[[2,1],0]],11],[[[[1,0],0],1],10],[[[[1,0],0],0],9],[[[[1,0],0],null],8]]],[[[[[[1,0],0],[[2,1],0]],11],[[[[2,1],0],1],15],[[[[2,1],0],0],14],[[[[2,1],0],null],13]],[[[[[1,0],0],[[2,1],1]],12],[[[[2,1],1],null],16]]]],"dag":[{"content":null,"roots":null,"deps":[],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,1]]]},"roots":[[1],0],"deps":[["MODIF",0],["RULE",4],["RULE",2],["ALG",0]],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,1],[false,null]]]},"roots":[[2],1],"deps":[["MODIF",0],["RULE",2],["ALG",0]],"sons":[{"dst":7,"inj":[[2,2]],"nav":[[[2,1],null]]}]},{"content":{"sorts":[null,0,1,0],"nodes":[null,[[{"node":2,"site":0},1]],[[{"node":1,"site":0},1],[{"node":3,"site":0},null]],[[{"node":2,"site":1},1]]]},"roots":[[1],0],"deps":[["MODIF",1],["ALG",1]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,0]]]},"roots":[[1],0],"deps":[["RULE",0]],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,0],[false,null]]]},"roots":[[2],1],"deps":[["RULE",1]],"sons":[]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},1]],[[{"node":1,"site":0},1],[false,null]]]},"roots":[[1],0],"deps":[["RULE",3]],"sons":[{"dst":3,"inj":[[3,3],[2,2],[1,1]],"nav":[[[2,1],[[3,0],0]],[[3,0],1]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,1],[true,null]]]},"roots":[[2],1],"deps":[["RULE",4]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,null]]]},"roots":null,"deps":[],"sons":[{"dst":1,"inj":[[1,1]],"nav":[[[1,0],1]]},{"dst":4,"inj":[[1,1]],"nav":[[[1,0],0]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,0]]]},"roots":null,"deps":[],"sons":[{"dst":4,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,1]]]},"roots":null,"deps":[],"sons":[{"dst":3,"inj":[[3,1],[2,2],[1,3]],"nav":[[[1,0],[[2,1],1]],[[2,0],[[3,0],0]],[[2,0],1],[[3,0],1]]},{"dst":6,"inj":[[2,2],[1,1]],"nav":[[[1,0],[[2,1],0]],[[2,0],1]]},{"dst":1,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},null]],[[{"node":1,"site":0},null],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":6,"inj":[[2,2],[1,1]],"nav":[[[2,0],1],[[1,0],1]]}]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":1},null]],[[false,null],[{"node":1,"site":0},null]]]},"roots":null,"deps":[],"sons":[{"dst":3,"inj":[[3,1],[2,2],[1,3]],"nav":[[[2,0],[[3,0],0]],[[1,0],1],[[2,0],1],[[3,0],1]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,null],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":2,"inj":[[2,2]],"nav":[[[2,0],1]]},{"dst":5,"inj":[[2,2]],"nav":[[[2,0],0]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,0],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":5,"inj":[[2,2]],"nav":[[[2,0],null]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,1],[false,null]]]},"roots":null,"deps":[],"sons":[{"dst":6,"inj":[[2,2],[1,1]],"nav":[[[2,0],[[1,0],0]],[[1,0],1]]},{"dst":2,"inj":[[2,2]],"nav":[[[2,0],null]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,null],[true,null]]]},"roots":null,"deps":[],"sons":[{"dst":7,"inj":[[2,2]],"nav":[[[2,0],null],[[2,0],1]]}]}],"id_by_type":[[1,3],[2]],"max_obs":17},"tokens":[],"algs":[{"name":"ApBp","decl":["MIX",[[1,2]]]},{"name":"ABA","decl":["MIX",[[3]]]}],"observables":["[T]",["VAR",0],["VAR",1]],"ast_rules":[["Ap",{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},"Maintained"]],"states":[[0,1]],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":4,"bchr":32,"echr":36}},"unary_rate":null,"edit_style":false}],["Bp",{"mixture":[{"type":1,"bindings":[[{"val":"FREE"},"Maintained"],[{"val":null},"Maintained"]],"states":[[0,1],null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":5,"bchr":32,"echr":36}},"unary_rate":null,"edit_style":false}],["A.B",{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[1,1]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1],[{"val":null},"Maintained"]],"states":[[1,1],null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":7,"bchr":57,"echr":61}},"unary_rate":null,"edit_style":false}],["A..B",{"mixture":[{"type":0,"bindings":[[{"val":[1,0,1],"loc":{"file":1,"bline":8,"bchr":14,"echr":15}},"Freed"]],"states":[[1,1]],"erased":false},{"type":1,"bindings":[[{"val":[1,0,0],"loc":{"file":1,"bline":8,"bchr":26,"echr":27}},"Freed"],[{"val":null},"Maintained"]],"states":[[1,1],null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":8,"bchr":58,"echr":62}},"unary_rate":null,"edit_style":false}],["A.B.A",{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[1,1]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1],[{"val":"FREE"},2]],"states":[[1,1],null],"erased":false},{"type":0,"bindings":[[{"val":"FREE"},2]],"states":[[1,1]],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":0.01,"loc":{"file":1,"bline":9,"bchr":93,"echr":97}},"unary_rate":null,"edit_style":false}]],"elementary_rules":[{"rate":{"val":0.01,"loc":{"file":1,"bline":4,"bchr":32,"echr":36}},"connected_components":[4],"removed":[{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"PositiveInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0,1]}],"syntactic_rule":1,"instantiations":[[[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],0],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":5,"bchr":32,"echr":36}},"connected_components":[5],"removed":[{"NegativeInternalized":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]}],"inserted":[{"PositiveInternalized":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,1]}],"syntactic_rule":2,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],0],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":7,"bchr":57,"echr":61}},"connected_components":[1,2],"removed":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":3,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":8,"bchr":58,"echr":62}},"connected_components":[6],"removed":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":4,"instantiations":[[[[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[4,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[4,[{"Existing":[{"agent":[2,1]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":0.01,"loc":{"file":1,"bline":9,"bchr":93,"echr":97}},"connected_components":[1,7,1],"removed":[{"Freed":[{"Existing":[{"agent":[1,0]},{"type":2}]},0]},{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},1]},{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[1,0]},{"type":2}]},0,{"Existing":[{"agent":[2,1]},{"type":1}]},1]},{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":5,"instantiations":[[[[2,[{"Existing":[{"agent":[1,0]},{"type":2}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":2}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":2}]}]],[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},1]],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[2,[{"Existing":[{"agent":[1,0]},{"type":2}]},0],[{"Existing":[{"agent":[2,1]},{"type":1}]},1]],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]}],"contact_map":[[[[1,0],[[1,1],[1,0]]]],[[[1,0],[[0,0]]],[[],[[0,0]]]]],"interventions":[{"alarm":null,"condition":{"val":true,"loc":{"file":1,"bline":14,"bchr":6,"echr":12}},"effect":[{"action":"CFLOW","name":"ApBp","pattern":[1,2],"tests":[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]]}],"repeat":{"val":false},"needs_backtrack":false},{"alarm":null,"condition":{"val":true,"loc":{"file":1,"bline":15,"bchr":6,"echr":12}},"effect":[{"action":"CFLOW","name":"ABA","pattern":[3],"tests":[[[5,[{"Existing":[{"agent":[3,0]},{"type":0}]},0],[{"Existing":[{"agent":[2,1]},{"type":0}]},1]],[1,[{"Existing":[{"agent":[3,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[3,0]},{"type":0}]}],[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]]}],"repeat":{"val":false},"needs_backtrack":false}],"dependencies_in_time":[],"dependencies_in_event":[],"algs_reverse_dependencies":[[],[]],"tokens_reverse_dependencies":[]}
diff --git a/tests/integration/cflows/side-effects3/output/trace.json.ref b/tests/integration/cflows/side-effects3/output/trace.json.ref
index b43e71a64..21db665c6 100644
--- a/tests/integration/cflows/side-effects3/output/trace.json.ref
+++ b/tests/integration/cflows/side-effects3/output/trace.json.ref
@@ -1,5 +1,5 @@
 {
 "dict":{"agent":{"id":0,"type":1},"binding_type":{"type":0,"site":1},"quark":{"agent":0,"site":1},"test":["Is_here","Has_Internal","Is_Free","Is_Bound","Has_Binding_type","Is_Bound_to"],"actions":["Create","Mod_internal","Bind","Bind_to","Free","Remove"],"binding_state":["ANY","FREE","BOUND","BOUND_TYPE","BOUND_to"],"event":{"tests":0,"actions":1,"side_effect_src":2,"side_effect_dst":3,"connectivity_tests":4},"simulation_info":{"id":0,"time":1,"event":2,"profiling":3},"step":["Subs","Rule","Pert","Init","Obs","Dummy"]},
-"model":{"filenames":["","side-effects.ka"],"update":{"signatures":[{"name":"A","decl":[{"name":"x","decl":{"internal_state":[{"name":"a","decl":null},{"name":"b","decl":null}],"links":null,"counters_info":null}}]},{"name":"B","decl":[{"name":"x","decl":{"internal_state":[{"name":"a","decl":null},{"name":"b","decl":null}],"links":null,"counters_info":null}}]},{"name":"C","decl":[]}],"single_agents":[null,null,null],"elementaries":[[[[[[[1,0],0],[[2,1],0]],1],[[[[1,0],0],1],8],[[[[1,0],0],0],7],[[[[1,0],0],null],6]]],[[[[[[1,0],0],[[2,1],0]],1],[[[[2,1],0],1],10],[[[[2,1],0],0],9],[[[[2,1],0],null],3]]],[]],"dag":[{"content":null,"roots":null,"deps":[],"sons":[]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},null]],[[{"node":1,"site":0},null]]]},"roots":[[1],0],"deps":[["RULE",1]],"sons":[{"dst":5,"inj":[[2,2],[1,1]],"nav":[[[2,0],1],[[1,0],1]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[true,0]]]},"roots":[[1],0],"deps":[["RULE",2]],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,null]]]},"roots":[[2],1],"deps":[["RULE",3],["RULE",2]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,1]]]},"roots":[[1],0],"deps":[["RULE",3]],"sons":[]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},1]],[[{"node":1,"site":0},1]]]},"roots":[[1],0],"deps":[["MODIF",0],["RULE",4]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,null]]]},"roots":null,"deps":[],"sons":[{"dst":4,"inj":[[1,1]],"nav":[[[1,0],1]]},{"dst":2,"inj":[[1,1]],"nav":[[[1,0],0]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,0]]]},"roots":null,"deps":[],"sons":[{"dst":2,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,1]]]},"roots":null,"deps":[],"sons":[{"dst":5,"inj":[[2,2],[1,1]],"nav":[[[1,0],[[2,1],0]],[[2,0],1]]},{"dst":4,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,0]]]},"roots":null,"deps":[],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,1]]]},"roots":null,"deps":[],"sons":[{"dst":5,"inj":[[2,2],[1,1]],"nav":[[[2,0],[[1,0],0]],[[1,0],1]]}]}],"id_by_type":[[1],[2],[]],"max_obs":11},"tokens":[],"algs":[],"observables":["[T]"],"ast_rules":[[null,{"mixture":[],"created":[{"type":2,"sites":[],"internals":[]}],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":1,"bchr":11,"echr":12}},"unary_rate":null,"edit_style":false}],[null,{"mixture":[{"type":0,"bindings":[[{"val":"SOME","loc":{"file":1,"bline":2,"bchr":4,"echr":5}},"Freed"]],"states":[null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":2,"bchr":21,"echr":22}},"unary_rate":null,"edit_style":false}],[null,{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[0,1]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1]],"states":[null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":3,"bchr":43,"echr":44}},"unary_rate":null,"edit_style":false}],[null,{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[1,0]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1]],"states":[null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":4,"bchr":43,"echr":44}},"unary_rate":null,"edit_style":false}],["GOAL",{"mixture":[{"type":0,"bindings":[[{"val":[1,0,1],"loc":{"file":1,"bline":5,"bchr":14,"echr":15}},"Erased"]],"states":[[1,"ERASED"]],"erased":true},{"type":1,"bindings":[[{"val":[1,0,0],"loc":{"file":1,"bline":5,"bchr":25,"echr":26}},"Erased"]],"states":[[1,"ERASED"]],"erased":true}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":5,"bchr":38,"echr":39}},"unary_rate":null,"edit_style":false}]],"elementary_rules":[{"rate":{"val":1,"loc":{"file":1,"bline":1,"bchr":11,"echr":12}},"inserted":[{"Agent":{"Fresh":{"id":2,"type":0}}}],"syntactic_rule":1,"instantiations":[[],[[0,{"Fresh":{"id":2,"type":0}},[]]],[],[],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":2,"bchr":21,"echr":22}},"connected_components":[1],"removed":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":2,"instantiations":[[[[3,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[4,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[[[{"Existing":[{"agent":[1,0]},{"type":0}]},0],[2]]],[[{"Existing":[{"agent":[2,1]},{"type":0}]},0]],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":3,"bchr":43,"echr":44}},"connected_components":[2,3],"removed":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"PositiveInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0,1]}],"syntactic_rule":3,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],0],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":4,"bchr":43,"echr":44}},"connected_components":[4,3],"removed":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"PositiveInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0,0]}],"syntactic_rule":4,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],0],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":5,"bchr":38,"echr":39}},"connected_components":[5],"removed":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"NegativeInternalized":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]},{"Agent":{"Existing":[{"agent":[2,1]},{"type":0}]}},{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"Agent":{"Existing":[{"agent":[1,0]},{"type":0}]}}],"syntactic_rule":5,"instantiations":[[[[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[5,{"Existing":[{"agent":[1,0]},{"type":0}]}],[5,{"Existing":[{"agent":[2,1]},{"type":0}]}]],[],[],[]]}],"contact_map":[[],[[[1,0],[[0,0]]]],[[[1,0],[[1,0]]]]],"interventions":[{"alarm":null,"condition":{"val":true,"loc":{"file":1,"bline":10,"bchr":6,"echr":12}},"effect":[{"action":"CFLOW","name":"GOAL","pattern":[5],"tests":[[[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]]}],"repeat":{"val":false},"needs_backtrack":false}],"dependencies_in_time":[],"dependencies_in_event":[],"algs_reverse_dependencies":[],"tokens_reverse_dependencies":[]},
+"model":{"filenames":["","side-effects.ka"],"update":{"signatures":[{"name":"A","decl":[{"name":"x","decl":{"internal_state":[{"name":"a","decl":null},{"name":"b","decl":null}],"links":null,"counter_info":null}}]},{"name":"B","decl":[{"name":"x","decl":{"internal_state":[{"name":"a","decl":null},{"name":"b","decl":null}],"links":null,"counter_info":null}}]},{"name":"C","decl":[]}],"single_agents":[null,null,null],"elementaries":[[[[[[[1,0],0],[[2,1],0]],1],[[[[1,0],0],1],8],[[[[1,0],0],0],7],[[[[1,0],0],null],6]]],[[[[[[1,0],0],[[2,1],0]],1],[[[[2,1],0],1],10],[[[[2,1],0],0],9],[[[[2,1],0],null],3]]],[]],"dag":[{"content":null,"roots":null,"deps":[],"sons":[]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},null]],[[{"node":1,"site":0},null]]]},"roots":[[1],0],"deps":[["RULE",1]],"sons":[{"dst":5,"inj":[[2,2],[1,1]],"nav":[[[2,0],1],[[1,0],1]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[true,0]]]},"roots":[[1],0],"deps":[["RULE",2]],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[true,null]]]},"roots":[[2],1],"deps":[["RULE",3],["RULE",2]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,1]]]},"roots":[[1],0],"deps":[["RULE",3]],"sons":[]},{"content":{"sorts":[null,0,1],"nodes":[null,[[{"node":2,"site":0},1]],[[{"node":1,"site":0},1]]]},"roots":[[1],0],"deps":[["MODIF",0],["RULE",4]],"sons":[]},{"content":{"sorts":[null,0],"nodes":[null,[[true,null]]]},"roots":null,"deps":[],"sons":[{"dst":4,"inj":[[1,1]],"nav":[[[1,0],1]]},{"dst":2,"inj":[[1,1]],"nav":[[[1,0],0]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,0]]]},"roots":null,"deps":[],"sons":[{"dst":2,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,0],"nodes":[null,[[false,1]]]},"roots":null,"deps":[],"sons":[{"dst":5,"inj":[[2,2],[1,1]],"nav":[[[1,0],[[2,1],0]],[[2,0],1]]},{"dst":4,"inj":[[1,1]],"nav":[[[1,0],null]]}]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,0]]]},"roots":null,"deps":[],"sons":[]},{"content":{"sorts":[null,null,1],"nodes":[null,null,[[false,1]]]},"roots":null,"deps":[],"sons":[{"dst":5,"inj":[[2,2],[1,1]],"nav":[[[2,0],[[1,0],0]],[[1,0],1]]}]}],"id_by_type":[[1],[2],[]],"max_obs":11},"tokens":[],"algs":[],"observables":["[T]"],"ast_rules":[[null,{"mixture":[],"created":[{"type":2,"sites":[],"internals":[]}],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":1,"bchr":11,"echr":12}},"unary_rate":null,"edit_style":false}],[null,{"mixture":[{"type":0,"bindings":[[{"val":"SOME","loc":{"file":1,"bline":2,"bchr":4,"echr":5}},"Freed"]],"states":[null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":2,"bchr":21,"echr":22}},"unary_rate":null,"edit_style":false}],[null,{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[0,1]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1]],"states":[null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":3,"bchr":43,"echr":44}},"unary_rate":null,"edit_style":false}],[null,{"mixture":[{"type":0,"bindings":[[{"val":"FREE"},1]],"states":[[1,0]],"erased":false},{"type":1,"bindings":[[{"val":"FREE"},1]],"states":[null],"erased":false}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":4,"bchr":43,"echr":44}},"unary_rate":null,"edit_style":false}],["GOAL",{"mixture":[{"type":0,"bindings":[[{"val":[1,0,1],"loc":{"file":1,"bline":5,"bchr":14,"echr":15}},"Erased"]],"states":[[1,"ERASED"]],"erased":true},{"type":1,"bindings":[[{"val":[1,0,0],"loc":{"file":1,"bline":5,"bchr":25,"echr":26}},"Erased"]],"states":[[1,"ERASED"]],"erased":true}],"created":[],"delta_tokens":[],"rate":{"val":1,"loc":{"file":1,"bline":5,"bchr":38,"echr":39}},"unary_rate":null,"edit_style":false}]],"elementary_rules":[{"rate":{"val":1,"loc":{"file":1,"bline":1,"bchr":11,"echr":12}},"inserted":[{"Agent":{"Fresh":{"id":2,"type":0}}}],"syntactic_rule":1,"instantiations":[[],[[0,{"Fresh":{"id":2,"type":0}},[]]],[],[],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":2,"bchr":21,"echr":22}},"connected_components":[1],"removed":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"syntactic_rule":2,"instantiations":[[[[3,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[4,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[[[{"Existing":[{"agent":[1,0]},{"type":0}]},0],[2]]],[[{"Existing":[{"agent":[2,1]},{"type":0}]},0]],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":3,"bchr":43,"echr":44}},"connected_components":[2,3],"removed":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"PositiveInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0,1]}],"syntactic_rule":3,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],0],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":4,"bchr":43,"echr":44}},"connected_components":[4,3],"removed":[{"Freed":[{"Existing":[{"agent":[2,1]},{"type":1}]},0]},{"Freed":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]}],"inserted":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":1}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"PositiveInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0,0]}],"syntactic_rule":4,"instantiations":[[[[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0]],[0,{"Existing":[{"agent":[2,1]},{"type":1}]}]],[[2,[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],0],[2,[{"Existing":[{"agent":[2,1]},{"type":1}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]]],[],[],[]]},{"rate":{"val":1,"loc":{"file":1,"bline":5,"bchr":38,"echr":39}},"connected_components":[5],"removed":[{"Linked":[{"Existing":[{"agent":[2,1]},{"type":0}]},0,{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"NegativeInternalized":[{"Existing":[{"agent":[2,1]},{"type":0}]},0]},{"Agent":{"Existing":[{"agent":[2,1]},{"type":0}]}},{"NegativeInternalized":[{"Existing":[{"agent":[1,0]},{"type":0}]},0]},{"Agent":{"Existing":[{"agent":[1,0]},{"type":0}]}}],"syntactic_rule":5,"instantiations":[[[[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]],[[5,{"Existing":[{"agent":[1,0]},{"type":0}]}],[5,{"Existing":[{"agent":[2,1]},{"type":0}]}]],[],[],[]]}],"contact_map":[[],[[[1,0],[[0,0]]]],[[[1,0],[[1,0]]]]],"interventions":[{"alarm":null,"condition":{"val":true,"loc":{"file":1,"bline":10,"bchr":6,"echr":12}},"effect":[{"action":"CFLOW","name":"GOAL","pattern":[5],"tests":[[[5,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],[{"Existing":[{"agent":[1,0]},{"type":0}]},0]],[1,[{"Existing":[{"agent":[2,1]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[2,1]},{"type":0}]}],[1,[{"Existing":[{"agent":[1,0]},{"type":0}]},0],1],[0,{"Existing":[{"agent":[1,0]},{"type":0}]}]]]}],"repeat":{"val":false},"needs_backtrack":false}],"dependencies_in_time":[],"dependencies_in_event":[],"algs_reverse_dependencies":[],"tokens_reverse_dependencies":[]},
 "trace":[[3,[[0,[0,0],[[0,0]]],[0,[1,1],[[0,1]]],[3,[[1,1],0],[[0,0],0]],[3,[[0,0],0],[[1,1],0]],[1,[[1,1],0],1],[1,[[0,0],0],0]]],[3,[[0,[2,1],[[0,0]]],[4,[[2,1],0]],[1,[[2,1],0],0]]],[3,[[0,[3,1],[[0,0]]],[4,[[3,1],0]],[1,[[3,1],0],0]]],[3,[[0,[4,1],[[0,0]]],[4,[[4,1],0]],[1,[[4,1],0],0]]],[3,[[0,[5,1],[[0,0]]],[4,[[5,1],0]],[1,[[5,1],0],0]]],[3,[[0,[6,1],[[0,0]]],[4,[[6,1],0]],[1,[[6,1],0],0]]],[3,[[0,[7,1],[[0,0]]],[4,[[7,1],0]],[1,[[7,1],0],0]]],[3,[[0,[8,1],[[0,0]]],[4,[[8,1],0]],[1,[[8,1],0],0]]],[3,[[0,[9,1],[[0,0]]],[4,[[9,1],0]],[1,[[9,1],0],0]]],[3,[[0,[10,1],[[0,0]]],[4,[[10,1],0]],[1,[[10,1],0],0]]],[3,[[0,[11,1],[[0,0]]],[4,[[11,1],0]],[1,[[11,1],0],0]]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[1,1],0]],[]],[-1,0.13823092776645854,1,null]],[1,2,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[-1,0.2336477634914299,2,null]],[1,0,[[],[[0,[12,2],[]]],[],[],[]],[-1,0.6020852152278433,3,null]],[1,0,[[],[[0,[13,2],[]]],[],[],[]],[-1,0.753963826966871,4,null]],[1,0,[[],[[0,[14,2],[]]],[],[],[]],[-1,1.1857271317886693,5,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[-1,1.4479897575337672,6,null]],[1,3,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[-1,1.626526792640157,7,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[-1,1.694399269405521,8,null]],[1,2,[[[[0,[7,1]],[2,[[7,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[7,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[-1,1.7360715939394153,9,null]],[1,0,[[],[[0,[15,2],[]]],[],[],[]],[-1,2.459919167473559,10,null]],[1,0,[[],[[0,[16,2],[]]],[],[],[]],[-1,2.5812814214359765,11,null]],[1,0,[[],[[0,[17,2],[]]],[],[],[]],[-1,2.667802570951534,12,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[7,1],0]],[]],[-1,2.7597142370975534,13,null]],[1,3,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[-1,2.805247638580207,14,null]],[1,0,[[],[[0,[18,2],[]]],[],[],[]],[-1,3.3537951297472084,15,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[-1,3.488364089958148,16,null]],[1,2,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[-1,3.4909102221521375,17,null]],[1,0,[[],[[0,[19,2],[]]],[],[],[]],[-1,3.645170784457633,18,null]],[1,0,[[],[[0,[20,2],[]]],[],[],[]],[-1,3.9423458730348933,19,null]],[1,0,[[],[[0,[21,2],[]]],[],[],[]],[-1,4.341679746398391,20,null]],[1,0,[[],[[0,[22,2],[]]],[],[],[]],[-1,4.434357796224944,21,null]],[1,0,[[],[[0,[23,2],[]]],[],[],[]],[-1,4.916008520028986,22,null]],[1,0,[[],[[0,[24,2],[]]],[],[],[]],[-1,5.080240108051781,23,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[-1,5.938225320375272,24,null]],[1,3,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[-1,5.998992351062857,25,null]],[1,0,[[],[[0,[25,2],[]]],[],[],[]],[-1,6.041503777915859,26,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[-1,7.304262330229044,27,null]],[1,2,[[[[0,[6,1]],[2,[[6,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[6,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[-1,7.37483820694515,28,null]],[1,0,[[],[[0,[26,2],[]]],[],[],[]],[-1,8.020261029820229,29,null]],[1,0,[[],[[0,[27,2],[]]],[],[],[]],[-1,8.026326967284767,30,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[6,1],0]],[]],[-1,8.573087115389793,31,null]],[1,3,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[-1,8.648001700685402,32,null]],[1,0,[[],[[0,[28,2],[]]],[],[],[]],[-1,9.79735928173821,33,null]],[1,0,[[],[[0,[29,2],[]]],[],[],[]],[-1,10.225470481224072,34,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[-1,10.255129992912112,35,null]],[1,2,[[[[0,[1,1]],[2,[[1,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[1,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[-1,10.330258056457728,36,null]],[4,"GOAL",[[[5,[[1,1],0],[[0,0],0]],[1,[[1,1],0],1],[0,[1,1]],[1,[[0,0],0],1],[0,[0,0]]]],[0,10.330258056457728,36,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[1,1],0]],[]],[0,10.43488219113191,37,null]],[1,3,[[[[0,[5,1]],[2,[[5,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[5,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,10.461288453408391,38,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[5,1],0]],[]],[0,10.74278735319708,39,null]],[1,2,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,10.800242424294126,40,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[0,11.105090715503655,41,null]],[1,3,[[[[0,[8,1]],[2,[[8,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[8,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,11.113446152479197,42,null]],[1,0,[[],[[0,[30,2],[]]],[],[],[]],[0,11.418490200525016,43,null]],[1,0,[[],[[0,[31,2],[]]],[],[],[]],[0,11.724351651371544,44,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[8,1],0]],[]],[0,12.471429005391435,45,null]],[1,0,[[],[[0,[32,2],[]]],[],[],[]],[0,12.486124450221796,46,null]],[1,2,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,12.76768321179996,47,null]],[1,0,[[],[[0,[33,2],[]]],[],[],[]],[0,13.024225497191784,48,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[0,15.925201543346688,49,null]],[1,3,[[[[0,[4,1]],[2,[[4,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[4,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,15.956692460372864,50,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[4,1],0]],[]],[0,16.95516113865209,51,null]],[1,2,[[[[0,[7,1]],[2,[[7,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[7,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,17.006031537627784,52,null]],[1,0,[[],[[0,[34,2],[]]],[],[],[]],[0,18.762982130501385,53,null]],[1,0,[[],[[0,[35,2],[]]],[],[],[]],[0,18.908988252459206,54,null]],[1,0,[[],[[0,[36,2],[]]],[],[],[]],[0,18.97850904982092,55,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[7,1],0]],[]],[0,19.23808623142504,56,null]],[1,3,[[[[0,[1,1]],[2,[[1,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[1,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,19.44815534655682,57,null]],[1,0,[[],[[0,[37,2],[]]],[],[],[]],[0,19.994623189169175,58,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[1,1],0]],[]],[0,20.638077346545646,59,null]],[1,2,[[[[0,[4,1]],[2,[[4,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[4,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,20.68375391678002,60,null]],[1,0,[[],[[0,[38,2],[]]],[],[],[]],[0,20.710914625206815,61,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[4,1],0]],[]],[0,20.912125511242472,62,null]],[1,3,[[[[0,[6,1]],[2,[[6,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[6,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,21.017657525564676,63,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[6,1],0]],[]],[0,21.15423751634369,64,null]],[1,2,[[[[0,[8,1]],[2,[[8,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[8,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,21.19165523107778,65,null]],[1,0,[[],[[0,[39,2],[]]],[],[],[]],[0,22.10312915121163,66,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[8,1],0]],[]],[0,22.424912825105707,67,null]],[1,0,[[],[[0,[40,2],[]]],[],[],[]],[0,22.49845197947521,68,null]],[1,3,[[[[0,[2,1]],[2,[[2,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[2,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,22.787215505466673,69,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[2,1],0]],[]],[0,22.850766922374206,70,null]],[1,2,[[[[0,[6,1]],[2,[[6,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[6,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,23.051101628343282,71,null]],[1,0,[[],[[0,[41,2],[]]],[],[],[]],[0,23.654573441546543,72,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[6,1],0]],[]],[0,24.473422416662334,73,null]],[1,3,[[[[0,[5,1]],[2,[[5,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[5,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,24.534887306968972,74,null]],[1,0,[[],[[0,[42,2],[]]],[],[],[]],[0,25.39795204140594,75,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[5,1],0]],[]],[0,25.529229359302782,76,null]],[1,2,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,25.569217346847054,77,null]],[1,0,[[],[[0,[43,2],[]]],[],[],[]],[0,26.07128837550854,78,null]],[1,0,[[],[[0,[44,2],[]]],[],[],[]],[0,26.516461716254526,79,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[0,27.427755694247335,80,null]],[1,3,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,27.711229118585187,81,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[0,28.910631551124876,82,null]],[1,2,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,29.14482013879848,83,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[0,30.037901571711018,84,null]],[1,3,[[[[0,[6,1]],[2,[[6,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[6,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,30.220010286647604,85,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[6,1],0]],[]],[0,30.39225205616227,86,null]],[1,2,[[[[0,[8,1]],[2,[[8,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[8,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,30.510848307941473,87,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[8,1],0]],[]],[0,30.88775834419144,88,null]],[1,3,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,30.904574640773408,89,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[0,31.884446123975675,90,null]],[1,2,[[[[0,[2,1]],[2,[[2,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[2,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,32.17363656417754,91,null]],[1,0,[[],[[0,[45,2],[]]],[],[],[]],[0,32.32295654205527,92,null]],[1,0,[[],[[0,[46,2],[]]],[],[],[]],[0,32.600966895541816,93,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[2,1],0]],[]],[0,33.07587641114492,94,null]],[1,3,[[[[0,[6,1]],[2,[[6,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[6,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,33.100271099414414,95,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[6,1],0]],[]],[0,33.29771303674189,96,null]],[1,2,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,33.35358941527632,97,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[0,33.713447280053295,98,null]],[1,3,[[[[0,[10,1]],[2,[[10,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[10,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,33.795464867588166,99,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[10,1],0]],[]],[0,34.86006243613086,100,null]],[1,2,[[[[0,[11,1]],[2,[[11,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[11,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,34.87022309590219,101,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[11,1],0]],[]],[0,35.027150147133405,102,null]],[1,3,[[[[0,[4,1]],[2,[[4,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[4,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,35.17178972212714,103,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[4,1],0]],[]],[0,36.143369884112474,104,null]],[1,2,[[[[0,[6,1]],[2,[[6,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[6,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,36.18948504450144,105,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[6,1],0]],[]],[0,36.86363243247595,106,null]],[1,3,[[[[0,[3,1]],[2,[[3,1],0]]],[[0,[0,0]],[1,[[0,0],0],1],[2,[[0,0],0]]]],[[2,[[3,1],0],[[0,0],0]],[1,[[0,0],0],0]],[],[],[]],[0,37.04252564956838,107,null]],[1,0,[[],[[0,[47,2],[]]],[],[],[]],[0,37.790458776616134,108,null]],[1,1,[[[[0,[0,0]],[3,[[0,0],0]]]],[[4,[[0,0],0]]],[[[[0,0],0],[2]]],[[[3,1],0]],[]],[0,38.04583677097828,109,null]],[1,2,[[[[0,[1,1]],[2,[[1,1],0]]],[[0,[0,0]],[1,[[0,0],0],0],[2,[[0,0],0]]]],[[2,[[1,1],0],[[0,0],0]],[1,[[0,0],0],1]],[],[],[]],[0,38.0464533255708,110,null]],[4,"GOAL",[[[5,[[1,1],0],[[0,0],0]],[1,[[1,1],0],1],[0,[1,1]],[1,[[0,0],0],1],[0,[0,0]]]],[1,38.0464533255708,110,null]],[1,4,[[[[0,[0,0]],[1,[[0,0],0],1],[0,[1,1]],[1,[[1,1],0],1],[5,[[1,1],0],[[0,0],0]]]],[[5,[1,1]],[5,[0,0]]],[],[],[]],[1,38.494097516076884,111,null]],[1,0,[[],[[0,[0,2],[]]],[],[],[]],[1,39.590521527652506,112,null]],[1,0,[[],[[0,[1,2],[]]],[],[],[]],[1,39.845413696129405,113,null]],[1,0,[[],[[0,[48,2],[]]],[],[],[]],[1,40.834442403493796,114,null]],[1,0,[[],[[0,[49,2],[]]],[],[],[]],[1,42.15964811691397,115,null]],[1,0,[[],[[0,[50,2],[]]],[],[],[]],[1,44.16380354850672,116,null]],[1,0,[[],[[0,[51,2],[]]],[],[],[]],[1,46.12185529518045,117,null]],[1,0,[[],[[0,[52,2],[]]],[],[],[]],[1,46.99020734328918,118,null]],[1,0,[[],[[0,[53,2],[]]],[],[],[]],[1,47.3195069041112,119,null]],[1,0,[[],[[0,[54,2],[]]],[],[],[]],[1,47.73501527654362,120,null]],[1,0,[[],[[0,[55,2],[]]],[],[],[]],[1,48.08037645904664,121,null]],[1,0,[[],[[0,[56,2],[]]],[],[],[]],[1,48.317057159348366,122,null]],[1,0,[[],[[0,[57,2],[]]],[],[],[]],[1,49.927819525247614,123,null]],[1,0,[[],[[0,[58,2],[]]],[],[],[]],[1,50.76896644557583,124,null]],[1,0,[[],[[0,[59,2],[]]],[],[],[]],[1,51.41382265556848,125,null]],[1,0,[[],[[0,[60,2],[]]],[],[],[]],[1,51.47946061956511,126,null]],[1,0,[[],[[0,[61,2],[]]],[],[],[]],[1,51.52410360626088,127,null]],[1,0,[[],[[0,[62,2],[]]],[],[],[]],[1,53.14318973162175,128,null]],[1,0,[[],[[0,[63,2],[]]],[],[],[]],[1,53.49460683049122,129,null]],[1,0,[[],[[0,[64,2],[]]],[],[],[]],[1,53.735906855421625,130,null]],[1,0,[[],[[0,[65,2],[]]],[],[],[]],[1,54.471226597667616,131,null]],[1,0,[[],[[0,[66,2],[]]],[],[],[]],[1,54.62366447803344,132,null]],[1,0,[[],[[0,[67,2],[]]],[],[],[]],[1,58.64891952667402,133,null]],[1,0,[[],[[0,[68,2],[]]],[],[],[]],[1,58.66571677933717,134,null]],[1,0,[[],[[0,[69,2],[]]],[],[],[]],[1,58.84261217832868,135,null]],[1,0,[[],[[0,[70,2],[]]],[],[],[]],[1,59.4104108357406,136,null]],[1,0,[[],[[0,[71,2],[]]],[],[],[]],[1,60.024837732409054,137,null]],[1,0,[[],[[0,[72,2],[]]],[],[],[]],[1,60.6835991122626,138,null]],[1,0,[[],[[0,[73,2],[]]],[],[],[]],[1,63.3158673530187,139,null]],[1,0,[[],[[0,[74,2],[]]],[],[],[]],[1,63.38727082230276,140,null]],[1,0,[[],[[0,[75,2],[]]],[],[],[]],[1,65.72170701603665,141,null]],[1,0,[[],[[0,[76,2],[]]],[],[],[]],[1,66.18079768519735,142,null]],[1,0,[[],[[0,[77,2],[]]],[],[],[]],[1,67.41232406185625,143,null]],[1,0,[[],[[0,[78,2],[]]],[],[],[]],[1,71.10030192720819,144,null]],[1,0,[[],[[0,[79,2],[]]],[],[],[]],[1,71.23991846826897,145,null]],[1,0,[[],[[0,[80,2],[]]],[],[],[]],[1,71.55358919906384,146,null]],[1,0,[[],[[0,[81,2],[]]],[],[],[]],[1,72.53844218807349,147,null]],[1,0,[[],[[0,[82,2],[]]],[],[],[]],[1,73.70309448099336,148,null]],[1,0,[[],[[0,[83,2],[]]],[],[],[]],[1,74.07464291937578,149,null]],[1,0,[[],[[0,[84,2],[]]],[],[],[]],[1,75.74858439444773,150,null]],[1,0,[[],[[0,[85,2],[]]],[],[],[]],[1,75.99083804520345,151,null]],[1,0,[[],[[0,[86,2],[]]],[],[],[]],[1,75.99474244284836,152,null]],[1,0,[[],[[0,[87,2],[]]],[],[],[]],[1,79.91041368447468,153,null]],[1,0,[[],[[0,[88,2],[]]],[],[],[]],[1,80.3617705040289,154,null]],[1,0,[[],[[0,[89,2],[]]],[],[],[]],[1,80.47115964962752,155,null]],[1,0,[[],[[0,[90,2],[]]],[],[],[]],[1,81.16950393224009,156,null]],[1,0,[[],[[0,[91,2],[]]],[],[],[]],[1,82.84208581519334,157,null]],[1,0,[[],[[0,[92,2],[]]],[],[],[]],[1,82.96862445066279,158,null]],[1,0,[[],[[0,[93,2],[]]],[],[],[]],[1,83.02574451634469,159,null]],[1,0,[[],[[0,[94,2],[]]],[],[],[]],[1,83.43494540628078,160,null]],[1,0,[[],[[0,[95,2],[]]],[],[],[]],[1,84.75897414500096,161,null]],[1,0,[[],[[0,[96,2],[]]],[],[],[]],[1,86.27800687992146,162,null]],[1,0,[[],[[0,[97,2],[]]],[],[],[]],[1,86.70523863145627,163,null]],[1,0,[[],[[0,[98,2],[]]],[],[],[]],[1,87.00291202216177,164,null]],[1,0,[[],[[0,[99,2],[]]],[],[],[]],[1,87.47683984452136,165,null]],[1,0,[[],[[0,[100,2],[]]],[],[],[]],[1,88.27692884308469,166,null]],[1,0,[[],[[0,[101,2],[]]],[],[],[]],[1,89.45094491401196,167,null]],[1,0,[[],[[0,[102,2],[]]],[],[],[]],[1,90.7999534354089,168,null]],[1,0,[[],[[0,[103,2],[]]],[],[],[]],[1,91.34000842351216,169,null]],[1,0,[[],[[0,[104,2],[]]],[],[],[]],[1,91.36124183554971,170,null]],[1,0,[[],[[0,[105,2],[]]],[],[],[]],[1,92.42637142894652,171,null]],[1,0,[[],[[0,[106,2],[]]],[],[],[]],[1,92.91976615768908,172,null]],[1,0,[[],[[0,[107,2],[]]],[],[],[]],[1,93.19804536448288,173,null]],[1,0,[[],[[0,[108,2],[]]],[],[],[]],[1,95.09421553172456,174,null]],[1,0,[[],[[0,[109,2],[]]],[],[],[]],[1,95.52108673781673,175,null]],[1,0,[[],[[0,[110,2],[]]],[],[],[]],[1,95.7469521442698,176,null]],[1,0,[[],[[0,[111,2],[]]],[],[],[]],[1,95.81231866505402,177,null]],[1,0,[[],[[0,[112,2],[]]],[],[],[]],[1,96.03214880580897,178,null]],[1,0,[[],[[0,[113,2],[]]],[],[],[]],[1,96.23827228909866,179,null]],[1,0,[[],[[0,[114,2],[]]],[],[],[]],[1,96.84541742093506,180,null]],[1,0,[[],[[0,[115,2],[]]],[],[],[]],[1,97.11530276779472,181,null]],[1,0,[[],[[0,[116,2],[]]],[],[],[]],[1,97.43980247159546,182,null]],[1,0,[[],[[0,[117,2],[]]],[],[],[]],[1,97.89061527379926,183,null]],[1,0,[[],[[0,[118,2],[]]],[],[],[]],[1,99.78604285068981,184,null]],[1,0,[[],[[0,[119,2],[]]],[],[],[]],[1,100.10249665795644,185,null]],[1,0,[[],[[0,[120,2],[]]],[],[],[]],[1,103.11273417850109,186,null]],[1,0,[[],[[0,[121,2],[]]],[],[],[]],[1,104.23313308244514,187,null]],[1,0,[[],[[0,[122,2],[]]],[],[],[]],[1,104.39464153879467,188,null]],[1,0,[[],[[0,[123,2],[]]],[],[],[]],[1,104.43775981504315,189,null]],[1,0,[[],[[0,[124,2],[]]],[],[],[]],[1,105.15012677269257,190,null]],[1,0,[[],[[0,[125,2],[]]],[],[],[]],[1,106.87820496904953,191,null]],[1,0,[[],[[0,[126,2],[]]],[],[],[]],[1,107.2378573981612,192,null]],[1,0,[[],[[0,[127,2],[]]],[],[],[]],[1,107.28791165470423,193,null]],[1,0,[[],[[0,[128,2],[]]],[],[],[]],[1,107.69861556813046,194,null]],[1,0,[[],[[0,[129,2],[]]],[],[],[]],[1,110.02295451648506,195,null]],[1,0,[[],[[0,[130,2],[]]],[],[],[]],[1,112.22226658416241,196,null]],[1,0,[[],[[0,[131,2],[]]],[],[],[]],[1,112.43722357268074,197,null]],[1,0,[[],[[0,[132,2],[]]],[],[],[]],[1,112.65766296263841,198,null]],[1,0,[[],[[0,[133,2],[]]],[],[],[]],[1,112.76894147316574,199,null]]]
 }
diff --git a/tests/integration/compiler/counters_smaller_than/output/inputs.ka.ref b/tests/integration/compiler/counters_smaller_than/output/inputs.ka.ref
index 836df5b98..930501e74 100644
--- a/tests/integration/compiler/counters_smaller_than/output/inputs.ka.ref
+++ b/tests/integration/compiler/counters_smaller_than/output/inputs.ka.ref
@@ -7,7 +7,7 @@
 %def: "outputFileName" "data.csv"
 
 
-%agent: A(c{=0/+=7} c__inverted{=0/+=7})
+%agent: A(c{=0/+=7} c__inverted{-=0/=7/+=7})
 %agent: B()
 
 %var:/*0*/ 'B' |B()|
diff --git a/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref b/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref
index 28429451b..7e80168fc 100644
--- a/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref
+++ b/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref
@@ -8,7 +8,7 @@ _____(1)
 A(c{>=8})
 Environment:
   
-  %agent: A(c{=0/+=7} c__inverted{=0/+=7})
+  %agent: A(c{=0/+=7} c__inverted{-=0/=7/+=7})
   
   %plot: [T]
   A(c{=0} c__inverted{=7})+ @ 1
diff --git a/tests/integration/compiler/site_mismatch/output/LOG.ref b/tests/integration/compiler/site_mismatch/output/LOG.ref
index 28c6fc2ce..8ed225fd8 100644
--- a/tests/integration/compiler/site_mismatch/output/LOG.ref
+++ b/tests/integration/compiler/site_mismatch/output/LOG.ref
@@ -73,4 +73,4 @@ every agent may occur in the model
 ------------------------------------------------------------
 
 Some exceptions have been raised
-error: file_name: core/KaSa_rep/frontend/prepreprocess.ml; message: line 719, File "crash.ka", line 4, characters 5-69:: missaligned rule: the rule is ignored; exception:Exit
+error: file_name: core/KaSa_rep/frontend/prepreprocess.ml; message: line 766, File "crash.ka", line 4, characters 5-69:: missaligned rule: the rule is ignored; exception:Exit
diff --git a/tests/integration/simulation/counters_create/output/inputs.ka.ref b/tests/integration/simulation/counters_create/output/inputs.ka.ref
index 77f12712a..27872027f 100644
--- a/tests/integration/simulation/counters_create/output/inputs.ka.ref
+++ b/tests/integration/simulation/counters_create/output/inputs.ka.ref
@@ -7,7 +7,7 @@
 %def: "outputFileName" "data.svg"
 
 
-%agent: A(c{=0/+=10} c__inverted{=0/+=10})
+%agent: A(c{=0/+=10} c__inverted{-=0/=10/+=10})
 %agent: B()
 
 %var:/*0*/ 'B' |B()|