4 ms·
Sure, 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).
by joppy 7y ago
Sure, 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.