
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin t_0)) (cos t_0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return ((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * sin(t_0)) * cos(t_0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return ((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * Math.sin(t_0)) * Math.cos(t_0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return ((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * math.sin(t_0)) * math.cos(t_0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * sin(t_0)) * cos(t_0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * sin(t_0)) * cos(t_0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(2.0 * N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \sin t\_0\right) \cdot \cos t\_0
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin t_0)) (cos t_0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return ((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * sin(t_0)) * cos(t_0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return ((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * Math.sin(t_0)) * Math.cos(t_0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return ((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * math.sin(t_0)) * math.cos(t_0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * sin(t_0)) * cos(t_0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * sin(t_0)) * cos(t_0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(2.0 * N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \sin t\_0\right) \cdot \cos t\_0
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (* (cos t_0) (* (* 2.0 (* (- b a) (+ b a))) (sin t_0)))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return cos(t_0) * ((2.0 * ((b - a) * (b + a))) * sin(t_0));
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.cos(t_0) * ((2.0 * ((b - a) * (b + a))) * Math.sin(t_0));
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.cos(t_0) * ((2.0 * ((b - a) * (b + a))) * math.sin(t_0))
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64(cos(t_0) * Float64(Float64(2.0 * Float64(Float64(b - a) * Float64(b + a))) * sin(t_0))) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = cos(t_0) * ((2.0 * ((b - a) * (b + a))) * sin(t_0)); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Cos[t$95$0], $MachinePrecision] * N[(N[(2.0 * N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
\cos t\_0 \cdot \left(\left(2 \cdot \left(\left(b - a\right) \cdot \left(b + a\right)\right)\right) \cdot \sin t\_0\right)
\end{array}
\end{array}
Initial program 58.9%
unpow258.9%
unpow258.9%
difference-of-squares63.3%
Applied egg-rr63.3%
Final simplification63.3%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* angle (/ PI -180.0)))) (* 2.0 (* (cos t_0) (* (sin t_0) (* (+ b a) (- a b)))))))
double code(double a, double b, double angle) {
double t_0 = angle * (((double) M_PI) / -180.0);
return 2.0 * (cos(t_0) * (sin(t_0) * ((b + a) * (a - b))));
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (Math.PI / -180.0);
return 2.0 * (Math.cos(t_0) * (Math.sin(t_0) * ((b + a) * (a - b))));
}
def code(a, b, angle): t_0 = angle * (math.pi / -180.0) return 2.0 * (math.cos(t_0) * (math.sin(t_0) * ((b + a) * (a - b))))
function code(a, b, angle) t_0 = Float64(angle * Float64(pi / -180.0)) return Float64(2.0 * Float64(cos(t_0) * Float64(sin(t_0) * Float64(Float64(b + a) * Float64(a - b))))) end
function tmp = code(a, b, angle) t_0 = angle * (pi / -180.0); tmp = 2.0 * (cos(t_0) * (sin(t_0) * ((b + a) * (a - b)))); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(Pi / -180.0), $MachinePrecision]), $MachinePrecision]}, N[(2.0 * N[(N[Cos[t$95$0], $MachinePrecision] * N[(N[Sin[t$95$0], $MachinePrecision] * N[(N[(b + a), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := angle \cdot \frac{\pi}{-180}\\
2 \cdot \left(\cos t\_0 \cdot \left(\sin t\_0 \cdot \left(\left(b + a\right) \cdot \left(a - b\right)\right)\right)\right)
\end{array}
\end{array}
Initial program 58.9%
Simplified58.4%
unpow258.4%
unpow258.4%
difference-of-squares62.4%
Applied egg-rr62.4%
Final simplification62.4%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (- b a) (+ b a))) (t_1 (* PI (/ angle 180.0))))
(if (<= a 2e+219)
(* (* 2.0 t_0) (sin t_1))
(* (cos t_1) (* 0.011111111111111112 (* angle (* t_0 PI)))))))
double code(double a, double b, double angle) {
double t_0 = (b - a) * (b + a);
double t_1 = ((double) M_PI) * (angle / 180.0);
double tmp;
if (a <= 2e+219) {
tmp = (2.0 * t_0) * sin(t_1);
} else {
tmp = cos(t_1) * (0.011111111111111112 * (angle * (t_0 * ((double) M_PI))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = (b - a) * (b + a);
double t_1 = Math.PI * (angle / 180.0);
double tmp;
if (a <= 2e+219) {
tmp = (2.0 * t_0) * Math.sin(t_1);
} else {
tmp = Math.cos(t_1) * (0.011111111111111112 * (angle * (t_0 * Math.PI)));
}
return tmp;
}
def code(a, b, angle): t_0 = (b - a) * (b + a) t_1 = math.pi * (angle / 180.0) tmp = 0 if a <= 2e+219: tmp = (2.0 * t_0) * math.sin(t_1) else: tmp = math.cos(t_1) * (0.011111111111111112 * (angle * (t_0 * math.pi))) return tmp
function code(a, b, angle) t_0 = Float64(Float64(b - a) * Float64(b + a)) t_1 = Float64(pi * Float64(angle / 180.0)) tmp = 0.0 if (a <= 2e+219) tmp = Float64(Float64(2.0 * t_0) * sin(t_1)); else tmp = Float64(cos(t_1) * Float64(0.011111111111111112 * Float64(angle * Float64(t_0 * pi)))); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = (b - a) * (b + a); t_1 = pi * (angle / 180.0); tmp = 0.0; if (a <= 2e+219) tmp = (2.0 * t_0) * sin(t_1); else tmp = cos(t_1) * (0.011111111111111112 * (angle * (t_0 * pi))); end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 2e+219], N[(N[(2.0 * t$95$0), $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision], N[(N[Cos[t$95$1], $MachinePrecision] * N[(0.011111111111111112 * N[(angle * N[(t$95$0 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b - a\right) \cdot \left(b + a\right)\\
t_1 := \pi \cdot \frac{angle}{180}\\
\mathbf{if}\;a \leq 2 \cdot 10^{+219}:\\
\;\;\;\;\left(2 \cdot t\_0\right) \cdot \sin t\_1\\
\mathbf{else}:\\
\;\;\;\;\cos t\_1 \cdot \left(0.011111111111111112 \cdot \left(angle \cdot \left(t\_0 \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if a < 1.99999999999999993e219Initial program 59.6%
unpow259.6%
unpow259.6%
difference-of-squares62.3%
Applied egg-rr62.3%
add-cbrt-cube60.2%
pow360.2%
Applied egg-rr60.2%
Taylor expanded in angle around 0 56.5%
if 1.99999999999999993e219 < a Initial program 50.8%
unpow250.8%
unpow250.8%
difference-of-squares73.9%
Applied egg-rr73.9%
Taylor expanded in angle around 0 64.8%
Final simplification57.2%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (- b a) (+ b a))))
(if (<= a 1e+187)
(* (* 2.0 t_0) (sin (* PI (/ angle 180.0))))
(* 2.0 (* 0.005555555555555556 (* angle (* t_0 PI)))))))
double code(double a, double b, double angle) {
double t_0 = (b - a) * (b + a);
double tmp;
if (a <= 1e+187) {
tmp = (2.0 * t_0) * sin((((double) M_PI) * (angle / 180.0)));
} else {
tmp = 2.0 * (0.005555555555555556 * (angle * (t_0 * ((double) M_PI))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = (b - a) * (b + a);
double tmp;
if (a <= 1e+187) {
tmp = (2.0 * t_0) * Math.sin((Math.PI * (angle / 180.0)));
} else {
tmp = 2.0 * (0.005555555555555556 * (angle * (t_0 * Math.PI)));
}
return tmp;
}
def code(a, b, angle): t_0 = (b - a) * (b + a) tmp = 0 if a <= 1e+187: tmp = (2.0 * t_0) * math.sin((math.pi * (angle / 180.0))) else: tmp = 2.0 * (0.005555555555555556 * (angle * (t_0 * math.pi))) return tmp
function code(a, b, angle) t_0 = Float64(Float64(b - a) * Float64(b + a)) tmp = 0.0 if (a <= 1e+187) tmp = Float64(Float64(2.0 * t_0) * sin(Float64(pi * Float64(angle / 180.0)))); else tmp = Float64(2.0 * Float64(0.005555555555555556 * Float64(angle * Float64(t_0 * pi)))); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = (b - a) * (b + a); tmp = 0.0; if (a <= 1e+187) tmp = (2.0 * t_0) * sin((pi * (angle / 180.0))); else tmp = 2.0 * (0.005555555555555556 * (angle * (t_0 * pi))); end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 1e+187], N[(N[(2.0 * t$95$0), $MachinePrecision] * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(0.005555555555555556 * N[(angle * N[(t$95$0 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(b - a\right) \cdot \left(b + a\right)\\
\mathbf{if}\;a \leq 10^{+187}:\\
\;\;\;\;\left(2 \cdot t\_0\right) \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \left(t\_0 \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if a < 9.99999999999999907e186Initial program 60.6%
unpow260.6%
unpow260.6%
difference-of-squares62.9%
Applied egg-rr62.9%
add-cbrt-cube60.8%
pow360.8%
Applied egg-rr60.8%
Taylor expanded in angle around 0 56.4%
if 9.99999999999999907e186 < a Initial program 46.4%
Simplified46.4%
Taylor expanded in angle around 0 49.6%
unpow246.4%
unpow246.4%
difference-of-squares65.9%
Applied egg-rr65.9%
Final simplification57.6%
(FPCore (a b angle) :precision binary64 (* 2.0 (* 0.005555555555555556 (* angle (* (* (- b a) (+ b a)) PI)))))
double code(double a, double b, double angle) {
return 2.0 * (0.005555555555555556 * (angle * (((b - a) * (b + a)) * ((double) M_PI))));
}
public static double code(double a, double b, double angle) {
return 2.0 * (0.005555555555555556 * (angle * (((b - a) * (b + a)) * Math.PI)));
}
def code(a, b, angle): return 2.0 * (0.005555555555555556 * (angle * (((b - a) * (b + a)) * math.pi)))
function code(a, b, angle) return Float64(2.0 * Float64(0.005555555555555556 * Float64(angle * Float64(Float64(Float64(b - a) * Float64(b + a)) * pi)))) end
function tmp = code(a, b, angle) tmp = 2.0 * (0.005555555555555556 * (angle * (((b - a) * (b + a)) * pi))); end
code[a_, b_, angle_] := N[(2.0 * N[(0.005555555555555556 * N[(angle * N[(N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \left(\left(\left(b - a\right) \cdot \left(b + a\right)\right) \cdot \pi\right)\right)\right)
\end{array}
Initial program 58.9%
Simplified58.4%
Taylor expanded in angle around 0 52.9%
unpow258.9%
unpow258.9%
difference-of-squares63.3%
Applied egg-rr56.5%
Final simplification56.5%
herbie shell --seed 2024039
(FPCore (a b angle)
:name "ab-angle->ABCF B"
:precision binary64
(* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* PI (/ angle 180.0)))) (cos (* PI (/ angle 180.0)))))