
(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 9 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 (+ (pow (* a (cos (pow (* (cbrt (/ angle 180.0)) (cbrt PI)) 3.0))) 2.0) (pow (* b (sin (* (/ angle 180.0) PI))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * cos(pow((cbrt((angle / 180.0)) * cbrt(((double) M_PI))), 3.0))), 2.0) + pow((b * sin(((angle / 180.0) * ((double) M_PI)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos(Math.pow((Math.cbrt((angle / 180.0)) * Math.cbrt(Math.PI)), 3.0))), 2.0) + Math.pow((b * Math.sin(((angle / 180.0) * Math.PI))), 2.0);
}
function code(a, b, angle) return Float64((Float64(a * cos((Float64(cbrt(Float64(angle / 180.0)) * cbrt(pi)) ^ 3.0))) ^ 2.0) + (Float64(b * sin(Float64(Float64(angle / 180.0) * pi))) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[Power[N[(N[Power[N[(angle / 180.0), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[Pi, 1/3], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left({\left(\sqrt[3]{\frac{angle}{180}} \cdot \sqrt[3]{\pi}\right)}^{3}\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2}
\end{array}
Initial program 81.8%
add-cube-cbrt81.9%
pow381.9%
div-inv81.9%
metadata-eval81.9%
Applied egg-rr81.9%
metadata-eval81.9%
div-inv81.9%
*-commutative81.9%
cbrt-prod82.0%
Applied egg-rr82.0%
Final simplification82.0%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* (/ angle 180.0) PI))) 2.0) (pow (* a (cos (pow (cbrt (* PI (* angle 0.005555555555555556))) 3.0))) 2.0)))
double code(double a, double b, double angle) {
return pow((b * sin(((angle / 180.0) * ((double) M_PI)))), 2.0) + pow((a * cos(pow(cbrt((((double) M_PI) * (angle * 0.005555555555555556))), 3.0))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin(((angle / 180.0) * Math.PI))), 2.0) + Math.pow((a * Math.cos(Math.pow(Math.cbrt((Math.PI * (angle * 0.005555555555555556))), 3.0))), 2.0);
}
function code(a, b, angle) return Float64((Float64(b * sin(Float64(Float64(angle / 180.0) * pi))) ^ 2.0) + (Float64(a * cos((cbrt(Float64(pi * Float64(angle * 0.005555555555555556))) ^ 3.0))) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(a * N[Cos[N[Power[N[Power[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + {\left(a \cdot \cos \left({\left(\sqrt[3]{\pi \cdot \left(angle \cdot 0.005555555555555556\right)}\right)}^{3}\right)\right)}^{2}
\end{array}
Initial program 81.8%
add-cube-cbrt81.9%
pow381.9%
div-inv81.9%
metadata-eval81.9%
Applied egg-rr81.9%
Final simplification81.9%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* 0.005555555555555556 (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Taylor expanded in b around 0 81.5%
Final simplification81.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* (/ angle 180.0) PI))) 2.0) (pow a 2.0)))
double code(double a, double b, double angle) {
return pow((b * sin(((angle / 180.0) * ((double) M_PI)))), 2.0) + pow(a, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin(((angle / 180.0) * Math.PI))), 2.0) + Math.pow(a, 2.0);
}
def code(a, b, angle): return math.pow((b * math.sin(((angle / 180.0) * math.pi))), 2.0) + math.pow(a, 2.0)
function code(a, b, angle) return Float64((Float64(b * sin(Float64(Float64(angle / 180.0) * pi))) ^ 2.0) + (a ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((b * sin(((angle / 180.0) * pi))) ^ 2.0) + (a ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + {a}^{2}
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Final simplification81.9%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (* angle (* PI b)) (* 0.005555555555555556 (* angle (/ b (/ 180.0 PI)))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + ((angle * (((double) M_PI) * b)) * (0.005555555555555556 * (angle * (b / (180.0 / ((double) M_PI))))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + ((angle * (Math.PI * b)) * (0.005555555555555556 * (angle * (b / (180.0 / Math.PI)))));
}
def code(a, b, angle): return math.pow(a, 2.0) + ((angle * (math.pi * b)) * (0.005555555555555556 * (angle * (b / (180.0 / math.pi)))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(Float64(angle * Float64(pi * b)) * Float64(0.005555555555555556 * Float64(angle * Float64(b / Float64(180.0 / pi)))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((angle * (pi * b)) * (0.005555555555555556 * (angle * (b / (180.0 / pi))))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(angle * N[(Pi * b), $MachinePrecision]), $MachinePrecision] * N[(0.005555555555555556 * N[(angle * N[(b / N[(180.0 / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + \left(angle \cdot \left(\pi \cdot b\right)\right) \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \frac{b}{\frac{180}{\pi}}\right)\right)
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Taylor expanded in angle around 0 77.5%
unpow277.5%
associate-*l*77.2%
*-commutative77.2%
associate-*r*77.2%
*-commutative77.2%
metadata-eval77.2%
div-inv77.2%
*-commutative77.2%
associate-*r*77.2%
div-inv77.2%
metadata-eval77.2%
Applied egg-rr77.2%
associate-*r*77.5%
*-commutative77.5%
associate-*r*77.5%
*-commutative77.5%
*-commutative77.5%
*-commutative77.5%
metadata-eval77.5%
associate-/r/77.5%
associate-*r/77.5%
*-rgt-identity77.5%
associate-/r/77.5%
associate-/l*77.5%
associate-/r/77.5%
*-commutative77.5%
*-commutative77.5%
associate-/l*77.5%
Simplified77.5%
Final simplification77.5%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* 3.08641975308642e-5 (pow (* angle (* PI b)) 2.0))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (3.08641975308642e-5 * pow((angle * (((double) M_PI) * b)), 2.0));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (3.08641975308642e-5 * Math.pow((angle * (Math.PI * b)), 2.0));
}
def code(a, b, angle): return math.pow(a, 2.0) + (3.08641975308642e-5 * math.pow((angle * (math.pi * b)), 2.0))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(3.08641975308642e-5 * (Float64(angle * Float64(pi * b)) ^ 2.0))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (3.08641975308642e-5 * ((angle * (pi * b)) ^ 2.0)); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(3.08641975308642e-5 * N[Power[N[(angle * N[(Pi * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot {\left(angle \cdot \left(\pi \cdot b\right)\right)}^{2}
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Taylor expanded in angle around 0 77.5%
*-commutative77.5%
unpow-prod-down77.2%
*-commutative77.2%
metadata-eval77.2%
Applied egg-rr77.2%
Final simplification77.2%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (pow (* PI (* angle b)) 2.0) 3.08641975308642e-5)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (pow((((double) M_PI) * (angle * b)), 2.0) * 3.08641975308642e-5);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (Math.pow((Math.PI * (angle * b)), 2.0) * 3.08641975308642e-5);
}
def code(a, b, angle): return math.pow(a, 2.0) + (math.pow((math.pi * (angle * b)), 2.0) * 3.08641975308642e-5)
function code(a, b, angle) return Float64((a ^ 2.0) + Float64((Float64(pi * Float64(angle * b)) ^ 2.0) * 3.08641975308642e-5)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (((pi * (angle * b)) ^ 2.0) * 3.08641975308642e-5); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[Power[N[(Pi * N[(angle * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 3.08641975308642e-5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(\pi \cdot \left(angle \cdot b\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Taylor expanded in angle around 0 77.5%
*-commutative77.5%
unpow-prod-down77.2%
*-commutative77.2%
metadata-eval77.2%
Applied egg-rr77.2%
Taylor expanded in angle around 0 77.2%
associate-*r*77.2%
Simplified77.2%
Final simplification77.2%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* 0.005555555555555556 (* angle (* PI b))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((0.005555555555555556 * (angle * (((double) M_PI) * b))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((0.005555555555555556 * (angle * (Math.PI * b))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((0.005555555555555556 * (angle * (math.pi * b))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(0.005555555555555556 * Float64(angle * Float64(pi * b))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((0.005555555555555556 * (angle * (pi * b))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(Pi * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(\pi \cdot b\right)\right)\right)}^{2}
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Taylor expanded in angle around 0 77.5%
Final simplification77.5%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* angle (/ b (/ 180.0 PI))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((angle * (b / (180.0 / ((double) M_PI)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((angle * (b / (180.0 / Math.PI))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((angle * (b / (180.0 / math.pi))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(angle * Float64(b / Float64(180.0 / pi))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((angle * (b / (180.0 / pi))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(angle * N[(b / N[(180.0 / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(angle \cdot \frac{b}{\frac{180}{\pi}}\right)}^{2}
\end{array}
Initial program 81.8%
Taylor expanded in angle around 0 81.9%
Taylor expanded in angle around 0 77.5%
Taylor expanded in angle around 0 67.9%
associate-*r*67.8%
*-commutative67.8%
unpow267.8%
metadata-eval67.8%
swap-sqr67.8%
*-commutative67.8%
unpow267.8%
unpow267.8%
swap-sqr67.8%
swap-sqr77.5%
associate-*l*77.5%
associate-*l*77.5%
unpow277.5%
Simplified77.5%
Final simplification77.5%
herbie shell --seed 2023224
(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)))