
(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 10 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 x) x) (+ (sqrt x) t_0)) (/ 1.0 (sqrt (* x (+ 1.0 x))))))))
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 + x) - x) / (sqrt(x) + t_0)) * (1.0 / sqrt((x * (1.0 + x))));
}
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 + x) - x) / (sqrt(x) + t_0)) * (1.0d0 / sqrt((x * (1.0d0 + x))))
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 + x) - x) / (Math.sqrt(x) + t_0)) * (1.0 / Math.sqrt((x * (1.0 + x))));
}
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 + x) - x) / (math.sqrt(x) + t_0)) * (1.0 / math.sqrt((x * (1.0 + x)))) 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(Float64(Float64(1.0 + x) - x) / Float64(sqrt(x) + t_0)) * Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x))))); 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 + x) - x) / (sqrt(x) + t_0)) * (1.0 / sqrt((x * (1.0 + x)))); 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[(N[(N[(1.0 + x), $MachinePrecision] - x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $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{\left(1 + x\right) - x}{\sqrt{x} + t_0} \cdot \frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 34.6%
*-un-lft-identity34.6%
clear-num34.6%
associate-/r/34.6%
prod-diff34.6%
*-un-lft-identity34.6%
fma-neg34.6%
*-un-lft-identity34.6%
pow1/234.6%
pow-flip24.2%
metadata-eval24.2%
pow1/224.2%
pow-flip34.6%
+-commutative34.6%
metadata-eval34.6%
Applied egg-rr34.6%
+-commutative34.6%
sub-neg34.6%
fma-udef34.6%
distribute-lft1-in34.6%
metadata-eval34.6%
mul0-lft34.6%
+-commutative34.6%
associate-+r+34.6%
sub-neg34.6%
neg-sub034.6%
+-commutative34.6%
sub-neg34.6%
Simplified34.6%
Taylor expanded in x around inf 64.2%
*-un-lft-identity64.2%
pow-flip66.2%
sqrt-pow1100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 97.2%
frac-sub97.3%
div-inv97.3%
*-un-lft-identity97.3%
*-rgt-identity97.3%
+-commutative97.3%
sqrt-unprod97.2%
+-commutative97.2%
Applied egg-rr97.2%
flip--98.4%
add-sqr-sqrt98.2%
+-commutative98.2%
add-sqr-sqrt99.5%
+-commutative99.5%
Applied egg-rr99.5%
Final simplification99.7%
(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 (+ 1.0 x)))) (/ 1.0 (+ (sqrt x) t_0))))))
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 * (1.0 + x)))) * (1.0 / (sqrt(x) + 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))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 0.0d0) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = (1.0d0 / sqrt((x * (1.0d0 + x)))) * (1.0d0 / (sqrt(x) + t_0))
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 * (1.0 + x)))) * (1.0 / (Math.sqrt(x) + t_0));
}
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 * (1.0 + x)))) * (1.0 / (math.sqrt(x) + t_0)) 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 / sqrt(Float64(x * Float64(1.0 + x)))) * Float64(1.0 / Float64(sqrt(x) + t_0))); 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 * (1.0 + x)))) * (1.0 / (sqrt(x) + t_0)); 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[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $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 \cdot \left(1 + x\right)}} \cdot \frac{1}{\sqrt{x} + t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 34.6%
*-un-lft-identity34.6%
clear-num34.6%
associate-/r/34.6%
prod-diff34.6%
*-un-lft-identity34.6%
fma-neg34.6%
*-un-lft-identity34.6%
pow1/234.6%
pow-flip24.2%
metadata-eval24.2%
pow1/224.2%
pow-flip34.6%
+-commutative34.6%
metadata-eval34.6%
Applied egg-rr34.6%
+-commutative34.6%
sub-neg34.6%
fma-udef34.6%
distribute-lft1-in34.6%
metadata-eval34.6%
mul0-lft34.6%
+-commutative34.6%
associate-+r+34.6%
sub-neg34.6%
neg-sub034.6%
+-commutative34.6%
sub-neg34.6%
Simplified34.6%
Taylor expanded in x around inf 64.2%
*-un-lft-identity64.2%
pow-flip66.2%
sqrt-pow1100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
Simplified100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 97.2%
frac-sub97.3%
div-inv97.3%
*-un-lft-identity97.3%
*-rgt-identity97.3%
+-commutative97.3%
sqrt-unprod97.2%
+-commutative97.2%
Applied egg-rr97.2%
flip--98.4%
add-sqr-sqrt98.2%
+-commutative98.2%
add-sqr-sqrt99.5%
+-commutative99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 99.5%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 1e-10)
(* (/ 1.0 (+ (sqrt x) t_0)) (/ 1.0 (+ x 0.5)))
(- (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)) <= 1e-10) {
tmp = (1.0 / (sqrt(x) + t_0)) * (1.0 / (x + 0.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) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 1d-10) then
tmp = (1.0d0 / (sqrt(x) + t_0)) * (1.0d0 / (x + 0.5d0))
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)) <= 1e-10) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) * (1.0 / (x + 0.5));
} 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)) <= 1e-10: tmp = (1.0 / (math.sqrt(x) + t_0)) * (1.0 / (x + 0.5)) 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)) <= 1e-10) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) * Float64(1.0 / Float64(x + 0.5))); 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)) <= 1e-10) tmp = (1.0 / (sqrt(x) + t_0)) * (1.0 / (x + 0.5)); 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], 1e-10], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(x + 0.5), $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 10^{-10}:\\
\;\;\;\;\frac{1}{\sqrt{x} + t_0} \cdot \frac{1}{x + 0.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.00000000000000004e-10Initial program 35.2%
frac-sub35.2%
div-inv35.2%
*-un-lft-identity35.2%
*-rgt-identity35.2%
+-commutative35.2%
sqrt-unprod35.2%
+-commutative35.2%
Applied egg-rr35.2%
flip--36.4%
add-sqr-sqrt36.2%
+-commutative36.2%
add-sqr-sqrt37.5%
+-commutative37.5%
Applied egg-rr37.5%
Taylor expanded in x around 0 83.4%
Taylor expanded in x around inf 99.3%
+-commutative7.7%
Simplified99.3%
if 1.00000000000000004e-10 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 1e-12) (* 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-12) {
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-12) 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-12) {
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-12: 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-12) 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-12) 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-12], 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^{-12}:\\
\;\;\;\;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)))) < 9.9999999999999998e-13Initial program 34.7%
*-un-lft-identity34.7%
clear-num34.7%
associate-/r/34.7%
prod-diff34.7%
*-un-lft-identity34.7%
fma-neg34.7%
*-un-lft-identity34.7%
pow1/234.7%
pow-flip24.7%
metadata-eval24.7%
pow1/224.7%
pow-flip34.7%
+-commutative34.7%
metadata-eval34.7%
Applied egg-rr34.7%
+-commutative34.7%
sub-neg34.7%
fma-udef34.7%
distribute-lft1-in34.7%
metadata-eval34.7%
mul0-lft34.7%
+-commutative34.7%
associate-+r+34.7%
sub-neg34.7%
neg-sub034.7%
+-commutative34.7%
sub-neg34.7%
Simplified34.7%
Taylor expanded in x around inf 64.6%
*-un-lft-identity64.6%
pow-flip66.6%
sqrt-pow199.3%
metadata-eval99.3%
metadata-eval99.3%
Applied egg-rr99.3%
*-lft-identity99.3%
Simplified99.3%
if 9.9999999999999998e-13 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.0%
*-un-lft-identity99.0%
clear-num99.0%
associate-/r/99.0%
prod-diff99.0%
*-un-lft-identity99.0%
fma-neg99.0%
*-un-lft-identity99.0%
pow1/299.0%
pow-flip99.4%
metadata-eval99.4%
pow1/299.4%
pow-flip99.5%
+-commutative99.5%
metadata-eval99.5%
Applied egg-rr99.5%
+-commutative99.5%
sub-neg99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
+-commutative99.5%
associate-+r+99.5%
sub-neg99.5%
neg-sub099.5%
+-commutative99.5%
sub-neg99.5%
Simplified99.5%
Final simplification99.4%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (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 <= 1.0d0) then
tmp = ((x ** (-0.5d0)) + (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 <= 1.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} 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) + (x * 0.5)) + -1.0 else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64((x ^ -0.5) + 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 <= 1.0) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.4%
if 1 < x Initial program 35.2%
*-un-lft-identity35.2%
clear-num35.2%
associate-/r/35.2%
prod-diff35.2%
*-un-lft-identity35.2%
fma-neg35.2%
*-un-lft-identity35.2%
pow1/235.2%
pow-flip25.3%
metadata-eval25.3%
pow1/225.3%
pow-flip35.2%
+-commutative35.2%
metadata-eval35.2%
Applied egg-rr35.2%
+-commutative35.2%
sub-neg35.2%
fma-udef35.2%
distribute-lft1-in35.2%
metadata-eval35.2%
mul0-lft35.2%
+-commutative35.2%
associate-+r+35.2%
sub-neg35.2%
neg-sub035.2%
+-commutative35.2%
sub-neg35.2%
Simplified35.2%
Taylor expanded in x around inf 64.5%
*-un-lft-identity64.5%
pow-flip66.4%
sqrt-pow198.6%
metadata-eval98.6%
metadata-eval98.6%
Applied egg-rr98.6%
*-lft-identity98.6%
Simplified98.6%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.68) {
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.68d0) 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.68) {
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.68: 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.68) 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.68) tmp = (x ^ -0.5) + -1.0; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], 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.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
if 0.680000000000000049 < x Initial program 35.7%
*-un-lft-identity35.7%
clear-num35.7%
associate-/r/35.7%
prod-diff35.7%
*-un-lft-identity35.7%
fma-neg35.7%
*-un-lft-identity35.7%
pow1/235.7%
pow-flip25.8%
metadata-eval25.8%
pow1/225.8%
pow-flip35.7%
+-commutative35.7%
metadata-eval35.7%
Applied egg-rr35.7%
+-commutative35.7%
sub-neg35.7%
fma-udef35.7%
distribute-lft1-in35.7%
metadata-eval35.7%
mul0-lft35.7%
+-commutative35.7%
associate-+r+35.7%
sub-neg35.7%
neg-sub035.7%
+-commutative35.7%
sub-neg35.7%
Simplified35.7%
Taylor expanded in x around inf 64.1%
*-un-lft-identity64.1%
pow-flip66.1%
sqrt-pow198.0%
metadata-eval98.0%
metadata-eval98.0%
Applied egg-rr98.0%
*-lft-identity98.0%
Simplified98.0%
Final simplification98.9%
(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 66.4%
*-un-lft-identity66.4%
clear-num66.4%
associate-/r/66.4%
prod-diff66.4%
*-un-lft-identity66.4%
fma-neg66.4%
*-un-lft-identity66.4%
pow1/266.4%
pow-flip61.5%
metadata-eval61.5%
pow1/261.5%
pow-flip66.6%
+-commutative66.6%
metadata-eval66.6%
Applied egg-rr66.6%
+-commutative66.6%
sub-neg66.6%
fma-udef66.6%
distribute-lft1-in66.6%
metadata-eval66.6%
mul0-lft66.6%
+-commutative66.6%
associate-+r+66.6%
sub-neg66.6%
neg-sub066.6%
+-commutative66.6%
sub-neg66.6%
Simplified66.6%
Taylor expanded in x around inf 35.7%
*-un-lft-identity35.7%
pow-flip36.7%
sqrt-pow153.5%
metadata-eval53.5%
metadata-eval53.5%
Applied egg-rr53.5%
*-lft-identity53.5%
Simplified53.5%
Final simplification53.5%
(FPCore (x) :precision binary64 (/ 1.0 (+ x 0.5)))
double code(double x) {
return 1.0 / (x + 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + 0.5d0)
end function
public static double code(double x) {
return 1.0 / (x + 0.5);
}
def code(x): return 1.0 / (x + 0.5)
function code(x) return Float64(1.0 / Float64(x + 0.5)) end
function tmp = code(x) tmp = 1.0 / (x + 0.5); end
code[x_] := N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 0.5}
\end{array}
Initial program 66.4%
frac-sub66.4%
div-inv66.4%
*-un-lft-identity66.4%
*-rgt-identity66.4%
+-commutative66.4%
sqrt-unprod66.4%
+-commutative66.4%
Applied egg-rr66.4%
Taylor expanded in x around 0 64.9%
Taylor expanded in x around inf 7.2%
+-commutative7.2%
Simplified7.2%
Final simplification7.2%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 66.4%
frac-sub66.4%
div-inv66.4%
*-un-lft-identity66.4%
*-rgt-identity66.4%
+-commutative66.4%
sqrt-unprod66.4%
+-commutative66.4%
Applied egg-rr66.4%
Taylor expanded in x around inf 21.3%
Taylor expanded in x around 0 7.2%
Final simplification7.2%
(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 66.4%
Taylor expanded in x around 0 49.2%
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 2023333
(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)))))