| author | paulson <lp15@cam.ac.uk> | 
| Thu, 02 May 2019 12:58:32 +0100 | |
| changeset 70228 | 2d5b122aa0ff | 
| parent 67560 | 0fa87bd86566 | 
| permissions | -rw-r--r-- | 
| 
63960
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
1  | 
(* Title: Tools/Argo/argo_heap.ML  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
2  | 
Author: Sascha Boehme  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
3  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
4  | 
A maximum-priority heap for literals with integer priorities and with inverse indices.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
5  | 
The heap is intended to be used as VSIDS-like decision heuristics. This implementation  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
6  | 
is based on pairing heaps described in:  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
7  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
8  | 
Chris Okasaki. Purely Functional Data Structures. Chapter 5.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
9  | 
Cambridge University Press, 1998.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
10  | 
*)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
11  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
12  | 
signature ARGO_HEAP =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
13  | 
sig  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
14  | 
type heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
15  | 
val heap: heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
16  | 
val insert: Argo_Lit.literal -> heap -> heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
17  | 
val extract: heap -> (Argo_Lit.literal * heap) option  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
18  | 
val increase: Argo_Lit.literal -> heap -> heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
19  | 
val count: Argo_Lit.literal -> heap -> heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
20  | 
val decay: heap -> heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
21  | 
val rebuild: (Argo_Term.term -> bool) -> heap -> heap  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
22  | 
end  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
23  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
24  | 
structure Argo_Heap: ARGO_HEAP =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
25  | 
struct  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
26  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
27  | 
(* heuristic activity constants *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
28  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
29  | 
val min_incr = 128  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
30  | 
fun decay_incr i = (i * 11) div 10  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
31  | 
val max_activity = Integer.pow 24 2  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
32  | 
val activity_rescale = Integer.pow 14 2  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
33  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
34  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
35  | 
(* data structures and basic operations *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
36  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
37  | 
datatype tree = E | T of Argo_Term.term * bool * tree list  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
38  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
39  | 
datatype parent = None | Root | Some of Argo_Term.term  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
40  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
41  | 
type heap = {
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
42  | 
incr: int, (* the increment to apply in an increase operation *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
43  | 
vals: ((int * int) * parent) Argo_Termtab.table, (* weights and parents of the stored terms *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
44  | 
tree: tree} (* the pairing heap of literals; note: the tree caches literal polarities *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
45  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
46  | 
fun mk_heap incr vals tree: heap = {incr=incr, vals=vals, tree=tree}
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
47  | 
fun mk_heap' incr (tree, vals) = mk_heap incr vals tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
48  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
49  | 
val heap = mk_heap min_incr Argo_Termtab.empty E  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
50  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
51  | 
val empty_value = ((0, 0), None)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
52  | 
fun value_of vals t = the_default empty_value (Argo_Termtab.lookup vals t)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
53  | 
fun map_value t = Argo_Termtab.map_default (t, empty_value)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
54  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
55  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
56  | 
(* weight operations *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
57  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
58  | 
(*  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
59  | 
The weight of a term is a pair of activity and count. The activity describes how  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
60  | 
often a term participated in conflicts. The count describes how often a term occurs  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
61  | 
in clauses.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
62  | 
*)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
63  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
64  | 
val weight_ord = prod_ord int_ord int_ord  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
65  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
66  | 
fun weight_of vals t = fst (value_of vals t)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
67  | 
|
| 67560 | 68  | 
fun less_than vals t1 t2 = is_less (weight_ord (weight_of vals t1, weight_of vals t2))  | 
| 
63960
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
69  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
70  | 
fun rescale activity = activity div activity_rescale  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
71  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
72  | 
fun incr_activity incr t = map_value t (apfst (apfst (Integer.add incr)))  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
73  | 
fun incr_count t = map_value t (apfst (apsnd (Integer.add 1)))  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
74  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
75  | 
fun rescale_activities a incr vals =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
76  | 
if a <= max_activity then (incr, vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
77  | 
else (rescale incr, Argo_Termtab.map (fn _ => apfst (apfst rescale)) vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
78  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
79  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
80  | 
(* reverse index operations *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
81  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
82  | 
(*  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
83  | 
The reverse index is required to retrieve elements when increasing their priorities.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
84  | 
*)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
85  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
86  | 
fun contains vals t =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
87  | 
(case value_of vals t of  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
88  | 
(_, None) => false  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
89  | 
| _ => true)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
90  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
91  | 
fun path_to vals t parents =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
92  | 
(case value_of vals t of  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
93  | 
(_, Root) => parents  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
94  | 
| (_, Some parent) => path_to vals parent (t :: parents)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
95  | 
| _ => raise Fail "bad heap")  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
96  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
97  | 
fun put_parent t parent = map_value t (apsnd (K parent))  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
98  | 
fun delete t = put_parent t None  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
99  | 
fun root t = put_parent t Root  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
100  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
101  | 
fun as_root (tree as T (t, _, _), vals) = (tree, root t vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
102  | 
| as_root x = x  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
103  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
104  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
105  | 
(* pairing heap operations *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
106  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
107  | 
fun merge E tree vals = (tree, vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
108  | 
| merge tree E vals = (tree, vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
109  | 
| merge (tree1 as T (t1, p1, trees1)) (tree2 as T (t2, p2, trees2)) vals =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
110  | 
if less_than vals t1 t2 then (T (t2, p2, tree1 :: trees2), put_parent t1 (Some t2) vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
111  | 
else (T (t1, p1, tree2 :: trees1), put_parent t2 (Some t1) vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
112  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
113  | 
fun merge_pairs [] vals = (E, vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
114  | 
| merge_pairs [tree] vals = (tree, vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
115  | 
| merge_pairs (tree1 :: tree2 :: trees) vals =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
116  | 
vals |> merge tree1 tree2 ||>> merge_pairs trees |-> uncurry merge  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
117  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
118  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
119  | 
(* cutting subtrees specified by a path *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
120  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
121  | 
(*  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
122  | 
The extractions are performed in such a way that the heap is changed in as few positions  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
123  | 
as possible.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
124  | 
*)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
125  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
126  | 
fun with_index f u ((tree as T (t, _, _)) :: trees) =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
127  | 
if Argo_Term.eq_term (t, u) then f tree ||> (fn E => trees | tree => tree :: trees)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
128  | 
else with_index f u trees ||> cons tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
129  | 
| with_index _ _ _ = raise Fail "bad heap"  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
130  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
131  | 
fun lift_index f u (T (t, p, trees)) = with_index f u trees ||> (fn trees => T (t, p, trees))  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
132  | 
| lift_index _ _ E = raise Fail "bad heap"  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
133  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
134  | 
fun cut t [] tree = lift_index (fn tree => (tree, E)) t tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
135  | 
| cut t (parent :: ts) tree = lift_index (cut t ts) parent tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
136  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
137  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
138  | 
(* filtering the heap *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
139  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
140  | 
val proper_trees = filter (fn E => false | T _ => true)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
141  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
142  | 
fun filter_tree _ E vals = (E, vals)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
143  | 
| filter_tree pred (T (t, p, ts)) vals =  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
144  | 
let val (ts, vals) = fold_map (filter_tree pred) ts vals |>> proper_trees  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
145  | 
in if pred t then (T (t, p, ts), vals) else merge_pairs ts (delete t vals) end  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
146  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
147  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
148  | 
(* exported heap operations *)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
149  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
150  | 
fun insert lit (h as {incr, vals, tree}: heap) = 
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
151  | 
let val (t, p) = Argo_Lit.dest lit  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
152  | 
in if contains vals t then h else mk_heap' incr (merge tree (T (t, p, [])) (root t vals)) end  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
153  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
154  | 
fun extract ({tree=E, ...}: heap) = NONE
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
155  | 
  | extract ({incr, vals, tree=T (t, p, ts)}: heap) =
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
156  | 
SOME (Argo_Lit.literal t p, mk_heap' incr (as_root (merge_pairs ts (delete t vals))))  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
157  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
158  | 
fun with_term lit f = f (Argo_Lit.term_of lit)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
159  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
160  | 
(*  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
161  | 
If the changed weight violates the heap property, the corresponding tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
162  | 
is extracted and merged with the root.  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
163  | 
*)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
164  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
165  | 
fun fix t (w, Some parent) (incr, vals) tree =  | 
| 67560 | 166  | 
if is_less (weight_ord (weight_of vals parent, w)) then  | 
| 
63960
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
167  | 
let val (tree1, tree2) = cut t (path_to vals parent []) tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
168  | 
in mk_heap' incr (merge tree1 tree2 (root t vals)) end  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
169  | 
else mk_heap incr vals tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
170  | 
| fix _ _ (incr, vals) tree = mk_heap incr vals tree  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
171  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
172  | 
fun increase lit ({incr, vals, tree}: heap) = with_term lit (fn t =>
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
173  | 
let  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
174  | 
val vals = incr_activity incr t vals  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
175  | 
val value as ((a, _), _) = value_of vals t  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
176  | 
in fix t value (rescale_activities a incr vals) tree end)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
177  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
178  | 
fun count lit ({incr, vals, tree}: heap) = with_term lit (fn t =>
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
179  | 
let val vals = incr_count t vals  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
180  | 
in fix t (value_of vals t) (incr, vals) tree end)  | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
181  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
182  | 
fun decay ({incr, vals, tree}: heap) = mk_heap (decay_incr incr) vals tree
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
183  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
184  | 
fun rebuild pred ({incr, vals, tree}: heap) = mk_heap' incr (filter_tree pred tree vals)
 | 
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
185  | 
|
| 
 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 
boehmes 
parents:  
diff
changeset
 | 
186  | 
end  |