Given a Z3 Sort and a string s
I am trying to create a Z3 constant of that sort named s
.
For instance, given IntSort()
and the name "x"
I'd like to get an integer constant named "x"
.
I know I can get it calling Int('x')
but since I am creating this variables dynamically I cannot predict what sort a given variable will have. What I have to do is to create a variable of the same sort of the one provided by the system but with a new name (which I have to be able to specify at runtime).
To be more specific,
1. I get a model for a user defined formula calling the Z3 Solver on it,
2. I save it in a database (recording for each assignment in such a model the variable name, the value to be assigned to it and the sort of that variable)
3. I retrieve that assignment after a while from the database and I try it o a new formula having the same variables of the original one.
In order to do so I turn each assignment into a clause of the form var == value
, I add them to the solver together with the target formula and I check for satisfiability.
Up to now I only worked with the integer sort so I hardcoded the transformation of string to constants using the Int
function. Now I am trying to generalize the approach to different logics and different datatypes so I need something to create the right constant out of what I saved in my database.
Is this approach reasonable in your opinion? Do you think there any trick to do it better?