Numeric.Log:$clog1p from log-domain-0.10.2.1, B

Percentage Accurate: 99.7% → 99.8%
Time: 6.6s
Alternatives: 9
Speedup: 1.0×

Specification

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

\\
\frac{x}{1 + \sqrt{x + 1}}
\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 9 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.7% accurate, 1.0× speedup?

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

\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}

Alternative 1: 99.8% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.00125:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.0390625, x, 0.0625\right), x, -0.125\right), x, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \left(1 - \sqrt{x - -1}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.00125)
   (* (fma (fma (fma -0.0390625 x 0.0625) x -0.125) x 0.5) x)
   (* -1.0 (- 1.0 (sqrt (- x -1.0))))))
double code(double x) {
	double tmp;
	if (x <= 0.00125) {
		tmp = fma(fma(fma(-0.0390625, x, 0.0625), x, -0.125), x, 0.5) * x;
	} else {
		tmp = -1.0 * (1.0 - sqrt((x - -1.0)));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 0.00125)
		tmp = Float64(fma(fma(fma(-0.0390625, x, 0.0625), x, -0.125), x, 0.5) * x);
	else
		tmp = Float64(-1.0 * Float64(1.0 - sqrt(Float64(x - -1.0))));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 0.00125], N[(N[(N[(N[(-0.0390625 * x + 0.0625), $MachinePrecision] * x + -0.125), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision], N[(-1.0 * N[(1.0 - N[Sqrt[N[(x - -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00125:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.0390625, x, 0.0625\right), x, -0.125\right), x, 0.5\right) \cdot x\\

\mathbf{else}:\\
\;\;\;\;-1 \cdot \left(1 - \sqrt{x - -1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.00125000000000000003

    1. Initial program 100.0%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + x \cdot \left(x \cdot \left(\frac{1}{16} + \frac{-5}{128} \cdot x\right) - \frac{1}{8}\right)\right)} \]
    4. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.0390625, x, 0.0625\right), x, -0.125\right), x, 0.5\right) \cdot x} \]

      if 0.00125000000000000003 < x

      1. Initial program 99.2%

        \[\frac{x}{1 + \sqrt{x + 1}} \]
      2. Add Preprocessing
      3. Step-by-step derivation
        1. lift-/.f64N/A

          \[\leadsto \color{blue}{\frac{x}{1 + \sqrt{x + 1}}} \]
        2. lift-+.f64N/A

          \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
        3. flip-+N/A

          \[\leadsto \frac{x}{\color{blue}{\frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}} \]
        4. associate-/r/N/A

          \[\leadsto \color{blue}{\frac{x}{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}} \cdot \left(1 - \sqrt{x + 1}\right)} \]
        5. lower-*.f64N/A

          \[\leadsto \color{blue}{\frac{x}{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}} \cdot \left(1 - \sqrt{x + 1}\right)} \]
      4. Applied rewrites100.0%

        \[\leadsto \color{blue}{\frac{x}{1 - \left(x - -1\right)} \cdot \left(1 - \sqrt{x - -1}\right)} \]
      5. Taylor expanded in x around 0

        \[\leadsto \color{blue}{-1} \cdot \left(1 - \sqrt{x - -1}\right) \]
      6. Step-by-step derivation
        1. Applied rewrites100.0%

          \[\leadsto \color{blue}{-1} \cdot \left(1 - \sqrt{x - -1}\right) \]
      7. Recombined 2 regimes into one program.
      8. Add Preprocessing

      Alternative 2: 99.8% accurate, 1.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.000225:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \left(1 - \sqrt{x - -1}\right)\\ \end{array} \end{array} \]
      (FPCore (x)
       :precision binary64
       (if (<= x 0.000225)
         (* (fma (fma 0.0625 x -0.125) x 0.5) x)
         (* -1.0 (- 1.0 (sqrt (- x -1.0))))))
      double code(double x) {
      	double tmp;
      	if (x <= 0.000225) {
      		tmp = fma(fma(0.0625, x, -0.125), x, 0.5) * x;
      	} else {
      		tmp = -1.0 * (1.0 - sqrt((x - -1.0)));
      	}
      	return tmp;
      }
      
      function code(x)
      	tmp = 0.0
      	if (x <= 0.000225)
      		tmp = Float64(fma(fma(0.0625, x, -0.125), x, 0.5) * x);
      	else
      		tmp = Float64(-1.0 * Float64(1.0 - sqrt(Float64(x - -1.0))));
      	end
      	return tmp
      end
      
      code[x_] := If[LessEqual[x, 0.000225], N[(N[(N[(0.0625 * x + -0.125), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision], N[(-1.0 * N[(1.0 - N[Sqrt[N[(x - -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq 0.000225:\\
      \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;-1 \cdot \left(1 - \sqrt{x - -1}\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < 2.2499999999999999e-4

        1. Initial program 100.0%

          \[\frac{x}{1 + \sqrt{x + 1}} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)} \]
        4. Step-by-step derivation
          1. Applied rewrites99.9%

            \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x} \]

          if 2.2499999999999999e-4 < x

          1. Initial program 99.2%

            \[\frac{x}{1 + \sqrt{x + 1}} \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-/.f64N/A

              \[\leadsto \color{blue}{\frac{x}{1 + \sqrt{x + 1}}} \]
            2. lift-+.f64N/A

              \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
            3. flip-+N/A

              \[\leadsto \frac{x}{\color{blue}{\frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 - \sqrt{x + 1}}}} \]
            4. associate-/r/N/A

              \[\leadsto \color{blue}{\frac{x}{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}} \cdot \left(1 - \sqrt{x + 1}\right)} \]
            5. lower-*.f64N/A

              \[\leadsto \color{blue}{\frac{x}{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}} \cdot \left(1 - \sqrt{x + 1}\right)} \]
          4. Applied rewrites100.0%

            \[\leadsto \color{blue}{\frac{x}{1 - \left(x - -1\right)} \cdot \left(1 - \sqrt{x - -1}\right)} \]
          5. Taylor expanded in x around 0

            \[\leadsto \color{blue}{-1} \cdot \left(1 - \sqrt{x - -1}\right) \]
          6. Step-by-step derivation
            1. Applied rewrites100.0%

              \[\leadsto \color{blue}{-1} \cdot \left(1 - \sqrt{x - -1}\right) \]
          7. Recombined 2 regimes into one program.
          8. Add Preprocessing

          Alternative 3: 99.7% accurate, 1.0× speedup?

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

            \[\frac{x}{1 + \sqrt{x + 1}} \]
          2. Add Preprocessing
          3. Final simplification99.7%

            \[\leadsto \frac{x}{1 + \sqrt{x - -1}} \]
          4. Add Preprocessing

          Alternative 4: 98.8% accurate, 1.2× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.3:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} - 1\\ \end{array} \end{array} \]
          (FPCore (x)
           :precision binary64
           (if (<= x 2.3) (* (fma (fma 0.0625 x -0.125) x 0.5) x) (- (sqrt x) 1.0)))
          double code(double x) {
          	double tmp;
          	if (x <= 2.3) {
          		tmp = fma(fma(0.0625, x, -0.125), x, 0.5) * x;
          	} else {
          		tmp = sqrt(x) - 1.0;
          	}
          	return tmp;
          }
          
          function code(x)
          	tmp = 0.0
          	if (x <= 2.3)
          		tmp = Float64(fma(fma(0.0625, x, -0.125), x, 0.5) * x);
          	else
          		tmp = Float64(sqrt(x) - 1.0);
          	end
          	return tmp
          end
          
          code[x_] := If[LessEqual[x, 2.3], N[(N[(N[(0.0625 * x + -0.125), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] - 1.0), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq 2.3:\\
          \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;\sqrt{x} - 1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < 2.2999999999999998

            1. Initial program 100.0%

              \[\frac{x}{1 + \sqrt{x + 1}} \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)} \]
            4. Step-by-step derivation
              1. Applied rewrites99.9%

                \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.0625, x, -0.125\right), x, 0.5\right) \cdot x} \]

              if 2.2999999999999998 < x

              1. Initial program 99.2%

                \[\frac{x}{1 + \sqrt{x + 1}} \]
              2. Add Preprocessing
              3. Taylor expanded in x around inf

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

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

              Alternative 5: 98.6% accurate, 1.2× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.3:\\ \;\;\;\;\mathsf{fma}\left(-0.125 \cdot x, x, 0.5 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} - 1\\ \end{array} \end{array} \]
              (FPCore (x)
               :precision binary64
               (if (<= x 2.3) (fma (* -0.125 x) x (* 0.5 x)) (- (sqrt x) 1.0)))
              double code(double x) {
              	double tmp;
              	if (x <= 2.3) {
              		tmp = fma((-0.125 * x), x, (0.5 * x));
              	} else {
              		tmp = sqrt(x) - 1.0;
              	}
              	return tmp;
              }
              
              function code(x)
              	tmp = 0.0
              	if (x <= 2.3)
              		tmp = fma(Float64(-0.125 * x), x, Float64(0.5 * x));
              	else
              		tmp = Float64(sqrt(x) - 1.0);
              	end
              	return tmp
              end
              
              code[x_] := If[LessEqual[x, 2.3], N[(N[(-0.125 * x), $MachinePrecision] * x + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] - 1.0), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;x \leq 2.3:\\
              \;\;\;\;\mathsf{fma}\left(-0.125 \cdot x, x, 0.5 \cdot x\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;\sqrt{x} - 1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if x < 2.2999999999999998

                1. Initial program 100.0%

                  \[\frac{x}{1 + \sqrt{x + 1}} \]
                2. Add Preprocessing
                3. Taylor expanded in x around 0

                  \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
                4. Step-by-step derivation
                  1. Applied rewrites99.7%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x} \]
                  2. Step-by-step derivation
                    1. Applied rewrites99.8%

                      \[\leadsto \mathsf{fma}\left(-0.125 \cdot x, \color{blue}{x}, 0.5 \cdot x\right) \]

                    if 2.2999999999999998 < x

                    1. Initial program 99.2%

                      \[\frac{x}{1 + \sqrt{x + 1}} \]
                    2. Add Preprocessing
                    3. Taylor expanded in x around inf

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

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

                    Alternative 6: 98.6% accurate, 1.4× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.3:\\ \;\;\;\;\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} - 1\\ \end{array} \end{array} \]
                    (FPCore (x)
                     :precision binary64
                     (if (<= x 2.3) (* (fma -0.125 x 0.5) x) (- (sqrt x) 1.0)))
                    double code(double x) {
                    	double tmp;
                    	if (x <= 2.3) {
                    		tmp = fma(-0.125, x, 0.5) * x;
                    	} else {
                    		tmp = sqrt(x) - 1.0;
                    	}
                    	return tmp;
                    }
                    
                    function code(x)
                    	tmp = 0.0
                    	if (x <= 2.3)
                    		tmp = Float64(fma(-0.125, x, 0.5) * x);
                    	else
                    		tmp = Float64(sqrt(x) - 1.0);
                    	end
                    	return tmp
                    end
                    
                    code[x_] := If[LessEqual[x, 2.3], N[(N[(-0.125 * x + 0.5), $MachinePrecision] * x), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] - 1.0), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;x \leq 2.3:\\
                    \;\;\;\;\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\sqrt{x} - 1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if x < 2.2999999999999998

                      1. Initial program 100.0%

                        \[\frac{x}{1 + \sqrt{x + 1}} \]
                      2. Add Preprocessing
                      3. Taylor expanded in x around 0

                        \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
                      4. Step-by-step derivation
                        1. Applied rewrites99.7%

                          \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x} \]

                        if 2.2999999999999998 < x

                        1. Initial program 99.2%

                          \[\frac{x}{1 + \sqrt{x + 1}} \]
                        2. Add Preprocessing
                        3. Taylor expanded in x around inf

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

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

                        Alternative 7: 97.8% accurate, 1.6× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 2.5:\\ \;\;\;\;\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \end{array} \]
                        (FPCore (x)
                         :precision binary64
                         (if (<= x 2.5) (* (fma -0.125 x 0.5) x) (sqrt x)))
                        double code(double x) {
                        	double tmp;
                        	if (x <= 2.5) {
                        		tmp = fma(-0.125, x, 0.5) * x;
                        	} else {
                        		tmp = sqrt(x);
                        	}
                        	return tmp;
                        }
                        
                        function code(x)
                        	tmp = 0.0
                        	if (x <= 2.5)
                        		tmp = Float64(fma(-0.125, x, 0.5) * x);
                        	else
                        		tmp = sqrt(x);
                        	end
                        	return tmp
                        end
                        
                        code[x_] := If[LessEqual[x, 2.5], N[(N[(-0.125 * x + 0.5), $MachinePrecision] * x), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;x \leq 2.5:\\
                        \;\;\;\;\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\sqrt{x}\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if x < 2.5

                          1. Initial program 100.0%

                            \[\frac{x}{1 + \sqrt{x + 1}} \]
                          2. Add Preprocessing
                          3. Taylor expanded in x around 0

                            \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
                          4. Step-by-step derivation
                            1. Applied rewrites99.7%

                              \[\leadsto \color{blue}{\mathsf{fma}\left(-0.125, x, 0.5\right) \cdot x} \]

                            if 2.5 < x

                            1. Initial program 99.2%

                              \[\frac{x}{1 + \sqrt{x + 1}} \]
                            2. Add Preprocessing
                            3. Taylor expanded in x around inf

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

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

                            Alternative 8: 97.1% accurate, 1.6× speedup?

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

                              1. Initial program 100.0%

                                \[\frac{x}{1 + \sqrt{x + 1}} \]
                              2. Add Preprocessing
                              3. Taylor expanded in x around 0

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

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

                                if 4 < x

                                1. Initial program 99.2%

                                  \[\frac{x}{1 + \sqrt{x + 1}} \]
                                2. Add Preprocessing
                                3. Taylor expanded in x around inf

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

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

                                Alternative 9: 68.2% accurate, 4.7× speedup?

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

                                  \[\frac{x}{1 + \sqrt{x + 1}} \]
                                2. Add Preprocessing
                                3. Taylor expanded in x around 0

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

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

                                  Reproduce

                                  ?
                                  herbie shell --seed 2025056 
                                  (FPCore (x)
                                    :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
                                    :precision binary64
                                    (/ x (+ 1.0 (sqrt (+ x 1.0)))))