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

Percentage Accurate: 69.5% → 99.9%
Time: 4.7s
Alternatives: 8
Speedup: 1.4×

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

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

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Step-by-step derivation
    1. sub-neg69.4%

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

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

      \[\leadsto \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2} \]
    4. associate-+l-69.4%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
    10. div-sub69.4%

      \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
    11. difference-of-squares73.0%

      \[\leadsto \left(\frac{\color{blue}{\left(z + x\right) \cdot \left(z - x\right)}}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
    12. +-commutative73.0%

      \[\leadsto \left(\frac{\color{blue}{\left(x + z\right)} \cdot \left(z - x\right)}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
    13. associate-*l/76.5%

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

      \[\leadsto \left(\color{blue}{\left(z - x\right) \cdot \frac{x + z}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
    15. associate-/l*99.9%

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

      \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
    17. /-rgt-identity99.9%

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

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

    \[\leadsto \color{blue}{\left(\left(z - x\right) \cdot \frac{x + z}{y} - y\right) \cdot -0.5} \]
  4. Step-by-step derivation
    1. clear-num99.9%

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

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

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

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

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

Alternative 2: 50.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{if}\;z \cdot z \leq 10^{-164}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-122}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+75}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \cdot z \leq 10^{+197}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \mathbf{elif}\;z \cdot z \leq 10^{+245}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* -0.5 (/ z (/ y z)))))
   (if (<= (* z z) 1e-164)
     (* y 0.5)
     (if (<= (* z z) 5e-122)
       (* 0.5 (/ x (/ y x)))
       (if (<= (* z z) 5e+75)
         (* y 0.5)
         (if (<= (* z z) 2e+165)
           t_0
           (if (<= (* z z) 1e+197)
             (* x (/ x (* y 2.0)))
             (if (<= (* z z) 1e+245) (* y 0.5) t_0))))))))
double code(double x, double y, double z) {
	double t_0 = -0.5 * (z / (y / z));
	double tmp;
	if ((z * z) <= 1e-164) {
		tmp = y * 0.5;
	} else if ((z * z) <= 5e-122) {
		tmp = 0.5 * (x / (y / x));
	} else if ((z * z) <= 5e+75) {
		tmp = y * 0.5;
	} else if ((z * z) <= 2e+165) {
		tmp = t_0;
	} else if ((z * z) <= 1e+197) {
		tmp = x * (x / (y * 2.0));
	} else if ((z * z) <= 1e+245) {
		tmp = y * 0.5;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-0.5d0) * (z / (y / z))
    if ((z * z) <= 1d-164) then
        tmp = y * 0.5d0
    else if ((z * z) <= 5d-122) then
        tmp = 0.5d0 * (x / (y / x))
    else if ((z * z) <= 5d+75) then
        tmp = y * 0.5d0
    else if ((z * z) <= 2d+165) then
        tmp = t_0
    else if ((z * z) <= 1d+197) then
        tmp = x * (x / (y * 2.0d0))
    else if ((z * z) <= 1d+245) then
        tmp = y * 0.5d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = -0.5 * (z / (y / z));
	double tmp;
	if ((z * z) <= 1e-164) {
		tmp = y * 0.5;
	} else if ((z * z) <= 5e-122) {
		tmp = 0.5 * (x / (y / x));
	} else if ((z * z) <= 5e+75) {
		tmp = y * 0.5;
	} else if ((z * z) <= 2e+165) {
		tmp = t_0;
	} else if ((z * z) <= 1e+197) {
		tmp = x * (x / (y * 2.0));
	} else if ((z * z) <= 1e+245) {
		tmp = y * 0.5;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -0.5 * (z / (y / z))
	tmp = 0
	if (z * z) <= 1e-164:
		tmp = y * 0.5
	elif (z * z) <= 5e-122:
		tmp = 0.5 * (x / (y / x))
	elif (z * z) <= 5e+75:
		tmp = y * 0.5
	elif (z * z) <= 2e+165:
		tmp = t_0
	elif (z * z) <= 1e+197:
		tmp = x * (x / (y * 2.0))
	elif (z * z) <= 1e+245:
		tmp = y * 0.5
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(-0.5 * Float64(z / Float64(y / z)))
	tmp = 0.0
	if (Float64(z * z) <= 1e-164)
		tmp = Float64(y * 0.5);
	elseif (Float64(z * z) <= 5e-122)
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	elseif (Float64(z * z) <= 5e+75)
		tmp = Float64(y * 0.5);
	elseif (Float64(z * z) <= 2e+165)
		tmp = t_0;
	elseif (Float64(z * z) <= 1e+197)
		tmp = Float64(x * Float64(x / Float64(y * 2.0)));
	elseif (Float64(z * z) <= 1e+245)
		tmp = Float64(y * 0.5);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = -0.5 * (z / (y / z));
	tmp = 0.0;
	if ((z * z) <= 1e-164)
		tmp = y * 0.5;
	elseif ((z * z) <= 5e-122)
		tmp = 0.5 * (x / (y / x));
	elseif ((z * z) <= 5e+75)
		tmp = y * 0.5;
	elseif ((z * z) <= 2e+165)
		tmp = t_0;
	elseif ((z * z) <= 1e+197)
		tmp = x * (x / (y * 2.0));
	elseif ((z * z) <= 1e+245)
		tmp = y * 0.5;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(-0.5 * N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * z), $MachinePrecision], 1e-164], N[(y * 0.5), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 5e-122], N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 5e+75], N[(y * 0.5), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 2e+165], t$95$0, If[LessEqual[N[(z * z), $MachinePrecision], 1e+197], N[(x * N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+245], N[(y * 0.5), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{z}{\frac{y}{z}}\\
\mathbf{if}\;z \cdot z \leq 10^{-164}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-122}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\

\mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+75}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+165}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \cdot z \leq 10^{+197}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot 2}\\

\mathbf{elif}\;z \cdot z \leq 10^{+245}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 z z) < 9.99999999999999962e-165 or 4.9999999999999999e-122 < (*.f64 z z) < 5.0000000000000002e75 or 9.9999999999999995e196 < (*.f64 z z) < 1.00000000000000004e245

    1. Initial program 72.2%

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

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

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

      \[\leadsto \color{blue}{y \cdot 0.5} \]

    if 9.99999999999999962e-165 < (*.f64 z z) < 4.9999999999999999e-122

    1. Initial program 76.3%

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    3. Step-by-step derivation
      1. unpow259.4%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    4. Simplified59.4%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    5. Taylor expanded in x around 0 59.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{y}} \]
    6. Step-by-step derivation
      1. *-commutative59.4%

        \[\leadsto \color{blue}{\frac{{x}^{2}}{y} \cdot 0.5} \]
      2. unpow259.4%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y} \cdot 0.5 \]
      3. associate-*l/67.0%

        \[\leadsto \color{blue}{\left(\frac{x}{y} \cdot x\right)} \cdot 0.5 \]
      4. associate-/r/67.1%

        \[\leadsto \color{blue}{\frac{x}{\frac{y}{x}}} \cdot 0.5 \]
    7. Simplified67.1%

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{x}} \cdot 0.5} \]

    if 5.0000000000000002e75 < (*.f64 z z) < 1.9999999999999998e165 or 1.00000000000000004e245 < (*.f64 z z)

    1. Initial program 65.7%

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

      \[\leadsto \color{blue}{-0.5 \cdot \frac{{z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. *-commutative66.5%

        \[\leadsto \color{blue}{\frac{{z}^{2}}{y} \cdot -0.5} \]
      2. unpow266.5%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      3. associate-/l*70.9%

        \[\leadsto \color{blue}{\frac{z}{\frac{y}{z}}} \cdot -0.5 \]
    4. Simplified70.9%

      \[\leadsto \color{blue}{\frac{z}{\frac{y}{z}} \cdot -0.5} \]

    if 1.9999999999999998e165 < (*.f64 z z) < 9.9999999999999995e196

    1. Initial program 60.5%

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    3. Step-by-step derivation
      1. unpow259.7%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    4. Simplified59.7%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    5. Step-by-step derivation
      1. associate-/l*85.9%

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

        \[\leadsto \color{blue}{\frac{x}{y \cdot 2} \cdot x} \]
    6. Applied egg-rr86.1%

      \[\leadsto \color{blue}{\frac{x}{y \cdot 2} \cdot x} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification63.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-164}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-122}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+75}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+165}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{elif}\;z \cdot z \leq 10^{+197}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \mathbf{elif}\;z \cdot z \leq 10^{+245}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \end{array} \]

Alternative 3: 88.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 10^{-36}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \left(\left(z - x\right) \cdot \frac{x}{y} - y\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* x x) 1e-36)
   (* -0.5 (- (/ z (/ y z)) y))
   (* -0.5 (- (* (- z x) (/ x y)) y))))
double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 1e-36) {
		tmp = -0.5 * ((z / (y / z)) - y);
	} else {
		tmp = -0.5 * (((z - x) * (x / y)) - y);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x * x) <= 1d-36) then
        tmp = (-0.5d0) * ((z / (y / z)) - y)
    else
        tmp = (-0.5d0) * (((z - x) * (x / y)) - y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x * x) <= 1e-36) {
		tmp = -0.5 * ((z / (y / z)) - y);
	} else {
		tmp = -0.5 * (((z - x) * (x / y)) - y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x * x) <= 1e-36:
		tmp = -0.5 * ((z / (y / z)) - y)
	else:
		tmp = -0.5 * (((z - x) * (x / y)) - y)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(x * x) <= 1e-36)
		tmp = Float64(-0.5 * Float64(Float64(z / Float64(y / z)) - y));
	else
		tmp = Float64(-0.5 * Float64(Float64(Float64(z - x) * Float64(x / y)) - y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x * x) <= 1e-36)
		tmp = -0.5 * ((z / (y / z)) - y);
	else
		tmp = -0.5 * (((z - x) * (x / y)) - y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e-36], N[(-0.5 * N[(N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(N[(z - x), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-36}:\\
\;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\

\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\left(z - x\right) \cdot \frac{x}{y} - y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 9.9999999999999994e-37

    1. Initial program 70.4%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. sub-neg70.4%

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

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

        \[\leadsto \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2} \]
      4. associate-+l-70.4%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub70.4%

        \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
      11. difference-of-squares70.4%

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

        \[\leadsto \left(\frac{\color{blue}{\left(x + z\right)} \cdot \left(z - x\right)}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
      13. associate-*l/73.0%

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

        \[\leadsto \left(\color{blue}{\left(z - x\right) \cdot \frac{x + z}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
      15. associate-/l*100.0%

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity100.0%

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\frac{z}{\frac{y}{z}}} - y\right) \cdot -0.5 \]
    6. Simplified96.9%

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

    if 9.9999999999999994e-37 < (*.f64 x x)

    1. Initial program 68.5%

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

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

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

        \[\leadsto \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2} \]
      4. associate-+l-68.5%

        \[\leadsto \frac{\color{blue}{0 - \left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2} \]
      5. sub0-neg68.5%

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{\color{blue}{\left(x + z\right)} \cdot \left(z - x\right)}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
      13. associate-*l/79.9%

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

        \[\leadsto \left(\color{blue}{\left(z - x\right) \cdot \frac{x + z}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
      15. associate-/l*99.9%

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

      \[\leadsto \left(\left(z - x\right) \cdot \color{blue}{\frac{x}{y}} - y\right) \cdot -0.5 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

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

Alternative 4: 99.9% accurate, 1.2× speedup?

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

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

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
  2. Step-by-step derivation
    1. sub-neg69.4%

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

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

      \[\leadsto \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2} \]
    4. associate-+l-69.4%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
    10. div-sub69.4%

      \[\leadsto \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2} \]
    11. difference-of-squares73.0%

      \[\leadsto \left(\frac{\color{blue}{\left(z + x\right) \cdot \left(z - x\right)}}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
    12. +-commutative73.0%

      \[\leadsto \left(\frac{\color{blue}{\left(x + z\right)} \cdot \left(z - x\right)}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
    13. associate-*l/76.5%

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

      \[\leadsto \left(\color{blue}{\left(z - x\right) \cdot \frac{x + z}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
    15. associate-/l*99.9%

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

      \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
    17. /-rgt-identity99.9%

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

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

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

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

Alternative 5: 72.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 5.5 \cdot 10^{+172}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x 5.5e+172) (* -0.5 (- (/ z (/ y z)) y)) (* x (/ x (* y 2.0)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= 5.5e+172) {
		tmp = -0.5 * ((z / (y / z)) - y);
	} else {
		tmp = x * (x / (y * 2.0));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 5.5d+172) then
        tmp = (-0.5d0) * ((z / (y / z)) - y)
    else
        tmp = x * (x / (y * 2.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= 5.5e+172) {
		tmp = -0.5 * ((z / (y / z)) - y);
	} else {
		tmp = x * (x / (y * 2.0));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= 5.5e+172:
		tmp = -0.5 * ((z / (y / z)) - y)
	else:
		tmp = x * (x / (y * 2.0))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= 5.5e+172)
		tmp = Float64(-0.5 * Float64(Float64(z / Float64(y / z)) - y));
	else
		tmp = Float64(x * Float64(x / Float64(y * 2.0)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= 5.5e+172)
		tmp = -0.5 * ((z / (y / z)) - y);
	else
		tmp = x * (x / (y * 2.0));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, 5.5e+172], N[(-0.5 * N[(N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision], N[(x * N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{+172}:\\
\;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot 2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.4999999999999999e172

    1. Initial program 69.0%

      \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2} \]
    2. Step-by-step derivation
      1. sub-neg69.0%

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

        \[\leadsto \frac{\color{blue}{\left(-z \cdot z\right) + \left(x \cdot x + y \cdot y\right)}}{y \cdot 2} \]
      3. neg-sub069.0%

        \[\leadsto \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2} \]
      4. associate-+l-69.0%

        \[\leadsto \frac{\color{blue}{0 - \left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2} \]
      5. sub0-neg69.0%

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2} \]
      10. div-sub69.0%

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

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

        \[\leadsto \left(\frac{\color{blue}{\left(x + z\right)} \cdot \left(z - x\right)}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
      13. associate-*l/73.9%

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

        \[\leadsto \left(\color{blue}{\left(z - x\right) \cdot \frac{x + z}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2} \]
      15. associate-/l*99.9%

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

        \[\leadsto \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2} \]
      17. /-rgt-identity99.9%

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\frac{z}{\frac{y}{z}}} - y\right) \cdot -0.5 \]
    6. Simplified78.5%

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

    if 5.4999999999999999e172 < x

    1. Initial program 73.2%

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

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{y \cdot 2} \]
    3. Step-by-step derivation
      1. unpow290.4%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    4. Simplified90.4%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    5. Step-by-step derivation
      1. associate-/l*93.3%

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

        \[\leadsto \color{blue}{\frac{x}{y \cdot 2} \cdot x} \]
    6. Applied egg-rr93.3%

      \[\leadsto \color{blue}{\frac{x}{y \cdot 2} \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.5 \cdot 10^{+172}:\\ \;\;\;\;-0.5 \cdot \left(\frac{z}{\frac{y}{z}} - y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \end{array} \]

Alternative 6: 43.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 7 \cdot 10^{+53}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x 7e+53) (* y 0.5) (* x (/ x (* y 2.0)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= 7e+53) {
		tmp = y * 0.5;
	} else {
		tmp = x * (x / (y * 2.0));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 7d+53) then
        tmp = y * 0.5d0
    else
        tmp = x * (x / (y * 2.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= 7e+53) {
		tmp = y * 0.5;
	} else {
		tmp = x * (x / (y * 2.0));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= 7e+53:
		tmp = y * 0.5
	else:
		tmp = x * (x / (y * 2.0))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= 7e+53)
		tmp = Float64(y * 0.5);
	else
		tmp = Float64(x * Float64(x / Float64(y * 2.0)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= 7e+53)
		tmp = y * 0.5;
	else
		tmp = x * (x / (y * 2.0));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, 7e+53], N[(y * 0.5), $MachinePrecision], N[(x * N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 7 \cdot 10^{+53}:\\
\;\;\;\;y \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot 2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 7.00000000000000038e53

    1. Initial program 69.5%

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

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

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    4. Simplified41.2%

      \[\leadsto \color{blue}{y \cdot 0.5} \]

    if 7.00000000000000038e53 < x

    1. Initial program 69.2%

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

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

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    4. Simplified63.5%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    5. Step-by-step derivation
      1. associate-/l*66.7%

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

        \[\leadsto \color{blue}{\frac{x}{y \cdot 2} \cdot x} \]
    6. Applied egg-rr66.7%

      \[\leadsto \color{blue}{\frac{x}{y \cdot 2} \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification46.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7 \cdot 10^{+53}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \end{array} \]

Alternative 7: 43.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.5 \cdot 10^{+53}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x 3.5e+53) (* y 0.5) (* 0.5 (/ x (/ y x)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= 3.5e+53) {
		tmp = y * 0.5;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= 3.5d+53) then
        tmp = y * 0.5d0
    else
        tmp = 0.5d0 * (x / (y / x))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= 3.5e+53) {
		tmp = y * 0.5;
	} else {
		tmp = 0.5 * (x / (y / x));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= 3.5e+53:
		tmp = y * 0.5
	else:
		tmp = 0.5 * (x / (y / x))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= 3.5e+53)
		tmp = Float64(y * 0.5);
	else
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= 3.5e+53)
		tmp = y * 0.5;
	else
		tmp = 0.5 * (x / (y / x));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, 3.5e+53], N[(y * 0.5), $MachinePrecision], N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5 \cdot 10^{+53}:\\
\;\;\;\;y \cdot 0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.50000000000000019e53

    1. Initial program 69.5%

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

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

        \[\leadsto \color{blue}{y \cdot 0.5} \]
    4. Simplified41.2%

      \[\leadsto \color{blue}{y \cdot 0.5} \]

    if 3.50000000000000019e53 < x

    1. Initial program 69.2%

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

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

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    4. Simplified63.5%

      \[\leadsto \frac{\color{blue}{x \cdot x}}{y \cdot 2} \]
    5. Taylor expanded in x around 0 63.5%

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{y}} \]
    6. Step-by-step derivation
      1. *-commutative63.5%

        \[\leadsto \color{blue}{\frac{{x}^{2}}{y} \cdot 0.5} \]
      2. unpow263.5%

        \[\leadsto \frac{\color{blue}{x \cdot x}}{y} \cdot 0.5 \]
      3. associate-*l/66.7%

        \[\leadsto \color{blue}{\left(\frac{x}{y} \cdot x\right)} \cdot 0.5 \]
      4. associate-/r/66.7%

        \[\leadsto \color{blue}{\frac{x}{\frac{y}{x}}} \cdot 0.5 \]
    7. Simplified66.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.5 \cdot 10^{+53}:\\ \;\;\;\;y \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \end{array} \]

Alternative 8: 33.9% accurate, 5.0× speedup?

\[\begin{array}{l} \\ y \cdot 0.5 \end{array} \]
(FPCore (x y z) :precision binary64 (* y 0.5))
double code(double x, double y, double z) {
	return y * 0.5;
}
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
end function
public static double code(double x, double y, double z) {
	return y * 0.5;
}
def code(x, y, z):
	return y * 0.5
function code(x, y, z)
	return Float64(y * 0.5)
end
function tmp = code(x, y, z)
	tmp = y * 0.5;
end
code[x_, y_, z_] := N[(y * 0.5), $MachinePrecision]
\begin{array}{l}

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

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

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

      \[\leadsto \color{blue}{y \cdot 0.5} \]
  4. Simplified36.6%

    \[\leadsto \color{blue}{y \cdot 0.5} \]
  5. Final simplification36.6%

    \[\leadsto y \cdot 0.5 \]

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 2023200 
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :herbie-target
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

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