The only logical answer is yes. It would be rather absurd to make an exception for the case where you start with one marble in the bag. That would make logical reasoning extremely cumbersome, for no benefit whatsoever.
The only logical answer is yes. It would be rather absurd to make an exception for the case where you start with one marble in the bag. That would make logical reasoning extremely cumbersome, for no benefit whatsoever.
As with anything mathematical, we picked the way that yields useful and elegant mathematics. The notion of "all" would be awkward to work with if it did not apply to the empty set (bags without marbles) so we extended it in a way that is consistent with what it means over non-empty sets (bags with marbles.)
One very nice thing about this definition of "all" is that it gives this simple relationship between logical "all" and logical "none":
"for all x, P(x) is true" is equivalent to "there is no x for which P(x) is false"
I.e., if there is no marble in the bag that is not black, then all marbles in the bag are black... so to speak.
This yields elegant and useful mathematics, and (as you would expect) that tends to mean elegant and useful code as well.
For example, suppose you had an enormous dataset of records that included zip codes and wanted to know: "Are all the zip codes in this dataset in the continental United States?" One approach would be to split the data into smaller shards, answer the question for each shard, and "and" all the answers together. What if you chose a bad way of sharding the data and one of the shards was empty? What result would you want returned for that shard?
- Take a bag for which “all marbles in this bag are black” is false
- Add a black marble to that bag
- After that, “all marbles in the bag are black” becomes true
As is often the case in mathematics/logic [1] with these kind of things, you can hold an alternative view where “are all marbles in this bag black” doesn’t make sense for an empty bag or one where it has the answer “yo”, but if you do that, you’ll find that many proofs get more cumbersome because you have to handle that case differently from all other cases.
[1] other examples are the convention that 0⁰ = 1 and the convention that 1 isn’t a prime number (that’s an example where mathematicians (eventually) decided that having 3 kinds of positive integers (prime numbers, composite numbers, and 1) is the better choice)
> - Take a bag for which “all marbles in this bag are black” is false
> - Add a black marble to that bag
> - After that, “all marbles in the bag are black” becomes true
This reasoning is not correct. If the bag contains exactly a red marble at the start, "all marbles in this bag are black" is false as you required, but it breaks the claim at the end that "all marbles in the bag are black".
There is in fact no bag that fulfills your reasoning, even the empty bag wouldn't (when starting to write my reply I had erroneously assumed so)
The only logical answer is no. It would be rather absurd to make an exception for the case where you start with one marble in the bag... and yet:
marbles = ["black"]
marbles.pop()
all(m=="white" for m in marbles) # => TrueThe logical answer is "maybe."
A common error would be a programming mistake in the selection of the list element return an empty list. The returned list would, unexpectedly, comes empty. Trying to check if everything is black would return True and the code would follow on. It would be very hard to debug
If you want the inverse behaviour, you have to verify that all elements do not satisfy it. And that necessarily results in the empty set being falsy on any, but truthy on all.
Also, its just easier to use .any to check if the set is empty or not, in many cases.
But we are operating under predicate logic. The negation of “all marbles in the bag are black” is “there is a marble in the bag which is not black”. Then, clearly the latter statement is false in the case of an empty bag.
In fact, we can confidently claim falsity for any given statement of the form “there is a marble in the bag such that…” when the bag is empty. Therefore, by the law of the excluded middle, its negation is true, so statements of the form “all marbles in the bag are…” are vacuously true when the bag is empty.
It's certainly misleading in every day speech. On the bright side, all my papers have been published and all of my research funding has been granted.
What do you mean here?
"some element doesn't have the attribute" requires a non-empty set.
If you mean "it is false that some element has the attribute", then you need to write that very differently, which makes it much less of a surprise that it has different implications from the "all" statement.
The comment he replied to was claiming that any question that is true for n = 1 should also be true for n = 0, but this comment shows that it is obvious nonsense.
The comment above basically claimed:
marbles = ["black"]
all(m=="black" for m in marbles) # => True
marbles.pop()
all(m=="black" for m in marbles) # => True
If that is the case then the following would also need to be true: all(m=="white" for m in marbles) # => True
all(m=="green" for m in marbles) # => True
What color is the marble?Just because the question “there is a marble in the bag such that…” is false does not mean you can just negate it and say “all marbles in the bag are…” if the actual answer is that the question is not applicable.
"All marbles in the bag are white" is equivalent to "For all x, if x is a marble and x is in the bag, then x is white". Since the antecedent is false if the bag is empty, the statement is true by material implication.
"For all x, if x is a marble and x is in the bag, then x is white"
I would question if nothingness is a marble. Or would you say that the following statement is also true? I would say that x is a marble and therefore can be neither even or odd because it is not a number?
"For all x, if x is a marble and x is in the bag, then x is even"
That is just a nonsense question same as asking if all the non-existing marbles are of a particular color.
https://en.wikipedia.org/wiki/Vacuous_truth
Agreed, sometimes this leads to true statements that sound like nonsense. One example from the article is "if Tokyo is in France, then the Eiffel Tower is in Bolivia". This is a true statement because Tokyo is not in France.
>"For all x, if x is a marble and x is in the bag, then x is even"
We can rewrite this as "For all x, x is not a marble or x is not in the bag or x is even". We can see that this is true if "x is not in the bag" is true for all x. It's not really nonsense because we can quantify over all objects, so some of them will be marbles, some of them will be even, etc.
Going back to the more general question we can look at the statement "For all x, F(x)" where F is any predicate. Call this statement P. The negation ~P is equivalent to "There exists some x such that ~F(x)". But if we are quantifying over the empty set, ~P is false, so P must be true in that case.
all(m=="white" for m in marbles)
is not the same as "For all x, if x is a marble and x is in the bag, then x is white". The statement is more "For all x in the bag, is x white?" and the answer to that is either "No, nothing is not white" or "Question is not applicable".They're the same, just quantifying over different sets. I can quantify over objects in the universe, in which case I need the clause about being in the bag. Or I can quantify over objects in the bag, in which case I'm quantifying over the empty set.
all(m=="white" for m in marbles)
By De Morgan's laws, this is equivalent to
not any(m != "white" for m in marbles)
If you want all(m=="white" for m in marbles) to evaluate to False for the empty set, then any(m != "white" for m in marbles) has to evaluate to True for the empty set, or you have to give up on De Morgan's laws.
This is how standard first-order logic works. Again, you're welcome to try to make your own system of logic that works differently, but good luck doing that while preserving all of our theorems in set theory and mathematics.
“Apologies, we’re out of milk. Could I offer you a coffee without sugar instead?”
Black is a property of a marble. Without a marble, black cannot evaluate to true. Therefore zero marbles equals “no”
Oh wait, nobody in the audience has a cell phone. Can the movie begin?
> Without a marble, black cannot evaluate to true. Therefore zero marbles equals “no”
"Is_Black" cannot evaluate to false either, therefore zero marbles equals "yes". But that's wrong too, because it is never evaluated, because there are no marbles to evaluate it on. TRUE is the identity of AND, and ALL is the aggregation of AND, so ALL([]) == TRUE. Put another way:
If you start from a bag with N black marbles and split it up between M bags, can you say that for each new bag, all the marbles in it must be black? Yes, you can. That is, if you find a marble in the bag, it will be black. This still holds even if one bag doesn't happen to get any marbles.
> Oh wait, nobody in the audience has a cell phone. Can the movie begin?
That's a really good one. Admittedly, I've never had to actually explain why statements can be vacuously true to anyone. But I'll keep this in mind if I ever have to.
"All marbles in the bag are black" is equivalent to "For all x, if x is a marble and x is in the bag, then x is black". Since the antecedent is false if the bag is empty, the statement is true by material implication.
So it's consistent to say that a bag can contain all red and all black marbles at the same time?
marbles = (BlackMarble() for _ in range(random.randint(0, 10)))
all(isinstance(m, BlackMarble) for m in marbles)
Surely should always be trueIf that case is so different, than the case with two marbles is also different - because removing the second-to-last marble will change will change the bag to be in that situation. But then, the case with three marbles is also different, and by induction you are left with only special cases.
On the other hand, see the related statement "If all marbles in a bag are black, adding a red marble will result in a mixed bag" clearly fails for the empty bag.
This isn't really a question of logic or mathematics. Mathematicians just use systems which are useful. And predicate logic, which has proven invaluable, would allow OP's claim.
[0] yes, “none()” doesn’t actually exist in Python, but we can imagine that it did, and see that if it did, it should have this relationship.)
> The only logical answer is yes.
The only "logical answer" is "there are no marbles in the bag". If this must be cast to a boolean somehow, the only "logical answer" is no. There should be a discontinuity as the last black marble is removed. That isn't absurd at all
A marble is in the bag -> the marble is black = True, even if there are no marbles in the bag. You can consider the "all" method as asking for the truth value of "A marble is in the bag -> the marble is black"
Also, why am I getting downvoted? I’m starting to realise that HN is not the place to come for intellectual discussion anymore if you have anything to say that isn’t immediate agreement. I guess dang has set a flag on my account that encourages others to downvote me, because I’m not sure what other explanation there is for how my comments have been treated recently
But is it useful?
Suppose I'm a bus driver and I ask "all aboard?"
I'd expect that if the answer is false, I'm missing somebody, and not that the bus is empty