
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ 1.0 x)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((1.0 + x)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((1.0d0 + x)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((1.0 + x)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\end{array}
Initial program 56.8%
flip--57.2%
div-inv57.2%
add-sqr-sqrt57.5%
add-sqr-sqrt58.2%
associate--l+58.3%
Applied egg-rr58.3%
associate-*r/58.3%
*-rgt-identity58.3%
+-commutative58.3%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 4e-5) (* 0.5 (pow x -0.5)) t_0)))
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 4e-5) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x)) - sqrt(x)
if (t_0 <= 4d-5) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
double tmp;
if (t_0 <= 4e-5) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 4e-5: tmp = 0.5 * math.pow(x, -0.5) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) tmp = 0.0 if (t_0 <= 4e-5) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)) - sqrt(x); tmp = 0.0; if (t_0 <= 4e-5) tmp = 0.5 * (x ^ -0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e-5], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 4.00000000000000033e-5Initial program 5.4%
expm1-log1p-u5.4%
Applied egg-rr5.4%
expm1-log1p-u5.4%
+-commutative5.4%
flip--6.0%
flip3-+6.0%
associate-/r/6.0%
Applied egg-rr5.8%
+-commutative5.8%
associate-+l-46.4%
+-inverses46.4%
metadata-eval46.4%
associate-*l/46.4%
*-lft-identity46.4%
associate-+l+46.4%
*-commutative46.4%
+-commutative46.4%
+-commutative46.4%
Simplified46.4%
Taylor expanded in x around inf 61.8%
associate-+r+61.8%
+-commutative61.8%
associate-*r/61.8%
metadata-eval61.8%
Simplified61.8%
Taylor expanded in x around inf 99.2%
unpow-199.2%
sqr-pow99.3%
metadata-eval99.3%
metadata-eval99.3%
rem-sqrt-square99.3%
rem-square-sqrt98.5%
fabs-sqr98.5%
rem-square-sqrt99.3%
Simplified99.3%
if 4.00000000000000033e-5 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (if (<= x 0.38) (/ 1.0 (+ 1.0 (+ 1.0 (+ (pow x 1.5) -1.0)))) (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.38) {
tmp = 1.0 / (1.0 + (1.0 + (pow(x, 1.5) + -1.0)));
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.38d0) then
tmp = 1.0d0 / (1.0d0 + (1.0d0 + ((x ** 1.5d0) + (-1.0d0))))
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.38) {
tmp = 1.0 / (1.0 + (1.0 + (Math.pow(x, 1.5) + -1.0)));
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.38: tmp = 1.0 / (1.0 + (1.0 + (math.pow(x, 1.5) + -1.0))) else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.38) tmp = Float64(1.0 / Float64(1.0 + Float64(1.0 + Float64((x ^ 1.5) + -1.0)))); else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.38) tmp = 1.0 / (1.0 + (1.0 + ((x ^ 1.5) + -1.0))); else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.38], N[(1.0 / N[(1.0 + N[(1.0 + N[(N[Power[x, 1.5], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.38:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left({x}^{1.5} + -1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.38Initial program 99.9%
expm1-log1p-u99.9%
Applied egg-rr99.9%
expm1-log1p-u99.9%
+-commutative99.9%
flip--99.9%
flip3-+99.8%
associate-/r/99.9%
Applied egg-rr99.9%
+-commutative99.9%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
associate-*l/99.9%
*-lft-identity99.9%
associate-+l+99.9%
*-commutative99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 94.6%
expm1-log1p-u94.6%
log1p-define94.6%
expm1-undefine94.6%
add-exp-log94.6%
Applied egg-rr94.6%
associate--l+94.6%
Simplified94.6%
if 0.38 < x Initial program 8.7%
expm1-log1p-u8.7%
Applied egg-rr8.7%
expm1-log1p-u8.7%
+-commutative8.7%
flip--9.7%
flip3-+9.7%
associate-/r/9.7%
Applied egg-rr9.7%
+-commutative9.7%
associate-+l-48.6%
+-inverses48.6%
metadata-eval48.6%
associate-*l/48.6%
*-lft-identity48.6%
associate-+l+48.6%
*-commutative48.6%
+-commutative48.6%
+-commutative48.6%
Simplified48.6%
Taylor expanded in x around inf 62.0%
associate-+r+62.0%
+-commutative62.0%
associate-*r/62.0%
metadata-eval62.0%
Simplified62.0%
Taylor expanded in x around inf 96.7%
unpow-196.7%
sqr-pow96.8%
metadata-eval96.8%
metadata-eval96.8%
rem-sqrt-square96.8%
rem-square-sqrt96.1%
fabs-sqr96.1%
rem-square-sqrt96.8%
Simplified96.8%
Final simplification95.7%
(FPCore (x) :precision binary64 (if (<= x 0.38) (/ 1.0 (+ 1.0 (pow x 1.5))) (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.38) {
tmp = 1.0 / (1.0 + pow(x, 1.5));
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.38d0) then
tmp = 1.0d0 / (1.0d0 + (x ** 1.5d0))
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.38) {
tmp = 1.0 / (1.0 + Math.pow(x, 1.5));
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.38: tmp = 1.0 / (1.0 + math.pow(x, 1.5)) else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.38) tmp = Float64(1.0 / Float64(1.0 + (x ^ 1.5))); else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.38) tmp = 1.0 / (1.0 + (x ^ 1.5)); else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.38], N[(1.0 / N[(1.0 + N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.38:\\
\;\;\;\;\frac{1}{1 + {x}^{1.5}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.38Initial program 99.9%
expm1-log1p-u99.9%
Applied egg-rr99.9%
expm1-log1p-u99.9%
+-commutative99.9%
flip--99.9%
flip3-+99.8%
associate-/r/99.9%
Applied egg-rr99.9%
+-commutative99.9%
associate-+l-99.9%
+-inverses99.9%
metadata-eval99.9%
associate-*l/99.9%
*-lft-identity99.9%
associate-+l+99.9%
*-commutative99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 94.6%
if 0.38 < x Initial program 8.7%
expm1-log1p-u8.7%
Applied egg-rr8.7%
expm1-log1p-u8.7%
+-commutative8.7%
flip--9.7%
flip3-+9.7%
associate-/r/9.7%
Applied egg-rr9.7%
+-commutative9.7%
associate-+l-48.6%
+-inverses48.6%
metadata-eval48.6%
associate-*l/48.6%
*-lft-identity48.6%
associate-+l+48.6%
*-commutative48.6%
+-commutative48.6%
+-commutative48.6%
Simplified48.6%
Taylor expanded in x around inf 62.0%
associate-+r+62.0%
+-commutative62.0%
associate-*r/62.0%
metadata-eval62.0%
Simplified62.0%
Taylor expanded in x around inf 96.7%
unpow-196.7%
sqr-pow96.8%
metadata-eval96.8%
metadata-eval96.8%
rem-sqrt-square96.8%
rem-square-sqrt96.1%
fabs-sqr96.1%
rem-square-sqrt96.8%
Simplified96.8%
Final simplification95.7%
(FPCore (x) :precision binary64 (if (<= x 0.25) 1.0 (* 0.5 (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.25) {
tmp = 1.0;
} else {
tmp = 0.5 * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.25d0) then
tmp = 1.0d0
else
tmp = 0.5d0 * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.25) {
tmp = 1.0;
} else {
tmp = 0.5 * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.25: tmp = 1.0 else: tmp = 0.5 * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.25) tmp = 1.0; else tmp = Float64(0.5 * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.25) tmp = 1.0; else tmp = 0.5 * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.25], 1.0, N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.25:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.25Initial program 99.9%
Taylor expanded in x around 0 95.2%
if 0.25 < x Initial program 9.5%
expm1-log1p-u9.5%
Applied egg-rr9.5%
expm1-log1p-u9.5%
+-commutative9.5%
flip--10.4%
flip3-+10.4%
associate-/r/10.4%
Applied egg-rr10.4%
+-commutative10.4%
associate-+l-49.0%
+-inverses49.0%
metadata-eval49.0%
associate-*l/49.1%
*-lft-identity49.1%
associate-+l+49.1%
*-commutative49.1%
+-commutative49.1%
+-commutative49.1%
Simplified49.1%
Taylor expanded in x around inf 61.7%
associate-+r+61.7%
+-commutative61.7%
associate-*r/61.7%
metadata-eval61.7%
Simplified61.7%
Taylor expanded in x around inf 96.0%
unpow-196.0%
sqr-pow96.2%
metadata-eval96.2%
metadata-eval96.2%
rem-sqrt-square96.2%
rem-square-sqrt95.4%
fabs-sqr95.4%
rem-square-sqrt96.2%
Simplified96.2%
Final simplification95.7%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 56.8%
Taylor expanded in x around 0 53.2%
Final simplification53.2%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((x + 1.0)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x + 1} + \sqrt{x}}
\end{array}
herbie shell --seed 2024034
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))