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

Percentage Accurate: 69.7% → 99.9%
Time: 7.6s
Alternatives: 9
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 9 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.7% 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 = |x|\\ z = |z|\\ \\ 0.5 \cdot \left(y + \frac{z + x}{y} \cdot \left(x - z\right)\right) \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z) :precision binary64 (* 0.5 (+ y (* (/ (+ z x) y) (- x z)))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	return 0.5 * (y + (((z + x) / y) * (x - z)));
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 * (y + (((z + x) / y) * (x - z)))
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	return 0.5 * (y + (((z + x) / y) * (x - z)));
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	return 0.5 * (y + (((z + x) / y) * (x - z)))
x = abs(x)
z = abs(z)
function code(x, y, z)
	return Float64(0.5 * Float64(y + Float64(Float64(Float64(z + x) / y) * Float64(x - z))))
end
x = abs(x)
z = abs(z)
function tmp = code(x, y, z)
	tmp = 0.5 * (y + (((z + x) / y) * (x - z)));
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := N[(0.5 * N[(y + N[(N[(N[(z + x), $MachinePrecision] / y), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
0.5 \cdot \left(y + \frac{z + x}{y} \cdot \left(x - z\right)\right)
\end{array}
Derivation
  1. Initial program 66.8%

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

    \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
  3. Step-by-step derivation
    1. distribute-lft-out82.2%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 51.7% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} t_0 := 0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{if}\;y \leq -1200000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-93}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 0.5 (/ x (/ y x)))))
   (if (<= y -1200000000000.0)
     (* 0.5 y)
     (if (<= y 3.2e-129)
       t_0
       (if (<= y 8e-93)
         (* (* z (/ z y)) -0.5)
         (if (<= y 1.8e+25) t_0 (* 0.5 y)))))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double t_0 = 0.5 * (x / (y / x));
	double tmp;
	if (y <= -1200000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 3.2e-129) {
		tmp = t_0;
	} else if (y <= 8e-93) {
		tmp = (z * (z / y)) * -0.5;
	} else if (y <= 1.8e+25) {
		tmp = t_0;
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 * (x / (y / x))
    if (y <= (-1200000000000.0d0)) then
        tmp = 0.5d0 * y
    else if (y <= 3.2d-129) then
        tmp = t_0
    else if (y <= 8d-93) then
        tmp = (z * (z / y)) * (-0.5d0)
    else if (y <= 1.8d+25) then
        tmp = t_0
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double t_0 = 0.5 * (x / (y / x));
	double tmp;
	if (y <= -1200000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 3.2e-129) {
		tmp = t_0;
	} else if (y <= 8e-93) {
		tmp = (z * (z / y)) * -0.5;
	} else if (y <= 1.8e+25) {
		tmp = t_0;
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	t_0 = 0.5 * (x / (y / x))
	tmp = 0
	if y <= -1200000000000.0:
		tmp = 0.5 * y
	elif y <= 3.2e-129:
		tmp = t_0
	elif y <= 8e-93:
		tmp = (z * (z / y)) * -0.5
	elif y <= 1.8e+25:
		tmp = t_0
	else:
		tmp = 0.5 * y
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	t_0 = Float64(0.5 * Float64(x / Float64(y / x)))
	tmp = 0.0
	if (y <= -1200000000000.0)
		tmp = Float64(0.5 * y);
	elseif (y <= 3.2e-129)
		tmp = t_0;
	elseif (y <= 8e-93)
		tmp = Float64(Float64(z * Float64(z / y)) * -0.5);
	elseif (y <= 1.8e+25)
		tmp = t_0;
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	t_0 = 0.5 * (x / (y / x));
	tmp = 0.0;
	if (y <= -1200000000000.0)
		tmp = 0.5 * y;
	elseif (y <= 3.2e-129)
		tmp = t_0;
	elseif (y <= 8e-93)
		tmp = (z * (z / y)) * -0.5;
	elseif (y <= 1.8e+25)
		tmp = t_0;
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := Block[{t$95$0 = N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1200000000000.0], N[(0.5 * y), $MachinePrecision], If[LessEqual[y, 3.2e-129], t$95$0, If[LessEqual[y, 8e-93], N[(N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], If[LessEqual[y, 1.8e+25], t$95$0, N[(0.5 * y), $MachinePrecision]]]]]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{x}{\frac{y}{x}}\\
\mathbf{if}\;y \leq -1200000000000:\\
\;\;\;\;0.5 \cdot y\\

\mathbf{elif}\;y \leq 3.2 \cdot 10^{-129}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 8 \cdot 10^{-93}:\\
\;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\

\mathbf{elif}\;y \leq 1.8 \cdot 10^{+25}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.2e12 or 1.80000000000000008e25 < y

    1. Initial program 45.5%

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

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

    if -1.2e12 < y < 3.2000000000000003e-129 or 7.9999999999999992e-93 < y < 1.80000000000000008e25

    1. Initial program 89.7%

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

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

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

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

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

    if 3.2000000000000003e-129 < y < 7.9999999999999992e-93

    1. Initial program 99.4%

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

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

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

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

      \[\leadsto \color{blue}{\frac{z \cdot z}{y} \cdot -0.5} \]
    5. Taylor expanded in z around 0 83.2%

      \[\leadsto \color{blue}{\frac{{z}^{2}}{y}} \cdot -0.5 \]
    6. Step-by-step derivation
      1. unpow283.2%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      2. associate-*r/83.2%

        \[\leadsto \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot -0.5 \]
    7. Simplified83.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1200000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-129}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-93}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]

Alternative 3: 51.8% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -175000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-130}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-98}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= y -175000000000.0)
   (* 0.5 y)
   (if (<= y 9e-130)
     (* x (/ x (* y 2.0)))
     (if (<= y 9e-98)
       (* (* z (/ z y)) -0.5)
       (if (<= y 1.85e+25) (* 0.5 (/ x (/ y x))) (* 0.5 y))))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= -175000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 9e-130) {
		tmp = x * (x / (y * 2.0));
	} else if (y <= 9e-98) {
		tmp = (z * (z / y)) * -0.5;
	} else if (y <= 1.85e+25) {
		tmp = 0.5 * (x / (y / x));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 (y <= (-175000000000.0d0)) then
        tmp = 0.5d0 * y
    else if (y <= 9d-130) then
        tmp = x * (x / (y * 2.0d0))
    else if (y <= 9d-98) then
        tmp = (z * (z / y)) * (-0.5d0)
    else if (y <= 1.85d+25) then
        tmp = 0.5d0 * (x / (y / x))
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -175000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 9e-130) {
		tmp = x * (x / (y * 2.0));
	} else if (y <= 9e-98) {
		tmp = (z * (z / y)) * -0.5;
	} else if (y <= 1.85e+25) {
		tmp = 0.5 * (x / (y / x));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	tmp = 0
	if y <= -175000000000.0:
		tmp = 0.5 * y
	elif y <= 9e-130:
		tmp = x * (x / (y * 2.0))
	elif y <= 9e-98:
		tmp = (z * (z / y)) * -0.5
	elif y <= 1.85e+25:
		tmp = 0.5 * (x / (y / x))
	else:
		tmp = 0.5 * y
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (y <= -175000000000.0)
		tmp = Float64(0.5 * y);
	elseif (y <= 9e-130)
		tmp = Float64(x * Float64(x / Float64(y * 2.0)));
	elseif (y <= 9e-98)
		tmp = Float64(Float64(z * Float64(z / y)) * -0.5);
	elseif (y <= 1.85e+25)
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -175000000000.0)
		tmp = 0.5 * y;
	elseif (y <= 9e-130)
		tmp = x * (x / (y * 2.0));
	elseif (y <= 9e-98)
		tmp = (z * (z / y)) * -0.5;
	elseif (y <= 1.85e+25)
		tmp = 0.5 * (x / (y / x));
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[y, -175000000000.0], N[(0.5 * y), $MachinePrecision], If[LessEqual[y, 9e-130], N[(x * N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9e-98], N[(N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], If[LessEqual[y, 1.85e+25], N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]]]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -175000000000:\\
\;\;\;\;0.5 \cdot y\\

\mathbf{elif}\;y \leq 9 \cdot 10^{-130}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot 2}\\

\mathbf{elif}\;y \leq 9 \cdot 10^{-98}:\\
\;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\

\mathbf{elif}\;y \leq 1.85 \cdot 10^{+25}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -1.75e11 or 1.8499999999999999e25 < y

    1. Initial program 45.5%

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

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

    if -1.75e11 < y < 9e-130

    1. Initial program 88.9%

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

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

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

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

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

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

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

    if 9e-130 < y < 8.99999999999999994e-98

    1. Initial program 99.4%

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

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

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

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

      \[\leadsto \color{blue}{\frac{z \cdot z}{y} \cdot -0.5} \]
    5. Taylor expanded in z around 0 83.2%

      \[\leadsto \color{blue}{\frac{{z}^{2}}{y}} \cdot -0.5 \]
    6. Step-by-step derivation
      1. unpow283.2%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      2. associate-*r/83.2%

        \[\leadsto \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot -0.5 \]
    7. Simplified83.2%

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

    if 8.99999999999999994e-98 < y < 1.8499999999999999e25

    1. Initial program 94.4%

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified64.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -175000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-130}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-98}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]

Alternative 4: 51.7% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -56000000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-128}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-95}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= y -56000000000000.0)
   (* 0.5 y)
   (if (<= y 1.7e-128)
     (* x (/ x (* y 2.0)))
     (if (<= y 1.15e-95)
       (* -0.5 (/ z (/ y z)))
       (if (<= y 1.65e+25) (* 0.5 (/ x (/ y x))) (* 0.5 y))))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= -56000000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 1.7e-128) {
		tmp = x * (x / (y * 2.0));
	} else if (y <= 1.15e-95) {
		tmp = -0.5 * (z / (y / z));
	} else if (y <= 1.65e+25) {
		tmp = 0.5 * (x / (y / x));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 (y <= (-56000000000000.0d0)) then
        tmp = 0.5d0 * y
    else if (y <= 1.7d-128) then
        tmp = x * (x / (y * 2.0d0))
    else if (y <= 1.15d-95) then
        tmp = (-0.5d0) * (z / (y / z))
    else if (y <= 1.65d+25) then
        tmp = 0.5d0 * (x / (y / x))
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -56000000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 1.7e-128) {
		tmp = x * (x / (y * 2.0));
	} else if (y <= 1.15e-95) {
		tmp = -0.5 * (z / (y / z));
	} else if (y <= 1.65e+25) {
		tmp = 0.5 * (x / (y / x));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	tmp = 0
	if y <= -56000000000000.0:
		tmp = 0.5 * y
	elif y <= 1.7e-128:
		tmp = x * (x / (y * 2.0))
	elif y <= 1.15e-95:
		tmp = -0.5 * (z / (y / z))
	elif y <= 1.65e+25:
		tmp = 0.5 * (x / (y / x))
	else:
		tmp = 0.5 * y
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (y <= -56000000000000.0)
		tmp = Float64(0.5 * y);
	elseif (y <= 1.7e-128)
		tmp = Float64(x * Float64(x / Float64(y * 2.0)));
	elseif (y <= 1.15e-95)
		tmp = Float64(-0.5 * Float64(z / Float64(y / z)));
	elseif (y <= 1.65e+25)
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -56000000000000.0)
		tmp = 0.5 * y;
	elseif (y <= 1.7e-128)
		tmp = x * (x / (y * 2.0));
	elseif (y <= 1.15e-95)
		tmp = -0.5 * (z / (y / z));
	elseif (y <= 1.65e+25)
		tmp = 0.5 * (x / (y / x));
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[y, -56000000000000.0], N[(0.5 * y), $MachinePrecision], If[LessEqual[y, 1.7e-128], N[(x * N[(x / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15e-95], N[(-0.5 * N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.65e+25], N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]]]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -56000000000000:\\
\;\;\;\;0.5 \cdot y\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{-128}:\\
\;\;\;\;x \cdot \frac{x}{y \cdot 2}\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{-95}:\\
\;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\

\mathbf{elif}\;y \leq 1.65 \cdot 10^{+25}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -5.6e13 or 1.6500000000000001e25 < y

    1. Initial program 45.5%

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

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

    if -5.6e13 < y < 1.69999999999999987e-128

    1. Initial program 88.9%

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

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

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

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

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

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

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

    if 1.69999999999999987e-128 < y < 1.15e-95

    1. Initial program 99.4%

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

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

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

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

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

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

    if 1.15e-95 < y < 1.6500000000000001e25

    1. Initial program 94.4%

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified64.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -56000000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-128}:\\ \;\;\;\;x \cdot \frac{x}{y \cdot 2}\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-95}:\\ \;\;\;\;-0.5 \cdot \frac{z}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+25}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]

Alternative 5: 85.4% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+196}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{y + z}{y} \cdot \left(y - z\right)\right)\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 2e+196)
   (* 0.5 (+ y (* x (/ x y))))
   (* 0.5 (* (/ (+ y z) y) (- y z)))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 2e+196) {
		tmp = 0.5 * (y + (x * (x / y)));
	} else {
		tmp = 0.5 * (((y + z) / y) * (y - z));
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 ((z * z) <= 2d+196) then
        tmp = 0.5d0 * (y + (x * (x / y)))
    else
        tmp = 0.5d0 * (((y + z) / y) * (y - z))
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 2e+196) {
		tmp = 0.5 * (y + (x * (x / y)));
	} else {
		tmp = 0.5 * (((y + z) / y) * (y - z));
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (z * z) <= 2e+196:
		tmp = 0.5 * (y + (x * (x / y)))
	else:
		tmp = 0.5 * (((y + z) / y) * (y - z))
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 2e+196)
		tmp = Float64(0.5 * Float64(y + Float64(x * Float64(x / y))));
	else
		tmp = Float64(0.5 * Float64(Float64(Float64(y + z) / y) * Float64(y - z)));
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 2e+196)
		tmp = 0.5 * (y + (x * (x / y)));
	else
		tmp = 0.5 * (((y + z) / y) * (y - z));
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+196], N[(0.5 * N[(y + N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(N[(y + z), $MachinePrecision] / y), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+196}:\\
\;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.9999999999999999e196

    1. Initial program 73.3%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out91.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{x}{\frac{y}{x}}}\right) \]
    7. Simplified88.7%

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

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

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

    if 1.9999999999999999e196 < (*.f64 z z)

    1. Initial program 51.5%

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

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

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

        \[\leadsto 0.5 \cdot \frac{y \cdot y - \color{blue}{z \cdot z}}{y} \]
      3. difference-of-squares62.1%

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{y + z}{\frac{y}{y - z}}} \]
      5. associate-/r/88.3%

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

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

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

Alternative 6: 85.4% accurate, 1.1× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+196}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y - z \cdot \frac{z}{y}\right)\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 2e+196)
   (* 0.5 (+ y (* x (/ x y))))
   (* 0.5 (- y (* z (/ z y))))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 2e+196) {
		tmp = 0.5 * (y + (x * (x / y)));
	} else {
		tmp = 0.5 * (y - (z * (z / y)));
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 ((z * z) <= 2d+196) then
        tmp = 0.5d0 * (y + (x * (x / y)))
    else
        tmp = 0.5d0 * (y - (z * (z / y)))
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 2e+196) {
		tmp = 0.5 * (y + (x * (x / y)));
	} else {
		tmp = 0.5 * (y - (z * (z / y)));
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	tmp = 0
	if (z * z) <= 2e+196:
		tmp = 0.5 * (y + (x * (x / y)))
	else:
		tmp = 0.5 * (y - (z * (z / y)))
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 2e+196)
		tmp = Float64(0.5 * Float64(y + Float64(x * Float64(x / y))));
	else
		tmp = Float64(0.5 * Float64(y - Float64(z * Float64(z / y))));
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 2e+196)
		tmp = 0.5 * (y + (x * (x / y)));
	else
		tmp = 0.5 * (y - (z * (z / y)));
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+196], N[(0.5 * N[(y + N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y - N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+196}:\\
\;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.9999999999999999e196

    1. Initial program 73.3%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out91.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{x}{\frac{y}{x}}}\right) \]
    7. Simplified88.7%

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

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

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

    if 1.9999999999999999e196 < (*.f64 z z)

    1. Initial program 51.5%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out60.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y - \color{blue}{z \cdot \frac{z}{y}}\right) \]
    7. Simplified88.3%

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

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

Alternative 7: 51.8% accurate, 1.3× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -30000000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+24}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= y -30000000000000.0)
   (* 0.5 y)
   (if (<= y 4.8e+24) (* 0.5 (/ x (/ y x))) (* 0.5 y))))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= -30000000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 4.8e+24) {
		tmp = 0.5 * (x / (y / x));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 (y <= (-30000000000000.0d0)) then
        tmp = 0.5d0 * y
    else if (y <= 4.8d+24) then
        tmp = 0.5d0 * (x / (y / x))
    else
        tmp = 0.5d0 * y
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -30000000000000.0) {
		tmp = 0.5 * y;
	} else if (y <= 4.8e+24) {
		tmp = 0.5 * (x / (y / x));
	} else {
		tmp = 0.5 * y;
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	tmp = 0
	if y <= -30000000000000.0:
		tmp = 0.5 * y
	elif y <= 4.8e+24:
		tmp = 0.5 * (x / (y / x))
	else:
		tmp = 0.5 * y
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (y <= -30000000000000.0)
		tmp = Float64(0.5 * y);
	elseif (y <= 4.8e+24)
		tmp = Float64(0.5 * Float64(x / Float64(y / x)));
	else
		tmp = Float64(0.5 * y);
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -30000000000000.0)
		tmp = 0.5 * y;
	elseif (y <= 4.8e+24)
		tmp = 0.5 * (x / (y / x));
	else
		tmp = 0.5 * y;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[y, -30000000000000.0], N[(0.5 * y), $MachinePrecision], If[LessEqual[y, 4.8e+24], N[(0.5 * N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -30000000000000:\\
\;\;\;\;0.5 \cdot y\\

\mathbf{elif}\;y \leq 4.8 \cdot 10^{+24}:\\
\;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3e13 or 4.8000000000000001e24 < y

    1. Initial program 45.5%

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

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

    if -3e13 < y < 4.8000000000000001e24

    1. Initial program 90.1%

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

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

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

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{y}{x}}} \]
    4. Simplified54.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -30000000000000:\\ \;\;\;\;0.5 \cdot y\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+24}:\\ \;\;\;\;0.5 \cdot \frac{x}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot y\\ \end{array} \]

Alternative 8: 78.5% accurate, 1.4× speedup?

\[\begin{array}{l} x = |x|\\ z = |z|\\ \\ \begin{array}{l} \mathbf{if}\;z \leq 2.4 \cdot 10^{+194}:\\ \;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot \frac{z}{y}\right) \cdot -0.5\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
(FPCore (x y z)
 :precision binary64
 (if (<= z 2.4e+194) (* 0.5 (+ y (* x (/ x y)))) (* (* z (/ z y)) -0.5)))
x = abs(x);
z = abs(z);
double code(double x, double y, double z) {
	double tmp;
	if (z <= 2.4e+194) {
		tmp = 0.5 * (y + (x * (x / y)));
	} else {
		tmp = (z * (z / y)) * -0.5;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
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 (z <= 2.4d+194) then
        tmp = 0.5d0 * (y + (x * (x / y)))
    else
        tmp = (z * (z / y)) * (-0.5d0)
    end if
    code = tmp
end function
x = Math.abs(x);
z = Math.abs(z);
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= 2.4e+194) {
		tmp = 0.5 * (y + (x * (x / y)));
	} else {
		tmp = (z * (z / y)) * -0.5;
	}
	return tmp;
}
x = abs(x)
z = abs(z)
def code(x, y, z):
	tmp = 0
	if z <= 2.4e+194:
		tmp = 0.5 * (y + (x * (x / y)))
	else:
		tmp = (z * (z / y)) * -0.5
	return tmp
x = abs(x)
z = abs(z)
function code(x, y, z)
	tmp = 0.0
	if (z <= 2.4e+194)
		tmp = Float64(0.5 * Float64(y + Float64(x * Float64(x / y))));
	else
		tmp = Float64(Float64(z * Float64(z / y)) * -0.5);
	end
	return tmp
end
x = abs(x)
z = abs(z)
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= 2.4e+194)
		tmp = 0.5 * (y + (x * (x / y)));
	else
		tmp = (z * (z / y)) * -0.5;
	end
	tmp_2 = tmp;
end
NOTE: x should be positive before calling this function
NOTE: z should be positive before calling this function
code[x_, y_, z_] := If[LessEqual[z, 2.4e+194], N[(0.5 * N[(y + N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
z = |z|\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.4 \cdot 10^{+194}:\\
\;\;\;\;0.5 \cdot \left(y + x \cdot \frac{x}{y}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 2.4e194

    1. Initial program 68.1%

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

      \[\leadsto \color{blue}{0.5 \cdot y + 0.5 \cdot \frac{{x}^{2} - {z}^{2}}{y}} \]
    3. Step-by-step derivation
      1. distribute-lft-out85.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto 0.5 \cdot \left(y + \color{blue}{\frac{x}{\frac{y}{x}}}\right) \]
    7. Simplified78.6%

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

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

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

    if 2.4e194 < z

    1. Initial program 54.2%

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

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

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

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

      \[\leadsto \color{blue}{\frac{z \cdot z}{y} \cdot -0.5} \]
    5. Taylor expanded in z around 0 76.2%

      \[\leadsto \color{blue}{\frac{{z}^{2}}{y}} \cdot -0.5 \]
    6. Step-by-step derivation
      1. unpow276.2%

        \[\leadsto \frac{\color{blue}{z \cdot z}}{y} \cdot -0.5 \]
      2. associate-*r/84.3%

        \[\leadsto \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot -0.5 \]
    7. Simplified84.3%

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

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

Alternative 9: 33.7% accurate, 5.0× speedup?

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

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

    \[\leadsto \color{blue}{0.5 \cdot y} \]
  3. Final simplification39.4%

    \[\leadsto 0.5 \cdot y \]

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 2023290 
(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)))