
(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 6 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 (/ PI 180.0)))) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
return pow((a * sin((angle * (((double) M_PI) / 180.0)))), 2.0) + pow(b, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((angle * (Math.PI / 180.0)))), 2.0) + Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow((a * math.sin((angle * (math.pi / 180.0)))), 2.0) + math.pow(b, 2.0)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0) + (b ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * sin((angle * (pi / 180.0)))) ^ 2.0) + (b ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 76.2%
*-commutative76.2%
associate-*r/75.8%
associate-*l/76.2%
*-commutative76.2%
*-commutative76.2%
associate-*r/75.7%
associate-*l/76.2%
*-commutative76.2%
Simplified76.2%
Taylor expanded in angle around 0 76.8%
Final simplification76.8%
(FPCore (a b angle) :precision binary64 (+ (pow b 2.0) (pow (* a (sin (* 0.005555555555555556 (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(b, 2.0) + pow((a * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(b, 2.0) + Math.pow((a * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(b, 2.0) + math.pow((a * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0)
function code(a, b, angle) return Float64((b ^ 2.0) + (Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (b ^ 2.0) + ((a * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[b, 2.0], $MachinePrecision] + N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{b}^{2} + {\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 76.2%
*-commutative76.2%
associate-*r/75.8%
associate-*l/76.2%
*-commutative76.2%
*-commutative76.2%
associate-*r/75.7%
associate-*l/76.2%
*-commutative76.2%
Simplified76.2%
Taylor expanded in angle around 0 76.8%
Taylor expanded in angle around inf 76.4%
Final simplification76.4%
(FPCore (a b angle)
:precision binary64
(if (<= a 8500000000000.0)
(pow b 2.0)
(+
(pow b 2.0)
(*
0.005555555555555556
(* (* PI (* 0.005555555555555556 (* a angle))) (* a (* angle PI)))))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 8500000000000.0) {
tmp = pow(b, 2.0);
} else {
tmp = pow(b, 2.0) + (0.005555555555555556 * ((((double) M_PI) * (0.005555555555555556 * (a * angle))) * (a * (angle * ((double) M_PI)))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 8500000000000.0) {
tmp = Math.pow(b, 2.0);
} else {
tmp = Math.pow(b, 2.0) + (0.005555555555555556 * ((Math.PI * (0.005555555555555556 * (a * angle))) * (a * (angle * Math.PI))));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 8500000000000.0: tmp = math.pow(b, 2.0) else: tmp = math.pow(b, 2.0) + (0.005555555555555556 * ((math.pi * (0.005555555555555556 * (a * angle))) * (a * (angle * math.pi)))) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 8500000000000.0) tmp = b ^ 2.0; else tmp = Float64((b ^ 2.0) + Float64(0.005555555555555556 * Float64(Float64(pi * Float64(0.005555555555555556 * Float64(a * angle))) * Float64(a * Float64(angle * pi))))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 8500000000000.0) tmp = b ^ 2.0; else tmp = (b ^ 2.0) + (0.005555555555555556 * ((pi * (0.005555555555555556 * (a * angle))) * (a * (angle * pi)))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 8500000000000.0], N[Power[b, 2.0], $MachinePrecision], N[(N[Power[b, 2.0], $MachinePrecision] + N[(0.005555555555555556 * N[(N[(Pi * N[(0.005555555555555556 * N[(a * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 8500000000000:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2} + 0.005555555555555556 \cdot \left(\left(\pi \cdot \left(0.005555555555555556 \cdot \left(a \cdot angle\right)\right)\right) \cdot \left(a \cdot \left(angle \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if a < 8.5e12Initial program 73.9%
*-commutative73.9%
associate-*r/73.4%
associate-*l/73.9%
*-commutative73.9%
*-commutative73.9%
associate-*r/73.3%
associate-*l/73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in angle around 0 74.7%
Taylor expanded in angle around 0 68.8%
*-commutative68.8%
*-commutative68.8%
associate-*l*68.8%
Simplified68.8%
Taylor expanded in angle around 0 57.6%
if 8.5e12 < a Initial program 84.6%
*-commutative84.6%
associate-*r/84.8%
associate-*l/84.8%
*-commutative84.8%
*-commutative84.8%
associate-*r/84.8%
associate-*l/84.8%
*-commutative84.8%
Simplified84.8%
Taylor expanded in angle around 0 84.8%
Taylor expanded in angle around 0 82.4%
*-commutative82.4%
*-commutative82.4%
associate-*l*82.4%
Simplified82.4%
unpow282.4%
*-commutative82.4%
associate-*r*82.5%
*-commutative82.5%
associate-*l*82.4%
*-commutative82.4%
*-commutative82.4%
*-commutative82.4%
associate-*l*82.5%
Applied egg-rr82.5%
Final simplification62.9%
(FPCore (a b angle) :precision binary64 (if (<= a 1300000000000.0) (pow b 2.0) (pow (hypot (* 0.005555555555555556 (* a (* angle PI))) b) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1300000000000.0) {
tmp = pow(b, 2.0);
} else {
tmp = pow(hypot((0.005555555555555556 * (a * (angle * ((double) M_PI)))), b), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1300000000000.0) {
tmp = Math.pow(b, 2.0);
} else {
tmp = Math.pow(Math.hypot((0.005555555555555556 * (a * (angle * Math.PI))), b), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1300000000000.0: tmp = math.pow(b, 2.0) else: tmp = math.pow(math.hypot((0.005555555555555556 * (a * (angle * math.pi))), b), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1300000000000.0) tmp = b ^ 2.0; else tmp = hypot(Float64(0.005555555555555556 * Float64(a * Float64(angle * pi))), b) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1300000000000.0) tmp = b ^ 2.0; else tmp = hypot((0.005555555555555556 * (a * (angle * pi))), b) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1300000000000.0], N[Power[b, 2.0], $MachinePrecision], N[Power[N[Sqrt[N[(0.005555555555555556 * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1300000000000:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(0.005555555555555556 \cdot \left(a \cdot \left(angle \cdot \pi\right)\right), b\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.3e12Initial program 73.9%
*-commutative73.9%
associate-*r/73.4%
associate-*l/73.9%
*-commutative73.9%
*-commutative73.9%
associate-*r/73.3%
associate-*l/73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in angle around 0 74.7%
Taylor expanded in angle around 0 68.8%
*-commutative68.8%
*-commutative68.8%
associate-*l*68.8%
Simplified68.8%
Taylor expanded in angle around 0 57.6%
if 1.3e12 < a Initial program 84.6%
*-commutative84.6%
associate-*r/84.8%
associate-*l/84.8%
*-commutative84.8%
*-commutative84.8%
associate-*r/84.8%
associate-*l/84.8%
*-commutative84.8%
Simplified84.8%
Taylor expanded in angle around 0 84.8%
Taylor expanded in angle around 0 82.4%
*-commutative82.4%
*-commutative82.4%
associate-*l*82.4%
Simplified82.4%
expm1-log1p-u80.4%
expm1-udef75.1%
Applied egg-rr75.1%
expm1-def80.3%
expm1-log1p82.4%
associate-*r*82.5%
*-commutative82.5%
*-commutative82.5%
associate-*r*82.5%
Simplified82.5%
Final simplification62.9%
(FPCore (a b angle) :precision binary64 (if (<= a 1800000000000.0) (pow b 2.0) (pow (hypot (* 0.005555555555555556 (* PI (* a angle))) b) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1800000000000.0) {
tmp = pow(b, 2.0);
} else {
tmp = pow(hypot((0.005555555555555556 * (((double) M_PI) * (a * angle))), b), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1800000000000.0) {
tmp = Math.pow(b, 2.0);
} else {
tmp = Math.pow(Math.hypot((0.005555555555555556 * (Math.PI * (a * angle))), b), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1800000000000.0: tmp = math.pow(b, 2.0) else: tmp = math.pow(math.hypot((0.005555555555555556 * (math.pi * (a * angle))), b), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1800000000000.0) tmp = b ^ 2.0; else tmp = hypot(Float64(0.005555555555555556 * Float64(pi * Float64(a * angle))), b) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1800000000000.0) tmp = b ^ 2.0; else tmp = hypot((0.005555555555555556 * (pi * (a * angle))), b) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1800000000000.0], N[Power[b, 2.0], $MachinePrecision], N[Power[N[Sqrt[N[(0.005555555555555556 * N[(Pi * N[(a * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1800000000000:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(0.005555555555555556 \cdot \left(\pi \cdot \left(a \cdot angle\right)\right), b\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.8e12Initial program 73.9%
*-commutative73.9%
associate-*r/73.4%
associate-*l/73.9%
*-commutative73.9%
*-commutative73.9%
associate-*r/73.3%
associate-*l/73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in angle around 0 74.7%
Taylor expanded in angle around 0 68.8%
*-commutative68.8%
*-commutative68.8%
associate-*l*68.8%
Simplified68.8%
Taylor expanded in angle around 0 57.6%
if 1.8e12 < a Initial program 84.6%
*-commutative84.6%
associate-*r/84.8%
associate-*l/84.8%
*-commutative84.8%
*-commutative84.8%
associate-*r/84.8%
associate-*l/84.8%
*-commutative84.8%
Simplified84.8%
Taylor expanded in angle around 0 84.8%
Taylor expanded in angle around 0 82.4%
*-commutative82.4%
*-commutative82.4%
associate-*l*82.4%
Simplified82.4%
expm1-log1p-u80.4%
expm1-udef75.1%
Applied egg-rr75.1%
expm1-def80.3%
expm1-log1p82.4%
associate-*r*82.5%
Simplified82.5%
Final simplification62.9%
(FPCore (a b angle) :precision binary64 (pow b 2.0))
double code(double a, double b, double angle) {
return pow(b, 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 = b ** 2.0d0
end function
public static double code(double a, double b, double angle) {
return Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow(b, 2.0)
function code(a, b, angle) return b ^ 2.0 end
function tmp = code(a, b, angle) tmp = b ^ 2.0; end
code[a_, b_, angle_] := N[Power[b, 2.0], $MachinePrecision]
\begin{array}{l}
\\
{b}^{2}
\end{array}
Initial program 76.2%
*-commutative76.2%
associate-*r/75.8%
associate-*l/76.2%
*-commutative76.2%
*-commutative76.2%
associate-*r/75.7%
associate-*l/76.2%
*-commutative76.2%
Simplified76.2%
Taylor expanded in angle around 0 76.8%
Taylor expanded in angle around 0 71.7%
*-commutative71.7%
*-commutative71.7%
associate-*l*71.7%
Simplified71.7%
Taylor expanded in angle around 0 54.4%
Final simplification54.4%
herbie shell --seed 2023332
(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)))