
(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}
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 (/ (* PI (/ 1.0 (* a b))) (* (+ a b) 2.0)))
double code(double a, double b) {
return (((double) M_PI) * (1.0 / (a * b))) / ((a + b) * 2.0);
}
public static double code(double a, double b) {
return (Math.PI * (1.0 / (a * b))) / ((a + b) * 2.0);
}
def code(a, b): return (math.pi * (1.0 / (a * b))) / ((a + b) * 2.0)
function code(a, b) return Float64(Float64(pi * Float64(1.0 / Float64(a * b))) / Float64(Float64(a + b) * 2.0)) end
function tmp = code(a, b) tmp = (pi * (1.0 / (a * b))) / ((a + b) * 2.0); end
code[a_, b_] := N[(N[(Pi * N[(1.0 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(a + b), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi \cdot \frac{1}{a \cdot b}}{\left(a + b\right) \cdot 2}
\end{array}
Initial program 78.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*r/N/A
difference-of-squaresN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6488.0
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in a around 0
lower-/.f64N/A
lift-*.f6499.6
Applied rewrites99.6%
lift-*.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-+.f64N/A
associate-*l/N/A
lower-/.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
(FPCore (a b) :precision binary64 (* (/ PI (* 2.0 (+ b a))) (/ 1.0 (* a b))))
double code(double a, double b) {
return (((double) M_PI) / (2.0 * (b + a))) * (1.0 / (a * b));
}
public static double code(double a, double b) {
return (Math.PI / (2.0 * (b + a))) * (1.0 / (a * b));
}
def code(a, b): return (math.pi / (2.0 * (b + a))) * (1.0 / (a * b))
function code(a, b) return Float64(Float64(pi / Float64(2.0 * Float64(b + a))) * Float64(1.0 / Float64(a * b))) end
function tmp = code(a, b) tmp = (pi / (2.0 * (b + a))) * (1.0 / (a * b)); end
code[a_, b_] := N[(N[(Pi / N[(2.0 * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{2 \cdot \left(b + a\right)} \cdot \frac{1}{a \cdot b}
\end{array}
Initial program 78.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*r/N/A
difference-of-squaresN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6488.0
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in a around 0
lower-/.f64N/A
lift-*.f6499.6
Applied rewrites99.6%
(FPCore (a b) :precision binary64 (if (<= a -1.45e-44) (* (/ (/ PI a) (* a b)) 0.5) (* (/ PI (+ b b)) (/ 1.0 (* a b)))))
double code(double a, double b) {
double tmp;
if (a <= -1.45e-44) {
tmp = ((((double) M_PI) / a) / (a * b)) * 0.5;
} else {
tmp = (((double) M_PI) / (b + b)) * (1.0 / (a * b));
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -1.45e-44) {
tmp = ((Math.PI / a) / (a * b)) * 0.5;
} else {
tmp = (Math.PI / (b + b)) * (1.0 / (a * b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.45e-44: tmp = ((math.pi / a) / (a * b)) * 0.5 else: tmp = (math.pi / (b + b)) * (1.0 / (a * b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -1.45e-44) tmp = Float64(Float64(Float64(pi / a) / Float64(a * b)) * 0.5); else tmp = Float64(Float64(pi / Float64(b + b)) * Float64(1.0 / Float64(a * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.45e-44) tmp = ((pi / a) / (a * b)) * 0.5; else tmp = (pi / (b + b)) * (1.0 / (a * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.45e-44], N[(N[(N[(Pi / a), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(Pi / N[(b + b), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.45 \cdot 10^{-44}:\\
\;\;\;\;\frac{\frac{\pi}{a}}{a \cdot b} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b + b} \cdot \frac{1}{a \cdot b}\\
\end{array}
\end{array}
if a < -1.4500000000000001e-44Initial program 78.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6456.1
Applied rewrites56.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6462.3
Applied rewrites62.3%
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lift-*.f6462.5
Applied rewrites62.5%
if -1.4500000000000001e-44 < a Initial program 78.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*r/N/A
difference-of-squaresN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6488.0
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in a around 0
lower-/.f64N/A
lift-*.f6499.6
Applied rewrites99.6%
Taylor expanded in a around 0
count-2-revN/A
lower-+.f6463.0
Applied rewrites63.0%
(FPCore (a b) :precision binary64 (if (<= a -1.45e-44) (* (/ (/ PI a) (* a b)) 0.5) (* (/ PI (* b (* a b))) 0.5)))
double code(double a, double b) {
double tmp;
if (a <= -1.45e-44) {
tmp = ((((double) M_PI) / a) / (a * b)) * 0.5;
} else {
tmp = (((double) M_PI) / (b * (a * b))) * 0.5;
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -1.45e-44) {
tmp = ((Math.PI / a) / (a * b)) * 0.5;
} else {
tmp = (Math.PI / (b * (a * b))) * 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.45e-44: tmp = ((math.pi / a) / (a * b)) * 0.5 else: tmp = (math.pi / (b * (a * b))) * 0.5 return tmp
function code(a, b) tmp = 0.0 if (a <= -1.45e-44) tmp = Float64(Float64(Float64(pi / a) / Float64(a * b)) * 0.5); else tmp = Float64(Float64(pi / Float64(b * Float64(a * b))) * 0.5); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.45e-44) tmp = ((pi / a) / (a * b)) * 0.5; else tmp = (pi / (b * (a * b))) * 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.45e-44], N[(N[(N[(Pi / a), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(Pi / N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.45 \cdot 10^{-44}:\\
\;\;\;\;\frac{\frac{\pi}{a}}{a \cdot b} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b \cdot \left(a \cdot b\right)} \cdot 0.5\\
\end{array}
\end{array}
if a < -1.4500000000000001e-44Initial program 78.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6456.1
Applied rewrites56.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6462.3
Applied rewrites62.3%
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lift-*.f6462.5
Applied rewrites62.5%
if -1.4500000000000001e-44 < a Initial program 78.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*r/N/A
difference-of-squaresN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6488.0
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6457.1
Applied rewrites57.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f6462.8
Applied rewrites62.8%
(FPCore (a b) :precision binary64 (if (<= a -1.45e-44) (* (/ PI (* a (* a b))) 0.5) (* (/ PI (* b (* a b))) 0.5)))
double code(double a, double b) {
double tmp;
if (a <= -1.45e-44) {
tmp = (((double) M_PI) / (a * (a * b))) * 0.5;
} else {
tmp = (((double) M_PI) / (b * (a * b))) * 0.5;
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -1.45e-44) {
tmp = (Math.PI / (a * (a * b))) * 0.5;
} else {
tmp = (Math.PI / (b * (a * b))) * 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -1.45e-44: tmp = (math.pi / (a * (a * b))) * 0.5 else: tmp = (math.pi / (b * (a * b))) * 0.5 return tmp
function code(a, b) tmp = 0.0 if (a <= -1.45e-44) tmp = Float64(Float64(pi / Float64(a * Float64(a * b))) * 0.5); else tmp = Float64(Float64(pi / Float64(b * Float64(a * b))) * 0.5); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -1.45e-44) tmp = (pi / (a * (a * b))) * 0.5; else tmp = (pi / (b * (a * b))) * 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -1.45e-44], N[(N[(Pi / N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(Pi / N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.45 \cdot 10^{-44}:\\
\;\;\;\;\frac{\pi}{a \cdot \left(a \cdot b\right)} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{b \cdot \left(a \cdot b\right)} \cdot 0.5\\
\end{array}
\end{array}
if a < -1.4500000000000001e-44Initial program 78.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6456.1
Applied rewrites56.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6462.3
Applied rewrites62.3%
if -1.4500000000000001e-44 < a Initial program 78.8%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
associate-*r/N/A
difference-of-squaresN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f6488.0
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6457.1
Applied rewrites57.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lift-*.f6462.8
Applied rewrites62.8%
(FPCore (a b) :precision binary64 (if (<= a -9.8e-45) (* (/ PI (* a (* a b))) 0.5) (* (/ PI (* (* b b) a)) 0.5)))
double code(double a, double b) {
double tmp;
if (a <= -9.8e-45) {
tmp = (((double) M_PI) / (a * (a * b))) * 0.5;
} else {
tmp = (((double) M_PI) / ((b * b) * a)) * 0.5;
}
return tmp;
}
public static double code(double a, double b) {
double tmp;
if (a <= -9.8e-45) {
tmp = (Math.PI / (a * (a * b))) * 0.5;
} else {
tmp = (Math.PI / ((b * b) * a)) * 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -9.8e-45: tmp = (math.pi / (a * (a * b))) * 0.5 else: tmp = (math.pi / ((b * b) * a)) * 0.5 return tmp
function code(a, b) tmp = 0.0 if (a <= -9.8e-45) tmp = Float64(Float64(pi / Float64(a * Float64(a * b))) * 0.5); else tmp = Float64(Float64(pi / Float64(Float64(b * b) * a)) * 0.5); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -9.8e-45) tmp = (pi / (a * (a * b))) * 0.5; else tmp = (pi / ((b * b) * a)) * 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -9.8e-45], N[(N[(Pi / N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(Pi / N[(N[(b * b), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.8 \cdot 10^{-45}:\\
\;\;\;\;\frac{\pi}{a \cdot \left(a \cdot b\right)} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\pi}{\left(b \cdot b\right) \cdot a} \cdot 0.5\\
\end{array}
\end{array}
if a < -9.7999999999999996e-45Initial program 78.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6456.1
Applied rewrites56.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6462.3
Applied rewrites62.3%
if -9.7999999999999996e-45 < a Initial program 78.8%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6457.1
Applied rewrites57.1%
(FPCore (a b) :precision binary64 (* (/ PI (* a (* a b))) 0.5))
double code(double a, double b) {
return (((double) M_PI) / (a * (a * b))) * 0.5;
}
public static double code(double a, double b) {
return (Math.PI / (a * (a * b))) * 0.5;
}
def code(a, b): return (math.pi / (a * (a * b))) * 0.5
function code(a, b) return Float64(Float64(pi / Float64(a * Float64(a * b))) * 0.5) end
function tmp = code(a, b) tmp = (pi / (a * (a * b))) * 0.5; end
code[a_, b_] := N[(N[(Pi / N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{\pi}{a \cdot \left(a \cdot b\right)} \cdot 0.5
\end{array}
Initial program 78.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6456.1
Applied rewrites56.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6462.3
Applied rewrites62.3%
herbie shell --seed 2025139
(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))))