
(FPCore (x) :precision binary64 :pre TRUE (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return x / (1.0 + sqrt((x + 1.0)));
}
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = x / ((1) + (sqrt((x + (1))))) END code
\frac{x}{1 + \sqrt{x + 1}}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return x / (1.0 + sqrt((x + 1.0)));
}
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = x / ((1) + (sqrt((x + (1))))) END code
\frac{x}{1 + \sqrt{x + 1}}
(FPCore (x) :precision binary64 :pre TRUE (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 5e-6) (fma -0.125 (* x x) (* 0.5 x)) (+ (sqrt (+ 1.0 x)) -1.0)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 5e-6) {
tmp = fma(-0.125, (x * x), (0.5 * x));
} else {
tmp = sqrt((1.0 + x)) + -1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 5e-6) tmp = fma(-0.125, Float64(x * x), Float64(0.5 * x)); else tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0); end return tmp end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-6], N[(-0.125 * N[(x * x), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (50000000000000004090152695701565477293115691281855106353759765625e-70)) THEN (((-125e-3) * (x * x)) + ((5e-1) * x)) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(-0.125, x \cdot x, 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} + -1\\
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.0000000000000004e-6Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites65.8%
Applied rewrites65.8%
if 5.0000000000000004e-6 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.7%
Applied rewrites99.7%
Applied rewrites39.3%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 5e-6) (/ x (fma 0.5 x 2.0)) (+ (sqrt (+ 1.0 x)) -1.0)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 5e-6) {
tmp = x / fma(0.5, x, 2.0);
} else {
tmp = sqrt((1.0 + x)) + -1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 5e-6) tmp = Float64(x / fma(0.5, x, 2.0)); else tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0); end return tmp end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-6], N[(x / N[(0.5 * x + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (50000000000000004090152695701565477293115691281855106353759765625e-70)) THEN (x / (((5e-1) * x) + (2))) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, x, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} + -1\\
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.0000000000000004e-6Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites67.9%
Applied rewrites67.9%
if 5.0000000000000004e-6 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.7%
Applied rewrites99.7%
Applied rewrites39.3%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 5e-6) (* x (fma -0.125 x 0.5)) (+ (sqrt (+ 1.0 x)) -1.0)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 5e-6) {
tmp = x * fma(-0.125, x, 0.5);
} else {
tmp = sqrt((1.0 + x)) + -1.0;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 5e-6) tmp = Float64(x * fma(-0.125, x, 0.5)); else tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0); end return tmp end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-6], N[(x * N[(-0.125 * x + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (50000000000000004090152695701565477293115691281855106353759765625e-70)) THEN (x * (((-125e-3) * x) + (5e-1))) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(-0.125, x, 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} + -1\\
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.0000000000000004e-6Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites65.8%
Applied rewrites65.8%
if 5.0000000000000004e-6 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.7%
Applied rewrites99.7%
Applied rewrites39.3%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 1e-12) (* 0.5 x) (+ (sqrt (+ 1.0 x)) -1.0)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 1e-12) {
tmp = 0.5 * x;
} else {
tmp = sqrt((1.0 + x)) + -1.0;
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 1d-12) then
tmp = 0.5d0 * x
else
tmp = sqrt((1.0d0 + x)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x / (1.0 + Math.sqrt((x + 1.0)))) <= 1e-12) {
tmp = 0.5 * x;
} else {
tmp = Math.sqrt((1.0 + x)) + -1.0;
}
return tmp;
}
def code(x): tmp = 0 if (x / (1.0 + math.sqrt((x + 1.0)))) <= 1e-12: tmp = 0.5 * x else: tmp = math.sqrt((1.0 + x)) + -1.0 return tmp
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 1e-12) tmp = Float64(0.5 * x); else tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x / (1.0 + sqrt((x + 1.0)))) <= 1e-12) tmp = 0.5 * x; else tmp = sqrt((1.0 + x)) + -1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-12], N[(0.5 * x), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (99999999999999997988664762925561536725284350612952266601496376097202301025390625e-92)) THEN ((5e-1) * x) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 10^{-12}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} + -1\\
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 9.9999999999999998e-13Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites67.3%
if 9.9999999999999998e-13 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.7%
Applied rewrites99.7%
Applied rewrites39.3%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.05) (* 0.5 x) (sqrt x)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.05) {
tmp = 0.5 * x;
} else {
tmp = sqrt(x);
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 0.05d0) 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 / (1.0 + Math.sqrt((x + 1.0)))) <= 0.05) {
tmp = 0.5 * x;
} else {
tmp = Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (x / (1.0 + math.sqrt((x + 1.0)))) <= 0.05: tmp = 0.5 * x else: tmp = math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.05) tmp = Float64(0.5 * x); else tmp = sqrt(x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.05) tmp = 0.5 * x; else tmp = sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.05], N[(0.5 * x), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (5000000000000000277555756156289135105907917022705078125e-56)) THEN ((5e-1) * x) ELSE (sqrt(x)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.05:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.050000000000000003Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites67.3%
if 0.050000000000000003 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites34.5%
Applied rewrites34.6%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 4e-210) (sqrt 0.0) (sqrt x)))
double code(double x) {
double tmp;
if ((x / (1.0 + sqrt((x + 1.0)))) <= 4e-210) {
tmp = sqrt(0.0);
} else {
tmp = sqrt(x);
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 4d-210) then
tmp = sqrt(0.0d0)
else
tmp = sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x / (1.0 + Math.sqrt((x + 1.0)))) <= 4e-210) {
tmp = Math.sqrt(0.0);
} else {
tmp = Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (x / (1.0 + math.sqrt((x + 1.0)))) <= 4e-210: tmp = math.sqrt(0.0) else: tmp = math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 4e-210) tmp = sqrt(0.0); else tmp = sqrt(x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x / (1.0 + sqrt((x + 1.0)))) <= 4e-210) tmp = sqrt(0.0); else tmp = sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e-210], N[Sqrt[0.0], $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (40000000000000001754955922235892998006218353004534480350476593552086812312828762824609665667893470382148702525598865546093318435031640624626745900808864392768698828487063690213161547567176664403997963093444535205751393006391340634994537348728463689202749036892606246670413469482542891968475704029388092629395892275133681299899143423556785033464480203676385451229669899140176458712009917313966594515003167803012359338524600134372869624583143557517732978270358050059486718115895288627009090148714358370352073279718752019107341766357421875e-745)) THEN (sqrt((0))) ELSE (sqrt(x)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-210}:\\
\;\;\;\;\sqrt{0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\
\end{array}
if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 4.0000000000000002e-210Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites34.5%
Applied rewrites34.6%
Taylor expanded in undef-var around zero
Applied rewrites4.5%
if 4.0000000000000002e-210 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites34.5%
Applied rewrites34.6%
(FPCore (x) :precision binary64 :pre TRUE (sqrt x))
double code(double x) {
return sqrt(x);
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = sqrt(x)
end function
public static double code(double x) {
return Math.sqrt(x);
}
def code(x): return math.sqrt(x)
function code(x) return sqrt(x) end
function tmp = code(x) tmp = sqrt(x); end
code[x_] := N[Sqrt[x], $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = sqrt(x) END code
\sqrt{x}
Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites34.5%
Applied rewrites34.6%
herbie shell --seed 2026092
(FPCore (x)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
:precision binary64
(/ x (+ 1.0 (sqrt (+ x 1.0)))))