Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My take (possible spoiler):

If he had no hats, then his statement would technically be true. Therefore he has at least one hat.

He may have some green hats and some non-green hats, but must have at least one non-green hat. He could have any number of green hats, including zero, as long as he has at least one non-green hat.

So the only derived statement that we can conclude to be true is A.



Speaking mathematically, you are right. However, linguistically I disagree. Consider: Someone tells you that "all of their kids are doing great in school". Turns out they have no kids. They obviously were trying to deceive you, and make you think they do have kids - in fact, since plural, more than one kid. Hence, it is effectively a lie.

So if the liar speaks of "all my hats" while having none, that is deceptive. I would consider it a lie.


The specific linguistic concept your reaching for is "implicature" from pragmatics.

https://en.wikipedia.org/wiki/Implicature


Ah yes, the only standardized test questions that gave me trouble back in school... "Guess what the speaker was implying"


And that's why SO gets mad when I come home with six cartons of milk[1].

[1]: https://blog.bryanbibat.net/2013/01/02/programming-joke/


I prefer to call her the first wife (apologies to Sir Clement Freud)

Also somehow saying she's my favourite wife was a problem, and yet "least favourite" was worse. Honestly!


Try "ex girlfriend"!


The joke, loosely, is :

A wife asks her programmer husband” on your way home, can you swing by the store and buy one carton of milk, and if they have eggs, get six?”

It’s funnier and more relatable to programming if he comes home empty handed, crashes the car into the garage door, and says, with perfect alacrity, “six what?”


English is an interpreted language. We wouldn't have this problem if we can check for undefined references during compilation.


Still, the REPL is nice to have.


More generally, the puzzle is kind of stupid -- not as a puzzle, but as a representation of life -- because speakers do not speak according to the rules of mathematical logic. That doesn't make them liars, it just means they don't agree about the ground rules.


What does it even mean to be right mathematically here? If I invent a mathematical structure where I define elements 1 and 2, an operation + and a relation = that posits that 1+2=2, I can say that mathematically one apple plus two apples equals two apples. Would I be mathematically right or would I be applying a wrong/not-even-wrong/linguistically deceiving /incoherent model to the real world?


Who hasn't had a picture taken with only them sitting in a room, labeled "X with all their friends" can cast the first stone.


"You can give me the loan, all my companies have millions in assets."


or

"You can give me the loan, I don't own any companies that have less than 1 million in assets"


If you actually give a loan without checking the companies themselves, that is on you.


That's not right; you're conflating dishonesty with lying. Why do people get weird when it comes to grokking what it means to lie?

Mere deception is not lying. (Though it is dishonest.)

A mere untrue statement is not a lie. (Though it is conterfactual.)

But to lie is to (a) state an untruth (b) that is intended to deceive. Absent both conditions being satisfied, you're not dealing with a lie.

There are other forms of dishonesty, but not all of them are lies.


For what it's worth (to whomever was upset by this): this is not apologetics—there's nothing here in my comment to give anyone cover for being dishonest. It is sufficient for something to be dishonest in order for to it to be deserving of all the judgement that people have for liars. It is the dishonesty that is bad, whether it takes form of a lie or not.

But conflating dishonesty with lying is harmful, because once you do that, you give ammunition to people who employ dishonesty in instances that don't involve lying, because if everyone is taking it as a given that dishonesty and lying are the same, and they can show that they weren't lying, then they can argue they weren't being dishonest. But that's wrong since dishonesty and lying are not synonymous—people can still be dishonest without lying—and, again, it is the dishonesty that is bad.


No, the liar having no hats would not make the statement true. ‘All my hats implies’ implies the liar stating they have hats.

The liar either has zero hats or some amount of hats. The only thing we know for certain is that if they do have hats, there is at least one non Green hat.


No. In formal logic, if you have no hats, it is true that all your hats are green. You can claim anything about those hats, it is even true that each one of those hats is the same size as the universe, or that they are all completely green and completely red at the same time. In normal language, this would be different, but that is not the context here.

> Note: this question was originally set in a maths exam, so the answer assumes some basic assumptions about formal logic. A liar is someone who only says false statements.


This is a somewhat irritating property of formal logic and mathematics. Natural language receives a “special” grammar that isn’t always declared up front. You just have to sort of be in on it.

In this case, the reader is given the special definition of liar, but not the special definition of “lie”. (As in, it’s not a lie to make definitive claims about nonexistent hats.)

A lot of the “trick” in logic puzzles boils down to this issue of word play. This puzzle could have been drafted so that the liar’s statement leaves proper room for the no-hats case, but then it would be too easy.


> In formal logic, if you have no hats, it is true that all your hats are green.

But told by someone who cannot make a true statement.


That's the thing, the problem isn't written in formal logic. It's written in English, which is vague.


It's written in a form of English that is formal enough to have a straightforward translation to logic formulas. Also, in the solution article that now has been posted, it's compared to the statement "I have read all books on my shelf" with an empty shelf, which is indeed vacuously true. The sentence about hats is equivalent, I think even the least exactly-minded English speaker would agree.


> Also, in the solution article that now has been posted, it's compared to the statement "I have read all books on my shelf" with an empty shelf, which is indeed vacuously true.

Really? Any human I have ever met when presented with that statement would likely immediately point out that there are no books on that shelf.


I read statement "All my hats are green" as meaning:

For every hat H that I have, H is green.

If I have no hats, this statement is true, just as

* the empty sum is 0,

* the empty product is 1,

* the empty AND is True, and

* the empty OR is False.

So with this interpretation, the liar having no hats would make the statement true.


by the same following, this would mean that any statement on the members of an empty set can be made and it would be logically true?

e.g. "all my lamborghinis have magical goat skin seat covers" is true if 1) I have no lamborghinis or 2) All the ones I own have magical goat skin seat covers.

(fr I have no logical or mathematical background)


Correct.

Common source of confusion/trickery/divergence between ordinary language and formal logic.

Edit: Logically speaking, the following two are equivalent:

They married and had kids.

They had kids and married.


Also I think sometimes children will realize a logic gap there and so they will try this funny trickery where they will make statements like these, which technically are true, but imply something totally otherwise to others. Which I find very interesting and kind of speaks to ability and inventiveness of children to think outside the box. Parents may find it annoying or dismiss it, but I think it is great.


vacuous truths are indeed a useful form of half-truth if you are aiming to deceive.


> Edit: Logically speaking, the following two are equivalent:

Depends on your logical system! There are temporal logics to allow one to capture logically the difference between the two.


I don't have formal logic or any math beyond calculus, either, and it appears that this fact is to our advantage.


You don't need to have learned formal logic to conclude the answer to this puzzle in my view. Yes, formal logic concludes it, but plain logic as well. The key is to realize that the answer will go against your learned social intuition and be fine with that. Social communication in many cases is illogical for efficiency reasons and that is fine. It is interesting to point out those cases and make puzzles out of them.


I agree.

I would appreciate it if you would correct my thinking on the subject, if I have erred: https://news.ycombinator.com/item?id=42365506

Thanks in advance.


Yes, your statement would be true.


Yes


Perhaps I'm being a bit too logical, but in mathematics and logic the statement

  For all x in A, x has XYZ property
is taken to be true when A is the empty set.


No, in logic that is a vacuous truth. All my hats is true for zero hats. But that would not be a lie. And since the liar always lies, that can not be case.


For me, this is one of those types of examples that illustrates the problem with logics allowing vacuous truth.

It amounts to an assumption of an implied conditional ("If I have hats...") which is not always warranted. The "gotcha" here says more about the vacuous truth assumption than it does someone who falls for it.


I think it is very logical to allow for vacuous truths. Doing otherwise would not be logical. The actual key insight is to accept that in a lot of cases everyday communication itself is not logical, because it is more efficient to communicate skipping always being logically correct. This builds social intuition that goes against the logic. It is interesting to observe and point out those cases, which this puzzle does.

Because for efficiency reasons you make a lot of assumptions constantly that may or may not be true, and 99% cases it would work for your favour.

Sometimes assumptions need to be challenged or we need to be reminded of that it can be good to challenge assumptions in certain cases, it can allow us to discover some new things.


> I think it is very logical to allow for vacuous truths. Doing otherwise would not be logical.

I guess I disagree, although I don't mean that disrespectfully. Vacuous truth is one reason why nonclassical logics exist. The wikipedia article gives a good example of how allowing for vacuous truth can lead to absurdities: "All my children are goats" said by someone without children. This is a statement that is vacuously true technically, but (assuming laws of biology hold, and a human is making the statement), it is something that could never be true even if the antecedent ("I have children") were true. It's not just something playing on incorrect intuition, it's a statement that is true only by convention or a certain line of reasoning that to me is made only out of convenience because of certain implications.

It stretches the definition of "true" so far that the term "vacuous truth" no longer means "truth" in the general sense in which it is understood. It plays on the use of the term "truth" more than anything else to me; one could redefine "vacuously true" statements as "vacuous" statements in the sense of "undefined" and then the "gotcha" would no longer apply.

I think the example also captures a sort of flaw in applying classical logic (at least classical logic with vacuous statements) to everyday speech in another way that I don't think is just incorrect intuition. If someone asserts "All my hats are green", it's understood to be an assertion that the speaker does in fact have hats, otherwise there would be no point in structuring the statement as it is. That is, the statement is evaluated as true or false with reference to the antecedent because it (the antecedent itself) exists, and another, different statement could have been made. Classical logic evaluates the statement "All my hats are green" as if it were the same as "If I had hats, all my hats would be green" — but they are not the same statement, they have different meanings. There's a counterfactual possibility in natural language, which I think requires nonclassical logic.


Thank you for taking the time to write this. I don't have any formal training in the field but it matches my intuition and I am surprised, astonished even, to see this explanation so far down.


i think its relevant that the liar has to say false things, which is more limited than just not-true things.

if you dont assume the vacuous truth, and instead leave it undefined, then when hes got no hats, "all my hats are green" is absurd, rather than false.

the gotcha only stops applying when you put a vacuous false, rather than true or undefined.

is this really a flaw in applying classical logic? with the vacuous true, the only information you get from "all my hats are green" being false is that they have at least a hat, same as the intuitive result


Do you think regular people, when communicating, use academic logic? Or do you think the liar is an academic?


Do you think that amongst regular people, there exists a liar who always lies?


No. But that is the premise. People redefining ‘all’ to include ‘none’ is not.


It is a logic puzzle. It is not two regular (or academic) people communicating


Yes. So we will apply logic, but assume the people making the statements are otherwise ordinary people and do not do strange things like defining ‘all’ to include ’none’.


Let's say that saying 'all my hats' implies that the set of hats is non empty, then you have the two following statements

    my-hats is not empty
    for every hat in my-hats, is-green(hat) is true
We know that the speaker always lies, so both statements must be false: my-hats must be empty, and it must be that it exists at least one hat in my-hat that is not green. This is a contradiction. So either the speaker or the puzzle is not consistent (and uninteresting), or the 'my-hats is not empty' is not a valid assumption.


I was initially thinking that, but you can parse it as one statement "my-hats is not empty AND for every hat in my-hats, is-green(hat) is true", in which case it's still consistent for that single statement to be false, and it can be false by my-hats being empty.


That's a very good point!


But ‘my hats is not empty’ is not a statement being made by the liar.


He said 'all my hats are green' either that statement is to be interpreted to require that the set of hats is not empty or it isn't. In the first case that interpretation would be part of the statement he made.


This person‘s argument hinges on trying to make two statements rather than one, I’ll illustrate with a quote:

> We know that the speaker always lies, so both statements must be false: my-hats must be empty, and it must be that it exists at least one hat in my-hat that is not green.

No. Since it is one statement as written, and the rules of common logic are not created by the liar, as I said up in the thread, either possibility is true. The person may have no hats or have one hat that is not green.


One of the points of this puzzle is to see beyond your social intuition. So yes, this puzzle plays on being able to figure out the logic while it goes against common social intuition.


Fascinating. I think many people here have applied their own social intuition- - a programmer’s idea of an empty sets- to the puzzle.


True, but "programmer's intuition" is because most programming languages are more or less based on formal logic so they agree with the formal logic interpretation even if many programmers have never studied formal logic.


"More or less" is the key and the rub. The specific semantics must be determined and utilized in place.

For me, the evaluation of the empty set should have separate semantics than that for how a non-empty set's elements are logically combined to produce a value.

This is the result of doing stats programming for grad students, doing lots of database design and programming, and lots of regular programming in imperative and functional languages.

The key is that we are always working within a context, and this problem's context involves both formal logic and regular old language. And, whew!, is there a disconnect and interference pattern.

What a delightfully unserious discussion!


  function areAllTheirHatsGreen(someone) {
      return someone.getHats().every(hat => hat.color === 'green')
  }
I wonder if there's a language or programming paradigm where this function wouldn't be determined simlarly.

I think best you could do is make a validation check that throws an error if there's no hats at all, but would that make sense?

What if you have a function that has to return a boolean and not throw an error.


The best I've found are languages like F# that allow you to return a pair of values, which for your example would be a tuple of (bool, bool), where the first is isError and the second is the evalResult. Of course, you better not mix `em up!

As to paradigms, I've not seen anything yet, but I haven't seen it all, and corporate America has their legacy systems that limit their explorations.


You are correct, and anyone that couldn’t come to that conclusion needs to stop overthinking the problem it is pretty basic 101 intro to logic type question.

Not sure why so many people got it wrong maybe ESL is at play here


Yeah, I'm a bit confused there is no option "he has at least one non-green hat", which is what I would answer.

Perhaps that means I'm wrong.


It's a multiple choice question, it's asking "which of the following is necessarily implied", and A is the only one.


Whether you are wrong depends on whether you interpret his statement in a mathematical or in a colloquial sense. Colloquially, if I have no cats and tell you "all my cats are brown", you'd say that I'm lying, beause I'm implying that I have cats. Mathematically, if I have no cats, then it is true to say that all of the ones I have, which are zero, are brown.


If you have none how can you say they are specifically brown? You could say they are any color then which makes them being just 1 specific color not true. Your non-existent cats aren't brown, they are every color or even no color.

Maybe even more accurately they aren't brown, they are an undefined color.

I'm not really satisfied saying that the characteristics of something that doesn't exist can be anything. I am satisfied saying the characteristics are undefined though.


You are talking about the colloquial meaning of these words.


At most people reading The Guardian would?


The article states that "this question was originally set in a maths exam, so the answer assumes some basic assumptions about formal logic." This is a funny way of phrasing it, but should make it sufficiently clear to any perceptive reader of The Guardian that they are supposed to ignore the colloquial interpretation of the phrase.

At any rate, it would hardly qualify as a puzzle if the answer was so obvious


Agree it must be true that it has at least one hat, and it must be non-green (he might have other green hats).


Why would you conclude that the liar is telling the truth that they have any hats at all?


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 the logical statement: "I own at least one hat and all my hats are green" (because most people don't consider vacuous truths to be relevant in most contexts), in which case it will be false if I own no 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)


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.


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


"for each hat in the set of hats I know. the statement 'the hat is green' is true"; the previous statement would be true if the set of hats I know is empty.

Incidentally, if you are a programmer it should be obvious that folding 'and' on an empty set must return True.


Uninitialized variables are 90% of our bugs, or so I've been told.

I don't consider a boolean "and" or "or" of a list of bools to be automatically true or false of an empty set, my friend. To me, the specific case for a boolean function applied to an empty list of bools would have to be explicitly stated in the design.

Thanks for explaining how mathematicians and logicians treat the empty set. I have more pragmatic situations to address :-)


Consider iterative code to sum a collection of ints:

  sum = 0
  for value in collection:
    sum += value
  return sum
For every non-empty collection this returns the correct result, and for the empty collection it returns 0.

Now the product:

  product = 1
  for value in collection:
    product *= value
  return product
For every non-empty collection this returns the correct result, and for the empty collection it returns 1.

Now the AND:

  A = True
  for value in collection:
    A = A AND value
  return A
For every non-empty collection this returns the correct result, and for the empty collection it returns True.

Now the OR:

  R = False
  for value in collection:
    R = R OR value
  return R
For every non-empty collection this returns the correct result, and for the empty collection it returns False.

Let's abstract it:

  Def FOLDR( initial, OP, collection )

    result = initial
    for value in collection:
      result = result OP value
    return result
So now:

  sum(     collection ) = FOLDR(   0  ,  + , collection )
  product( collection ) = FOLDR(   1  ,  * , collection )
  and(     collection ) = FOLDR( True , AND, collection )
  or(      collection ) = FOLDR( False, OR , collection )
This is why we define the results we do on empty collections. It's not just a convenience or a convention, it's consistent, and to do otherwise, even if documented, is to lay a trap for future maintainers.


Exactly. More generally the natural initial value for a fold of an operation is the identity (or zero) element for that operation.


But you have specifically initialized your AND and OR results to be True and then False, respectively, thus specifying the resulting value for their processing of the empty set.

What I'm saying is that you always need to specify that default value to handle the empty set properly. In no way would I consider ANDing or ORing an empty set's boolean values to be automatically True or False, (no pun intended). You have chosen to specify them, and in real world programming, not having any elements of that specific set's specific kinds of values could well mean that the default results could be any combination of False and True, (NPI, again).

And, yes, I understand that you must initialize the temporary processing value (that you then return) to True and False in order to properly AND and OR the set's values, but that is different from the semantics of the set's cardinality.

I programmed professionally in C# (with the help of F# for its fsi.exe command-line utility) for a number of years, so I am well aware of how fold et al work. They were a very useful aspect to functional programming, making a lot of processing tasks very straightforward, as you have.

To apply my thinking to your FOLDR function, I would add a parameter that specifies the value to return for the empty set, because I would want to specify its semantics for that specific set such that they do not depend upon the value needed for computation to define it.

  Def FOLDR( emptysetval, initial, OP, collection )

    if length( collection ) == 0 then
      return emptysetval
    result = initial
    for value in collection:
      result = result OP value
    return result
In a similar vein, I also used to specify my db wrapper functions to add special error conditions for specific cases. Let's say you're using a select statement that is only going to return 0 or 1 rows, my select wrapper would have a parameter that would say its valid result cardinality is specifically 0 or 1 and nothing else. Yes, the select statement would succeed, but the situation in the table might not be semantically correct, and it's better IMO to catch the problem when it is issued. It also standardizes the handling of such error conditions by the caller of the wrapper.

The same occurs with a "select count(*) ..."; it must return a single row, or it is an error in semantics if not for the db engine. It can also be a problem if your update statement affects more than one row. And there are other situations where the cardinality must be "> 0" or ">= 0". All these cases were my own error conditions that were not SQL errors, but merely semantic errors caused by db data problems.

I used these this style of manual ORM from perl to VB to C# and F# for 15+ years, to great success.

SEPARATELY

In a db/stats context, the empty set should count as a NULL value, and I don't like to AND or OR actual boolean values with NULL values. Sure, the semantics are defined but I find it's better to catch the NULL value's presence before it gets to being involved in operations.

That's why I always specified NOT NULL in my column defs, because all hell breaks loose once a NULL gets put into a column's values.

Statistics also has such difficulties, as I was many, many years ago helping grad students with their SAS and SPSS data sets and processing. It's always just better to get rid of NULLs, unless the stats you need use are built to handle them. Once again, properly producing the required semantics are the end goal.


> But you have specifically initialized your AND and OR results to be True and then False

No other value would be meaningful.

> What I'm saying is that you always need to specify that default value to handle the empty set properly

no you need a default value to handle the base case of the recursion. The result of the empty set falls off from it.


IIUC, using your function with an empty set in SPSS or SAS will result in a NULL value, which is neither True nor False (NPI).

Do you know the truth tables that include NULL? I don't off-hand, but I seem to remember that combining NULL with a True or False results in NULL, which is why I catch my NULLs before they become operands in my operations.

ANDing or ORing the lack of values in the empty-set is always specified by someone's semantics. You're just determining those semantics as a by-product of the way ANDs and ORs are calculated.

This is why the reality of "All my hats are green" has a great deal of real-world ambiguity when there are no hats, because "Color( NULL[-hat] )" is NULL. Now, how you interpret NULL in that case is up to you, because NULL is neither True nor False, in my experience and understanding.

I am open to learning, tho.

ETA: Wouldn't your method also mean that the liar saying "All my hats are not green" would also be true? And, I'm no mathematician, but if "All my hats are green" and "All my hats are not green" both eval to True, I think something has gone very wrong. That looks like why the NULL value is so useful in SQL and stats.


But you have specifically initialized your AND and OR results to be True and then False, respectively, thus specifying the resulting value for their processing of the empty set.

I've read through your reply several times, and I think you've missed the point.

The code here is the code that produces the right result for non-empty collections. It's the shortest, cleanest, clearest code that does so. These aren't random initial values, chosen arbitrarily. They are the unique values that make the code give the right answer.

Then we ask: What result does it give for the empty collection?

The answer is that for "sum" it gives "0", for "product" it gives "1", for "AND" it gives "True", for "OR" it gives "False".

In particular, in each case it gives the identity element of the algebraic structure. This isn't a coincidence, it's a part of how algebraic operations work.

That's why for any operator, the result of applying it to an empty collection is the identity element. It's algebraically consistent.


Sure, but as a programmer, my job is to specify and code out the semantics of the system. ANDing and ORing a set of bools may very well be different for one list's semantics than another's.

So, the initial value that forms the basis for those computations -- to my mind and experience -- is as related to the value computed for the empty set as the programmer decides it should be. I don't think that function's default will necessarily be the proper semantic result when applied to the empty set.

As an example, why should "Are all hats green?" have the same result as "Are all hats NOT green?"? If the logical computation's initial value is the automatic result, then you have merely answered the mathematical-logic answer to a question about sets, not about the list of real-world things being modeled.

If one is writing pure math software, then the answer will be the pure math logical result. When one is modeling a real-world system, the semantics require another level of specification, in my experience and opinion.

(Good morning. I've never replied to such an old comment before. I do not yet have software to monitor my active conversations around here, and am only just beginning to entertain undertaking such a project, so it is merely luck of the universe that I found your interesting comment this morning. Thanks. It's like a mental warm-up as I begin my day.)


"Which, if any, of the following statements can we conclude from what the liar has said?"


That's the conclusion I came to as well. That said, for whatever reason, the part that was most confusing to me was realizing that the logic puzzle was about the idea that the statement itself had to be false. For whatever reason, I glossed over the phrase "a liar who always lies" the first time and just read "liar" everywhere else, so it wasn't obvious to me what the intent was behind using the word "liar" was.

Personally, I'd change the original wording (from the quoted italic section) to "someone who only tells lies" if I were the author. It's probably specific to me, but I'm always thrown by phrases like that because it seems like it's trying to differentiate in some way from someone else; surely there isn't anyone who "always lies" who _isn't_ a liar, so why say that? It's distracting to me in the same way as if someone said "the speech-capable human being who speaks only in lies". Normally it wouldn't bother me, but because puzzles like this often seem to be used to try to illustrate some smug point about how bad people are at logic, phrasing things in an unnecessarily confusing way just makes it seem even more smug (see https://xkcd.com/169/).


Wait, is there are any color space in which Turquoise gets classified as green?


Yes, the one in which there is no word for blue.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: