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 6918663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:53:18+00:00 2026-05-27T09:53:18+00:00

This is mainly a logic problem I guess… I use this smtlib formula: (declare-fun

  • 0

This is mainly a logic problem I guess…

I use this smtlib formula:

(declare-fun a () Bool)
(declare-fun b () Bool)
(declare-fun c () Bool)
(declare-fun d () Bool)
(assert (xor (and a (xor b c)) d))

Which is a term of this structure(in my opinion, at least):

    XOR
    | |
  AND d
  | |
  a XOR
    | |
    b c

My guess: The resultSet would look like this:

{ab, ac, d}

But its this using scala^z3 ctx.checkAndGetAllModels():

{ab, d, ac, ad, abcd}

Why is ad and abcd in there?
Is it possible to get only the results I would expect?

  • 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-27T09:53:19+00:00Added an answer on May 27, 2026 at 9:53 am

    Using Scala (without Z3) to show that there are, in fact, more solutions to the constraint:

    val tf = Seq(true, false)
    val allValid =
      for(a <- tf; b <- tf; c <- tf; d <- tf; 
          if((a && (b ^ c)) ^ d)) yield (
        (if(a) "a" else "") + (if(b) "b" else "") +
        (if(c) "c" else "") + (if(d) "d" else ""))
    
    allValid.mkString("{ ", ", ", " }")
    

    Prints:

    { abcd, ab, ac, ad, bcd, bd, cd, d }
    

    So unless I’m missing something, the question is, why does it not find all solutions? Now here is the answer to that one. (Spoiler alert: “getAllModels” doesn’t really get all models.) First, let’s reproduce what you observed:

    import z3.scala._
    val ctx = new Z3Context("MODEL" -> true)
    val a = ctx.mkFreshConst("a", ctx.mkBoolSort)
    val b = ctx.mkFreshConst("b", ctx.mkBoolSort)
    val c = ctx.mkFreshConst("c", ctx.mkBoolSort)
    val d = ctx.mkFreshConst("d", ctx.mkBoolSort)
    val cstr0 = ctx.mkXor(b, c)
    val cstr1 = ctx.mkAnd(a, cstr0)
    val cstr2 = ctx.mkXor(cstr1, d)
    ctx.assertCnstr(cstr2)
    

    Now, if I run: ctx.checkAndGetAllModels.foreach(println(_)), I get:

    d!3 -> false
    a!0 -> true
    c!2 -> false
    b!1 -> true
    
    d!3 -> true    // this model is problematic
    a!0 -> false
    
    d!3 -> false
    a!0 -> true
    c!2 -> true
    b!1 -> false
    
    d!3 -> true
    a!0 -> true
    c!2 -> false
    b!1 -> false
    
    d!3 -> true
    a!0 -> true
    c!2 -> true
    b!1 -> true
    

    Now, the problem is that the second model is an incomplete model. Z3 can return it, because whatever the values for b and c are, the constraint is satisfied (b and c are don’t-care variables). The current implementation of checkAndGetAllModels simply negates the model to prevent repetition; in this case, it will ask for another model such that (not (and d (not a))) holds. This will prevent all other models with this two values from being returned. In a sense, the incomplete model actually represents four valid, completed, models.

    By the way, what happens if you use the DSL of ScalaZ3 with the findAll function is that all models will be completed with default values when they are incomplete (and before they are used to compute the next one). In the context of the DSL we can do this, because we know the set of variables that appear in the formula. In this case, it’s harder to guess how the model should be completed. One option would be for ScalaZ3 to remember which variables were used. A better solution would be for Z3 to have an option to always return values for don’t-care variables, or perhaps simply to list all don’t-care variables in a model.

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

Sidebar

Related Questions

When you say thin data access layer, does this mainly mean you are talking
There is an application with an extensive object graph. This graph mainly consists of
This question is mainly to verify my current idea. I have a series of
I'm mainly asking this to professionals who know the playing field of professional developing.
This question and my answer below are mainly in response to an area of
Hey guys, hope this isn't too much of a n00b question I'm mainly a
The company where I work created this application which is core to our business
Which are the approach (simplest possible) that we can use to get notified for
I tagged this question both Java and Scala because while I mainly develop on
This question is mainly geared towards Zend in PHP, although it certainly applies to

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.