
(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 9 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)
(* (pow x -1.5) 0.5)
(/ (/ 1.0 (+ (sqrt x) t_0)) (sqrt (fma x x 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 = pow(x, -1.5) * 0.5;
} else {
tmp = (1.0 / (sqrt(x) + t_0)) / sqrt(fma(x, x, 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((x ^ -1.5) * 0.5); else tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / sqrt(fma(x, x, x))); end return 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[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * x + x), $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:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{\sqrt{\mathsf{fma}\left(x, x, x\right)}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 38.4%
flip--38.4%
clear-num38.4%
*-un-lft-identity38.4%
associate-/l*38.4%
flip--38.4%
pow1/238.4%
pow-flip27.0%
metadata-eval27.0%
pow1/227.0%
pow-flip38.4%
+-commutative38.4%
metadata-eval38.4%
Applied egg-rr38.4%
Taylor expanded in x around inf 65.4%
div-inv65.4%
associate-/r*65.4%
metadata-eval65.4%
sqrt-pow197.7%
metadata-eval97.7%
Applied egg-rr97.7%
*-lft-identity97.7%
Simplified97.7%
div-inv97.7%
*-commutative97.7%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 97.5%
frac-sub97.5%
*-un-lft-identity97.5%
*-rgt-identity97.5%
flip--98.0%
associate-/l/97.9%
add-sqr-sqrt98.7%
+-commutative98.7%
add-sqr-sqrt99.5%
associate--l+99.5%
sqrt-unprod99.6%
+-commutative99.6%
distribute-rgt-in99.6%
*-un-lft-identity99.6%
pow299.6%
+-commutative99.6%
+-commutative99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-commutative99.6%
associate-/r*99.6%
+-commutative99.6%
+-commutative99.6%
unpow299.6%
fma-def99.6%
Simplified99.6%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 t_0)) 1e-6)
(/ (/ 1.0 (+ (sqrt x) t_0)) (+ x (- 0.5 (/ 0.125 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)) <= 1e-6) {
tmp = (1.0 / (sqrt(x) + t_0)) / (x + (0.5 - (0.125 / 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)) <= 1d-6) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / (x + (0.5d0 - (0.125d0 / 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)) <= 1e-6) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / (x + (0.5 - (0.125 / 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)) <= 1e-6: tmp = (1.0 / (math.sqrt(x) + t_0)) / (x + (0.5 - (0.125 / 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)) <= 1e-6) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(x + Float64(0.5 - Float64(0.125 / 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)) <= 1e-6) tmp = (1.0 / (sqrt(x) + t_0)) / (x + (0.5 - (0.125 / 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], 1e-6], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x + N[(0.5 - N[(0.125 / 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 10^{-6}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + \left(0.5 - \frac{0.125}{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)))) < 9.99999999999999955e-7Initial program 39.0%
frac-sub39.0%
*-un-lft-identity39.0%
*-rgt-identity39.0%
flip--39.5%
associate-/l/39.6%
add-sqr-sqrt40.2%
+-commutative40.2%
add-sqr-sqrt41.2%
associate--l+97.3%
sqrt-unprod84.4%
+-commutative84.4%
distribute-rgt-in84.4%
*-un-lft-identity84.4%
pow284.4%
+-commutative84.4%
+-commutative84.4%
Applied egg-rr84.4%
+-inverses84.4%
metadata-eval84.4%
*-commutative84.4%
associate-/r*84.3%
+-commutative84.3%
+-commutative84.3%
unpow284.3%
fma-def84.3%
Simplified84.3%
Taylor expanded in x around inf 99.5%
+-commutative99.5%
associate--l+99.5%
associate-*r/99.5%
metadata-eval99.5%
Simplified99.5%
if 9.99999999999999955e-7 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.7%
expm1-log1p-u99.7%
expm1-udef99.6%
associate--r-99.6%
pow1/299.7%
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-def100.0%
expm1-log1p100.0%
Simplified100.0%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ 1.0 x)))) 1e-20) (* (pow x -1.5) 0.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-20) {
tmp = pow(x, -1.5) * 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) :: tmp
if (((1.0d0 / sqrt(x)) - (1.0d0 / sqrt((1.0d0 + x)))) <= 1d-20) then
tmp = (x ** (-1.5d0)) * 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 tmp;
if (((1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((1.0 + x)))) <= 1e-20) {
tmp = Math.pow(x, -1.5) * 0.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-20: tmp = math.pow(x, -1.5) * 0.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-20) tmp = Float64((x ^ -1.5) * 0.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-20) tmp = (x ^ -1.5) * 0.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-20], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $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^{-20}:\\
\;\;\;\;{x}^{-1.5} \cdot 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)))) < 9.99999999999999945e-21Initial program 38.1%
flip--38.1%
clear-num38.1%
*-un-lft-identity38.1%
associate-/l*38.1%
flip--38.1%
pow1/238.1%
pow-flip27.0%
metadata-eval27.0%
pow1/227.0%
pow-flip38.2%
+-commutative38.2%
metadata-eval38.2%
Applied egg-rr38.2%
Taylor expanded in x around inf 66.1%
div-inv66.1%
associate-/r*66.1%
metadata-eval66.1%
sqrt-pow197.6%
metadata-eval97.6%
Applied egg-rr97.6%
*-lft-identity97.6%
Simplified97.6%
div-inv97.6%
*-commutative97.6%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
if 9.99999999999999945e-21 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.1%
expm1-log1p-u99.1%
expm1-udef98.8%
associate--r-98.8%
pow1/298.8%
pow-flip99.1%
metadata-eval99.1%
pow1/299.1%
pow-flip99.1%
+-commutative99.1%
metadata-eval99.1%
Applied egg-rr99.1%
associate-+l-99.1%
expm1-def99.5%
expm1-log1p99.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -1.5) * 0.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 = (x ** (-1.5d0)) * 0.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 = Math.pow(x, -1.5) * 0.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 = math.pow(x, -1.5) * 0.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((x ^ -1.5) * 0.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 = (x ^ -1.5) * 0.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[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 1Initial program 99.7%
flip--99.5%
clear-num99.4%
*-un-lft-identity99.4%
associate-/l*99.5%
flip--99.6%
pow1/299.6%
pow-flip99.9%
metadata-eval99.9%
pow1/299.9%
pow-flip99.9%
+-commutative99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.8%
Taylor expanded in x around 0 98.9%
if 1 < x Initial program 39.0%
flip--39.0%
clear-num39.0%
*-un-lft-identity39.0%
associate-/l*39.0%
flip--39.0%
pow1/239.0%
pow-flip28.1%
metadata-eval28.1%
pow1/228.1%
pow-flip39.1%
+-commutative39.1%
metadata-eval39.1%
Applied egg-rr39.1%
Taylor expanded in x around inf 65.5%
div-inv65.5%
associate-/r*65.5%
metadata-eval65.5%
sqrt-pow196.3%
metadata-eval96.3%
Applied egg-rr96.3%
*-lft-identity96.3%
Simplified96.3%
div-inv96.3%
*-commutative96.3%
pow-flip98.5%
metadata-eval98.5%
Applied egg-rr98.5%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 0.66) (+ (pow x -0.5) -1.0) (* (pow x -1.5) 0.5)))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow(x, -1.5) * 0.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 = (x ** (-1.5d0)) * 0.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 = Math.pow(x, -1.5) * 0.5;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow(x, -1.5) * 0.5 return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64((x ^ -1.5) * 0.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 = (x ^ -1.5) * 0.5; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-1.5} \cdot 0.5\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.7%
Taylor expanded in x around 0 99.1%
expm1-log1p-u92.2%
expm1-udef92.2%
pow1/292.2%
pow-flip92.2%
metadata-eval92.2%
Applied egg-rr92.2%
expm1-def92.2%
expm1-log1p99.4%
Simplified99.4%
if 0.660000000000000031 < x Initial program 39.5%
flip--39.5%
clear-num39.5%
*-un-lft-identity39.5%
associate-/l*39.5%
flip--39.5%
pow1/239.5%
pow-flip28.7%
metadata-eval28.7%
pow1/228.7%
pow-flip39.5%
+-commutative39.5%
metadata-eval39.5%
Applied egg-rr39.5%
Taylor expanded in x around inf 65.2%
div-inv65.2%
associate-/r*65.2%
metadata-eval65.2%
sqrt-pow195.7%
metadata-eval95.7%
Applied egg-rr95.7%
*-lft-identity95.7%
Simplified95.7%
div-inv95.7%
*-commutative95.7%
pow-flip97.9%
metadata-eval97.9%
Applied egg-rr97.9%
Final simplification98.6%
(FPCore (x) :precision binary64 (* (pow x -1.5) 0.5))
double code(double x) {
return pow(x, -1.5) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-1.5d0)) * 0.5d0
end function
public static double code(double x) {
return Math.pow(x, -1.5) * 0.5;
}
def code(x): return math.pow(x, -1.5) * 0.5
function code(x) return Float64((x ^ -1.5) * 0.5) end
function tmp = code(x) tmp = (x ^ -1.5) * 0.5; end
code[x_] := N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5} \cdot 0.5
\end{array}
Initial program 68.9%
flip--68.8%
clear-num68.7%
*-un-lft-identity68.7%
associate-/l*68.8%
flip--68.9%
pow1/268.9%
pow-flip63.4%
metadata-eval63.4%
pow1/263.4%
pow-flip69.0%
+-commutative69.0%
metadata-eval69.0%
Applied egg-rr69.0%
Taylor expanded in x around inf 36.0%
div-inv36.0%
associate-/r*36.0%
metadata-eval36.0%
sqrt-pow151.7%
metadata-eval51.7%
Applied egg-rr51.7%
*-lft-identity51.7%
Simplified51.7%
div-inv51.7%
*-commutative51.7%
pow-flip52.9%
metadata-eval52.9%
Applied egg-rr52.9%
Final simplification52.9%
(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.9%
frac-sub68.9%
*-un-lft-identity68.9%
*-rgt-identity68.9%
flip--69.1%
associate-/l/69.1%
add-sqr-sqrt69.4%
+-commutative69.4%
add-sqr-sqrt69.9%
associate--l+98.4%
sqrt-unprod91.9%
+-commutative91.9%
distribute-rgt-in91.9%
*-un-lft-identity91.9%
pow291.9%
+-commutative91.9%
+-commutative91.9%
Applied egg-rr91.9%
+-inverses91.9%
metadata-eval91.9%
*-commutative91.9%
associate-/r*91.9%
+-commutative91.9%
+-commutative91.9%
unpow291.9%
fma-def91.9%
Simplified91.9%
Taylor expanded in x around inf 53.4%
Taylor expanded in x around 0 7.3%
Final simplification7.3%
(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.9%
Taylor expanded in x around 0 49.8%
Taylor expanded in x around inf 2.0%
Final simplification2.0%
(FPCore (x) :precision binary64 2.0)
double code(double x) {
return 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0
end function
public static double code(double x) {
return 2.0;
}
def code(x): return 2.0
function code(x) return 2.0 end
function tmp = code(x) tmp = 2.0; end
code[x_] := 2.0
\begin{array}{l}
\\
2
\end{array}
Initial program 68.9%
frac-sub68.9%
div-inv68.9%
*-un-lft-identity68.9%
*-rgt-identity68.9%
flip--69.1%
metadata-eval69.1%
frac-times69.1%
associate-*l/69.1%
Applied egg-rr91.9%
Taylor expanded in x around inf 53.8%
Simplified53.8%
Taylor expanded in x around 0 5.7%
Final simplification5.7%
(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 2023301
(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)))))