Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A

Percentage Accurate: 68.9% → 99.9%
Time: 12.4s
Alternatives: 4
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z):
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0))
end
function tmp = code(x, y, z)
	tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\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: 68.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z):
	return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0))
end
function tmp = code(x, y, z)
	tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}

Alternative 1: 99.9% accurate, 1.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ 0.5 \cdot \left(y + \left(x\_m + z\right) \cdot \frac{x\_m - z}{y}\right) \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z)
 :precision binary64
 (* 0.5 (+ y (* (+ x_m z) (/ (- x_m z) y)))))
x_m = fabs(x);
double code(double x_m, double y, double z) {
	return 0.5 * (y + ((x_m + z) * ((x_m - z) / y)));
}
x_m = abs(x)
real(8) function code(x_m, y, z)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.5d0 * (y + ((x_m + z) * ((x_m - z) / y)))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
	return 0.5 * (y + ((x_m + z) * ((x_m - z) / y)));
}
x_m = math.fabs(x)
def code(x_m, y, z):
	return 0.5 * (y + ((x_m + z) * ((x_m - z) / y)))
x_m = abs(x)
function code(x_m, y, z)
	return Float64(0.5 * Float64(y + Float64(Float64(x_m + z) * Float64(Float64(x_m - z) / y))))
end
x_m = abs(x);
function tmp = code(x_m, y, z)
	tmp = 0.5 * (y + ((x_m + z) * ((x_m - z) / y)));
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_] := N[(0.5 * N[(y + N[(N[(x$95$m + z), $MachinePrecision] * N[(N[(x$95$m - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
0.5 \cdot \left(y + \left(x\_m + z\right) \cdot \frac{x\_m - z}{y}\right)
\end{array}
Derivation
  1. Initial program 68.8%

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Step-by-step derivation
    1. remove-double-neg68.8%

      \[\leadsto \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\color{blue}{-\left(-y \cdot 2\right)}} \]
    2. distribute-lft-neg-out68.8%

      \[\leadsto \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{-\color{blue}{\left(-y\right) \cdot 2}} \]
    3. distribute-frac-neg268.8%

      \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
    4. distribute-frac-neg68.8%

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

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}}{\left(-y\right) \cdot 2} \]
    6. distribute-lft-neg-out68.8%

      \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{-y \cdot 2}} \]
    7. *-commutative68.8%

      \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{-\color{blue}{2 \cdot y}} \]
    8. distribute-lft-neg-in68.8%

      \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{\left(-2\right) \cdot y}} \]
    9. times-frac68.8%

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

      \[\leadsto \frac{-1}{\color{blue}{-2}} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
    11. metadata-eval68.8%

      \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
    12. associate--l+68.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
    13. fma-define71.6%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
  3. Simplified71.6%

    \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 82.3%

    \[\leadsto 0.5 \cdot \color{blue}{\left(\left(y + \frac{{x}^{2}}{y}\right) - \frac{{z}^{2}}{y}\right)} \]
  6. Step-by-step derivation
    1. associate--l+82.3%

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

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

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

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

      \[\leadsto 0.5 \cdot \left(y + \frac{x \cdot x - \color{blue}{z \cdot z}}{y}\right) \]
    3. difference-of-squares90.2%

      \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{y}\right) \]
  9. Applied egg-rr90.2%

    \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{y}\right) \]
  10. Step-by-step derivation
    1. associate-/l*99.9%

      \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(x + z\right) \cdot \frac{x - z}{y}}\right) \]
  11. Applied egg-rr99.9%

    \[\leadsto 0.5 \cdot \left(y + \color{blue}{\left(x + z\right) \cdot \frac{x - z}{y}}\right) \]
  12. Final simplification99.9%

    \[\leadsto 0.5 \cdot \left(y + \left(x + z\right) \cdot \frac{x - z}{y}\right) \]
  13. Add Preprocessing

Alternative 2: 74.2% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;y \leq 1.8 \cdot 10^{+72} \lor \neg \left(y \leq 7.5 \cdot 10^{+87}\right) \land y \leq 2.9 \cdot 10^{+109}:\\ \;\;\;\;\left(x\_m + z\right) \cdot \left(0.5 \cdot \frac{x\_m - z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z)
 :precision binary64
 (if (or (<= y 1.8e+72) (and (not (<= y 7.5e+87)) (<= y 2.9e+109)))
   (* (+ x_m z) (* 0.5 (/ (- x_m z) y)))
   (* 0.5 y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
	double tmp;
	if ((y <= 1.8e+72) || (!(y <= 7.5e+87) && (y <= 2.9e+109))) {
		tmp = (x_m + z) * (0.5 * ((x_m - z) / y));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= 1.8d+72) .or. (.not. (y <= 7.5d+87)) .and. (y <= 2.9d+109)) then
        tmp = (x_m + z) * (0.5d0 * ((x_m - z) / y))
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
	double tmp;
	if ((y <= 1.8e+72) || (!(y <= 7.5e+87) && (y <= 2.9e+109))) {
		tmp = (x_m + z) * (0.5 * ((x_m - z) / y));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y, z):
	tmp = 0
	if (y <= 1.8e+72) or (not (y <= 7.5e+87) and (y <= 2.9e+109)):
		tmp = (x_m + z) * (0.5 * ((x_m - z) / y))
	else:
		tmp = 0.5 * y
	return tmp
x_m = abs(x)
function code(x_m, y, z)
	tmp = 0.0
	if ((y <= 1.8e+72) || (!(y <= 7.5e+87) && (y <= 2.9e+109)))
		tmp = Float64(Float64(x_m + z) * Float64(0.5 * Float64(Float64(x_m - z) / y)));
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y, z)
	tmp = 0.0;
	if ((y <= 1.8e+72) || (~((y <= 7.5e+87)) && (y <= 2.9e+109)))
		tmp = (x_m + z) * (0.5 * ((x_m - z) / y));
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_] := If[Or[LessEqual[y, 1.8e+72], And[N[Not[LessEqual[y, 7.5e+87]], $MachinePrecision], LessEqual[y, 2.9e+109]]], N[(N[(x$95$m + z), $MachinePrecision] * N[(0.5 * N[(N[(x$95$m - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.8 \cdot 10^{+72} \lor \neg \left(y \leq 7.5 \cdot 10^{+87}\right) \land y \leq 2.9 \cdot 10^{+109}:\\
\;\;\;\;\left(x\_m + z\right) \cdot \left(0.5 \cdot \frac{x\_m - z}{y}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.80000000000000017e72 or 7.50000000000000014e87 < y < 2.9e109

    1. Initial program 76.7%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 79.7%

      \[\leadsto \color{blue}{y \cdot \left(0.5 + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{{y}^{2}}\right)} \]
    4. Step-by-step derivation
      1. *-commutative79.7%

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \frac{x \cdot x - \color{blue}{z \cdot z}}{y}\right) \]
      3. difference-of-squares93.6%

        \[\leadsto 0.5 \cdot \left(y + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{y}\right) \]
    7. Applied egg-rr83.1%

      \[\leadsto y \cdot \left(0.5 + \frac{\color{blue}{\left(x + z\right) \cdot \left(x - z\right)}}{{y}^{2}} \cdot 0.5\right) \]
    8. Taylor expanded in y around 0 70.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\left(x + z\right) \cdot \left(x - z\right)}{y}} \]
    9. Step-by-step derivation
      1. associate-*r/70.4%

        \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\left(x + z\right) \cdot \left(x - z\right)\right)}{y}} \]
      2. +-commutative70.4%

        \[\leadsto \frac{0.5 \cdot \left(\color{blue}{\left(z + x\right)} \cdot \left(x - z\right)\right)}{y} \]
    10. Simplified70.4%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(\left(z + x\right) \cdot \left(x - z\right)\right)}{y}} \]
    11. Step-by-step derivation
      1. associate-/l*70.4%

        \[\leadsto \color{blue}{0.5 \cdot \frac{\left(z + x\right) \cdot \left(x - z\right)}{y}} \]
      2. *-commutative70.4%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\left(x - z\right) \cdot \left(z + x\right)}}{y} \]
      3. associate-*l/73.4%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x - z}{y} \cdot \left(z + x\right)\right)} \]
      4. associate-*r*73.4%

        \[\leadsto \color{blue}{\left(0.5 \cdot \frac{x - z}{y}\right) \cdot \left(z + x\right)} \]
      5. +-commutative73.4%

        \[\leadsto \left(0.5 \cdot \frac{x - z}{y}\right) \cdot \color{blue}{\left(x + z\right)} \]
    12. Applied egg-rr73.4%

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

    if 1.80000000000000017e72 < y < 7.50000000000000014e87 or 2.9e109 < y

    1. Initial program 37.3%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 73.4%

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative73.4%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified73.4%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.8 \cdot 10^{+72} \lor \neg \left(y \leq 7.5 \cdot 10^{+87}\right) \land y \leq 2.9 \cdot 10^{+109}:\\ \;\;\;\;\left(x + z\right) \cdot \left(0.5 \cdot \frac{x - z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 43.4% accurate, 1.2× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;y \leq 3.2 \cdot 10^{+23}:\\ \;\;\;\;0.5 \cdot \left(x\_m \cdot \frac{x\_m}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z)
 :precision binary64
 (if (<= y 3.2e+23) (* 0.5 (* x_m (/ x_m y))) (* 0.5 y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
	double tmp;
	if (y <= 3.2e+23) {
		tmp = 0.5 * (x_m * (x_m / y));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= 3.2d+23) then
        tmp = 0.5d0 * (x_m * (x_m / y))
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
	double tmp;
	if (y <= 3.2e+23) {
		tmp = 0.5 * (x_m * (x_m / y));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y, z):
	tmp = 0
	if y <= 3.2e+23:
		tmp = 0.5 * (x_m * (x_m / y))
	else:
		tmp = 0.5 * y
	return tmp
x_m = abs(x)
function code(x_m, y, z)
	tmp = 0.0
	if (y <= 3.2e+23)
		tmp = Float64(0.5 * Float64(x_m * Float64(x_m / y)));
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y, z)
	tmp = 0.0;
	if (y <= 3.2e+23)
		tmp = 0.5 * (x_m * (x_m / y));
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_] := If[LessEqual[y, 3.2e+23], N[(0.5 * N[(x$95$m * N[(x$95$m / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{+23}:\\
\;\;\;\;0.5 \cdot \left(x\_m \cdot \frac{x\_m}{y}\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\


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

    1. Initial program 75.5%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. remove-double-neg75.5%

        \[\leadsto \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\color{blue}{-\left(-y \cdot 2\right)}} \]
      2. distribute-lft-neg-out75.5%

        \[\leadsto \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{-\color{blue}{\left(-y\right) \cdot 2}} \]
      3. distribute-frac-neg275.5%

        \[\leadsto \color{blue}{-\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{\left(-y\right) \cdot 2}} \]
      4. distribute-frac-neg75.5%

        \[\leadsto \color{blue}{\frac{-\left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\left(-y\right) \cdot 2}} \]
      5. neg-mul-175.5%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}}{\left(-y\right) \cdot 2} \]
      6. distribute-lft-neg-out75.5%

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{-y \cdot 2}} \]
      7. *-commutative75.5%

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{-\color{blue}{2 \cdot y}} \]
      8. distribute-lft-neg-in75.5%

        \[\leadsto \frac{-1 \cdot \left(\left(x \cdot x + y \cdot y\right) - z \cdot z\right)}{\color{blue}{\left(-2\right) \cdot y}} \]
      9. times-frac75.5%

        \[\leadsto \color{blue}{\frac{-1}{-2} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y}} \]
      10. metadata-eval75.5%

        \[\leadsto \frac{-1}{\color{blue}{-2}} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      11. metadata-eval75.5%

        \[\leadsto \color{blue}{0.5} \cdot \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y} \]
      12. associate--l+75.5%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{x \cdot x + \left(y \cdot y - z \cdot z\right)}}{y} \]
      13. fma-define78.6%

        \[\leadsto 0.5 \cdot \frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}}{y} \]
    3. Simplified78.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{\mathsf{fma}\left(x, x, y \cdot y - z \cdot z\right)}{y}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 56.1%

      \[\leadsto 0.5 \cdot \color{blue}{\left({z}^{2} \cdot \left(\left(\frac{y}{{z}^{2}} + \frac{{x}^{2}}{y \cdot {z}^{2}}\right) - \frac{1}{y}\right)\right)} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt30.9%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{{z}^{2} \cdot \left(\left(\frac{y}{{z}^{2}} + \frac{{x}^{2}}{y \cdot {z}^{2}}\right) - \frac{1}{y}\right)} \cdot \sqrt{{z}^{2} \cdot \left(\left(\frac{y}{{z}^{2}} + \frac{{x}^{2}}{y \cdot {z}^{2}}\right) - \frac{1}{y}\right)}\right)} \]
      2. pow230.9%

        \[\leadsto 0.5 \cdot \color{blue}{{\left(\sqrt{{z}^{2} \cdot \left(\left(\frac{y}{{z}^{2}} + \frac{{x}^{2}}{y \cdot {z}^{2}}\right) - \frac{1}{y}\right)}\right)}^{2}} \]
    7. Applied egg-rr11.5%

      \[\leadsto 0.5 \cdot \color{blue}{{\left(z \cdot \sqrt{\mathsf{fma}\left(y, {z}^{-2}, {\left(\frac{x}{z \cdot \sqrt{y}}\right)}^{2}\right) + \frac{-1}{y}}\right)}^{2}} \]
    8. Taylor expanded in x around inf 14.7%

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

        \[\leadsto 0.5 \cdot \color{blue}{\left(\left(x \cdot \sqrt{\frac{1}{y}}\right) \cdot \left(x \cdot \sqrt{\frac{1}{y}}\right)\right)} \]
      2. associate-*l*14.7%

        \[\leadsto 0.5 \cdot \color{blue}{\left(x \cdot \left(\sqrt{\frac{1}{y}} \cdot \left(x \cdot \sqrt{\frac{1}{y}}\right)\right)\right)} \]
      3. sqrt-div14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \left(\color{blue}{\frac{\sqrt{1}}{\sqrt{y}}} \cdot \left(x \cdot \sqrt{\frac{1}{y}}\right)\right)\right) \]
      4. metadata-eval14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \left(\frac{\color{blue}{1}}{\sqrt{y}} \cdot \left(x \cdot \sqrt{\frac{1}{y}}\right)\right)\right) \]
      5. sqrt-div14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \left(\frac{1}{\sqrt{y}} \cdot \left(x \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{y}}}\right)\right)\right) \]
      6. metadata-eval14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \left(\frac{1}{\sqrt{y}} \cdot \left(x \cdot \frac{\color{blue}{1}}{\sqrt{y}}\right)\right)\right) \]
      7. un-div-inv14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \left(\frac{1}{\sqrt{y}} \cdot \color{blue}{\frac{x}{\sqrt{y}}}\right)\right) \]
      8. times-frac14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \color{blue}{\frac{1 \cdot x}{\sqrt{y} \cdot \sqrt{y}}}\right) \]
      9. *-un-lft-identity14.7%

        \[\leadsto 0.5 \cdot \left(x \cdot \frac{\color{blue}{x}}{\sqrt{y} \cdot \sqrt{y}}\right) \]
      10. add-sqr-sqrt34.4%

        \[\leadsto 0.5 \cdot \left(x \cdot \frac{x}{\color{blue}{y}}\right) \]
    10. Applied egg-rr34.4%

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

    if 3.2e23 < y

    1. Initial program 47.6%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 65.0%

      \[\leadsto \color{blue}{0.5 \cdot y} \]
    4. Step-by-step derivation
      1. *-commutative65.0%

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    5. Simplified65.0%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification41.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 3.2 \cdot 10^{+23}:\\ \;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 34.3% accurate, 5.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ 0.5 \cdot y \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z) :precision binary64 (* 0.5 y))
x_m = fabs(x);
double code(double x_m, double y, double z) {
	return 0.5 * y;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.5d0 * y
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
	return 0.5 * y;
}
x_m = math.fabs(x)
def code(x_m, y, z):
	return 0.5 * y
x_m = abs(x)
function code(x_m, y, z)
	return Float64(0.5 * y)
end
x_m = abs(x);
function tmp = code(x_m, y, z)
	tmp = 0.5 * y;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_] := N[(0.5 * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
0.5 \cdot y
\end{array}
Derivation
  1. Initial program 68.8%

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Add Preprocessing
  3. Taylor expanded in y around inf 37.1%

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  4. Step-by-step derivation
    1. *-commutative37.1%

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  5. Simplified37.1%

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  6. Final simplification37.1%

    \[\leadsto 0.5 \cdot y \]
  7. Add Preprocessing

Developer target: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right) \end{array} \]
(FPCore (x y z)
 :precision binary64
 (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x))))
double code(double x, double y, double z) {
	return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (y * 0.5d0) - (((0.5d0 / y) * (z + x)) * (z - x))
end function
public static double code(double x, double y, double z) {
	return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
def code(x, y, z):
	return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x))
function code(x, y, z)
	return Float64(Float64(y * 0.5) - Float64(Float64(Float64(0.5 / y) * Float64(z + x)) * Float64(z - x)))
end
function tmp = code(x, y, z)
	tmp = (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] - N[(N[(N[(0.5 / y), $MachinePrecision] * N[(z + x), $MachinePrecision]), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)
\end{array}

Reproduce

?
herbie shell --seed 2024073 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :alt
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

  (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))