5 ms·
assumption that ‘add’ is a function of two arguments is wrong if not deliberately misleading
by keymone 7y ago
assumption that ‘add’ is a function of two arguments is wrong if not deliberately misleading
- leethargo 7y agoWhy? In math, that's actually how operators are defined.
- keymone 7y agoBecause you’re limiting expressiveness of the function by applying unnecessary restrictions
- joppy 7y agoSure, so prove that add(x1, x2, ..., xn) is equal to any permutation of the numbers x1, ..., xn. You still need to prove that add(x, add(y, z)) = add(x, y, z). So now you have two things to prove...
- keymone 7y ago“Sure” what? I don’t need to prove any of that to use variadic ‘add’ function. Pretending like it’s function of just two args is just a cherry-picked example to make operators look nicer.
- joppy 7y agoSurely you still want to know about properties like add(x, add(y, z)) = add(x, y, z), to take advantage of the variadic functions. I was just pointing out that making something variadic doesn’t mean you have less work to do correctness-wise - it’s strictly a quality-of-life improvement for using the operator.
- keymone 7y agoThe difference between function add and operator plus are solely in the resulting parsing tree. Chaining pluses together is the same as adding arguments to add. Proving correctness of operators and stuff is just not something I do when I write python code.
- moefh 7y ago> Chaining pluses together is the same as adding arguments to add No, chaining multiple pluses together in Python (as in most widely-used programming languages) is exactly the same as doing multiple two-argument additions, and is not the same as doing a multiple-argument addition. You can see that in this Python code: n = 2.0 ** 53 print("(1)", n + 1 + 1) print("(2)", (n + 1) + 1) print("(3)", n + (1 + 1)) the line (1) has the same result as line (2), but is different from (3). That's because addition of floating point numbers is only defined for two numbers and is not associative, so `n+1+1` is parsed as `(n+1)+1` and not some magical three-argument floating point addition, which would give the same result as (3).
- keymone 7y agoirrelevant edge cases chaining pluses is the same as adding arguments to add watch: 1+1+1 == add(1,1,1) == 3 you dont have to be so pedantic about implementation quirks, it's not going to become important in your lifetime, unless you consider this comment thread important, in which case, congrats.
- AnimalMuppet 7y agoDepends on your language. In Lisp, + takes any number of arguments. In C++, it takes exactly two. (I'm presuming that by 'add', you mean '+'. If not, then 'add' takes however many arguments it is defined as a function to take, and that still is language- or library-dependent.) (And if you refer to pure math, then add or + is only a function of more than two arguments if it associates, which is dependent on the argument type.)
- keymone 7y agono, by `add` i mean exactly the function `add`, not + operator. he cherry picked the example to show how operators are "better", he's wrong. in practice sum of a sequence is more important concept than it's special case - sum of two arguments.
- AnimalMuppet 7y agoWhat function 'add'? 'add' in some computer language? If so, which language? Or 'add' in mathematics? If so, what is the difference between 'add' and '+'?
- keymone 7y ago`add` is just another manipulation on guido's part. `sum` is the name of the concept.
- AnimalMuppet 7y agoOne more time: Are you talking about a specific feature in a language, or are you talking about mathematics?
- keymone 7y agoa concept in programming
- 7y ago