5 ms·
Except it isn't. Unless you learn imperative programming before you learn basic algebra, the first definition of a variable you encounter is that of an immutabl
by chousuke 13y ago
Except it isn't. Unless you learn imperative programming before you learn basic algebra, the first definition of a variable you encounter is that of an immutable one.
- Shorel 13y agoActually an algebraic variable is named that way because you can change it every time you do the exercise. So you don't change it during one exercise, but you can and certainly will change it when you change the exercise to another one with the same principle.
- chongli 13y agoRight, but you're not mutating it in the middle of your calculation.
- Gravityloss 13y agoIf you have a sum for example sum_{x=1}^{10}x^2, x definitely changes quite many times during your calculation.
- chongli 13y agoNo, that's an example of recursion. With recursion you aren't mutating the variable, you're shadowing its definition. This is a subtle, but important, distinction.
- Gravityloss 13y agoRecursion? The "function" is not calling itself at all. I'm quite sure that is not recursion, neither in the mathematical nor computer science sense.
- chongli 13y agoRecursion is how you implement a sum without mutation (an imperative loop is how you'd implement it with mutation). You've merely given me the function written in a declarative notation.
- Gravityloss 13y agoI think we are talking about different things. For example, if you integrate x^2 dx from x=0 to 10, x changes continuously. It's clear that x is not fixed to any particular value.
- chongli 13y agoYeah, you're talking about the mathematical definition of a bound variable. Functional programming languages use this whenever you define a function: foo x = x * 2 Every time you call foo, x is bound to a new value (but only within the scope of foo). This is not the same as mutating some memory location associated with the name x.
- chousuke 13y agox does not mutate at all. x is simply a placeholder for the values in the series of additions that your expression expands to, that is, 1² + 2² + 3² + ... + 10². Or stepwise, to 1² + sum_{x=2}^{10}x² etc. all three expressions are equivalent, and no mutation of x occurs anywhere The series of additions can also be infinite, in which case it would be quite difficult to expand fully, but that doesn't prevent you from doing mathematics with it.
- ams6110 13y agoAn algebraic "variable" is perhaps better called an "unknown"
- tikhonj 13y agoThat behaves just like a function: the values of the variables change each time you call the function but not within. When you do a new exercise, it's really a bunch of new variables with the same name--variables cannot affect each other between exercises! That's not analogous at all to mutation.