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

  • SEARCH
  • Home
  • 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 7626979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:23:55+00:00 2026-05-31T05:23:55+00:00

Assuming the use of several built-in and user defined Z3 sorts, e.g. Int, Bool,

  • 0

Assuming the use of several built-in and user defined Z3 sorts, e.g. Int, Bool, S1, S2, …, is there a way of writing a generic sort-wrapping and -unwrapping function that kind of casts from sort A to sort B and back? For example

(declare-const a S1)
(declare-const b S2)
(declare-const c Int)

(WRAP[S1] b) ; Expression is of sort S1
(WRAP[S1] c) ; Expression is of sort S1
(WRAP[Int] (WRAP[S1] c)) ; Expression is of sort Int

I currently cover each case manually, e.g.

(declare-fun $boolToInt (Bool) Int)
(declare-fun $intToBool (Int) Bool)

(assert (forall ((x Int))
  (= x ($boolToInt($intToBool x)))))

(assert (forall ((x Bool))
  (= x ($intToBool($boolToInt x)))))

Such wrappers could be created automatically from a given set of sorts, but I would prefer a generic solution of possible.

  • 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-05-31T05:23:55+00:00Added an answer on May 31, 2026 at 5:23 am

    You can use datatypes to encode “union types”.
    Here is an example:

    (declare-sort S1)
    (declare-sort S2)
    
    (declare-datatypes () ((S1-S2-Int (WRAP-S1 (S1-Value S1))
                                      (WRAP-S2 (S2-Value S2))
                                      (WRAP-Int (Int-Value Int)))))
    
    (declare-const a S1)
    (declare-const b S2)
    (declare-const c Int)
    
    (simplify (WRAP-S1 a))
    (simplify (= (WRAP-S1 a) (WRAP-Int 10)))
    (simplify (S1-Value (WRAP-S1 a)))
    (simplify (is-WRAP-S2 (WRAP-S1 a)))
    (simplify (is-WRAP-S1 (WRAP-S1 a)))
    (simplify (is-WRAP-Int (WRAP-Int c)))
    (simplify (S1-Value (WRAP-S2 b)))
    

    You can find more information about datatypes in the Z3 guide. The datatype S1-S2-Int has three constructors: WRAP-S1, WRAP-S2 and WRAP-Int. Z3 automatically generates the recognizer predicates: is-WRAP-S1, is-WRAP-S2 and is-WRAP-Int. The accessors S1-Value, S2-Value and Int-Value are used to “deconstruct” a S1-S2-Int value. For example, for all a, (S1-Value (WRAP-S1 a)) = a. The value of (S1-Value (WRAP-S2 b)) is underspecified. In this case, Z3 treats S1-Value as a uninterpreted function.

    BTW, the axiom

    (assert (forall ((x Int))
      (= x ($boolToInt($intToBool x)))))
    

    is equivalent to false. It is essentially trying to inject the integers into the Booleans.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a web app that needs to use several ansi C functions to
There are several packages in my application that user can select each one according
I've been googling this one and haven't turned up anything useful: Assuming you use
Assuming I have to use C (no C++ or object oriented compilers) and I
Can I use specific html if the browser is IE? (Assuming FF is the
Assuming sr is an IEnumerable<string> , I want to use code like this to
What underlying rendering system does the Qt GUI toolkit use on Windows? (I'm assuming
Assuming all my Gradle plugin user going to have a MYAPP_HOME sys variable set
I have several functions which use jquery that are called across different pages. I'm
The Quetion Hello. I'm trying to figure out the best way to use one

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.