Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:05:38+00:00 2026-06-11T23:05:38+00:00

How can I get real python values from a Z3 model? E.g. p =

  • 0

How can I get real python values from a Z3 model?

E.g.

p = Bool('p')
x = Real('x')
s = Solver()
s.add(Or(x < 5, x > 10), Or(p, x**2 == 2), Not(p))
s.check()
print s.model()[x]
print s.model()[p]

prints

-1.4142135623?
False

but those are Z3 objects and not python float/bool objects.

I know that I can check boolean values using is_true/is_false, but how can I elegantly convert ints/reals/… back to usable values (without going through strings and cutting away this extra ? symbol, for example).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:05:39+00:00Added an answer on June 11, 2026 at 11:05 pm

    For Boolean values, you can use the functions is_true and is_false. Numerical values can be integer, rational or algebraic. We can use the functions is_int_value, is_rational_value and is_algebraic_value to test each case. The integer case is the simplest, we can use the method as_long() to convert the Z3 integer value into a Python long. For rational values, we can use the methods numerator() and denominator() to obtain the Z3 integers representing the numerator and denominator. The methods numerator_as_long() and denominator_as_long() are shortcuts for self.numerator().as_long() and self.denominator().as_long(). Finally, algebraic numbers are used to represent irrational numbers. The AlgebraicNumRef class has a method called approx(self, precision). It returns a Z3 rational number that approximates the algebraic number with precision 1/10^precision. Here is an example on how to use this methods. It is also available online at: http://rise4fun.com/Z3Py/Mkw

    p = Bool('p')
    x = Real('x')
    s = Solver()
    s.add(Or(x < 5, x > 10), Or(p, x**2 == 2), Not(p))
    s.check()
    m = s.model()
    print m[p], m[x]
    print "is_true(m[p]):", is_true(m[p])
    print "is_false(m[p]):", is_false(m[p])
    print "is_int_value(m[x]):", is_int_value(m[x])
    print "is_rational_value(m[x]):", is_rational_value(m[x])
    print "is_algebraic_value(m[x]):", is_algebraic_value(m[x])
    r = m[x].approx(20) # r is an approximation of m[x] with precision 1/10^20
    print "is_rational_value(r):", is_rational_value(r)
    print r.numerator_as_long()
    print r.denominator_as_long()
    print float(r.numerator_as_long())/float(r.denominator_as_long())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Real noob question no doubt, but I can't get my head around this behaviour.
I can get this to work: [<DllImport(user32.dll)>] extern bool GetClientRect(nativeint, RECT*) let getClientRect hwnd
short version: how can I get rid of the multiple-versions-of-python nightmare ? long version:
How can I check if a file uploaded by a user is a real
Can get all triples with value null in specific field? All people with date_of_birth
We can get class Class object by 3 methods: MyClass.class obj.getClass Class.forName(className) I don't
I can get the file path with: (message (file-name-directory (or buffer-file-name load-file-name))) But if
You can get the nodes of the document object of an <iframe> with the
You can get underground processes by ps ux I am searching a way to
You can get a list of databases using PRAGMA database_list or a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.