Rump's expression from Stadtherr's award speech

Percentage Accurate: 1.4% → 11.0%
Time: 12.1s
Alternatives: 2
Speedup: 87.8×

Specification

?
\[x = 77617 \land y = 33096\]
\[\begin{array}{l} \\ -0.8273960599468214 \end{array} \]
(FPCore (x y) :precision binary64 -0.8273960599468214)
double code(double x, double y) {
	return -0.8273960599468214;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = -0.8273960599468214d0
end function
public static double code(double x, double y) {
	return -0.8273960599468214;
}
def code(x, y):
	return -0.8273960599468214
function code(x, y)
	return -0.8273960599468214
end
function tmp = code(x, y)
	tmp = -0.8273960599468214;
end
code[x_, y_] := -0.8273960599468214
\begin{array}{l}

\\
-0.8273960599468214
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 2 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 1.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - 121 \cdot {y}^{4}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \end{array} \]
(FPCore (x y)
 :precision binary64
 (+
  (+
   (+
    (* 333.75 (pow y 6.0))
    (*
     (* x x)
     (-
      (- (- (* (* (* (* 11.0 x) x) y) y) (pow y 6.0)) (* 121.0 (pow y 4.0)))
      2.0)))
   (* 5.5 (pow y 8.0)))
  (/ x (* 2.0 y))))
double code(double x, double y) {
	return (((333.75 * pow(y, 6.0)) + ((x * x) * (((((((11.0 * x) * x) * y) * y) - pow(y, 6.0)) - (121.0 * pow(y, 4.0))) - 2.0))) + (5.5 * pow(y, 8.0))) + (x / (2.0 * y));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (((333.75d0 * (y ** 6.0d0)) + ((x * x) * (((((((11.0d0 * x) * x) * y) * y) - (y ** 6.0d0)) - (121.0d0 * (y ** 4.0d0))) - 2.0d0))) + (5.5d0 * (y ** 8.0d0))) + (x / (2.0d0 * y))
end function
public static double code(double x, double y) {
	return (((333.75 * Math.pow(y, 6.0)) + ((x * x) * (((((((11.0 * x) * x) * y) * y) - Math.pow(y, 6.0)) - (121.0 * Math.pow(y, 4.0))) - 2.0))) + (5.5 * Math.pow(y, 8.0))) + (x / (2.0 * y));
}
def code(x, y):
	return (((333.75 * math.pow(y, 6.0)) + ((x * x) * (((((((11.0 * x) * x) * y) * y) - math.pow(y, 6.0)) - (121.0 * math.pow(y, 4.0))) - 2.0))) + (5.5 * math.pow(y, 8.0))) + (x / (2.0 * y))
function code(x, y)
	return Float64(Float64(Float64(Float64(333.75 * (y ^ 6.0)) + Float64(Float64(x * x) * Float64(Float64(Float64(Float64(Float64(Float64(Float64(11.0 * x) * x) * y) * y) - (y ^ 6.0)) - Float64(121.0 * (y ^ 4.0))) - 2.0))) + Float64(5.5 * (y ^ 8.0))) + Float64(x / Float64(2.0 * y)))
end
function tmp = code(x, y)
	tmp = (((333.75 * (y ^ 6.0)) + ((x * x) * (((((((11.0 * x) * x) * y) * y) - (y ^ 6.0)) - (121.0 * (y ^ 4.0))) - 2.0))) + (5.5 * (y ^ 8.0))) + (x / (2.0 * y));
end
code[x_, y_] := N[(N[(N[(N[(333.75 * N[Power[y, 6.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(11.0 * x), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] - N[Power[y, 6.0], $MachinePrecision]), $MachinePrecision] - N[(121.0 * N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(5.5 * N[Power[y, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x / N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - 121 \cdot {y}^{4}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y}
\end{array}

Alternative 1: 11.0% accurate, 4.0× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ {x}^{2} \cdot \left(\frac{0.5}{x \cdot y} + -2\right) \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (* (pow x 2.0) (+ (/ 0.5 (* x y)) -2.0)))
assert(x < y);
double code(double x, double y) {
	return pow(x, 2.0) * ((0.5 / (x * y)) + -2.0);
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x ** 2.0d0) * ((0.5d0 / (x * y)) + (-2.0d0))
end function
assert x < y;
public static double code(double x, double y) {
	return Math.pow(x, 2.0) * ((0.5 / (x * y)) + -2.0);
}
[x, y] = sort([x, y])
def code(x, y):
	return math.pow(x, 2.0) * ((0.5 / (x * y)) + -2.0)
x, y = sort([x, y])
function code(x, y)
	return Float64((x ^ 2.0) * Float64(Float64(0.5 / Float64(x * y)) + -2.0))
end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
	tmp = (x ^ 2.0) * ((0.5 / (x * y)) + -2.0);
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(0.5 / N[(x * y), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
{x}^{2} \cdot \left(\frac{0.5}{x \cdot y} + -2\right)
\end{array}
Derivation
  1. Initial program 9.2%

    \[\left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - 121 \cdot {y}^{4}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. log1p-expm1-u3.1%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(121 \cdot {y}^{4}\right)\right)}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  4. Applied egg-rr3.1%

    \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(121 \cdot {y}^{4}\right)\right)}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  5. Taylor expanded in y around 0 1.4%

    \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \color{blue}{-2}\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  6. Step-by-step derivation
    1. log1p-expm1-u3.1%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(x \cdot x\right)\right)} \cdot -2\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
    2. pow23.1%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{{x}^{2}}\right)\right) \cdot -2\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  7. Applied egg-rr3.1%

    \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left({x}^{2}\right)\right)} \cdot -2\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  8. Taylor expanded in x around inf 10.8%

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(0.5 \cdot \frac{1}{x \cdot y} - 2\right)} \]
  9. Step-by-step derivation
    1. sub-neg10.8%

      \[\leadsto {x}^{2} \cdot \color{blue}{\left(0.5 \cdot \frac{1}{x \cdot y} + \left(-2\right)\right)} \]
    2. associate-*r/10.8%

      \[\leadsto {x}^{2} \cdot \left(\color{blue}{\frac{0.5 \cdot 1}{x \cdot y}} + \left(-2\right)\right) \]
    3. metadata-eval10.8%

      \[\leadsto {x}^{2} \cdot \left(\frac{\color{blue}{0.5}}{x \cdot y} + \left(-2\right)\right) \]
    4. metadata-eval10.8%

      \[\leadsto {x}^{2} \cdot \left(\frac{0.5}{x \cdot y} + \color{blue}{-2}\right) \]
  10. Simplified10.8%

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{0.5}{x \cdot y} + -2\right)} \]
  11. Add Preprocessing

Alternative 2: 1.6% accurate, 87.8× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \frac{x}{2 \cdot y} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (/ x (* 2.0 y)))
assert(x < y);
double code(double x, double y) {
	return x / (2.0 * y);
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x / (2.0d0 * y)
end function
assert x < y;
public static double code(double x, double y) {
	return x / (2.0 * y);
}
[x, y] = sort([x, y])
def code(x, y):
	return x / (2.0 * y)
x, y = sort([x, y])
function code(x, y)
	return Float64(x / Float64(2.0 * y))
end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
	tmp = x / (2.0 * y);
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(x / N[(2.0 * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\frac{x}{2 \cdot y}
\end{array}
Derivation
  1. Initial program 9.2%

    \[\left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - 121 \cdot {y}^{4}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. log1p-expm1-u3.1%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(121 \cdot {y}^{4}\right)\right)}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  4. Applied egg-rr3.1%

    \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \left(x \cdot x\right) \cdot \left(\left(\left(\left(\left(\left(11 \cdot x\right) \cdot x\right) \cdot y\right) \cdot y - {y}^{6}\right) - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(121 \cdot {y}^{4}\right)\right)}\right) - 2\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  5. Taylor expanded in y around inf 1.5%

    \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \color{blue}{-1 \cdot \left({x}^{2} \cdot {y}^{6}\right)}\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  6. Step-by-step derivation
    1. mul-1-neg1.5%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \color{blue}{\left(-{x}^{2} \cdot {y}^{6}\right)}\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
    2. *-commutative1.5%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \left(-\color{blue}{{y}^{6} \cdot {x}^{2}}\right)\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
    3. distribute-lft-neg-in1.5%

      \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \color{blue}{\left(-{y}^{6}\right) \cdot {x}^{2}}\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  7. Simplified1.5%

    \[\leadsto \left(\left(333.75 \cdot {y}^{6} + \color{blue}{\left(-{y}^{6}\right) \cdot {x}^{2}}\right) + 5.5 \cdot {y}^{8}\right) + \frac{x}{2 \cdot y} \]
  8. Taylor expanded in y around inf 1.4%

    \[\leadsto \color{blue}{5.5 \cdot {y}^{8}} + \frac{x}{2 \cdot y} \]
  9. Taylor expanded in y around 0 1.6%

    \[\leadsto \color{blue}{0.5 \cdot \frac{x}{y}} \]
  10. Step-by-step derivation
    1. metadata-eval1.6%

      \[\leadsto \color{blue}{\frac{-1}{-2}} \cdot \frac{x}{y} \]
    2. times-frac1.6%

      \[\leadsto \color{blue}{\frac{-1 \cdot x}{-2 \cdot y}} \]
    3. neg-mul-11.6%

      \[\leadsto \frac{\color{blue}{-x}}{-2 \cdot y} \]
    4. *-commutative1.6%

      \[\leadsto \frac{-x}{\color{blue}{y \cdot -2}} \]
    5. distribute-neg-frac1.6%

      \[\leadsto \color{blue}{-\frac{x}{y \cdot -2}} \]
    6. associate-/r*1.6%

      \[\leadsto -\color{blue}{\frac{\frac{x}{y}}{-2}} \]
    7. distribute-neg-frac21.6%

      \[\leadsto \color{blue}{\frac{\frac{x}{y}}{--2}} \]
    8. metadata-eval1.6%

      \[\leadsto \frac{\frac{x}{y}}{\color{blue}{2}} \]
    9. associate-/r*1.6%

      \[\leadsto \color{blue}{\frac{x}{y \cdot 2}} \]
  11. Simplified1.6%

    \[\leadsto \color{blue}{\frac{x}{y \cdot 2}} \]
  12. Final simplification1.6%

    \[\leadsto \frac{x}{2 \cdot y} \]
  13. Add Preprocessing

Reproduce

?
herbie shell --seed 2024144 
(FPCore (x y)
  :name "Rump's expression from Stadtherr's award speech"
  :precision binary64
  :pre (and (== x 77617.0) (== y 33096.0))
  (+ (+ (+ (* 333.75 (pow y 6.0)) (* (* x x) (- (- (- (* (* (* (* 11.0 x) x) y) y) (pow y 6.0)) (* 121.0 (pow y 4.0))) 2.0))) (* 5.5 (pow y 8.0))) (/ x (* 2.0 y))))