4 ms·
> all([]) True > any([]) False Not very consistent philosophy in that case. Surely if 'all' is True then 'any' got to be too?
by rightbyte 3y ago
> all([])
True
> any([])
False
Not very consistent philosophy in that case. Surely if 'all' is True then 'any' got to be too?
- shawnz 3y agoHow could they both have the same answer? They must have opposite answers because of De Morgan's law: asking "is any item true" is the same as asking "are NOT all items NOT true"
- orf 3y agoGoing by the example in the post, "all unicorns are blue" seems truthy whereas "are any unicorns blue" seems falsey in a world with no unicorns?
- JadeNB 3y ago> Surely if 'all' is True then 'any' got to be too? No. `any([])` means "some element of [] is true", which is false because there aren't any elements. `all([])` means "all elements of [] are true", which is true because it's (classically, anyway) got to be true or false, and being false would require that there be some element of [] that isn't true, which there isn't. More generally, `!all([!x for x in xs])` (or whatever the syntax is; I'm not a Python programmer)—meaning "it's not the case that the negation of every element of xs is true"—is `any(xs)`, so `!all([])` is `any([])`.
- deleted 3y ago[deleted]
- CJefferson 3y agoIt is consistent, and in practice this is the only definition that ends up being sensible, if you play with lots of examples. I have done this as a, I believe, surprisingly fun thing with older school children, where we think about all the things we want to be true about all, and any, and then figure out what the answers are. Some examples are "if something is true for 'all students', it should be true for any group of students", and if "all students have a hat" is true, then it should not be true that "any student had no hat", etc.
- thewakalix 3y ago`any` corresponds to the existential quantifier, not the universal.
- Arnavion 3y agoany(collection, predicate) == not(all(collection, not(predicate))). Or in English, "It is true that there is an even number in this list." is the same as "It is false that all the numbers in this list are odd."
- zem 3y agothink of "any" as "we can find an element for which this is true", and "all" as "we cannot find an element for which this is false"
- knappa 3y agoI would read all more formally as: for each element in this list, the element is true. Then you get a vacuous truth. (Think about the negation: there is an element in the list which is false. That's obviously false.) Any would be more formally: there is an element of the list which is true. But the list doesn't have any elements, so that's false. Looks logical to me. Plus you get that `not any( map(lambda x: not x, l) )` is the same as `all(l)` for any list `l`.
- rightbyte 3y ago> Any would be more formally: there is an element of the list which is true. But the list doesn't have any elements, so that's false. It is just a matter of convention and I see no logic behind why any convention would be worse or wrong. But I believe if 'any' implies 'at least one' so should 'all' otherwise they use different conventions. In practice I get it was arbitrary choices and this is just how you end up when doing the obvious implementation. def all(l): for e in l: if not e: return False return True def any(l): for e in l: if e: return True return False
- dragonwriter 3y ago> But I believe if 'any' implies 'at least one' so should 'all' otherwise they use different conventions. The conventions they use are not an arbitrary choice, and are those of predicate logic. any() is the “for any” (existential quantification) operator, while all() is the “for all” (universal quantification) operator. They are deeply connected: “all items in xs are true” is “there are not any items in xs that are not true”, or, in code terms, all(xs) == not any(not x for x in xs). And, vice versa, any(xs) == not all(not x for x in xs)
- rightbyte 3y agoSure thinking about it the 'all ([]) => True', 'any ([]) => False' might be more intuitive.
- petesergeant 3y agoTo prove “do all x satisfy y” you need to find an example that is not. In order to satisfy “does any x satisfy y” you need find an example that does.
- Sohcahtoa82 3y agoThink of it this way... You're logging incoming web requests and then gathering statistics in 5 minute intervals. During one interval, you get no requests. You check to see...did "all" of the requests get processed without errors? The answer is Yes, because to say No would imply there were errors. Did "any" of the requests cause an error? The answer is No, because to say Yes would imply at least one error.
- mrkeen 3y agoNo need for philosophy. any (<5) [6,7,8] any (<5) ([6,7,8] ++ []) (any (<5) [6,7,8]) || (any (<5) []) False || True True
- earthboundkid 3y agoNo need for philosophy, we can just use whatever assumptions underlie our technology without any reflection on what they are or how they got their.