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

Percentage Accurate: 82.0% → 97.9%
Time: 8.8s
Alternatives: 5
Speedup: 1.5×

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: 82.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: 97.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 2 \cdot 10^{-135}:\\ \;\;\;\;x + z \cdot \frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z \cdot -2 + t \cdot \frac{y}{z}}, 2, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= z 2e-135)
   (+ x (* z (/ 2.0 (- t (* z (/ 2.0 (/ y z)))))))
   (fma (/ y (+ (* z -2.0) (* t (/ y z)))) 2.0 x)))
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= 2e-135) {
		tmp = x + (z * (2.0 / (t - (z * (2.0 / (y / z))))));
	} else {
		tmp = fma((y / ((z * -2.0) + (t * (y / z)))), 2.0, x);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (z <= 2e-135)
		tmp = Float64(x + Float64(z * Float64(2.0 / Float64(t - Float64(z * Float64(2.0 / Float64(y / z)))))));
	else
		tmp = fma(Float64(y / Float64(Float64(z * -2.0) + Float64(t * Float64(y / z)))), 2.0, x);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[z, 2e-135], N[(x + N[(z * N[(2.0 / N[(t - N[(z * N[(2.0 / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / N[(N[(z * -2.0), $MachinePrecision] + N[(t * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0 + x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{-135}:\\
\;\;\;\;x + z \cdot \frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z \cdot -2 + t \cdot \frac{y}{z}}, 2, x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 2.0000000000000001e-135

    1. Initial program 84.0%

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

      \[\leadsto \color{blue}{x + \frac{y}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)} \cdot \left(z \cdot -2\right)} \]
    3. Step-by-step derivation
      1. *-commutative91.4%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x + \color{blue}{\frac{-z \cdot -2}{-\frac{2 \cdot \left(z \cdot z\right) - y \cdot t}{y}}} \]
    5. Step-by-step derivation
      1. distribute-rgt-neg-in91.1%

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

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

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

        \[\leadsto x + \frac{z \cdot 2}{\frac{\color{blue}{0 - \left(2 \cdot \left(z \cdot z\right) - y \cdot t\right)}}{y}} \]
      5. cancel-sign-sub-inv91.0%

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

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

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

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

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

        \[\leadsto x + \frac{z \cdot 2}{\frac{\color{blue}{t \cdot \left(-\left(-y\right)\right)} - 2 \cdot \left(z \cdot z\right)}{y}} \]
      11. remove-double-neg91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x + \frac{2}{t - \frac{z \cdot 2}{\color{blue}{y \cdot \frac{1}{z}}}} \cdot z \]
      13. *-lft-identity98.7%

        \[\leadsto x + \frac{2}{t - \frac{z \cdot 2}{\color{blue}{1 \cdot \left(y \cdot \frac{1}{z}\right)}}} \cdot z \]
      14. times-frac98.7%

        \[\leadsto x + \frac{2}{t - \color{blue}{\frac{z}{1} \cdot \frac{2}{y \cdot \frac{1}{z}}}} \cdot z \]
      15. /-rgt-identity98.7%

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

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

      \[\leadsto x + \color{blue}{\frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}} \cdot z} \]

    if 2.0000000000000001e-135 < z

    1. Initial program 77.3%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z \cdot -2 + \frac{y}{z} \cdot t}, 2, x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.2%

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

Alternative 2: 98.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{+136}:\\
\;\;\;\;x + z \cdot \frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}}\\

\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\


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

    1. Initial program 85.6%

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

      \[\leadsto \color{blue}{x + \frac{y}{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)} \cdot \left(z \cdot -2\right)} \]
    3. Step-by-step derivation
      1. *-commutative93.0%

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

        \[\leadsto x + \left(z \cdot -2\right) \cdot \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(2, z \cdot z, -y \cdot t\right)}{y}}} \]
      3. un-div-inv92.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto x + \frac{-z \cdot -2}{-\frac{\color{blue}{2 \cdot \left(z \cdot z\right)} - y \cdot t}{y}} \]
    4. Applied egg-rr92.7%

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

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

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

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

        \[\leadsto x + \frac{z \cdot 2}{\frac{\color{blue}{0 - \left(2 \cdot \left(z \cdot z\right) - y \cdot t\right)}}{y}} \]
      5. cancel-sign-sub-inv92.6%

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

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

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

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

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

        \[\leadsto x + \frac{z \cdot 2}{\frac{\color{blue}{t \cdot \left(-\left(-y\right)\right)} - 2 \cdot \left(z \cdot z\right)}{y}} \]
      11. remove-double-neg92.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x + \frac{2}{t - \frac{z \cdot 2}{\color{blue}{y \cdot \frac{1}{z}}}} \cdot z \]
      13. *-lft-identity98.9%

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

        \[\leadsto x + \frac{2}{t - \color{blue}{\frac{z}{1} \cdot \frac{2}{y \cdot \frac{1}{z}}}} \cdot z \]
      15. /-rgt-identity98.9%

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

        \[\leadsto x + \frac{2}{t - z \cdot \frac{2}{\color{blue}{\frac{y}{z}}}} \cdot z \]
    8. Applied egg-rr98.9%

      \[\leadsto x + \color{blue}{\frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}} \cdot z} \]

    if 2.00000000000000012e136 < z

    1. Initial program 57.5%

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

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

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

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

        \[\leadsto \color{blue}{x - \frac{y}{z}} \]
    5. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 2 \cdot 10^{+136}:\\ \;\;\;\;x + z \cdot \frac{2}{t - z \cdot \frac{2}{\frac{y}{z}}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{z}\\ \end{array} \]

Alternative 3: 89.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.3 \cdot 10^{+39} \lor \neg \left(z \leq 0.0105\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 -2.3e+39) (not (<= z 0.0105)))
   (- x (/ y z))
   (- x (* -2.0 (/ z t)))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -2.3e+39) || !(z <= 0.0105)) {
		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 <= (-2.3d+39)) .or. (.not. (z <= 0.0105d0))) 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 <= -2.3e+39) || !(z <= 0.0105)) {
		tmp = x - (y / z);
	} else {
		tmp = x - (-2.0 * (z / t));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -2.3e+39) or not (z <= 0.0105):
		tmp = x - (y / z)
	else:
		tmp = x - (-2.0 * (z / t))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -2.3e+39) || !(z <= 0.0105))
		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 <= -2.3e+39) || ~((z <= 0.0105)))
		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, -2.3e+39], N[Not[LessEqual[z, 0.0105]], $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 -2.3 \cdot 10^{+39} \lor \neg \left(z \leq 0.0105\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 < -2.30000000000000012e39 or 0.0105000000000000007 < z

    1. Initial program 69.7%

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

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

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

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

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

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

    if -2.30000000000000012e39 < z < 0.0105000000000000007

    1. Initial program 90.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. *-commutative90.1%

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

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

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

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

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

        \[\leadsto x - z \cdot \frac{y \cdot 2}{\color{blue}{\left(\left(-z\right) \cdot 2\right) \cdot \left(-z\right)} - y \cdot t} \]
      7. cancel-sign-sub-inv93.4%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.3 \cdot 10^{+39} \lor \neg \left(z \leq 0.0105\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x - -2 \cdot \frac{z}{t}\\ \end{array} \]

Alternative 4: 81.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.15 \cdot 10^{+40} \lor \neg \left(z \leq 1.8 \cdot 10^{+136}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= z -2.15e+40) (not (<= z 1.8e+136))) (- x (/ y z)) x))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z <= -2.15e+40) || !(z <= 1.8e+136)) {
		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 <= (-2.15d+40)) .or. (.not. (z <= 1.8d+136))) 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 <= -2.15e+40) || !(z <= 1.8e+136)) {
		tmp = x - (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (z <= -2.15e+40) or not (z <= 1.8e+136):
		tmp = x - (y / z)
	else:
		tmp = x
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((z <= -2.15e+40) || !(z <= 1.8e+136))
		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 <= -2.15e+40) || ~((z <= 1.8e+136)))
		tmp = x - (y / z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.15e+40], N[Not[LessEqual[z, 1.8e+136]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.15 \cdot 10^{+40} \lor \neg \left(z \leq 1.8 \cdot 10^{+136}\right):\\
\;\;\;\;x - \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.1500000000000001e40 or 1.80000000000000003e136 < z

    1. Initial program 65.5%

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

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

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

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

        \[\leadsto \color{blue}{x - \frac{y}{z}} \]
    5. Simplified95.3%

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

    if -2.1500000000000001e40 < z < 1.80000000000000003e136

    1. Initial program 89.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.15 \cdot 10^{+40} \lor \neg \left(z \leq 1.8 \cdot 10^{+136}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 5: 74.9% 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 81.7%

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

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification80.5%

    \[\leadsto x \]

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