
(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 20 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}
a_m = (fabs.f64 a)
(FPCore (a_m b angle)
:precision binary64
(let* ((t_0
(*
(+ b a_m)
(* (- b a_m) (* 2.0 (sin (* PI (* angle 0.005555555555555556))))))))
(if (<= a_m 3.6e-45)
(*
(+ b a_m)
(*
(- b a_m)
(sin
(*
0.011111111111111112
(* angle (* (sqrt (sqrt PI)) (sqrt (* PI (sqrt PI)))))))))
(if (<= a_m 1.65e+161) (* t_0 (cos (/ PI (/ 180.0 angle)))) t_0))))a_m = fabs(a);
double code(double a_m, double b, double angle) {
double t_0 = (b + a_m) * ((b - a_m) * (2.0 * sin((((double) M_PI) * (angle * 0.005555555555555556)))));
double tmp;
if (a_m <= 3.6e-45) {
tmp = (b + a_m) * ((b - a_m) * sin((0.011111111111111112 * (angle * (sqrt(sqrt(((double) M_PI))) * sqrt((((double) M_PI) * sqrt(((double) M_PI)))))))));
} else if (a_m <= 1.65e+161) {
tmp = t_0 * cos((((double) M_PI) / (180.0 / angle)));
} else {
tmp = t_0;
}
return tmp;
}
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle) {
double t_0 = (b + a_m) * ((b - a_m) * (2.0 * Math.sin((Math.PI * (angle * 0.005555555555555556)))));
double tmp;
if (a_m <= 3.6e-45) {
tmp = (b + a_m) * ((b - a_m) * Math.sin((0.011111111111111112 * (angle * (Math.sqrt(Math.sqrt(Math.PI)) * Math.sqrt((Math.PI * Math.sqrt(Math.PI))))))));
} else if (a_m <= 1.65e+161) {
tmp = t_0 * Math.cos((Math.PI / (180.0 / angle)));
} else {
tmp = t_0;
}
return tmp;
}
a_m = math.fabs(a) def code(a_m, b, angle): t_0 = (b + a_m) * ((b - a_m) * (2.0 * math.sin((math.pi * (angle * 0.005555555555555556))))) tmp = 0 if a_m <= 3.6e-45: tmp = (b + a_m) * ((b - a_m) * math.sin((0.011111111111111112 * (angle * (math.sqrt(math.sqrt(math.pi)) * math.sqrt((math.pi * math.sqrt(math.pi)))))))) elif a_m <= 1.65e+161: tmp = t_0 * math.cos((math.pi / (180.0 / angle))) else: tmp = t_0 return tmp
a_m = abs(a) function code(a_m, b, angle) t_0 = Float64(Float64(b + a_m) * Float64(Float64(b - a_m) * Float64(2.0 * sin(Float64(pi * Float64(angle * 0.005555555555555556)))))) tmp = 0.0 if (a_m <= 3.6e-45) tmp = Float64(Float64(b + a_m) * Float64(Float64(b - a_m) * sin(Float64(0.011111111111111112 * Float64(angle * Float64(sqrt(sqrt(pi)) * sqrt(Float64(pi * sqrt(pi))))))))); elseif (a_m <= 1.65e+161) tmp = Float64(t_0 * cos(Float64(pi / Float64(180.0 / angle)))); else tmp = t_0; end return tmp end
a_m = abs(a); function tmp_2 = code(a_m, b, angle) t_0 = (b + a_m) * ((b - a_m) * (2.0 * sin((pi * (angle * 0.005555555555555556))))); tmp = 0.0; if (a_m <= 3.6e-45) tmp = (b + a_m) * ((b - a_m) * sin((0.011111111111111112 * (angle * (sqrt(sqrt(pi)) * sqrt((pi * sqrt(pi)))))))); elseif (a_m <= 1.65e+161) tmp = t_0 * cos((pi / (180.0 / angle))); else tmp = t_0; end tmp_2 = tmp; end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_] := Block[{t$95$0 = N[(N[(b + a$95$m), $MachinePrecision] * N[(N[(b - a$95$m), $MachinePrecision] * N[(2.0 * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a$95$m, 3.6e-45], N[(N[(b + a$95$m), $MachinePrecision] * N[(N[(b - a$95$m), $MachinePrecision] * N[Sin[N[(0.011111111111111112 * N[(angle * N[(N[Sqrt[N[Sqrt[Pi], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(Pi * N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a$95$m, 1.65e+161], N[(t$95$0 * N[Cos[N[(Pi / N[(180.0 / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \left(b + a\_m\right) \cdot \left(\left(b - a\_m\right) \cdot \left(2 \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)\right)\\
\mathbf{if}\;a\_m \leq 3.6 \cdot 10^{-45}:\\
\;\;\;\;\left(b + a\_m\right) \cdot \left(\left(b - a\_m\right) \cdot \sin \left(0.011111111111111112 \cdot \left(angle \cdot \left(\sqrt{\sqrt{\pi}} \cdot \sqrt{\pi \cdot \sqrt{\pi}}\right)\right)\right)\right)\\
\mathbf{elif}\;a\_m \leq 1.65 \cdot 10^{+161}:\\
\;\;\;\;t\_0 \cdot \cos \left(\frac{\pi}{\frac{180}{angle}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if a < 3.60000000000000001e-45Initial program 60.1%
Applied egg-rr67.3%
lift-PI.f6467.3
rem-square-sqrtN/A
sqrt-unprodN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
lift-*.f64N/A
sqrt-unprodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f6472.4
Applied egg-rr72.4%
if 3.60000000000000001e-45 < a < 1.64999999999999999e161Initial program 61.1%
lift-pow.f64N/A
lift-pow.f64N/A
lift--.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
associate-*l*N/A
lift--.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-pow.f64N/A
unpow2N/A
difference-of-squaresN/A
associate-*l*N/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
Applied egg-rr67.4%
lift-PI.f64N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6468.6
Applied egg-rr68.6%
if 1.64999999999999999e161 < a Initial program 34.1%
lift-pow.f64N/A
lift-pow.f64N/A
lift--.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
associate-*l*N/A
lift--.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-pow.f64N/A
unpow2N/A
difference-of-squaresN/A
associate-*l*N/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
Applied egg-rr67.0%
Taylor expanded in angle around 0
Simplified81.8%
Final simplification73.3%
a_m = (fabs.f64 a)
(FPCore (a_m b angle)
:precision binary64
(let* ((t_0 (sqrt (sqrt PI))) (t_1 (sqrt t_0)) (t_2 (* t_1 (* t_0 t_1))))
(if (<= (/ angle 180.0) 1e+53)
(*
(+ b a_m)
(* (- b a_m) (* 2.0 (sin (* PI (* angle 0.005555555555555556))))))
(*
(+ b a_m)
(* (- b a_m) (sin (* (* angle (* t_2 t_2)) 0.011111111111111112)))))))a_m = fabs(a);
double code(double a_m, double b, double angle) {
double t_0 = sqrt(sqrt(((double) M_PI)));
double t_1 = sqrt(t_0);
double t_2 = t_1 * (t_0 * t_1);
double tmp;
if ((angle / 180.0) <= 1e+53) {
tmp = (b + a_m) * ((b - a_m) * (2.0 * sin((((double) M_PI) * (angle * 0.005555555555555556)))));
} else {
tmp = (b + a_m) * ((b - a_m) * sin(((angle * (t_2 * t_2)) * 0.011111111111111112)));
}
return tmp;
}
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle) {
double t_0 = Math.sqrt(Math.sqrt(Math.PI));
double t_1 = Math.sqrt(t_0);
double t_2 = t_1 * (t_0 * t_1);
double tmp;
if ((angle / 180.0) <= 1e+53) {
tmp = (b + a_m) * ((b - a_m) * (2.0 * Math.sin((Math.PI * (angle * 0.005555555555555556)))));
} else {
tmp = (b + a_m) * ((b - a_m) * Math.sin(((angle * (t_2 * t_2)) * 0.011111111111111112)));
}
return tmp;
}
a_m = math.fabs(a) def code(a_m, b, angle): t_0 = math.sqrt(math.sqrt(math.pi)) t_1 = math.sqrt(t_0) t_2 = t_1 * (t_0 * t_1) tmp = 0 if (angle / 180.0) <= 1e+53: tmp = (b + a_m) * ((b - a_m) * (2.0 * math.sin((math.pi * (angle * 0.005555555555555556))))) else: tmp = (b + a_m) * ((b - a_m) * math.sin(((angle * (t_2 * t_2)) * 0.011111111111111112))) return tmp
a_m = abs(a) function code(a_m, b, angle) t_0 = sqrt(sqrt(pi)) t_1 = sqrt(t_0) t_2 = Float64(t_1 * Float64(t_0 * t_1)) tmp = 0.0 if (Float64(angle / 180.0) <= 1e+53) tmp = Float64(Float64(b + a_m) * Float64(Float64(b - a_m) * Float64(2.0 * sin(Float64(pi * Float64(angle * 0.005555555555555556)))))); else tmp = Float64(Float64(b + a_m) * Float64(Float64(b - a_m) * sin(Float64(Float64(angle * Float64(t_2 * t_2)) * 0.011111111111111112)))); end return tmp end
a_m = abs(a); function tmp_2 = code(a_m, b, angle) t_0 = sqrt(sqrt(pi)); t_1 = sqrt(t_0); t_2 = t_1 * (t_0 * t_1); tmp = 0.0; if ((angle / 180.0) <= 1e+53) tmp = (b + a_m) * ((b - a_m) * (2.0 * sin((pi * (angle * 0.005555555555555556))))); else tmp = (b + a_m) * ((b - a_m) * sin(((angle * (t_2 * t_2)) * 0.011111111111111112))); end tmp_2 = tmp; end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_] := Block[{t$95$0 = N[Sqrt[N[Sqrt[Pi], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(angle / 180.0), $MachinePrecision], 1e+53], N[(N[(b + a$95$m), $MachinePrecision] * N[(N[(b - a$95$m), $MachinePrecision] * N[(2.0 * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + a$95$m), $MachinePrecision] * N[(N[(b - a$95$m), $MachinePrecision] * N[Sin[N[(N[(angle * N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision] * 0.011111111111111112), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \sqrt{\sqrt{\pi}}\\
t_1 := \sqrt{t\_0}\\
t_2 := t\_1 \cdot \left(t\_0 \cdot t\_1\right)\\
\mathbf{if}\;\frac{angle}{180} \leq 10^{+53}:\\
\;\;\;\;\left(b + a\_m\right) \cdot \left(\left(b - a\_m\right) \cdot \left(2 \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(b + a\_m\right) \cdot \left(\left(b - a\_m\right) \cdot \sin \left(\left(angle \cdot \left(t\_2 \cdot t\_2\right)\right) \cdot 0.011111111111111112\right)\right)\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 9.9999999999999999e52Initial program 60.3%
lift-pow.f64N/A
lift-pow.f64N/A
lift--.f64N/A
*-commutativeN/A
lift-PI.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
associate-*l*N/A
lift--.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-pow.f64N/A
unpow2N/A
difference-of-squaresN/A
associate-*l*N/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
Applied egg-rr76.6%
Taylor expanded in angle around 0
Simplified74.8%
if 9.9999999999999999e52 < (/.f64 angle #s(literal 180 binary64)) Initial program 29.8%
Applied egg-rr33.5%
lift-PI.f6433.5
rem-square-sqrtN/A
sqrt-unprodN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
lift-*.f64N/A
pow1/2N/A
pow-prod-downN/A
sqr-powN/A
pow1/2N/A
rem-cube-cbrtN/A
lift-cbrt.f64N/A
sqrt-pow1N/A
sqr-powN/A
Applied egg-rr32.1%
Final simplification66.2%
herbie shell --seed 2024218
(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)))))