Radioactive exchange between two surfaces

Percentage Accurate: 86.4% → 95.9%
Time: 10.6s
Alternatives: 4
Speedup: 12.0×

Specification

?
\[\begin{array}{l} \\ {x}^{4} - {y}^{4} \end{array} \]
(FPCore (x y) :precision binary64 (- (pow x 4.0) (pow y 4.0)))
double code(double x, double y) {
	return pow(x, 4.0) - pow(y, 4.0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x ** 4.0d0) - (y ** 4.0d0)
end function
public static double code(double x, double y) {
	return Math.pow(x, 4.0) - Math.pow(y, 4.0);
}
def code(x, y):
	return math.pow(x, 4.0) - math.pow(y, 4.0)
function code(x, y)
	return Float64((x ^ 4.0) - (y ^ 4.0))
end
function tmp = code(x, y)
	tmp = (x ^ 4.0) - (y ^ 4.0);
end
code[x_, y_] := N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{x}^{4} - {y}^{4}
\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 4 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: 86.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ {x}^{4} - {y}^{4} \end{array} \]
(FPCore (x y) :precision binary64 (- (pow x 4.0) (pow y 4.0)))
double code(double x, double y) {
	return pow(x, 4.0) - pow(y, 4.0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x ** 4.0d0) - (y ** 4.0d0)
end function
public static double code(double x, double y) {
	return Math.pow(x, 4.0) - Math.pow(y, 4.0);
}
def code(x, y):
	return math.pow(x, 4.0) - math.pow(y, 4.0)
function code(x, y)
	return Float64((x ^ 4.0) - (y ^ 4.0))
end
function tmp = code(x, y)
	tmp = (x ^ 4.0) - (y ^ 4.0);
end
code[x_, y_] := N[(N[Power[x, 4.0], $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{x}^{4} - {y}^{4}
\end{array}

Alternative 1: 95.9% accurate, 1.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 10^{+136}:\\ \;\;\;\;{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x - y \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 1e+136)
   (* (pow (hypot x y) 2.0) (- (* x x) (* y y)))
   (* (* y y) (* y (- y)))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1e+136) {
		tmp = pow(hypot(x, y), 2.0) * ((x * x) - (y * y));
	} else {
		tmp = (y * y) * (y * -y);
	}
	return tmp;
}
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 1e+136) {
		tmp = Math.pow(Math.hypot(x, y), 2.0) * ((x * x) - (y * y));
	} else {
		tmp = (y * y) * (y * -y);
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1e+136:
		tmp = math.pow(math.hypot(x, y), 2.0) * ((x * x) - (y * y))
	else:
		tmp = (y * y) * (y * -y)
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1e+136)
		tmp = Float64((hypot(x, y) ^ 2.0) * Float64(Float64(x * x) - Float64(y * y)));
	else
		tmp = Float64(Float64(y * y) * Float64(y * Float64(-y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 1e+136)
		tmp = (hypot(x, y) ^ 2.0) * ((x * x) - (y * y));
	else
		tmp = (y * y) * (y * -y);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 1e+136], N[(N[Power[N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * y), $MachinePrecision] * N[(y * (-y)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{+136}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x - y \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.00000000000000006e136

    1. Initial program 93.6%

      \[{x}^{4} - {y}^{4} \]
    2. Step-by-step derivation
      1. sqr-pow93.5%

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow93.3%

        \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      3. difference-of-squares97.0%

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

        \[\leadsto \left({x}^{\color{blue}{2}} + {y}^{\left(\frac{4}{2}\right)}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      5. pow297.0%

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

        \[\leadsto \left(x \cdot x + {y}^{\color{blue}{2}}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      7. pow297.0%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow297.0%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
      11. pow297.0%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr97.0%

      \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]
    4. Step-by-step derivation
      1. sub-neg97.0%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(x \cdot x + \left(-y \cdot y\right)\right)} \]
      2. distribute-lft-in64.6%

        \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x\right) + \left(x \cdot x + y \cdot y\right) \cdot \left(-y \cdot y\right)} \]
      3. add-sqr-sqrt64.6%

        \[\leadsto \color{blue}{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right)} \cdot \left(x \cdot x\right) + \left(x \cdot x + y \cdot y\right) \cdot \left(-y \cdot y\right) \]
      4. pow264.6%

        \[\leadsto \color{blue}{{\left(\sqrt{x \cdot x + y \cdot y}\right)}^{2}} \cdot \left(x \cdot x\right) + \left(x \cdot x + y \cdot y\right) \cdot \left(-y \cdot y\right) \]
      5. hypot-def64.6%

        \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left(x, y\right)\right)}}^{2} \cdot \left(x \cdot x\right) + \left(x \cdot x + y \cdot y\right) \cdot \left(-y \cdot y\right) \]
      6. add-sqr-sqrt64.5%

        \[\leadsto {\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x\right) + \color{blue}{\left(\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}\right)} \cdot \left(-y \cdot y\right) \]
      7. pow264.5%

        \[\leadsto {\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x\right) + \color{blue}{{\left(\sqrt{x \cdot x + y \cdot y}\right)}^{2}} \cdot \left(-y \cdot y\right) \]
      8. hypot-def64.5%

        \[\leadsto {\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x\right) + {\color{blue}{\left(\mathsf{hypot}\left(x, y\right)\right)}}^{2} \cdot \left(-y \cdot y\right) \]
    5. Applied egg-rr64.5%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x\right) + {\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(-y \cdot y\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-out97.0%

        \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x + \left(-y \cdot y\right)\right)} \]
      2. sub-neg97.0%

        \[\leadsto {\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \color{blue}{\left(x \cdot x - y \cdot y\right)} \]
    7. Simplified97.0%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x - y \cdot y\right)} \]

    if 1.00000000000000006e136 < y

    1. Initial program 59.5%

      \[{x}^{4} - {y}^{4} \]
    2. Step-by-step derivation
      1. sqr-pow59.5%

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow59.5%

        \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      3. difference-of-squares67.6%

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

        \[\leadsto \left({x}^{\color{blue}{2}} + {y}^{\left(\frac{4}{2}\right)}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      5. pow267.6%

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

        \[\leadsto \left(x \cdot x + {y}^{\color{blue}{2}}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      7. pow267.6%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow267.6%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
      11. pow267.6%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr67.6%

      \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]
    4. Taylor expanded in x around 0 83.8%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(-1 \cdot \color{blue}{\left(y \cdot y\right)}\right) \]
      2. neg-mul-183.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(-y \cdot y\right)} \]
      3. distribute-rgt-neg-in83.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)} \]
    6. Simplified83.8%

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)} \]
    7. Taylor expanded in x around 0 83.8%

      \[\leadsto \color{blue}{{y}^{2}} \cdot \left(y \cdot \left(-y\right)\right) \]
    8. Step-by-step derivation
      1. unpow283.8%

        \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot \left(y \cdot \left(-y\right)\right) \]
    9. Simplified83.8%

      \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot \left(y \cdot \left(-y\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 10^{+136}:\\ \;\;\;\;{\left(\mathsf{hypot}\left(x, y\right)\right)}^{2} \cdot \left(x \cdot x - y \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \end{array} \]

Alternative 2: 96.0% accurate, 12.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 5.7 \cdot 10^{+138}:\\ \;\;\;\;\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= y 5.7e+138)
   (* (- (* x x) (* y y)) (+ (* x x) (* y y)))
   (* (* y y) (* y (- y)))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 5.7e+138) {
		tmp = ((x * x) - (y * y)) * ((x * x) + (y * y));
	} else {
		tmp = (y * y) * (y * -y);
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= 5.7d+138) then
        tmp = ((x * x) - (y * y)) * ((x * x) + (y * y))
    else
        tmp = (y * y) * (y * -y)
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (y <= 5.7e+138) {
		tmp = ((x * x) - (y * y)) * ((x * x) + (y * y));
	} else {
		tmp = (y * y) * (y * -y);
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 5.7e+138:
		tmp = ((x * x) - (y * y)) * ((x * x) + (y * y))
	else:
		tmp = (y * y) * (y * -y)
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 5.7e+138)
		tmp = Float64(Float64(Float64(x * x) - Float64(y * y)) * Float64(Float64(x * x) + Float64(y * y)));
	else
		tmp = Float64(Float64(y * y) * Float64(y * Float64(-y)));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= 5.7e+138)
		tmp = ((x * x) - (y * y)) * ((x * x) + (y * y));
	else
		tmp = (y * y) * (y * -y);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[y, 5.7e+138], N[(N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * y), $MachinePrecision] * N[(y * (-y)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.7 \cdot 10^{+138}:\\
\;\;\;\;\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 5.69999999999999986e138

    1. Initial program 93.6%

      \[{x}^{4} - {y}^{4} \]
    2. Step-by-step derivation
      1. sqr-pow93.5%

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow93.3%

        \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      3. difference-of-squares97.0%

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

        \[\leadsto \left({x}^{\color{blue}{2}} + {y}^{\left(\frac{4}{2}\right)}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      5. pow297.0%

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

        \[\leadsto \left(x \cdot x + {y}^{\color{blue}{2}}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      7. pow297.0%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow297.0%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
      11. pow297.0%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr97.0%

      \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]

    if 5.69999999999999986e138 < y

    1. Initial program 59.5%

      \[{x}^{4} - {y}^{4} \]
    2. Step-by-step derivation
      1. sqr-pow59.5%

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow59.5%

        \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      3. difference-of-squares67.6%

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

        \[\leadsto \left({x}^{\color{blue}{2}} + {y}^{\left(\frac{4}{2}\right)}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      5. pow267.6%

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

        \[\leadsto \left(x \cdot x + {y}^{\color{blue}{2}}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      7. pow267.6%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow267.6%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
      11. pow267.6%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr67.6%

      \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]
    4. Taylor expanded in x around 0 83.8%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(-1 \cdot \color{blue}{\left(y \cdot y\right)}\right) \]
      2. neg-mul-183.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(-y \cdot y\right)} \]
      3. distribute-rgt-neg-in83.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)} \]
    6. Simplified83.8%

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)} \]
    7. Taylor expanded in x around 0 83.8%

      \[\leadsto \color{blue}{{y}^{2}} \cdot \left(y \cdot \left(-y\right)\right) \]
    8. Step-by-step derivation
      1. unpow283.8%

        \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot \left(y \cdot \left(-y\right)\right) \]
    9. Simplified83.8%

      \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot \left(y \cdot \left(-y\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 5.7 \cdot 10^{+138}:\\ \;\;\;\;\left(x \cdot x - y \cdot y\right) \cdot \left(x \cdot x + y \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \end{array} \]

Alternative 3: 69.2% accurate, 20.4× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 2.45 \cdot 10^{-46}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(x \cdot x\right)\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (<= x 2.45e-46) (* (* y y) (* y (- y))) (* (* x x) (* x x))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (x <= 2.45e-46) {
		tmp = (y * y) * (y * -y);
	} else {
		tmp = (x * x) * (x * x);
	}
	return tmp;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= 2.45d-46) then
        tmp = (y * y) * (y * -y)
    else
        tmp = (x * x) * (x * x)
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if (x <= 2.45e-46) {
		tmp = (y * y) * (y * -y);
	} else {
		tmp = (x * x) * (x * x);
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if x <= 2.45e-46:
		tmp = (y * y) * (y * -y)
	else:
		tmp = (x * x) * (x * x)
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (x <= 2.45e-46)
		tmp = Float64(Float64(y * y) * Float64(y * Float64(-y)));
	else
		tmp = Float64(Float64(x * x) * Float64(x * x));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= 2.45e-46)
		tmp = (y * y) * (y * -y);
	else
		tmp = (x * x) * (x * x);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[LessEqual[x, 2.45e-46], N[(N[(y * y), $MachinePrecision] * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.45 \cdot 10^{-46}:\\
\;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(x \cdot x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 2.45e-46

    1. Initial program 91.3%

      \[{x}^{4} - {y}^{4} \]
    2. Step-by-step derivation
      1. sqr-pow91.2%

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow91.0%

        \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      3. difference-of-squares94.8%

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

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

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

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

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

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

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
      11. pow294.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr94.8%

      \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]
    4. Taylor expanded in x around 0 68.8%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(-1 \cdot \color{blue}{\left(y \cdot y\right)}\right) \]
      2. neg-mul-168.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(-y \cdot y\right)} \]
      3. distribute-rgt-neg-in68.8%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)} \]
    6. Simplified68.8%

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(y \cdot \left(-y\right)\right)} \]
    7. Taylor expanded in x around 0 69.2%

      \[\leadsto \color{blue}{{y}^{2}} \cdot \left(y \cdot \left(-y\right)\right) \]
    8. Step-by-step derivation
      1. unpow269.2%

        \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot \left(y \cdot \left(-y\right)\right) \]
    9. Simplified69.2%

      \[\leadsto \color{blue}{\left(y \cdot y\right)} \cdot \left(y \cdot \left(-y\right)\right) \]

    if 2.45e-46 < x

    1. Initial program 81.9%

      \[{x}^{4} - {y}^{4} \]
    2. Step-by-step derivation
      1. sqr-pow81.7%

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow81.7%

        \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      3. difference-of-squares87.3%

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

        \[\leadsto \left({x}^{\color{blue}{2}} + {y}^{\left(\frac{4}{2}\right)}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      5. pow287.3%

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

        \[\leadsto \left(x \cdot x + {y}^{\color{blue}{2}}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      7. pow287.3%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow287.3%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
      11. pow287.3%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr87.3%

      \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]
    4. Taylor expanded in x around inf 76.2%

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{{x}^{2}} \]
    5. Step-by-step derivation
      1. unpow276.2%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
    6. Simplified76.2%

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
    7. Taylor expanded in x around inf 76.3%

      \[\leadsto \color{blue}{{x}^{2}} \cdot \left(x \cdot x\right) \]
    8. Step-by-step derivation
      1. unpow276.3%

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(x \cdot x\right) \]
    9. Simplified76.3%

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(x \cdot x\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.45 \cdot 10^{-46}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(x \cdot x\right)\\ \end{array} \]

Alternative 4: 57.3% accurate, 29.3× speedup?

\[\begin{array}{l} y = |y|\\ \\ \left(x \cdot x\right) \cdot \left(x \cdot x\right) \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y) :precision binary64 (* (* x x) (* x x)))
y = abs(y);
double code(double x, double y) {
	return (x * x) * (x * x);
}
NOTE: y should be positive before calling this function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * x) * (x * x)
end function
y = Math.abs(y);
public static double code(double x, double y) {
	return (x * x) * (x * x);
}
y = abs(y)
def code(x, y):
	return (x * x) * (x * x)
y = abs(y)
function code(x, y)
	return Float64(Float64(x * x) * Float64(x * x))
end
y = abs(y)
function tmp = code(x, y)
	tmp = (x * x) * (x * x);
end
NOTE: y should be positive before calling this function
code[x_, y_] := N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\left(x \cdot x\right) \cdot \left(x \cdot x\right)
\end{array}
Derivation
  1. Initial program 88.7%

    \[{x}^{4} - {y}^{4} \]
  2. Step-by-step derivation
    1. sqr-pow88.6%

      \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
    2. sqr-pow88.4%

      \[\leadsto {x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)} - \color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
    3. difference-of-squares92.7%

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

      \[\leadsto \left({x}^{\color{blue}{2}} + {y}^{\left(\frac{4}{2}\right)}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
    5. pow292.7%

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

      \[\leadsto \left(x \cdot x + {y}^{\color{blue}{2}}\right) \cdot \left({x}^{\left(\frac{4}{2}\right)} - {y}^{\left(\frac{4}{2}\right)}\right) \]
    7. pow292.7%

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

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
    9. pow292.7%

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

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - {y}^{\color{blue}{2}}\right) \]
    11. pow292.7%

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
  3. Applied egg-rr92.7%

    \[\leadsto \color{blue}{\left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - y \cdot y\right)} \]
  4. Taylor expanded in x around inf 58.8%

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

      \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
  6. Simplified58.8%

    \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \color{blue}{\left(x \cdot x\right)} \]
  7. Taylor expanded in x around inf 59.1%

    \[\leadsto \color{blue}{{x}^{2}} \cdot \left(x \cdot x\right) \]
  8. Step-by-step derivation
    1. unpow259.1%

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(x \cdot x\right) \]
  9. Simplified59.1%

    \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(x \cdot x\right) \]
  10. Final simplification59.1%

    \[\leadsto \left(x \cdot x\right) \cdot \left(x \cdot x\right) \]

Reproduce

?
herbie shell --seed 2023278 
(FPCore (x y)
  :name "Radioactive exchange between two surfaces"
  :precision binary64
  (- (pow x 4.0) (pow y 4.0)))