Z3
 
Loading...
Searching...
No Matches
FuncInterp.cs
Go to the documentation of this file.
1/*++
2Copyright (c) 2012 Microsoft Corporation
3
4Module Name:
5
6 FuncInterp.cs
7
8Abstract:
9
10 Z3 Managed API: Function Interpretations
11
12Author:
13
14 Christoph Wintersteiger (cwinter) 2012-03-21
15
16Notes:
17
18--*/
19
20using System.Diagnostics;
21using System;
22
23namespace Microsoft.Z3
24{
29 public class FuncInterp : Z3Object
30 {
35 public class Entry : Z3Object
36 {
40 public Expr Value
41 {
42 get
43 {
44 return Expr.Create(Context, Native.Z3_func_entry_get_value(Context.nCtx, NativeObject));
45 }
46 }
47
51 public uint NumArgs
52 {
53 get { return Native.Z3_func_entry_get_num_args(Context.nCtx, NativeObject); }
54 }
55
59 public Expr[] Args
60 {
61 get
62 {
63
64 uint n = NumArgs;
65 Expr[] res = new Expr[n];
66 for (uint i = 0; i < n; i++)
67 res[i] = Expr.Create(Context, Native.Z3_func_entry_get_arg(Context.nCtx, NativeObject, i));
68 return res;
69 }
70 }
71
75 public override string ToString()
76 {
77 uint n = NumArgs;
78 string res = "[";
79 Expr[] args = Args;
80 for (uint i = 0; i < n; i++)
81 res += args[i] + ", ";
82 return res + Value + "]";
83 }
84
85 #region Internal
86 internal Entry(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
87
88 internal override void IncRef(IntPtr o)
89 {
90 Native.Z3_func_entry_inc_ref(Context.nCtx, o);
91 }
92
93 internal override void DecRef(IntPtr o)
94 {
95 lock (Context)
96 {
97 if (Context.nCtx != IntPtr.Zero)
98 Native.Z3_func_entry_dec_ref(Context.nCtx, o);
99 }
100 }
101 #endregion
102 };
103
107 public uint NumEntries
108 {
109 get { return Native.Z3_func_interp_get_num_entries(Context.nCtx, NativeObject); }
110 }
111
115 public Entry[] Entries
116 {
117 get
118 {
119
120 uint n = NumEntries;
121 Entry[] res = new Entry[n];
122 for (uint i = 0; i < n; i++)
123 res[i] = new Entry(Context, Native.Z3_func_interp_get_entry(Context.nCtx, NativeObject, i));
124 return res;
125 }
126 }
127
131 public Expr Else
132 {
133 get
134 {
135
136 return Expr.Create(Context, Native.Z3_func_interp_get_else(Context.nCtx, NativeObject));
137 }
138 }
139
143 public uint Arity
144 {
145 get { return Native.Z3_func_interp_get_arity(Context.nCtx, NativeObject); }
146 }
147
151 public override string ToString()
152 {
153 string res = "";
154 res += "[";
155 foreach (Entry e in Entries)
156 {
157 uint n = e.NumArgs;
158 if (n > 1) res += "[";
159 Expr[] args = e.Args;
160 for (uint i = 0; i < n; i++)
161 {
162 if (i != 0) res += ", ";
163 res += args[i];
164 }
165 if (n > 1) res += "]";
166 res += " -> " + e.Value + ", ";
167 }
168 res += "else -> " + Else;
169 res += "]";
170 return res;
171 }
172
173 #region Internal
174 internal FuncInterp(Context ctx, IntPtr obj)
175 : base(ctx, obj)
176 {
177 Debug.Assert(ctx != null);
178 }
179
180 internal override void IncRef(IntPtr o)
181 {
182 Native.Z3_func_interp_inc_ref(Context.nCtx, o);
183 }
184
185 internal override void DecRef(IntPtr o)
186 {
187 lock (Context)
188 {
189 if (Context.nCtx != IntPtr.Zero)
190 Native.Z3_func_interp_dec_ref(Context.nCtx, o);
191 }
192 }
193 #endregion
194 }
195}
The main interaction with Z3 happens via the Context.
Definition Context.cs:34
Expressions are terms.
Definition Expr.cs:31
An Entry object represents an element in the finite map used to encode a function interpretation.
Definition FuncInterp.cs:36
uint NumArgs
The number of arguments of the entry.
Definition FuncInterp.cs:52
Expr Value
Return the (symbolic) value of this entry.
Definition FuncInterp.cs:41
Expr[] Args
The arguments of the function entry.
Definition FuncInterp.cs:60
override string ToString()
A string representation of the function entry.
Definition FuncInterp.cs:75
A function interpretation is represented as a finite map and an 'else' value. Each entry in the finit...
Definition FuncInterp.cs:30
uint Arity
The arity of the function interpretation.
override string ToString()
A string representation of the function interpretation.
Entry[] Entries
The entries in the function interpretation.
uint NumEntries
The number of entries in the function interpretation.
Expr Else
The (symbolic) ‘else’ value of the function interpretation.
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Definition Z3Object.cs:33
Context Context
Access Context object.
Definition Z3Object.cs:111