2isqrt (example 3.6)

Percentage Accurate: 38.2% → 98.9%
Time: 4.0s
Alternatives: 10
Speedup: 1.5×

Specification

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

\\
\frac{1}{\sqrt{x}} - \frac{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 10 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: 38.2% accurate, 1.0× speedup?

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

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

Alternative 1: 98.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;x \leq 260000000:\\ \;\;\;\;\frac{t\_0 - \sqrt{x}}{\sqrt{x} \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (<= x 260000000.0)
     (/ (- t_0 (sqrt x)) (* (sqrt x) t_0))
     (* (pow x -1.5) 0.5))))
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if (x <= 260000000.0) {
		tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0);
	} else {
		tmp = pow(x, -1.5) * 0.5;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((x + 1.0d0))
    if (x <= 260000000.0d0) then
        tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0)
    else
        tmp = (x ** (-1.5d0)) * 0.5d0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = Math.sqrt((x + 1.0));
	double tmp;
	if (x <= 260000000.0) {
		tmp = (t_0 - Math.sqrt(x)) / (Math.sqrt(x) * t_0);
	} else {
		tmp = Math.pow(x, -1.5) * 0.5;
	}
	return tmp;
}
def code(x):
	t_0 = math.sqrt((x + 1.0))
	tmp = 0
	if x <= 260000000.0:
		tmp = (t_0 - math.sqrt(x)) / (math.sqrt(x) * t_0)
	else:
		tmp = math.pow(x, -1.5) * 0.5
	return tmp
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (x <= 260000000.0)
		tmp = Float64(Float64(t_0 - sqrt(x)) / Float64(sqrt(x) * t_0));
	else
		tmp = Float64((x ^ -1.5) * 0.5);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = sqrt((x + 1.0));
	tmp = 0.0;
	if (x <= 260000000.0)
		tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0);
	else
		tmp = (x ^ -1.5) * 0.5;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 260000000.0], N[(N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;x \leq 260000000:\\
\;\;\;\;\frac{t\_0 - \sqrt{x}}{\sqrt{x} \cdot t\_0}\\

\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\


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

    1. Initial program 79.2%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{x + 1}}} \]
      7. frac-subN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
      8. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      10. lower-*.f64N/A

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

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

        \[\leadsto \frac{1 \cdot \sqrt{\color{blue}{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      13. lower-*.f64N/A

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

        \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \color{blue}{\sqrt{x}} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      15. lower-*.f64N/A

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

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

        \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \color{blue}{\sqrt{x + 1}}} \]
      18. lift-+.f6481.8

        \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{\color{blue}{x + 1}}} \]
    4. Applied rewrites81.8%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]

    if 2.6e8 < x

    1. Initial program 35.0%

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

      \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
    5. Applied rewrites85.1%

      \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
    6. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \sqrt{\frac{1}{{x}^{3}}}} \]
    7. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{1}{{x}^{3}}} \]
      2. pow2N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{1}{{x}^{3}}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{1}{{x}^{3}}} \]
      4. pow2N/A

        \[\leadsto \frac{1}{2} \cdot \sqrt{\frac{1}{{x}^{3}}} \]
      5. *-commutativeN/A

        \[\leadsto \sqrt{\frac{1}{{x}^{3}}} \cdot \color{blue}{\frac{1}{2}} \]
      6. lower-*.f64N/A

        \[\leadsto \sqrt{\frac{1}{{x}^{3}}} \cdot \color{blue}{\frac{1}{2}} \]
      7. pow-flipN/A

        \[\leadsto \sqrt{{x}^{\left(\mathsf{neg}\left(3\right)\right)}} \cdot \frac{1}{2} \]
      8. metadata-evalN/A

        \[\leadsto \sqrt{{x}^{-3}} \cdot \frac{1}{2} \]
      9. sqrt-pow1N/A

        \[\leadsto {x}^{\left(\frac{-3}{2}\right)} \cdot \frac{1}{2} \]
      10. lower-pow.f64N/A

        \[\leadsto {x}^{\left(\frac{-3}{2}\right)} \cdot \frac{1}{2} \]
      11. metadata-eval99.4

        \[\leadsto {x}^{-1.5} \cdot 0.5 \]
    8. Applied rewrites99.4%

      \[\leadsto \color{blue}{{x}^{-1.5} \cdot 0.5} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 260000000:\\ \;\;\;\;\frac{\sqrt{x + 1} - \sqrt{x}}{\sqrt{x} \cdot \sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-1.5} \cdot 0.5\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, \frac{{x}^{-0.5} \cdot 0.375}{-x}\right)}{x} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (fma (pow x -0.5) 0.5 (/ (* (pow x -0.5) 0.375) (- x))) x))
double code(double x) {
	return fma(pow(x, -0.5), 0.5, ((pow(x, -0.5) * 0.375) / -x)) / x;
}
function code(x)
	return Float64(fma((x ^ -0.5), 0.5, Float64(Float64((x ^ -0.5) * 0.375) / Float64(-x))) / x)
end
code[x_] := N[(N[(N[Power[x, -0.5], $MachinePrecision] * 0.5 + N[(N[(N[Power[x, -0.5], $MachinePrecision] * 0.375), $MachinePrecision] / (-x)), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, \frac{{x}^{-0.5} \cdot 0.375}{-x}\right)}{x}
\end{array}
Derivation
  1. Initial program 36.7%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
  5. Applied rewrites84.3%

    \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
  6. Taylor expanded in x around inf

    \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{\color{blue}{x}} \]
  7. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
  8. Applied rewrites98.1%

    \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{\color{blue}{x}} \]
  9. Final simplification98.1%

    \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, \frac{{x}^{-0.5} \cdot 0.375}{-x}\right)}{x} \]
  10. Add Preprocessing

Alternative 3: 98.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \frac{\frac{{x}^{-0.5} \cdot 0.375}{-x}}{x} + \frac{\frac{0.5}{\sqrt{x}}}{x} \end{array} \]
(FPCore (x)
 :precision binary64
 (+ (/ (/ (* (pow x -0.5) 0.375) (- x)) x) (/ (/ 0.5 (sqrt x)) x)))
double code(double x) {
	return (((pow(x, -0.5) * 0.375) / -x) / x) + ((0.5 / sqrt(x)) / 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 = ((((x ** (-0.5d0)) * 0.375d0) / -x) / x) + ((0.5d0 / sqrt(x)) / x)
end function
public static double code(double x) {
	return (((Math.pow(x, -0.5) * 0.375) / -x) / x) + ((0.5 / Math.sqrt(x)) / x);
}
def code(x):
	return (((math.pow(x, -0.5) * 0.375) / -x) / x) + ((0.5 / math.sqrt(x)) / x)
function code(x)
	return Float64(Float64(Float64(Float64((x ^ -0.5) * 0.375) / Float64(-x)) / x) + Float64(Float64(0.5 / sqrt(x)) / x))
end
function tmp = code(x)
	tmp = ((((x ^ -0.5) * 0.375) / -x) / x) + ((0.5 / sqrt(x)) / x);
end
code[x_] := N[(N[(N[(N[(N[Power[x, -0.5], $MachinePrecision] * 0.375), $MachinePrecision] / (-x)), $MachinePrecision] / x), $MachinePrecision] + N[(N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{{x}^{-0.5} \cdot 0.375}{-x}}{x} + \frac{\frac{0.5}{\sqrt{x}}}{x}
\end{array}
Derivation
  1. Initial program 36.7%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
  5. Applied rewrites84.3%

    \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
  6. Taylor expanded in x around inf

    \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{\color{blue}{x}} \]
  7. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
  8. Applied rewrites98.1%

    \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{\color{blue}{x}} \]
  9. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-1}{2}}, \frac{1}{2}, -\frac{{x}^{\frac{-1}{2}} \cdot \frac{3}{8}}{x}\right)}{x} \]
    2. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\left(\frac{-1}{2}\right)}, \frac{1}{2}, -\frac{{x}^{\frac{-1}{2}} \cdot \frac{3}{8}}{x}\right)}{x} \]
    3. sqrt-pow2N/A

      \[\leadsto \frac{\mathsf{fma}\left({\left(\sqrt{x}\right)}^{-1}, \frac{1}{2}, -\frac{{x}^{\frac{-1}{2}} \cdot \frac{3}{8}}{x}\right)}{x} \]
    4. inv-powN/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{\sqrt{x}}, \frac{1}{2}, -\frac{{x}^{\frac{-1}{2}} \cdot \frac{3}{8}}{x}\right)}{x} \]
    5. lower-/.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{\sqrt{x}}, \frac{1}{2}, -\frac{{x}^{\frac{-1}{2}} \cdot \frac{3}{8}}{x}\right)}{x} \]
    6. lift-sqrt.f6498.0

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{\sqrt{x}}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{x} \]
  10. Applied rewrites98.0%

    \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{\sqrt{x}}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{x} \]
  11. Applied rewrites98.0%

    \[\leadsto \frac{\frac{{x}^{-0.5} \cdot 0.375}{-x}}{x} + \frac{\frac{0.5}{\sqrt{x}}}{\color{blue}{x}} \]
  12. Add Preprocessing

Alternative 4: 98.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \frac{\mathsf{fma}\left({x}^{-1.5}, -0.375, \frac{0.5}{\sqrt{x}}\right)}{x} \end{array} \]
(FPCore (x)
 :precision binary64
 (/ (fma (pow x -1.5) -0.375 (/ 0.5 (sqrt x))) x))
double code(double x) {
	return fma(pow(x, -1.5), -0.375, (0.5 / sqrt(x))) / x;
}
function code(x)
	return Float64(fma((x ^ -1.5), -0.375, Float64(0.5 / sqrt(x))) / x)
end
code[x_] := N[(N[(N[Power[x, -1.5], $MachinePrecision] * -0.375 + N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}

\\
\frac{\mathsf{fma}\left({x}^{-1.5}, -0.375, \frac{0.5}{\sqrt{x}}\right)}{x}
\end{array}
Derivation
  1. Initial program 36.7%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
  5. Applied rewrites84.3%

    \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
  6. Taylor expanded in x around inf

    \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{\color{blue}{x}} \]
  7. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
  8. Applied rewrites98.1%

    \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{\color{blue}{x}} \]
  9. Taylor expanded in x around 0

    \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} - \frac{3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
  10. Step-by-step derivation
    1. fp-cancel-sub-sign-invN/A

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \left(\mathsf{neg}\left(\frac{3}{8}\right)\right) \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    2. metadata-evalN/A

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    3. +-commutativeN/A

      \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
    4. lower-/.f64N/A

      \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
    5. +-commutativeN/A

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    6. *-commutativeN/A

      \[\leadsto \frac{\frac{\sqrt{{x}^{3}} \cdot \frac{1}{2} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    7. lower-fma.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left(\sqrt{{x}^{3}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    8. sqrt-pow1N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    9. lower-pow.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    10. metadata-evalN/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    11. lower-*.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    12. lift-sqrt.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    13. pow2N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
    14. lift-*.f6455.2

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
  11. Applied rewrites55.2%

    \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
  12. Taylor expanded in x around inf

    \[\leadsto \frac{\frac{-3}{8} \cdot \sqrt{\frac{1}{{x}^{3}}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
  13. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\sqrt{\frac{1}{{x}^{3}}} \cdot \frac{-3}{8} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
    2. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\sqrt{\frac{1}{{x}^{3}}}, \frac{-3}{8}, \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)}{x} \]
    3. pow-flipN/A

      \[\leadsto \frac{\mathsf{fma}\left(\sqrt{{x}^{\left(\mathsf{neg}\left(3\right)\right)}}, \frac{-3}{8}, \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)}{x} \]
    4. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left(\sqrt{{x}^{-3}}, \frac{-3}{8}, \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)}{x} \]
    5. sqrt-pow1N/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\left(\frac{-3}{2}\right)}, \frac{-3}{8}, \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)}{x} \]
    6. lower-pow.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\left(\frac{-3}{2}\right)}, \frac{-3}{8}, \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)}{x} \]
    7. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)}{x} \]
    8. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \sqrt{\frac{1}{x}} \cdot \frac{1}{2}\right)}{x} \]
    9. sqrt-divN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \frac{\sqrt{1}}{\sqrt{x}} \cdot \frac{1}{2}\right)}{x} \]
    10. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \frac{1}{\sqrt{x}} \cdot \frac{1}{2}\right)}{x} \]
    11. associate-*l/N/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \frac{1 \cdot \frac{1}{2}}{\sqrt{x}}\right)}{x} \]
    12. metadata-evalN/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \frac{\frac{1}{2}}{\sqrt{x}}\right)}{x} \]
    13. lower-/.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left({x}^{\frac{-3}{2}}, \frac{-3}{8}, \frac{\frac{1}{2}}{\sqrt{x}}\right)}{x} \]
    14. lift-sqrt.f6498.0

      \[\leadsto \frac{\mathsf{fma}\left({x}^{-1.5}, -0.375, \frac{0.5}{\sqrt{x}}\right)}{x} \]
  14. Applied rewrites98.0%

    \[\leadsto \frac{\mathsf{fma}\left({x}^{-1.5}, -0.375, \frac{0.5}{\sqrt{x}}\right)}{x} \]
  15. Add Preprocessing

Alternative 5: 98.6% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;x \leq 260000000:\\ \;\;\;\;\frac{t\_0 - \sqrt{x}}{\sqrt{x} \cdot t\_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{\sqrt{x}}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (<= x 260000000.0)
     (/ (- t_0 (sqrt x)) (* (sqrt x) t_0))
     (/ (/ 0.5 (sqrt x)) x))))
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if (x <= 260000000.0) {
		tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0);
	} else {
		tmp = (0.5 / sqrt(x)) / 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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((x + 1.0d0))
    if (x <= 260000000.0d0) then
        tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0)
    else
        tmp = (0.5d0 / sqrt(x)) / x
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = Math.sqrt((x + 1.0));
	double tmp;
	if (x <= 260000000.0) {
		tmp = (t_0 - Math.sqrt(x)) / (Math.sqrt(x) * t_0);
	} else {
		tmp = (0.5 / Math.sqrt(x)) / x;
	}
	return tmp;
}
def code(x):
	t_0 = math.sqrt((x + 1.0))
	tmp = 0
	if x <= 260000000.0:
		tmp = (t_0 - math.sqrt(x)) / (math.sqrt(x) * t_0)
	else:
		tmp = (0.5 / math.sqrt(x)) / x
	return tmp
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (x <= 260000000.0)
		tmp = Float64(Float64(t_0 - sqrt(x)) / Float64(sqrt(x) * t_0));
	else
		tmp = Float64(Float64(0.5 / sqrt(x)) / x);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = sqrt((x + 1.0));
	tmp = 0.0;
	if (x <= 260000000.0)
		tmp = (t_0 - sqrt(x)) / (sqrt(x) * t_0);
	else
		tmp = (0.5 / sqrt(x)) / x;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 260000000.0], N[(N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;x \leq 260000000:\\
\;\;\;\;\frac{t\_0 - \sqrt{x}}{\sqrt{x} \cdot t\_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{\sqrt{x}}}{x}\\


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

    1. Initial program 79.2%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{x + 1}}} \]
      7. frac-subN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
      8. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]
      9. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      10. lower-*.f64N/A

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

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

        \[\leadsto \frac{1 \cdot \sqrt{\color{blue}{x + 1}} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      13. lower-*.f64N/A

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

        \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \color{blue}{\sqrt{x}} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}} \]
      15. lower-*.f64N/A

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

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

        \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \color{blue}{\sqrt{x + 1}}} \]
      18. lift-+.f6481.8

        \[\leadsto \frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{\color{blue}{x + 1}}} \]
    4. Applied rewrites81.8%

      \[\leadsto \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}} \]

    if 2.6e8 < x

    1. Initial program 35.0%

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

      \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
    5. Applied rewrites85.1%

      \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
    6. Taylor expanded in x around inf

      \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{\color{blue}{x}} \]
    7. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
    8. Applied rewrites99.6%

      \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{\color{blue}{x}} \]
    9. Taylor expanded in x around 0

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} - \frac{3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    10. Step-by-step derivation
      1. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \left(\mathsf{neg}\left(\frac{3}{8}\right)\right) \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      3. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
      5. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\frac{\sqrt{{x}^{3}} \cdot \frac{1}{2} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\sqrt{{x}^{3}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      8. sqrt-pow1N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      9. lower-pow.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      11. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      12. lift-sqrt.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      13. pow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
      14. lift-*.f6455.0

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
    11. Applied rewrites55.0%

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
    12. Taylor expanded in x around inf

      \[\leadsto \frac{\frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
    13. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \frac{1}{2}}{x} \]
      2. sqrt-divN/A

        \[\leadsto \frac{\frac{\sqrt{1}}{\sqrt{x}} \cdot \frac{1}{2}}{x} \]
      3. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{2}}{x} \]
      4. associate-*l/N/A

        \[\leadsto \frac{\frac{1 \cdot \frac{1}{2}}{\sqrt{x}}}{x} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{\frac{1}{2}}{\sqrt{x}}}{x} \]
      6. lower-/.f64N/A

        \[\leadsto \frac{\frac{\frac{1}{2}}{\sqrt{x}}}{x} \]
      7. lift-sqrt.f6499.0

        \[\leadsto \frac{\frac{0.5}{\sqrt{x}}}{x} \]
    14. Applied rewrites99.0%

      \[\leadsto \frac{\frac{0.5}{\sqrt{x}}}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 260000000:\\ \;\;\;\;\frac{\sqrt{x + 1} - \sqrt{x}}{\sqrt{x} \cdot \sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{\sqrt{x}}}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 90000000:\\ \;\;\;\;\sqrt{\frac{1}{x}} - \frac{1}{\sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{\sqrt{x}}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 90000000.0)
   (- (sqrt (/ 1.0 x)) (/ 1.0 (sqrt (+ x 1.0))))
   (/ (/ 0.5 (sqrt x)) x)))
double code(double x) {
	double tmp;
	if (x <= 90000000.0) {
		tmp = sqrt((1.0 / x)) - (1.0 / sqrt((x + 1.0)));
	} else {
		tmp = (0.5 / sqrt(x)) / 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 <= 90000000.0d0) then
        tmp = sqrt((1.0d0 / x)) - (1.0d0 / sqrt((x + 1.0d0)))
    else
        tmp = (0.5d0 / sqrt(x)) / x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 90000000.0) {
		tmp = Math.sqrt((1.0 / x)) - (1.0 / Math.sqrt((x + 1.0)));
	} else {
		tmp = (0.5 / Math.sqrt(x)) / x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 90000000.0:
		tmp = math.sqrt((1.0 / x)) - (1.0 / math.sqrt((x + 1.0)))
	else:
		tmp = (0.5 / math.sqrt(x)) / x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 90000000.0)
		tmp = Float64(sqrt(Float64(1.0 / x)) - Float64(1.0 / sqrt(Float64(x + 1.0))));
	else
		tmp = Float64(Float64(0.5 / sqrt(x)) / x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 90000000.0)
		tmp = sqrt((1.0 / x)) - (1.0 / sqrt((x + 1.0)));
	else
		tmp = (0.5 / sqrt(x)) / x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 90000000.0], N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 90000000:\\
\;\;\;\;\sqrt{\frac{1}{x}} - \frac{1}{\sqrt{x + 1}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{\sqrt{x}}}{x}\\


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

    1. Initial program 81.8%

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

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

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

        \[\leadsto \frac{\sqrt{1}}{\color{blue}{\sqrt{x}}} - \frac{1}{\sqrt{x + 1}} \]
      4. sqrt-divN/A

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

        \[\leadsto \color{blue}{\sqrt{\frac{1}{x}}} - \frac{1}{\sqrt{x + 1}} \]
      6. inv-powN/A

        \[\leadsto \sqrt{\color{blue}{{x}^{-1}}} - \frac{1}{\sqrt{x + 1}} \]
      7. lower-pow.f6481.9

        \[\leadsto \sqrt{\color{blue}{{x}^{-1}}} - \frac{1}{\sqrt{x + 1}} \]
    4. Applied rewrites81.9%

      \[\leadsto \color{blue}{\sqrt{{x}^{-1}}} - \frac{1}{\sqrt{x + 1}} \]
    5. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \sqrt{\color{blue}{{x}^{-1}}} - \frac{1}{\sqrt{x + 1}} \]
      2. inv-powN/A

        \[\leadsto \sqrt{\color{blue}{\frac{1}{x}}} - \frac{1}{\sqrt{x + 1}} \]
      3. lower-/.f6481.9

        \[\leadsto \sqrt{\color{blue}{\frac{1}{x}}} - \frac{1}{\sqrt{x + 1}} \]
    6. Applied rewrites81.9%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{x}}} - \frac{1}{\sqrt{x + 1}} \]

    if 9e7 < x

    1. Initial program 35.1%

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

      \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
    5. Applied rewrites85.2%

      \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
    6. Taylor expanded in x around inf

      \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{\color{blue}{x}} \]
    7. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
    8. Applied rewrites99.6%

      \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{\color{blue}{x}} \]
    9. Taylor expanded in x around 0

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} - \frac{3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    10. Step-by-step derivation
      1. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \left(\mathsf{neg}\left(\frac{3}{8}\right)\right) \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      2. metadata-evalN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      3. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
      5. +-commutativeN/A

        \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\frac{\sqrt{{x}^{3}} \cdot \frac{1}{2} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left(\sqrt{{x}^{3}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      8. sqrt-pow1N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      9. lower-pow.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      10. metadata-evalN/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      11. lower-*.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      12. lift-sqrt.f64N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
      13. pow2N/A

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
      14. lift-*.f6455.2

        \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
    11. Applied rewrites55.2%

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
    12. Taylor expanded in x around inf

      \[\leadsto \frac{\frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
    13. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \frac{1}{2}}{x} \]
      2. sqrt-divN/A

        \[\leadsto \frac{\frac{\sqrt{1}}{\sqrt{x}} \cdot \frac{1}{2}}{x} \]
      3. metadata-evalN/A

        \[\leadsto \frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{2}}{x} \]
      4. associate-*l/N/A

        \[\leadsto \frac{\frac{1 \cdot \frac{1}{2}}{\sqrt{x}}}{x} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\frac{\frac{1}{2}}{\sqrt{x}}}{x} \]
      6. lower-/.f64N/A

        \[\leadsto \frac{\frac{\frac{1}{2}}{\sqrt{x}}}{x} \]
      7. lift-sqrt.f6498.8

        \[\leadsto \frac{\frac{0.5}{\sqrt{x}}}{x} \]
    14. Applied rewrites98.8%

      \[\leadsto \frac{\frac{0.5}{\sqrt{x}}}{x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 97.6% accurate, 1.5× speedup?

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

\\
\frac{\frac{0.5}{\sqrt{x}}}{x}
\end{array}
Derivation
  1. Initial program 36.7%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
  5. Applied rewrites84.3%

    \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
  6. Taylor expanded in x around inf

    \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{\color{blue}{x}} \]
  7. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{-1 \cdot \frac{\frac{-1}{8} \cdot \sqrt{\frac{1}{x}} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
  8. Applied rewrites98.1%

    \[\leadsto \frac{\mathsf{fma}\left({x}^{-0.5}, 0.5, -\frac{{x}^{-0.5} \cdot 0.375}{x}\right)}{\color{blue}{x}} \]
  9. Taylor expanded in x around 0

    \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} - \frac{3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
  10. Step-by-step derivation
    1. fp-cancel-sub-sign-invN/A

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \left(\mathsf{neg}\left(\frac{3}{8}\right)\right) \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    2. metadata-evalN/A

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    3. +-commutativeN/A

      \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
    4. lower-/.f64N/A

      \[\leadsto \frac{\frac{\frac{-3}{8} \cdot \sqrt{x} + \frac{1}{2} \cdot \sqrt{{x}^{3}}}{{x}^{2}}}{x} \]
    5. +-commutativeN/A

      \[\leadsto \frac{\frac{\frac{1}{2} \cdot \sqrt{{x}^{3}} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    6. *-commutativeN/A

      \[\leadsto \frac{\frac{\sqrt{{x}^{3}} \cdot \frac{1}{2} + \frac{-3}{8} \cdot \sqrt{x}}{{x}^{2}}}{x} \]
    7. lower-fma.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left(\sqrt{{x}^{3}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    8. sqrt-pow1N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    9. lower-pow.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\left(\frac{3}{2}\right)}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    10. metadata-evalN/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    11. lower-*.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    12. lift-sqrt.f64N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{{x}^{2}}}{x} \]
    13. pow2N/A

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{\frac{3}{2}}, \frac{1}{2}, \frac{-3}{8} \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
    14. lift-*.f6455.2

      \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
  11. Applied rewrites55.2%

    \[\leadsto \frac{\frac{\mathsf{fma}\left({x}^{1.5}, 0.5, -0.375 \cdot \sqrt{x}\right)}{x \cdot x}}{x} \]
  12. Taylor expanded in x around inf

    \[\leadsto \frac{\frac{1}{2} \cdot \sqrt{\frac{1}{x}}}{x} \]
  13. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \frac{\sqrt{\frac{1}{x}} \cdot \frac{1}{2}}{x} \]
    2. sqrt-divN/A

      \[\leadsto \frac{\frac{\sqrt{1}}{\sqrt{x}} \cdot \frac{1}{2}}{x} \]
    3. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{\sqrt{x}} \cdot \frac{1}{2}}{x} \]
    4. associate-*l/N/A

      \[\leadsto \frac{\frac{1 \cdot \frac{1}{2}}{\sqrt{x}}}{x} \]
    5. metadata-evalN/A

      \[\leadsto \frac{\frac{\frac{1}{2}}{\sqrt{x}}}{x} \]
    6. lower-/.f64N/A

      \[\leadsto \frac{\frac{\frac{1}{2}}{\sqrt{x}}}{x} \]
    7. lift-sqrt.f6496.7

      \[\leadsto \frac{\frac{0.5}{\sqrt{x}}}{x} \]
  14. Applied rewrites96.7%

    \[\leadsto \frac{\frac{0.5}{\sqrt{x}}}{x} \]
  15. Add Preprocessing

Alternative 8: 81.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \frac{0.5 \cdot \sqrt{x}}{x \cdot x} \end{array} \]
(FPCore (x) :precision binary64 (/ (* 0.5 (sqrt x)) (* x x)))
double code(double x) {
	return (0.5 * sqrt(x)) / (x * 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 * sqrt(x)) / (x * x)
end function
public static double code(double x) {
	return (0.5 * Math.sqrt(x)) / (x * x);
}
def code(x):
	return (0.5 * math.sqrt(x)) / (x * x)
function code(x)
	return Float64(Float64(0.5 * sqrt(x)) / Float64(x * x))
end
function tmp = code(x)
	tmp = (0.5 * sqrt(x)) / (x * x);
end
code[x_] := N[(N[(0.5 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5 \cdot \sqrt{x}}{x \cdot x}
\end{array}
Derivation
  1. Initial program 36.7%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{{x}^{2}}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot \left(1 + \frac{1}{2} \cdot x\right)\right) - \left(\frac{-1}{2} \cdot \sqrt{x} + \left(\frac{-1}{2} \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot \left(1 + \frac{1}{4} \cdot x\right)\right) + \frac{1}{2} \cdot \sqrt{\frac{1}{x}}\right)\right)}{\color{blue}{{x}^{2}}} \]
  5. Applied rewrites84.3%

    \[\leadsto \color{blue}{\frac{\left(\sqrt{{x}^{-5}} \cdot -0.5\right) \cdot \mathsf{fma}\left(0.5, x, 1\right) - \mathsf{fma}\left(-0.5, \sqrt{x}, \mathsf{fma}\left(\mathsf{fma}\left(0.25, x, 1\right) \cdot \sqrt{{x}^{-3}}, -0.5, 0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\right)\right)}{x \cdot x}} \]
  6. Taylor expanded in x around inf

    \[\leadsto \frac{\frac{1}{2} \cdot \sqrt{x}}{\color{blue}{x} \cdot x} \]
  7. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \frac{\frac{1}{2} \cdot \sqrt{x}}{x \cdot x} \]
    2. lift-sqrt.f6482.8

      \[\leadsto \frac{0.5 \cdot \sqrt{x}}{x \cdot x} \]
  8. Applied rewrites82.8%

    \[\leadsto \frac{0.5 \cdot \sqrt{x}}{\color{blue}{x} \cdot x} \]
  9. Add Preprocessing

Alternative 9: 5.6% accurate, 2.2× speedup?

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

\\
\frac{\sqrt{x}}{x}
\end{array}
Derivation
  1. Initial program 36.7%

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

    \[\leadsto \color{blue}{\frac{\sqrt{x} + x \cdot \left(\frac{1}{2} \cdot x - 1\right)}{x}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

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

      \[\leadsto \frac{x \cdot \left(\frac{1}{2} \cdot x - 1\right) + \sqrt{x}}{x} \]
    3. *-commutativeN/A

      \[\leadsto \frac{\left(\frac{1}{2} \cdot x - 1\right) \cdot x + \sqrt{x}}{x} \]
    4. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot x - 1, x, \sqrt{x}\right)}{x} \]
    5. lower--.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot x - 1, x, \sqrt{x}\right)}{x} \]
    6. lower-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot x - 1, x, \sqrt{x}\right)}{x} \]
    7. lift-sqrt.f643.5

      \[\leadsto \frac{\mathsf{fma}\left(0.5 \cdot x - 1, x, \sqrt{x}\right)}{x} \]
  5. Applied rewrites3.5%

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

    \[\leadsto \frac{\sqrt{x}}{x} \]
  7. Step-by-step derivation
    1. lift-sqrt.f645.8

      \[\leadsto \frac{\sqrt{x}}{x} \]
  8. Applied rewrites5.8%

    \[\leadsto \frac{\sqrt{x}}{x} \]
  9. Add Preprocessing

Alternative 10: 3.4% accurate, 8.2× 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 36.7%

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

    \[\leadsto \color{blue}{\frac{\sqrt{x} + x \cdot \left(\frac{1}{2} \cdot x - 1\right)}{x}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

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

      \[\leadsto \frac{x \cdot \left(\frac{1}{2} \cdot x - 1\right) + \sqrt{x}}{x} \]
    3. *-commutativeN/A

      \[\leadsto \frac{\left(\frac{1}{2} \cdot x - 1\right) \cdot x + \sqrt{x}}{x} \]
    4. lower-fma.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot x - 1, x, \sqrt{x}\right)}{x} \]
    5. lower--.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot x - 1, x, \sqrt{x}\right)}{x} \]
    6. lower-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(\frac{1}{2} \cdot x - 1, x, \sqrt{x}\right)}{x} \]
    7. lift-sqrt.f643.5

      \[\leadsto \frac{\mathsf{fma}\left(0.5 \cdot x - 1, x, \sqrt{x}\right)}{x} \]
  5. Applied rewrites3.5%

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

    \[\leadsto \frac{1}{2} \cdot \color{blue}{x} \]
  7. Step-by-step derivation
    1. lift-*.f643.6

      \[\leadsto 0.5 \cdot x \]
  8. Applied rewrites3.6%

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

Developer Target 1: 38.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ {x}^{-0.5} - {\left(x + 1\right)}^{-0.5} \end{array} \]
(FPCore (x) :precision binary64 (- (pow x -0.5) (pow (+ x 1.0) -0.5)))
double code(double x) {
	return pow(x, -0.5) - pow((x + 1.0), -0.5);
}
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 ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
end function
public static double code(double x) {
	return Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
def code(x):
	return math.pow(x, -0.5) - math.pow((x + 1.0), -0.5)
function code(x)
	return Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5))
end
function tmp = code(x)
	tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5);
end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}
\end{array}

Reproduce

?
herbie shell --seed 2025072 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64
  :pre (and (> x 1.0) (< x 1e+308))

  :alt
  (! :herbie-platform default (- (pow x -1/2) (pow (+ x 1) -1/2)))

  (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))