6 ms·
sum([1,1]) = 1 + 1 = 2 sum([1]) = 1 sum([]) = 0 0 + n = n + 0 = n Zero is the unit with respect to addition, so when we add together a list of no number
by sullyj3 7y ago
sum([1,1]) = 1 + 1 = 2
sum([1]) = 1
sum([]) = 0
0 + n = n + 0 = n
Zero is the unit with respect to addition, so when we add together a list of no numbers, we ought to get back zero.
you can `from math import prod` in python3.8
prod([2,2]) = 2*2 = 2
prod([2]) = 2
prod([]) = 1
1 * n = n * 1 = n
The same way, one is the unit with respect to multiplication. So, multiplying no numbers together gets you one.
all([True,True]) = True && True = True
all([True]) = True
all([]) = True
True && x = x && True = x
You get the idea.
- abathologist 7y agoI like the algebraic point of view as a way of spotting essential patterns like this :) The essential missing step here is to point out that conjunction is multiplicative, not additive, and this is why `all` gives the unit under conjunction, rather than the unit under disjunction. Corresponding to `sum` is `any`, which gives the unit under disjunction for the empty list, since disjunction is additive. That said, I do think there is something to the perspective presented in the article. Something which is not accidental to the algebraization of logic...
- wyager 7y agoThere's no need to think in terms of rings here ((+,*) and (|,&) together) - Monoids are precisely the most powerful algebraic object we need to consider here (only one binary operation at a time). All of these binary operations form a monoid.
- senthil_rajasek 7y agoHmmm... An identity is something that does not change the left operand a * i = a 0 for + and 1 for x pass this test. But for Boolean && neither True nor False pass the identity test because, ( True as identity) False && True = False True && True = True ( False as identity) False && False False True && False = False Perhaps there is more to it....
- furyofantares 7y agoI think your post indeed shows that a && True = a
- senthil_rajasek 7y agoit makes sense if you look at it as a && True = a. Thanks.
- LgWoodenBadger 7y agoI'm not clear how true doesn't work as the identity for AND.
- deleted 7y ago[deleted]
- chias 7y agoGP is suggesting that in this setting, the set is Booleans, the operation is &&, and the identity is True. So taking your calculation of a * i = a the operation (denoted * above) is &&, and the identity (denoted i above) is True. Lets see how it holds out for all possible values of a: a && True =?= a let a := True True && True =?= True correct! a && True =?= a let a := False False && True =?= False correct!
- globular-toast 7y agoI was going to write unit in my comment, but unit is the wrong word. The word unit applies only to multiplication. In the natural numbers there is only one unit: 1. Some other fields have multiple units. The integers have 1 and -1 and the rationals contain infinitely many units (every element is a unit). The correct term is an identity.
- TheAsprngHacker 7y agoI was going to comment this, but you got here before me. So, I would just like to ramble about type theory and constructive logic a bit. According to the Curry-Howard correspondence and the BHK interpretation of logic, there is a syntactic correspondence between types and logical formulas and between terms and proofs. Here, the unit type corresponds with truth because it is trivially inhabited with a single inhabitant. The product type A * B is interpreted as logical conjunction because you need a proof of A and a proof of B to inhabit it. The unit type (true) is the identity of the product type (and). Unit * A = A * Unit = A from an isomorphism perspective. From the category theory point of view, a Cartesian monoidal category is a monoidal category where the tensor product is the categorical product and the unit object is the terminal object. It's no coincidence that the terminal object is written as 1. So, an n-ary sequence of propositions connected by ANDs is like an n-ary tuple type, and an empty sequence of propositions connected by ANDs is like the nullary tuple type, or in other words the trivially inhabited unit type.
- nixpulvis 7y ago⊤ ∨ ⊥ ? ɪ, don't know.
- cochne 7y agoYou could also look at it like this: We want this general property to hold: sum([ sum(x[0:n]), sum(x[n:]) ]) == sum(x) define sum([]) (n = 0) so that it holds It works the same for prod, all, and any, and gives a hint as to what the answer should be if there were things like union(sets) (the empty set) or intersection(sets) (the universe, or union of all sets)
- earthboundkid 7y agoOkay, but intuitively, I also want the property !(all(x==1) and all(x!=1)) to hold. Now what?
- scott_s 7y agoThat should be: prod([2,2]) = 2*2 = 4 Right?
- adverbly 7y agoI hope so! Edit: could have picked better examples too imo... Id have used 1 + 0 = 1 and 2 × 1 = 2... basically you add 1s for free when multiplying, 0s for free when adding, and trues for free when "Alling".
- cesarb 7y agoAn alternative way of viewing this is: find the recursive definition of that function, and think of its base case. For sum, it is something like sum([Head:Tail]) = Head + sum(Tail), which works only if sum([]) is 0. For prod, we have prod([Head:Tail]) = Head * prod(Tail), which again works only if prod([]) is 1. And for all, we have all([Head:Tail]) = Head && all(Tail), which again works only if all([]) is True.
- pedro1976 7y agoIn mathematics in binary operations this element is called neutral element or idendity element. https://en.wikipedia.org/wiki/Identity_element?wprov=sfla1 https://en.wikipedia.org/wiki/Identity_element?wprov=sfla1