Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Integer value from Instance in Z3

Tags:

casting

z3

sat

My code is

def test():
    s = Solver()
    a = Int('x')
    b = Int('y')
    s.add(a*b==22)
    print s.check()
    return s.model()[a], s.model()[b]

This will print numbers, but when you see type(s.model()[a]) or type(s.model()[b]) it will give <type 'instance'> . How to cast it in a way it will return <type 'int'> ? I cannot use the return type into my code any further as it returned instance even though if you print s.model()[a] it will look like a integer but it isn't.

like image 884
user8877134 Avatar asked Oct 17 '25 13:10

user8877134


1 Answers

Simply use the as_long method. That is, replace the last line in your function with:

   return s.model()[a].as_long(), s.model()[b].as_long()
like image 174
alias Avatar answered Oct 20 '25 04:10

alias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!