
(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 5 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 (hypot a (* b (sin (* angle (/ PI 180.0))))) 2.0))
double code(double a, double b, double angle) {
return pow(hypot(a, (b * sin((angle * (((double) M_PI) / 180.0))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(Math.hypot(a, (b * Math.sin((angle * (Math.PI / 180.0))))), 2.0);
}
def code(a, b, angle): return math.pow(math.hypot(a, (b * math.sin((angle * (math.pi / 180.0))))), 2.0)
function code(a, b, angle) return hypot(a, Float64(b * sin(Float64(angle * Float64(pi / 180.0))))) ^ 2.0 end
function tmp = code(a, b, angle) tmp = hypot(a, (b * sin((angle * (pi / 180.0))))) ^ 2.0; end
code[a_, b_, angle_] := N[Power[N[Sqrt[a ^ 2 + N[(b * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)\right)}^{2}
\end{array}
Initial program 74.1%
associate-*r/74.2%
metadata-eval74.2%
metadata-eval74.2%
distribute-neg-frac274.2%
distribute-frac-neg74.2%
distribute-rgt-neg-out74.2%
associate-/l*74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.2%
metadata-eval74.2%
metadata-eval74.2%
Simplified74.2%
Taylor expanded in angle around 0 74.6%
*-un-lft-identity74.6%
*-commutative74.6%
Applied egg-rr74.6%
*-rgt-identity74.6%
associate-*r/74.7%
*-commutative74.7%
associate-/l*74.7%
Simplified74.7%
(FPCore (a b angle) :precision binary64 (if (<= a 1.16e-153) (pow (* b (sin (* 0.005555555555555556 (* angle PI)))) 2.0) (pow (hypot a (* 0.005555555555555556 (* angle (* b PI)))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.16e-153) {
tmp = pow((b * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
} else {
tmp = pow(hypot(a, (0.005555555555555556 * (angle * (b * ((double) M_PI))))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.16e-153) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
} else {
tmp = Math.pow(Math.hypot(a, (0.005555555555555556 * (angle * (b * Math.PI)))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.16e-153: tmp = math.pow((b * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) else: tmp = math.pow(math.hypot(a, (0.005555555555555556 * (angle * (b * math.pi)))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.16e-153) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; else tmp = hypot(a, 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 (a <= 1.16e-153) tmp = (b * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0; else tmp = hypot(a, (0.005555555555555556 * (angle * (b * pi)))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.16e-153], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[N[Sqrt[a ^ 2 + N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.16 \cdot 10^{-153}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, 0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.16e-153Initial program 73.9%
associate-*r/73.9%
metadata-eval73.9%
metadata-eval73.9%
distribute-neg-frac273.9%
distribute-frac-neg73.9%
distribute-rgt-neg-out73.9%
associate-/l*73.9%
neg-mul-173.9%
*-commutative73.9%
associate-/l*73.9%
metadata-eval73.9%
metadata-eval73.9%
Simplified73.8%
Taylor expanded in a around 0 37.5%
unpow237.5%
*-commutative37.5%
unpow237.5%
swap-sqr46.1%
unpow246.1%
*-commutative46.1%
Simplified46.1%
if 1.16e-153 < a Initial program 74.6%
associate-*r/74.6%
metadata-eval74.6%
metadata-eval74.6%
distribute-neg-frac274.6%
distribute-frac-neg74.6%
distribute-rgt-neg-out74.6%
associate-/l*74.6%
neg-mul-174.6%
*-commutative74.6%
associate-/l*74.7%
metadata-eval74.7%
metadata-eval74.7%
Simplified74.7%
Taylor expanded in angle around 0 75.0%
*-un-lft-identity75.0%
*-commutative75.0%
Applied egg-rr75.0%
*-rgt-identity75.0%
associate-*r/75.0%
*-commutative75.0%
associate-/l*75.0%
Simplified75.0%
Taylor expanded in angle around 0 71.9%
(FPCore (a b angle) :precision binary64 (if (<= b 7e+112) (* a a) (pow (* b (sin (* 0.005555555555555556 (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 7e+112) {
tmp = a * a;
} else {
tmp = pow((b * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 7e+112) {
tmp = a * a;
} else {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 7e+112: tmp = a * a else: tmp = math.pow((b * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 7e+112) tmp = Float64(a * a); else tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 7e+112) tmp = a * a; else tmp = (b * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 7e+112], N[(a * a), $MachinePrecision], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+112}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 6.99999999999999994e112Initial program 70.7%
associate-*r/70.7%
metadata-eval70.7%
metadata-eval70.7%
distribute-neg-frac270.7%
distribute-frac-neg70.7%
distribute-rgt-neg-out70.7%
associate-/l*70.7%
neg-mul-170.7%
*-commutative70.7%
associate-/l*70.7%
metadata-eval70.7%
metadata-eval70.7%
Simplified70.7%
Taylor expanded in angle around 0 55.5%
unpow271.2%
Applied egg-rr55.5%
if 6.99999999999999994e112 < b Initial program 91.8%
associate-*r/91.8%
metadata-eval91.8%
metadata-eval91.8%
distribute-neg-frac291.8%
distribute-frac-neg91.8%
distribute-rgt-neg-out91.8%
associate-/l*91.8%
neg-mul-191.8%
*-commutative91.8%
associate-/l*91.8%
metadata-eval91.8%
metadata-eval91.8%
Simplified91.8%
Taylor expanded in a around 0 60.0%
unpow260.0%
*-commutative60.0%
unpow260.0%
swap-sqr78.3%
unpow278.3%
*-commutative78.3%
Simplified78.3%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $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 \cdot a + {\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 74.1%
associate-*r/74.2%
metadata-eval74.2%
metadata-eval74.2%
distribute-neg-frac274.2%
distribute-frac-neg74.2%
distribute-rgt-neg-out74.2%
associate-/l*74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.2%
metadata-eval74.2%
metadata-eval74.2%
Simplified74.2%
Taylor expanded in angle around 0 74.6%
unpow274.6%
Applied egg-rr74.6%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 74.1%
associate-*r/74.2%
metadata-eval74.2%
metadata-eval74.2%
distribute-neg-frac274.2%
distribute-frac-neg74.2%
distribute-rgt-neg-out74.2%
associate-/l*74.1%
neg-mul-174.1%
*-commutative74.1%
associate-/l*74.2%
metadata-eval74.2%
metadata-eval74.2%
Simplified74.2%
Taylor expanded in angle around 0 51.0%
unpow274.6%
Applied egg-rr51.0%
herbie shell --seed 2024163
(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)))