Radioactive exchange between two surfaces

Percentage Accurate: 86.5% → 96.8%
Time: 4.1s
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.5% 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: 96.8% accurate, 12.0× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.28 \cdot 10^{+154}:\\ \;\;\;\;\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 1.28e+154)
   (* (+ (* 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 <= 1.28e+154) {
		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 <= 1.28d+154) 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 <= 1.28e+154) {
		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 <= 1.28e+154:
		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 <= 1.28e+154)
		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 <= 1.28e+154)
		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, 1.28e+154], 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 1.28 \cdot 10^{+154}:\\
\;\;\;\;\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 < 1.2800000000000001e154

    1. Initial program 89.7%

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

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow89.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-squares95.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-eval95.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. pow295.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-eval95.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. pow295.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-eval95.3%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow295.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-eval95.3%

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

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

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

    if 1.2800000000000001e154 < y

    1. Initial program 48.5%

      \[{x}^{4} - {y}^{4} \]
    2. Taylor expanded in x around 0 78.8%

      \[\leadsto \color{blue}{-1 \cdot {y}^{4}} \]
    3. Step-by-step derivation
      1. neg-mul-178.8%

        \[\leadsto \color{blue}{-{y}^{4}} \]
    4. Simplified78.8%

      \[\leadsto \color{blue}{-{y}^{4}} \]
    5. Step-by-step derivation
      1. sqr-pow78.8%

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

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

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

        \[\leadsto -\left(y \cdot y\right) \cdot {y}^{\color{blue}{2}} \]
      5. pow278.8%

        \[\leadsto -\left(y \cdot y\right) \cdot \color{blue}{\left(y \cdot y\right)} \]
    6. Applied egg-rr78.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.28 \cdot 10^{+154}:\\ \;\;\;\;\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 2: 63.2% accurate, 14.4× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 7.8 \cdot 10^{+148} \lor \neg \left(x \leq 1.95 \cdot 10^{+164}\right) \land x \leq 1.4 \cdot 10^{+175}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(y \cdot y\right)\\ \end{array} \end{array} \]
NOTE: y should be positive before calling this function
(FPCore (x y)
 :precision binary64
 (if (or (<= x 7.8e+148) (and (not (<= x 1.95e+164)) (<= x 1.4e+175)))
   (* (* y y) (* y (- y)))
   (* (* x x) (* y y))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if ((x <= 7.8e+148) || (!(x <= 1.95e+164) && (x <= 1.4e+175))) {
		tmp = (y * y) * (y * -y);
	} else {
		tmp = (x * x) * (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 ((x <= 7.8d+148) .or. (.not. (x <= 1.95d+164)) .and. (x <= 1.4d+175)) then
        tmp = (y * y) * (y * -y)
    else
        tmp = (x * x) * (y * y)
    end if
    code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y) {
	double tmp;
	if ((x <= 7.8e+148) || (!(x <= 1.95e+164) && (x <= 1.4e+175))) {
		tmp = (y * y) * (y * -y);
	} else {
		tmp = (x * x) * (y * y);
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if (x <= 7.8e+148) or (not (x <= 1.95e+164) and (x <= 1.4e+175)):
		tmp = (y * y) * (y * -y)
	else:
		tmp = (x * x) * (y * y)
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if ((x <= 7.8e+148) || (!(x <= 1.95e+164) && (x <= 1.4e+175)))
		tmp = Float64(Float64(y * y) * Float64(y * Float64(-y)));
	else
		tmp = Float64(Float64(x * x) * Float64(y * y));
	end
	return tmp
end
y = abs(y)
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= 7.8e+148) || (~((x <= 1.95e+164)) && (x <= 1.4e+175)))
		tmp = (y * y) * (y * -y);
	else
		tmp = (x * x) * (y * y);
	end
	tmp_2 = tmp;
end
NOTE: y should be positive before calling this function
code[x_, y_] := If[Or[LessEqual[x, 7.8e+148], And[N[Not[LessEqual[x, 1.95e+164]], $MachinePrecision], LessEqual[x, 1.4e+175]]], N[(N[(y * y), $MachinePrecision] * N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.8 \cdot 10^{+148} \lor \neg \left(x \leq 1.95 \cdot 10^{+164}\right) \land x \leq 1.4 \cdot 10^{+175}:\\
\;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 7.80000000000000004e148 or 1.94999999999999993e164 < x < 1.4000000000000001e175

    1. Initial program 85.7%

      \[{x}^{4} - {y}^{4} \]
    2. Taylor expanded in x around 0 64.7%

      \[\leadsto \color{blue}{-1 \cdot {y}^{4}} \]
    3. Step-by-step derivation
      1. neg-mul-164.7%

        \[\leadsto \color{blue}{-{y}^{4}} \]
    4. Simplified64.7%

      \[\leadsto \color{blue}{-{y}^{4}} \]
    5. Step-by-step derivation
      1. sqr-pow64.6%

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

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

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

        \[\leadsto -\left(y \cdot y\right) \cdot {y}^{\color{blue}{2}} \]
      5. pow264.6%

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

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

    if 7.80000000000000004e148 < x < 1.94999999999999993e164 or 1.4000000000000001e175 < x

    1. Initial program 75.0%

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

        \[\leadsto \color{blue}{{x}^{\left(\frac{4}{2}\right)} \cdot {x}^{\left(\frac{4}{2}\right)}} - {y}^{4} \]
      2. sqr-pow75.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-squares81.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-eval81.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. pow281.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-eval81.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. pow281.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-eval81.3%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow281.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-eval81.3%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr81.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 90.6%

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

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

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

      \[\leadsto \color{blue}{{x}^{2} \cdot {y}^{2}} \]
    8. Step-by-step derivation
      1. unpow268.8%

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

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(y \cdot y\right)} \]
      3. *-commutative68.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7.8 \cdot 10^{+148} \lor \neg \left(x \leq 1.95 \cdot 10^{+164}\right) \land x \leq 1.4 \cdot 10^{+175}:\\ \;\;\;\;\left(y \cdot y\right) \cdot \left(y \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(y \cdot y\right)\\ \end{array} \]

Alternative 3: 82.3% accurate, 15.7× speedup?

\[\begin{array}{l} y = |y|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 1.15 \cdot 10^{-12}:\\ \;\;\;\;\left(x \cdot x\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 1.15e-12) (* (* x x) (+ (* x x) (* y y))) (* (* y y) (* y (- y)))))
y = abs(y);
double code(double x, double y) {
	double tmp;
	if (y <= 1.15e-12) {
		tmp = (x * x) * ((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 <= 1.15d-12) then
        tmp = (x * x) * ((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 <= 1.15e-12) {
		tmp = (x * x) * ((x * x) + (y * y));
	} else {
		tmp = (y * y) * (y * -y);
	}
	return tmp;
}
y = abs(y)
def code(x, y):
	tmp = 0
	if y <= 1.15e-12:
		tmp = (x * x) * ((x * x) + (y * y))
	else:
		tmp = (y * y) * (y * -y)
	return tmp
y = abs(y)
function code(x, y)
	tmp = 0.0
	if (y <= 1.15e-12)
		tmp = Float64(Float64(x * x) * 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 <= 1.15e-12)
		tmp = (x * x) * ((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, 1.15e-12], N[(N[(x * x), $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 1.15 \cdot 10^{-12}:\\
\;\;\;\;\left(x \cdot x\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 < 1.14999999999999995e-12

    1. Initial program 89.3%

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

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

        \[\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.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-eval94.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. pow294.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-eval94.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. pow294.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-eval94.7%

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left({x}^{\color{blue}{2}} - {y}^{\left(\frac{4}{2}\right)}\right) \]
      9. pow294.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-eval94.7%

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

        \[\leadsto \left(x \cdot x + y \cdot y\right) \cdot \left(x \cdot x - \color{blue}{y \cdot y}\right) \]
    3. Applied egg-rr94.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 68.6%

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

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

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

    if 1.14999999999999995e-12 < y

    1. Initial program 68.3%

      \[{x}^{4} - {y}^{4} \]
    2. Taylor expanded in x around 0 75.1%

      \[\leadsto \color{blue}{-1 \cdot {y}^{4}} \]
    3. Step-by-step derivation
      1. neg-mul-175.1%

        \[\leadsto \color{blue}{-{y}^{4}} \]
    4. Simplified75.1%

      \[\leadsto \color{blue}{-{y}^{4}} \]
    5. Step-by-step derivation
      1. sqr-pow74.9%

        \[\leadsto -\color{blue}{{y}^{\left(\frac{4}{2}\right)} \cdot {y}^{\left(\frac{4}{2}\right)}} \]
      2. metadata-eval74.9%

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

        \[\leadsto -\color{blue}{\left(y \cdot y\right)} \cdot {y}^{\left(\frac{4}{2}\right)} \]
      4. metadata-eval74.9%

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

        \[\leadsto -\left(y \cdot y\right) \cdot \color{blue}{\left(y \cdot y\right)} \]
    6. Applied egg-rr74.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.15 \cdot 10^{-12}:\\ \;\;\;\;\left(x \cdot x\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 4: 32.4% accurate, 29.3× speedup?

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

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

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

      \[\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-squares91.2%

      \[\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-eval91.2%

      \[\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. pow291.2%

      \[\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-eval91.2%

      \[\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. pow291.2%

      \[\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-eval91.2%

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

      \[\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-eval91.2%

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

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

    \[\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.5%

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

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

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

    \[\leadsto \color{blue}{{x}^{2} \cdot {y}^{2}} \]
  8. Step-by-step derivation
    1. unpow236.5%

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot {y}^{2} \]
    2. unpow236.5%

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(y \cdot y\right)} \]
    3. *-commutative36.5%

      \[\leadsto \color{blue}{\left(y \cdot y\right) \cdot \left(x \cdot x\right)} \]
  9. Simplified36.5%

    \[\leadsto \color{blue}{\left(y \cdot y\right) \cdot \left(x \cdot x\right)} \]
  10. Final simplification36.5%

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

Reproduce

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