Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about combining Kyle's answer with distinct, for up to n of the x_i variables (randomly chosen)?</p> <p>This will give a model like (for N = 50 and 100 x_i variables):</p> <pre><code> x = [0 -&gt; 1, 1 -&gt; 11, 2 -&gt; 50, 3 -&gt; 1, 4 -&gt; 2, 5 -&gt; 1, 6 -&gt; 36, 7 -&gt; 1, 8 -&gt; 34, 9 -&gt; 1, 10 -&gt; 13, 11 -&gt; 5, 12 -&gt; 7, 13 -&gt; 23, 14 -&gt; 1, 15 -&gt; 40, 16 -&gt; 42, 17 -&gt; 1, 18 -&gt; 1, 19 -&gt; 1, 20 -&gt; 16, 21 -&gt; 33, 22 -&gt; 1, 23 -&gt; 17, 24 -&gt; 20, 25 -&gt; 1, 26 -&gt; 9, 27 -&gt; 44, 28 -&gt; 1, 29 -&gt; 49, 30 -&gt; 26, 31 -&gt; 1, 32 -&gt; 29, 33 -&gt; 46, 34 -&gt; 8, 35 -&gt; 1, 36 -&gt; 27, 37 -&gt; 1, 38 -&gt; 1, 39 -&gt; 32, 40 -&gt; 1, 41 -&gt; 31, 42 -&gt; 1, 43 -&gt; 1, 44 -&gt; 14, 45 -&gt; 1, 46 -&gt; 1, 47 -&gt; 1, 48 -&gt; 1, 49 -&gt; 1, 50 -&gt; 35, 51 -&gt; 19, 52 -&gt; 43, 53 -&gt; 22, 54 -&gt; 1, 55 -&gt; 1, 56 -&gt; 1, 57 -&gt; 1, 58 -&gt; 21, 59 -&gt; 1, 60 -&gt; 1, 61 -&gt; 39, 62 -&gt; 28, 63 -&gt; 12, 64 -&gt; 1, 65 -&gt; 1, 66 -&gt; 1, 67 -&gt; 1, 68 -&gt; 1, 69 -&gt; 41, 70 -&gt; 1, 71 -&gt; 25, 72 -&gt; 1, 73 -&gt; 6, 74 -&gt; 1, 75 -&gt; 1, 76 -&gt; 1, 77 -&gt; 1, 78 -&gt; 1, 79 -&gt; 24, 80 -&gt; 1, 81 -&gt; 30, 82 -&gt; 38, 83 -&gt; 3, 84 -&gt; 4, 85 -&gt; 1, 86 -&gt; 1, 87 -&gt; 1, 88 -&gt; 1, 89 -&gt; 1, 90 -&gt; 18, 91 -&gt; 1, 92 -&gt; 47, 93 -&gt; 37, 94 -&gt; 1, 95 -&gt; 45, 96 -&gt; 1, 97 -&gt; 15, 98 -&gt; 48, 99 -&gt; 10, else -&gt; 1], </code></pre> <p>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): <a href="http://rise4fun.com/Z3Py/M3TG" rel="nofollow">http://rise4fun.com/Z3Py/M3TG</a></p> <p>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.</p> <pre><code>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) &gt;= 1, x(i) &lt;= 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() </code></pre> <p>(Beware if you make this query unsat, it may timeout.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload