39348
|
1 |
(* ========================================================================= *)
|
|
2 |
(* FIRST ORDER LOGIC TERMS *)
|
39502
|
3 |
(* Copyright (c) 2001 Joe Hurd, distributed under the BSD License *)
|
39348
|
4 |
(* ========================================================================= *)
|
|
5 |
|
|
6 |
signature Term =
|
|
7 |
sig
|
|
8 |
|
|
9 |
(* ------------------------------------------------------------------------- *)
|
|
10 |
(* A type of first order logic terms. *)
|
|
11 |
(* ------------------------------------------------------------------------- *)
|
|
12 |
|
|
13 |
type var = Name.name
|
|
14 |
|
|
15 |
type functionName = Name.name
|
|
16 |
|
|
17 |
type function = functionName * int
|
|
18 |
|
|
19 |
type const = functionName
|
|
20 |
|
|
21 |
datatype term =
|
|
22 |
Var of var
|
|
23 |
| Fn of functionName * term list
|
|
24 |
|
|
25 |
(* ------------------------------------------------------------------------- *)
|
|
26 |
(* Constructors and destructors. *)
|
|
27 |
(* ------------------------------------------------------------------------- *)
|
|
28 |
|
|
29 |
(* Variables *)
|
|
30 |
|
|
31 |
val destVar : term -> var
|
|
32 |
|
|
33 |
val isVar : term -> bool
|
|
34 |
|
|
35 |
val equalVar : var -> term -> bool
|
|
36 |
|
|
37 |
(* Functions *)
|
|
38 |
|
|
39 |
val destFn : term -> functionName * term list
|
|
40 |
|
|
41 |
val isFn : term -> bool
|
|
42 |
|
|
43 |
val fnName : term -> functionName
|
|
44 |
|
|
45 |
val fnArguments : term -> term list
|
|
46 |
|
|
47 |
val fnArity : term -> int
|
|
48 |
|
|
49 |
val fnFunction : term -> function
|
|
50 |
|
|
51 |
val functions : term -> NameAritySet.set
|
|
52 |
|
|
53 |
val functionNames : term -> NameSet.set
|
|
54 |
|
|
55 |
(* Constants *)
|
|
56 |
|
|
57 |
val mkConst : const -> term
|
|
58 |
|
|
59 |
val destConst : term -> const
|
|
60 |
|
|
61 |
val isConst : term -> bool
|
|
62 |
|
|
63 |
(* Binary functions *)
|
|
64 |
|
|
65 |
val mkBinop : functionName -> term * term -> term
|
|
66 |
|
|
67 |
val destBinop : functionName -> term -> term * term
|
|
68 |
|
|
69 |
val isBinop : functionName -> term -> bool
|
|
70 |
|
|
71 |
(* ------------------------------------------------------------------------- *)
|
|
72 |
(* The size of a term in symbols. *)
|
|
73 |
(* ------------------------------------------------------------------------- *)
|
|
74 |
|
|
75 |
val symbols : term -> int
|
|
76 |
|
|
77 |
(* ------------------------------------------------------------------------- *)
|
|
78 |
(* A total comparison function for terms. *)
|
|
79 |
(* ------------------------------------------------------------------------- *)
|
|
80 |
|
|
81 |
val compare : term * term -> order
|
|
82 |
|
|
83 |
val equal : term -> term -> bool
|
|
84 |
|
|
85 |
(* ------------------------------------------------------------------------- *)
|
|
86 |
(* Subterms. *)
|
|
87 |
(* ------------------------------------------------------------------------- *)
|
|
88 |
|
|
89 |
type path = int list
|
|
90 |
|
|
91 |
val subterm : term -> path -> term
|
|
92 |
|
|
93 |
val subterms : term -> (path * term) list
|
|
94 |
|
|
95 |
val replace : term -> path * term -> term
|
|
96 |
|
|
97 |
val find : (term -> bool) -> term -> path option
|
|
98 |
|
|
99 |
val ppPath : path Print.pp
|
|
100 |
|
|
101 |
val pathToString : path -> string
|
|
102 |
|
|
103 |
(* ------------------------------------------------------------------------- *)
|
|
104 |
(* Free variables. *)
|
|
105 |
(* ------------------------------------------------------------------------- *)
|
|
106 |
|
|
107 |
val freeIn : var -> term -> bool
|
|
108 |
|
|
109 |
val freeVars : term -> NameSet.set
|
|
110 |
|
|
111 |
val freeVarsList : term list -> NameSet.set
|
|
112 |
|
|
113 |
(* ------------------------------------------------------------------------- *)
|
|
114 |
(* Fresh variables. *)
|
|
115 |
(* ------------------------------------------------------------------------- *)
|
|
116 |
|
|
117 |
val newVar : unit -> term
|
|
118 |
|
|
119 |
val newVars : int -> term list
|
|
120 |
|
|
121 |
val variantPrime : NameSet.set -> var -> var
|
|
122 |
|
|
123 |
val variantNum : NameSet.set -> var -> var
|
|
124 |
|
|
125 |
(* ------------------------------------------------------------------------- *)
|
|
126 |
(* Special support for terms with type annotations. *)
|
|
127 |
(* ------------------------------------------------------------------------- *)
|
|
128 |
|
|
129 |
val hasTypeFunctionName : functionName
|
|
130 |
|
|
131 |
val hasTypeFunction : function
|
|
132 |
|
|
133 |
val isTypedVar : term -> bool
|
|
134 |
|
|
135 |
val typedSymbols : term -> int
|
|
136 |
|
|
137 |
val nonVarTypedSubterms : term -> (path * term) list
|
|
138 |
|
|
139 |
(* ------------------------------------------------------------------------- *)
|
|
140 |
(* Special support for terms with an explicit function application operator. *)
|
|
141 |
(* ------------------------------------------------------------------------- *)
|
|
142 |
|
|
143 |
val appName : Name.name
|
|
144 |
|
|
145 |
val mkApp : term * term -> term
|
|
146 |
|
|
147 |
val destApp : term -> term * term
|
|
148 |
|
|
149 |
val isApp : term -> bool
|
|
150 |
|
|
151 |
val listMkApp : term * term list -> term
|
|
152 |
|
|
153 |
val stripApp : term -> term * term list
|
|
154 |
|
|
155 |
(* ------------------------------------------------------------------------- *)
|
|
156 |
(* Parsing and pretty printing. *)
|
|
157 |
(* ------------------------------------------------------------------------- *)
|
|
158 |
|
|
159 |
(* Infix symbols *)
|
|
160 |
|
|
161 |
val infixes : Print.infixes ref
|
|
162 |
|
|
163 |
(* The negation symbol *)
|
|
164 |
|
|
165 |
val negation : string ref
|
|
166 |
|
|
167 |
(* Binder symbols *)
|
|
168 |
|
|
169 |
val binders : string list ref
|
|
170 |
|
|
171 |
(* Bracket symbols *)
|
|
172 |
|
|
173 |
val brackets : (string * string) list ref
|
|
174 |
|
|
175 |
(* Pretty printing *)
|
|
176 |
|
|
177 |
val pp : term Print.pp
|
|
178 |
|
|
179 |
val toString : term -> string
|
|
180 |
|
|
181 |
(* Parsing *)
|
|
182 |
|
|
183 |
val fromString : string -> term
|
|
184 |
|
|
185 |
val parse : term Parse.quotation -> term
|
|
186 |
|
|
187 |
end
|