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

Percentage Accurate: 81.9% → 94.8%
Time: 4.1s
Alternatives: 6
Speedup: 1.4×

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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    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 6 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.9% 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)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    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: 94.8% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.00000000000000019e153 or 2.8000000000000002e136 < z

    1. Initial program 57.6%

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

      \[\leadsto x - \color{blue}{\frac{y}{z}} \]
    4. Step-by-step derivation
      1. Applied rewrites99.5%

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

      if -3.00000000000000019e153 < z < 2.8000000000000002e136

      1. Initial program 87.6%

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

        \[\leadsto \color{blue}{x - 2 \cdot \frac{y \cdot z}{2 \cdot {z}^{2} - t \cdot y}} \]
      4. Step-by-step derivation
        1. Applied rewrites92.9%

          \[\leadsto \color{blue}{\mathsf{fma}\left(-2 \cdot y, \frac{z}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)}, x\right)} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification94.7%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3 \cdot 10^{+153} \lor \neg \left(z \leq 2.8 \cdot 10^{+136}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-2 \cdot y, \frac{z}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)}, x\right)\\ \end{array} \]
      7. Add Preprocessing

      Alternative 2: 88.3% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+40} \lor \neg \left(z \leq 1.1 \cdot 10^{-50}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\ \end{array} \end{array} \]
      (FPCore (x y z t)
       :precision binary64
       (if (or (<= z -3.3e+40) (not (<= z 1.1e-50)))
         (- x (/ y z))
         (fma (/ z t) 2.0 x)))
      double code(double x, double y, double z, double t) {
      	double tmp;
      	if ((z <= -3.3e+40) || !(z <= 1.1e-50)) {
      		tmp = x - (y / z);
      	} else {
      		tmp = fma((z / t), 2.0, x);
      	}
      	return tmp;
      }
      
      function code(x, y, z, t)
      	tmp = 0.0
      	if ((z <= -3.3e+40) || !(z <= 1.1e-50))
      		tmp = Float64(x - Float64(y / z));
      	else
      		tmp = fma(Float64(z / t), 2.0, x);
      	end
      	return tmp
      end
      
      code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.3e+40], N[Not[LessEqual[z, 1.1e-50]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * 2.0 + x), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -3.3 \cdot 10^{+40} \lor \neg \left(z \leq 1.1 \cdot 10^{-50}\right):\\
      \;\;\;\;x - \frac{y}{z}\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(\frac{z}{t}, 2, x\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < -3.2999999999999998e40 or 1.0999999999999999e-50 < z

        1. Initial program 70.2%

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

          \[\leadsto x - \color{blue}{\frac{y}{z}} \]
        4. Step-by-step derivation
          1. Applied rewrites89.0%

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

          if -3.2999999999999998e40 < z < 1.0999999999999999e-50

          1. Initial program 90.2%

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

            \[\leadsto \color{blue}{x - -2 \cdot \frac{z}{t}} \]
          4. Step-by-step derivation
            1. Applied rewrites89.2%

              \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, 2, x\right)} \]
          5. Recombined 2 regimes into one program.
          6. Final simplification89.1%

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

          Alternative 3: 88.3% accurate, 1.4× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{+40} \lor \neg \left(z \leq 1.1 \cdot 10^{-50}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{2}{t}, x\right)\\ \end{array} \end{array} \]
          (FPCore (x y z t)
           :precision binary64
           (if (or (<= z -3.3e+40) (not (<= z 1.1e-50)))
             (- x (/ y z))
             (fma z (/ 2.0 t) x)))
          double code(double x, double y, double z, double t) {
          	double tmp;
          	if ((z <= -3.3e+40) || !(z <= 1.1e-50)) {
          		tmp = x - (y / z);
          	} else {
          		tmp = fma(z, (2.0 / t), x);
          	}
          	return tmp;
          }
          
          function code(x, y, z, t)
          	tmp = 0.0
          	if ((z <= -3.3e+40) || !(z <= 1.1e-50))
          		tmp = Float64(x - Float64(y / z));
          	else
          		tmp = fma(z, Float64(2.0 / t), x);
          	end
          	return tmp
          end
          
          code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.3e+40], N[Not[LessEqual[z, 1.1e-50]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], N[(z * N[(2.0 / t), $MachinePrecision] + x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -3.3 \cdot 10^{+40} \lor \neg \left(z \leq 1.1 \cdot 10^{-50}\right):\\
          \;\;\;\;x - \frac{y}{z}\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(z, \frac{2}{t}, x\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z < -3.2999999999999998e40 or 1.0999999999999999e-50 < z

            1. Initial program 70.2%

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

              \[\leadsto x - \color{blue}{\frac{y}{z}} \]
            4. Step-by-step derivation
              1. Applied rewrites89.0%

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

              if -3.2999999999999998e40 < z < 1.0999999999999999e-50

              1. Initial program 90.2%

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

                \[\leadsto \color{blue}{x - -2 \cdot \frac{z}{t}} \]
              4. Step-by-step derivation
                1. Applied rewrites89.2%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{t}, 2, x\right)} \]
                2. Step-by-step derivation
                  1. Applied rewrites89.1%

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

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

                Alternative 4: 80.9% accurate, 1.6× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{+62} \lor \neg \left(z \leq 2.8 \cdot 10^{-51}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
                (FPCore (x y z t)
                 :precision binary64
                 (if (or (<= z -2.1e+62) (not (<= z 2.8e-51))) (- x (/ y z)) x))
                double code(double x, double y, double z, double t) {
                	double tmp;
                	if ((z <= -2.1e+62) || !(z <= 2.8e-51)) {
                		tmp = x - (y / z);
                	} else {
                		tmp = x;
                	}
                	return tmp;
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(x, y, z, t)
                use fmin_fmax_functions
                    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.1d+62)) .or. (.not. (z <= 2.8d-51))) 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.1e+62) || !(z <= 2.8e-51)) {
                		tmp = x - (y / z);
                	} else {
                		tmp = x;
                	}
                	return tmp;
                }
                
                def code(x, y, z, t):
                	tmp = 0
                	if (z <= -2.1e+62) or not (z <= 2.8e-51):
                		tmp = x - (y / z)
                	else:
                		tmp = x
                	return tmp
                
                function code(x, y, z, t)
                	tmp = 0.0
                	if ((z <= -2.1e+62) || !(z <= 2.8e-51))
                		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.1e+62) || ~((z <= 2.8e-51)))
                		tmp = x - (y / z);
                	else
                		tmp = x;
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.1e+62], N[Not[LessEqual[z, 2.8e-51]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;z \leq -2.1 \cdot 10^{+62} \lor \neg \left(z \leq 2.8 \cdot 10^{-51}\right):\\
                \;\;\;\;x - \frac{y}{z}\\
                
                \mathbf{else}:\\
                \;\;\;\;x\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if z < -2.1e62 or 2.8e-51 < z

                  1. Initial program 70.1%

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

                    \[\leadsto x - \color{blue}{\frac{y}{z}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites91.2%

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

                    if -2.1e62 < z < 2.8e-51

                    1. Initial program 88.7%

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

                      \[\leadsto \color{blue}{x} \]
                    4. Step-by-step derivation
                      1. Applied rewrites67.0%

                        \[\leadsto \color{blue}{x} \]
                    5. Recombined 2 regimes into one program.
                    6. Final simplification79.0%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{+62} \lor \neg \left(z \leq 2.8 \cdot 10^{-51}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
                    7. Add Preprocessing

                    Alternative 5: 74.0% accurate, 1.7× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-168} \lor \neg \left(x \leq 1.05 \cdot 10^{-271}\right):\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-y}{z}\\ \end{array} \end{array} \]
                    (FPCore (x y z t)
                     :precision binary64
                     (if (or (<= x -6.2e-168) (not (<= x 1.05e-271))) x (/ (- y) z)))
                    double code(double x, double y, double z, double t) {
                    	double tmp;
                    	if ((x <= -6.2e-168) || !(x <= 1.05e-271)) {
                    		tmp = x;
                    	} else {
                    		tmp = -y / z;
                    	}
                    	return tmp;
                    }
                    
                    module fmin_fmax_functions
                        implicit none
                        private
                        public fmax
                        public fmin
                    
                        interface fmax
                            module procedure fmax88
                            module procedure fmax44
                            module procedure fmax84
                            module procedure fmax48
                        end interface
                        interface fmin
                            module procedure fmin88
                            module procedure fmin44
                            module procedure fmin84
                            module procedure fmin48
                        end interface
                    contains
                        real(8) function fmax88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmax44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmax84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmax48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                        end function
                        real(8) function fmin88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmin44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmin84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmin48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                        end function
                    end module
                    
                    real(8) function code(x, y, z, t)
                    use fmin_fmax_functions
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        real(8), intent (in) :: z
                        real(8), intent (in) :: t
                        real(8) :: tmp
                        if ((x <= (-6.2d-168)) .or. (.not. (x <= 1.05d-271))) then
                            tmp = x
                        else
                            tmp = -y / z
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double x, double y, double z, double t) {
                    	double tmp;
                    	if ((x <= -6.2e-168) || !(x <= 1.05e-271)) {
                    		tmp = x;
                    	} else {
                    		tmp = -y / z;
                    	}
                    	return tmp;
                    }
                    
                    def code(x, y, z, t):
                    	tmp = 0
                    	if (x <= -6.2e-168) or not (x <= 1.05e-271):
                    		tmp = x
                    	else:
                    		tmp = -y / z
                    	return tmp
                    
                    function code(x, y, z, t)
                    	tmp = 0.0
                    	if ((x <= -6.2e-168) || !(x <= 1.05e-271))
                    		tmp = x;
                    	else
                    		tmp = Float64(Float64(-y) / z);
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(x, y, z, t)
                    	tmp = 0.0;
                    	if ((x <= -6.2e-168) || ~((x <= 1.05e-271)))
                    		tmp = x;
                    	else
                    		tmp = -y / z;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[x_, y_, z_, t_] := If[Or[LessEqual[x, -6.2e-168], N[Not[LessEqual[x, 1.05e-271]], $MachinePrecision]], x, N[((-y) / z), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;x \leq -6.2 \cdot 10^{-168} \lor \neg \left(x \leq 1.05 \cdot 10^{-271}\right):\\
                    \;\;\;\;x\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\frac{-y}{z}\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if x < -6.2e-168 or 1.05e-271 < x

                      1. Initial program 84.3%

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

                        \[\leadsto \color{blue}{x} \]
                      4. Step-by-step derivation
                        1. Applied rewrites77.5%

                          \[\leadsto \color{blue}{x} \]

                        if -6.2e-168 < x < 1.05e-271

                        1. Initial program 56.4%

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

                          \[\leadsto \color{blue}{-2 \cdot \frac{y \cdot z}{2 \cdot {z}^{2} - t \cdot y}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites41.7%

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

                            \[\leadsto -1 \cdot \color{blue}{\frac{y}{z}} \]
                          3. Step-by-step derivation
                            1. Applied rewrites59.4%

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

                            \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{-168} \lor \neg \left(x \leq 1.05 \cdot 10^{-271}\right):\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-y}{z}\\ \end{array} \]
                          6. Add Preprocessing

                          Alternative 6: 74.6% accurate, 43.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;
                          }
                          
                          module fmin_fmax_functions
                              implicit none
                              private
                              public fmax
                              public fmin
                          
                              interface fmax
                                  module procedure fmax88
                                  module procedure fmax44
                                  module procedure fmax84
                                  module procedure fmax48
                              end interface
                              interface fmin
                                  module procedure fmin88
                                  module procedure fmin44
                                  module procedure fmin84
                                  module procedure fmin48
                              end interface
                          contains
                              real(8) function fmax88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmax44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmax84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmax48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                              end function
                              real(8) function fmin88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmin44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmin84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmin48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                              end function
                          end module
                          
                          real(8) function code(x, y, z, t)
                          use fmin_fmax_functions
                              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 79.5%

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

                            \[\leadsto \color{blue}{x} \]
                          4. Step-by-step derivation
                            1. Applied rewrites67.2%

                              \[\leadsto \color{blue}{x} \]
                            2. Add Preprocessing

                            Developer Target 1: 99.9% accurate, 0.8× 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)));
                            }
                            
                            module fmin_fmax_functions
                                implicit none
                                private
                                public fmax
                                public fmin
                            
                                interface fmax
                                    module procedure fmax88
                                    module procedure fmax44
                                    module procedure fmax84
                                    module procedure fmax48
                                end interface
                                interface fmin
                                    module procedure fmin88
                                    module procedure fmin44
                                    module procedure fmin84
                                    module procedure fmin48
                                end interface
                            contains
                                real(8) function fmax88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmax44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmax84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmax48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                end function
                                real(8) function fmin88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmin44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmin84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmin48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                end function
                            end module
                            
                            real(8) function code(x, y, z, t)
                            use fmin_fmax_functions
                                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 2025022 
                            (FPCore (x y z t)
                              :name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
                              :precision binary64
                            
                              :alt
                              (! :herbie-platform default (- x (/ 1 (- (/ z y) (/ (/ t 2) z)))))
                            
                              (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))