
(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 13 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 (* (* 0.005555555555555556 (sqrt PI)) (/ angle (/ 1.0 (sqrt PI))))))
2.0)
(pow
(*
b
(cos
(*
0.005555555555555556
(* angle (* (sqrt (* PI (sqrt PI))) (sqrt (sqrt PI)))))))
2.0)))
double code(double a, double b, double angle) {
return pow((a * sin(((0.005555555555555556 * sqrt(((double) M_PI))) * (angle / (1.0 / sqrt(((double) M_PI))))))), 2.0) + pow((b * cos((0.005555555555555556 * (angle * (sqrt((((double) M_PI) * sqrt(((double) M_PI)))) * sqrt(sqrt(((double) M_PI)))))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(((0.005555555555555556 * Math.sqrt(Math.PI)) * (angle / (1.0 / Math.sqrt(Math.PI)))))), 2.0) + Math.pow((b * Math.cos((0.005555555555555556 * (angle * (Math.sqrt((Math.PI * Math.sqrt(Math.PI))) * Math.sqrt(Math.sqrt(Math.PI))))))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.sin(((0.005555555555555556 * math.sqrt(math.pi)) * (angle / (1.0 / math.sqrt(math.pi)))))), 2.0) + math.pow((b * math.cos((0.005555555555555556 * (angle * (math.sqrt((math.pi * math.sqrt(math.pi))) * math.sqrt(math.sqrt(math.pi))))))), 2.0)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64(0.005555555555555556 * sqrt(pi)) * Float64(angle / Float64(1.0 / sqrt(pi)))))) ^ 2.0) + (Float64(b * cos(Float64(0.005555555555555556 * Float64(angle * Float64(sqrt(Float64(pi * sqrt(pi))) * sqrt(sqrt(pi))))))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * sin(((0.005555555555555556 * sqrt(pi)) * (angle / (1.0 / sqrt(pi)))))) ^ 2.0) + ((b * cos((0.005555555555555556 * (angle * (sqrt((pi * sqrt(pi))) * sqrt(sqrt(pi))))))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(0.005555555555555556 * N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(angle / N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[N[(0.005555555555555556 * N[(angle * N[(N[Sqrt[N[(Pi * N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Sqrt[Pi], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(0.005555555555555556 \cdot \sqrt{\pi}\right) \cdot \frac{angle}{\frac{1}{\sqrt{\pi}}}\right)\right)}^{2} + {\left(b \cdot \cos \left(0.005555555555555556 \cdot \left(angle \cdot \left(\sqrt{\pi \cdot \sqrt{\pi}} \cdot \sqrt{\sqrt{\pi}}\right)\right)\right)\right)}^{2}
\end{array}
Initial program 76.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval76.9
Applied rewrites76.9%
lift-*.f64N/A
lift-PI.f64N/A
add-cube-cbrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
lift-PI.f64N/A
pow1/3N/A
lift-PI.f64N/A
pow1/3N/A
pow-sqrN/A
lower-pow.f64N/A
metadata-evalN/A
lift-PI.f64N/A
lower-cbrt.f6476.9
Applied rewrites76.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-pow.f64N/A
lift-cbrt.f64N/A
pow1/3N/A
pow-prod-upN/A
metadata-evalN/A
unpow1N/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f64N/A
lift-PI.f64N/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*l*N/A
metadata-evalN/A
div-invN/A
lift-/.f64N/A
Applied rewrites76.9%
rem-square-sqrtN/A
sqrt-unprodN/A
rem-square-sqrtN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
associate-*r*N/A
sqrt-prodN/A
sqrt-unprodN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6476.9
Applied rewrites76.9%
Final simplification76.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* PI (/ angle 180.0)))) 2.0) (pow (* b (cos (* 0.005555555555555556 (* PI angle)))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * sin((((double) M_PI) * (angle / 180.0)))), 2.0) + pow((b * cos((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((Math.PI * (angle / 180.0)))), 2.0) + Math.pow((b * Math.cos((0.005555555555555556 * (Math.PI * angle)))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.sin((math.pi * (angle / 180.0)))), 2.0) + math.pow((b * math.cos((0.005555555555555556 * (math.pi * angle)))), 2.0)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + (Float64(b * cos(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * sin((pi * (angle / 180.0)))) ^ 2.0) + ((b * cos((0.005555555555555556 * (pi * angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \cos \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 79.7%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval79.7
Applied rewrites79.7%
Final simplification79.7%
herbie shell --seed 2024228
(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)))