Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E

Percentage Accurate: 99.9% → 99.9%
Time: 2.5s
Alternatives: 7
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \left(1 - x\right) + y \cdot \sqrt{x} \end{array} \]
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
	return (1.0 - x) + (y * sqrt(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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
	return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y):
	return (1.0 - x) + (y * math.sqrt(x))
function code(x, y)
	return Float64(Float64(1.0 - x) + Float64(y * sqrt(x)))
end
function tmp = code(x, y)
	tmp = (1.0 - x) + (y * sqrt(x));
end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - x\right) + y \cdot \sqrt{x}
\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 7 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: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(1 - x\right) + y \cdot \sqrt{x} \end{array} \]
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
	return (1.0 - x) + (y * sqrt(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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
	return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y):
	return (1.0 - x) + (y * math.sqrt(x))
function code(x, y)
	return Float64(Float64(1.0 - x) + Float64(y * sqrt(x)))
end
function tmp = code(x, y)
	tmp = (1.0 - x) + (y * sqrt(x));
end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}

Alternative 1: 99.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\sqrt{x}, y, 1 - x\right) \end{array} \]
(FPCore (x y) :precision binary64 (fma (sqrt x) y (- 1.0 x)))
double code(double x, double y) {
	return fma(sqrt(x), y, (1.0 - x));
}
function code(x, y)
	return fma(sqrt(x), y, Float64(1.0 - x))
end
code[x_, y_] := N[(N[Sqrt[x], $MachinePrecision] * y + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(1 - x\right) + y \cdot \sqrt{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(1 - x\right) + y \cdot \sqrt{x}} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{y \cdot \sqrt{x} + \left(1 - x\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{y \cdot \sqrt{x}} + \left(1 - x\right) \]
    4. *-commutativeN/A

      \[\leadsto \color{blue}{\sqrt{x} \cdot y} + \left(1 - x\right) \]
    5. lower-fma.f6499.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)} \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)} \]
  5. Add Preprocessing

Alternative 2: 97.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 4.5 \cdot 10^{-18}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\ \mathbf{elif}\;x \leq 500000:\\ \;\;\;\;1 - x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, -x\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x 4.5e-18)
   (fma (sqrt x) y 1.0)
   (if (<= x 500000.0) (- 1.0 x) (fma (sqrt x) y (- x)))))
double code(double x, double y) {
	double tmp;
	if (x <= 4.5e-18) {
		tmp = fma(sqrt(x), y, 1.0);
	} else if (x <= 500000.0) {
		tmp = 1.0 - x;
	} else {
		tmp = fma(sqrt(x), y, -x);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (x <= 4.5e-18)
		tmp = fma(sqrt(x), y, 1.0);
	elseif (x <= 500000.0)
		tmp = Float64(1.0 - x);
	else
		tmp = fma(sqrt(x), y, Float64(-x));
	end
	return tmp
end
code[x_, y_] := If[LessEqual[x, 4.5e-18], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision], If[LessEqual[x, 500000.0], N[(1.0 - x), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * y + (-x)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.5 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\

\mathbf{elif}\;x \leq 500000:\\
\;\;\;\;1 - x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, -x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 4.49999999999999994e-18

    1. Initial program 99.9%

      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]
    4. Step-by-step derivation
      1. Applied rewrites99.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x}, y, 1\right)} \]

      if 4.49999999999999994e-18 < x < 5e5

      1. Initial program 100.0%

        \[\left(1 - x\right) + y \cdot \sqrt{x} \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

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

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

        if 5e5 < x

        1. Initial program 100.0%

          \[\left(1 - x\right) + y \cdot \sqrt{x} \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{\left(1 - x\right) + y \cdot \sqrt{x}} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{y \cdot \sqrt{x} + \left(1 - x\right)} \]
          3. lift-*.f64N/A

            \[\leadsto \color{blue}{y \cdot \sqrt{x}} + \left(1 - x\right) \]
          4. *-commutativeN/A

            \[\leadsto \color{blue}{\sqrt{x} \cdot y} + \left(1 - x\right) \]
          5. lower-fma.f64100.0

            \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)} \]
        4. Applied rewrites100.0%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)} \]
        5. Taylor expanded in x around inf

          \[\leadsto \mathsf{fma}\left(\sqrt{x}, y, \color{blue}{-1 \cdot x}\right) \]
        6. Step-by-step derivation
          1. Applied rewrites99.9%

            \[\leadsto \mathsf{fma}\left(\sqrt{x}, y, \color{blue}{-x}\right) \]
        7. Recombined 3 regimes into one program.
        8. Add Preprocessing

        Alternative 3: 63.3% accurate, 0.7× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(1 - x\right) + y \cdot \sqrt{x} \leq -0.5:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
        (FPCore (x y)
         :precision binary64
         (if (<= (+ (- 1.0 x) (* y (sqrt x))) -0.5) (- x) 1.0))
        double code(double x, double y) {
        	double tmp;
        	if (((1.0 - x) + (y * sqrt(x))) <= -0.5) {
        		tmp = -x;
        	} else {
        		tmp = 1.0;
        	}
        	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)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8) :: tmp
            if (((1.0d0 - x) + (y * sqrt(x))) <= (-0.5d0)) then
                tmp = -x
            else
                tmp = 1.0d0
            end if
            code = tmp
        end function
        
        public static double code(double x, double y) {
        	double tmp;
        	if (((1.0 - x) + (y * Math.sqrt(x))) <= -0.5) {
        		tmp = -x;
        	} else {
        		tmp = 1.0;
        	}
        	return tmp;
        }
        
        def code(x, y):
        	tmp = 0
        	if ((1.0 - x) + (y * math.sqrt(x))) <= -0.5:
        		tmp = -x
        	else:
        		tmp = 1.0
        	return tmp
        
        function code(x, y)
        	tmp = 0.0
        	if (Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) <= -0.5)
        		tmp = Float64(-x);
        	else
        		tmp = 1.0;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y)
        	tmp = 0.0;
        	if (((1.0 - x) + (y * sqrt(x))) <= -0.5)
        		tmp = -x;
        	else
        		tmp = 1.0;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.5], (-x), 1.0]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;\left(1 - x\right) + y \cdot \sqrt{x} \leq -0.5:\\
        \;\;\;\;-x\\
        
        \mathbf{else}:\\
        \;\;\;\;1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -0.5

          1. Initial program 99.9%

            \[\left(1 - x\right) + y \cdot \sqrt{x} \]
          2. Add Preprocessing
          3. Taylor expanded in y around 0

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

              \[\leadsto \color{blue}{1 - x} \]
            2. Taylor expanded in x around inf

              \[\leadsto -1 \cdot \color{blue}{x} \]
            3. Step-by-step derivation
              1. Applied rewrites59.7%

                \[\leadsto -x \]

              if -0.5 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x)))

              1. Initial program 99.9%

                \[\left(1 - x\right) + y \cdot \sqrt{x} \]
              2. Add Preprocessing
              3. Taylor expanded in y around 0

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

                  \[\leadsto \color{blue}{1 - x} \]
                2. Taylor expanded in x around 0

                  \[\leadsto 1 \]
                3. Step-by-step derivation
                  1. Applied rewrites63.2%

                    \[\leadsto 1 \]
                4. Recombined 2 regimes into one program.
                5. Add Preprocessing

                Alternative 4: 95.4% accurate, 0.8× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+53} \lor \neg \left(y \leq 3.3 \cdot 10^{+39}\right):\\ \;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \end{array} \]
                (FPCore (x y)
                 :precision binary64
                 (if (or (<= y -5.8e+53) (not (<= y 3.3e+39))) (fma (sqrt x) y 1.0) (- 1.0 x)))
                double code(double x, double y) {
                	double tmp;
                	if ((y <= -5.8e+53) || !(y <= 3.3e+39)) {
                		tmp = fma(sqrt(x), y, 1.0);
                	} else {
                		tmp = 1.0 - x;
                	}
                	return tmp;
                }
                
                function code(x, y)
                	tmp = 0.0
                	if ((y <= -5.8e+53) || !(y <= 3.3e+39))
                		tmp = fma(sqrt(x), y, 1.0);
                	else
                		tmp = Float64(1.0 - x);
                	end
                	return tmp
                end
                
                code[x_, y_] := If[Or[LessEqual[y, -5.8e+53], N[Not[LessEqual[y, 3.3e+39]], $MachinePrecision]], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;y \leq -5.8 \cdot 10^{+53} \lor \neg \left(y \leq 3.3 \cdot 10^{+39}\right):\\
                \;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;1 - x\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if y < -5.8000000000000004e53 or 3.30000000000000021e39 < y

                  1. Initial program 99.8%

                    \[\left(1 - x\right) + y \cdot \sqrt{x} \]
                  2. Add Preprocessing
                  3. Taylor expanded in x around 0

                    \[\leadsto \color{blue}{1 + \sqrt{x} \cdot y} \]
                  4. Step-by-step derivation
                    1. Applied rewrites96.0%

                      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x}, y, 1\right)} \]

                    if -5.8000000000000004e53 < y < 3.30000000000000021e39

                    1. Initial program 100.0%

                      \[\left(1 - x\right) + y \cdot \sqrt{x} \]
                    2. Add Preprocessing
                    3. Taylor expanded in y around 0

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

                        \[\leadsto \color{blue}{1 - x} \]
                    5. Recombined 2 regimes into one program.
                    6. Final simplification97.7%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+53} \lor \neg \left(y \leq 3.3 \cdot 10^{+39}\right):\\ \;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \]
                    7. Add Preprocessing

                    Alternative 5: 92.7% accurate, 0.8× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{+91} \lor \neg \left(y \leq 5.5 \cdot 10^{+67}\right):\\ \;\;\;\;\sqrt{x} \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \end{array} \]
                    (FPCore (x y)
                     :precision binary64
                     (if (or (<= y -4.5e+91) (not (<= y 5.5e+67))) (* (sqrt x) y) (- 1.0 x)))
                    double code(double x, double y) {
                    	double tmp;
                    	if ((y <= -4.5e+91) || !(y <= 5.5e+67)) {
                    		tmp = sqrt(x) * y;
                    	} else {
                    		tmp = 1.0 - 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)
                    use fmin_fmax_functions
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        real(8) :: tmp
                        if ((y <= (-4.5d+91)) .or. (.not. (y <= 5.5d+67))) then
                            tmp = sqrt(x) * y
                        else
                            tmp = 1.0d0 - x
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double x, double y) {
                    	double tmp;
                    	if ((y <= -4.5e+91) || !(y <= 5.5e+67)) {
                    		tmp = Math.sqrt(x) * y;
                    	} else {
                    		tmp = 1.0 - x;
                    	}
                    	return tmp;
                    }
                    
                    def code(x, y):
                    	tmp = 0
                    	if (y <= -4.5e+91) or not (y <= 5.5e+67):
                    		tmp = math.sqrt(x) * y
                    	else:
                    		tmp = 1.0 - x
                    	return tmp
                    
                    function code(x, y)
                    	tmp = 0.0
                    	if ((y <= -4.5e+91) || !(y <= 5.5e+67))
                    		tmp = Float64(sqrt(x) * y);
                    	else
                    		tmp = Float64(1.0 - x);
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(x, y)
                    	tmp = 0.0;
                    	if ((y <= -4.5e+91) || ~((y <= 5.5e+67)))
                    		tmp = sqrt(x) * y;
                    	else
                    		tmp = 1.0 - x;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[x_, y_] := If[Or[LessEqual[y, -4.5e+91], N[Not[LessEqual[y, 5.5e+67]], $MachinePrecision]], N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision], N[(1.0 - x), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;y \leq -4.5 \cdot 10^{+91} \lor \neg \left(y \leq 5.5 \cdot 10^{+67}\right):\\
                    \;\;\;\;\sqrt{x} \cdot y\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;1 - x\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if y < -4.5e91 or 5.49999999999999968e67 < y

                      1. Initial program 99.8%

                        \[\left(1 - x\right) + y \cdot \sqrt{x} \]
                      2. Add Preprocessing
                      3. Taylor expanded in y around inf

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

                          \[\leadsto \color{blue}{\sqrt{x} \cdot y} \]

                        if -4.5e91 < y < 5.49999999999999968e67

                        1. Initial program 100.0%

                          \[\left(1 - x\right) + y \cdot \sqrt{x} \]
                        2. Add Preprocessing
                        3. Taylor expanded in y around 0

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

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

                          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{+91} \lor \neg \left(y \leq 5.5 \cdot 10^{+67}\right):\\ \;\;\;\;\sqrt{x} \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 - x\\ \end{array} \]
                        7. Add Preprocessing

                        Alternative 6: 63.8% accurate, 5.5× speedup?

                        \[\begin{array}{l} \\ 1 - x \end{array} \]
                        (FPCore (x y) :precision binary64 (- 1.0 x))
                        double code(double x, double y) {
                        	return 1.0 - 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)
                        use fmin_fmax_functions
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            code = 1.0d0 - x
                        end function
                        
                        public static double code(double x, double y) {
                        	return 1.0 - x;
                        }
                        
                        def code(x, y):
                        	return 1.0 - x
                        
                        function code(x, y)
                        	return Float64(1.0 - x)
                        end
                        
                        function tmp = code(x, y)
                        	tmp = 1.0 - x;
                        end
                        
                        code[x_, y_] := N[(1.0 - x), $MachinePrecision]
                        
                        \begin{array}{l}
                        
                        \\
                        1 - x
                        \end{array}
                        
                        Derivation
                        1. Initial program 99.9%

                          \[\left(1 - x\right) + y \cdot \sqrt{x} \]
                        2. Add Preprocessing
                        3. Taylor expanded in y around 0

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

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

                          Alternative 7: 32.7% accurate, 22.0× speedup?

                          \[\begin{array}{l} \\ 1 \end{array} \]
                          (FPCore (x y) :precision binary64 1.0)
                          double code(double x, double y) {
                          	return 1.0;
                          }
                          
                          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)
                          use fmin_fmax_functions
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              code = 1.0d0
                          end function
                          
                          public static double code(double x, double y) {
                          	return 1.0;
                          }
                          
                          def code(x, y):
                          	return 1.0
                          
                          function code(x, y)
                          	return 1.0
                          end
                          
                          function tmp = code(x, y)
                          	tmp = 1.0;
                          end
                          
                          code[x_, y_] := 1.0
                          
                          \begin{array}{l}
                          
                          \\
                          1
                          \end{array}
                          
                          Derivation
                          1. Initial program 99.9%

                            \[\left(1 - x\right) + y \cdot \sqrt{x} \]
                          2. Add Preprocessing
                          3. Taylor expanded in y around 0

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

                              \[\leadsto \color{blue}{1 - x} \]
                            2. Taylor expanded in x around 0

                              \[\leadsto 1 \]
                            3. Step-by-step derivation
                              1. Applied rewrites30.6%

                                \[\leadsto 1 \]
                              2. Add Preprocessing

                              Reproduce

                              ?
                              herbie shell --seed 2025018 
                              (FPCore (x y)
                                :name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
                                :precision binary64
                                (+ (- 1.0 x) (* y (sqrt x))))