
(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 13 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 (/ (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))) (hypot x (sqrt x))))
double code(double x) {
return (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / hypot(x, sqrt(x));
}
public static double code(double x) {
return (1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)))) / Math.hypot(x, Math.sqrt(x));
}
def code(x): return (1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))) / math.hypot(x, math.sqrt(x))
function code(x) return Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) / hypot(x, sqrt(x))) end
function tmp = code(x) tmp = (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / hypot(x, sqrt(x)); end
code[x_] := N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{\mathsf{hypot}\left(x, \sqrt{x}\right)}
\end{array}
Initial program 68.8%
frac-sub68.8%
*-un-lft-identity68.8%
*-rgt-identity68.8%
flip--68.8%
associate-/l/68.8%
add-sqr-sqrt68.6%
+-commutative68.6%
add-sqr-sqrt69.3%
associate--l+99.2%
sqrt-unprod92.6%
+-commutative92.6%
distribute-rgt-in92.6%
*-un-lft-identity92.6%
pow292.6%
+-commutative92.6%
+-commutative92.6%
Applied egg-rr92.6%
+-inverses92.6%
metadata-eval92.6%
+-commutative92.6%
Simplified92.6%
inv-pow92.6%
add-sqr-sqrt92.3%
metadata-eval92.3%
unpow-prod-down92.0%
Applied egg-rr98.8%
pow-sqr99.0%
metadata-eval99.0%
Simplified99.0%
sqrt-pow299.4%
metadata-eval99.4%
unpow-199.4%
*-commutative99.4%
associate-/r*99.6%
+-commutative99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-23)
(/ 1.0 (* x (+ (sqrt x) t_0)))
(- (pow x -0.5) (/ 1.0 t_0)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-23) {
tmp = 1.0 / (x * (sqrt(x) + t_0));
} else {
tmp = pow(x, -0.5) - (1.0 / 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)) <= 2d-23) then
tmp = 1.0d0 / (x * (sqrt(x) + t_0))
else
tmp = (x ** (-0.5d0)) - (1.0d0 / 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)) <= 2e-23) {
tmp = 1.0 / (x * (Math.sqrt(x) + t_0));
} else {
tmp = Math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23: tmp = 1.0 / (x * (math.sqrt(x) + t_0)) else: tmp = math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23) tmp = Float64(1.0 / Float64(x * Float64(sqrt(x) + t_0))); else tmp = Float64((x ^ -0.5) - Float64(1.0 / 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)) <= 2e-23) tmp = 1.0 / (x * (sqrt(x) + t_0)); else tmp = (x ^ -0.5) - (1.0 / 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], 2e-23], N[(1.0 / N[(x * N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{x \cdot \left(\sqrt{x} + t_0\right)}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.99999999999999992e-23Initial program 35.8%
frac-sub35.8%
*-un-lft-identity35.8%
*-rgt-identity35.8%
flip--35.8%
associate-/l/35.8%
add-sqr-sqrt35.2%
+-commutative35.2%
add-sqr-sqrt36.4%
associate--l+98.7%
sqrt-unprod84.9%
+-commutative84.9%
distribute-rgt-in84.9%
*-un-lft-identity84.9%
pow284.9%
+-commutative84.9%
+-commutative84.9%
Applied egg-rr84.9%
+-inverses84.9%
metadata-eval84.9%
+-commutative84.9%
Simplified84.9%
Taylor expanded in x around inf 99.0%
if 1.99999999999999992e-23 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
expm1-log1p-u89.5%
expm1-udef89.5%
pow1/289.5%
pow-flip89.5%
metadata-eval89.5%
Applied egg-rr91.8%
expm1-def89.5%
expm1-log1p96.9%
Simplified99.6%
Final simplification99.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-23)
(/ (/ 1.0 x) (+ (sqrt x) t_0))
(- (pow x -0.5) (/ 1.0 t_0)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-23) {
tmp = (1.0 / x) / (sqrt(x) + t_0);
} else {
tmp = pow(x, -0.5) - (1.0 / 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)) <= 2d-23) then
tmp = (1.0d0 / x) / (sqrt(x) + t_0)
else
tmp = (x ** (-0.5d0)) - (1.0d0 / 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)) <= 2e-23) {
tmp = (1.0 / x) / (Math.sqrt(x) + t_0);
} else {
tmp = Math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23: tmp = (1.0 / x) / (math.sqrt(x) + t_0) else: tmp = math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23) tmp = Float64(Float64(1.0 / x) / Float64(sqrt(x) + t_0)); else tmp = Float64((x ^ -0.5) - Float64(1.0 / 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)) <= 2e-23) tmp = (1.0 / x) / (sqrt(x) + t_0); else tmp = (x ^ -0.5) - (1.0 / 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], 2e-23], N[(N[(1.0 / x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} + t_0}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.99999999999999992e-23Initial program 35.8%
frac-sub35.8%
*-un-lft-identity35.8%
*-rgt-identity35.8%
flip--35.8%
associate-/l/35.8%
add-sqr-sqrt35.2%
+-commutative35.2%
add-sqr-sqrt36.4%
associate--l+98.7%
sqrt-unprod84.9%
+-commutative84.9%
distribute-rgt-in84.9%
*-un-lft-identity84.9%
pow284.9%
+-commutative84.9%
+-commutative84.9%
Applied egg-rr84.9%
+-inverses84.9%
metadata-eval84.9%
+-commutative84.9%
Simplified84.9%
expm1-log1p-u84.9%
expm1-udef35.6%
associate-/r*35.6%
+-commutative35.6%
unpow235.6%
add-sqr-sqrt35.6%
hypot-def35.6%
+-commutative35.6%
+-commutative35.6%
Applied egg-rr35.6%
expm1-def99.6%
expm1-log1p99.6%
Simplified99.6%
Taylor expanded in x around inf 99.6%
if 1.99999999999999992e-23 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
expm1-log1p-u89.5%
expm1-udef89.5%
pow1/289.5%
pow-flip89.5%
metadata-eval89.5%
Applied egg-rr91.8%
expm1-def89.5%
expm1-log1p96.9%
Simplified99.6%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-23)
(/ (/ 1.0 (+ (sqrt x) t_0)) x)
(- (pow x -0.5) (/ 1.0 t_0)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-23) {
tmp = (1.0 / (sqrt(x) + t_0)) / x;
} else {
tmp = pow(x, -0.5) - (1.0 / 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)) <= 2d-23) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / x
else
tmp = (x ** (-0.5d0)) - (1.0d0 / 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)) <= 2e-23) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / x;
} else {
tmp = Math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23: tmp = (1.0 / (math.sqrt(x) + t_0)) / x else: tmp = math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / x); else tmp = Float64((x ^ -0.5) - Float64(1.0 / 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)) <= 2e-23) tmp = (1.0 / (sqrt(x) + t_0)) / x; else tmp = (x ^ -0.5) - (1.0 / 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], 2e-23], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.99999999999999992e-23Initial program 35.8%
frac-sub35.8%
*-un-lft-identity35.8%
*-rgt-identity35.8%
flip--35.8%
associate-/l/35.8%
add-sqr-sqrt35.2%
+-commutative35.2%
add-sqr-sqrt36.4%
associate--l+98.7%
sqrt-unprod84.9%
+-commutative84.9%
distribute-rgt-in84.9%
*-un-lft-identity84.9%
pow284.9%
+-commutative84.9%
+-commutative84.9%
Applied egg-rr84.9%
+-inverses84.9%
metadata-eval84.9%
+-commutative84.9%
Simplified84.9%
inv-pow84.9%
add-sqr-sqrt84.8%
metadata-eval84.8%
unpow-prod-down84.6%
Applied egg-rr98.6%
pow-sqr98.9%
metadata-eval98.9%
Simplified98.9%
sqrt-pow299.0%
metadata-eval99.0%
unpow-199.0%
*-commutative99.0%
associate-/r*99.6%
+-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 99.6%
if 1.99999999999999992e-23 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
expm1-log1p-u89.5%
expm1-udef89.5%
pow1/289.5%
pow-flip89.5%
metadata-eval89.5%
Applied egg-rr91.8%
expm1-def89.5%
expm1-log1p96.9%
Simplified99.6%
Final simplification99.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-23)
(* 0.5 (sqrt (/ 1.0 (pow x 3.0))))
(- (pow x -0.5) (/ 1.0 t_0)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-23) {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
} else {
tmp = pow(x, -0.5) - (1.0 / 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)) <= 2d-23) then
tmp = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
else
tmp = (x ** (-0.5d0)) - (1.0d0 / 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)) <= 2e-23) {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
} else {
tmp = Math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23: tmp = 0.5 * math.sqrt((1.0 / math.pow(x, 3.0))) else: tmp = math.pow(x, -0.5) - (1.0 / 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)) <= 2e-23) tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); else tmp = Float64((x ^ -0.5) - Float64(1.0 / 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)) <= 2e-23) tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); else tmp = (x ^ -0.5) - (1.0 / 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], 2e-23], N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{t_0}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.99999999999999992e-23Initial program 35.8%
flip--35.8%
flip--35.8%
associate-/l/7.4%
Applied egg-rr7.4%
Taylor expanded in x around inf 59.0%
if 1.99999999999999992e-23 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.3%
expm1-log1p-u89.5%
expm1-udef89.5%
pow1/289.5%
pow-flip89.5%
metadata-eval89.5%
Applied egg-rr91.8%
expm1-def89.5%
expm1-log1p96.9%
Simplified99.6%
Final simplification80.1%
(FPCore (x) :precision binary64 (if (<= x 118000000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 118000000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 118000000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 118000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 118000000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = 0.5 * math.sqrt((1.0 / math.pow(x, 3.0))) return tmp
function code(x) tmp = 0.0 if (x <= 118000000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 118000000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 118000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 118000000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 1.18e8Initial program 99.3%
expm1-log1p-u99.3%
expm1-udef99.1%
associate--r-99.1%
pow1/299.1%
pow-flip99.4%
metadata-eval99.4%
pow1/299.4%
pow-flip99.4%
+-commutative99.4%
metadata-eval99.4%
Applied egg-rr99.4%
associate-+l-99.4%
expm1-def99.6%
expm1-log1p99.6%
Simplified99.6%
if 1.18e8 < x Initial program 35.8%
flip--35.8%
flip--35.8%
associate-/l/7.4%
Applied egg-rr7.4%
Taylor expanded in x around inf 59.0%
Final simplification80.1%
(FPCore (x) :precision binary64 (if (<= x 1.68) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 1.68) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.68d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.68) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.68: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = 0.5 * math.sqrt((1.0 / math.pow(x, 3.0))) return tmp
function code(x) tmp = 0.0 if (x <= 1.68) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.68) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.68], 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[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.68:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 1.67999999999999994Initial program 99.7%
expm1-log1p-u91.5%
expm1-udef91.5%
pow1/291.5%
pow-flip91.5%
metadata-eval91.5%
Applied egg-rr92.3%
expm1-def91.5%
expm1-log1p99.1%
Simplified100.0%
Taylor expanded in x around 0 99.7%
*-commutative99.7%
Simplified99.7%
if 1.67999999999999994 < x Initial program 36.9%
flip--36.9%
flip--36.9%
associate-/l/9.2%
Applied egg-rr9.2%
Taylor expanded in x around inf 58.5%
Final simplification79.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ 1.0 (* x 0.5))))
(if (<= x 1.32)
(+ (pow x -0.5) (/ -1.0 t_0))
(/ 1.0 (* x (+ (sqrt x) t_0))))))
double code(double x) {
double t_0 = 1.0 + (x * 0.5);
double tmp;
if (x <= 1.32) {
tmp = pow(x, -0.5) + (-1.0 / t_0);
} else {
tmp = 1.0 / (x * (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 = 1.0d0 + (x * 0.5d0)
if (x <= 1.32d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / t_0)
else
tmp = 1.0d0 / (x * (sqrt(x) + t_0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = 1.0 + (x * 0.5);
double tmp;
if (x <= 1.32) {
tmp = Math.pow(x, -0.5) + (-1.0 / t_0);
} else {
tmp = 1.0 / (x * (Math.sqrt(x) + t_0));
}
return tmp;
}
def code(x): t_0 = 1.0 + (x * 0.5) tmp = 0 if x <= 1.32: tmp = math.pow(x, -0.5) + (-1.0 / t_0) else: tmp = 1.0 / (x * (math.sqrt(x) + t_0)) return tmp
function code(x) t_0 = Float64(1.0 + Float64(x * 0.5)) tmp = 0.0 if (x <= 1.32) tmp = Float64((x ^ -0.5) + Float64(-1.0 / t_0)); else tmp = Float64(1.0 / Float64(x * Float64(sqrt(x) + t_0))); end return tmp end
function tmp_2 = code(x) t_0 = 1.0 + (x * 0.5); tmp = 0.0; if (x <= 1.32) tmp = (x ^ -0.5) + (-1.0 / t_0); else tmp = 1.0 / (x * (sqrt(x) + t_0)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 1.32], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x * N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + x \cdot 0.5\\
\mathbf{if}\;x \leq 1.32:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(\sqrt{x} + t_0\right)}\\
\end{array}
\end{array}
if x < 1.32000000000000006Initial program 99.7%
expm1-log1p-u91.5%
expm1-udef91.5%
pow1/291.5%
pow-flip91.5%
metadata-eval91.5%
Applied egg-rr92.3%
expm1-def91.5%
expm1-log1p99.1%
Simplified100.0%
Taylor expanded in x around 0 99.7%
*-commutative99.7%
Simplified99.7%
if 1.32000000000000006 < x Initial program 36.9%
frac-sub36.9%
*-un-lft-identity36.9%
*-rgt-identity36.9%
flip--36.9%
associate-/l/36.9%
add-sqr-sqrt36.5%
+-commutative36.5%
add-sqr-sqrt37.9%
associate--l+98.8%
sqrt-unprod85.3%
+-commutative85.3%
distribute-rgt-in85.3%
*-un-lft-identity85.3%
pow285.3%
+-commutative85.3%
+-commutative85.3%
Applied egg-rr85.3%
+-inverses85.3%
metadata-eval85.3%
+-commutative85.3%
Simplified85.3%
Taylor expanded in x around inf 97.6%
Taylor expanded in x around 0 36.7%
*-commutative36.7%
Simplified36.7%
Final simplification68.7%
(FPCore (x) :precision binary64 (if (<= x 1.65) (+ (pow x -0.5) (- -1.0 (* x -0.5))) (/ 1.0 x)))
double code(double x) {
double tmp;
if (x <= 1.65) {
tmp = pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.65d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.65) {
tmp = Math.pow(x, -0.5) + (-1.0 - (x * -0.5));
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.65: tmp = math.pow(x, -0.5) + (-1.0 - (x * -0.5)) else: tmp = 1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 1.65) tmp = Float64((x ^ -0.5) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.65) tmp = (x ^ -0.5) + (-1.0 - (x * -0.5)); else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.65], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.65:\\
\;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < 1.6499999999999999Initial program 99.7%
expm1-log1p-u91.5%
expm1-udef91.5%
pow1/291.5%
pow-flip91.5%
metadata-eval91.5%
Applied egg-rr92.3%
expm1-def91.5%
expm1-log1p99.1%
Simplified100.0%
Taylor expanded in x around 0 99.7%
if 1.6499999999999999 < x Initial program 36.9%
frac-sub36.9%
*-un-lft-identity36.9%
*-rgt-identity36.9%
flip--36.9%
associate-/l/36.9%
add-sqr-sqrt36.5%
+-commutative36.5%
add-sqr-sqrt37.9%
associate--l+98.8%
sqrt-unprod85.3%
+-commutative85.3%
distribute-rgt-in85.3%
*-un-lft-identity85.3%
pow285.3%
+-commutative85.3%
+-commutative85.3%
Applied egg-rr85.3%
+-inverses85.3%
metadata-eval85.3%
+-commutative85.3%
Simplified85.3%
Taylor expanded in x around inf 97.6%
Taylor expanded in x around 0 7.5%
Final simplification54.3%
(FPCore (x) :precision binary64 (/ 1.0 (* x (+ 1.0 (pow x -0.5)))))
double code(double x) {
return 1.0 / (x * (1.0 + pow(x, -0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * (1.0d0 + (x ** (-0.5d0))))
end function
public static double code(double x) {
return 1.0 / (x * (1.0 + Math.pow(x, -0.5)));
}
def code(x): return 1.0 / (x * (1.0 + math.pow(x, -0.5)))
function code(x) return Float64(1.0 / Float64(x * Float64(1.0 + (x ^ -0.5)))) end
function tmp = code(x) tmp = 1.0 / (x * (1.0 + (x ^ -0.5))); end
code[x_] := N[(1.0 / N[(x * N[(1.0 + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(1 + {x}^{-0.5}\right)}
\end{array}
Initial program 68.8%
flip--68.7%
flip--41.5%
associate-/l/27.0%
Applied egg-rr27.0%
Taylor expanded in x around 0 53.4%
Final simplification53.4%
(FPCore (x) :precision binary64 (if (<= x 0.82) (+ (pow x -0.5) -1.0) (/ 1.0 x)))
double code(double x) {
double tmp;
if (x <= 0.82) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.82d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.82) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.82: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 0.82) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.82) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.82], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.82:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < 0.819999999999999951Initial program 99.7%
Taylor expanded in x around 0 98.9%
expm1-log1p-u91.5%
expm1-udef91.5%
pow1/291.5%
pow-flip91.5%
metadata-eval91.5%
Applied egg-rr91.5%
expm1-def91.5%
expm1-log1p99.1%
Simplified99.1%
if 0.819999999999999951 < x Initial program 36.9%
frac-sub36.9%
*-un-lft-identity36.9%
*-rgt-identity36.9%
flip--36.9%
associate-/l/36.9%
add-sqr-sqrt36.5%
+-commutative36.5%
add-sqr-sqrt37.9%
associate--l+98.8%
sqrt-unprod85.3%
+-commutative85.3%
distribute-rgt-in85.3%
*-un-lft-identity85.3%
pow285.3%
+-commutative85.3%
+-commutative85.3%
Applied egg-rr85.3%
+-inverses85.3%
metadata-eval85.3%
+-commutative85.3%
Simplified85.3%
Taylor expanded in x around inf 97.6%
Taylor expanded in x around 0 7.5%
Final simplification54.0%
(FPCore (x) :precision binary64 (pow x -0.5))
double code(double x) {
return pow(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 Math.pow(x, -0.5);
}
def code(x): return math.pow(x, -0.5)
function code(x) return x ^ -0.5 end
function tmp = code(x) tmp = x ^ -0.5; end
code[x_] := N[Power[x, -0.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5}
\end{array}
Initial program 68.8%
inv-pow68.8%
add-sqr-sqrt61.1%
metadata-eval61.1%
unpow-prod-down57.8%
pow1/257.8%
sqrt-pow159.4%
metadata-eval59.4%
metadata-eval59.4%
pow1/259.4%
sqrt-pow157.9%
metadata-eval57.9%
metadata-eval57.9%
Applied egg-rr57.9%
pow-sqr60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around inf 52.0%
unpow1/252.0%
rem-exp-log48.3%
exp-neg48.3%
exp-prod48.3%
*-commutative48.3%
neg-mul-148.3%
associate-*r*48.3%
metadata-eval48.3%
*-commutative48.3%
exp-to-pow52.1%
Simplified52.1%
Final simplification52.1%
(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 68.8%
frac-sub68.8%
*-un-lft-identity68.8%
*-rgt-identity68.8%
flip--68.8%
associate-/l/68.8%
add-sqr-sqrt68.6%
+-commutative68.6%
add-sqr-sqrt69.3%
associate--l+99.2%
sqrt-unprod92.6%
+-commutative92.6%
distribute-rgt-in92.6%
*-un-lft-identity92.6%
pow292.6%
+-commutative92.6%
+-commutative92.6%
Applied egg-rr92.6%
+-inverses92.6%
metadata-eval92.6%
+-commutative92.6%
Simplified92.6%
Taylor expanded in x around inf 51.4%
Taylor expanded in x around 0 7.1%
Final simplification7.1%
(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 2023305
(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)))))