4 ms·
I learned about Vacuous Truth the hard way recently when I found out that `every` method in JavaScript returns `true` for empty arrays as well.
by predictand 2y ago
I learned about Vacuous Truth the hard way recently when I found out that `every` method in JavaScript returns `true` for empty arrays as well.
- chiakic 2y agoBut if you consider “liar” to be an object, > liar.hats.every((hat) => hat.color === "green") will throw a TypeError: Cannot read properties of undefined. That’s definitely not `true`.
- wrigby 2y agoThis depends on `liar.hats` being undefined, but what if `liar.hats` is an empty array? That seems like an equally valid way of representing a person that owns no hats.
- deleted 2y ago[deleted]
- ecshafer 2y agoYou implemented the problem wrong, and thus got an error. If hats is a list of colors, then every hat != green is true if the list is empty.
- LudwigNagasena 2y agoI wouldn’t say it is wrong per se. It certainly defies the conventional translation into FOL, but there is no a priori reason to pick the conventional formalism of FOL for this problem.
- Volundr 2y agoI don't think that's true. What if the liar buys a red hat? liar.hats.push("red") This only works if hats is an empty array. If hats is just not a property people have (undefined in the example), then you can't represent adding them. Now you might argue hats can be null when a user doesn't have them, or a non-empty array, but that's clearly not a great way to represent that. Now you have owning no hats represented two different ways as an empty array or null, and must build special casing around the null case (unless you are using a language where nil and the empty array are one and the same)
- recursive 2y agoHm. No. const liar = { hats: [] }; liar.hats.every(hat => hat.color === "green") true
- marcosdumay 2y agoIn programing, you can always rewrite that first rule as "all" and "some" must compose over set union. So, "all (A ∪ B) == all A && all B", and "some (A ∪ B) == some A || some B". That lets you discover the answer for the empty set.
- LudwigNagasena 2y agoWhich leads to a funny fact that if all elements of the set S satisfy proposition P it doesn’t necessarily imply that some elements of the set S satisfy proposition P.
- aabhay 2y agoMy description of the power set is by definition allowing all to imply some
- LudwigNagasena 2y agoI don’t follow. Can you elaborate?
- Spivak 2y agoThe power set of a set S, P(S) (or sometimes 2^S) is the set of all subsets of S including both the empty set and the set itself. To bridge the gap with programming, make a map f: S -> bool which represents our predicate. all(f, S) => either S is empty or for all elements s in S, f(s) = True. Now make f work on sets as well as individual values. f({x, y}) means True if f(x) and f(y) are True, False otherwise. all(f, S) => all(f, P(S)) If we take the opposite and define all(f, {}) = False then this doesn't work and in addition all(f, P(S)) = False for all sets S.
- LudwigNagasena 2y agoThat doesn’t explain how all(f,{}) => some(f,{}) may be made true with your definition preserving the distributive property.
- adamc 2y agoThis is even what I expected, but I majored in math, so maybe that biased my response.
- crazygringo 2y agoAs I think you would hope from a practical standpoint -- you don't want to have to handle a special case of false and always check if the array is empty. I agree it's only logical in engineering contexts like that though, not in everyday language.