6 ms·
Zero to the Power of Zero
- kens 6y agoI consider the debate over 0^0 to be easily solved with type signatures. If you consider the function pow(float, float), 0^0 should be undefined. If you consider the function pow(float, int), then 0^0 should be 1. The problem is that people view these two different power functions as a single function.
- lidHanteyk 6y agoWhich languages are you thinking of? I just checked Haskell and Python, and they both give 1 for both integer and floating-point exponentiation.
- karpierz 6y agoI wouldn't say it's the type of numbers, rather whether they're constant. (Const 0)^(var 0) is 0. (Var 0)^(const 0) is 1. (Const 0)^(const 0) is undefined. (Var 0)^(var 0) is defined based on the functions that define those variables.
- kadoban 6y agoShouldn't the int version be enbedded in the float version? Shouldn't they agree for equal values?
- Koshkin 6y agoBut isn’t the following expected to be true? pow(0.0f, 0.0f) == (float)pow(0, 0) If one is defined then so should the other. (At least, for developers’ benefit.)
- gizmo686 6y agoSpeaking as a mathamatician, and replacing "float" with "real number": We really like like to pretend that the integers are a subset of the real numbers. As such, we really like to pretend that the function pow : real X int -> real is a restriction of the function pow : real X real -> real. Speaking as a programmer, I really expect the effect of casting between numeric types is only precision. If pow(0f,0) != pow (0f, 0f), then you break both of these assumptions.
- murkle 6y agoGood referenced reasoning about it here https://www.nctm.org/tmf/dr.math/faq/faq.0.to.0.power.html https://www.nctm.org/tmf/dr.math/faq/faq.0.to.0.power.html
- Koshkin 6y agoFrom the programmer’s standpoint, the reasoning goes like this. In C++, the initial value you pass to std::accumulate depends on the operator. For addition, 0 is the “natural” choice. For multiplication, it is 1. So, if you raise a number to some power using this function, you implicitly or explicitly start with 1. Followed by accumulation of the zero number of 0s this leaves you with 1.
- ken 6y agoC++ pow() is a function of doubles, not ints. You can't define it in terms of std::accumulate.
- Koshkin 6y agoThe integers are a subset of the reals, so the rule still should hold.
- nine_k 6y agoThis logic is broken. If you take 1 as the initial value, and run the operation n ≥ 1 times, the initial value is used at least once. But if you run the operation zero times, the initial value is never used, so the result is undefined.
- deleted 6y ago[deleted]
- badrabbit 6y agoHow is nothing multiplied nothing times 1? I feel dumb asking this,but, why is it not 0 or NaN. 2^4 == 2222 == 16 0^0 == 0000 == 0 Why is it not that simple?
- gizmo686 6y agoWhy should the answer be 0? We have an intuition that 0 is the identity element for addition, so it makes sense to treat it as the starting point for many things. However, when we look at multiplication, 0 looks very different. Instead of preserving the other value, as it does with addition, multiplying by 0 changes the other value in an information destroying way (e.g if you know that x * 0 = 0, you have no idea what x is). This property of 0 is so distinct from the other numbers, that when we consider the integers (or reals, or complex numbers) as a structure that only has multiplication, but not addition, we typically exclude 0 from consideration. Since (discrete) exponentiation is a multiplicative process, it makes sense to consider it in terms of the integers under multiplication; and so excluding 0. When we consider integers under multiplication, we notice that 1 has the same properties that 0 had under addition. Namely, 1 * x = x for all x. Given this, it makes sense to treat 1 as the "empty" element, the same way you want to do with 0 in additive contexts.
- badrabbit 6y agoThank you for the explanation, the reasoning sort of makes sense but I still can't wrap my head around how on the left side of the equation there is nothing(0) on the right hand there is something. Something cannot come out of nothing when considering natural phenomena in reality.
- Koshkin 6y agoIn the context of multiplication, raising a number to the zero-th power is a NOP (no operation, or nothing). So, for any x, x^0 = 1 times (x^0) = 1 times nothing = 1.
- gizmo686 6y agoMultiplying by a number raised to the zero-th power is a NOP. This comes up frequently in the context of polynomials, where the constant term is often expressed as the x^0 term. E.g in f(x) = 3x^2 + 2x^1 + 1x^0 , we would like to have f(0)=0. In many cases this is important because we express polynomials as a sum: f(x) = sum (n from 0 to 2) { (n+1)x^n }, so having x^0 behave reasonably at x=0 allows us to avoid needed to special case the n=0 term.
- _nalply 6y agoAfter reading this I think a mathematically sound approach is to leave 0^0 undefined. Then because of practicality define 0^0 = 1 accepting some weirdness around 0^0 (limits to 0^0 not being 1). With "practicality" I mean for mathematicians the convenience for some definitions, perhaps like this: "While we know that 0^0 is undefined, we proceed with the definition 0^0 = 1, because in our domain the disconuity doesn't matter [...]". This could be a footnote. For programmers just let the pow() function(s) return 1. It's a pity (or in a more positive way: spicy) that nature doesn't hold the principle of the least surprise. It's something we can't or shouldn't fix.
- lidHanteyk 6y agoI think that you are overcomplicating the underlying reasoning. Consider: How many functions are there from the empty set to the empty set? One, right?
- Tainnor 6y agoThis is one of the things most mathematicians usually don't care much about. Unlike programming (or automated theorem proving), mathematics can tolerate slight ambiguities that end up not mattering for the argument at hand, because it's ultimately read by people who understand the context.