Proving Correctness of a KRK Chess Endgame Strategy by SAT-based - - PowerPoint PPT Presentation

proving correctness of a krk chess endgame strategy by
SMART_READER_LITE
LIVE PREVIEW

Proving Correctness of a KRK Chess Endgame Strategy by SAT-based - - PowerPoint PPT Presentation

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratkos Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Proving Correctness of a KRK Chess


slide-1
SLIDE 1

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions

Proving Correctness of a KRK Chess Endgame Strategy by SAT-based Constraint Solving

Marko Malikovi´ c, University of Rijeka, Croatia Predrag Janiˇ ci´ c, University of Belgrade, Serbia

COST IC0901 Meeting — SVARM 2013 Madrid, Spain, October 17-18, 2013.

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-2
SLIDE 2

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Introduction Overview

Introduction

Within COST Action IC0901: a number of SAT-based systems and applications To be presented: application of SAT in chess, using the URSA system Marko Malikovi´ c, Predrag Janiˇ ci´ c: Proving Correctness of a KRK Chess Endgame Strategy by SAT-based Constraint Solving. ICGA Journal (International Computer Games Association), 36(2) (2013).

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-3
SLIDE 3

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Introduction Overview

Overview

Reduction to SAT and URSA system Chess endgame strategies and Bratko’s strategy for KRK URSA specification of KRK and the strategy Correctness of the strategy Discussion and conclusions

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-4
SLIDE 4

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Reduction to SAT URSA System

Reduction to SAT

Wide range of applications: planning, scheduling, operations research, combinatorial optimization, software and hardware verification SAT solvers — ,,Swiss army knife“ ,,Efficient SAT solving is a key technology for 21st century computer science.” (Clarke) Most often reduction to SAT is performed by ad-hoc tools

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-5
SLIDE 5

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Reduction to SAT URSA System

Example: Eigth Queens

Different encodings can be used For instance: pij is true iff there is a queen on (i, j) Or: vi is a row of the queen in i-th column (represented by three bits) Or: ...

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-6
SLIDE 6

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Reduction to SAT URSA System

Overview of URSA

Uniform Reduction to SAt Stand-alone, implemented in C++, open-source C-like specification language Unknowns are represented by bit-vectors Symbolic execution of specifications Constraints translated to SAT instances Models give solutions of the constraints

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-7
SLIDE 7

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Reduction to SAT URSA System

URSA: Example specification (Seed)

Linear congruential pseudorandom number generator:

nX = nSeed; for(nI = 0; nI < 100; nI++) nX = 1664525 * nX + 1013904223; assert(nX==123);

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-8
SLIDE 8

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Reduction to SAT URSA System

URSA: Properties

Theorem: If the variables v1, v2, . . ., vn are (the only) unknowns in an URSA specification S; assert(b);, then it leads to a solution (v1, v2, . . . , vn) = (c1, c2, . . . , cn), iff v1 = c1; v2 = c2; . . . ; vn = cn; S; assert(b), s∅ → skip, s where s(b) is true.

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-9
SLIDE 9

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Reduction to SAT URSA System

Eight Queens Example

nDim=8; bDomain = true; bNoCapture = true; for(ni=0; ni<nDim; ni++) { bDomain &&= (n[ni]<nDim); for(nj=0; nj<nDim; nj++) if(ni!=nj) { bNoCapture &&= (n[ni]!=n[nj]); bNoCapture &&= (ni+n[nj]!=nj+ n[ni]) && (ni+n[ni] != nj+n[nj]); } } assert(bDomain && bNoCapture);

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-10
SLIDE 10

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Chess Endgame Strategies Bratko’s Strategy for KRK

Chess Endgame Strategies

Different from midgame computer strategies Different from lookup tables approach Should be concise and intuitive and useful both for computers and humans Endgame strategies do not need to ensure optimal moves

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-11
SLIDE 11

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Chess Endgame Strategies Bratko’s Strategy for KRK

(Simplified) Bratko’s Strategy for KRK (for White)

Mate: If possible, mate black in two moves; Squeeze: Otherwise, if possible, further constrain the area to which the black king is confined by the white rook Approach: Otherwise, if possible, move the king closer to the black king KeepRoom: Otherwise, if possible, maintain the present achievements in the sense of Squeeze and Approach Divide: Otherwise, if possible, obtain a position in which the rook divides the two kings vertically or horizontally.

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-12
SLIDE 12

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Chess Endgame Strategies Bratko’s Strategy for KRK

Modified Bratko’s Strategy for KRK – No Search

Instead of Mate: ImmediateMate: If there is such, play a mating move; ReadyToMate: If the above is not possible, then play a move that leads to the ,,ready to mate position” Instead of Divide: RookHome: Otherwise, if possible, move the rook to be safe and horizontally or vertically adjacent to the white king RookSafe: Otherwise, if possible, move the rook to be safe and on some edge

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-13
SLIDE 13

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Chess Endgame Strategies Bratko’s Strategy for KRK

Basic Ideas of the Strategy

Reducing ,,room“ / ready for mate

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-14
SLIDE 14

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Chess Endgame Strategies Bratko’s Strategy for KRK

Strategy Performance

The strategy is not optimal:

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 2000 4000 6000 8000 10000 12000 14000 16000 18000 20000 22000

  • ptimal play

play by strategy

The number of positions with certain number of moves to win

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-15
SLIDE 15

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Specification of KRK Endgame Specification of Strategy

Specification of Position

Bit-vectors of length 19 were used.

procedure Cartesian2Pos(nWKx, nWKy, nBKx, nBKy, nWRx, nWRy, bWhiteOnTurn, nPos) { nPos = ite(bWhiteOnTurn,1,0); nPos = (nPos << 3) | (nWRy & 7); nPos = (nPos << 3) | (nWRx & 7); nPos = (nPos << 3) | (nBKy & 7); nPos = (nPos << 3) | (nBKx & 7); nPos = (nPos << 3) | (nWKy & 7); nPos = (nPos << 3) | (nWKx & 7); } procedure Pos2Cartesian(nPos, nWKx, nWKy, nBKx, nBKy, nWRx, nWRy, bWhiteOnTurn) { ...

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-16
SLIDE 16

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Specification of KRK Endgame Specification of Strategy

Specification of ,,Black is Attacked“

procedure BlackKingAttacked(nPos, bBlackKingAttacked) { call Pos2Cartesian(nPos, nWKx, nWKy, nBKx, nBKy, nWRx, nWRy, bWhiteOnTurn); call Between(nWRx, nWRy, nWKx, nWKy, nBKx, nBKy, bBetween); bBlackKingAttacked = (nWRx==nBKx ^^ nWRy==nBKy) && !bBetween; }

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-17
SLIDE 17

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Specification of KRK Endgame Specification of Strategy

Specification of ImmediateMateCond

procedure ImmediateMateCond(nPos1, nPos2, bImmediateMateCond) { call LegalMoveWhiteRook(nPos1, nPos2, bLegalMoveWhiteRook); call Mate(nPos2, bMate); bImmediateMateCond = bLegalMoveWhiteRook && bMate; }

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-18
SLIDE 18

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions

Example Lemma

Lemma: Starting from any legal KRK position, after a step by white (by strategy) and a legal step by black, the obtained position is again a legal KRK position. Indeed, no model for:

call LegalKRKPosition(nPos1,bLegalKRKPosition1); call StrategyStep(nPos1,nPos2,b1,nStep1); call LegalMoveBlack(nPos2,nPos3,b2); call LegalKRKPosition(nPos3,bLegalKRKPosition3); bKRKLegalityNotPreserved = (bLegalKRKPosition1 && b1 && b2 && !bLegalKRKPosition3); assert(bKRKLegalityNotPreserved);

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-19
SLIDE 19

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions

Relation →

Definition [relation →]: p1 → p2 holds iff: it is white’s turn in p1 and p2 is reached from p1 following a strategy step or; it is black’s turn in p1 and p2 is reached from p1 by a legal ply.

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-20
SLIDE 20

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions

Partial Correctness

Theorem [Partial Correctness]: If a KRK game ends, then the last move was made by white and black is mated. Follows from: Lemma: If a KRK game ends, then the last ply was made by white. Lemma: If, after a ply by of white, black cannot move, then black is mated (not stalemated).

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-21
SLIDE 21

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions

Termination

Theorem [Termination]: The relation → is well-founded. Follows from A suitable measure (decreases in 6-plies) and Several lemmas ...

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-22
SLIDE 22

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Size and Hardness of SAT instances Clarity Target Theory Confidence Confidence Conclusions

Discussion: Size and Hardness

The largest lemma: 463770 vars/1641425 clauses The hardest lemma: 1.6h (using the Clasp solver)

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-23
SLIDE 23

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Size and Hardness of SAT instances Clarity Target Theory Confidence Confidence Conclusions

Discussion: Clarity

High-level statements vs. exhaustive analysis URSA can be used for both In many mathematical contexts, high-level arguments are preferable Given URSA specifications are high-level and readable

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-24
SLIDE 24

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Size and Hardness of SAT instances Clarity Target Theory Confidence Confidence Conclusions

Discussion: Target Theory

The lemmas are translated into SAT instances ... but could be also translated to BVA or LA instances Our systems URBIVA and URSA Major can do that

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-25
SLIDE 25

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Size and Hardness of SAT instances Clarity Target Theory Confidence Confidence Conclusions

Discussion: Confidence

The (high-level) lemmas can be also checked by a C program. However, systems like URSA are more reliable (since the solving process is delegated)

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-26
SLIDE 26

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Size and Hardness of SAT instances Clarity Target Theory Confidence Confidence Conclusions

Discussion: Confidence (2)

Lemmas are ”proved“ individually, cannot be glued together into URSA statements Solution within a proof assistant would give higher confidence Without support for SMT provers, it is often difficult to construct hard combinatorial proofs within proof assistants The current support for SMT solvers within Coq cannot handle the generated formulae (subject of current work)

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy

slide-27
SLIDE 27

Introduction Reduction to SAT and URSA system Chess Endgame Strategies and Bratko’s Strategy for KRK URSA Specification of KRK Endgame and of Strategy Correctness of Strategy Discussion and Conclusions Size and Hardness of SAT instances Clarity Target Theory Confidence Confidence Conclusions

Conclusions

An approach for proving properties of chess procedures presented Can be used in other domains We will also use translation to LA and Coq for similar approaches.

Marko Malikovi´ c and Predrag Janiˇ ci´ c Proving Correctness of a KRK Chess Endgame Strategy