]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/terms.ml
Branched paramodulation for CNF (Horn clauses)
[helm.git] / helm / software / components / ng_paramodulation / terms.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 (* $Id$ *)
13
14 type 'a foterm = 
15   | Leaf of 'a
16   | Var of int
17   | Node of ('a foterm) list
18
19 type 'a substitution = (int * 'a foterm) list
20
21 type comparison = Lt | Eq | Gt | Incomparable
22
23 type rule = Superposition | Demodulation
24 type direction = Left2Right | Right2Left | Nodir
25 type position = int list
26
27 type 'a proof =
28   | Exact of 'a foterm
29   | Step of rule * int * int * direction * position * 'a substitution
30          (* rule, eq1, eq2, direction of eq2, position, substitution *)
31
32 type 'a literal = 
33  | Equation of    'a foterm  (* lhs *)
34                 * 'a foterm  (* rhs *)
35                 * 'a foterm  (* type *)
36                 * comparison (* orientation *)
37  | Predicate of   'a foterm 
38
39 type varlist = int list
40
41 type 'a unit_clause =
42    int        (* ID *)
43  * 'a literal
44  * varlist       (* variable list *)
45  * 'a proof      (* proof *)
46
47 type 'a clause =
48     int
49     * 'a literal list (* left hand side of the arrow *)
50     * 'a literal list (* right hand side of the arrow *)
51     * varlist
52     * 'a proof
53
54 type 'a passive_clause = int * 'a clause (* weight * equation *)
55
56
57 let vars_of_term ?(start_acc=[]) t =
58   let rec aux acc = function
59     | Leaf _ -> acc
60     | Var i -> if (List.mem i acc) then acc else i::acc
61     | Node l -> List.fold_left aux acc l
62   in aux start_acc t
63 ;;
64
65 module OT =
66  struct
67    type t = int 
68    let compare = Pervasives.compare
69  end
70
71 module M : Map.S with type key = int 
72   = Map.Make(OT) 
73
74 type 'a bag = int
75               * (('a unit_clause * bool * int) M.t)
76
77   let add_to_bag (_,lit,vl,proof) (id,bag) =
78     let id = id+1 in
79     let clause = (id, lit, vl, proof) in
80     let bag = M.add id (clause,false,0) bag in
81     (id,bag), clause 
82    ;;
83
84   let replace_in_bag ((id,_,_,_),_,_ as cl) (max_id,bag) =
85     let bag = M.add id cl bag in
86       (max_id,bag)
87   ;;
88
89   let get_from_bag id (_,bag) =
90     M.find id bag
91   ;;
92     
93   let empty_bag = (0,M.empty);;
94
95 module type Blob =
96   sig
97     type t
98     val eq : t -> t -> bool
99     val compare : t -> t -> int
100     val eqP : t
101     val pp : t -> string
102     type input
103     val embed : input -> t foterm
104     val saturate : input -> input -> t foterm * t foterm
105   end
106