<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-41126578026266439</id><updated>2011-04-21T19:36:04.182-07:00</updated><title type='text'>queens problem solution</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://summerschool-ashish.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/41126578026266439/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://summerschool-ashish.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>ashish</name><uri>http://www.blogger.com/profile/15533464648853562382</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-41126578026266439.post-8837734878665541510</id><published>2008-07-24T00:01:00.000-07:00</published><updated>2008-07-24T08:54:36.610-07:00</updated><title type='text'>queens problem solution</title><content type='html'>Hi guys ,&lt;br /&gt;                 i would like to share my experience while i was part of  MSR summer school in Bangalore. It was really fun and challenging to be part of that great community of people. I was one of the 14 B.tech students selected for Summer school from all over world . It was really a great opportunity for me to learn new things especially in field of programming languages, verification  and analysis. Researchers and Professors from different part of worlds have come to share their knowledge to us. I am really thankful to all the faculties and organizer committee of summer school program.&lt;br /&gt;    We have been given lots of problem to solve in summer school and one of the them was the classical n-queens puzzle is to place n queens on an n × n chess-board so that no two queens attack each other. The exercise asks you to encode an n queens placement problem and then have Z3 enumerate solutions.&lt;br /&gt;&lt;br /&gt;Solution to the problem as follows :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(benchmark nqueens&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;:logic QF_BV&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;:extrafuns ( (r1 BitVec[8]) (r2 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(r3 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(r4 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(r5 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(r6 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(r7 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(r8 BitVec[8]) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;:formula (and&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;;Row Constraints&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r1 (bvsub r1 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r2 (bvsub r2 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r3 (bvsub r3 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r4 (bvsub r4 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r5 (bvsub r5 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r6 (bvsub r6 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r7 (bvsub r7 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(= bv0[8] (bvand r8 (bvsub r8 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;; Column Constraints&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r1))(not (= r1 r2) ) (not (= r1 r3) )(not (= r1 r4) )(not (= r1 r5) )(not (= r1 r6) )(not (= r1 r7) )(not (= r1 r8) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r2))(not (= r2 r3) ) (not (= r2 r4) )(not (= r2 r5) )(not (= r2 r6) )(not (= r2 r7) )(not (= r2 r8) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r3))(not (= r3 r4) )(not (= r3 r5) )(not (= r3 r6) )(not (= r3 r7) )(not (= r3 r8) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r4))(not (= r4 r5) )(not (= r4 r6) )(not (= r4 r7) )(not (= r4 r8) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r5))(not (= r5 r6) )(not (= r5 r7) )(not (= r5 r8) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r6))(not (= r6 r7) )(not (= r6 r8) )&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r7))(not (= r7 r8))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= bv0[8] r8))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;; Diagonal Constraints&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r1 (bvshl r2 bv1[8]))) (not (= r1 (bvshl r3 bv2[8]))) (not (= r1 (bvshl r4 bv3[8]))) (not (= r1 (bvshl r5 bv4[8]))) (not (= r1 (bvshl r6 bv5[8]))) (not (= r1 (bvshl r7 bv6[8]))) (not (= r1 (bvshl r8 bv7[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r1 (bvlshr r2 bv1[8]))) (not (= r1 (bvlshr r3 bv2[8]))) (not (= r1 (bvlshr r4 bv3[8]))) (not (= r1 (bvlshr r5 bv4[8]))) (not (= r1 (bvlshr r6 bv5[8]))) (not (= r1 (bvlshr r7 bv6[8]))) (not (= r1 (bvlshr r8 bv7[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r2 (bvshl r3 bv1[8]))) (not (= r2 (bvshl r4 bv2[8]))) (not (= r2 (bvshl r5 bv3[8]))) (not (= r2 (bvshl r6 bv4[8]))) (not (= r2 (bvshl r7 bv5[8]))) (not (= r2 (bvshl r8 bv6[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r2 (bvlshr r3 bv1[8]))) (not (= r2 (bvlshr r4 bv2[8]))) (not (= r2 (bvlshr r5 bv3[8]))) (not (= r2 (bvlshr r6 bv4[8]))) (not (= r2 (bvlshr r7 bv5[8]))) (not (= r2 (bvlshr r8 bv6[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r3 (bvshl r4 bv1[8]))) (not (= r3 (bvshl r5 bv2[8]))) (not (= r3 (bvshl r6 bv3[8]))) (not (= r3 (bvshl r7 bv4[8]))) (not (= r3 (bvshl r8 bv5[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r3 (bvlshr r4 bv1[8]))) (not (= r3 (bvlshr r5 bv2[8]))) (not (= r3 (bvlshr r6 bv3[8]))) (not (= r3 (bvlshr r7 bv4[8]))) (not (= r3 (bvlshr r8 bv5[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r4 (bvshl r5 bv1[8]))) (not (= r4 (bvshl r6 bv2[8]))) (not (= r4 (bvshl r7 bv3[8]))) (not (= r4 (bvshl r8 bv4[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r4 (bvlshr r5 bv1[8]))) (not (= r4 (bvlshr r6 bv2[8]))) (not (= r4 (bvlshr r7 bv3[8]))) (not (= r4 (bvlshr r8 bv4[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r5 (bvshl r6 bv1[8]))) (not (= r5 (bvshl r7 bv2[8]))) (not (= r5 (bvshl r8 bv3[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r5 (bvlshr r6 bv1[8]))) (not (= r5 (bvlshr r7 bv2[8]))) (not (= r5 (bvlshr r8 bv3[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r6 (bvshl r7 bv1[8]))) (not (= r6 (bvshl r8 bv2[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r6 (bvlshr r7 bv1[8]))) (not (= r6 (bvlshr r8 bv2[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r7 (bvshl r8 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;(not (= r7 (bvlshr r8 bv1[8])))&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/41126578026266439-8837734878665541510?l=summerschool-ashish.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://summerschool-ashish.blogspot.com/feeds/8837734878665541510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=41126578026266439&amp;postID=8837734878665541510' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/41126578026266439/posts/default/8837734878665541510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/41126578026266439/posts/default/8837734878665541510'/><link rel='alternate' type='text/html' href='http://summerschool-ashish.blogspot.com/2008/07/queens-problem-solution.html' title='queens problem solution'/><author><name>ashish</name><uri>http://www.blogger.com/profile/15533464648853562382</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
