
(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 5 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 (/ PI (* a b))) (+ a b)))
double code(double a, double b) {
return (0.5 * (((double) M_PI) / (a * b))) / (a + b);
}
public static double code(double a, double b) {
return (0.5 * (Math.PI / (a * b))) / (a + b);
}
def code(a, b): return (0.5 * (math.pi / (a * b))) / (a + b)
function code(a, b) return Float64(Float64(0.5 * Float64(pi / Float64(a * b))) / Float64(a + b)) end
function tmp = code(a, b) tmp = (0.5 * (pi / (a * b))) / (a + b); end
code[a_, b_] := N[(N[(0.5 * N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\pi}{a \cdot b}}{a + b}
\end{array}
Initial program 76.9%
associate-*l*76.9%
associate-*l/76.9%
*-lft-identity76.9%
difference-of-squares85.8%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
Final simplification99.7%
(FPCore (a b) :precision binary64 (if (<= a -8.2e-22) (/ (* (/ 0.5 a) (/ PI a)) b) (* (/ PI b) (/ 0.5 (* a b)))))
double code(double a, double b) {
double tmp;
if (a <= -8.2e-22) {
tmp = ((0.5 / a) * (((double) M_PI) / a)) / b;
} else {
tmp = (((double) M_PI) / b) * (0.5 / (a * b));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -8.2e-22) {
tmp = ((0.5 / a) * (Math.PI / a)) / b;
} else {
tmp = (Math.PI / b) * (0.5 / (a * b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -8.2e-22: tmp = ((0.5 / a) * (math.pi / a)) / b else: tmp = (math.pi / b) * (0.5 / (a * b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -8.2e-22) tmp = Float64(Float64(Float64(0.5 / a) * Float64(pi / a)) / b); else tmp = Float64(Float64(pi / b) * Float64(0.5 / Float64(a * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -8.2e-22) tmp = ((0.5 / a) * (pi / a)) / b; else tmp = (pi / b) * (0.5 / (a * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -8.2e-22], N[(N[(N[(0.5 / a), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], N[(N[(Pi / b), $MachinePrecision] * N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -8.2 \cdot 10^{-22}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot \frac{\pi}{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b} \cdot \frac{0.5}{a \cdot b}\\
\end{array}
\end{array}
if a < -8.1999999999999999e-22Initial program 76.2%
associate-*l*76.1%
associate-*l/76.2%
*-lft-identity76.2%
difference-of-squares85.9%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.6%
*-commutative99.6%
associate-/l/97.9%
frac-times97.9%
*-un-lft-identity97.9%
+-commutative97.9%
Applied egg-rr97.9%
associate-/l/97.9%
associate-*r*86.0%
*-un-lft-identity86.0%
*-commutative86.0%
times-frac85.8%
div-inv85.8%
metadata-eval85.8%
+-commutative85.8%
times-frac85.8%
+-commutative85.8%
Applied egg-rr85.8%
associate-*l/85.9%
*-lft-identity85.9%
*-commutative85.9%
Simplified85.9%
Taylor expanded in a around inf 73.0%
if -8.1999999999999999e-22 < a Initial program 77.1%
associate-*l*77.1%
associate-*l/77.1%
*-lft-identity77.1%
difference-of-squares85.8%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
expm1-log1p-u81.2%
expm1-udef52.1%
*-commutative52.1%
associate-/l/52.1%
frac-times52.1%
*-un-lft-identity52.1%
+-commutative52.1%
Applied egg-rr52.1%
expm1-def79.7%
expm1-log1p98.2%
*-commutative98.2%
associate-/r*98.2%
associate-*r*93.8%
Simplified93.8%
Taylor expanded in a around 0 69.2%
div-inv69.2%
metadata-eval69.2%
*-commutative69.2%
times-frac69.8%
Applied egg-rr69.8%
Final simplification70.5%
(FPCore (a b) :precision binary64 (if (<= a -7.5e-22) (/ (* (/ 0.5 a) (/ PI a)) b) (/ (* (/ 0.5 a) (/ PI b)) b)))
double code(double a, double b) {
double tmp;
if (a <= -7.5e-22) {
tmp = ((0.5 / a) * (((double) M_PI) / a)) / b;
} else {
tmp = ((0.5 / a) * (((double) M_PI) / b)) / b;
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -7.5e-22) {
tmp = ((0.5 / a) * (Math.PI / a)) / b;
} else {
tmp = ((0.5 / a) * (Math.PI / b)) / b;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -7.5e-22: tmp = ((0.5 / a) * (math.pi / a)) / b else: tmp = ((0.5 / a) * (math.pi / b)) / b return tmp
function code(a, b) tmp = 0.0 if (a <= -7.5e-22) tmp = Float64(Float64(Float64(0.5 / a) * Float64(pi / a)) / b); else tmp = Float64(Float64(Float64(0.5 / a) * Float64(pi / b)) / b); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -7.5e-22) tmp = ((0.5 / a) * (pi / a)) / b; else tmp = ((0.5 / a) * (pi / b)) / b; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -7.5e-22], N[(N[(N[(0.5 / a), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], N[(N[(N[(0.5 / a), $MachinePrecision] * N[(Pi / b), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -7.5 \cdot 10^{-22}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot \frac{\pi}{a}}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{a} \cdot \frac{\pi}{b}}{b}\\
\end{array}
\end{array}
if a < -7.49999999999999978e-22Initial program 76.2%
associate-*l*76.1%
associate-*l/76.2%
*-lft-identity76.2%
difference-of-squares85.9%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.6%
*-commutative99.6%
associate-/l/97.9%
frac-times97.9%
*-un-lft-identity97.9%
+-commutative97.9%
Applied egg-rr97.9%
associate-/l/97.9%
associate-*r*86.0%
*-un-lft-identity86.0%
*-commutative86.0%
times-frac85.8%
div-inv85.8%
metadata-eval85.8%
+-commutative85.8%
times-frac85.8%
+-commutative85.8%
Applied egg-rr85.8%
associate-*l/85.9%
*-lft-identity85.9%
*-commutative85.9%
Simplified85.9%
Taylor expanded in a around inf 73.0%
if -7.49999999999999978e-22 < a Initial program 77.1%
associate-*l*77.1%
associate-*l/77.1%
*-lft-identity77.1%
difference-of-squares85.8%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.7%
*-commutative99.7%
associate-/l/98.2%
frac-times98.2%
*-un-lft-identity98.2%
+-commutative98.2%
Applied egg-rr98.2%
associate-/l/98.2%
associate-*r*93.8%
*-un-lft-identity93.8%
*-commutative93.8%
times-frac94.4%
div-inv94.4%
metadata-eval94.4%
+-commutative94.4%
times-frac94.4%
+-commutative94.4%
Applied egg-rr94.4%
associate-*l/94.5%
*-lft-identity94.5%
*-commutative94.5%
Simplified94.5%
Taylor expanded in a around 0 69.9%
Final simplification70.6%
(FPCore (a b) :precision binary64 (* (/ PI (* a b)) (/ 0.5 (+ a b))))
double code(double a, double b) {
return (((double) M_PI) / (a * b)) * (0.5 / (a + b));
}
public static double code(double a, double b) {
return (Math.PI / (a * b)) * (0.5 / (a + b));
}
def code(a, b): return (math.pi / (a * b)) * (0.5 / (a + b))
function code(a, b) return Float64(Float64(pi / Float64(a * b)) * Float64(0.5 / Float64(a + b))) end
function tmp = code(a, b) tmp = (pi / (a * b)) * (0.5 / (a + b)); end
code[a_, b_] := N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a + b}
\end{array}
Initial program 76.9%
associate-*l*76.9%
associate-*l/76.9%
*-lft-identity76.9%
difference-of-squares85.8%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
associate-*r/99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 99.7%
expm1-log1p-u83.0%
expm1-udef52.7%
*-un-lft-identity52.7%
times-frac52.7%
metadata-eval52.7%
+-commutative52.7%
Applied egg-rr52.7%
expm1-def82.9%
expm1-log1p99.7%
associate-*r/99.7%
*-commutative99.7%
associate-*r/99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (* (/ PI b) (/ 0.5 (* a b))))
double code(double a, double b) {
return (((double) M_PI) / b) * (0.5 / (a * b));
}
public static double code(double a, double b) {
return (Math.PI / b) * (0.5 / (a * b));
}
def code(a, b): return (math.pi / b) * (0.5 / (a * b))
function code(a, b) return Float64(Float64(pi / b) * Float64(0.5 / Float64(a * b))) end
function tmp = code(a, b) tmp = (pi / b) * (0.5 / (a * b)); end
code[a_, b_] := N[(N[(Pi / b), $MachinePrecision] * N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{b} \cdot \frac{0.5}{a \cdot b}
\end{array}
Initial program 76.9%
associate-*l*76.9%
associate-*l/76.9%
*-lft-identity76.9%
difference-of-squares85.8%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around 0 99.6%
expm1-log1p-u82.9%
expm1-udef52.7%
*-commutative52.7%
associate-/l/52.7%
frac-times52.7%
*-un-lft-identity52.7%
+-commutative52.7%
Applied egg-rr52.7%
expm1-def81.4%
expm1-log1p98.1%
*-commutative98.1%
associate-/r*98.1%
associate-*r*91.9%
Simplified91.9%
Taylor expanded in a around 0 63.1%
div-inv63.1%
metadata-eval63.1%
*-commutative63.1%
times-frac63.6%
Applied egg-rr63.6%
Final simplification63.6%
herbie shell --seed 2024026
(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))))