News for hackers. Stuff that matters.
Re:A liar who always lies says "All my hats are green." by rcxdude on Monday December 09, 2024 @07:59AM (#42365885)
This is the contentious, formal-logicy part of the puzzle. "All my hats are green" as a logical statement, in most formal logic systems, would be true if I didn't own any hats (a so-called vacuous truth, because it doesn't mean anything, for similar reasons any statement conditioned on a false statement is true, e.g. "if 2+2=5, then I am god" is similarly vacuously true). So if I'm a liar and that statement is false, it must be false by me owning a non-green hat. But colloquially, people will usually break it down into two logical statements: "I own at least one hat", and "given I own a hat, all those hats are green" (because most people don't consider vacuous truths to be relevant in most contexts), in which case those are both false if the liar does not own any hats.

(other systems of logic exist which will attempt to resolve this. Forcing such statements to be false makes things much trickier formally, as does e.g. three-valued logic to try to avoid assigning truth or falsity to such statements)

Re:A liar who always lies says "All my hats are green." by MrMcCall on Monday December 09, 2024 @08:52AM (#42366277)
Thanks for breaking that down for me.

I guess, to me, a programmer logician not a mathematician logician, the real problem for me here is the definition of "liar" as it applies to how we parse the problem statement's facts.

Re:A liar who always lies says "All my hats are green." by n4r9 on Tuesday December 17, 2024 @07:08AM (#42440713)
I'd argue that this bit of mathematical logic carries over to many programming languages. For example using LINQ expressions in C#:

https://dotnetfiddle.net/3QGurc