
(FPCore (a b) :precision binary64 (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))
double code(double a, double b) {
return ((((double) M_PI) / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
public static double code(double a, double b) {
return ((Math.PI / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
def code(a, b): return ((math.pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b))
function code(a, b) return Float64(Float64(Float64(pi / 2.0) * Float64(1.0 / Float64(Float64(b * b) - Float64(a * a)))) * Float64(Float64(1.0 / a) - Float64(1.0 / b))) end
function tmp = code(a, b) tmp = ((pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b)); end
code[a_, b_] := N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(1.0 / N[(N[(b * b), $MachinePrecision] - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))
double code(double a, double b) {
return ((((double) M_PI) / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
public static double code(double a, double b) {
return ((Math.PI / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b));
}
def code(a, b): return ((math.pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b))
function code(a, b) return Float64(Float64(Float64(pi / 2.0) * Float64(1.0 / Float64(Float64(b * b) - Float64(a * a)))) * Float64(Float64(1.0 / a) - Float64(1.0 / b))) end
function tmp = code(a, b) tmp = ((pi / 2.0) * (1.0 / ((b * b) - (a * a)))) * ((1.0 / a) - (1.0 / b)); end
code[a_, b_] := N[(N[(N[(Pi / 2.0), $MachinePrecision] * N[(1.0 / N[(N[(b * b), $MachinePrecision] - N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / a), $MachinePrecision] - N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{\pi}{2} \cdot \frac{1}{b \cdot b - a \cdot a}\right) \cdot \left(\frac{1}{a} - \frac{1}{b}\right)
\end{array}
(FPCore (a b) :precision binary64 (/ (* (/ (/ 0.5 b) a) PI) (+ b a)))
double code(double a, double b) {
return (((0.5 / b) / a) * ((double) M_PI)) / (b + a);
}
public static double code(double a, double b) {
return (((0.5 / b) / a) * Math.PI) / (b + a);
}
def code(a, b): return (((0.5 / b) / a) * math.pi) / (b + a)
function code(a, b) return Float64(Float64(Float64(Float64(0.5 / b) / a) * pi) / Float64(b + a)) end
function tmp = code(a, b) tmp = (((0.5 / b) / a) * pi) / (b + a); end
code[a_, b_] := N[(N[(N[(N[(0.5 / b), $MachinePrecision] / a), $MachinePrecision] * Pi), $MachinePrecision] / N[(b + a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{0.5}{b}}{a} \cdot \pi}{b + a}
\end{array}
Initial program 80.0%
div-inv80.1%
clear-num80.0%
frac-sub79.9%
frac-times75.0%
*-un-lft-identity75.0%
*-un-lft-identity75.0%
div-inv75.0%
metadata-eval75.0%
Applied egg-rr75.0%
*-rgt-identity75.0%
*-commutative75.0%
associate-*r/75.0%
associate-/l*75.0%
*-commutative75.0%
associate-*l*75.0%
*-commutative75.0%
Simplified75.0%
*-un-lft-identity75.0%
times-frac80.0%
*-commutative80.0%
Applied egg-rr80.0%
*-lft-identity80.0%
associate-*l/80.0%
difference-of-squares86.6%
+-commutative86.6%
times-frac99.6%
*-commutative99.6%
times-frac88.3%
Simplified88.3%
expm1-log1p-u73.0%
expm1-udef49.6%
*-commutative49.6%
associate-/l*49.6%
Applied egg-rr49.6%
expm1-def73.0%
expm1-log1p88.3%
associate-/l/88.3%
associate-/r*88.3%
associate-/r/99.6%
*-inverses99.6%
Simplified99.6%
associate-*r/99.6%
*-un-lft-identity99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= b 4.7e-133) (* (/ (/ 0.5 a) b) (/ PI a)) (* 0.5 (/ (/ PI (* b b)) a))))
double code(double a, double b) {
double tmp;
if (b <= 4.7e-133) {
tmp = ((0.5 / a) / b) * (((double) M_PI) / a);
} else {
tmp = 0.5 * ((((double) M_PI) / (b * b)) / a);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 4.7e-133) {
tmp = ((0.5 / a) / b) * (Math.PI / a);
} else {
tmp = 0.5 * ((Math.PI / (b * b)) / a);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4.7e-133: tmp = ((0.5 / a) / b) * (math.pi / a) else: tmp = 0.5 * ((math.pi / (b * b)) / a) return tmp
function code(a, b) tmp = 0.0 if (b <= 4.7e-133) tmp = Float64(Float64(Float64(0.5 / a) / b) * Float64(pi / a)); else tmp = Float64(0.5 * Float64(Float64(pi / Float64(b * b)) / a)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4.7e-133) tmp = ((0.5 / a) / b) * (pi / a); else tmp = 0.5 * ((pi / (b * b)) / a); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4.7e-133], N[(N[(N[(0.5 / a), $MachinePrecision] / b), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(Pi / N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-133}:\\
\;\;\;\;\frac{\frac{0.5}{a}}{b} \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\frac{\pi}{b \cdot b}}{a}\\
\end{array}
\end{array}
if b < 4.70000000000000003e-133Initial program 80.1%
div-inv80.2%
clear-num80.1%
frac-sub80.0%
frac-times74.2%
*-un-lft-identity74.2%
*-un-lft-identity74.2%
div-inv74.2%
metadata-eval74.2%
Applied egg-rr74.2%
*-rgt-identity74.2%
*-commutative74.2%
associate-*r/74.3%
associate-/l*74.3%
*-commutative74.3%
associate-*l*74.3%
*-commutative74.3%
Simplified74.3%
*-un-lft-identity74.3%
times-frac80.1%
*-commutative80.1%
Applied egg-rr80.1%
*-lft-identity80.1%
associate-*l/80.0%
difference-of-squares87.8%
+-commutative87.8%
times-frac99.6%
*-commutative99.6%
times-frac81.4%
Simplified81.4%
Taylor expanded in a around 0 99.6%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in a around inf 68.6%
if 4.70000000000000003e-133 < b Initial program 80.0%
inv-pow80.0%
difference-of-squares84.9%
unpow-prod-down84.7%
inv-pow84.7%
inv-pow84.7%
Applied egg-rr84.7%
associate-*r/84.8%
*-rgt-identity84.8%
+-commutative84.8%
Simplified84.8%
Taylor expanded in a around 0 66.2%
associate-*r/66.2%
times-frac66.1%
unpow266.1%
associate-*l/66.1%
*-lft-identity66.1%
times-frac66.1%
metadata-eval66.1%
Simplified66.1%
Final simplification67.6%
(FPCore (a b) :precision binary64 (let* ((t_0 (/ (/ 0.5 a) b))) (if (<= b 4.7e-133) (* t_0 (/ PI a)) (* t_0 (/ PI b)))))
double code(double a, double b) {
double t_0 = (0.5 / a) / b;
double tmp;
if (b <= 4.7e-133) {
tmp = t_0 * (((double) M_PI) / a);
} else {
tmp = t_0 * (((double) M_PI) / b);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = (0.5 / a) / b;
double tmp;
if (b <= 4.7e-133) {
tmp = t_0 * (Math.PI / a);
} else {
tmp = t_0 * (Math.PI / b);
}
return tmp;
}
def code(a, b): t_0 = (0.5 / a) / b tmp = 0 if b <= 4.7e-133: tmp = t_0 * (math.pi / a) else: tmp = t_0 * (math.pi / b) return tmp
function code(a, b) t_0 = Float64(Float64(0.5 / a) / b) tmp = 0.0 if (b <= 4.7e-133) tmp = Float64(t_0 * Float64(pi / a)); else tmp = Float64(t_0 * Float64(pi / b)); end return tmp end
function tmp_2 = code(a, b) t_0 = (0.5 / a) / b; tmp = 0.0; if (b <= 4.7e-133) tmp = t_0 * (pi / a); else tmp = t_0 * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(N[(0.5 / a), $MachinePrecision] / b), $MachinePrecision]}, If[LessEqual[b, 4.7e-133], N[(t$95$0 * N[(Pi / a), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(Pi / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\frac{0.5}{a}}{b}\\
\mathbf{if}\;b \leq 4.7 \cdot 10^{-133}:\\
\;\;\;\;t_0 \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 4.70000000000000003e-133Initial program 80.1%
div-inv80.2%
clear-num80.1%
frac-sub80.0%
frac-times74.2%
*-un-lft-identity74.2%
*-un-lft-identity74.2%
div-inv74.2%
metadata-eval74.2%
Applied egg-rr74.2%
*-rgt-identity74.2%
*-commutative74.2%
associate-*r/74.3%
associate-/l*74.3%
*-commutative74.3%
associate-*l*74.3%
*-commutative74.3%
Simplified74.3%
*-un-lft-identity74.3%
times-frac80.1%
*-commutative80.1%
Applied egg-rr80.1%
*-lft-identity80.1%
associate-*l/80.0%
difference-of-squares87.8%
+-commutative87.8%
times-frac99.6%
*-commutative99.6%
times-frac81.4%
Simplified81.4%
Taylor expanded in a around 0 99.6%
associate-/r*99.6%
Simplified99.6%
Taylor expanded in a around inf 68.6%
if 4.70000000000000003e-133 < b Initial program 80.0%
div-inv79.9%
clear-num79.9%
frac-sub79.8%
frac-times76.1%
*-un-lft-identity76.1%
*-un-lft-identity76.1%
div-inv76.1%
metadata-eval76.1%
Applied egg-rr76.1%
*-rgt-identity76.1%
*-commutative76.1%
associate-*r/76.1%
associate-/l*76.1%
*-commutative76.1%
associate-*l*76.1%
*-commutative76.1%
Simplified76.1%
*-un-lft-identity76.1%
times-frac79.9%
*-commutative79.9%
Applied egg-rr79.9%
*-lft-identity79.9%
associate-*l/79.9%
difference-of-squares84.8%
+-commutative84.8%
times-frac99.6%
*-commutative99.6%
times-frac98.7%
Simplified98.7%
Taylor expanded in a around 0 99.7%
associate-/r*99.7%
Simplified99.7%
Taylor expanded in a around 0 80.0%
Final simplification73.1%
(FPCore (a b) :precision binary64 (* (/ PI (+ b a)) (/ 0.5 (* b a))))
double code(double a, double b) {
return (((double) M_PI) / (b + a)) * (0.5 / (b * a));
}
public static double code(double a, double b) {
return (Math.PI / (b + a)) * (0.5 / (b * a));
}
def code(a, b): return (math.pi / (b + a)) * (0.5 / (b * a))
function code(a, b) return Float64(Float64(pi / Float64(b + a)) * Float64(0.5 / Float64(b * a))) end
function tmp = code(a, b) tmp = (pi / (b + a)) * (0.5 / (b * a)); end
code[a_, b_] := N[(N[(Pi / N[(b + a), $MachinePrecision]), $MachinePrecision] * N[(0.5 / N[(b * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{b + a} \cdot \frac{0.5}{b \cdot a}
\end{array}
Initial program 80.0%
div-inv80.1%
clear-num80.0%
frac-sub79.9%
frac-times75.0%
*-un-lft-identity75.0%
*-un-lft-identity75.0%
div-inv75.0%
metadata-eval75.0%
Applied egg-rr75.0%
*-rgt-identity75.0%
*-commutative75.0%
associate-*r/75.0%
associate-/l*75.0%
*-commutative75.0%
associate-*l*75.0%
*-commutative75.0%
Simplified75.0%
*-un-lft-identity75.0%
times-frac80.0%
*-commutative80.0%
Applied egg-rr80.0%
*-lft-identity80.0%
associate-*l/80.0%
difference-of-squares86.6%
+-commutative86.6%
times-frac99.6%
*-commutative99.6%
times-frac88.3%
Simplified88.3%
Taylor expanded in a around 0 99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (* (/ PI (+ b a)) (/ (/ 0.5 a) b)))
double code(double a, double b) {
return (((double) M_PI) / (b + a)) * ((0.5 / a) / b);
}
public static double code(double a, double b) {
return (Math.PI / (b + a)) * ((0.5 / a) / b);
}
def code(a, b): return (math.pi / (b + a)) * ((0.5 / a) / b)
function code(a, b) return Float64(Float64(pi / Float64(b + a)) * Float64(Float64(0.5 / a) / b)) end
function tmp = code(a, b) tmp = (pi / (b + a)) * ((0.5 / a) / b); end
code[a_, b_] := N[(N[(Pi / N[(b + a), $MachinePrecision]), $MachinePrecision] * N[(N[(0.5 / a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{b + a} \cdot \frac{\frac{0.5}{a}}{b}
\end{array}
Initial program 80.0%
div-inv80.1%
clear-num80.0%
frac-sub79.9%
frac-times75.0%
*-un-lft-identity75.0%
*-un-lft-identity75.0%
div-inv75.0%
metadata-eval75.0%
Applied egg-rr75.0%
*-rgt-identity75.0%
*-commutative75.0%
associate-*r/75.0%
associate-/l*75.0%
*-commutative75.0%
associate-*l*75.0%
*-commutative75.0%
Simplified75.0%
*-un-lft-identity75.0%
times-frac80.0%
*-commutative80.0%
Applied egg-rr80.0%
*-lft-identity80.0%
associate-*l/80.0%
difference-of-squares86.6%
+-commutative86.6%
times-frac99.6%
*-commutative99.6%
times-frac88.3%
Simplified88.3%
Taylor expanded in a around 0 99.6%
associate-/r*99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (* 0.5 (/ (/ PI a) (* b b))))
double code(double a, double b) {
return 0.5 * ((((double) M_PI) / a) / (b * b));
}
public static double code(double a, double b) {
return 0.5 * ((Math.PI / a) / (b * b));
}
def code(a, b): return 0.5 * ((math.pi / a) / (b * b))
function code(a, b) return Float64(0.5 * Float64(Float64(pi / a) / Float64(b * b))) end
function tmp = code(a, b) tmp = 0.5 * ((pi / a) / (b * b)); end
code[a_, b_] := N[(0.5 * N[(N[(Pi / a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{\frac{\pi}{a}}{b \cdot b}
\end{array}
Initial program 80.0%
inv-pow80.0%
difference-of-squares86.7%
unpow-prod-down86.8%
inv-pow86.8%
inv-pow86.8%
Applied egg-rr86.8%
associate-*r/86.9%
*-rgt-identity86.9%
+-commutative86.9%
Simplified86.9%
Taylor expanded in a around 0 57.0%
associate-/r*57.2%
unpow257.2%
Simplified57.2%
Final simplification57.2%
(FPCore (a b) :precision binary64 (* 0.5 (/ (/ PI (* b b)) a)))
double code(double a, double b) {
return 0.5 * ((((double) M_PI) / (b * b)) / a);
}
public static double code(double a, double b) {
return 0.5 * ((Math.PI / (b * b)) / a);
}
def code(a, b): return 0.5 * ((math.pi / (b * b)) / a)
function code(a, b) return Float64(0.5 * Float64(Float64(pi / Float64(b * b)) / a)) end
function tmp = code(a, b) tmp = 0.5 * ((pi / (b * b)) / a); end
code[a_, b_] := N[(0.5 * N[(N[(Pi / N[(b * b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{\frac{\pi}{b \cdot b}}{a}
\end{array}
Initial program 80.0%
inv-pow80.0%
difference-of-squares86.7%
unpow-prod-down86.8%
inv-pow86.8%
inv-pow86.8%
Applied egg-rr86.8%
associate-*r/86.9%
*-rgt-identity86.9%
+-commutative86.9%
Simplified86.9%
Taylor expanded in a around 0 57.0%
associate-*r/57.0%
times-frac57.2%
unpow257.2%
associate-*l/57.2%
*-lft-identity57.2%
times-frac57.2%
metadata-eval57.2%
Simplified57.2%
Final simplification57.2%
herbie shell --seed 2023287
(FPCore (a b)
:name "NMSE Section 6.1 mentioned, B"
:precision binary64
(* (* (/ PI 2.0) (/ 1.0 (- (* b b) (* a a)))) (- (/ 1.0 a) (/ 1.0 b))))