
(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 9 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 x) (sqrt (+ 1.0 x)))))
double code(double x) {
return 1.0 / (sqrt(x) + sqrt((1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x): return 1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} + \sqrt{1 + x}}
\end{array}
Initial program 54.5%
flip--54.6%
div-inv54.6%
add-sqr-sqrt54.4%
add-sqr-sqrt55.6%
associate--l+55.6%
Applied egg-rr55.6%
associate-*r/55.6%
*-rgt-identity55.6%
+-commutative55.6%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
+-commutative99.7%
+-commutative99.7%
Simplified99.7%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 5e-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 <= 5e-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 <= 5d-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 <= 5e-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 <= 5e-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 <= 5e-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 <= 5e-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, 5e-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 5 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) < 5.00000000000000024e-5Initial program 5.4%
flip--5.7%
div-inv5.7%
add-sqr-sqrt5.3%
add-sqr-sqrt7.7%
associate--l+7.7%
Applied egg-rr7.7%
associate-*r/7.7%
*-rgt-identity7.7%
+-commutative7.7%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around inf 99.1%
unpow-199.1%
metadata-eval99.1%
pow-sqr99.2%
rem-sqrt-square99.2%
rem-square-sqrt98.4%
fabs-sqr98.4%
rem-square-sqrt99.2%
Simplified99.2%
if 5.00000000000000024e-5 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) Initial program 99.9%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= (- (sqrt (+ 1.0 x)) (sqrt x)) 0.2) (* 0.5 (pow x -0.5)) (- (+ 1.0 (* x (+ 0.5 (* x (- (* x 0.0625) 0.125))))) (sqrt x))))
double code(double x) {
double tmp;
if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.2) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = (1.0 + (x * (0.5 + (x * ((x * 0.0625) - 0.125))))) - sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((sqrt((1.0d0 + x)) - sqrt(x)) <= 0.2d0) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = (1.0d0 + (x * (0.5d0 + (x * ((x * 0.0625d0) - 0.125d0))))) - sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((Math.sqrt((1.0 + x)) - Math.sqrt(x)) <= 0.2) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = (1.0 + (x * (0.5 + (x * ((x * 0.0625) - 0.125))))) - Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (math.sqrt((1.0 + x)) - math.sqrt(x)) <= 0.2: tmp = 0.5 * math.pow(x, -0.5) else: tmp = (1.0 + (x * (0.5 + (x * ((x * 0.0625) - 0.125))))) - math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) <= 0.2) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = Float64(Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * Float64(Float64(x * 0.0625) - 0.125))))) - sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.2) tmp = 0.5 * (x ^ -0.5); else tmp = (1.0 + (x * (0.5 + (x * ((x * 0.0625) - 0.125))))) - sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.2], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(x * N[(0.5 + N[(x * N[(N[(x * 0.0625), $MachinePrecision] - 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{1 + x} - \sqrt{x} \leq 0.2:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + x \cdot \left(0.5 + x \cdot \left(x \cdot 0.0625 - 0.125\right)\right)\right) - \sqrt{x}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) < 0.20000000000000001Initial program 6.2%
flip--6.5%
div-inv6.5%
add-sqr-sqrt6.1%
add-sqr-sqrt8.5%
associate--l+8.5%
Applied egg-rr8.5%
associate-*r/8.5%
*-rgt-identity8.5%
+-commutative8.5%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around inf 98.5%
unpow-198.5%
metadata-eval98.5%
pow-sqr98.6%
rem-sqrt-square98.6%
rem-square-sqrt97.9%
fabs-sqr97.9%
rem-square-sqrt98.6%
Simplified98.6%
if 0.20000000000000001 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) Initial program 100.0%
Taylor expanded in x around 0 99.3%
Final simplification98.9%
(FPCore (x) :precision binary64 (if (<= (- (sqrt (+ 1.0 x)) (sqrt x)) 0.2) (* 0.5 (pow x -0.5)) (- (+ 1.0 (* x (+ 0.5 (* x -0.125)))) (sqrt x))))
double code(double x) {
double tmp;
if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.2) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((sqrt((1.0d0 + x)) - sqrt(x)) <= 0.2d0) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = (1.0d0 + (x * (0.5d0 + (x * (-0.125d0))))) - sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((Math.sqrt((1.0 + x)) - Math.sqrt(x)) <= 0.2) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (math.sqrt((1.0 + x)) - math.sqrt(x)) <= 0.2: tmp = 0.5 * math.pow(x, -0.5) else: tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) <= 0.2) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = Float64(Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * -0.125)))) - sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.2) tmp = 0.5 * (x ^ -0.5); else tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.2], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(x * N[(0.5 + N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{1 + x} - \sqrt{x} \leq 0.2:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + x \cdot \left(0.5 + x \cdot -0.125\right)\right) - \sqrt{x}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) < 0.20000000000000001Initial program 6.2%
flip--6.5%
div-inv6.5%
add-sqr-sqrt6.1%
add-sqr-sqrt8.5%
associate--l+8.5%
Applied egg-rr8.5%
associate-*r/8.5%
*-rgt-identity8.5%
+-commutative8.5%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around inf 98.5%
unpow-198.5%
metadata-eval98.5%
pow-sqr98.6%
rem-sqrt-square98.6%
rem-square-sqrt97.9%
fabs-sqr97.9%
rem-square-sqrt98.6%
Simplified98.6%
if 0.20000000000000001 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) Initial program 100.0%
Taylor expanded in x around 0 99.2%
*-commutative99.2%
Simplified99.2%
Final simplification98.9%
(FPCore (x) :precision binary64 (if (<= (- (sqrt (+ 1.0 x)) (sqrt x)) 0.2) (* 0.5 (pow x -0.5)) (+ 1.0 (- (* x 0.5) (sqrt x)))))
double code(double x) {
double tmp;
if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.2) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = 1.0 + ((x * 0.5) - sqrt(x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((sqrt((1.0d0 + x)) - sqrt(x)) <= 0.2d0) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = 1.0d0 + ((x * 0.5d0) - sqrt(x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((Math.sqrt((1.0 + x)) - Math.sqrt(x)) <= 0.2) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = 1.0 + ((x * 0.5) - Math.sqrt(x));
}
return tmp;
}
def code(x): tmp = 0 if (math.sqrt((1.0 + x)) - math.sqrt(x)) <= 0.2: tmp = 0.5 * math.pow(x, -0.5) else: tmp = 1.0 + ((x * 0.5) - math.sqrt(x)) return tmp
function code(x) tmp = 0.0 if (Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) <= 0.2) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = Float64(1.0 + Float64(Float64(x * 0.5) - sqrt(x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.2) tmp = 0.5 * (x ^ -0.5); else tmp = 1.0 + ((x * 0.5) - sqrt(x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.2], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x * 0.5), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{1 + x} - \sqrt{x} \leq 0.2:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) < 0.20000000000000001Initial program 6.2%
flip--6.5%
div-inv6.5%
add-sqr-sqrt6.1%
add-sqr-sqrt8.5%
associate--l+8.5%
Applied egg-rr8.5%
associate-*r/8.5%
*-rgt-identity8.5%
+-commutative8.5%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around inf 98.5%
unpow-198.5%
metadata-eval98.5%
pow-sqr98.6%
rem-sqrt-square98.6%
rem-square-sqrt97.9%
fabs-sqr97.9%
rem-square-sqrt98.6%
Simplified98.6%
if 0.20000000000000001 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) Initial program 100.0%
Taylor expanded in x around 0 99.0%
associate--l+99.0%
*-commutative99.0%
Simplified99.0%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= (- (sqrt (+ 1.0 x)) (sqrt x)) 0.5) (* 0.5 (pow x -0.5)) (- 1.0 (sqrt x))))
double code(double x) {
double tmp;
if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.5) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = 1.0 - sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((sqrt((1.0d0 + x)) - sqrt(x)) <= 0.5d0) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = 1.0d0 - sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((Math.sqrt((1.0 + x)) - Math.sqrt(x)) <= 0.5) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = 1.0 - Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (math.sqrt((1.0 + x)) - math.sqrt(x)) <= 0.5: tmp = 0.5 * math.pow(x, -0.5) else: tmp = 1.0 - math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) <= 0.5) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = Float64(1.0 - sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.5) tmp = 0.5 * (x ^ -0.5); else tmp = 1.0 - sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.5], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{1 + x} - \sqrt{x} \leq 0.5:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{x}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) < 0.5Initial program 6.9%
flip--7.2%
div-inv7.2%
add-sqr-sqrt6.8%
add-sqr-sqrt9.2%
associate--l+9.2%
Applied egg-rr9.2%
associate-*r/9.2%
*-rgt-identity9.2%
+-commutative9.2%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around inf 97.9%
unpow-197.9%
metadata-eval97.9%
pow-sqr97.9%
rem-sqrt-square97.9%
rem-square-sqrt97.2%
fabs-sqr97.2%
rem-square-sqrt97.9%
Simplified97.9%
if 0.5 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) Initial program 100.0%
Taylor expanded in x around 0 98.2%
Final simplification98.1%
(FPCore (x) :precision binary64 (if (<= (- (sqrt (+ 1.0 x)) (sqrt x)) 0.5) (sqrt (/ 0.25 x)) (- 1.0 (sqrt x))))
double code(double x) {
double tmp;
if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.5) {
tmp = sqrt((0.25 / x));
} else {
tmp = 1.0 - sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((sqrt((1.0d0 + x)) - sqrt(x)) <= 0.5d0) then
tmp = sqrt((0.25d0 / x))
else
tmp = 1.0d0 - sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((Math.sqrt((1.0 + x)) - Math.sqrt(x)) <= 0.5) {
tmp = Math.sqrt((0.25 / x));
} else {
tmp = 1.0 - Math.sqrt(x);
}
return tmp;
}
def code(x): tmp = 0 if (math.sqrt((1.0 + x)) - math.sqrt(x)) <= 0.5: tmp = math.sqrt((0.25 / x)) else: tmp = 1.0 - math.sqrt(x) return tmp
function code(x) tmp = 0.0 if (Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) <= 0.5) tmp = sqrt(Float64(0.25 / x)); else tmp = Float64(1.0 - sqrt(x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((sqrt((1.0 + x)) - sqrt(x)) <= 0.5) tmp = sqrt((0.25 / x)); else tmp = 1.0 - sqrt(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 0.5], N[Sqrt[N[(0.25 / x), $MachinePrecision]], $MachinePrecision], N[(1.0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{1 + x} - \sqrt{x} \leq 0.5:\\
\;\;\;\;\sqrt{\frac{0.25}{x}}\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{x}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) < 0.5Initial program 6.9%
flip--7.2%
div-inv7.2%
add-sqr-sqrt6.8%
add-sqr-sqrt9.2%
associate--l+9.2%
Applied egg-rr9.2%
associate-*r/9.2%
*-rgt-identity9.2%
+-commutative9.2%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around inf 97.6%
*-commutative97.6%
Simplified97.6%
add-sqr-sqrt97.2%
sqrt-unprod97.6%
frac-times96.8%
metadata-eval96.8%
swap-sqr96.8%
add-sqr-sqrt97.1%
metadata-eval97.1%
Applied egg-rr97.1%
*-commutative97.1%
associate-/r*97.9%
metadata-eval97.9%
Simplified97.9%
if 0.5 < (-.f64 (sqrt.f64 (+.f64 x #s(literal 1 binary64))) (sqrt.f64 x)) Initial program 100.0%
Taylor expanded in x around 0 98.2%
Final simplification98.0%
(FPCore (x) :precision binary64 (sqrt (/ 0.25 x)))
double code(double x) {
return sqrt((0.25 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((0.25d0 / x))
end function
public static double code(double x) {
return Math.sqrt((0.25 / x));
}
def code(x): return math.sqrt((0.25 / x))
function code(x) return sqrt(Float64(0.25 / x)) end
function tmp = code(x) tmp = sqrt((0.25 / x)); end
code[x_] := N[Sqrt[N[(0.25 / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{0.25}{x}}
\end{array}
Initial program 54.5%
flip--54.6%
div-inv54.6%
add-sqr-sqrt54.4%
add-sqr-sqrt55.6%
associate--l+55.6%
Applied egg-rr55.6%
associate-*r/55.6%
*-rgt-identity55.6%
+-commutative55.6%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
+-commutative99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around inf 51.1%
*-commutative51.1%
Simplified51.1%
add-sqr-sqrt50.9%
sqrt-unprod51.1%
frac-times50.8%
metadata-eval50.8%
swap-sqr50.8%
add-sqr-sqrt50.9%
metadata-eval50.9%
Applied egg-rr50.9%
*-commutative50.9%
associate-/r*51.3%
metadata-eval51.3%
Simplified51.3%
(FPCore (x) :precision binary64 (sqrt x))
double code(double x) {
return sqrt(x);
}
real(8) function code(x)
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]
\begin{array}{l}
\\
\sqrt{x}
\end{array}
Initial program 54.5%
Taylor expanded in x around 0 51.1%
Taylor expanded in x around inf 1.7%
neg-mul-11.7%
Simplified1.7%
add-sqr-sqrt0.0%
sqrt-unprod6.1%
sqr-neg6.1%
add-sqr-sqrt6.1%
pow1/26.1%
Applied egg-rr6.1%
Taylor expanded in x around 0 6.1%
(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 2024191
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
:alt
(! :herbie-platform default (/ 1 (+ (sqrt (+ x 1)) (sqrt x))))
(- (sqrt (+ x 1.0)) (sqrt x)))