-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuantifier.java
More file actions
214 lines (192 loc) · 6.62 KB
/
Quantifier.java
File metadata and controls
214 lines (192 loc) · 6.62 KB
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
212
213
214
/**
* This file was automatically generated from Quantifier.cs
* w/ further modifications by:
* @author Christoph M. Wintersteiger (cwinter)
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_ast_kind;
/**
* Quantifier expressions.
**/
public class Quantifier extends BoolExpr
{
/**
* Indicates whether the quantifier is universal.
**/
public boolean isUniversal() throws Z3Exception
{
return Native.isQuantifierForall(getContext().nCtx(), getNativeObject());
}
/**
* Indicates whether the quantifier is existential.
**/
public boolean isExistential() throws Z3Exception
{
return !isUniversal();
}
/**
* The weight of the quantifier.
**/
public int getWeight() throws Z3Exception
{
return Native.getQuantifierWeight(getContext().nCtx(), getNativeObject());
}
/**
* The number of patterns.
**/
public int getNumPatterns() throws Z3Exception
{
return Native
.getQuantifierNumPatterns(getContext().nCtx(), getNativeObject());
}
/**
* The patterns.
*
* @throws Z3Exception
**/
public Pattern[] getPatterns() throws Z3Exception
{
int n = getNumPatterns();
Pattern[] res = new Pattern[n];
for (int i = 0; i < n; i++)
res[i] = new Pattern(getContext(), Native.getQuantifierPatternAst(
getContext().nCtx(), getNativeObject(), i));
return res;
}
/**
* The number of no-patterns.
**/
public int getNumNoPatterns() throws Z3Exception
{
return Native.getQuantifierNumNoPatterns(getContext().nCtx(),
getNativeObject());
}
/**
* The no-patterns.
*
* @throws Z3Exception
**/
public Pattern[] getNoPatterns() throws Z3Exception
{
int n = getNumNoPatterns();
Pattern[] res = new Pattern[n];
for (int i = 0; i < n; i++)
res[i] = new Pattern(getContext(), Native.getQuantifierNoPatternAst(
getContext().nCtx(), getNativeObject(), i));
return res;
}
/**
* The number of bound variables.
**/
public int getNumBound() throws Z3Exception
{
return Native.getQuantifierNumBound(getContext().nCtx(), getNativeObject());
}
/**
* The symbols for the bound variables.
*
* @throws Z3Exception
**/
public Symbol[] getBoundVariableNames() throws Z3Exception
{
int n = getNumBound();
Symbol[] res = new Symbol[n];
for (int i = 0; i < n; i++)
res[i] = Symbol.create(getContext(), Native.getQuantifierBoundName(
getContext().nCtx(), getNativeObject(), i));
return res;
}
/**
* The sorts of the bound variables.
*
* @throws Z3Exception
**/
public Sort[] getBoundVariableSorts() throws Z3Exception
{
int n = getNumBound();
Sort[] res = new Sort[n];
for (int i = 0; i < n; i++)
res[i] = Sort.create(getContext(), Native.getQuantifierBoundSort(
getContext().nCtx(), getNativeObject(), i));
return res;
}
/**
* The body of the quantifier.
*
* @throws Z3Exception
**/
public BoolExpr getBody() throws Z3Exception
{
return new BoolExpr(getContext(), Native.getQuantifierBody(getContext()
.nCtx(), getNativeObject()));
}
Quantifier(Context ctx, boolean isForall, Sort[] sorts, Symbol[] names,
Expr body, int weight, Pattern[] patterns, Expr[] noPatterns,
Symbol quantifierID, Symbol skolemID) throws Z3Exception
{
super(ctx);
getContext().checkContextMatch(patterns);
getContext().checkContextMatch(noPatterns);
getContext().checkContextMatch(sorts);
getContext().checkContextMatch(names);
getContext().checkContextMatch(body);
if (sorts.length != names.length)
throw new Z3Exception(
"Number of sorts does not match number of names");
if (noPatterns == null && quantifierID == null && skolemID == null)
{
setNativeObject(Native.mkQuantifier(ctx.nCtx(), (isForall) ? true
: false, weight, AST.arrayLength(patterns), AST
.arrayToNative(patterns), AST.arrayLength(sorts), AST
.arrayToNative(sorts), Symbol.arrayToNative(names), body
.getNativeObject()));
} else
{
setNativeObject(Native.mkQuantifierEx(ctx.nCtx(),
(isForall) ? true : false, weight, AST.getNativeObject(quantifierID),
AST.getNativeObject(skolemID),
AST.arrayLength(patterns), AST.arrayToNative(patterns),
AST.arrayLength(noPatterns), AST.arrayToNative(noPatterns),
AST.arrayLength(sorts), AST.arrayToNative(sorts),
Symbol.arrayToNative(names),
body.getNativeObject()));
}
}
Quantifier(Context ctx, boolean isForall, Expr[] bound, Expr body,
int weight, Pattern[] patterns, Expr[] noPatterns,
Symbol quantifierID, Symbol skolemID) throws Z3Exception
{
super(ctx);
getContext().checkContextMatch(noPatterns);
getContext().checkContextMatch(patterns);
// Context().CheckContextMatch(bound);
getContext().checkContextMatch(body);
if (noPatterns == null && quantifierID == null && skolemID == null)
{
setNativeObject(Native.mkQuantifierConst(ctx.nCtx(),
(isForall) ? true : false, weight, AST.arrayLength(bound),
AST.arrayToNative(bound), AST.arrayLength(patterns),
AST.arrayToNative(patterns), body.getNativeObject()));
} else
{
setNativeObject(Native.mkQuantifierConstEx(ctx.nCtx(),
(isForall) ? true : false, weight,
AST.getNativeObject(quantifierID),
AST.getNativeObject(skolemID), AST.arrayLength(bound),
AST.arrayToNative(bound), AST.arrayLength(patterns),
AST.arrayToNative(patterns), AST.arrayLength(noPatterns),
AST.arrayToNative(noPatterns), body.getNativeObject()));
}
}
Quantifier(Context ctx, long obj) throws Z3Exception
{
super(ctx, obj);
}
void checkNativeObject(long obj) throws Z3Exception
{
if (Native.getAstKind(getContext().nCtx(), obj) != Z3_ast_kind.Z3_QUANTIFIER_AST
.toInt())
throw new Z3Exception("Underlying object is not a quantifier");
super.checkNativeObject(obj);
}
}