
(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 7 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 2.0) (pow (* b (sin (/ 1.0 (/ (/ 180.0 angle) PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((1.0 / ((180.0 / 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((1.0 / ((180.0 / angle) / Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((1.0 / ((180.0 / angle) / math.pi)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(1.0 / Float64(Float64(180.0 / angle) / pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((1.0 / ((180.0 / angle) / pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(1.0 / N[(N[(180.0 / angle), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(\frac{1}{\frac{\frac{180}{angle}}{\pi}}\right)\right)}^{2}
\end{array}
Initial program 77.2%
Taylor expanded in angle around 0 77.5%
associate-*r/77.5%
clear-num77.5%
*-commutative77.5%
associate-/r*77.6%
Applied egg-rr77.6%
Final simplification77.6%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 77.2%
Simplified77.1%
Taylor expanded in b around 0 66.2%
Taylor expanded in angle around 0 66.6%
add-sqr-sqrt66.6%
unpow266.6%
Applied egg-rr77.5%
Final simplification77.5%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (/ angle (/ 180.0 PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 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, 2.0) + Math.pow((b * Math.sin((angle / (180.0 / Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((angle / (180.0 / math.pi)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(angle / Float64(180.0 / pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((angle / (180.0 / pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(angle / N[(180.0 / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(\frac{angle}{\frac{180}{\pi}}\right)\right)}^{2}
\end{array}
Initial program 77.2%
Taylor expanded in angle around 0 77.5%
associate-*r/77.5%
*-commutative77.5%
associate-/l*77.5%
Applied egg-rr77.5%
Final simplification77.5%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (/ PI (/ 180.0 angle)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((((double) M_PI) / (180.0 / angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((Math.PI / (180.0 / angle)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((math.pi / (180.0 / angle)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(pi / Float64(180.0 / angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((pi / (180.0 / angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi / N[(180.0 / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(\frac{\pi}{\frac{180}{angle}}\right)\right)}^{2}
\end{array}
Initial program 77.2%
Taylor expanded in angle around 0 77.5%
clear-num77.5%
un-div-inv77.6%
Applied egg-rr77.6%
Final simplification77.6%
(FPCore (a b angle) :precision binary64 (if (<= b 1.4e-78) (pow a 2.0) (+ (pow a 2.0) (pow (* 0.005555555555555556 (* angle (* b PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 1.4e-78) {
tmp = pow(a, 2.0);
} else {
tmp = pow(a, 2.0) + pow((0.005555555555555556 * (angle * (b * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 1.4e-78) {
tmp = Math.pow(a, 2.0);
} else {
tmp = Math.pow(a, 2.0) + Math.pow((0.005555555555555556 * (angle * (b * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 1.4e-78: tmp = math.pow(a, 2.0) else: tmp = math.pow(a, 2.0) + math.pow((0.005555555555555556 * (angle * (b * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 1.4e-78) tmp = a ^ 2.0; else tmp = Float64((a ^ 2.0) + (Float64(0.005555555555555556 * Float64(angle * Float64(b * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 1.4e-78) tmp = a ^ 2.0; else tmp = (a ^ 2.0) + ((0.005555555555555556 * (angle * (b * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 1.4e-78], N[Power[a, 2.0], $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.4 \cdot 10^{-78}:\\
\;\;\;\;{a}^{2}\\
\mathbf{else}:\\
\;\;\;\;{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 1.40000000000000012e-78Initial program 75.0%
Simplified74.9%
Applied egg-rr45.7%
*-commutative45.7%
associate-/l*45.7%
+-inverses45.7%
div054.9%
Simplified54.9%
Taylor expanded in angle around 0 55.4%
if 1.40000000000000012e-78 < b Initial program 81.6%
Taylor expanded in angle around 0 81.7%
Taylor expanded in angle around 0 78.6%
Final simplification63.1%
(FPCore (a b angle) :precision binary64 (if (<= b 5e-80) (pow a 2.0) (+ (pow a 2.0) (pow (* 0.005555555555555556 (* PI (* b angle))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 5e-80) {
tmp = pow(a, 2.0);
} else {
tmp = pow(a, 2.0) + pow((0.005555555555555556 * (((double) M_PI) * (b * angle))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 5e-80) {
tmp = Math.pow(a, 2.0);
} else {
tmp = Math.pow(a, 2.0) + Math.pow((0.005555555555555556 * (Math.PI * (b * angle))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 5e-80: tmp = math.pow(a, 2.0) else: tmp = math.pow(a, 2.0) + math.pow((0.005555555555555556 * (math.pi * (b * angle))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 5e-80) tmp = a ^ 2.0; else tmp = Float64((a ^ 2.0) + (Float64(0.005555555555555556 * Float64(pi * Float64(b * angle))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 5e-80) tmp = a ^ 2.0; else tmp = (a ^ 2.0) + ((0.005555555555555556 * (pi * (b * angle))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 5e-80], N[Power[a, 2.0], $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(Pi * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-80}:\\
\;\;\;\;{a}^{2}\\
\mathbf{else}:\\
\;\;\;\;{a}^{2} + {\left(0.005555555555555556 \cdot \left(\pi \cdot \left(b \cdot angle\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 5e-80Initial program 75.0%
Simplified74.9%
Applied egg-rr45.7%
*-commutative45.7%
associate-/l*45.7%
+-inverses45.7%
div054.9%
Simplified54.9%
Taylor expanded in angle around 0 55.4%
if 5e-80 < b Initial program 81.6%
Taylor expanded in angle around 0 81.7%
Taylor expanded in angle around 0 78.6%
associate-*r*78.6%
Simplified78.6%
Final simplification63.1%
(FPCore (a b angle) :precision binary64 (pow a 2.0))
double code(double a, double b, double angle) {
return pow(a, 2.0);
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a ** 2.0d0
end function
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0)
function code(a, b, angle) return a ^ 2.0 end
function tmp = code(a, b, angle) tmp = a ^ 2.0; end
code[a_, b_, angle_] := N[Power[a, 2.0], $MachinePrecision]
\begin{array}{l}
\\
{a}^{2}
\end{array}
Initial program 77.2%
Simplified77.1%
Applied egg-rr38.8%
*-commutative38.8%
associate-/l*38.8%
+-inverses38.8%
div053.4%
Simplified53.4%
Taylor expanded in angle around 0 53.8%
Final simplification53.8%
herbie shell --seed 2023305
(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)))