Answers.Body: <p>Generally speaking, tablebases (and other engines) do not filter out illegal positions. Instead they filter out <em>ill-formed</em> positions, typically:</p>
  <ol>
  <li>Wrong number of kings for a side</li>
  <li>Pawns on first or last rank</li>
  <li>Player to move already delivering check</li>
  </ol>
  <p>It's unclear from an orthodox perspective how to play forward from an ill-formed position, so it's right that such positions are excluded. The criteria are easy to apply.</p>
  <p>In some engines, the stated reason for exclusion of an ill-formed position is that it is is “illegal”, but that is misleading. Many illegal positions are handled perfectly well by the engine. If an ill-formed position was not illegal, then players would have stumbled across it, and the rules would have been fixed to allow us to play forwards from it. It is exactly the ill-formedness that means the position cannot be covered by the engine.</p>
  <p>Another source of confusion is that tablebases do use what they call &quot;retrograde analysis&quot; to iterate backwards from checkmate positions, to find out how they can be forced. But that is completely different from RA in determining whether a random position has an ancestor in the game array and hence is legal.</p>
  <p>Reasons for <em>not</em> excluding illegal positions from engine consideration include:</p>
  <ol>
  <li>The FIDE Laws of Chess apply to illegal positions too. Although the notion of &quot;illegal position&quot; is defined in the Laws, it is never used (except in a single weird corner case in Rapid Chess I think). It's just defined so that arbiters can refer to it.</li>
  <li>It can be really hard to determine whether a position is legal. So much so that an entire genre of problem composition is built around it.</li>
  <li>Removing illegal positions doesn't make it easier to write the engine, whether it be a tablebase like Syzygy or more general engine like Stockfish.</li>
  <li>There are interesting positions which happen to be illegal.</li>
  <li>Chess problems, according to the Codex, can still be sound if the position is illegal.</li>
  <li>When composing a problem, it's sometimes a helpful approach to find an illegal diagram version first, and later to refine the diagram so that it's legal.</li>
  </ol>
  <p>There are engines which obsessively disallow certain kinds of illegality (e.g. more than 8 White pawns, taking into account promoted material). As a composer, I find such behaviour inconvenient. Sure legality is nice and all, but we should be able to ignore it early in the design as there are harder challenges in composition.</p>
  <p>The distinction between well-formed positions &amp; legal positions parallels the distinction between well-formed formulae &amp; valid formulae (theorems) in mathematical logic.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-28T03:18:48.133Z
Answers.Text: I am more interest by the set of admissible position, than caring about how non legal, it is.  I don't really care about dynamic definition of legal.  and even would rather have other characteristics to form position sets.  I agree, compositions and also sort of still board logical positions still are flexing the chess physics muscles...  if I can paraphrase extremely, my fast reading from above...  Why I was being precise in the title.
Answers.UserDisplayName: dbdb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-28T03:25:36.330Z
Answers.Text: I agree so much with the first look at exemplars or caricatures of features one wants to study, and then apply logic or fact layers, to find more grey versions, that still keep the problem and the solution scheme.  Why I want to handle the bigger position sets.
Answers.UserDisplayName: dbdb
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-23T07:04:48.617Z
Answers.LastActivityDate: 2024-02-24T10:22:17.570Z
Answers.LastEditDate: 2024-02-24T10:22:17.570Z
Answers.UserDisplayName: Laska
Answers.Body: <p>Here notes trying to find existing threads that were proposed to me as I wrote my question title:</p>
  <p>List of the ones I thought promising (in process of reading):</p>
  <p><a href="https://chess.stackexchange.com/questions/8424/endgame-tablebases-what-are-they">Endgame Tablebases-What are they?</a>
  This does not seem to have the answer directly.</p>
  <p><a href="https://chess.stackexchange.com/questions/18572/how-to-iterate-over-all-fens-in-syzygy-table">How to iterate over all FENs in Syzygy table?</a></p>
  <p><a href="https://chess.stackexchange.com/questions/9565/endgame-fen-generator">Endgame FEN generator</a></p>
  <p><a href="https://chess.stackexchange.com/questions/33722/how-do-endgame-tablebases-calculate-checkmates-to-do-retrograde-analysis-on">How do endgame tablebases calculate checkmates to do retrograde analysis on?</a></p>
  <p>I welcome all help. for existing such threads, or other specific enlightening links.
  I will add more posts to help answering this question, or a better one.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-23T00:19:42.713Z
Answers.LastActivityDate: 2024-02-23T00:19:42.713Z
Answers.UserDisplayName: dbdb
Body: <p>The title is my question for now.</p>
  <p>I also wonder if similar legality concerns may reduce the number of input FENs as checkmates used as input to the retrograde proofing or construction process. In principle this could apply to any number of men, but this might be simpler for positions with smaller numbers of units (i.e. 8 or less, to be in tablebase range)</p>
  <p>How this question came about: it occurred to me that there are many input positions that we can statically agree are not possibly legally reachable from a standard game array, or even one in Chess960. We might exclude these positions from consideration, using a retrograde logic &quot;generator&quot; which would be a subset of the FIDE rules possibly mobility of each piece, and the particular king rules.</p>
  <p>The inputs would be things like checkmate positions (that again could be reduced by considering legality).</p>
  <p>I will look for related questions in Chess.se.</p>
  <p>(Later I may pose other questions of the same type, e.g. how is draw by repetition handled in retrograde reasoning, and specifically in existing EGTB technology? but those are for later.)</p>
  <p>I welcome help in improving this question, or finding existing answers.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-23T07:18:41.017Z
Comments.Text: Hi, I have responded to your request to improve the question. I hope I have captured what you are getting at, and not over-simplified. See my answer too
Comments.UserDisplayName: Laska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-23T15:41:39.237Z
Comments.Text: With respect I don’t think that English is a comfortable language for you to write complex technical ideas. I have tried to recast them in a more readable form but I hope I haven’t overstepped
Comments.UserDisplayName: Laska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-28T03:05:34.830Z
Comments.Text: I am sorry, is there a way to have the notifications sent through email.  I welcome the help, my goal is to get through the questions and ideas, and yes language, possibly English, not my native language, but also things I do not know and ask questions about, can be torture.  Thank you I will revise.
Comments.UserDisplayName: dbdb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-28T03:10:38.190Z
Comments.Text: Well, the title was more specific, perhaps a bit mathematical, that was on purpose.  I already know (could provide examples) that it can have non-legal input positions.
  And I does make sense that it would.  The computation logic being about retrograde mobility ruleset cranking from some domain of specific mate or other outcome positions, and 7 men being how far it could go so far, they must have had simpler constraints, and most likely from the retrograde ruleset logic subset chosen.
Comments.UserDisplayName: dbdb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-28T03:14:03.500Z
Comments.Text: The new title is a bit tame.  I was asking for more of the high level model backing the construction of the tablebases.  Even same 3men.  One question being about the outcome range of positions considered.  I would say, perhaps best answer first the set of mate positions.  Same argument here, that they would not be able to test fo dynamic legality as continuation from a chess initial set up. Legality, might have to get some layers, or shades.  Not only English being the torture, the meaning too.
Comments.UserDisplayName: dbdb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-28T03:15:07.993Z
Comments.Text: I might take some time.  I need to compare the oridinigal with the current as well as your discussion. thank you for you effotrts.. will find how to get notifaction to email.
Comments.UserDisplayName: dbdb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-28T06:02:54.950Z
Comments.Text: feel free to adjust your title question again - I was just trying to guess your scope
Comments.UserDisplayName: Laska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-29T23:39:33.017Z
Comments.Text: hard one the scope.... I will keep this one for a while. still not having time to process this. I might need to make more than one question for clarity.  As it is not often asked the user-end input legality.  But I learned that there has been at least one paper. I will put that.  Since you went for this title, I think it was needed as precursor.  We don't know until we try.
Comments.UserDisplayName: dbdb
Tags: <rules><endgame><tablebases><retrograde-analysis>
Title: Do endgame tablebases only handle legal positions?
ThreadText: # Do endgame tablebases only handle legal positions?
  
  (Asked by: username_0 on 2024-02-23)
  
  The title is my question for now.
  
  I also wonder if similar legality concerns may reduce the number of input FENs as checkmates used as input to the retrograde proofing or construction process. In principle this could apply to any number of men, but this might be simpler for positions with smaller numbers of units (i.e. 8 or less, to be in tablebase range)
  
  How this question came about: it occurred to me that there are many input positions that we can statically agree are not possibly legally reachable from a standard game array, or even one in Chess960. We might exclude these positions from consideration, using a retrograde logic "generator" which would be a subset of the FIDE rules possibly mobility of each piece, and the particular king rules.
  
  The inputs would be things like checkmate positions (that again could be reduced by considering legality).
  
  I will look for related questions in Chess.se.
  
  (Later I may pose other questions of the same type, e.g. how is draw by repetition handled in retrograde reasoning, and specifically in existing EGTB technology? but those are for later.)
  
  I welcome help in improving this question, or finding existing answers.
  
  **Tags:** rules, endgame, tablebases, retrograde-analysis
  
  > **Comments:**
  > **username_1**: Hi, I have responded to your request to improve the question. I hope I have captured what you are getting at, and not over-simplified. See my answer too  
  > **username_1**: With respect I don’t think that English is a comfortable language for you to write complex technical ideas. I have tried to recast them in a more readable form but I hope I haven’t overstepped  
  > **username_0**: I am sorry, is there a way to have the notifications sent through email.  I welcome the help, my goal is to get through the questions and ideas, and yes language, possibly English, not my native language, but also things I do not know and ask questions about, can be torture.  Thank you I will revise.  
  > **username_0**: Well, the title was more specific, perhaps a bit mathematical, that was on purpose.  I already know (could provide examples) that it can have non-legal input positions. And I does make sense that it would.  The computation logic being about retrograde mobility ruleset cranking from some domain of specific mate or other outcome positions, and 7 men being how far it could go so far, they must have had simpler constraints, and most likely from the retrograde ruleset logic subset chosen.  
  > **username_0**: The new title is a bit tame.  I was asking for more of the high level model backing the construction of the tablebases.  Even same 3men.  One question being about the outcome range of positions considered.  I would say, perhaps best answer first the set of mate positions.  Same argument here, that they would not be able to test fo dynamic legality as continuation from a chess initial set up. Legality, might have to get some layers, or shades.  Not only English being the torture, the meaning too.  
  > **username_0**: I might take some time.  I need to compare the oridinigal with the current as well as your discussion. thank you for you effotrts.. will find how to get notifaction to email.  
  > **username_1**: feel free to adjust your title question again - I was just trying to guess your scope  
  > **username_0**: hard one the scope.... I will keep this one for a while. still not having time to process this. I might need to make more than one question for clarity.  As it is not often asked the user-end input legality.  But I learned that there has been at least one paper. I will put that.  Since you went for this title, I think it was needed as precursor.  We don't know until we try.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-02-23. Score: 4
  
  Generally speaking, tablebases (and other engines) do not filter out illegal positions. Instead they filter out *ill-formed* positions, typically:
  
  1. Wrong number of kings for a side
  2. Pawns on first or last rank
  3. Player to move already delivering check
  
  It's unclear from an orthodox perspective how to play forward from an ill-formed position, so it's right that such positions are excluded. The criteria are easy to apply.
  
  In some engines, the stated reason for exclusion of an ill-formed position is that it is is “illegal”, but that is misleading. Many illegal positions are handled perfectly well by the engine. If an ill-formed position was not illegal, then players would have stumbled across it, and the rules would have been fixed to allow us to play forwards from it. It is exactly the ill-formedness that means the position cannot be covered by the engine.
  
  Another source of confusion is that tablebases do use what they call "retrograde analysis" to iterate backwards from checkmate positions, to find out how they can be forced. But that is completely different from RA in determining whether a random position has an ancestor in the game array and hence is legal.
  
  Reasons for *not* excluding illegal positions from engine consideration include:
  
  1. The FIDE Laws of Chess apply to illegal positions too. Although the notion of "illegal position" is defined in the Laws, it is never used (except in a single weird corner case in Rapid Chess I think). It's just defined so that arbiters can refer to it.
  2. It can be really hard to determine whether a position is legal. So much so that an entire genre of problem composition is built around it.
  3. Removing illegal positions doesn't make it easier to write the engine, whether it be a tablebase like Syzygy or more general engine like Stockfish.
  4. There are interesting positions which happen to be illegal.
  5. Chess problems, according to the Codex, can still be sound if the position is illegal.
  6. When composing a problem, it's sometimes a helpful approach to find an illegal diagram version first, and later to refine the diagram so that it's legal.
  
  There are engines which obsessively disallow certain kinds of illegality (e.g. more than 8 White pawns, taking into account promoted material). As a composer, I find such behaviour inconvenient. Sure legality is nice and all, but we should be able to ignore it early in the design as there are harder challenges in composition.
  
  The distinction between well-formed positions & legal positions parallels the distinction between well-formed formulae & valid formulae (theorems) in mathematical logic.
  
  > **Comments:**
  > **username_0**: I am more interest by the set of admissible position, than caring about how non legal, it is.  I don't really care about dynamic definition of legal.  and even would rather have other characteristics to form position sets.  I agree, compositions and also sort of still board logical positions still are flexing the chess physics muscles...  if I can paraphrase extremely, my fast reading from above...  Why I was being precise in the title.  
  > **username_0**: I agree so much with the first look at exemplars or caricatures of features one wants to study, and then apply logic or fact layers, to find more grey versions, that still keep the problem and the solution scheme.  Why I want to handle the bigger position sets.  
  
  ---
  
  ### Answer by username_0 on 2024-02-23. Score: 0
  
  Here notes trying to find existing threads that were proposed to me as I wrote my question title:
  
  List of the ones I thought promising (in process of reading):
  
  [Endgame Tablebases-What are they?](https://chess.stackexchange.com/questions/8424/endgame-tablebases-what-are-they)
  This does not seem to have the answer directly.
  
  [How to iterate over all FENs in Syzygy table?](https://chess.stackexchange.com/questions/18572/how-to-iterate-over-all-fens-in-syzygy-table)
  
  [Endgame FEN generator](https://chess.stackexchange.com/questions/9565/endgame-fen-generator)
  
  [How do endgame tablebases calculate checkmates to do retrograde analysis on?](https://chess.stackexchange.com/questions/33722/how-do-endgame-tablebases-calculate-checkmates-to-do-retrograde-analysis-on)
  
  I welcome all help. for existing such threads, or other specific enlightening links.
  I will add more posts to help answering this question, or a better one.
  
  
  ---
  
  