15 ms·
Why does all() return True if the iterable is empty?
- deleted 3y ago[deleted]
- aib 3y agoIt's the identity element of the monoid, no? Similarly, the product of an empty list should be 1.
- 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.
- rgovostes 3y agoall([x]+x)
- Minor49er 3y agoWhy try to reduce assertions made against something that doesn't exist down to a boolean result? Clearly the answer is undefinable
- neuromanser 3y agoThe assertion is against the set (list in the TFA).
- rwmj 3y agoIt makes recursion easier. For example: ∀(head::tail) = head ∩ ∀(tail) if ∀([]) is defined as true then this works for the single element list.
- IshKebab 3y agoIt's easily definable. all(x) is true iff none of the elements in x are false. This is really the only sane option. To do anything else would be a weird special case for []. Like defining len([]) == None. There's no point; it just makes everything more complicated and worse.
- neuromanser 3y ago> In logic, this is called the principle of bivalence: there are only two values that a proposition can have, true or false. But Python has None, many other programming languages have null or nil, and Zen has mu. Maybe adding another value would help? Hoare labeled his invention of null a "billion dollar mistake". SQL NULL can't be far behind. Boolean logic has 4 unary and 16 binary operators, ternary logic has 27 and 19683, respectively. That's not helpful, that's intractable! I cannot recommend C. J. Date's books enough.
- jewel 3y ago> SQL NULL can't be far behind. SQL's NULL is far more useful though, since NULL != NULL. That lets you do things like join two tables with a column and not have the NULLs match. Consider, for example: select * from users where id = null; That will give 0 results, even if somehow you have a user with a null id. It's also really nice for non-ID, non-reference fields to represent N/A. For example, user.birthdate can be NULL if the birthdate is not known. SQL also lets you choose when you want NULL to be allowed for a column, so it's less likely to be a gotcha.
- tomp 3y agoFor anyone wondering how to fix the above query so that it works for arbitrary X (which can be NULL or non-NULL): SELECT * FROM users WHERE status IS NOT DISTINCT FROM $x
- neuromanser 3y ago> SQL's NULL is far more useful though, since NULL != NULL. That's not true! (Nor is it false.) NULL = NULL IS NULL, NULL != NULL IS NULL. I can't overstate this: as soon as either (or both) operand of any binary relational operator is NULL, the whole expression is NULL! I'm not being an asshole, this is the exact mistake that makes SQL NULL the other billion dollar sink! This is really funny, because i wasn't aware of laying such a beatiful trap.
- jerf 3y ago
- dkersten 3y ago“Are there any items in this list that are true? No? Ok, then False” I don’t care about any fancy philosophy. What’s important is what kind of operation you want for when implementing algorithms, and False is what I always want in cases where I do “all”.
- kadoban 3y ago> “Are there any items in this list that are true? No? Ok, then False” There's no particular reasoning that this is any more compelling than: “Are there any items in this list that are false? No? Ok, then True”
- jamilton 3y ago"is any item in this list true" is any(), which is different from all().
- CJefferson 3y agoCan you give a couple of examples where you want False for an empty all? I'd be interested to see them, as I've found I always want True.
- robot_no_421 3y ago> What’s important is what kind of operation you want for when implementing algorithms, and False is what I always want in cases where I do “all”. Why would you want "all" to produce results that are inconsistent with logic and mathematics? Consider this tautology, which is a result of De Morgan's laws: for any list L, we have that all(L) == ~any([~x for x in L]). In other words, if all([]) == False, then you would also logically need to accept that: False == all([]) == ~any([~x for x in []]) == ~any([]) which means that we'd require any([]) == True. And that's definitely an illogical result.
- stop50 3y agoYou can define all() as "is there any False item?" Which is False for an empty list, but true for any list with an false item. all(list) == anyfalse(list)
- shawnz 3y ago
- edflsafoiewq 3y agoall = foldr and True any = foldr or False
- hiAndrewQuinn 3y agoSo glad I know this language
- xcdzvyn 3y agoMan I love Haskell.
- aportnoy 3y ago1 is the multiplicative identity 0 is the additive identity all([]) is True any([]) is False
- kubb 3y agoEvery one (all) of the set of zero elements is true. It's not counterintuitive or inconsistent, this is the only way that makes sense. The complement is also consistent. None of the set of zero elements are true. So there aren't any true's. They're symmetrical cases, and negation turns them into each other. Not-any-true is equivalent to all-false, and not-all-true is equivalent to any-false.
- tromp 3y agoIf all marbles in a bag are black, and you take one marble out, are all marbles in the bag still black? 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.
- Eldt 3y agoThat's not an exception, that's a different situation...
- jackbrookes 3y agonot really marbles = (BlackMarble() for _ in range(random.randint(0, 10))) all(isinstance(m, BlackMarble) for m in marbles) Surely should always be true
- cedilla 3y agoIs it? If 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.
- pixl97 3y agoEh, wouldn't the induction reduce to 0, 1, infinity?
- bowsamic 3y ago> If all marbles in a bag are black, and you take one marble out, are all marbles in the bag still black? > 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
- manlobster 3y agoGiven: all(xs + ys) == (all(xs) and all(ys)) And: xs == xs + [] We have: all(xs) == all(xs + []) == all(xs) and all([]) Which implies: all([]) == True.
- toxik 3y agoI like this variant, it also works to show why any([]) is False.
- Smaug123 3y agoAlthough it's presumably much less controversional that `any([])` is false. After all, most people presumably think of an existential statement as being satisfied precisely when there's a witness to that statement, and of course an empty list contains no witnesses to any statement.
- kccqzy 3y ago"Any" is an existential quantification (what you mean by existential statement). "All" is a universal quantification. It can be vacuously true. If this is controversial to any one at all, refer them to an introduction to logic course.
- Smaug123 3y agoThere are logics in which vacuous truth is just not a thing (e.g. relevance logics). Your casual dismissal of the less common logics does not cause them not to exist.
- whoopdedo 3y agodef all(L): for i in L: if not L: return False return True Seems quite clear when presented that way. Same with `any`. > In logic, this is called the principle of bivalence: there are only two values that a proposition can have, true or false. But Python has None, many other programming languages have null or nil, and Zen has mu. Maybe adding another value would help? If `all` were in Python v1 it would have thrown an exception when called with an empty list. (Said jokingly, or is it?)
- Buttons840 3y agoWe could have just used: all(L) if L else True
- ajross 3y agoThis is the essence of the issue. All the pontification about (sigh) periods of western logic is missing the point. The object isn't question isn't a statement of philosophical logic[1]. It's a computer program. And, yeah, it's implemented by iterating over the list and returning false if it finds anything false. If it gets to the end, it returns true. And that is all that needs to be said, because it is an algorithm and not a statement about the world. Maybe it's wrong. In which case, file a bug. But the bug isn't about philosophy either, it's about "I want to solve a problem and all() is giving me the wrong answer". [1] Not to be confused with actual mathematics, of course. Math doesn't have semantic arguments like this because it starts from a stance of defining terms and axioms such that no one gets confused over words. Sigh, again.
- cpgxiii 3y agoThis and the parent are mistaking the "how" all([]) is True for the why. The code is the "how", but it doesn't just exist. It could just as easily end in return len(L) > 0 instead, which would obviously have different behavior. The code is the embodiment of a particular design, the "why", which has a more complex history.
- ajross 3y ago
- mabbo 3y agoI think a key point is that (correct me if I'm wrong here) in predicate logic you can rewrite ∀x Fx As Not ∃x (not Fx) Ie: "for all x, f(x)" implies the opposite of "there exists an x where not F(x)". People seem to have less of a problem with Not ∃x (not Fx) when the universe is x is empty. I usually explain it to junior developers by telling them to imagine it's a for loop over a list that returns true/false if it finds a value that doesn't match what's expected, and the opposite of it reaches the end of the list.
- dylan604 3y agoIn any discussion on languages like this, I feel the Wat discussion is always appropriate: https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat
- H8crilA 3y agoThis video is over 10 years old. I felt very old all of a sudden. (BTW, it's hilarious, go watch it)
- travisjungroth 3y agoThink often when people want/expect this to be false, they’re combining two checks: that there’s an item and all items are true. This covers doing an operation on “ready” items. Instead: if items and all(items):
- Nevermark 3y agoThe sum of no numbers is 0. The product of no numbers is 1. The union of no areas (sets, …) is the empty area. The intersection of no areas (sets, …) is the universal area. The commonality here, is what element z can you add or remove from a list which won’t change the result? We call the element that makes no change to the result, the “identity element”. For y = sum of {x1,x2, … Xn, z}, We know z must be 0, if it has no impact on y. So the identity element for sum is 0. So if y = sum of {}, we know we can insert the identity element without changing the result, and we know the sum of {0} is 0. The identity element itself. So operations applied across lists return that operation’s identity element for an empty list. —- Ergo: the identity element of “all” is “true”. The identity element of “any” is “false”. —— More fun: The identity element for the resistance sum across parallel resistors, is the infinite ohm resister. The identity element for the vector distance sum of a child making a sequence of jumps is the in-place jump. —- Getting meta with, oh hell, monads: The identity element for C, the concatenation operator over lists, is the empty list {}. Since all lists are concatenations of lists (down to empty & unitary lists), we can view any operation Q over lists also as an operation over the concatenation of lists. So any Q acts like a monad over list concatenation operations. If Q = sum, then it is the monad that transforms concatenations of lists of numbers into the sum of those numbers. If Q = all, then it is the monad that transforms concatenations of lists of truth values to the conjunction of the truth values in those lists. With that view in place, we can see another reason why the identity of any operation Q is Q on an empty list Q{} Because as a monad, Q applies over C, the concatenation of lists. The identity of C is {}, so the identity of Q must be Q{}. Voila! So we really shouldn’t define sum{} as 0, but define 0 as sum{}. “0” is just a symbol. Sum{} is what it is. 0 is the sum of nothing. So “True” IS the conjunction of nothing. It’s meaning IS all{}. It is the truth of “no requirements”.
- billpg 3y agoI posted in a political thread once... "Re-joining the EU would give the UK all the benefits of EU membership as well as all the benefits of Brexit too."
- gizajob 3y agoTrue
- gizajob 3y agoThe present king of France is bald.
- ptx 3y agoDoes that work, though? If you're talking about a set of kings, then the set can be empty. But "the king" – isn't that more like Kotlin's single() method, which throws an exception if the number of elements is not 1?
- gizajob 3y agoIt's a Bertrand Russel joke, and an issue that caused him to want to fix and rebuild formal logic from top to bottom, to differentiate statements like that which aren't really part of reality from functionally identical statements that are part of reality.
- deleted 3y ago[deleted]
- rickboyce 3y agoI think the analysis is really interesting, but I suspect it’s quite possible that this behaviour is just a result of optimising the implementation than GVR taking sides in a 2,500 year old philosophical debate. Both implementations of all() and any() short-circuit by returning as soon as a fasly element in all or a truthy element in any is iterated over. The origin of these two functions seems to be this post: https://www.artima.com/forums/flat.jsp?forum=106&thread=98196 https://www.artima.com/forums/flat.jsp?forum=106&thread=9819... Guido makes no comment on empty iterables, but does comment on the final implementation needing to be efficient. It’s possible this behaviour is just the engineering trade off made for a slightly more efficient implementation. The initial commit of these two functions - https://github.com/python/cpython/commit/96229b191814556622b575fd320e822f918f355a?diff=unified https://github.com/python/cpython/commit/96229b191814556622b... - is exactly as Guido’s suggestion, but does include a test case for empty iterables for both functions so we know it wasn’t overlooked.
- justin_oaks 3y agoRegardless of whether you thing the return value should be True or False, this behavior violates the Principle of Least Astonishment [0] for a significant number of people. Such violations in software inevitably lead to bugs that could have been avoided. The real question in my mind isn't what the return value should be. The question is "How can this problem be wholly avoided?" Some have suggested requiring a default return value when the iterator argument is empty. Others have suggested throwing an error. Perhaps others will suggest the all() function shouldn't exist, although that may be throwing the baby out with the bathwater. [0] https://en.wikipedia.org/wiki/Principle_of_least_astonishment https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...
- H8crilA 3y agoWhat's an example realistic problem/piece of code that could be buggy because of this definition of all()?
- justincredible 3y ago[dead]
- kstrauser 3y agoI disagree. If lst = [True, True]; all(lst) is True is True, and lst = [True]; all(lst) is True is True, I'd be very surprised by lst = []; all(lst) is False Basically, all(lst) is the same as `not any(not item for item in lst)`. If we inverted the value of `all([])`, I'd argue that we'd also have to invert the value of `any([])`, which today evaluates as False. `any([]) is True` would be beyond bizarre to me.
- rain1 3y agoThe people that are astonished by this just need to learn why. It's not the function that is wrong, it's those people.
- gouggoug 3y agoI'm a bit confused by this: > “All stonemen are made of stone” is true by definition, but “no men are made of stone” is also true and seems to contradict it. I don't see how “no men are made of stone” contradicts “All stonemen are made of stone”. "stonemen" are not the same as "men". English isn't my first language so maybe I don't know what a stoneman is (and google failed me), but I assumed it is a statue?
- assbuttbuttass 3y agoI'm guessing, a stoneman means a man made out of stone
- Smaug123 3y agoThe originator of that quote was writing in the 12th century. The quote is cited without a source at https://en.wikipedia.org/wiki/Square_of_opposition https://en.wikipedia.org/wiki/Square_of_opposition , where the phrase is "Omnis homo qui lapis est" ("every man who is a stone"). I haven't dug any further than that. But the phrase literally is intended to indicate a contradiction.
- Jtsummers 3y agoA stoneman would be a man made of stone, not a stone shaped like a man. It comes down to a philosophy of logic issue. A universal quantifier ("for all x P(x)") is ambiguous when there are no x's. You can take it as false, true, or indeterminant, your system of logic will determine which interpretation should be used. In modern predicate logic, that statement is true if there are no x's. In syllogistic logic it's considered false because there's a second presumption which must be satisfied: That there are any x's to talk about.
- ptx 3y agoShouldn't this question fail at the parsing stage then, before it has even been asked? Q: All stonemen are ... A: ERROR: Undefined operation. Stonemen do not exist.
- 3y ago
- Waterluvian 3y agoI feel like I’d just make a poll and pick the least surprising option if there’s a clear winner. But maybe that’s why I’m not a language developer.
- shadowgovt 3y agoFTA: > But it is interesting how even extremely practical twenty-first century programming can get drawn into millennia old philosophical controversies, intentionally or not. This turns out to happen a lot. I can't find the source right now, but there was a good essay I read ages ago about how questions that are abstract and hand-waveable in day-to-day life become cornerstones of architecture rapidly in computer science and software engineering. The cow in the field epistemological puzzle [http://www.philosophical-investigations.org/2021/09/the-cow-in-field-and-riddle-of-what-do.html http://www.philosophical-investigations.org/2021/09/the-cow-...] maps directly to the nature of proving code is "correct" by testing (and any practicing coder has a story of false-positive or false-negative tests, as well as times they identified one of those by a "gut check" telling them "That result... doesn't feel right; I should investigate further"). Similarly, the philosophical question of "sameness" or "equality" ends up concretized over and over again in language design; there's a reason languages end up with so many ways to say 'equals', and it's because the underlying question of what it means for two things to be the same thing is legitimately philosophically complicated!
- earthboundkid 3y agoHere’s a real Gettier question from my actual life: In college, my future ex-wife rented a video from the video store called “Kama Sutra” on my card and returned it late. The late fee was sent to my parents’ house. My dad discreetly told me later that it was not a problem that we got a late fee, which means he read the letter and thinks we had watched a porno together and was trying to let me know and be cool about it. However, https://en.wikipedia.org/wiki/Kama_Sutra:_A_Tale_of_Love https://en.wikipedia.org/wiki/Kama_Sutra:_A_Tale_of_Love is a “historical erotic romance film” and not a porno. But my ex-wife and I did in fact see a different porno together. So then, does my dad know that we saw a porno together?
- feoren 3y agoHumans have trouble with this because our brains cannot let go of the context surrounding a question. For example, a logician may find it funny to walk up to a police officer and say "all of the hookers in my trunk are dead." That is technically true, even though there are no bodies in his trunk. But the brain of the police officer is awash with why someone would be talking about dead hookers at all. Surely something is going on! I would not expect that logician to have a great day. So we read things about bags with no marbles and bearded kings of France and pink goblins and we think someone is taking the piss out of us, because we can't let go of the context behind those statements. Why are we talking about goblins at all? All models are wrong. Some models are useful. If you're getting hung up on how it just doesn't make sense that "A -> B" is always true when A is false (which is really the same issue), you have to realize that it's not meant to be intuitive, it's meant to be useful. And the theory of predicate logic where ALL([]) == TRUE is much more useful than the one where it's FALSE or even NULL. It's more useful because TRUE is the identity element of the monoid AND and ALL is the unary set-aggregation of AND. There really cannot be any other choice if you want your theory to fit in with the rest of mathematics and logic, which a useful theory must. It's internally consistent, useful, and really does make deep sense if you are able to let go of context-laden real-world examples. You should not rely on English sentences making sense to be a good metric of whether a model is useful or not. Consider: Dogs must be carried on escalators. You don't have a dog. Are you allowed on the escalator? Of course you are. This is, in fact, a perfect example of why Your_Dogs.All(is_carried) must be TRUE if Your_Dogs is empty. Hard hats must be worn in work areas. You don't have a hard hat. Are you allowed in the work area? No! How can you tell the difference between these two situations? Only from context. Yet you can see how easy it would be to form the 2nd sentence as an (erroneous) example of "Enforce(HardHats.All(are_worn))", but it's not that. It's more like "Enforce(People.Where(in_work_areas).All(have_hard_hat_on))" -- if there is someone in a work area, then they must have a hard hat on. But if there's nobody in the work area, no rule is being broken! Again we actually see ANY([]) having to be true here. When you come up with weird-sounding examples where you're sure All([]) must be False, you're just poisoning your intuition with unhelpful context.
- msie 3y agoI'm studying this comment many times. I do have a hang up with A->B being true when A is false.
- michaelteter 3y agoThe problem isn't with all([]) -> True, the problem is the if [] -> False. [] exists. It happens to be empty, but it is neither a False nor a None. Therefore it should be a True if applying truthiness to it. IMO, any expression which does not result in an actual False or None should be judged as True. - edit - On second thought, all([]) -> True is also a poor choice, same in Ruby. The idea of judging an empty collection as having all items being any value is flawed, since there are no items to measure. It is on par with 1 / 0. This is fun: in both Ruby and Python... [].all? -> true all([]) -> True [].any? -> false any([]) -> False So both languages agree that all elements of any empty collection are true, but if you ask them if any of the elements are true, they deny it. So they are all true while also not having any true elements.
- x3n0ph3n3 3y agoThat's exactly how Ruby behaves.
- michaelteter 3y agoRuby and Python agree on the all/any functions, but they disagree on the if. And in the "if", I think the Ruby result is better.
- earthboundkid 3y agoJavaScript thinks empty arrays are true and it’s annoying because you have to write if (a.length) instead of if (a).
- kstrauser 3y agoI disagree. An empty string is False. Any empty set is False. An empty dict is False. Basically, in Python emptiness implies falseness. This has practical benefits: users = database.fetch_users() if not users: print("Didn't find anyone.") and name = input() if not name: print("You didn't enter a name.") Of course you could work around those like `if len(users) == 0` or `if not len(users)` or `if name != ""`, but each of those is uglier. `if not users` translates very nicely to English: "if there are not any users...". I'm glad Python defined `bool(list)` that way.
- mrkeen 3y agoI like `all = foldr and True` as others have pointed out. But I think I have a more convincing example of why it can't be the other way around: all (>5) [6,7,8] all (>5) ([6,7,8] ++ []) (all (>5) [6,7,8]) && (all (>5) []) (True && False) False
- waffletower 3y agoI miss using the Midje testing library for Clojure, as it has the 'truthy' and 'falsey' functions. It reduced these variously bivalent and trivalent conditions into binary in a way that would do Stephen Colbert proud (https://web.archive.org/web/20150121223555/http://www.merriam-webster.com/info/06words.htm https://web.archive.org/web/20150121223555/http://www.merria...) Of course you or I can add such to what ever language we are using that supports actual functions -- or smash some abstraction of truthiness into those that don't.
- ptx 3y ago> in the new logic, you can’t soundly argue that “all dogs are mammals; all mammals have fur; therefore, all dogs have fur” because one person shaving their dog suddenly makes “all mammals have fur” untrue. Isn't this just a problem with an unclear definition of "having fur"? Is the article saying that the old logic would hand-wave this problem away because it's about "universals and essences"?
- earthboundkid 3y agoYes. “All dogs have fur” is untrue. “Dogs have fur” is true. The former is modern; the latter is classical.
- devmunchies 3y agoI actually used this in my F# code yesterday. The forall function does the same and it was exactly what I needed. https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-listmodule.html#forall https://fsharp.github.io/fsharp-core-docs/reference/fsharp-c...
- adameasterling 3y agoI had to deal with this problem in our product, which has a visual programming language. I opted to throw an exception if, for whatever reason, "all()" receives an empty list! I had forgotten I'd done that. There's no explanation for it in the code. As I sit here justifying my own reasoning, though, it sort of makes sense. For ordinary people (for whom this product is supposed to be for), I figure if they put in nothing, that was probably just a mistake.
- cheald 3y agoIt helps to think in terms of `any` first: any([], predicate) => false This is plainly obvious, because it is illogical to say "the predicate is true for at least one member of the empty set". If we can agree on that, then all([], predicate) must be true, because the complement of all(list, predicate) is any(list, predicate') The naive assumption is that the complement of all(list, p) is all(list, p'), but this is demonstrably false, because in the case of an empty list: all([], e => e) and all([], e => !e) would both return the same value. > [[], [true], [false]].map(s => s.every(e => e) == !s.every(e => !e)) [ false, true, true ] Instead, its proper complement is any(list, p'), which means that all(list, p) = !any(list, p') > [[], [true], [false]].map(s => s.every(e => e) == !s.some(e => !e)) [ true, true, true ] So, for all([], p) to be false, any([], p') would have to be true, which makes even less sense than all([], p) => true.
- the-alchemist 3y agoClojure does the same thing: > clj Clojure 1.11.1 user=> (every? true? []) true user=> (every? false? []) true user=> (every? true? nil) true user=> Also: user=> (true? []) false In English, an empty list is `false`, but any predicate on an empty list is `true`. So I believe the logic is the same as Python. Logic article on this in Wikipedia: https://en.wikipedia.org/wiki/Vacuous_truth https://en.wikipedia.org/wiki/Vacuous_truth
- NoToP 3y agoA man goes into court not sure how he got there or what he's accused of. The judge starts saying the opening formalities. "If and only if every member of the jury is convinced you are guilty then this court will convict you." The man looks around. "Your honor, there are no members of the jury." The judge slams the gavel hard. "Guilty". That's the trivial case.
- nwah1 3y agoThe codebase of Apache Kafka must be littered with this.
- deleted 3y ago[deleted]
- junon 3y agoI remember explaining this rather simply, the same question actually. Look at the implementation. def all(it): for v in it: if not v: return False return True If there are no items, it returns True. def any(it): for v in it: if v: return True return False If there are no items, it returns False. There's no need for fancy mathematical or "marbles in a bag" explanations here. Just look at the code.
- earthboundkid 3y ago(2020)
- earthboundkid 3y agoIncidentally I wrote the post. Please don’t AMA. It’s all in the post. No further questions.
- nighthawk454 3y agoclaims on empty sets can be vacuously true. "All elephants in my pocket are made of dark matter". Sure, all _zero_ of them, so it's 'technically correct'. https://en.wikipedia.org/wiki/Vacuous_truth?useskin=vector https://en.wikipedia.org/wiki/Vacuous_truth?useskin=vector
- aftbit 3y agoSorry for the meta comment, but ?useskin=vector is game changing. I thought I had just lost the old readable Wikipedia.
- Akronymus 3y agoNot the gp: I have redirector with a regex url rewriter that gets me the skin on all wiki pages. (it is somewhat complex, due to anchors and such) Writing this comment so that I can find it again later so I can post it here, if yoou want to have it.
- nighthawk454 3y agoThere's actually 5 skins! If you sign in you can also set your preferred skin in preferences. Check them out below: https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=vector https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=vector https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=vector-2022 https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=vector-... https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=monobook https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=monoboo... https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=timeless https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=timeles... https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=minerva https://en.wikipedia.org/wiki/Wikipedia:Skin?useskin=minerva
- nobody0 3y agoThe empty set is vacuously true for any properties with elements.
- pharmakom 3y agoIn logic class, these were axiomatically equivalent for all x. P(x) not (exists x. not P(x))
- nurettin 3y agoBecause of this http://en.m.wikipedia.org/wiki/Vacuous_truth http://en.m.wikipedia.org/wiki/Vacuous_truth
- kazinator 3y agoIf you have some set S and predicate P(x) is true for every x in S, ∀x∈S:P(x), then you can partition the set into pieces S₁ ∪ S₂ ∪ ... u Sₙ. such that ∀x∈S₁:P(x) ∧ ∀x∈S₂:P(x) ∧ ... ∧ ∀x∈Sₙ:P(x). If the quantified predicate were to be false for an empty set, then the above breaks if any of the partitions are empty. A property can then be true when quantified over a set such that it's not true over subsets, which is inconsistent. A similar problem occurs with products. We can use Lisp: (* 2 3 4) -> 24 We would like to be partition that into partial products. Here, we have a partition of length 1: (* (* 2 3) (* 4)) -> 24 So we want (* N) -> N. And empty partitions: (* (*) (* 2 3) (*) (* 4)) -> 24 For that to work we need: (*) -> 1
- kaleidawave 3y agoCase of the “Vacuous truth”