
(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 6 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 (/ (/ (/ PI a) (* 2.0 b)) (+ a b)))
double code(double a, double b) {
return ((((double) M_PI) / a) / (2.0 * b)) / (a + b);
}
public static double code(double a, double b) {
return ((Math.PI / a) / (2.0 * b)) / (a + b);
}
def code(a, b): return ((math.pi / a) / (2.0 * b)) / (a + b)
function code(a, b) return Float64(Float64(Float64(pi / a) / Float64(2.0 * b)) / Float64(a + b)) end
function tmp = code(a, b) tmp = ((pi / a) / (2.0 * b)) / (a + b); end
code[a_, b_] := N[(N[(N[(Pi / a), $MachinePrecision] / N[(2.0 * b), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{\pi}{a}}{2 \cdot b}}{a + b}
\end{array}
Initial program 78.5%
associate-*l*78.5%
associate-*l/78.5%
*-lft-identity78.5%
difference-of-squares86.3%
associate-/l/99.7%
sub-neg99.7%
distribute-neg-frac99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in a around inf 68.5%
Taylor expanded in b around 0 99.6%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.6%
frac-times99.7%
div-inv99.7%
+-commutative99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (a b) :precision binary64 (let* ((t_0 (/ PI (* a b)))) (if (<= a -4e-42) (* t_0 (/ 0.5 a)) (* t_0 (/ 0.5 b)))))
double code(double a, double b) {
double t_0 = ((double) M_PI) / (a * b);
double tmp;
if (a <= -4e-42) {
tmp = t_0 * (0.5 / a);
} else {
tmp = t_0 * (0.5 / b);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = Math.PI / (a * b);
double tmp;
if (a <= -4e-42) {
tmp = t_0 * (0.5 / a);
} else {
tmp = t_0 * (0.5 / b);
}
return tmp;
}
def code(a, b): t_0 = math.pi / (a * b) tmp = 0 if a <= -4e-42: tmp = t_0 * (0.5 / a) else: tmp = t_0 * (0.5 / b) return tmp
function code(a, b) t_0 = Float64(pi / Float64(a * b)) tmp = 0.0 if (a <= -4e-42) tmp = Float64(t_0 * Float64(0.5 / a)); else tmp = Float64(t_0 * Float64(0.5 / b)); end return tmp end
function tmp_2 = code(a, b) t_0 = pi / (a * b); tmp = 0.0; if (a <= -4e-42) tmp = t_0 * (0.5 / a); else tmp = t_0 * (0.5 / b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -4e-42], N[(t$95$0 * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\pi}{a \cdot b}\\
\mathbf{if}\;a \leq -4 \cdot 10^{-42}:\\
\;\;\;\;t_0 \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{0.5}{b}\\
\end{array}
\end{array}
if a < -4.00000000000000015e-42Initial program 81.3%
associate-*l*81.2%
associate-*l/81.2%
*-lft-identity81.2%
difference-of-squares90.7%
associate-/l/99.8%
sub-neg99.8%
distribute-neg-frac99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in a around 0 99.7%
expm1-log1p-u91.6%
expm1-udef58.5%
*-commutative58.5%
associate-/l/58.5%
frac-times58.5%
*-un-lft-identity58.5%
+-commutative58.5%
Applied egg-rr58.5%
expm1-def91.2%
expm1-log1p99.5%
*-rgt-identity99.5%
*-commutative99.5%
times-frac99.4%
*-commutative99.4%
associate-/r*99.7%
times-frac99.7%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
expm1-log1p-u91.5%
expm1-udef58.5%
*-un-lft-identity58.5%
times-frac58.5%
metadata-eval58.5%
Applied egg-rr58.5%
expm1-def91.5%
expm1-log1p99.7%
associate-/r*99.5%
associate-*r/99.5%
*-commutative99.5%
times-frac99.7%
Simplified99.7%
Taylor expanded in a around inf 86.3%
if -4.00000000000000015e-42 < a Initial program 77.6%
associate-*l*77.6%
associate-*l/77.6%
*-lft-identity77.6%
difference-of-squares84.9%
associate-/l/99.6%
sub-neg99.6%
distribute-neg-frac99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in a around 0 99.5%
expm1-log1p-u75.0%
expm1-udef49.0%
*-commutative49.0%
associate-/l/49.0%
frac-times49.0%
*-un-lft-identity49.0%
+-commutative49.0%
Applied egg-rr49.0%
expm1-def74.2%
expm1-log1p98.8%
*-rgt-identity98.8%
*-commutative98.8%
times-frac98.8%
*-commutative98.8%
associate-/r*99.5%
times-frac99.6%
associate-*r/99.6%
*-rgt-identity99.6%
Simplified99.6%
expm1-log1p-u75.0%
expm1-udef49.0%
*-un-lft-identity49.0%
times-frac49.0%
metadata-eval49.0%
Applied egg-rr49.0%
expm1-def75.0%
expm1-log1p99.6%
associate-/r*98.8%
associate-*r/98.8%
*-commutative98.8%
times-frac99.6%
Simplified99.6%
Taylor expanded in a around 0 70.1%
Final simplification74.1%
(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 78.5%
associate-*l*78.5%
associate-*l/78.5%
*-lft-identity78.5%
difference-of-squares86.3%
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-u79.1%
expm1-udef51.3%
*-commutative51.3%
associate-/l/51.3%
frac-times51.3%
*-un-lft-identity51.3%
+-commutative51.3%
Applied egg-rr51.3%
expm1-def78.4%
expm1-log1p99.0%
*-rgt-identity99.0%
*-commutative99.0%
times-frac98.9%
*-commutative98.9%
associate-/r*99.6%
times-frac99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
expm1-log1p-u79.1%
expm1-udef51.3%
*-un-lft-identity51.3%
times-frac51.3%
metadata-eval51.3%
Applied egg-rr51.3%
expm1-def79.1%
expm1-log1p99.7%
associate-/r*99.0%
associate-*r/99.0%
*-commutative99.0%
times-frac99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (/ (* PI (/ 0.5 (+ a b))) (* a b)))
double code(double a, double b) {
return (((double) M_PI) * (0.5 / (a + b))) / (a * b);
}
public static double code(double a, double b) {
return (Math.PI * (0.5 / (a + b))) / (a * b);
}
def code(a, b): return (math.pi * (0.5 / (a + b))) / (a * b)
function code(a, b) return Float64(Float64(pi * Float64(0.5 / Float64(a + b))) / Float64(a * b)) end
function tmp = code(a, b) tmp = (pi * (0.5 / (a + b))) / (a * b); end
code[a_, b_] := N[(N[(Pi * N[(0.5 / N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi \cdot \frac{0.5}{a + b}}{a \cdot b}
\end{array}
Initial program 78.5%
associate-*l*78.5%
associate-*l/78.5%
*-lft-identity78.5%
difference-of-squares86.3%
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-u79.1%
expm1-udef51.3%
*-commutative51.3%
associate-/l/51.3%
frac-times51.3%
*-un-lft-identity51.3%
+-commutative51.3%
Applied egg-rr51.3%
expm1-def78.4%
expm1-log1p99.0%
*-rgt-identity99.0%
*-commutative99.0%
times-frac98.9%
*-commutative98.9%
associate-/r*99.6%
times-frac99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
expm1-log1p-u79.1%
expm1-udef51.3%
*-un-lft-identity51.3%
times-frac51.3%
metadata-eval51.3%
Applied egg-rr51.3%
expm1-def79.1%
expm1-log1p99.7%
associate-/r*99.0%
associate-*r/99.0%
*-commutative99.0%
times-frac99.6%
Simplified99.6%
associate-*l/99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (/ (/ PI (* a b)) (* 2.0 (+ a b))))
double code(double a, double b) {
return (((double) M_PI) / (a * b)) / (2.0 * (a + b));
}
public static double code(double a, double b) {
return (Math.PI / (a * b)) / (2.0 * (a + b));
}
def code(a, b): return (math.pi / (a * b)) / (2.0 * (a + b))
function code(a, b) return Float64(Float64(pi / Float64(a * b)) / Float64(2.0 * Float64(a + b))) end
function tmp = code(a, b) tmp = (pi / (a * b)) / (2.0 * (a + b)); end
code[a_, b_] := N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\pi}{a \cdot b}}{2 \cdot \left(a + b\right)}
\end{array}
Initial program 78.5%
associate-*l*78.5%
associate-*l/78.5%
*-lft-identity78.5%
difference-of-squares86.3%
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-u79.1%
expm1-udef51.3%
*-commutative51.3%
associate-/l/51.3%
frac-times51.3%
*-un-lft-identity51.3%
+-commutative51.3%
Applied egg-rr51.3%
expm1-def78.4%
expm1-log1p99.0%
*-rgt-identity99.0%
*-commutative99.0%
times-frac98.9%
*-commutative98.9%
associate-/r*99.6%
times-frac99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (a b) :precision binary64 (* (/ PI (* a b)) (/ 0.5 a)))
double code(double a, double b) {
return (((double) M_PI) / (a * b)) * (0.5 / a);
}
public static double code(double a, double b) {
return (Math.PI / (a * b)) * (0.5 / a);
}
def code(a, b): return (math.pi / (a * b)) * (0.5 / a)
function code(a, b) return Float64(Float64(pi / Float64(a * b)) * Float64(0.5 / a)) end
function tmp = code(a, b) tmp = (pi / (a * b)) * (0.5 / a); end
code[a_, b_] := N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{a \cdot b} \cdot \frac{0.5}{a}
\end{array}
Initial program 78.5%
associate-*l*78.5%
associate-*l/78.5%
*-lft-identity78.5%
difference-of-squares86.3%
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-u79.1%
expm1-udef51.3%
*-commutative51.3%
associate-/l/51.3%
frac-times51.3%
*-un-lft-identity51.3%
+-commutative51.3%
Applied egg-rr51.3%
expm1-def78.4%
expm1-log1p99.0%
*-rgt-identity99.0%
*-commutative99.0%
times-frac98.9%
*-commutative98.9%
associate-/r*99.6%
times-frac99.6%
associate-*r/99.7%
*-rgt-identity99.7%
Simplified99.7%
expm1-log1p-u79.1%
expm1-udef51.3%
*-un-lft-identity51.3%
times-frac51.3%
metadata-eval51.3%
Applied egg-rr51.3%
expm1-def79.1%
expm1-log1p99.7%
associate-/r*99.0%
associate-*r/99.0%
*-commutative99.0%
times-frac99.6%
Simplified99.6%
Taylor expanded in a around inf 61.1%
Final simplification61.1%
herbie shell --seed 2024018
(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))))