1
$\begingroup$

In computer science, some functions are said to be "pure", meaning that (amongst other things) they can only use variables defined in their parameters. In a mathematical context, are all functions pure or is something like this allowed?: $$ a = 3 \\ f(x) = x + a $$ If this is allowed, then does this mean "variables" (e.g. $a$ in this case) is immutable? (also is this true even if math functions are pure?)

$\endgroup$
2
  • $\begingroup$ That's allowed provided $a$ remains $3$ within the scope that $f$ is defined. If you know Haskell, this is similar to saying "f x = let a=3 in x+a", in which case f will never see another value of "a", even if you go on to define "a" globally elsewhere. $\endgroup$
    – Ian
    Jan 6 at 17:25
  • $\begingroup$ Mathematical functions are as "pure" as pure can be. They've always been pure. It was the compsci people who confused this concept by letting functions have "side effects" - when a function stops acting as a lookup table. $\endgroup$
    – user867070
    Jan 6 at 17:34
2
$\begingroup$

Well, variables in math are not really containers as in programming. You might think of them as rather being constants, in the computer science sense, but they are called variables because their meaning can vary, e.g. $x \in \mathbb{R}$ can be any real number, but it's just one (or rather, it's all of them), it doesn't change overtime.

In a function, the argument varies depending on what is actually "passed" to the function, to use a CS term, but again, it doesn't change at all. Not the function, nor anything else changes what a specific letter refers to after being defined (as in "Let $n \in \mathbb{N}$" or as in "$f : \mathbb{R} \to \mathbb{R}$" which also defines what $x$ in "$f(x) = x+3$" is).

Now, every other variables than the arguments of a function or the unknowns of an equation are called parameters. In your example, $a$ is a parameter.

So, yes, you could say that functions in math are 'pure', but that is a CS term afaik.

$\endgroup$
0
$\begingroup$

You can write $$ f(x)=x+a $$ but then it is assumed that $a$ is some constant. If $a$ is a variable, then you should write $$ f(x,a)=x+a $$ instead.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.