
(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)));
}
real(8) function code(x)
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:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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)));
}
real(8) function code(x)
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}
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
(* 0.5 (pow x -1.5))
(* (/ 1.0 (+ (sqrt x) t_0)) (pow (+ x (* x x)) -0.5)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = 0.5 * pow(x, -1.5);
} else {
tmp = (1.0 / (sqrt(x) + t_0)) * pow((x + (x * x)), -0.5);
}
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))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 0.0d0) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = (1.0d0 / (sqrt(x) + t_0)) * ((x + (x * x)) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = 0.5 * Math.pow(x, -1.5);
} else {
tmp = (1.0 / (Math.sqrt(x) + t_0)) * Math.pow((x + (x * x)), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 0.0: tmp = 0.5 * math.pow(x, -1.5) else: tmp = (1.0 / (math.sqrt(x) + t_0)) * math.pow((x + (x * x)), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0) tmp = Float64(0.5 * (x ^ -1.5)); else tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) * (Float64(x + Float64(x * x)) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) tmp = 0.5 * (x ^ -1.5); else tmp = (1.0 / (sqrt(x) + t_0)) * ((x + (x * x)) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] * N[Power[N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x} + t_0} \cdot {\left(x + x \cdot x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 38.8%
flip--38.8%
div-inv38.8%
frac-times19.8%
metadata-eval19.8%
add-sqr-sqrt15.9%
frac-times28.8%
metadata-eval28.8%
add-sqr-sqrt38.8%
+-commutative38.8%
pow1/238.8%
pow-flip38.8%
metadata-eval38.8%
inv-pow38.8%
sqrt-pow238.8%
+-commutative38.8%
metadata-eval38.8%
Applied egg-rr38.8%
Taylor expanded in x around inf 63.6%
expm1-log1p-u63.6%
expm1-udef38.8%
pow-flip38.8%
sqrt-pow138.8%
metadata-eval38.8%
metadata-eval38.8%
Applied egg-rr38.8%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.5%
frac-sub98.5%
div-inv98.5%
*-un-lft-identity98.5%
+-commutative98.5%
*-rgt-identity98.5%
metadata-eval98.5%
frac-times98.6%
un-div-inv98.6%
pow1/298.6%
pow-flip98.9%
metadata-eval98.9%
+-commutative98.9%
Applied egg-rr98.9%
flip--99.7%
add-sqr-sqrt99.4%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
associate--l+99.8%
+-inverses99.8%
metadata-eval99.8%
+-commutative99.8%
Simplified99.8%
expm1-log1p-u92.8%
expm1-udef91.9%
div-inv91.9%
pow1/291.9%
pow-flip91.9%
metadata-eval91.9%
pow-prod-down91.9%
Applied egg-rr91.9%
expm1-def92.8%
expm1-log1p99.9%
distribute-lft-in99.9%
*-rgt-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 0.0) (* 0.5 (pow x -1.5)) (* (/ 1.0 (+ x (* x x))) (/ 1.0 (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 0.0) {
tmp = 0.5 * pow(x, -1.5);
} else {
tmp = (1.0 / (x + (x * x))) * (1.0 / (pow(x, -0.5) + pow((1.0 + x), -0.5)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 0.0d0) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = (1.0d0 / (x + (x * x))) * (1.0d0 / ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 0.0) {
tmp = 0.5 * Math.pow(x, -1.5);
} else {
tmp = (1.0 / (x + (x * x))) * (1.0 / (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5)));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 0.0: tmp = 0.5 * math.pow(x, -1.5) else: tmp = (1.0 / (x + (x * x))) * (1.0 / (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 0.0) tmp = Float64(0.5 * (x ^ -1.5)); else tmp = Float64(Float64(1.0 / Float64(x + Float64(x * x))) * Float64(1.0 / Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 0.0) tmp = 0.5 * (x ^ -1.5); else tmp = (1.0 / (x + (x * x))) * (1.0 / ((x ^ -0.5) + ((1.0 + x) ^ -0.5))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(x + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 0:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x + x \cdot x} \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 38.8%
flip--38.8%
div-inv38.8%
frac-times19.8%
metadata-eval19.8%
add-sqr-sqrt15.9%
frac-times28.8%
metadata-eval28.8%
add-sqr-sqrt38.8%
+-commutative38.8%
pow1/238.8%
pow-flip38.8%
metadata-eval38.8%
inv-pow38.8%
sqrt-pow238.8%
+-commutative38.8%
metadata-eval38.8%
Applied egg-rr38.8%
Taylor expanded in x around inf 63.6%
expm1-log1p-u63.6%
expm1-udef38.8%
pow-flip38.8%
sqrt-pow138.8%
metadata-eval38.8%
metadata-eval38.8%
Applied egg-rr38.8%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.5%
flip--98.4%
div-inv98.2%
frac-times98.2%
metadata-eval98.2%
add-sqr-sqrt98.3%
frac-times98.2%
metadata-eval98.2%
add-sqr-sqrt98.3%
+-commutative98.3%
pow1/298.3%
pow-flip98.1%
metadata-eval98.1%
inv-pow98.1%
sqrt-pow298.1%
+-commutative98.1%
metadata-eval98.1%
Applied egg-rr98.1%
frac-sub99.1%
*-un-lft-identity99.1%
Applied egg-rr99.1%
*-rgt-identity99.1%
associate--l+99.1%
+-inverses99.1%
metadata-eval99.1%
distribute-lft-in99.1%
*-rgt-identity99.1%
Simplified99.1%
Final simplification99.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 5e-12)
(* (/ 1.0 (+ (sqrt x) t_0)) (- (/ 1.0 x) (/ 0.5 (* x x))))
(- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 5e-12) {
tmp = (1.0 / (sqrt(x) + t_0)) * ((1.0 / x) - (0.5 / (x * x)));
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
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))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 5d-12) then
tmp = (1.0d0 / (sqrt(x) + t_0)) * ((1.0d0 / x) - (0.5d0 / (x * x)))
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 5e-12) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) * ((1.0 / x) - (0.5 / (x * x)));
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 5e-12: tmp = (1.0 / (math.sqrt(x) + t_0)) * ((1.0 / x) - (0.5 / (x * x))) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 5e-12) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) * Float64(Float64(1.0 / x) - Float64(0.5 / Float64(x * x)))); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 5e-12) tmp = (1.0 / (sqrt(x) + t_0)) * ((1.0 / x) - (0.5 / (x * x))); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 5e-12], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] - N[(0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 5 \cdot 10^{-12}:\\
\;\;\;\;\frac{1}{\sqrt{x} + t_0} \cdot \left(\frac{1}{x} - \frac{0.5}{x \cdot x}\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.9999999999999997e-12Initial program 39.0%
frac-sub39.1%
div-inv39.1%
*-un-lft-identity39.1%
+-commutative39.1%
*-rgt-identity39.1%
metadata-eval39.1%
frac-times39.1%
un-div-inv39.1%
pow1/239.1%
pow-flip39.1%
metadata-eval39.1%
+-commutative39.1%
Applied egg-rr39.1%
flip--39.8%
add-sqr-sqrt26.4%
add-sqr-sqrt39.8%
Applied egg-rr39.8%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in x around inf 99.5%
associate-*r/39.1%
metadata-eval39.1%
unpow239.1%
Simplified99.5%
if 4.9999999999999997e-12 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.1%
*-un-lft-identity99.1%
clear-num99.1%
associate-/r/99.1%
prod-diff99.1%
*-un-lft-identity99.1%
fma-neg99.1%
*-un-lft-identity99.1%
inv-pow99.1%
sqrt-pow299.5%
metadata-eval99.5%
pow1/299.5%
pow-flip99.5%
+-commutative99.5%
metadata-eval99.5%
Applied egg-rr99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
+-rgt-identity99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 1e-15) (* 0.5 (pow x -1.5)) (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 1e-15) {
tmp = 0.5 * pow(x, -1.5);
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 1d-15) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 1e-15) {
tmp = 0.5 * Math.pow(x, -1.5);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 1e-15: tmp = 0.5 * math.pow(x, -1.5) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 1e-15) tmp = Float64(0.5 * (x ^ -1.5)); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 1e-15) tmp = 0.5 * (x ^ -1.5); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-15], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 10^{-15}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.0000000000000001e-15Initial program 38.8%
flip--38.8%
div-inv38.8%
frac-times20.0%
metadata-eval20.0%
add-sqr-sqrt16.2%
frac-times28.9%
metadata-eval28.9%
add-sqr-sqrt38.9%
+-commutative38.9%
pow1/238.9%
pow-flip38.9%
metadata-eval38.9%
inv-pow38.9%
sqrt-pow238.9%
+-commutative38.9%
metadata-eval38.9%
Applied egg-rr38.9%
Taylor expanded in x around inf 63.6%
expm1-log1p-u63.6%
expm1-udef38.7%
pow-flip38.7%
sqrt-pow138.7%
metadata-eval38.7%
metadata-eval38.7%
Applied egg-rr38.7%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
if 1.0000000000000001e-15 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 98.9%
*-un-lft-identity98.9%
clear-num98.9%
associate-/r/98.9%
prod-diff98.9%
*-un-lft-identity98.9%
fma-neg98.9%
*-un-lft-identity98.9%
inv-pow98.9%
sqrt-pow299.3%
metadata-eval99.3%
pow1/299.3%
pow-flip99.3%
+-commutative99.3%
metadata-eval99.3%
Applied egg-rr99.3%
fma-udef99.3%
distribute-lft1-in99.3%
metadata-eval99.3%
mul0-lft99.3%
+-rgt-identity99.3%
Simplified99.3%
Final simplification99.5%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (+ 1.0 x)))) (* (/ 1.0 (+ (sqrt x) t_0)) (/ (pow x -0.5) t_0))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
return (1.0 / (sqrt(x) + t_0)) * (pow(x, -0.5) / t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = sqrt((1.0d0 + x))
code = (1.0d0 / (sqrt(x) + t_0)) * ((x ** (-0.5d0)) / t_0)
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
return (1.0 / (Math.sqrt(x) + t_0)) * (Math.pow(x, -0.5) / t_0);
}
def code(x): t_0 = math.sqrt((1.0 + x)) return (1.0 / (math.sqrt(x) + t_0)) * (math.pow(x, -0.5) / t_0)
function code(x) t_0 = sqrt(Float64(1.0 + x)) return Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) * Float64((x ^ -0.5) / t_0)) end
function tmp = code(x) t_0 = sqrt((1.0 + x)); tmp = (1.0 / (sqrt(x) + t_0)) * ((x ^ -0.5) / t_0); end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\frac{1}{\sqrt{x} + t_0} \cdot \frac{{x}^{-0.5}}{t_0}
\end{array}
\end{array}
Initial program 71.4%
frac-sub71.4%
div-inv71.5%
*-un-lft-identity71.5%
+-commutative71.5%
*-rgt-identity71.5%
metadata-eval71.5%
frac-times71.5%
un-div-inv71.5%
pow1/271.5%
pow-flip71.7%
metadata-eval71.7%
+-commutative71.7%
Applied egg-rr71.7%
flip--72.1%
add-sqr-sqrt65.9%
add-sqr-sqrt72.2%
Applied egg-rr72.2%
associate--l+99.6%
+-inverses99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= x 1.7) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.7d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.7) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.6%
Taylor expanded in x around 0 97.3%
add-log-exp5.2%
*-un-lft-identity5.2%
log-prod5.2%
metadata-eval5.2%
add-log-exp96.5%
pow1/296.5%
pow-flip96.9%
metadata-eval96.9%
Applied egg-rr97.7%
+-lft-identity96.9%
Simplified97.7%
if 1.69999999999999996 < x Initial program 40.5%
flip--40.5%
div-inv40.5%
frac-times22.5%
metadata-eval22.5%
add-sqr-sqrt18.9%
frac-times31.1%
metadata-eval31.1%
add-sqr-sqrt40.7%
+-commutative40.7%
pow1/240.7%
pow-flip40.7%
metadata-eval40.7%
inv-pow40.7%
sqrt-pow240.7%
+-commutative40.7%
metadata-eval40.7%
Applied egg-rr40.7%
Taylor expanded in x around inf 62.6%
expm1-log1p-u62.6%
expm1-udef38.6%
pow-flip38.6%
sqrt-pow138.6%
metadata-eval38.6%
metadata-eval38.6%
Applied egg-rr38.6%
expm1-def97.3%
expm1-log1p97.3%
Simplified97.3%
Final simplification97.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = Math.pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
Taylor expanded in x around 0 97.2%
add-log-exp5.2%
*-un-lft-identity5.2%
log-prod5.2%
metadata-eval5.2%
add-log-exp96.5%
pow1/296.5%
pow-flip96.9%
metadata-eval96.9%
Applied egg-rr97.6%
+-lft-identity96.9%
Simplified97.6%
if 1 < x Initial program 40.5%
flip--40.5%
div-inv40.5%
frac-times22.5%
metadata-eval22.5%
add-sqr-sqrt18.9%
frac-times31.1%
metadata-eval31.1%
add-sqr-sqrt40.7%
+-commutative40.7%
pow1/240.7%
pow-flip40.7%
metadata-eval40.7%
inv-pow40.7%
sqrt-pow240.7%
+-commutative40.7%
metadata-eval40.7%
Applied egg-rr40.7%
Taylor expanded in x around inf 62.6%
expm1-log1p-u62.6%
expm1-udef38.6%
pow-flip38.6%
sqrt-pow138.6%
metadata-eval38.6%
metadata-eval38.6%
Applied egg-rr38.6%
expm1-def97.3%
expm1-log1p97.3%
Simplified97.3%
Final simplification97.4%
(FPCore (x) :precision binary64 (if (<= x 0.66) (+ (pow x -0.5) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.66d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = (x ^ -0.5) + -1.0; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.6%
Taylor expanded in x around 0 96.5%
add-log-exp5.2%
*-un-lft-identity5.2%
log-prod5.2%
metadata-eval5.2%
add-log-exp96.5%
pow1/296.5%
pow-flip96.9%
metadata-eval96.9%
Applied egg-rr96.9%
+-lft-identity96.9%
Simplified96.9%
if 0.660000000000000031 < x Initial program 40.5%
flip--40.5%
div-inv40.5%
frac-times22.5%
metadata-eval22.5%
add-sqr-sqrt18.9%
frac-times31.1%
metadata-eval31.1%
add-sqr-sqrt40.7%
+-commutative40.7%
pow1/240.7%
pow-flip40.7%
metadata-eval40.7%
inv-pow40.7%
sqrt-pow240.7%
+-commutative40.7%
metadata-eval40.7%
Applied egg-rr40.7%
Taylor expanded in x around inf 62.6%
expm1-log1p-u62.6%
expm1-udef38.6%
pow-flip38.6%
sqrt-pow138.6%
metadata-eval38.6%
metadata-eval38.6%
Applied egg-rr38.6%
expm1-def97.3%
expm1-log1p97.3%
Simplified97.3%
Final simplification97.1%
(FPCore (x) :precision binary64 (* 0.5 (pow x -1.5)))
double code(double x) {
return 0.5 * pow(x, -1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x ** (-1.5d0))
end function
public static double code(double x) {
return 0.5 * Math.pow(x, -1.5);
}
def code(x): return 0.5 * math.pow(x, -1.5)
function code(x) return Float64(0.5 * (x ^ -1.5)) end
function tmp = code(x) tmp = 0.5 * (x ^ -1.5); end
code[x_] := N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{-1.5}
\end{array}
Initial program 71.4%
flip--71.4%
div-inv71.3%
frac-times62.6%
metadata-eval62.6%
add-sqr-sqrt61.0%
frac-times66.7%
metadata-eval66.7%
add-sqr-sqrt71.3%
+-commutative71.3%
pow1/271.3%
pow-flip71.2%
metadata-eval71.2%
inv-pow71.2%
sqrt-pow271.2%
+-commutative71.2%
metadata-eval71.2%
Applied egg-rr71.2%
Taylor expanded in x around inf 32.8%
expm1-log1p-u32.8%
expm1-udef21.3%
pow-flip21.3%
sqrt-pow121.5%
metadata-eval21.5%
metadata-eval21.5%
Applied egg-rr21.5%
expm1-def49.4%
expm1-log1p49.4%
Simplified49.4%
Final simplification49.4%
(FPCore (x) :precision binary64 (if (<= x 3.6e+102) (* x 0.5) (/ -0.5 (* x x))))
double code(double x) {
double tmp;
if (x <= 3.6e+102) {
tmp = x * 0.5;
} else {
tmp = -0.5 / (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 3.6d+102) then
tmp = x * 0.5d0
else
tmp = (-0.5d0) / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 3.6e+102) {
tmp = x * 0.5;
} else {
tmp = -0.5 / (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 3.6e+102: tmp = x * 0.5 else: tmp = -0.5 / (x * x) return tmp
function code(x) tmp = 0.0 if (x <= 3.6e+102) tmp = Float64(x * 0.5); else tmp = Float64(-0.5 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 3.6e+102) tmp = x * 0.5; else tmp = -0.5 / (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 3.6e+102], N[(x * 0.5), $MachinePrecision], N[(-0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.6 \cdot 10^{+102}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{x \cdot x}\\
\end{array}
\end{array}
if x < 3.6000000000000002e102Initial program 81.8%
Taylor expanded in x around 0 77.9%
Taylor expanded in x around inf 5.0%
*-commutative5.0%
Simplified5.0%
if 3.6000000000000002e102 < x Initial program 50.9%
frac-sub50.9%
div-inv50.9%
*-un-lft-identity50.9%
+-commutative50.9%
*-rgt-identity50.9%
metadata-eval50.9%
frac-times50.9%
un-div-inv50.9%
pow1/250.9%
pow-flip50.9%
metadata-eval50.9%
+-commutative50.9%
Applied egg-rr50.9%
Taylor expanded in x around inf 50.9%
associate-*r/50.9%
metadata-eval50.9%
unpow250.9%
Simplified50.9%
Taylor expanded in x around 0 50.7%
unpow250.7%
Simplified50.7%
Final simplification20.4%
(FPCore (x) :precision binary64 (* x 0.5))
double code(double x) {
return x * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.5d0
end function
public static double code(double x) {
return x * 0.5;
}
def code(x): return x * 0.5
function code(x) return Float64(x * 0.5) end
function tmp = code(x) tmp = x * 0.5; end
code[x_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 71.4%
Taylor expanded in x around 0 52.5%
Taylor expanded in x around inf 4.1%
*-commutative4.1%
Simplified4.1%
Final simplification4.1%
(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 71.4%
Taylor expanded in x around 0 51.7%
Taylor expanded in x around inf 1.9%
Final simplification1.9%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
herbie shell --seed 2023258
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))