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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:32:11+00:00 2026-06-12T06:32:11+00:00

I am asking this question in context of sat solver. Lets suppose I have

  • 0

I am asking this question in context of sat solver.
Lets suppose I have 100 integer variables x1, x2, x3 ... x100 which are assigned a value randomly between 1 to N. I want to make sure that at least one variable of x1 to x100 should have each of value from 1 to N.

Now I would like to encode this problem in sat solver constraints. Since while writing the constraints I don’t know the value N, it is difficult to me to code as below –

(assert (x1 = 0 or x2 = 0 or ... x100 = 0))
(assert (x1 = 1 or x2 = 1 or ... x100 = 1))
(assert (x1 = 2 or x2 = 2 or ... x100 = 2))
...
(assert (x1 = N or x2 = N or ... x100 = N))

Lets say, that at the end, I assert the value of N to be 2, then the above constraints will not work. Further to that, I would not like to use arrays or un-interpreted functions for performance reasons.

Update :

In Short, the constraints are as follows –

  1. N < 100
  2. (Lets say N = 20), then there are 20 variables which maybe be any of them from x_1 to x_100 which are distinct. So this constraint will ensure that there will be assignment of at least one variable for each of values from 1 to N.
  3. The values of remaining variables (100-N) can overlap each other.

Can anyone give me some suggestions?

  • 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-12T06:32:13+00:00Added an answer on June 12, 2026 at 6:32 am

    How about combining Kyle’s answer with distinct, for up to n of the x_i variables (randomly chosen)?

    This will give a model like (for N = 50 and 100 x_i variables):

     x = [0 -> 1,
      1 -> 11,
      2 -> 50,
      3 -> 1,
      4 -> 2,
      5 -> 1,
      6 -> 36,
      7 -> 1,
      8 -> 34,
      9 -> 1,
      10 -> 13,
      11 -> 5,
      12 -> 7,
      13 -> 23,
      14 -> 1,
      15 -> 40,
      16 -> 42,
      17 -> 1,
      18 -> 1,
      19 -> 1,
      20 -> 16,
      21 -> 33,
      22 -> 1,
      23 -> 17,
      24 -> 20,
      25 -> 1,
      26 -> 9,
      27 -> 44,
      28 -> 1,
      29 -> 49,
      30 -> 26,
      31 -> 1,
      32 -> 29,
      33 -> 46,
      34 -> 8,
      35 -> 1,
      36 -> 27,
      37 -> 1,
      38 -> 1,
      39 -> 32,
      40 -> 1,
      41 -> 31,
      42 -> 1,
      43 -> 1,
      44 -> 14,
      45 -> 1,
      46 -> 1,
      47 -> 1,
      48 -> 1,
      49 -> 1,
      50 -> 35,
      51 -> 19,
      52 -> 43,
      53 -> 22,
      54 -> 1,
      55 -> 1,
      56 -> 1,
      57 -> 1,
      58 -> 21,
      59 -> 1,
      60 -> 1,
      61 -> 39,
      62 -> 28,
      63 -> 12,
      64 -> 1,
      65 -> 1,
      66 -> 1,
      67 -> 1,
      68 -> 1,
      69 -> 41,
      70 -> 1,
      71 -> 25,
      72 -> 1,
      73 -> 6,
      74 -> 1,
      75 -> 1,
      76 -> 1,
      77 -> 1,
      78 -> 1,
      79 -> 24,
      80 -> 1,
      81 -> 30,
      82 -> 38,
      83 -> 3,
      84 -> 4,
      85 -> 1,
      86 -> 1,
      87 -> 1,
      88 -> 1,
      89 -> 1,
      90 -> 18,
      91 -> 1,
      92 -> 47,
      93 -> 37,
      94 -> 1,
      95 -> 45,
      96 -> 1,
      97 -> 15,
      98 -> 48,
      99 -> 10,
      else -> 1],
    

    Here’s a Z3Py script accomplishing this, assuming the first N indices can be constrained, instead of random ones (and using a function for x instead of constants so it was faster to write): http://rise4fun.com/Z3Py/M3TG

    Next is code for doing this for a random set of indices, but you can’t run this on Z3Py@Rise, because it does not allow using imports, so you’ll have to run it locally.

    from random import *
    from z3 import *
    
    x = Function('x', IntSort(), IntSort())
    
    M = 100
    N = 50
    
    s = Solver()
    idxs = sample(xrange(M),N) # get N random ids from sequence {1,...M}
    print idxs
    
    distinctlist = []
    for i in range(M):
      s.add(And(x(i) >= 1, x(i) <= N))
      if i in idxs:
        distinctlist.append(x(i))
    
    print distinctlist
    
    s.add(Distinct(distinctlist))
    
    print "checking..."
    
    r = s.check()
    print r
    if r == sat:
      print s.model()
    

    (Beware if you make this query unsat, it may timeout.)

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

Sidebar

Related Questions

I am finally asking this question as I have never actually found an answer.
I'm asking this question because I have gone through the tutorial posted here: Preventing
I am asking this question in the context of computers and microcontrollers. I need
Appologies if I am asking a inappropraite question but I have been hearing this
Before asking a question i will shortly describe the context. I have a Widget
In asking this question, I'm looking for either better understanding of the situation or
I searched before asking this question. I didn't find an answer probably because I
I am asking this question here because it is my understanding that this is
I searched SO before asking this question, I am completely new to this and
No luck asking this question on the AWS forum , so will try my

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.