Source file Elo_to_model1.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
(** Provides a converter from Electrod models to (part of) a solver
    model.  *)
open Containers
module S = Iter
module Make
    (Ltl : Solver.LTL)
    (ConvertFormulas : Elo_to_ltl_intf.S
                         with type ltl = Ltl.t
                          and type atomic = Ltl.Atomic.t)
    (Model : Solver.MODEL
               with type ltl = ConvertFormulas.ltl
                and type atomic = ConvertFormulas.atomic) =
struct
  type atomic = Ltl.Atomic.t
  
  let syms_to_ltl elo =
    let open Elo in
    let open Ltl in
    let syms = elo.sym in
    let sym_to_ltl (sym : Symmetry.t) =
      Symmetry.fold
        (fun (name1, tuple1) (name2, tuple2) (fml_acc : Ltl.t) ->
          
          if not (Name.equal name1 name2)
          then assert false
          else
            let at1 = Ltl.Atomic.make elo.domain name1 tuple1 in
            let at_fml1 = atomic at1 in
            let at2 = Ltl.Atomic.make elo.domain name2 tuple2 in
            let at_fml2 = atomic at2 in
            and_
              (implies at_fml1 (lazy at_fml2))
              (lazy (implies (iff at_fml1 at_fml2) (lazy fml_acc))))
        sym
        true_
    in
    List.fold_left
      (fun fmls_acc sym ->
        let cur_fml = sym_to_ltl sym in
        S.cons ("-- (symmetry)", cur_fml) fmls_acc)
      S.empty
      syms
  
  let split_invar_noninvar_fmls elo blk =
    let open Invar_computation in
    let invf, tmp_restf =
      List.partition_map
        (fun fml ->
          let color = Invar_computation.color elo fml in
          
          match color with
          | Invar | Static_prop ->
              `Left (remove_always_from_invar fml)
          | Init | Primed_prop | Trans | Temporal ->
              `Right fml)
        blk
    in
    let transf, tmp_restf2 =
      List.partition_map
        (fun fml ->
          let color = Invar_computation.color elo fml in
          
          match color with
          | Trans ->
              `Left (remove_always_from_invar fml)
          | _ ->
              `Right fml)
        tmp_restf
    in
    let initf, restf =
      List.partition_map
        (fun fml ->
          let color = Invar_computation.color elo fml in
          
          match color with Init -> `Left fml | _ -> `Right fml)
        tmp_restf2
    in
    match (restf, List.rev invf, List.rev transf, List.rev initf) with
    | _ :: _, _, _, _ ->
        (initf, invf, transf, restf)
    | [], _, hd :: tl, _ ->
        (initf, invf, List.rev tl, [ add_always_to_invar hd ])
    | [], hd :: tl, _, _ ->
        (initf, List.rev tl, transf, [ add_always_to_invar hd ])
    | [], _, _, hd :: tl ->
        (List.rev tl, invf, transf, [ hd ])
    | _ ->
        assert false
  
  
  let dualise_fmls fmls =
    let open Elo in
    match List.rev fmls with
    | [] ->
        assert false
    | (Fml { node; _ } as hd) :: tl ->
        let premise = List.fold_left (fun x y -> lbinary x and_ y) true_ tl in
        let rhs_fml =
          match node with LUn (Not, subfml) -> subfml | _ -> lunary not_ hd
        in
        lbinary premise impl rhs_fml
  let run elo =
    let open Elo in
    
    let elo =
      Elo.
        { elo with
          domain = Domain.update_domain_with_instance elo.domain elo.instance
        ; instance = Instance.empty
        }
    in
    Msg.debug (fun m ->
        m "Elo_to_model1.run: after instance update:@ %a" Elo.pp elo);
    
    
    let translate_formulas fmls =
      
      List.fold_left
        (fun acc_fml fml ->
          let fml_str, ltl = ConvertFormulas.convert elo fml in
          
          
          
          S.cons (fml_str, ltl) acc_fml)
        S.empty
        fmls
      
      
      |> S.rev
    in
    
    let syms_fmls = syms_to_ltl elo in
    
    let goal_blk = match elo.goal with Elo.Run (g, _) -> g in
    
    let detected_inits, detected_invars, detected_trans, general_fmls =
      split_invar_noninvar_fmls elo goal_blk
    in
    
    
    
    let spec_fml = dualise_fmls general_fmls in
    
    let spec_fml_str, prop_ltl = ConvertFormulas.convert elo spec_fml in
    
    let inits = translate_formulas detected_inits in
    let invars =
      translate_formulas @@ List.append detected_invars elo.Elo.invariants
    in
    let trans = translate_formulas detected_trans in
    Model.make
      ~elo
      ~init:S.(append inits syms_fmls)
      ~invariant:invars
      ~trans
      ~property:(spec_fml_str, prop_ltl)
end