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

Percentage Accurate: 82.3% → 91.8%
Time: 4.5s
Alternatives: 5
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 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.3% 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: 91.8% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \leq 5 \cdot 10^{+177}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)}, -2 \cdot z, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 x (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t)))) < 5.0000000000000003e177

    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. 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 rewrites97.0%

        \[\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)} \]
      2. Step-by-step derivation
        1. Applied rewrites97.4%

          \[\leadsto \mathsf{fma}\left(\frac{y}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)}, \color{blue}{-2 \cdot z}, x\right) \]

        if 5.0000000000000003e177 < (-.f64 x (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))))

        1. Initial program 45.8%

          \[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 rewrites87.0%

            \[\leadsto \color{blue}{x} \]
        5. Recombined 2 regimes into one program.
        6. Add Preprocessing

        Alternative 2: 91.5% accurate, 0.5× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \leq 5 \cdot 10^{+177}:\\ \;\;\;\;\mathsf{fma}\left(-2 \cdot y, \frac{z}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
        (FPCore (x y z t)
         :precision binary64
         (if (<= (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))) 5e+177)
           (fma (* -2.0 y) (/ z (fma (- t) y (* (* z z) 2.0))) x)
           x))
        double code(double x, double y, double z, double t) {
        	double tmp;
        	if ((x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))) <= 5e+177) {
        		tmp = fma((-2.0 * y), (z / fma(-t, y, ((z * z) * 2.0))), x);
        	} else {
        		tmp = x;
        	}
        	return tmp;
        }
        
        function code(x, y, z, t)
        	tmp = 0.0
        	if (Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) <= 5e+177)
        		tmp = fma(Float64(-2.0 * y), Float64(z / fma(Float64(-t), y, Float64(Float64(z * z) * 2.0))), x);
        	else
        		tmp = x;
        	end
        	return tmp
        end
        
        code[x_, y_, z_, t_] := If[LessEqual[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], 5e+177], N[(N[(-2.0 * y), $MachinePrecision] * N[(z / N[((-t) * y + N[(N[(z * z), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], x]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \leq 5 \cdot 10^{+177}:\\
        \;\;\;\;\mathsf{fma}\left(-2 \cdot y, \frac{z}{\mathsf{fma}\left(-t, y, \left(z \cdot z\right) \cdot 2\right)}, x\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (-.f64 x (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t)))) < 5.0000000000000003e177

          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. 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 rewrites97.0%

              \[\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)} \]

            if 5.0000000000000003e177 < (-.f64 x (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))))

            1. Initial program 45.8%

              \[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 rewrites87.0%

                \[\leadsto \color{blue}{x} \]
            5. Recombined 2 regimes into one program.
            6. Add Preprocessing

            Alternative 3: 89.0% accurate, 1.4× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{+51} \lor \neg \left(z \leq 1.55 \cdot 10^{-12}\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 -4.5e+51) (not (<= z 1.55e-12)))
               (- x (/ y z))
               (fma (/ z t) 2.0 x)))
            double code(double x, double y, double z, double t) {
            	double tmp;
            	if ((z <= -4.5e+51) || !(z <= 1.55e-12)) {
            		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 <= -4.5e+51) || !(z <= 1.55e-12))
            		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, -4.5e+51], N[Not[LessEqual[z, 1.55e-12]], $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 -4.5 \cdot 10^{+51} \lor \neg \left(z \leq 1.55 \cdot 10^{-12}\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 < -4.5e51 or 1.5500000000000001e-12 < z

              1. Initial program 75.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 rewrites88.8%

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

                if -4.5e51 < z < 1.5500000000000001e-12

                1. Initial program 90.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 inf

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

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

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

                Alternative 4: 81.9% accurate, 1.6× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+84} \lor \neg \left(z \leq 1.52 \cdot 10^{+32}\right):\\ \;\;\;\;x - \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
                (FPCore (x y z t)
                 :precision binary64
                 (if (or (<= z -1.55e+84) (not (<= z 1.52e+32))) (- x (/ y z)) x))
                double code(double x, double y, double z, double t) {
                	double tmp;
                	if ((z <= -1.55e+84) || !(z <= 1.52e+32)) {
                		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 <= (-1.55d+84)) .or. (.not. (z <= 1.52d+32))) 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 <= -1.55e+84) || !(z <= 1.52e+32)) {
                		tmp = x - (y / z);
                	} else {
                		tmp = x;
                	}
                	return tmp;
                }
                
                def code(x, y, z, t):
                	tmp = 0
                	if (z <= -1.55e+84) or not (z <= 1.52e+32):
                		tmp = x - (y / z)
                	else:
                		tmp = x
                	return tmp
                
                function code(x, y, z, t)
                	tmp = 0.0
                	if ((z <= -1.55e+84) || !(z <= 1.52e+32))
                		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 <= -1.55e+84) || ~((z <= 1.52e+32)))
                		tmp = x - (y / z);
                	else
                		tmp = x;
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.55e+84], N[Not[LessEqual[z, 1.52e+32]], $MachinePrecision]], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision], x]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;z \leq -1.55 \cdot 10^{+84} \lor \neg \left(z \leq 1.52 \cdot 10^{+32}\right):\\
                \;\;\;\;x - \frac{y}{z}\\
                
                \mathbf{else}:\\
                \;\;\;\;x\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if z < -1.55000000000000001e84 or 1.5200000000000001e32 < z

                  1. Initial program 73.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 y around 0

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

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

                    if -1.55000000000000001e84 < z < 1.5200000000000001e32

                    1. Initial program 90.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 rewrites83.2%

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

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

                    Alternative 5: 75.3% 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 83.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 rewrites81.8%

                        \[\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 2025018 
                      (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)))))