
(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 8 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 (if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ 1.0 x)))) 5e-17) (* 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)))) <= 5e-17) {
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)))) <= 5d-17) 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)))) <= 5e-17) {
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)))) <= 5e-17: 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)))) <= 5e-17) 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)))) <= 5e-17) 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], 5e-17], 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 5 \cdot 10^{-17}:\\
\;\;\;\;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)))) < 4.9999999999999999e-17Initial program 39.1%
flip--39.0%
frac-times17.0%
metadata-eval17.0%
add-sqr-sqrt19.5%
frac-times26.5%
metadata-eval26.5%
add-sqr-sqrt39.1%
+-commutative39.1%
pow1/239.1%
pow-flip39.1%
metadata-eval39.1%
inv-pow39.1%
sqrt-pow239.1%
+-commutative39.1%
metadata-eval39.1%
Applied egg-rr39.1%
frac-sub41.1%
*-un-lft-identity41.1%
Applied egg-rr41.1%
associate-/r*41.1%
*-rgt-identity41.1%
associate--l+85.1%
+-inverses85.1%
metadata-eval85.1%
Simplified85.1%
Taylor expanded in x around inf 68.0%
unpow-168.0%
exp-to-pow65.6%
*-commutative65.6%
exp-prod66.4%
*-commutative66.4%
associate-*r*66.4%
metadata-eval66.4%
*-commutative66.4%
exp-to-pow68.8%
metadata-eval68.8%
pow-sqr68.9%
rem-sqrt-square99.6%
rem-square-sqrt99.2%
fabs-sqr99.2%
rem-square-sqrt99.6%
Simplified99.6%
if 4.9999999999999999e-17 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.7%
metadata-eval99.7%
pow1/299.7%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.5%
associate--l-99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
metadata-eval99.5%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x) :precision binary64 (* (/ 1.0 x) (/ 1.0 (* (+ 1.0 x) (+ (pow x -0.5) (pow (+ 1.0 x) -0.5))))))
double code(double x) {
return (1.0 / x) * (1.0 / ((1.0 + x) * (pow(x, -0.5) + pow((1.0 + x), -0.5))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) * (1.0d0 / ((1.0d0 + x) * ((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0)))))
end function
public static double code(double x) {
return (1.0 / x) * (1.0 / ((1.0 + x) * (Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5))));
}
def code(x): return (1.0 / x) * (1.0 / ((1.0 + x) * (math.pow(x, -0.5) + math.pow((1.0 + x), -0.5))))
function code(x) return Float64(Float64(1.0 / x) * Float64(1.0 / Float64(Float64(1.0 + x) * Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5))))) end
function tmp = code(x) tmp = (1.0 / x) * (1.0 / ((1.0 + x) * ((x ^ -0.5) + ((1.0 + x) ^ -0.5)))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / N[(N[(1.0 + x), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} \cdot \frac{1}{\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}
\end{array}
Initial program 68.8%
flip--68.6%
frac-times57.3%
metadata-eval57.3%
add-sqr-sqrt58.6%
frac-times62.2%
metadata-eval62.2%
add-sqr-sqrt68.6%
+-commutative68.6%
pow1/268.6%
pow-flip68.6%
metadata-eval68.6%
inv-pow68.6%
sqrt-pow268.6%
+-commutative68.6%
metadata-eval68.6%
Applied egg-rr68.6%
frac-sub69.7%
*-un-lft-identity69.7%
Applied egg-rr69.7%
associate-/r*69.7%
*-rgt-identity69.7%
associate--l+92.1%
+-inverses92.1%
metadata-eval92.1%
Simplified92.1%
associate-/l/99.4%
div-inv99.3%
*-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(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%
inv-pow99.6%
add-sqr-sqrt99.1%
unpow-prod-down99.0%
pow1/299.0%
sqrt-pow199.1%
metadata-eval99.1%
pow1/299.1%
sqrt-pow199.0%
metadata-eval99.0%
Applied egg-rr99.0%
pow-sqr99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around 0 98.2%
*-commutative98.2%
Simplified98.2%
expm1-log1p-u91.8%
expm1-udef91.8%
log1p-udef91.8%
+-commutative91.8%
add-exp-log98.2%
+-commutative98.2%
pow-pow98.9%
metadata-eval98.9%
Applied egg-rr98.9%
+-commutative98.9%
associate--l+98.9%
metadata-eval98.9%
+-rgt-identity98.9%
Simplified98.9%
if 1.69999999999999996 < x Initial program 40.3%
flip--40.1%
frac-times18.6%
metadata-eval18.6%
add-sqr-sqrt21.0%
frac-times27.8%
metadata-eval27.8%
add-sqr-sqrt40.2%
+-commutative40.2%
pow1/240.2%
pow-flip40.2%
metadata-eval40.2%
inv-pow40.2%
sqrt-pow240.2%
+-commutative40.2%
metadata-eval40.2%
Applied egg-rr40.2%
frac-sub42.4%
*-un-lft-identity42.4%
Applied egg-rr42.4%
associate-/r*42.4%
*-rgt-identity42.4%
associate--l+85.5%
+-inverses85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in x around inf 67.2%
unpow-167.2%
exp-to-pow64.9%
*-commutative64.9%
exp-prod65.6%
*-commutative65.6%
associate-*r*65.6%
metadata-eval65.6%
*-commutative65.6%
exp-to-pow67.9%
metadata-eval67.9%
pow-sqr68.0%
rem-sqrt-square98.1%
rem-square-sqrt97.7%
fabs-sqr97.7%
rem-square-sqrt98.1%
Simplified98.1%
Final simplification98.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%
*-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%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
if 1 < x Initial program 40.3%
flip--40.1%
frac-times18.6%
metadata-eval18.6%
add-sqr-sqrt21.0%
frac-times27.8%
metadata-eval27.8%
add-sqr-sqrt40.2%
+-commutative40.2%
pow1/240.2%
pow-flip40.2%
metadata-eval40.2%
inv-pow40.2%
sqrt-pow240.2%
+-commutative40.2%
metadata-eval40.2%
Applied egg-rr40.2%
frac-sub42.4%
*-un-lft-identity42.4%
Applied egg-rr42.4%
associate-/r*42.4%
*-rgt-identity42.4%
associate--l+85.5%
+-inverses85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in x around inf 67.2%
unpow-167.2%
exp-to-pow64.9%
*-commutative64.9%
exp-prod65.6%
*-commutative65.6%
associate-*r*65.6%
metadata-eval65.6%
*-commutative65.6%
exp-to-pow67.9%
metadata-eval67.9%
pow-sqr68.0%
rem-sqrt-square98.1%
rem-square-sqrt97.7%
fabs-sqr97.7%
rem-square-sqrt98.1%
Simplified98.1%
Final simplification98.4%
(FPCore (x) :precision binary64 (if (<= x 0.5) (pow x -0.5) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.5) {
tmp = pow(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 <= 0.5d0) then
tmp = 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 <= 0.5) {
tmp = Math.pow(x, -0.5);
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.5: tmp = math.pow(x, -0.5) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.5) tmp = 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 <= 0.5) tmp = x ^ -0.5; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.5], N[Power[x, -0.5], $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.5:\\
\;\;\;\;{x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.5Initial program 99.6%
inv-pow99.6%
add-sqr-sqrt99.1%
unpow-prod-down99.0%
pow1/299.0%
sqrt-pow199.1%
metadata-eval99.1%
pow1/299.1%
sqrt-pow199.0%
metadata-eval99.0%
Applied egg-rr99.0%
pow-sqr99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around 0 98.2%
*-commutative98.2%
Simplified98.2%
Taylor expanded in x around inf 94.8%
inv-pow94.8%
sqrt-pow194.9%
metadata-eval94.9%
*-un-lft-identity94.9%
Applied egg-rr94.9%
*-lft-identity94.9%
Simplified94.9%
if 0.5 < x Initial program 40.3%
flip--40.1%
frac-times18.6%
metadata-eval18.6%
add-sqr-sqrt21.0%
frac-times27.8%
metadata-eval27.8%
add-sqr-sqrt40.2%
+-commutative40.2%
pow1/240.2%
pow-flip40.2%
metadata-eval40.2%
inv-pow40.2%
sqrt-pow240.2%
+-commutative40.2%
metadata-eval40.2%
Applied egg-rr40.2%
frac-sub42.4%
*-un-lft-identity42.4%
Applied egg-rr42.4%
associate-/r*42.4%
*-rgt-identity42.4%
associate--l+85.5%
+-inverses85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in x around inf 67.2%
unpow-167.2%
exp-to-pow64.9%
*-commutative64.9%
exp-prod65.6%
*-commutative65.6%
associate-*r*65.6%
metadata-eval65.6%
*-commutative65.6%
exp-to-pow67.9%
metadata-eval67.9%
pow-sqr68.0%
rem-sqrt-square98.1%
rem-square-sqrt97.7%
fabs-sqr97.7%
rem-square-sqrt98.1%
Simplified98.1%
Final simplification96.5%
(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%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
Simplified100.0%
Taylor expanded in x around 0 97.8%
if 0.680000000000000049 < x Initial program 40.3%
flip--40.1%
frac-times18.6%
metadata-eval18.6%
add-sqr-sqrt21.0%
frac-times27.8%
metadata-eval27.8%
add-sqr-sqrt40.2%
+-commutative40.2%
pow1/240.2%
pow-flip40.2%
metadata-eval40.2%
inv-pow40.2%
sqrt-pow240.2%
+-commutative40.2%
metadata-eval40.2%
Applied egg-rr40.2%
frac-sub42.4%
*-un-lft-identity42.4%
Applied egg-rr42.4%
associate-/r*42.4%
*-rgt-identity42.4%
associate--l+85.5%
+-inverses85.5%
metadata-eval85.5%
Simplified85.5%
Taylor expanded in x around inf 67.2%
unpow-167.2%
exp-to-pow64.9%
*-commutative64.9%
exp-prod65.6%
*-commutative65.6%
associate-*r*65.6%
metadata-eval65.6%
*-commutative65.6%
exp-to-pow67.9%
metadata-eval67.9%
pow-sqr68.0%
rem-sqrt-square98.1%
rem-square-sqrt97.7%
fabs-sqr97.7%
rem-square-sqrt98.1%
Simplified98.1%
Final simplification97.9%
(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-sqrt59.9%
unpow-prod-down58.8%
pow1/258.8%
sqrt-pow158.7%
metadata-eval58.7%
pow1/258.7%
sqrt-pow157.8%
metadata-eval57.8%
Applied egg-rr57.8%
pow-sqr57.9%
metadata-eval57.9%
Simplified57.9%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
Simplified50.1%
Taylor expanded in x around inf 48.5%
inv-pow48.5%
sqrt-pow148.5%
metadata-eval48.5%
*-un-lft-identity48.5%
Applied egg-rr48.5%
*-lft-identity48.5%
Simplified48.5%
Final simplification48.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 68.8%
Taylor expanded in x around 0 48.2%
Taylor expanded in x around inf 2.0%
Final simplification2.0%
(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 2024024
(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)))))