
(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 7 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 (* (- b a) (* (+ b a) (sin (* 0.011111111111111112 (* PI angle))))))
double code(double a, double b, double angle) {
return (b - a) * ((b + a) * sin((0.011111111111111112 * (((double) M_PI) * angle))));
}
public static double code(double a, double b, double angle) {
return (b - a) * ((b + a) * Math.sin((0.011111111111111112 * (Math.PI * angle))));
}
def code(a, b, angle): return (b - a) * ((b + a) * math.sin((0.011111111111111112 * (math.pi * angle))))
function code(a, b, angle) return Float64(Float64(b - a) * Float64(Float64(b + a) * sin(Float64(0.011111111111111112 * Float64(pi * angle))))) end
function tmp = code(a, b, angle) tmp = (b - a) * ((b + a) * sin((0.011111111111111112 * (pi * angle)))); end
code[a_, b_, angle_] := N[(N[(b - a), $MachinePrecision] * N[(N[(b + a), $MachinePrecision] * N[Sin[N[(0.011111111111111112 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(b - a\right) \cdot \left(\left(b + a\right) \cdot \sin \left(0.011111111111111112 \cdot \left(\pi \cdot angle\right)\right)\right)
\end{array}
Initial program 56.4%
*-commutative56.4%
associate-*l*56.7%
associate-*l*56.7%
Simplified56.7%
unpow256.7%
unpow256.7%
difference-of-squares60.7%
Applied egg-rr60.7%
add-sqr-sqrt35.0%
sqrt-unprod38.6%
pow238.6%
Applied egg-rr40.1%
unpow240.1%
sqrt-prod39.8%
add-sqr-sqrt69.3%
associate-*r*60.0%
*-commutative60.0%
associate-*l*69.3%
+-commutative69.3%
*-commutative69.3%
*-commutative69.3%
associate-*r*69.3%
*-commutative69.3%
associate-*r*71.9%
associate-*l*71.9%
metadata-eval71.9%
Applied egg-rr71.9%
Final simplification71.9%
(FPCore (a b angle) :precision binary64 (if (<= a 8.6e-26) (* 0.011111111111111112 (* angle (* (- b a) (* b PI)))) (* 0.011111111111111112 (* angle (* (- b a) (* a PI))))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 8.6e-26) {
tmp = 0.011111111111111112 * (angle * ((b - a) * (b * ((double) M_PI))));
} else {
tmp = 0.011111111111111112 * (angle * ((b - a) * (a * ((double) M_PI))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 8.6e-26) {
tmp = 0.011111111111111112 * (angle * ((b - a) * (b * Math.PI)));
} else {
tmp = 0.011111111111111112 * (angle * ((b - a) * (a * Math.PI)));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 8.6e-26: tmp = 0.011111111111111112 * (angle * ((b - a) * (b * math.pi))) else: tmp = 0.011111111111111112 * (angle * ((b - a) * (a * math.pi))) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 8.6e-26) tmp = Float64(0.011111111111111112 * Float64(angle * Float64(Float64(b - a) * Float64(b * pi)))); else tmp = Float64(0.011111111111111112 * Float64(angle * Float64(Float64(b - a) * Float64(a * pi)))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 8.6e-26) tmp = 0.011111111111111112 * (angle * ((b - a) * (b * pi))); else tmp = 0.011111111111111112 * (angle * ((b - a) * (a * pi))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 8.6e-26], N[(0.011111111111111112 * N[(angle * N[(N[(b - a), $MachinePrecision] * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.011111111111111112 * N[(angle * N[(N[(b - a), $MachinePrecision] * N[(a * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 8.6 \cdot 10^{-26}:\\
\;\;\;\;0.011111111111111112 \cdot \left(angle \cdot \left(\left(b - a\right) \cdot \left(b \cdot \pi\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.011111111111111112 \cdot \left(angle \cdot \left(\left(b - a\right) \cdot \left(a \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if a < 8.59999999999999976e-26Initial program 58.2%
*-commutative58.2%
associate-*l*58.6%
associate-*l*58.6%
Simplified58.6%
unpow258.6%
unpow258.6%
difference-of-squares62.0%
Applied egg-rr62.0%
Taylor expanded in angle around 0 62.9%
associate-*r*62.9%
sub-neg62.9%
distribute-lft-in60.1%
+-commutative60.1%
+-commutative60.1%
Applied egg-rr60.1%
distribute-lft-out62.9%
+-commutative62.9%
sub-neg62.9%
Simplified62.9%
Taylor expanded in a around 0 47.6%
*-commutative47.6%
Simplified47.6%
if 8.59999999999999976e-26 < a Initial program 52.3%
*-commutative52.3%
associate-*l*52.3%
associate-*l*52.3%
Simplified52.3%
unpow252.3%
unpow252.3%
difference-of-squares57.5%
Applied egg-rr57.5%
Taylor expanded in angle around 0 54.9%
associate-*r*54.9%
sub-neg54.9%
distribute-lft-in48.3%
+-commutative48.3%
+-commutative48.3%
Applied egg-rr48.3%
distribute-lft-out54.9%
+-commutative54.9%
sub-neg54.9%
Simplified54.9%
Taylor expanded in a around inf 49.5%
*-commutative49.5%
Simplified49.5%
Final simplification48.2%
(FPCore (a b angle) :precision binary64 (* 0.011111111111111112 (* angle (* PI (* (- b a) (+ b a))))))
double code(double a, double b, double angle) {
return 0.011111111111111112 * (angle * (((double) M_PI) * ((b - a) * (b + a))));
}
public static double code(double a, double b, double angle) {
return 0.011111111111111112 * (angle * (Math.PI * ((b - a) * (b + a))));
}
def code(a, b, angle): return 0.011111111111111112 * (angle * (math.pi * ((b - a) * (b + a))))
function code(a, b, angle) return Float64(0.011111111111111112 * Float64(angle * Float64(pi * Float64(Float64(b - a) * Float64(b + a))))) end
function tmp = code(a, b, angle) tmp = 0.011111111111111112 * (angle * (pi * ((b - a) * (b + a)))); end
code[a_, b_, angle_] := N[(0.011111111111111112 * N[(angle * N[(Pi * N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.011111111111111112 \cdot \left(angle \cdot \left(\pi \cdot \left(\left(b - a\right) \cdot \left(b + a\right)\right)\right)\right)
\end{array}
Initial program 56.4%
*-commutative56.4%
associate-*l*56.7%
associate-*l*56.7%
Simplified56.7%
unpow256.7%
unpow256.7%
difference-of-squares60.7%
Applied egg-rr60.7%
Taylor expanded in angle around 0 60.5%
Final simplification60.5%
(FPCore (a b angle) :precision binary64 (* 0.011111111111111112 (* angle (* (- b a) (* (+ b a) PI)))))
double code(double a, double b, double angle) {
return 0.011111111111111112 * (angle * ((b - a) * ((b + a) * ((double) M_PI))));
}
public static double code(double a, double b, double angle) {
return 0.011111111111111112 * (angle * ((b - a) * ((b + a) * Math.PI)));
}
def code(a, b, angle): return 0.011111111111111112 * (angle * ((b - a) * ((b + a) * math.pi)))
function code(a, b, angle) return Float64(0.011111111111111112 * Float64(angle * Float64(Float64(b - a) * Float64(Float64(b + a) * pi)))) end
function tmp = code(a, b, angle) tmp = 0.011111111111111112 * (angle * ((b - a) * ((b + a) * pi))); end
code[a_, b_, angle_] := N[(0.011111111111111112 * N[(angle * N[(N[(b - a), $MachinePrecision] * N[(N[(b + a), $MachinePrecision] * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.011111111111111112 \cdot \left(angle \cdot \left(\left(b - a\right) \cdot \left(\left(b + a\right) \cdot \pi\right)\right)\right)
\end{array}
Initial program 56.4%
*-commutative56.4%
associate-*l*56.7%
associate-*l*56.7%
Simplified56.7%
unpow256.7%
unpow256.7%
difference-of-squares60.7%
Applied egg-rr60.7%
Taylor expanded in angle around 0 60.5%
associate-*r*60.5%
sub-neg60.5%
distribute-lft-in56.5%
+-commutative56.5%
+-commutative56.5%
Applied egg-rr56.5%
distribute-lft-out60.5%
+-commutative60.5%
sub-neg60.5%
Simplified60.5%
Final simplification60.5%
(FPCore (a b angle) :precision binary64 (* 0.011111111111111112 (* (* PI angle) (* (- b a) (+ b a)))))
double code(double a, double b, double angle) {
return 0.011111111111111112 * ((((double) M_PI) * angle) * ((b - a) * (b + a)));
}
public static double code(double a, double b, double angle) {
return 0.011111111111111112 * ((Math.PI * angle) * ((b - a) * (b + a)));
}
def code(a, b, angle): return 0.011111111111111112 * ((math.pi * angle) * ((b - a) * (b + a)))
function code(a, b, angle) return Float64(0.011111111111111112 * Float64(Float64(pi * angle) * Float64(Float64(b - a) * Float64(b + a)))) end
function tmp = code(a, b, angle) tmp = 0.011111111111111112 * ((pi * angle) * ((b - a) * (b + a))); end
code[a_, b_, angle_] := N[(0.011111111111111112 * N[(N[(Pi * angle), $MachinePrecision] * N[(N[(b - a), $MachinePrecision] * N[(b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.011111111111111112 \cdot \left(\left(\pi \cdot angle\right) \cdot \left(\left(b - a\right) \cdot \left(b + a\right)\right)\right)
\end{array}
Initial program 56.4%
*-commutative56.4%
associate-*l*56.7%
associate-*l*56.7%
Simplified56.7%
unpow256.7%
unpow256.7%
difference-of-squares60.7%
Applied egg-rr60.7%
Taylor expanded in angle around 0 60.5%
associate-*r*60.5%
sub-neg60.5%
distribute-lft-in56.5%
+-commutative56.5%
+-commutative56.5%
Applied egg-rr56.5%
distribute-lft-out60.5%
+-commutative60.5%
sub-neg60.5%
Simplified60.5%
Taylor expanded in angle around 0 60.5%
associate-*r*60.6%
Simplified60.6%
Final simplification60.6%
(FPCore (a b angle) :precision binary64 (* (- b a) (* (+ b a) (* 0.011111111111111112 (* PI angle)))))
double code(double a, double b, double angle) {
return (b - a) * ((b + a) * (0.011111111111111112 * (((double) M_PI) * angle)));
}
public static double code(double a, double b, double angle) {
return (b - a) * ((b + a) * (0.011111111111111112 * (Math.PI * angle)));
}
def code(a, b, angle): return (b - a) * ((b + a) * (0.011111111111111112 * (math.pi * angle)))
function code(a, b, angle) return Float64(Float64(b - a) * Float64(Float64(b + a) * Float64(0.011111111111111112 * Float64(pi * angle)))) end
function tmp = code(a, b, angle) tmp = (b - a) * ((b + a) * (0.011111111111111112 * (pi * angle))); end
code[a_, b_, angle_] := N[(N[(b - a), $MachinePrecision] * N[(N[(b + a), $MachinePrecision] * N[(0.011111111111111112 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(b - a\right) \cdot \left(\left(b + a\right) \cdot \left(0.011111111111111112 \cdot \left(\pi \cdot angle\right)\right)\right)
\end{array}
Initial program 56.4%
*-commutative56.4%
associate-*l*56.7%
associate-*l*56.7%
Simplified56.7%
unpow256.7%
unpow256.7%
difference-of-squares60.7%
Applied egg-rr60.7%
add-sqr-sqrt35.0%
sqrt-unprod38.6%
pow238.6%
Applied egg-rr40.1%
unpow240.1%
sqrt-prod39.8%
add-sqr-sqrt69.3%
associate-*r*60.0%
*-commutative60.0%
associate-*l*69.3%
+-commutative69.3%
*-commutative69.3%
*-commutative69.3%
associate-*r*69.3%
*-commutative69.3%
associate-*r*71.9%
associate-*l*71.9%
metadata-eval71.9%
Applied egg-rr71.9%
Taylor expanded in angle around 0 68.9%
Final simplification68.9%
(FPCore (a b angle) :precision binary64 (* 0.011111111111111112 (* angle (* (- b a) (* a PI)))))
double code(double a, double b, double angle) {
return 0.011111111111111112 * (angle * ((b - a) * (a * ((double) M_PI))));
}
public static double code(double a, double b, double angle) {
return 0.011111111111111112 * (angle * ((b - a) * (a * Math.PI)));
}
def code(a, b, angle): return 0.011111111111111112 * (angle * ((b - a) * (a * math.pi)))
function code(a, b, angle) return Float64(0.011111111111111112 * Float64(angle * Float64(Float64(b - a) * Float64(a * pi)))) end
function tmp = code(a, b, angle) tmp = 0.011111111111111112 * (angle * ((b - a) * (a * pi))); end
code[a_, b_, angle_] := N[(0.011111111111111112 * N[(angle * N[(N[(b - a), $MachinePrecision] * N[(a * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.011111111111111112 \cdot \left(angle \cdot \left(\left(b - a\right) \cdot \left(a \cdot \pi\right)\right)\right)
\end{array}
Initial program 56.4%
*-commutative56.4%
associate-*l*56.7%
associate-*l*56.7%
Simplified56.7%
unpow256.7%
unpow256.7%
difference-of-squares60.7%
Applied egg-rr60.7%
Taylor expanded in angle around 0 60.5%
associate-*r*60.5%
sub-neg60.5%
distribute-lft-in56.5%
+-commutative56.5%
+-commutative56.5%
Applied egg-rr56.5%
distribute-lft-out60.5%
+-commutative60.5%
sub-neg60.5%
Simplified60.5%
Taylor expanded in a around inf 40.5%
*-commutative40.5%
Simplified40.5%
Final simplification40.5%
herbie shell --seed 2023298
(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)))))