
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) PI))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\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 (* (/ angle 180.0) PI))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle)
:precision binary64
(+
(pow (* a (sin (* (/ angle 180.0) PI))) 2.0)
(*
(* b b)
(pow
(sin (* angle (fma 0.5 (/ PI angle) (* -0.005555555555555556 PI))))
2.0))))
double code(double a, double b, double angle) {
return pow((a * sin(((angle / 180.0) * ((double) M_PI)))), 2.0) + ((b * b) * pow(sin((angle * fma(0.5, (((double) M_PI) / angle), (-0.005555555555555556 * ((double) M_PI))))), 2.0));
}
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64(angle / 180.0) * pi))) ^ 2.0) + Float64(Float64(b * b) * (sin(Float64(angle * fma(0.5, Float64(pi / angle), Float64(-0.005555555555555556 * pi)))) ^ 2.0))) end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[Power[N[Sin[N[(angle * N[(0.5 * N[(Pi / angle), $MachinePrecision] + N[(-0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + \left(b \cdot b\right) \cdot {\sin \left(angle \cdot \mathsf{fma}\left(0.5, \frac{\pi}{angle}, -0.005555555555555556 \cdot \pi\right)\right)}^{2}
\end{array}
Initial program 76.5%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6476.4
Applied rewrites76.4%
Taylor expanded in angle around inf
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lift-PI.f6476.5
Applied rewrites76.5%
lift-pow.f64N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-pow.f6476.5
Applied rewrites76.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* 0.005555555555555556 (* angle PI)))) 2.0) (pow (* b (sin (fma 0.5 PI (* -0.005555555555555556 (* angle PI))))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0) + pow((b * sin(fma(0.5, ((double) M_PI), (-0.005555555555555556 * (angle * ((double) M_PI)))))), 2.0);
}
function code(a, b, angle) return Float64((Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0) + (Float64(b * sin(fma(0.5, pi, Float64(-0.005555555555555556 * Float64(angle * pi))))) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(0.5 * Pi + N[(-0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2} + {\left(b \cdot \sin \left(\mathsf{fma}\left(0.5, \pi, -0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)\right)}^{2}
\end{array}
Initial program 76.5%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lower-+.f64N/A
lower-neg.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f6476.4
Applied rewrites76.4%
Taylor expanded in a around 0
lower-+.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
Applied rewrites76.1%
Final simplification76.1%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (* PI angle) 0.005555555555555556))) (+ (pow (* (sin t_0) a) 2.0) (pow (* (sin (fma 0.5 PI t_0)) b) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
return pow((sin(t_0) * a), 2.0) + pow((sin(fma(0.5, ((double) M_PI), t_0)) * b), 2.0);
}
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) return Float64((Float64(sin(t_0) * a) ^ 2.0) + (Float64(sin(fma(0.5, pi, t_0)) * b) ^ 2.0)) end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, N[(N[Power[N[(N[Sin[t$95$0], $MachinePrecision] * a), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(N[Sin[N[(0.5 * Pi + t$95$0), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
{\left(\sin t\_0 \cdot a\right)}^{2} + {\left(\sin \left(\mathsf{fma}\left(0.5, \pi, t\_0\right)\right) \cdot b\right)}^{2}
\end{array}
\end{array}
Initial program 76.5%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
Applied rewrites76.5%
Taylor expanded in a around 0
Applied rewrites76.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556)))
(*
(+ (/ (pow (* (sin (fma 0.5 PI t_0)) b) 2.0) (* a a)) (pow (sin t_0) 2.0))
(* a a))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
return ((pow((sin(fma(0.5, ((double) M_PI), t_0)) * b), 2.0) / (a * a)) + pow(sin(t_0), 2.0)) * (a * a);
}
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) return Float64(Float64(Float64((Float64(sin(fma(0.5, pi, t_0)) * b) ^ 2.0) / Float64(a * a)) + (sin(t_0) ^ 2.0)) * Float64(a * a)) end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, N[(N[(N[(N[Power[N[(N[Sin[N[(0.5 * Pi + t$95$0), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
\left(\frac{{\left(\sin \left(\mathsf{fma}\left(0.5, \pi, t\_0\right)\right) \cdot b\right)}^{2}}{a \cdot a} + {\sin t\_0}^{2}\right) \cdot \left(a \cdot a\right)
\end{array}
\end{array}
Initial program 76.5%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
Applied rewrites76.5%
Taylor expanded in a around inf
Applied rewrites44.7%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556)))
(*
(+
(/ (pow (* (sin (fma 0.5 PI t_0)) b) 2.0) (exp (* (log a) 2.0)))
(pow (sin t_0) 2.0))
(* a a))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
return ((pow((sin(fma(0.5, ((double) M_PI), t_0)) * b), 2.0) / exp((log(a) * 2.0))) + pow(sin(t_0), 2.0)) * (a * a);
}
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) return Float64(Float64(Float64((Float64(sin(fma(0.5, pi, t_0)) * b) ^ 2.0) / exp(Float64(log(a) * 2.0))) + (sin(t_0) ^ 2.0)) * Float64(a * a)) end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, N[(N[(N[(N[Power[N[(N[Sin[N[(0.5 * Pi + t$95$0), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision] / N[Exp[N[(N[Log[a], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
\left(\frac{{\left(\sin \left(\mathsf{fma}\left(0.5, \pi, t\_0\right)\right) \cdot b\right)}^{2}}{e^{\log a \cdot 2}} + {\sin t\_0}^{2}\right) \cdot \left(a \cdot a\right)
\end{array}
\end{array}
Initial program 76.5%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
Applied rewrites76.5%
Taylor expanded in a around inf
Applied rewrites44.7%
lift-*.f64N/A
pow2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6424.3
Applied rewrites24.3%
herbie shell --seed 2025057
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
(+ (pow (* a (sin (* (/ angle 180.0) PI))) 2.0) (pow (* b (cos (* (/ angle 180.0) PI))) 2.0)))