
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\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)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Initial program 75.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* PI (/ angle 180.0)))) 2.0) (* a (* a (/ (+ 1.0 (cos (* PI (* angle 0.011111111111111112)))) 2.0)))))
double code(double a, double b, double angle) {
return pow((b * sin((((double) M_PI) * (angle / 180.0)))), 2.0) + (a * (a * ((1.0 + cos((((double) M_PI) * (angle * 0.011111111111111112)))) / 2.0)));
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin((Math.PI * (angle / 180.0)))), 2.0) + (a * (a * ((1.0 + Math.cos((Math.PI * (angle * 0.011111111111111112)))) / 2.0)));
}
def code(a, b, angle): return math.pow((b * math.sin((math.pi * (angle / 180.0)))), 2.0) + (a * (a * ((1.0 + math.cos((math.pi * (angle * 0.011111111111111112)))) / 2.0)))
function code(a, b, angle) return Float64((Float64(b * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + Float64(a * Float64(a * Float64(Float64(1.0 + cos(Float64(pi * Float64(angle * 0.011111111111111112)))) / 2.0)))) end
function tmp = code(a, b, angle) tmp = ((b * sin((pi * (angle / 180.0)))) ^ 2.0) + (a * (a * ((1.0 + cos((pi * (angle * 0.011111111111111112)))) / 2.0))); end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * N[(a * N[(N[(1.0 + N[Cos[N[(Pi * N[(angle * 0.011111111111111112), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + a \cdot \left(a \cdot \frac{1 + \cos \left(\pi \cdot \left(angle \cdot 0.011111111111111112\right)\right)}{2}\right)
\end{array}
Initial program 75.9%
add-cbrt-cube75.8%
pow375.8%
Applied egg-rr75.8%
unpow-prod-down75.8%
rem-cbrt-cube75.9%
div-inv75.8%
metadata-eval75.8%
pow275.8%
associate-*l*75.8%
Applied egg-rr75.8%
unpow275.8%
cos-mult75.8%
Applied egg-rr75.8%
+-commutative75.8%
+-inverses75.8%
cos-075.8%
distribute-lft-out75.8%
distribute-lft-out75.8%
metadata-eval75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* 0.005555555555555556 (* PI angle)))) (if (<= a 3.75e-118) (pow (* b (sin t_0)) 2.0) (pow (* a (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (((double) M_PI) * angle);
double tmp;
if (a <= 3.75e-118) {
tmp = pow((b * sin(t_0)), 2.0);
} else {
tmp = pow((a * cos(t_0)), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (Math.PI * angle);
double tmp;
if (a <= 3.75e-118) {
tmp = Math.pow((b * Math.sin(t_0)), 2.0);
} else {
tmp = Math.pow((a * Math.cos(t_0)), 2.0);
}
return tmp;
}
def code(a, b, angle): t_0 = 0.005555555555555556 * (math.pi * angle) tmp = 0 if a <= 3.75e-118: tmp = math.pow((b * math.sin(t_0)), 2.0) else: tmp = math.pow((a * math.cos(t_0)), 2.0) return tmp
function code(a, b, angle) t_0 = Float64(0.005555555555555556 * Float64(pi * angle)) tmp = 0.0 if (a <= 3.75e-118) tmp = Float64(b * sin(t_0)) ^ 2.0; else tmp = Float64(a * cos(t_0)) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) t_0 = 0.005555555555555556 * (pi * angle); tmp = 0.0; if (a <= 3.75e-118) tmp = (b * sin(t_0)) ^ 2.0; else tmp = (a * cos(t_0)) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 3.75e-118], N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(\pi \cdot angle\right)\\
\mathbf{if}\;a \leq 3.75 \cdot 10^{-118}:\\
\;\;\;\;{\left(b \cdot \sin t\_0\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\
\end{array}
\end{array}
if a < 3.74999999999999989e-118Initial program 75.1%
Simplified75.0%
expm1-log1p-u62.7%
Applied egg-rr62.7%
Taylor expanded in a around 0 33.5%
unpow233.5%
associate-*r*33.5%
*-commutative33.5%
*-commutative33.5%
unpow233.5%
swap-sqr41.5%
unpow241.5%
*-commutative41.5%
*-commutative41.5%
associate-*r*41.5%
Simplified41.5%
if 3.74999999999999989e-118 < a Initial program 77.2%
Simplified77.1%
Taylor expanded in a around inf 64.5%
*-commutative64.5%
*-commutative64.5%
*-commutative64.5%
associate-*r*64.5%
unpow264.5%
unpow264.5%
swap-sqr64.5%
unpow264.5%
associate-*r*64.5%
*-commutative64.5%
*-commutative64.5%
*-commutative64.5%
Simplified64.5%
Final simplification50.2%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* PI (/ angle 180.0)))) 2.0) (* a a)))
double code(double a, double b, double angle) {
return pow((b * sin((((double) M_PI) * (angle / 180.0)))), 2.0) + (a * a);
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin((Math.PI * (angle / 180.0)))), 2.0) + (a * a);
}
def code(a, b, angle): return math.pow((b * math.sin((math.pi * (angle / 180.0)))), 2.0) + (a * a)
function code(a, b, angle) return Float64((Float64(b * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + Float64(a * a)) end
function tmp = code(a, b, angle) tmp = ((b * sin((pi * (angle / 180.0)))) ^ 2.0) + (a * a); end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + a \cdot a
\end{array}
Initial program 75.9%
add-cbrt-cube75.8%
pow375.8%
Applied egg-rr75.8%
unpow-prod-down75.8%
rem-cbrt-cube75.9%
div-inv75.8%
metadata-eval75.8%
pow275.8%
associate-*l*75.8%
Applied egg-rr75.8%
Taylor expanded in angle around 0 75.4%
Final simplification75.4%
(FPCore (a b angle) :precision binary64 (pow (* a (cos (* 0.005555555555555556 (* PI angle)))) 2.0))
double code(double a, double b, double angle) {
return pow((a * cos((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos((0.005555555555555556 * (Math.PI * angle)))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.cos((0.005555555555555556 * (math.pi * angle)))), 2.0)
function code(a, b, angle) return Float64(a * cos(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0 end
function tmp = code(a, b, angle) tmp = (a * cos((0.005555555555555556 * (pi * angle)))) ^ 2.0; end
code[a_, b_, angle_] := N[Power[N[(a * N[Cos[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 75.9%
Simplified75.8%
Taylor expanded in a around inf 56.4%
*-commutative56.4%
*-commutative56.4%
*-commutative56.4%
associate-*r*56.3%
unpow256.3%
unpow256.3%
swap-sqr56.3%
unpow256.3%
associate-*r*56.4%
*-commutative56.4%
*-commutative56.4%
*-commutative56.4%
Simplified56.4%
Final simplification56.4%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 75.9%
Simplified75.8%
Taylor expanded in angle around 0 56.3%
unpow256.3%
Applied egg-rr56.3%
herbie shell --seed 2024114
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))