The function f is defined on the integers in the range 0..100 by the rule:
analysis/step.function New
New entry, edited from material collected for the archive and not yet in a released version.
Problem
The function f is defined on the integers in the range 0..100 by the rule: f(n) = 100 if 80 <= n <= 100, f(n) = n if 0 <= n <= 79. (In other words, students who score 80% or over are deemed to have learnt the material, and awarded 100%.) How do you define f with a single formula, using only the standard arithmetical operations, together with max(x,y) and min(x,y)? What is the least number of operators needed? Suppose instead f is to be defined on all real numbers x in the range 0 <= x <= 100, with f(x) = x if 0 <= x < 80 and f(x) = 100 if 80 <= x <= 100. Can such a function be constructed using only min, max, +, -, * and /?
Show solution
So far, we got 2 solutions using 6 operators: x + (100-x) * max(0, min(1, x-79)) (Charles Bryant) 1 2 3 4 5 6 and min(n,80) + min( max(n-79,0) , 1 ) * 20 (Erik Buitenhuis [Editor: spelled "Buitnhuis" in the original] (me)) 1 2 3 4 5 6 who can do better? -- Erik Buitenhuis <erikb@xs4all.nl> I can do it with four, provided the range of the function is restricted to the integers: f(x) = min(min(x,20*(x-75)),100) with two mins, one multiplication, and one subtraction. The first min yields x for x < 79 and 20*(x-75), which is >= 100, for x >= 80; the second min then gives x for x < 79 and 100 for x >= 80. -- Mark Thornquist I don't think so: x=0 f(x) = -1500 -- Erik Buitenhuis <erikb@xs4all.nl> Oops. I realized after I sent this in that the inner "min" should be a "max". It works then. -- Mark Thornquist Not quite. The original problem required f(79) = 79, and you have f(79) = 80. Graphing f(x) vs. x, you need a line with a slope of at least 21, not 20, to get from (79, 79) to (80, 100). The following function clearly works: f(x) = min(max(x, 100 * (x - 79)), 100). If you really want to "connect the dots" (which is not necessary---you only need to hit the correct values of f(x) at integer values of x), you might try f(x) = min(max(x, 21 * x - 1580), 100). Still four operations. Is it possible to construct a correct function in fewer operations? I don't think so, but it ought to be provable. ObPuzzle: Suppose the requirement were for a function defined on all real numbers x (not just integers) in the range 0 <= x <= 100, as follows: f(x) = x if 0 <= x < 80 f(x) = 100 if 80 <= x <= 100 Can such a function be constructed using only the operators min, max, +, -, *, and / ? If so, how? Suppose the function need merely be defined on the real numbers that can be stored in an ordinary 64-bit "real" variable on a typical modern computer? -- David A. Karr <karr@world.std.com> [ Editor: no answer to the real-number version was found in the collected postings. ]