
(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 (pow (pow (+ (sqrt x) (sqrt (+ x 1.0))) 2.0) -0.5))
double code(double x) {
return pow(pow((sqrt(x) + sqrt((x + 1.0))), 2.0), -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((sqrt(x) + sqrt((x + 1.0d0))) ** 2.0d0) ** (-0.5d0)
end function
public static double code(double x) {
return Math.pow(Math.pow((Math.sqrt(x) + Math.sqrt((x + 1.0))), 2.0), -0.5);
}
def code(x): return math.pow(math.pow((math.sqrt(x) + math.sqrt((x + 1.0))), 2.0), -0.5)
function code(x) return (Float64(sqrt(x) + sqrt(Float64(x + 1.0))) ^ 2.0) ^ -0.5 end
function tmp = code(x) tmp = ((sqrt(x) + sqrt((x + 1.0))) ^ 2.0) ^ -0.5; end
code[x_] := N[Power[N[Power[N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left({\left(\sqrt{x} + \sqrt{x + 1}\right)}^{2}\right)}^{-0.5}
\end{array}
Initial program 51.1%
flip--51.3%
div-inv51.3%
add-sqr-sqrt51.7%
add-sqr-sqrt52.7%
associate--l+52.7%
Applied egg-rr52.7%
associate-*r/52.7%
*-rgt-identity52.7%
+-commutative52.7%
associate-+l-99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
+-commutative99.8%
add-sqr-sqrt99.6%
fma-def99.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
inv-pow99.8%
add-sqr-sqrt99.5%
unpow-prod-down99.4%
Applied egg-rr99.8%
+-commutative99.8%
unpow1/299.8%
metadata-eval99.8%
pow-sqr99.6%
hypot-1-def99.6%
pow-sqr99.7%
metadata-eval99.7%
metadata-eval99.7%
pow-sqr99.8%
metadata-eval99.8%
metadata-eval99.8%
sqr-pow99.8%
unpow199.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (- (sqrt (+ x 1.0)) (sqrt x)))) (if (<= t_0 1e-5) (* 0.5 (pow (sqrt x) -1.0)) t_0)))
double code(double x) {
double t_0 = sqrt((x + 1.0)) - sqrt(x);
double tmp;
if (t_0 <= 1e-5) {
tmp = 0.5 * pow(sqrt(x), -1.0);
} 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((x + 1.0d0)) - sqrt(x)
if (t_0 <= 1d-5) then
tmp = 0.5d0 * (sqrt(x) ** (-1.0d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((x + 1.0)) - Math.sqrt(x);
double tmp;
if (t_0 <= 1e-5) {
tmp = 0.5 * Math.pow(Math.sqrt(x), -1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = math.sqrt((x + 1.0)) - math.sqrt(x) tmp = 0 if t_0 <= 1e-5: tmp = 0.5 * math.pow(math.sqrt(x), -1.0) else: tmp = t_0 return tmp
function code(x) t_0 = Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) tmp = 0.0 if (t_0 <= 1e-5) tmp = Float64(0.5 * (sqrt(x) ^ -1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 1.0)) - sqrt(x); tmp = 0.0; if (t_0 <= 1e-5) tmp = 0.5 * (sqrt(x) ^ -1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(0.5 * N[Power[N[Sqrt[x], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1} - \sqrt{x}\\
\mathbf{if}\;t\_0 \leq 10^{-5}:\\
\;\;\;\;0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 1.00000000000000008e-5Initial program 5.2%
flip--5.7%
div-inv5.7%
add-sqr-sqrt6.1%
add-sqr-sqrt7.5%
associate--l+7.5%
Applied egg-rr7.5%
associate-*r/7.5%
*-rgt-identity7.5%
+-commutative7.5%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.0%
inv-pow99.0%
count-299.0%
unpow-prod-down99.0%
metadata-eval99.0%
Applied egg-rr99.0%
if 1.00000000000000008e-5 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 99.2%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x 1.25) (- (+ 1.0 (* x (+ 0.5 (* x -0.125)))) (sqrt x)) (* 0.5 (pow (sqrt x) -1.0))))
double code(double x) {
double tmp;
if (x <= 1.25) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x);
} else {
tmp = 0.5 * pow(sqrt(x), -1.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.25d0) then
tmp = (1.0d0 + (x * (0.5d0 + (x * (-0.125d0))))) - sqrt(x)
else
tmp = 0.5d0 * (sqrt(x) ** (-1.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.25) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - Math.sqrt(x);
} else {
tmp = 0.5 * Math.pow(Math.sqrt(x), -1.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.25: tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - math.sqrt(x) else: tmp = 0.5 * math.pow(math.sqrt(x), -1.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.25) tmp = Float64(Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * -0.125)))) - sqrt(x)); else tmp = Float64(0.5 * (sqrt(x) ^ -1.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.25) tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x); else tmp = 0.5 * (sqrt(x) ^ -1.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.25], N[(N[(1.0 + N[(x * N[(0.5 + N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[N[Sqrt[x], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.25:\\
\;\;\;\;\left(1 + x \cdot \left(0.5 + x \cdot -0.125\right)\right) - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {\left(\sqrt{x}\right)}^{-1}\\
\end{array}
\end{array}
if x < 1.25Initial program 100.0%
Taylor expanded in x around 0 99.6%
+-commutative99.6%
unpow299.6%
associate-*r*99.6%
distribute-rgt-out99.6%
*-commutative99.6%
Simplified99.6%
if 1.25 < x Initial program 7.3%
flip--7.8%
div-inv7.8%
add-sqr-sqrt8.5%
add-sqr-sqrt10.3%
associate--l+10.3%
Applied egg-rr10.3%
associate-*r/10.3%
*-rgt-identity10.3%
+-commutative10.3%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 97.4%
inv-pow97.4%
count-297.4%
unpow-prod-down97.4%
metadata-eval97.4%
Applied egg-rr97.4%
Final simplification98.4%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt x) (sqrt (+ x 1.0)))))
double code(double x) {
return 1.0 / (sqrt(x) + sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) + sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + Math.sqrt((x + 1.0)));
}
def code(x): return 1.0 / (math.sqrt(x) + math.sqrt((x + 1.0)))
function code(x) return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + sqrt((x + 1.0))); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} + \sqrt{x + 1}}
\end{array}
Initial program 51.1%
flip--51.3%
div-inv51.3%
add-sqr-sqrt51.7%
add-sqr-sqrt52.7%
associate--l+52.7%
Applied egg-rr52.7%
associate-*r/52.7%
*-rgt-identity52.7%
+-commutative52.7%
associate-+l-99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ 1.0 (- (* x 0.5) (sqrt x))) (if (<= x 2e+205) (* x (/ 1.0 (* 2.0 (pow x 1.5)))) (/ (sqrt x) x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 + ((x * 0.5) - sqrt(x));
} else if (x <= 2e+205) {
tmp = x * (1.0 / (2.0 * pow(x, 1.5)));
} else {
tmp = sqrt(x) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 1.0d0 + ((x * 0.5d0) - sqrt(x))
else if (x <= 2d+205) then
tmp = x * (1.0d0 / (2.0d0 * (x ** 1.5d0)))
else
tmp = sqrt(x) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 1.0 + ((x * 0.5) - Math.sqrt(x));
} else if (x <= 2e+205) {
tmp = x * (1.0 / (2.0 * Math.pow(x, 1.5)));
} else {
tmp = Math.sqrt(x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 1.0 + ((x * 0.5) - math.sqrt(x)) elif x <= 2e+205: tmp = x * (1.0 / (2.0 * math.pow(x, 1.5))) else: tmp = math.sqrt(x) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 + Float64(Float64(x * 0.5) - sqrt(x))); elseif (x <= 2e+205) tmp = Float64(x * Float64(1.0 / Float64(2.0 * (x ^ 1.5)))); else tmp = Float64(sqrt(x) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 1.0 + ((x * 0.5) - sqrt(x)); elseif (x <= 2e+205) tmp = x * (1.0 / (2.0 * (x ^ 1.5))); else tmp = sqrt(x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(1.0 + N[(N[(x * 0.5), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e+205], N[(x * N[(1.0 / N[(2.0 * N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+205}:\\
\;\;\;\;x \cdot \frac{1}{2 \cdot {x}^{1.5}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{x}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
associate--l+99.5%
+-commutative99.5%
Applied egg-rr99.5%
if 1 < x < 2.00000000000000003e205Initial program 8.6%
flip--9.4%
div-inv9.4%
add-sqr-sqrt10.9%
add-sqr-sqrt13.0%
associate--l+13.0%
Applied egg-rr13.0%
associate-*r/13.0%
*-rgt-identity13.0%
+-commutative13.0%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
+-commutative99.7%
Simplified99.7%
add-sqr-sqrt99.4%
pow299.4%
pow1/299.4%
sqrt-pow199.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 96.5%
flip3-+96.3%
associate-/r/96.3%
count-296.3%
sqrt-pow296.0%
metadata-eval96.0%
add-sqr-sqrt96.3%
add-sqr-sqrt96.0%
add-sqr-sqrt96.3%
+-inverses96.3%
Applied egg-rr96.3%
if 2.00000000000000003e205 < x Initial program 4.4%
flip--4.4%
div-inv4.4%
add-sqr-sqrt3.3%
add-sqr-sqrt4.4%
associate--l+4.4%
Applied egg-rr4.4%
associate-*r/4.4%
*-rgt-identity4.4%
+-commutative4.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.5%
flip-+0.0%
add-sqr-sqrt2.7%
add-sqr-sqrt0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
add-sqr-sqrt1.0%
add-sqr-sqrt0.0%
clear-num0.0%
flip-+3.5%
flip3-+2.3%
div-inv2.3%
count-22.3%
sqrt-pow22.3%
metadata-eval2.3%
Applied egg-rr2.3%
Simplified18.8%
Final simplification84.8%
(FPCore (x) :precision binary64 (if (<= x 1.25) (- (+ 1.0 (* x (+ 0.5 (* x -0.125)))) (sqrt x)) (if (<= x 2e+205) (* x (/ 1.0 (* 2.0 (pow x 1.5)))) (/ (sqrt x) x))))
double code(double x) {
double tmp;
if (x <= 1.25) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x);
} else if (x <= 2e+205) {
tmp = x * (1.0 / (2.0 * pow(x, 1.5)));
} else {
tmp = sqrt(x) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.25d0) then
tmp = (1.0d0 + (x * (0.5d0 + (x * (-0.125d0))))) - sqrt(x)
else if (x <= 2d+205) then
tmp = x * (1.0d0 / (2.0d0 * (x ** 1.5d0)))
else
tmp = sqrt(x) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.25) {
tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - Math.sqrt(x);
} else if (x <= 2e+205) {
tmp = x * (1.0 / (2.0 * Math.pow(x, 1.5)));
} else {
tmp = Math.sqrt(x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.25: tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - math.sqrt(x) elif x <= 2e+205: tmp = x * (1.0 / (2.0 * math.pow(x, 1.5))) else: tmp = math.sqrt(x) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.25) tmp = Float64(Float64(1.0 + Float64(x * Float64(0.5 + Float64(x * -0.125)))) - sqrt(x)); elseif (x <= 2e+205) tmp = Float64(x * Float64(1.0 / Float64(2.0 * (x ^ 1.5)))); else tmp = Float64(sqrt(x) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.25) tmp = (1.0 + (x * (0.5 + (x * -0.125)))) - sqrt(x); elseif (x <= 2e+205) tmp = x * (1.0 / (2.0 * (x ^ 1.5))); else tmp = sqrt(x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.25], N[(N[(1.0 + N[(x * N[(0.5 + N[(x * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e+205], N[(x * N[(1.0 / N[(2.0 * N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.25:\\
\;\;\;\;\left(1 + x \cdot \left(0.5 + x \cdot -0.125\right)\right) - \sqrt{x}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+205}:\\
\;\;\;\;x \cdot \frac{1}{2 \cdot {x}^{1.5}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{x}}{x}\\
\end{array}
\end{array}
if x < 1.25Initial program 100.0%
Taylor expanded in x around 0 99.6%
+-commutative99.6%
unpow299.6%
associate-*r*99.6%
distribute-rgt-out99.6%
*-commutative99.6%
Simplified99.6%
if 1.25 < x < 2.00000000000000003e205Initial program 8.6%
flip--9.4%
div-inv9.4%
add-sqr-sqrt10.9%
add-sqr-sqrt13.0%
associate--l+13.0%
Applied egg-rr13.0%
associate-*r/13.0%
*-rgt-identity13.0%
+-commutative13.0%
associate-+l-99.7%
+-inverses99.7%
metadata-eval99.7%
+-commutative99.7%
Simplified99.7%
add-sqr-sqrt99.4%
pow299.4%
pow1/299.4%
sqrt-pow199.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in x around inf 96.5%
flip3-+96.3%
associate-/r/96.3%
count-296.3%
sqrt-pow296.0%
metadata-eval96.0%
add-sqr-sqrt96.3%
add-sqr-sqrt96.0%
add-sqr-sqrt96.3%
+-inverses96.3%
Applied egg-rr96.3%
if 2.00000000000000003e205 < x Initial program 4.4%
flip--4.4%
div-inv4.4%
add-sqr-sqrt3.3%
add-sqr-sqrt4.4%
associate--l+4.4%
Applied egg-rr4.4%
associate-*r/4.4%
*-rgt-identity4.4%
+-commutative4.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 99.5%
flip-+0.0%
add-sqr-sqrt2.7%
add-sqr-sqrt0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
add-sqr-sqrt1.0%
add-sqr-sqrt0.0%
clear-num0.0%
flip-+3.5%
flip3-+2.3%
div-inv2.3%
count-22.3%
sqrt-pow22.3%
metadata-eval2.3%
Applied egg-rr2.3%
Simplified18.8%
Final simplification84.8%
(FPCore (x) :precision binary64 (if (<= x 0.4) (+ 1.0 (* x -2.0)) (/ (sqrt x) x)))
double code(double x) {
double tmp;
if (x <= 0.4) {
tmp = 1.0 + (x * -2.0);
} else {
tmp = sqrt(x) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.4d0) then
tmp = 1.0d0 + (x * (-2.0d0))
else
tmp = sqrt(x) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.4) {
tmp = 1.0 + (x * -2.0);
} else {
tmp = Math.sqrt(x) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.4: tmp = 1.0 + (x * -2.0) else: tmp = math.sqrt(x) / x return tmp
function code(x) tmp = 0.0 if (x <= 0.4) tmp = Float64(1.0 + Float64(x * -2.0)); else tmp = Float64(sqrt(x) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.4) tmp = 1.0 + (x * -2.0); else tmp = sqrt(x) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.4], N[(1.0 + N[(x * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.4:\\
\;\;\;\;1 + x \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{x}}{x}\\
\end{array}
\end{array}
if x < 0.40000000000000002Initial program 100.0%
Taylor expanded in x around 0 99.5%
associate--l+99.5%
+-commutative99.5%
Applied egg-rr99.5%
Taylor expanded in x around inf 97.0%
Simplified97.0%
if 0.40000000000000002 < x Initial program 7.3%
flip--7.8%
div-inv7.8%
add-sqr-sqrt8.5%
add-sqr-sqrt10.3%
associate--l+10.3%
Applied egg-rr10.3%
associate-*r/10.3%
*-rgt-identity10.3%
+-commutative10.3%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
add-sqr-sqrt99.3%
pow299.3%
pow1/299.3%
sqrt-pow199.3%
metadata-eval99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 97.4%
flip-+0.0%
add-sqr-sqrt1.9%
add-sqr-sqrt0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
+-inverses0.0%
add-sqr-sqrt0.9%
add-sqr-sqrt0.0%
clear-num0.0%
flip-+5.5%
flip3-+5.1%
div-inv5.1%
count-25.1%
sqrt-pow25.1%
metadata-eval5.1%
Applied egg-rr5.1%
Simplified18.7%
Final simplification55.7%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt x) 1.0)))
double code(double x) {
return 1.0 / (sqrt(x) + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) + 1.0d0)
end function
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + 1.0);
}
def code(x): return 1.0 / (math.sqrt(x) + 1.0)
function code(x) return Float64(1.0 / Float64(sqrt(x) + 1.0)) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + 1.0); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} + 1}
\end{array}
Initial program 51.1%
flip--51.3%
div-inv51.3%
add-sqr-sqrt51.7%
add-sqr-sqrt52.7%
associate--l+52.7%
Applied egg-rr52.7%
associate-*r/52.7%
*-rgt-identity52.7%
+-commutative52.7%
associate-+l-99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
+-commutative99.8%
add-sqr-sqrt99.6%
fma-def99.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
pow1/299.8%
sqrt-pow199.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 56.5%
Final simplification56.5%
(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 51.1%
Taylor expanded in x around 0 49.6%
Final simplification49.6%
(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 2024027
(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)))