Numeric.AD.Rank1.Halley:findZero from ad-4.2.4

Percentage Accurate: 81.0% → 99.9%
Time: 9.5s
Alternatives: 5
Speedup: 1.3×

Specification

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

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

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

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

Alternative 1: 99.9% accurate, 1.3× speedup?

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

\\
x + \frac{2}{-2 \cdot \frac{z}{y} + \frac{t}{z}}
\end{array}
Derivation
  1. Initial program 85.2%

    \[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
  2. Simplified99.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z \cdot -2 + \frac{y}{\frac{z}{t}}}, 2, x\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in x around 0 98.3%

    \[\leadsto \color{blue}{x + 2 \cdot \frac{y}{-2 \cdot z + \frac{t \cdot y}{z}}} \]
  5. Step-by-step derivation
    1. clear-num98.1%

      \[\leadsto x + 2 \cdot \color{blue}{\frac{1}{\frac{-2 \cdot z + \frac{t \cdot y}{z}}{y}}} \]
    2. un-div-inv98.1%

      \[\leadsto x + \color{blue}{\frac{2}{\frac{-2 \cdot z + \frac{t \cdot y}{z}}{y}}} \]
    3. fma-def98.1%

      \[\leadsto x + \frac{2}{\frac{\color{blue}{\mathsf{fma}\left(-2, z, \frac{t \cdot y}{z}\right)}}{y}} \]
    4. associate-/l*96.9%

      \[\leadsto x + \frac{2}{\frac{\mathsf{fma}\left(-2, z, \color{blue}{\frac{t}{\frac{z}{y}}}\right)}{y}} \]
  6. Applied egg-rr96.9%

    \[\leadsto x + \color{blue}{\frac{2}{\frac{\mathsf{fma}\left(-2, z, \frac{t}{\frac{z}{y}}\right)}{y}}} \]
  7. Taylor expanded in z around 0 99.8%

    \[\leadsto x + \frac{2}{\color{blue}{-2 \cdot \frac{z}{y} + \frac{t}{z}}} \]
  8. Final simplification99.8%

    \[\leadsto x + \frac{2}{-2 \cdot \frac{z}{y} + \frac{t}{z}} \]
  9. Add Preprocessing

Alternative 2: 89.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -11000 \lor \neg \left(z \leq 3 \cdot 10^{+46}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{2}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -11000.0) (not (<= z 3e+46)))
   (- x (/ y z))
   (+ x (* z (/ 2.0 t)))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -11000.0) || !(z <= 3e+46)) {
		tmp = x - (y / z);
	} else {
		tmp = x + (z * (2.0 / t));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((z <= (-11000.0d0)) .or. (.not. (z <= 3d+46))) then
        tmp = x - (y / z)
    else
        tmp = x + (z * (2.0d0 / t))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -11000.0) || !(z <= 3e+46)) {
		tmp = x - (y / z);
	} else {
		tmp = x + (z * (2.0 / t));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -11000.0) or not (z <= 3e+46):
		tmp = x - (y / z)
	else:
		tmp = x + (z * (2.0 / t))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -11000.0) || !(z <= 3e+46))
		tmp = Float64(x - Float64(y / z));
	else
		tmp = Float64(x + Float64(z * Float64(2.0 / t)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z <= -11000.0) || ~((z <= 3e+46)))
		tmp = x - (y / z);
	else
		tmp = x + (z * (2.0 / t));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -11000.0], N[Not[LessEqual[z, 3e+46]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(2.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -11000 \lor \neg \left(z \leq 3 \cdot 10^{+46}\right):\\
\;\;\;\;x - \frac{y}{z}\\

\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{2}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -11000 or 3.00000000000000023e46 < z

    1. Initial program 73.1%

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

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

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

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

        \[\leadsto x + \frac{\color{blue}{\left(-y\right) \cdot 2}}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}} \]
      5. associate-/r/83.4%

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

        \[\leadsto x + \frac{\color{blue}{-y \cdot 2}}{\left(z \cdot 2\right) \cdot z - y \cdot t} \cdot z \]
      7. distribute-rgt-neg-in83.4%

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

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\left(2 \cdot z\right)} \cdot z - y \cdot t} \cdot z \]
      10. associate-*l*83.4%

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}} \cdot z \]
    3. Simplified83.4%

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

      \[\leadsto \color{blue}{x + -1 \cdot \frac{y}{z}} \]
    6. Step-by-step derivation
      1. mul-1-neg91.4%

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

        \[\leadsto \color{blue}{x - \frac{y}{z}} \]
    7. Simplified91.4%

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

    if -11000 < z < 3.00000000000000023e46

    1. Initial program 94.5%

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

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

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

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

        \[\leadsto x + \frac{\color{blue}{\left(-y\right) \cdot 2}}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}} \]
      5. associate-/r/95.8%

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

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

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

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\left(2 \cdot z\right)} \cdot z - y \cdot t} \cdot z \]
      10. associate-*l*95.8%

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}} \cdot z \]
    3. Simplified95.8%

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

      \[\leadsto x + \color{blue}{\frac{2}{t}} \cdot z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -11000 \lor \neg \left(z \leq 3 \cdot 10^{+46}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{2}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 89.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -8100000 \lor \neg \left(z \leq 1.1 \cdot 10^{+50}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x - -2 \cdot \frac{z}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -8100000.0) (not (<= z 1.1e+50)))
   (- x (/ y z))
   (- x (* -2.0 (/ z t)))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -8100000.0) || !(z <= 1.1e+50)) {
		tmp = x - (y / z);
	} else {
		tmp = x - (-2.0 * (z / t));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((z <= (-8100000.0d0)) .or. (.not. (z <= 1.1d+50))) then
        tmp = x - (y / z)
    else
        tmp = x - ((-2.0d0) * (z / t))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -8100000.0) || !(z <= 1.1e+50)) {
		tmp = x - (y / z);
	} else {
		tmp = x - (-2.0 * (z / t));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -8100000.0) or not (z <= 1.1e+50):
		tmp = x - (y / z)
	else:
		tmp = x - (-2.0 * (z / t))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -8100000.0) || !(z <= 1.1e+50))
		tmp = Float64(x - Float64(y / z));
	else
		tmp = Float64(x - Float64(-2.0 * Float64(z / t)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z <= -8100000.0) || ~((z <= 1.1e+50)))
		tmp = x - (y / z);
	else
		tmp = x - (-2.0 * (z / t));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8100000.0], N[Not[LessEqual[z, 1.1e+50]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -8100000 \lor \neg \left(z \leq 1.1 \cdot 10^{+50}\right):\\
\;\;\;\;x - \frac{y}{z}\\

\mathbf{else}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -8.1e6 or 1.10000000000000008e50 < z

    1. Initial program 73.1%

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

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

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

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

        \[\leadsto x + \frac{\color{blue}{\left(-y\right) \cdot 2}}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}} \]
      5. associate-/r/83.4%

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

        \[\leadsto x + \frac{\color{blue}{-y \cdot 2}}{\left(z \cdot 2\right) \cdot z - y \cdot t} \cdot z \]
      7. distribute-rgt-neg-in83.4%

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

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\left(2 \cdot z\right)} \cdot z - y \cdot t} \cdot z \]
      10. associate-*l*83.4%

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}} \cdot z \]
    3. Simplified83.4%

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

      \[\leadsto \color{blue}{x + -1 \cdot \frac{y}{z}} \]
    6. Step-by-step derivation
      1. mul-1-neg91.4%

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

        \[\leadsto \color{blue}{x - \frac{y}{z}} \]
    7. Simplified91.4%

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

    if -8.1e6 < z < 1.10000000000000008e50

    1. Initial program 94.5%

      \[x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \]
    2. Step-by-step derivation
      1. associate-/l*95.3%

        \[\leadsto x - \color{blue}{\frac{y \cdot 2}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}}} \]
      2. associate-*l*95.3%

        \[\leadsto x - \frac{y \cdot 2}{\frac{\color{blue}{z \cdot \left(2 \cdot z\right)} - y \cdot t}{z}} \]
    3. Simplified95.3%

      \[\leadsto \color{blue}{x - \frac{y \cdot 2}{\frac{z \cdot \left(2 \cdot z\right) - y \cdot t}{z}}} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 88.9%

      \[\leadsto x - \color{blue}{-2 \cdot \frac{z}{t}} \]
    6. Step-by-step derivation
      1. *-commutative88.9%

        \[\leadsto x - \color{blue}{\frac{z}{t} \cdot -2} \]
    7. Simplified88.9%

      \[\leadsto x - \color{blue}{\frac{z}{t} \cdot -2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -8100000 \lor \neg \left(z \leq 1.1 \cdot 10^{+50}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x - -2 \cdot \frac{z}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -400000000000 \lor \neg \left(z \leq 0.0125\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -400000000000.0) (not (<= z 0.0125))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -400000000000.0) || !(z <= 0.0125)) {
		tmp = x - (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((z <= (-400000000000.0d0)) .or. (.not. (z <= 0.0125d0))) then
        tmp = x - (y / z)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -400000000000.0) || !(z <= 0.0125)) {
		tmp = x - (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -400000000000.0) or not (z <= 0.0125):
		tmp = x - (y / z)
	else:
		tmp = x
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -400000000000.0) || !(z <= 0.0125))
		tmp = Float64(x - Float64(y / z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z <= -400000000000.0) || ~((z <= 0.0125)))
		tmp = x - (y / z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -400000000000.0], N[Not[LessEqual[z, 0.0125]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -400000000000 \lor \neg \left(z \leq 0.0125\right):\\
\;\;\;\;x - \frac{y}{z}\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4e11 or 0.012500000000000001 < z

    1. Initial program 74.9%

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

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

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

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

        \[\leadsto x + \frac{\color{blue}{\left(-y\right) \cdot 2}}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}} \]
      5. associate-/r/84.9%

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

        \[\leadsto x + \frac{\color{blue}{-y \cdot 2}}{\left(z \cdot 2\right) \cdot z - y \cdot t} \cdot z \]
      7. distribute-rgt-neg-in84.9%

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

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\left(2 \cdot z\right)} \cdot z - y \cdot t} \cdot z \]
      10. associate-*l*84.9%

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{2 \cdot \left(z \cdot z\right)} - y \cdot t} \cdot z \]
      11. fma-neg84.9%

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}} \cdot z \]
    3. Simplified84.9%

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

      \[\leadsto \color{blue}{x + -1 \cdot \frac{y}{z}} \]
    6. Step-by-step derivation
      1. mul-1-neg86.2%

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

        \[\leadsto \color{blue}{x - \frac{y}{z}} \]
    7. Simplified86.2%

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

    if -4e11 < z < 0.012500000000000001

    1. Initial program 94.8%

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

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

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

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

        \[\leadsto x + \frac{\color{blue}{\left(-y\right) \cdot 2}}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}} \]
      5. associate-/r/95.5%

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

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

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

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\left(2 \cdot z\right)} \cdot z - y \cdot t} \cdot z \]
      10. associate-*l*95.5%

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

        \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}} \cdot z \]
    3. Simplified95.5%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification82.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -400000000000 \lor \neg \left(z \leq 0.0125\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 75.2% accurate, 17.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
	return x;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x
end function
public static double code(double x, double y, double z, double t) {
	return x;
}
def code(x, y, z, t):
	return x
function code(x, y, z, t)
	return x
end
function tmp = code(x, y, z, t)
	tmp = x;
end
code[x_, y_, z_, t_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 85.2%

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

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

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

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

      \[\leadsto x + \frac{\color{blue}{\left(-y\right) \cdot 2}}{\frac{\left(z \cdot 2\right) \cdot z - y \cdot t}{z}} \]
    5. associate-/r/90.4%

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

      \[\leadsto x + \frac{\color{blue}{-y \cdot 2}}{\left(z \cdot 2\right) \cdot z - y \cdot t} \cdot z \]
    7. distribute-rgt-neg-in90.4%

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

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

      \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\left(2 \cdot z\right)} \cdot z - y \cdot t} \cdot z \]
    10. associate-*l*90.4%

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

      \[\leadsto x + \frac{y \cdot -2}{\color{blue}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}} \cdot z \]
  3. Simplified90.4%

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

    \[\leadsto \color{blue}{x} \]
  6. Final simplification74.9%

    \[\leadsto x \]
  7. Add Preprocessing

Developer target: 99.9% accurate, 1.3× speedup?

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

\\
x - \frac{1}{\frac{z}{y} - \frac{\frac{t}{2}}{z}}
\end{array}

Reproduce

?
herbie shell --seed 2024026 
(FPCore (x y z t)
  :name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
  :precision binary64

  :herbie-target
  (- x (/ 1.0 (- (/ z y) (/ (/ t 2.0) z))))

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