2 let stat = Gc.stat() in
\r
3 let word = float_of_int (Sys.word_size / 8) in
\r
4 let free = float_of_int stat.Gc.free_words *. word /. 1024.0 in
\r
5 let total = float_of_int stat.Gc.heap_words *. word /. 1024.0 in
\r
6 let allocated = total -. free in
\r
7 let str = sprintf "allocated = %f (free = %f; total_size = %f; %f)\n"
\r
8 allocated free total (free /. total) in
\r
12 (* allocated = 85862 *)
\r
15 Gc.set { (Gc.get()) with Gc.verbose = 0x05 };;
\r
18 (* allocated = 60243 *)
\r
24 flyspeck_needs "../formal_lp/formal_interval/m_verifier.hl";;
\r
26 (* allocated = 129006 *)
\r
30 (* allocated = 80510 *)
\r
33 Arith_cache.print_stat();;
\r
34 Arith_float.print_stat();;
\r
38 Arith_cache.reset_cache();
\r
39 Arith_cache.reset_stat();
\r
40 Arith_float.reset_cache();
\r
41 Arith_float.reset_stat();;
\r
46 (* allocated = 79346 *)
\r
50 (**************************)
\r
52 let heart_poly = expr_to_vector_fun `-- x1 * x6 pow 3 + &3 * x1 * x6 * x7 pow 2 - x3 * x7 pow 3 +
\r
53 &3 * x3 * x7 * x6 pow 2 - x2 * x5 pow 3 + &3 * x2 * x5 * x8 pow 2 - x4 * x8 pow 3 +
\r
54 &3 * x4 * x8 * x5 pow 2 - #0.9563453`;;
\r
56 let poly1 = `x2 + x3 + x5 + x6 - #7.99 - #0.00385 * delta_y x1 x2 x3 x4 x5 x6 -
\r
57 #2.75 * ((x1 + x4) * #0.5 - sqrt (&8))`;;
\r
58 let poly_ineq = (expr_to_vector_fun o rand o concl o
\r
59 REWRITE_CONV[Sphere.delta_y; Sphere.delta_x]) poly1;;
\r
61 let heart_min = `-- #1.7435` and
\r
64 let heart_dom = `[-- #0.1; #0.4; -- #0.7; -- #0.7; #0.1; -- #0.1; -- #0.3; -- #1.1]`,
\r
65 `[#0.4; &1; -- #0.4; #0.4; #0.2; #0.2; #1.1; -- #0.3]`;;
\r
66 let poly_dom = `[sqrt (&8); &2; &2; sqrt (&8); &2; &2]`,
\r
67 `[&3; #2.07; #2.07; &4 * #1.26; #2.07; #2.07]`;;
\r
70 (***********************************)
\r
72 let test_verify pp poly_tm min_flag val_tm (xx,zz) eps =
\r
73 let total_start = Sys.time() in
\r
74 let n = (get_dim o fst o dest_abs) poly_tm in
\r
75 let xx1 = convert_to_float_list pp true xx and
\r
76 zz1 = convert_to_float_list pp false zz in
\r
77 let xx_float = map float_of_float_tm (dest_list xx1) and
\r
78 zz_float = map float_of_float_tm (dest_list zz1) in
\r
79 let eval_fs, tf = mk_verification_functions pp poly_tm min_flag val_tm in
\r
80 let certificate = run_test tf xx_float zz_float false 0.0 true true true true eps in
\r
81 let c1 = transform_result xx_float zz_float certificate in
\r
82 let start = Sys.time() in
\r
83 let result = m_verify_list n pp eval_fs c1 xx1 zz1 in
\r
84 let finish = Sys.time() in
\r
86 (sprintf "Total time: %f; Verification time: %f" (finish -. total_start) (finish -. start)) in
\r
94 8 (10): 27.937; 9.176
\r
95 64 (6): 24.249; 5.672
\r
96 512 (3): 23.113; 3.428
\r
98 Why is the base 10 much faster than 8?
\r
99 Possible explanation: the domain is described by decimal numbers,
\r
100 so computations with the base 10 are faster in general (the approximation is better:
\r
101 requires less digits).
\r
102 10 (10): 23.205; 4.376
\r
103 10 (10, cached, float_cached): 20.001; 1.548
\r
104 10 (10, float_cached): 19.769; 1.744
\r
105 100 (5): 21.733; 3.180
\r
106 100 (5, cached): 20.737; 2.196
\r
111 test_verify 10 heart_poly true heart_min heart_dom 1e-10;;
\r
113 Arith_cache.print_stat();;
\r
114 Arith_float.print_stat();;
\r
129 8 (10): 215.953; 112.399
\r
130 64 (6): 162.754; 62.588
\r
131 64 (5): 150.573; 49.991
\r
132 512 (3): 137.967; 32.250
\r
134 10 (10): 185.211; 83.785
\r
135 100 (5): 139.821; 40.975
\r
136 100 (5, cached): 119.267; 20.009
\r
140 test_verify 5 poly_ineq true poly_min poly_dom 0.0;;
\r
141 Arith_cache.print_stat();;
\r
147 let n = (get_dim o fst o dest_abs) poly_ineq;;
\r
148 let xx, zz = poly_dom;;
\r
149 let xx1 = convert_to_float_list pp true xx and
\r
150 zz1 = convert_to_float_list pp false zz;;
\r
151 let xx_float = map float_of_float_tm (dest_list xx1) and
\r
152 zz_float = map float_of_float_tm (dest_list zz1);;
\r
154 Arith_cache.print_stat();;
\r
155 Arith_float.print_stat();;
\r
157 let eval_fs, tf = mk_verification_functions pp poly_ineq true poly_min;;
\r
159 Arith_cache.print_stat();;
\r
160 Arith_float.print_stat();;
\r
162 let certificate = run_test tf xx_float zz_float false 0.0 true true true true 0.0;;
\r
163 let c1 = transform_result xx_float zz_float certificate;;
\r
167 (* 10 (10, cached): 30.589 *)
\r
168 (* 10 (10, cached, float_cached): 16.137 *)
\r
169 (* 10 (10, float_cached): 17.001 *)
\r
170 (* 100 (5, cached): 20.101 *)
\r
171 (* 100 (5, cached, float_cached): 10.452 *)
\r
174 let start = Sys.time() in
\r
175 let result = m_verify_list n pp eval_fs c1 xx1 zz1 in
\r
176 let finish = Sys.time() in
\r
178 (sprintf "Verification time: %f" (finish -. start)) in
\r
181 Arith_cache.print_stat();;
\r
182 Arith_float.print_stat();;
\r
196 let add_list = !Arith_cache.add_list and
\r
197 mul_list = !Arith_cache.mul_list and
\r
198 sub_le_list = !Arith_cache.sub_le_list;;
\r
202 test 1 (map Arith_hash.raw_add_conv_hash) add_list;;
\r
204 test 1 (map Arith_hash.raw_mul_conv_hash) mul_list;;
\r
206 test 1 (map (fun tm1, tm2 -> Arith_hash.raw_sub_and_le_hash_conv tm1 tm2)) sub_le_list;;
\r
208 Arith_cache.reset_cache();;
\r
212 test 1 (map raw_add_conv_hash) add_list;;
\r
214 test 1 (map raw_mul_conv_hash) mul_list;;
\r
216 test 1 (map (fun tm1, tm2 -> raw_sub_and_le_hash_conv tm1 tm2)) sub_le_list;;
\r
222 let mul_lo_list = !Arith_float.mul_lo_list and
\r
223 mul_hi_list = !Arith_float.mul_hi_list and
\r
224 add_lo_list = !Arith_float.add_lo_list and
\r
225 add_hi_list = !Arith_float.add_hi_list;;
\r
229 test 1 (map (fun p,tm1,tm2 -> float_mul_lo p tm1 tm2)) mul_lo_list;;
\r
232 test 1 (map (fun p,tm1,tm2 -> float_mul_hi p tm1 tm2)) mul_hi_list;;
\r
236 test 1 (map (fun p,tm1,tm2 -> float_add_lo p tm1 tm2)) add_lo_list;;
\r
239 test 1 (map (fun p,tm1,tm2 -> float_add_hi p tm1 tm2)) add_hi_list;;
\r
243 let float_hash tm =
\r
244 let s, n_tm, e_tm = dest_float tm in
\r
245 s ^ (num_tm_hash n_tm) ^ "e" ^ (num_tm_hash e_tm);;
\r
248 let float_op_hash pp tm1 tm2 =
\r
249 string_of_int pp ^ float_hash tm1 ^ "x" ^ float_hash tm2;;
\r
251 let float_mul_table = Hashtbl.create 10000;;
\r
253 let float_mul_lo_cached pp tm1 tm2 =
\r
254 let hash = float_op_hash pp tm1 tm2 in
\r
256 Hashtbl.find float_mul_table hash
\r
258 let result = float_mul_lo pp tm1 tm2 in
\r
259 let _ = Hashtbl.add float_mul_table hash result in
\r
265 test 1 (map (fun p,tm1,tm2 -> float_mul_lo_cached p tm1 tm2)) mul_lo_list;;
\r
267 Hashtbl.length float_mul_table;;
\r
269 length mul_lo_list;;
\r
278 Hashtbl.length Arith_cache.mul_table;;
\r
279 Hashtbl.length Arith_cache.sub_le_table;;
\r
280 Hashtbl.length Arith_cache.add_table;;
\r
284 test 1 (map Arith_hash.raw_suc_conv_hash) !Arith_cache.suc_list;;
\r
286 test 1 (map Arith_hash.raw_eq0_hash_conv) !Arith_cache.eq0_list;;
\r
288 test 1 (map Arith_hash.raw_div_hash_conv) !Arith_cache.div_list;;
\r
291 test 1 (map (fun tm1, tm2 -> Arith_hash.raw_sub_and_le_hash_conv tm1 tm2)) !Arith_cache.sub_le_list;;
\r
296 let mul_table = Hashtbl.create 100000;;
\r
298 let mul_cache1 tm =
\r
299 if Hashtbl.mem mul_table tm then
\r
300 Hashtbl.find mul_table tm
\r
302 let result = Arith_hash.raw_mul_conv_hash tm in
\r
303 let _ = Hashtbl.add mul_table tm result in
\r
308 Hashtbl.clear mul_table;;
\r
309 test 1 (map mul_cache1) !Arith_cache.mul_list;;
\r
311 test 1 (map mul_cache1) !Arith_cache.mul_list;;
\r
314 test 1 (map (Hashtbl.mem mul_table)) !Arith_cache.mul_list;;
\r
316 test 1 (map (Hashtbl.find mul_table)) !Arith_cache.mul_list;;
\r
318 test 1 (map Hashtbl.hash) !Arith_cache.mul_list;;
\r
320 let rec num_tm_hash tm =
\r
322 let b_tm, n_tm = dest_comb tm in
\r
323 let str = (fst o dest_const) b_tm in
\r
324 str ^ num_tm_hash n_tm
\r
329 let op_tm_hash tm =
\r
330 let lhs, tm2 = dest_comb tm in
\r
331 let tm1 = rand lhs in
\r
332 num_tm_hash tm1 ^ "x" ^ num_tm_hash tm2;;
\r
336 test 1 (map op_tm_hash) !Arith_cache.mul_list;;
\r
338 test 1 (map (Hashtbl.hash o op_tm_hash)) !Arith_cache.mul_list;;
\r
342 let mul_table2 = Hashtbl.create 10000;;
\r
343 let add_table2 = Hashtbl.create 10000;;
\r
344 let div_table2 = Hashtbl.create 10000;;
\r
346 let mul_cache2 tm =
\r
347 let hash = op_tm_hash tm in
\r
349 Hashtbl.find mul_table2 hash
\r
351 let result = Arith_hash.raw_mul_conv_hash tm in
\r
352 let _ = Hashtbl.add mul_table2 hash result in
\r
355 let add_cache2 tm =
\r
356 let hash = op_tm_hash tm in
\r
358 Hashtbl.find add_table2 hash
\r
360 let result = Arith_hash.raw_add_conv_hash tm in
\r
361 let _ = Hashtbl.add add_table2 hash result in
\r
364 let div_cache2 tm =
\r
365 let hash = op_tm_hash tm in
\r
367 Hashtbl.find div_table2 hash
\r
369 let result = Arith_hash.raw_div_hash_conv tm in
\r
370 let _ = Hashtbl.add div_table2 hash result in
\r
373 Hashtbl.clear div_table2;;
\r
375 test 1 (map div_cache2) !Arith_cache.div_list;;
\r
377 Hashtbl.length div_table2;;
\r
379 test 1 (map div_cache2) !Arith_cache.div_list;;
\r
382 Hashtbl.clear mul_table2;;
\r
384 test 1 (map mul_cache2) !Arith_cache.mul_list;;
\r
386 Hashtbl.length mul_table2;;
\r
388 test 1 (map mul_cache2) !Arith_cache.mul_list;;
\r
390 Hashtbl.clear add_table2;;
\r
392 test 1 (map add_cache2) !Arith_cache.add_list;;
\r
394 Hashtbl.length add_table2;;
\r
396 test 1 (map add_cache2) !Arith_cache.add_list;;
\r
401 let lhs, tm2 = dest_comb tm in
\r
402 let tm1 = rand lhs in
\r
403 let list1 = striplist dest_comb tm1 and
\r
404 list2 = striplist dest_comb tm2 in
\r
405 length list1, length list2;;
\r
407 let l0 = map op_sizes !Arith_cache.mul_list;;
\r
409 length (List.filter (fun p -> fst p = 1) l0);;
\r
411 length (List.filter (fun p -> fst p = 2) l0);;
\r
413 length (List.filter (fun p -> fst p = 3) l0);;
\r
415 length (List.filter (fun p -> fst p = 4) l0);;
\r
417 length (List.filter (fun p -> fst p = 5) l0);;
\r
419 length (List.filter (fun p -> fst p = 6) l0);;
\r
421 length (List.filter (fun p -> fst p = 7) l0);;
\r
424 length (List.filter (fun p -> snd p = 1) l0);;
\r
426 length (List.filter (fun p -> snd p = 2) l0);;
\r
428 length (List.filter (fun p -> snd p = 3) l0);;
\r
430 length (List.filter (fun p -> snd p = 4) l0);;
\r
432 length (List.filter (fun p -> snd p = 5) l0);;
\r
434 length (List.filter (fun p -> snd p = 6) l0);;
\r
436 length (List.filter (fun p -> snd p = 7) l0);;
\r