Skip to content

Commit 2d5791e

Browse files
committed
now with wrapper to collect multiple contribs to same global and also collection of unknowns representing the same origin
1 parent d8fbd67 commit 2d5791e

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

src/solver/td_simplified_ref_improved.ml

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ module Base : GenericEqSolver =
2626
called: bool;
2727
}
2828

29+
(*
2930
module OM = HM
3031
let source x = x
32+
*)
3133

32-
(*
3334
module OM = Hashtbl.Make(Node)
3435
let source = S.Var.node
35-
*)
3636

3737
type origin = {
3838
init: S.Dom.t;
39-
from: (S.Dom.t * int * int * bool) OM.t
39+
from: (S.Dom.t * int * int * bool * VS.t) OM.t;
40+
last: S.Dom.t HM.t
4041
}
4142

42-
let gas_default = ref (10,0)
43+
let gas_default = ref (10,3)
4344

4445
let warrow (a,delay,gas,narrow) b =
4546
let (delay0,_) = !gas_default in
@@ -52,7 +53,7 @@ module Base : GenericEqSolver =
5253
else if delay <= 0 then (S.Dom.widen a (S.Dom.join a b),0,gas,false)
5354
else (S.Dom.join a b, delay-1,gas,false)
5455

55-
let get_global_value init from = OM.fold (fun _ (b,_,_,_) a -> S.Dom.join a b) from init
56+
let get_global_value init from = OM.fold (fun _ (b,_,_,_,_) a -> S.Dom.join a b) from init
5657

5758
let is_global y = (S.system y = None)
5859

@@ -89,6 +90,7 @@ module Base : GenericEqSolver =
8990
let orig_x = {
9091
init = S.Dom.bot();
9192
from = OM.create 10;
93+
last = HM.create 10
9294
} in
9395
HM.add origin x orig_x;
9496
data_x
@@ -104,7 +106,7 @@ alternatively, distinguish contribs by session number?
104106
match S.system x with
105107
| None -> S.Dom.bot ()
106108
| Some f -> f get set
107-
in
109+
in
108110

109111
let rec destabilize x =
110112
if tracing then trace "destab" "destabilize %a" S.Var.pretty_trace x;
@@ -146,48 +148,43 @@ alternatively, distinguish contribs by session number?
146148
let sx = source x in
147149
let y_ref = init y in
148150
if tracing then trace "side" "side to %a (wpx: %b) from %a ## value: %a" S.Var.pretty_trace y (!y_ref.wpoint) S.Var.pretty_trace x S.Dom.pretty d;
149-
let {init;from} = HM.find origin y in
150-
let (old_xy,delay,gas,narrow) = try OM.find from sx
151+
let {init;last;from} = HM.find origin y in
152+
let (old_xy,delay,gas,narrow,set) = try OM.find from sx
151153
with _ ->
152154
let (delay,gas) = !gas_default in
153-
let tuple = (S.Dom.bot (),delay,gas,false) in
155+
let tuple = (S.Dom.bot (),delay,gas,false,VS.empty) in
154156
let () = OM.add from sx tuple in
155157
tuple in
158+
let () = HM.add last x d in
159+
let set = VS.add x set in
160+
let d = VS.fold (fun x d -> S.Dom.join d (HM.find last x)) set d in
156161
let (new_xy,delay,gas,narrow) =
157162
if M.tracing then M.trace "wpoint" "side widen %a" S.Var.pretty_trace y;
158163
warrow (old_xy,delay,gas,narrow) d in
159-
(*
160-
let widen a b =
161-
S.Dom.widen a (S.Dom.join a b)
162-
in
163-
let op a b = if !y_ref.wpoint then widen a b else S.Dom.join a b
164-
in
165-
let old = !y_ref.value in
166-
let tmp = op old d in
167-
y_ref := { !y_ref with stable = true };
168-
*)
164+
OM.replace from sx (new_xy,delay,gas,narrow,set);
169165
if S.Dom.equal new_xy old_xy then ()
170166
else (
171-
OM.replace from sx (new_xy,delay,gas,narrow);
172167
let new_y = get_global_value init from in
173168
if S.Dom.equal new_y !y_ref.value then ()
174169
else (
175170
y_ref := { !y_ref with value = new_y };
176171
destabilize y
177172
)
178173
)
179-
(*
180-
if not (S.Dom.leq tmp old) then (
181-
if tracing && not (S.Dom.is_bot old) then trace "update" "side to %a (wpx: %b) from %a: %a -> %a" S.Var.pretty_trace y (!y_ref.wpoint) S.Var.pretty_trace x S.Dom.pretty old S.Dom.pretty tmp;
182-
y_ref := { !y_ref with value = tmp };
183-
destabilize y;
184-
(* make y a widening point. This will only matter for the next side _ y. *)
185-
if tracing && not (!y_ref.wpoint) then trace "wpoint" "side adding wpoint %a" S.Var.pretty_trace y;
186-
y_ref := { !y_ref with wpoint = true };
187-
)
188-
*)
189174

190-
and iterate x = (* ~(inner) solve in td3*)
175+
and wrap_eq x =
176+
match S.system x with
177+
| None -> S.Dom.bot ()
178+
| Some f ->
179+
let sigma = HM.create 10 in
180+
let add_sigma y d =
181+
let d = try S.Dom.join d (HM.find sigma y) with _ -> d in
182+
HM.replace sigma y d;
183+
side x y d in
184+
f (query x) add_sigma
185+
186+
187+
and iterate x = (* ~(inner) solve in td3 *)
191188

192189
(* begining of iterate*)
193190
let x_ref = init x in
@@ -196,7 +193,11 @@ alternatively, distinguish contribs by session number?
196193
if not (!x_ref.stable) then (
197194
x_ref := { !x_ref with stable = true };
198195
let wp = !x_ref.wpoint in (* if x becomes a wpoint during eq, checking this will delay widening until next iterate *)
199-
let eqd = eq x (query x) (side x) in (* d from equation/rhs *)
196+
let eqd =
197+
wrap_eq x in
198+
(*
199+
eq x (query x) (side x) in (* d from equation/rhs *)
200+
*)
200201
let old = !x_ref.value in (* d from older iterate *)
201202
let wpd = (* d after widen/narrow (if wp) *)
202203
if not wp then eqd
@@ -230,7 +231,7 @@ alternatively, distinguish contribs by session number?
230231
let set_start (x,d) =
231232
let x_ref = init x in
232233
x_ref := { !x_ref with value = d; stable = true };
233-
if is_global x then HM.replace origin x { init = d; from = OM.create 10 }
234+
if is_global x then HM.replace origin x { init = d; from = OM.create 10; last = HM.create 10 }
234235
in
235236

236237
(* beginning of main solve *)

0 commit comments

Comments
 (0)