
(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 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 + b} \cdot \frac{0.5}{a \cdot b}
\end{array}
Initial program 75.1%
associate-*l*75.0%
*-rgt-identity75.0%
associate-/l*75.0%
metadata-eval75.0%
associate-*l/75.1%
*-lft-identity75.1%
sub-neg75.1%
distribute-neg-frac75.1%
metadata-eval75.1%
Simplified75.1%
*-un-lft-identity75.1%
clear-num74.8%
frac-add74.7%
associate-/r/74.8%
*-un-lft-identity74.8%
*-commutative74.8%
neg-mul-174.8%
sub-neg74.8%
flip-+98.2%
+-commutative98.2%
Applied egg-rr98.2%
*-lft-identity98.2%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.6%
Applied egg-rr99.6%
un-div-inv99.7%
associate-/r*98.3%
times-frac99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (let* ((t_0 (/ 0.5 (* a b)))) (if (<= b 4.6e-55) (* 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.6e-55) {
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.6e-55) {
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.6e-55: tmp = t_0 * (math.pi / a) else: tmp = t_0 * (math.pi / b) return tmp
function code(a, b) t_0 = Float64(0.5 / Float64(a * b)) tmp = 0.0 if (b <= 4.6e-55) 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.6e-55) tmp = t_0 * (pi / a); else tmp = t_0 * (pi / b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 4.6e-55], 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{0.5}{a \cdot b}\\
\mathbf{if}\;b \leq 4.6 \cdot 10^{-55}:\\
\;\;\;\;t\_0 \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \frac{\pi}{b}\\
\end{array}
\end{array}
if b < 4.60000000000000023e-55Initial program 74.6%
associate-*l*74.5%
*-rgt-identity74.5%
associate-/l*74.5%
metadata-eval74.5%
associate-*l/74.6%
*-lft-identity74.6%
sub-neg74.6%
distribute-neg-frac74.6%
metadata-eval74.6%
Simplified74.6%
*-un-lft-identity74.6%
clear-num74.5%
frac-add74.5%
associate-/r/74.5%
*-un-lft-identity74.5%
*-commutative74.5%
neg-mul-174.5%
sub-neg74.5%
flip-+98.4%
+-commutative98.4%
Applied egg-rr98.4%
*-lft-identity98.4%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.6%
Applied egg-rr99.6%
un-div-inv99.7%
associate-/r*98.4%
times-frac99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 71.7%
if 4.60000000000000023e-55 < b Initial program 76.0%
associate-*l*76.0%
*-rgt-identity76.0%
associate-/l*76.0%
metadata-eval76.0%
associate-*l/76.1%
*-lft-identity76.1%
sub-neg76.1%
distribute-neg-frac76.1%
metadata-eval76.1%
Simplified76.1%
*-un-lft-identity76.1%
clear-num75.3%
frac-add75.2%
associate-/r/75.2%
*-un-lft-identity75.2%
*-commutative75.2%
neg-mul-175.2%
sub-neg75.2%
flip-+97.9%
+-commutative97.9%
Applied egg-rr97.9%
*-lft-identity97.9%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.7%
Applied egg-rr99.7%
un-div-inv99.7%
associate-/r*98.1%
times-frac99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 88.1%
Final simplification77.2%
(FPCore (a b) :precision binary64 (if (<= b 1.25e-62) (* (/ 0.5 (* a b)) (/ PI a)) (* (/ (/ PI b) a) (/ 0.5 b))))
double code(double a, double b) {
double tmp;
if (b <= 1.25e-62) {
tmp = (0.5 / (a * b)) * (((double) M_PI) / a);
} else {
tmp = ((((double) M_PI) / b) / a) * (0.5 / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 1.25e-62) {
tmp = (0.5 / (a * b)) * (Math.PI / a);
} else {
tmp = ((Math.PI / b) / a) * (0.5 / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.25e-62: tmp = (0.5 / (a * b)) * (math.pi / a) else: tmp = ((math.pi / b) / a) * (0.5 / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.25e-62) tmp = Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / a)); else tmp = Float64(Float64(Float64(pi / b) / a) * Float64(0.5 / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.25e-62) tmp = (0.5 / (a * b)) * (pi / a); else tmp = ((pi / b) / a) * (0.5 / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.25e-62], N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi / b), $MachinePrecision] / a), $MachinePrecision] * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25 \cdot 10^{-62}:\\
\;\;\;\;\frac{0.5}{a \cdot b} \cdot \frac{\pi}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\
\end{array}
\end{array}
if b < 1.25e-62Initial program 74.4%
associate-*l*74.4%
*-rgt-identity74.4%
associate-/l*74.4%
metadata-eval74.4%
associate-*l/74.4%
*-lft-identity74.4%
sub-neg74.4%
distribute-neg-frac74.4%
metadata-eval74.4%
Simplified74.4%
*-un-lft-identity74.4%
clear-num74.4%
frac-add74.3%
associate-/r/74.4%
*-un-lft-identity74.4%
*-commutative74.4%
neg-mul-174.4%
sub-neg74.4%
flip-+98.3%
+-commutative98.3%
Applied egg-rr98.3%
*-lft-identity98.3%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.6%
Applied egg-rr99.6%
un-div-inv99.7%
associate-/r*98.4%
times-frac99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 71.6%
if 1.25e-62 < b Initial program 76.3%
associate-*l*76.3%
*-rgt-identity76.3%
associate-/l*76.3%
metadata-eval76.3%
associate-*l/76.3%
*-lft-identity76.3%
sub-neg76.3%
distribute-neg-frac76.3%
metadata-eval76.3%
Simplified76.3%
*-un-lft-identity76.3%
clear-num75.5%
frac-add75.5%
associate-/r/75.5%
*-un-lft-identity75.5%
*-commutative75.5%
neg-mul-175.5%
sub-neg75.5%
flip-+98.0%
+-commutative98.0%
Applied egg-rr98.0%
*-lft-identity98.0%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 87.2%
*-commutative87.2%
times-frac87.2%
Applied egg-rr87.2%
Final simplification76.8%
(FPCore (a b) :precision binary64 (if (<= b 1.6e-54) (/ (* 0.5 (/ PI a)) (* a b)) (* (/ (/ PI b) a) (/ 0.5 b))))
double code(double a, double b) {
double tmp;
if (b <= 1.6e-54) {
tmp = (0.5 * (((double) M_PI) / a)) / (a * b);
} else {
tmp = ((((double) M_PI) / b) / a) * (0.5 / b);
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (b <= 1.6e-54) {
tmp = (0.5 * (Math.PI / a)) / (a * b);
} else {
tmp = ((Math.PI / b) / a) * (0.5 / b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.6e-54: tmp = (0.5 * (math.pi / a)) / (a * b) else: tmp = ((math.pi / b) / a) * (0.5 / b) return tmp
function code(a, b) tmp = 0.0 if (b <= 1.6e-54) tmp = Float64(Float64(0.5 * Float64(pi / a)) / Float64(a * b)); else tmp = Float64(Float64(Float64(pi / b) / a) * Float64(0.5 / b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.6e-54) tmp = (0.5 * (pi / a)) / (a * b); else tmp = ((pi / b) / a) * (0.5 / b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.6e-54], N[(N[(0.5 * N[(Pi / a), $MachinePrecision]), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(Pi / b), $MachinePrecision] / a), $MachinePrecision] * N[(0.5 / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.6 \cdot 10^{-54}:\\
\;\;\;\;\frac{0.5 \cdot \frac{\pi}{a}}{a \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\pi}{b}}{a} \cdot \frac{0.5}{b}\\
\end{array}
\end{array}
if b < 1.59999999999999999e-54Initial program 74.6%
associate-*l*74.5%
*-rgt-identity74.5%
associate-/l*74.5%
metadata-eval74.5%
associate-*l/74.6%
*-lft-identity74.6%
sub-neg74.6%
distribute-neg-frac74.6%
metadata-eval74.6%
Simplified74.6%
*-un-lft-identity74.6%
clear-num74.5%
frac-add74.5%
associate-/r/74.5%
*-un-lft-identity74.5%
*-commutative74.5%
neg-mul-174.5%
sub-neg74.5%
flip-+98.4%
+-commutative98.4%
Applied egg-rr98.4%
*-lft-identity98.4%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 71.7%
if 1.59999999999999999e-54 < b Initial program 76.0%
associate-*l*76.0%
*-rgt-identity76.0%
associate-/l*76.0%
metadata-eval76.0%
associate-*l/76.1%
*-lft-identity76.1%
sub-neg76.1%
distribute-neg-frac76.1%
metadata-eval76.1%
Simplified76.1%
*-un-lft-identity76.1%
clear-num75.3%
frac-add75.2%
associate-/r/75.2%
*-un-lft-identity75.2%
*-commutative75.2%
neg-mul-175.2%
sub-neg75.2%
flip-+97.9%
+-commutative97.9%
Applied egg-rr97.9%
*-lft-identity97.9%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.7%
Applied egg-rr99.7%
Taylor expanded in a around 0 88.1%
*-commutative88.1%
times-frac88.1%
Applied egg-rr88.1%
Final simplification77.2%
(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(0.5 * Float64(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[(0.5 * N[(N[(Pi / N[(a * b), $MachinePrecision]), $MachinePrecision] / N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{\frac{\pi}{a \cdot b}}{a + b}
\end{array}
Initial program 75.1%
associate-*l*75.0%
*-rgt-identity75.0%
associate-/l*75.0%
metadata-eval75.0%
associate-*l/75.1%
*-lft-identity75.1%
sub-neg75.1%
distribute-neg-frac75.1%
metadata-eval75.1%
Simplified75.1%
metadata-eval75.1%
div-inv75.1%
clear-num74.8%
un-div-inv74.9%
div-inv74.9%
metadata-eval74.9%
frac-add74.8%
associate-/r/74.8%
*-un-lft-identity74.8%
*-commutative74.8%
neg-mul-174.8%
sub-neg74.8%
flip-+98.3%
+-commutative98.3%
Applied egg-rr98.3%
Taylor expanded in a around 0 86.4%
*-commutative86.4%
unpow286.4%
distribute-lft-out91.5%
Simplified91.5%
*-commutative91.5%
associate-*r*98.3%
frac-times99.6%
*-commutative99.6%
associate-*l/99.6%
div-inv99.6%
associate-*r*99.6%
div-inv99.6%
*-commutative99.6%
associate-*r/99.6%
*-un-lft-identity99.6%
times-frac99.6%
metadata-eval99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (* (/ 0.5 (* a b)) (/ PI a)))
double code(double a, double b) {
return (0.5 / (a * b)) * (((double) M_PI) / a);
}
public static double code(double a, double b) {
return (0.5 / (a * b)) * (Math.PI / a);
}
def code(a, b): return (0.5 / (a * b)) * (math.pi / a)
function code(a, b) return Float64(Float64(0.5 / Float64(a * b)) * Float64(pi / a)) end
function tmp = code(a, b) tmp = (0.5 / (a * b)) * (pi / a); end
code[a_, b_] := N[(N[(0.5 / N[(a * b), $MachinePrecision]), $MachinePrecision] * N[(Pi / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{a \cdot b} \cdot \frac{\pi}{a}
\end{array}
Initial program 75.1%
associate-*l*75.0%
*-rgt-identity75.0%
associate-/l*75.0%
metadata-eval75.0%
associate-*l/75.1%
*-lft-identity75.1%
sub-neg75.1%
distribute-neg-frac75.1%
metadata-eval75.1%
Simplified75.1%
*-un-lft-identity75.1%
clear-num74.8%
frac-add74.7%
associate-/r/74.8%
*-un-lft-identity74.8%
*-commutative74.8%
neg-mul-174.8%
sub-neg74.8%
flip-+98.2%
+-commutative98.2%
Applied egg-rr98.2%
*-lft-identity98.2%
associate-/r*99.6%
Simplified99.6%
associate-*r/99.6%
Applied egg-rr99.6%
un-div-inv99.7%
associate-/r*98.3%
times-frac99.6%
Applied egg-rr99.6%
Taylor expanded in a around inf 59.0%
Final simplification59.0%
herbie shell --seed 2024115
(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))))