
(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 6 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)))) (* (* (* 2.0 (* (- b a) (+ b a))) (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 * ((b - a) * (b + a))) * 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 * ((b - a) * (b + a))) * Math.sin(t_0)) * Math.cos(t_0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return ((2.0 * ((b - a) * (b + a))) * 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(Float64(b - a) * Float64(b + a))) * sin(t_0)) * cos(t_0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((2.0 * ((b - a) * (b + a))) * 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[(b - a), $MachinePrecision] * N[(b + a), $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(\left(b - a\right) \cdot \left(b + a\right)\right)\right) \cdot \sin t\_0\right) \cdot \cos t\_0
\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 (* -0.005555555555555556 (* PI angle))))
(if (<= b 1.05e+217)
(* 2.0 (* (cos t_0) (* (* (+ b a) (- a b)) (sin t_0))))
(*
(cos (* PI (/ angle 180.0)))
(* 0.011111111111111112 (* angle (* PI (* (- b a) (+ b a)))))))))
double code(double a, double b, double angle) {
double t_0 = -0.005555555555555556 * (((double) M_PI) * angle);
double tmp;
if (b <= 1.05e+217) {
tmp = 2.0 * (cos(t_0) * (((b + a) * (a - b)) * sin(t_0)));
} else {
tmp = cos((((double) M_PI) * (angle / 180.0))) * (0.011111111111111112 * (angle * (((double) M_PI) * ((b - a) * (b + a)))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = -0.005555555555555556 * (Math.PI * angle);
double tmp;
if (b <= 1.05e+217) {
tmp = 2.0 * (Math.cos(t_0) * (((b + a) * (a - b)) * Math.sin(t_0)));
} else {
tmp = Math.cos((Math.PI * (angle / 180.0))) * (0.011111111111111112 * (angle * (Math.PI * ((b - a) * (b + a)))));
}
return tmp;
}
def code(a, b, angle): t_0 = -0.005555555555555556 * (math.pi * angle) tmp = 0 if b <= 1.05e+217: tmp = 2.0 * (math.cos(t_0) * (((b + a) * (a - b)) * math.sin(t_0))) else: tmp = math.cos((math.pi * (angle / 180.0))) * (0.011111111111111112 * (angle * (math.pi * ((b - a) * (b + a))))) return tmp
function code(a, b, angle) t_0 = Float64(-0.005555555555555556 * Float64(pi * angle)) tmp = 0.0 if (b <= 1.05e+217) tmp = Float64(2.0 * Float64(cos(t_0) * Float64(Float64(Float64(b + a) * Float64(a - b)) * sin(t_0)))); else tmp = Float64(cos(Float64(pi * Float64(angle / 180.0))) * Float64(0.011111111111111112 * Float64(angle * Float64(pi * Float64(Float64(b - a) * Float64(b + a)))))); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = -0.005555555555555556 * (pi * angle); tmp = 0.0; if (b <= 1.05e+217) tmp = 2.0 * (cos(t_0) * (((b + a) * (a - b)) * sin(t_0))); else tmp = cos((pi * (angle / 180.0))) * (0.011111111111111112 * (angle * (pi * ((b - a) * (b + a))))); end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(-0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.05e+217], N[(2.0 * N[(N[Cos[t$95$0], $MachinePrecision] * N[(N[(N[(b + a), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision] * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.011111111111111112 * N[(angle * N[(Pi * N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.005555555555555556 \cdot \left(\pi \cdot angle\right)\\
\mathbf{if}\;b \leq 1.05 \cdot 10^{+217}:\\
\;\;\;\;2 \cdot \left(\cos t\_0 \cdot \left(\left(\left(b + a\right) \cdot \left(a - b\right)\right) \cdot \sin t\_0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \frac{angle}{180}\right) \cdot \left(0.011111111111111112 \cdot \left(angle \cdot \left(\pi \cdot \left(\left(b - a\right) \cdot \left(b + a\right)\right)\right)\right)\right)\\
\end{array}
\end{array}
if b < 1.05e217Initial program 59.9%
Simplified59.5%
unpow253.5%
unpow253.5%
difference-of-squares56.5%
Applied egg-rr62.0%
Taylor expanded in angle around inf 60.7%
*-commutative60.7%
Simplified60.7%
if 1.05e217 < b Initial program 45.2%
unpow245.2%
unpow245.2%
difference-of-squares73.5%
Applied egg-rr73.5%
Taylor expanded in angle around 0 79.1%
Final simplification61.9%
(FPCore (a b angle) :precision binary64 (* 2.0 (* (sin (* PI (* angle -0.005555555555555556))) (* (cos (* angle (/ PI -180.0))) (* (+ b a) (- a b))))))
double code(double a, double b, double angle) {
return 2.0 * (sin((((double) M_PI) * (angle * -0.005555555555555556))) * (cos((angle * (((double) M_PI) / -180.0))) * ((b + a) * (a - b))));
}
public static double code(double a, double b, double angle) {
return 2.0 * (Math.sin((Math.PI * (angle * -0.005555555555555556))) * (Math.cos((angle * (Math.PI / -180.0))) * ((b + a) * (a - b))));
}
def code(a, b, angle): return 2.0 * (math.sin((math.pi * (angle * -0.005555555555555556))) * (math.cos((angle * (math.pi / -180.0))) * ((b + a) * (a - b))))
function code(a, b, angle) return Float64(2.0 * Float64(sin(Float64(pi * Float64(angle * -0.005555555555555556))) * Float64(cos(Float64(angle * Float64(pi / -180.0))) * Float64(Float64(b + a) * Float64(a - b))))) end
function tmp = code(a, b, angle) tmp = 2.0 * (sin((pi * (angle * -0.005555555555555556))) * (cos((angle * (pi / -180.0))) * ((b + a) * (a - b)))); end
code[a_, b_, angle_] := N[(2.0 * N[(N[Sin[N[(Pi * N[(angle * -0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[Cos[N[(angle * N[(Pi / -180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(b + a), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(\sin \left(\pi \cdot \left(angle \cdot -0.005555555555555556\right)\right) \cdot \left(\cos \left(angle \cdot \frac{\pi}{-180}\right) \cdot \left(\left(b + a\right) \cdot \left(a - b\right)\right)\right)\right)
\end{array}
Initial program 58.9%
Simplified58.5%
unpow252.9%
unpow252.9%
difference-of-squares56.5%
Applied egg-rr62.5%
Taylor expanded in angle around 0 63.2%
associate-*r*62.9%
Simplified62.9%
Final simplification62.9%
(FPCore (a b angle) :precision binary64 (* 2.0 (* angle (* -0.005555555555555556 (* PI (* (+ b a) (- a b)))))))
double code(double a, double b, double angle) {
return 2.0 * (angle * (-0.005555555555555556 * (((double) M_PI) * ((b + a) * (a - b)))));
}
public static double code(double a, double b, double angle) {
return 2.0 * (angle * (-0.005555555555555556 * (Math.PI * ((b + a) * (a - b)))));
}
def code(a, b, angle): return 2.0 * (angle * (-0.005555555555555556 * (math.pi * ((b + a) * (a - b)))))
function code(a, b, angle) return Float64(2.0 * Float64(angle * Float64(-0.005555555555555556 * Float64(pi * Float64(Float64(b + a) * Float64(a - b)))))) end
function tmp = code(a, b, angle) tmp = 2.0 * (angle * (-0.005555555555555556 * (pi * ((b + a) * (a - b))))); end
code[a_, b_, angle_] := N[(2.0 * N[(angle * N[(-0.005555555555555556 * N[(Pi * N[(N[(b + a), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(angle \cdot \left(-0.005555555555555556 \cdot \left(\pi \cdot \left(\left(b + a\right) \cdot \left(a - b\right)\right)\right)\right)\right)
\end{array}
Initial program 58.9%
Simplified58.5%
Taylor expanded in angle around 0 52.9%
unpow252.9%
unpow252.9%
difference-of-squares56.5%
Applied egg-rr56.5%
pow156.5%
*-commutative56.5%
associate-*r*56.5%
+-commutative56.5%
Applied egg-rr56.5%
unpow156.5%
associate-*l*56.5%
associate-*l*56.5%
+-commutative56.5%
Simplified56.5%
Final simplification56.5%
(FPCore (a b angle) :precision binary64 (* -0.011111111111111112 (* angle (* PI (* (+ b a) (- a b))))))
double code(double a, double b, double angle) {
return -0.011111111111111112 * (angle * (((double) M_PI) * ((b + a) * (a - b))));
}
public static double code(double a, double b, double angle) {
return -0.011111111111111112 * (angle * (Math.PI * ((b + a) * (a - b))));
}
def code(a, b, angle): return -0.011111111111111112 * (angle * (math.pi * ((b + a) * (a - b))))
function code(a, b, angle) return Float64(-0.011111111111111112 * Float64(angle * Float64(pi * Float64(Float64(b + a) * Float64(a - b))))) end
function tmp = code(a, b, angle) tmp = -0.011111111111111112 * (angle * (pi * ((b + a) * (a - b)))); end
code[a_, b_, angle_] := N[(-0.011111111111111112 * N[(angle * N[(Pi * N[(N[(b + a), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.011111111111111112 \cdot \left(angle \cdot \left(\pi \cdot \left(\left(b + a\right) \cdot \left(a - b\right)\right)\right)\right)
\end{array}
Initial program 58.9%
Simplified58.5%
Taylor expanded in angle around 0 52.9%
unpow252.9%
unpow252.9%
difference-of-squares56.5%
Applied egg-rr56.5%
pow156.5%
*-commutative56.5%
associate-*r*56.5%
+-commutative56.5%
Applied egg-rr56.5%
unpow156.5%
associate-*l*56.5%
associate-*l*56.5%
+-commutative56.5%
Simplified56.5%
Taylor expanded in angle around 0 56.5%
*-commutative56.5%
Simplified56.5%
Final simplification56.5%
(FPCore (a b angle) :precision binary64 (* (* (* (+ b a) (- a b)) (* PI angle)) -0.011111111111111112))
double code(double a, double b, double angle) {
return (((b + a) * (a - b)) * (((double) M_PI) * angle)) * -0.011111111111111112;
}
public static double code(double a, double b, double angle) {
return (((b + a) * (a - b)) * (Math.PI * angle)) * -0.011111111111111112;
}
def code(a, b, angle): return (((b + a) * (a - b)) * (math.pi * angle)) * -0.011111111111111112
function code(a, b, angle) return Float64(Float64(Float64(Float64(b + a) * Float64(a - b)) * Float64(pi * angle)) * -0.011111111111111112) end
function tmp = code(a, b, angle) tmp = (((b + a) * (a - b)) * (pi * angle)) * -0.011111111111111112; end
code[a_, b_, angle_] := N[(N[(N[(N[(b + a), $MachinePrecision] * N[(a - b), $MachinePrecision]), $MachinePrecision] * N[(Pi * angle), $MachinePrecision]), $MachinePrecision] * -0.011111111111111112), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\left(b + a\right) \cdot \left(a - b\right)\right) \cdot \left(\pi \cdot angle\right)\right) \cdot -0.011111111111111112
\end{array}
Initial program 58.9%
Simplified58.5%
Taylor expanded in angle around 0 52.9%
unpow252.9%
unpow252.9%
difference-of-squares56.5%
Applied egg-rr56.5%
pow156.5%
*-commutative56.5%
associate-*r*56.5%
+-commutative56.5%
Applied egg-rr56.5%
unpow156.5%
associate-*l*56.5%
associate-*l*56.5%
+-commutative56.5%
Simplified56.5%
Taylor expanded in angle around 0 56.5%
*-commutative56.5%
associate-*r*56.5%
Simplified56.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)))))