Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

Uniqueness test: A new twist
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku
View previous topic :: View next topic  
Author Message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Fri Sep 23, 2005 1:39 am    Post subject: Uniqueness test: A new twist Reply with quote

I posted today about how I implemented the uniqueness test in my solver. It's a great little test, but the cool thing is I just discovered a puzzle that brings up a new way of using it.

For those who haven't seen it before, basically it operates on the assumption that the puzzle you're solving is a valid one with a unique solution. It requires you to have two cells with the same 2 candidates (no others) which are aligned in the same column or row, and share a box. You need two other cells to form a rectangle, one of which has only those same 2 candidates, and another which has those 2 candidates plus at least one more.
Code:
 .   AB  .  | .  ABC  .
 .   .   .  | .   .   .
 .   AB  .  | .   AB  .

If the ABC cell was simply AB, then the puzzle has no unique solution because the A's and B's are interchangeable with nothing to force them to one value or the other. Thus, the ABC cell cannot be A or B.

Now today I was going through a puzzle and got it to this point:
Code:
9 3 6|. . .|. 7 5
8 7 5|. . 3|. . 1
1 4 2|7 5 6|3 8 9
-----+-----+-----
. . 7|. . .|8 . .
5 1 4|8 . 2|7 . 6
. 8 9|. 7 .|. . .
-----+-----+-----
4 . .|. . 7|9 . 3
. . .|. 4 .|. . 7
7 9 .|2 . 5|. . 8

Looking at the rightmost 3 columns and their candidates, I get this:
Code:
24   7    5
246  246  1
3    8    9
------------
8    1359 24
7    39   6
15   135  24
------------
9    25   3
125  125  7
46   46   8

Now note the cells (7,2), (8,2), (7,9), and (8,9). The cells in row 2 have 2 as an extra candidate. Now, I know there's a hidden pair for 4 and 6 in row 8, meaning I can just eliminate 2 at (8,2). However if you ignore that, it brings up an intriguing possibility that could apply to future puzzles.

By the logic of the uniqueness test, both of those cells in row 2 cannot be 46. Therefore one of them is a 2. That eliminates the 2 at (7,1).

From what I can tell this logic only applies to situations where the 3rd and 4th cells are both ABC and have no other candidates. In the original test, C can represent multiple digits, but here this pair of cells can have only 3 candidates. Elimination is done on C within the same box and row/col as the ABC cells, but not on those cells themselves.

This second test is quite interesting and brings up yet another heretofore undiscovered (or perhaps just not formalized) form of pairwise logical elimination.
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Fri Sep 23, 2005 3:17 am    Post subject: Reply with quote

Doh. Once again I've discovered this is not a new discovery. If I'd read the very end of the original thread fully, I'd've seen that this variation was already known.

Well, at least I can update my solver for it.
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sat Sep 24, 2005 10:17 pm    Post subject: Reply with quote

I believe I actually have, now, discovered something new to the uniqueness test. There is yet another flavor involving subsets of values. Consider this portion of a puzzle, from the lower left corner:
Code:
9     58    6
2     3     78
1    4578  4578
----------------
6     2     9
8     1     3
7     45    45

By the logic of the uniqueness test, either a 7 or an 8 must appear in (2,6) or (3,6). This doesn't tell us enough to eliminate anything just yet because one of those cells can still be 45. However a 7 or 8 must also appear in (3,5). Whichever value is in cell (3,5), the other digit must appear in either (2,6) or (3,6). So therefore 7 and 8 can only appear in those three cells. As a result, 8 can be removed from (2,4).

Therefore, this third style of uniqueness test works as follows: After finding a naked pair with candidates AB in the same box and in the same column/row, find a pair of cells in another box which form a rectangle, which both have the same candidates ABCD+. Let N be the number of extra candidates CD+ (e.g., CD=2, CDE=3, CDEF=4) in those two cells. If you can find N-1 other cells in the same box as the ABCD+ cells which have only CD+ as candidates, you can eliminate CD+ from all other cells in that box.

I expect this test to appear very very infrequently. However, it does give us yet another tool.

[edit]
Rather than post anew, I figured I'd just tack on this note. After implementing this new style of test in my solver, I ran through the generator/solver a few times and finally got a puzzle where it occurs. It took about four runs of 100 for this to appear, so I figure you can expect to find it maybe once in a few hundred random puzzles.
Code:
. . 9|. 3 5|. . .
. . 6|. . .|1 . 8
. 2 .|1 . .|. . 5
-----------------
. . 4|. . .|. 7 2
. . 1|. 9 .|. . 6
. . .|. . .|4 . .
-----------------
. 7 .|. 8 4|. . .
. . 5|. 7 3|. . 1
6 . .|2 1 .|. . .

My solver first will find all singles, pointing pairs, box-line intersections, and basic subsets (pairs and triples), and then will move on to the pairwise techniques. Uniqueness is one of the first because it's one of the easiest to spot. In this puzzle once you've taken care of the easy steps, you'll get to a point where 26 is in cells (7,1) and (8,1) in box 3, and 2369 appears in (7,7) and (8,7), while 39 is in (9,7). The 9's already having been eliminated from the other spots, this will eliminate 3 at (3,7), (7,9), and (8,9).

Of course this puzzle is still quite nasty. The next step it will try after this test is coloring, which will find one elimination, and after that you have to do a few forcing chains, followed by a few rounds of something more advanced like Bowman bingo, followed by more forcing chains, at which point it will finally fall together. (My solver actually gives up before forcing chains because that's not implemented yet, nor is Bowman bingo. I've so far stuck exclusively to pure logic techniques.)
Back to top
View user's profile Send private message
Moschopulus

Joined: 12 Aug 2005
Posts: 39
:

Items
PostPosted: Sun Sep 25, 2005 12:34 pm    Post subject: Reply with quote

If you use this uniqueness trick in your solver, then your solver doesn't prove that a puzzle has a unique solution. (At least any time it uses this fact to solve.)

Some people don't use the fact that a puzzle has a unique solution to solve it, because when you find a solution you haven't proved that its the only solution. If you solve by purely "logical" deduction techniques then you can not only deduce the solution, you've also proved that its the only solution.

It's a matter of personal taste. But there is a logical distinction between the conclusions. There was a thread on this somewhere......can't find it.
--------------------------

I also want to mention positions like
a..b.....
.........
.........
b..a.....
.........etc
in a completed grid. Any set of cells in a completed grid is called an "unavoidable set" if the digits in those cells can be permuted so that you still end up with a valid completed grid. Since a and b can be interchanged in this example, this is an unavoidable set with 4 cells.
The name comes from the fact that if you were setting a puzzle from this grid, you have to use a clue from any unavoidable set if you want a unique solution, so they are unavoidable.

This trick using the unique solution would work for any unavoidable set. Here is another unavoidable set:
1.2......
.........
.........
21.......
.........
.........
.21......
.........
.........
so you can never have 6 cells in that arrangement with the same 2 candidates for each cell.
Back to top
View user's profile Send private message Visit poster's website
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sun Sep 25, 2005 8:39 pm    Post subject: Reply with quote

Moschopulus wrote:
If you use this uniqueness trick in your solver, then your solver doesn't prove that a puzzle has a unique solution. (At least any time it uses this fact to solve.)

Some people don't use the fact that a puzzle has a unique solution to solve it, because when you find a solution you haven't proved that its the only solution. If you solve by purely "logical" deduction techniques then you can not only deduce the solution, you've also proved that its the only solution.

It's a matter of personal taste. But there is a logical distinction between the conclusions. There was a thread on this somewhere......can't find it.

While I'm aware of the philosophical debate behind that argument, I find it mostly nitpicking. If the puzzle is such that it does not have a unique solution and that set is the reason why, the uniqueness test will show up an inconsistency. At any rate the test will hold for all valid sudoku, and the assumption of validity could just as easily be compromised in other ways.

My solver, which also can generate sudoku (the solver is to rate difficulty), finds the number of solutions via dancing links and prunes clues appropriately to maintain a valid board. Only once it has a minimal board with a unique solution will it try to use human-style deduction. So proving the uniqueness of the solution is not strictly necessary.

However, if I so desired I could always back up the current row/column cover state for DLX and then run through the standard DLX algorithm just to see if the puzzle was valid before continuing. That would definitely help if I turned this into a windowed program like Trebor's Sudoku Susser.
Back to top
View user's profile Send private message
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Sun Sep 25, 2005 8:56 pm    Post subject: Unavoidable Sets Reply with quote

I find these unavoidable sets very interesting. They might be the key to finding a 16 clue puzzle. I've been thinking about modifying the DLX routine to add a "no unavoidable sets allowed" constraint, and see whether it can then produce a 16.

About Moschopulus' argument: You're right that it does not PROVE that there is only one solution, but when the premisis is that there IS only one solution, this technique is as valid as any other.
Back to top
View user's profile Send private message Visit poster's website
Moschopulus

Joined: 12 Aug 2005
Posts: 39
:

Items
PostPosted: Mon Sep 26, 2005 9:17 am    Post subject: Re: Unavoidable Sets Reply with quote

Ruud wrote:
I find these unavoidable sets very interesting. They might be the key to finding a 16 clue puzzle. I've been thinking about modifying the DLX routine to add a "no unavoidable sets allowed" constraint, and see whether it can then produce a 16.


That would be interesting!

I agree that they are important in finding a 16. I was able to prove using unavoidable sets that one particular grid has no 16, but it was a special grid that has a lot of unavoidable sets. The post is here
http://www.sudoku.com/forums/viewtopic.php?t=1527
How to deal with other grids is still under discussion!
Back to top
View user's profile Send private message Visit poster's website
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Fri Sep 30, 2005 8:56 pm    Post subject: Reply with quote

Here's another interesting twist:

When you generate a puzzle using a solver that incorporates uniqueness tests, will it always generate a valid puzzle?

There's a chicken & egg thing to it, I guess.

I like to see your thoughts on this.
Back to top
View user's profile Send private message Visit poster's website
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sat Oct 01, 2005 4:25 am    Post subject: Reply with quote

You would never want to use a human-style solver to generate a puzzle. For that you'd definitely want a backtracking algorithm such as dancing links. The point to including human techniques is merely to assess difficulty, and if creating a full-featured program, to provide hints.
Back to top
View user's profile Send private message
Ruud
Site Admin
Joined: 17 Sep 2005
Posts: 708
:
Location: Netherlands

Items
PostPosted: Sun Oct 02, 2005 2:52 pm    Post subject: Reply with quote

I see no reason why not to use a human-type solver to generate a puzzle. Seems to work fine for me. When you enable-disable the techniques in the solver according to the difficulty settings, it can very quickly generate a valid puzzle with the desired difficulty level.

However, that was not my question.

In the meantime, I found out that this uniqueness test must be handled with care. When enabled in the solver, it can indeed generate puzzles which, validated without the uniqueness test, have multiple solutions. So now I disable uniqueness tests when generating puzzles.

Also, when loading (or manually entering) puzzles, the uniqueness test must be delayed until all clues have been entered, otherwise it can jump to conclusions later contradicted by additional clues.

Of course, this can only occur when the program uses "on the fly" solving, and does not wait for a "go" signal from the user.
Back to top
View user's profile Send private message Visit poster's website
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Mon Oct 03, 2005 4:21 am    Post subject: Reply with quote

Quote:
I see no reason why not to use a human-type solver to generate a puzzle. Seems to work fine for me. When you enable-disable the techniques in the solver according to the difficulty settings, it can very quickly generate a valid puzzle with the desired difficulty level.

I really don't see how that approach is even possible, unless you've tacked down a solution in advance via something like dancing links and you only add clues as you go along. If your human-style solver declares itself stuck, though, you'd have to add a clue from the known solution, and it would invalidate all the logic that went before leading to a whole new set of steps to a solution--perhaps many the same, but some like naked pairs might cease to exist. And if your human-style solver gets stuck and you don't choose a clue from a valid solution, you could wind up with an insoluble board.
Quote:
In the meantime, I found out that this uniqueness test must be handled with care. When enabled in the solver, it can indeed generate puzzles which, validated without the uniqueness test, have multiple solutions. So now I disable uniqueness tests when generating puzzles.

Well the uniqueness test clearly should never be used in generating a puzzle, because it operates on the principle of having a ready-to-solve puzzle. To use it in the generating process is to misunderstand how to use it at all.
Quote:
Also, when loading (or manually entering) puzzles, the uniqueness test must be delayed until all clues have been entered, otherwise it can jump to conclusions later contradicted by additional clues.

Of course, this can only occur when the program uses "on the fly" solving, and does not wait for a "go" signal from the user.

Actually if the clues dictate a unique solution, adding additional clues can't contradict the test, any more than solving other steps of the puzzle would. If the user is entering clues as they go along, you'll always have to verify with something like dancing links that the solution is unique before actually applying the test. In a finished puzzle, the assumption that the puzzle is correct can be a given.
Back to top
View user's profile Send private message
Agent Allen

Joined: 01 Oct 2005
Posts: 34
:

Items
PostPosted: Wed Oct 05, 2005 10:08 pm    Post subject: A wee bit confused Reply with quote

Ruud,

I think Lummox JR is right.
You setter works like a bit like mine but mind the pit-falls!!

1. If you use deductions that don't rely on uniqueness and the deduct the solution absolutely, then the solution found (if any) is unique.

2. If you use methods that rely on uniqueness and find a solution, it might not be the only one.

3. There may be methods that rely on uniqueness and fail to find any solution when there is in fact one or more than one.

I haven't looked but this is a possible consequence of a false premise.

4. If you employ trial and error, make sure you go back and look for more solutions on all the other "trials" before declaring uniqueness.
_________________
Agent A
Back to top
View user's profile Send private message
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Thu Oct 06, 2005 12:06 am    Post subject: Reply with quote

Trial and error can be used in a way that doesn't eliminate multiple solutions; in fact it's the only safe kind to use. There are only a few methods that work:

1) Placing a digit causes a contradiction. That placement must be false.
2) All digits that can go in a cell, or all placements for a digit within a house, show that a particular cell cannot have a particular value. That placement must be false.
3) All digits that can go in a cell, or all placements for a digit within a house, show that a particular cell must have a particular value. That placement must be true.
Back to top
View user's profile Send private message
gaby

Joined: 02 Jul 2005
Posts: 120
:

Items
PostPosted: Sat Oct 15, 2005 10:55 pm    Post subject: Reply with quote

I get the feeling that the Unqiueness test feels like a swordfish-style variant. In my mind there are two approaches usually used, looking for cells with two candidates in, or looking for rows/cols/blocks where a candidate appears twice. The various techniques then revolve around maniupulating sets of these.

The uniqueness test looks very much like Y-Wing, looking at a very small forcing chain, which results in the final 'corner' of the box having either the candidates removed (Y-wing) or being set to the value (Uniqueness).

Is the uniqueness test constrained to having two of each of the numbers in the same block? Can it not work across rows/cols alone? This is again starting to sound very much like a Y wing, but with more restrictive removal policy.

Does this algorithm sound reasonable:

1. Find a cell with two numbers in it.

2. Find a cell in the same (row/column) with at least the same two numbers in it, and optionally some more numbers.

3. Find a cell in the same (column/row) with at least the same two numbers in it, and optionally some more numbers.

4. Find a cell that intersects the two cells from steps 2 and 3, that contains at least the same two numbers in it, and optionally some more numbers.

5. Only continue if the cells appear in two different blocks only, with two cells in each block.

6. We now assume that cells 1 and 2 are in b1, and cells 3 and 4 are in b2. The arrangement can be different, but we'll assume that this is the case. There are four uniqueness tests avaialble to us:

6.1 Test 1, cells 1, 2, and 3 only have two numbers in, cell 4 has 1 extra number in. Cell 4 must be the extra number, so remove the two numbers from that cell.

6.2 Test 2, cells 1, 2, and 3 only have two numbers in, cell 4 has several extra numbers in. Cell 4 can only contain the extra numbers, so remove the two numbers from that cell, leaving the two extra numbers

6.3 Test 3, the cells in one block have only two numbers in, the cells in the other block both have one extra number. We can remove that extra number from all the other cells in that block. If they're in a row, then we can also remove from the other cells in that row, and likewise for a column.

6.4 Test 4, the cells in one block have only two numbers in, the cells in the other block both have N extra numbers, and they are the same N extra numbers. If we find N-1 other cells in the same block that only the extra numbers in them, then we can remove those extra numbers from all the other cells in that block.
_________________
Free daily sudoku - Online puzzle database
http://vanhegan.net/sudoku/
Back to top
View user's profile Send private message Visit poster's website
Lummox JR

Joined: 07 Sep 2005
Posts: 202
:

Items
PostPosted: Sun Oct 16, 2005 1:05 am    Post subject: Reply with quote

gaby wrote:
I get the feeling that the Unqiueness test feels like a swordfish-style variant. In my mind there are two approaches usually used, looking for cells with two candidates in, or looking for rows/cols/blocks where a candidate appears twice. The various techniques then revolve around maniupulating sets of these.

Uniqueness is unrelated to swordfish. Swordfish is just a subset rule.
Quote:
The uniqueness test looks very much like Y-Wing, looking at a very small forcing chain, which results in the final 'corner' of the box having either the candidates removed (Y-wing) or being set to the value (Uniqueness).

Is the uniqueness test constrained to having two of each of the numbers in the same block? Can it not work across rows/cols alone? This is again starting to sound very much like a Y wing, but with more restrictive removal policy.

From what you're saying I think you might mean XY-wing. I've heard the term Y-wing used before but I can find no information on it; it may be one that's being used incorrectly. XY-wing is a configuration in which cells XY and XZ share a house, and XY and YZ share a house, and Z can be eliminated from the intersection of XZ and YZ. If Y-wing is something different I'd like to learn about it; if you have a link that'd be great.

Uniqueness is only tangentially related to XY-wing, in that it's what I call a "pairwise" method; it operates using cells constrained to just 2 candidates. Remote pairs is another obvious member of this family. One thing I'm curious about is if this family is any bigger. XY-wing apparently has a fleet of descendants.

And yes, uniqueness is constrained to two blocks. The reason is that the logic behind it dictates the puzzle may not have multiple solutions and still be valid. It's not enough that the cells form a rectangle or any other configuration that could connect two cells at a time, as you might see in an XY-wing. (Actually XY-wing concerns itself with only 3 cells. Eliminations can happen in up to 5 other cells.) If all four cells could be whittled down to the same two candidates, you could switch them either of two ways and still satisfy the constraint that each digit appear once per box, column, and row. If you have a rectangle that spans 4 boxes, in each of them there would be the possibility of placing only one of the candidates, and the other must be somewhere else in the box. Hence, no danger of violating uniqueness.
Quote:
Does this algorithm sound reasonable:

1. Find a cell with two numbers in it.

2. Find a cell in the same (row/column) with at least the same two numbers in it, and optionally some more numbers.

3. Find a cell in the same (column/row) with at least the same two numbers in it, and optionally some more numbers.

4. Find a cell that intersects the two cells from steps 2 and 3, that contains at least the same two numbers in it, and optionally some more numbers.

5. Only continue if the cells appear in two different blocks only, with two cells in each block.

I'd actually restrict the algorithm more at this point, and did. All four cells must form a rectangle, and the corners must occur in exactly two boxes. If by the time you get to the third cell, cell 2 or cell 3 doesn't share a box with cell 1 and you don't have the partial rectangle pattern, you can move on. Also at least two of the cells must have only the two candidates, so if cell 2 or cell 3 doesn't match cell 1, move on. If not, you should automatically know cell 4 since it's the other corner of the rectangle.

If the two cells with the pair occur in the same box, we have the original uniqueness format "A", and if not it's the "B" form.
Quote:
6. We now assume that cells 1 and 2 are in b1, and cells 3 and 4 are in b2. The arrangement can be different, but we'll assume that this is the case. There are four uniqueness tests avaialble to us:

6.1 Test 1, cells 1, 2, and 3 only have two numbers in, cell 4 has 1 extra number in. Cell 4 must be the extra number, so remove the two numbers from that cell.

Cell 4 can actually have any number of extra candidates. The same logic still applies. This is the original uniqueness test, form 1. You could also call it 1A, since the "B" format doesn't apply here.
Quote:
6.2 Test 2, cells 1, 2, and 3 only have two numbers in, cell 4 has several extra numbers in. Cell 4 can only contain the extra numbers, so remove the two numbers from that cell, leaving the two extra numbers

This is just the first one all over again. Uniqueness test 2 is what you labeled as 6.3.
Quote:
6.3 Test 3, the cells in one block have only two numbers in, the cells in the other block both have one extra number. We can remove that extra number from all the other cells in that block. If they're in a row, then we can also remove from the other cells in that row, and likewise for a column.

This is uniqueness test 2. In form 2b, there's no chance of eliminations within the common box because cells 3 and 4 won't have a common box; cells 1 and 3 and 2 and 4 will.
Quote:
6.4 Test 4, the cells in one block have only two numbers in, the cells in the other block both have N extra numbers, and they are the same N extra numbers. If we find N-1 other cells in the same block that only the extra numbers in them, then we can remove those extra numbers from all the other cells in that block.

That's uniqueness test 3. It also has another angle, too: If N=2 and therefore only one extra cell is involved, and that cell is in line with cells 3 and 4, you can eliminate within that column/row. In form 3b, cells 3 and 4 will not share a box. To put it more accurately, you can eliminate along the intersection of all the N-1 cells and cells 3 and 4. Interestingly you can also perform this test more than once with the same four cells, because the N-1 extra cells may appear in a common box and elsewhere in a common column/row. I've never seen this happen but it's possible.

Uniqueness test 4 was discovered more recently on the players' forum by PaulIQ164. If one of the two candidates from cells 1 and 2 is constrained to only cells 3 and 4 within their common box or column/row, the other candidate may not appear in either cells 3 or 4. The reason this works is that there's already nothing else to distinguish between cell 1 and cell 2; something has to exist in a valid puzzle that will force each to be one value or the other. That something is in cells 3 or 4. If one of them has to be one of the candidates, and if we were to place the other candidate in the other, there would be nothing to keep us from switching cells 1 and 2, 3 and 4, and still achieving a solvable puzzle.

So between test 1, the original, and tests 2-4 and 2b-4b, there are seven distinct flavors of uniqueness test. I prefer to number them by the logic involved, and use B to distinguish between the layouts.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Solving sudoku All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron