While doing a math question on piecewise functions, I came across an answer which seemed wrong to me but I could not explain it mathematically.
The question states (summarised):
A lottery dealer makes 6 cents on each ticket sold. If the lottery dealer sells more than 25,000 tickets, she gets an extra 2 cents for every ticket after the 25,000th ticket. Express her profits as a function of the number of sold tickets.
The correct (or expected) answer was the piecewise function: $$ f(x) = \begin{cases} 6x, & \text{when } 0 \le x \le 25000 \\ 8x-50000, & \text{when } x \gt 25000 \end{cases} $$
However, another answer I saw was:
$$ \text{let } x \text{ be the number of tickets sold } \le 25000 \\ \text{let } z \text{ be the number of tickets sold } \gt 25000 \\ f(x) = 6x + 8z $$
I found this answer intuitively incorrect. To me, all mathematical functions are pure (a concept from programming). In particular, all values in a function should not be determined by anything other than it's inputs.
In this case, $f(x)$ is defined with an extra $z$ which is not given as an input.
But this is a concept from programming, not mathematics. After reading the definition of a function on Wikipedia, I don't see anything that explicitly says that additional variables are allowed or not allowed in function definitions.
Is there something I missed in the definition or is the second answer acceptable?
EDIT
To clarify and amplify the problem, here is another example. Let's say I want to define a function that adds $x$ to the current hour (in 24 hours). For example,
$$ \text{let } t \text{ be the current 24 hour time, } 0 \le t \le 23, t \in \mathbb{Z} \\ f(x) = t + x $$
Similar as before, this introduces a variable $t$ that is not given as an input to $f(x)$.
My question is this: What part of the mathematical definition of a function disallows this?
I'm going to address this part of your question, since the other answers have addressed the other parts:
Well, some might object that the notion of "the current time" doesn't have any mathematical meaning. But let's set that objection aside.
The definition you've given is, in fact, the definition of a function, but it's the definition of a pure function. Specifically, given the time and place that I'm writing this, the function that you've defined is $f(x) = x + 17$. An hour from now, the definition will refer to a different function instead: namely, the function $f(x) = x + 18$.
All right, but let me give another attempt at defining an impure function. This time, I'm going to write something that really is an invalid definition:
$$g(x) = x + (\text{the current year, as of the time that this function is being evaluated})$$
I've attempted to define one function, $g$, where $g(10)$ is $2028$ right now, but will change to be $2029$ next year, and so on.
So, what part of the mathematical definition of a function disallows this? Well, here's one standard definition of a function:
Given sets $X$ and $Y$, a function $X \to Y$ consists of a subset $s$ of $X \times Y$, such that each element of $X$ appears exactly once as the left-hand component of an element of $s$.
To a software developer, a mathematical function isn't like a subroutine (or "function") at all. Instead, a mathematical function is essentially a mere list of input and output values (and each valid input must be listed exactly once). And there simply is no way for a mere list of input and output values to be an "impure function", because once you've determined what the function is, you've determined all of its outputs, too.