
(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 5 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 79.5%
associate-*l/79.5%
associate-*r/79.6%
associate-*l/79.7%
associate-*r/79.7%
Simplified79.7%
Taylor expanded in angle around 0 80.0%
Final simplification80.0%
(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 79.5%
associate-*l/79.5%
associate-*r/79.6%
associate-*l/79.7%
associate-*r/79.7%
Simplified79.7%
Taylor expanded in angle around 0 80.0%
Taylor expanded in angle around inf 79.9%
Final simplification79.9%
(FPCore (a b angle) :precision binary64 (if (<= a 2.8e-35) (* b b) (pow (hypot b (* 0.005555555555555556 (* a (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.8e-35) {
tmp = b * b;
} else {
tmp = pow(hypot(b, (0.005555555555555556 * (a * (angle * ((double) M_PI))))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.8e-35) {
tmp = b * b;
} else {
tmp = Math.pow(Math.hypot(b, (0.005555555555555556 * (a * (angle * Math.PI)))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 2.8e-35: tmp = b * b else: tmp = math.pow(math.hypot(b, (0.005555555555555556 * (a * (angle * math.pi)))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 2.8e-35) tmp = Float64(b * b); else tmp = hypot(b, Float64(0.005555555555555556 * Float64(a * Float64(angle * pi)))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 2.8e-35) tmp = b * b; else tmp = hypot(b, (0.005555555555555556 * (a * (angle * pi)))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 2.8e-35], N[(b * b), $MachinePrecision], N[Power[N[Sqrt[b ^ 2 + N[(0.005555555555555556 * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.8 \cdot 10^{-35}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(b, 0.005555555555555556 \cdot \left(a \cdot \left(angle \cdot \pi\right)\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 2.8e-35Initial program 75.9%
associate-*l/75.9%
associate-*r/76.0%
associate-*l/76.0%
associate-*r/76.1%
Simplified76.1%
Taylor expanded in angle around 0 76.4%
Taylor expanded in angle around 0 67.1%
*-commutative67.1%
unpow-prod-down67.2%
*-commutative67.2%
*-commutative67.2%
associate-*l*67.2%
metadata-eval67.2%
Applied egg-rr67.2%
Taylor expanded in a around 0 61.6%
unpow261.6%
Simplified61.6%
if 2.8e-35 < a Initial program 88.4%
associate-*l/88.6%
associate-*r/88.7%
associate-*l/88.7%
associate-*r/88.7%
Simplified88.7%
Taylor expanded in angle around 0 88.8%
Taylor expanded in angle around 0 85.7%
*-commutative85.7%
unpow-prod-down85.7%
*-commutative85.7%
*-commutative85.7%
associate-*l*85.7%
metadata-eval85.7%
Applied egg-rr85.7%
expm1-log1p-u84.3%
expm1-udef76.0%
Applied egg-rr76.0%
expm1-def84.3%
expm1-log1p85.7%
*-commutative85.7%
associate-*l*85.7%
Simplified85.7%
Final simplification68.5%
(FPCore (a b angle)
:precision binary64
(if (<= a 2.5e-35)
(* b b)
(+
(* b b)
(* 3.08641975308642e-5 (* (* (* a a) (pow PI 2.0)) (* angle angle))))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.5e-35) {
tmp = b * b;
} else {
tmp = (b * b) + (3.08641975308642e-5 * (((a * a) * pow(((double) M_PI), 2.0)) * (angle * angle)));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.5e-35) {
tmp = b * b;
} else {
tmp = (b * b) + (3.08641975308642e-5 * (((a * a) * Math.pow(Math.PI, 2.0)) * (angle * angle)));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 2.5e-35: tmp = b * b else: tmp = (b * b) + (3.08641975308642e-5 * (((a * a) * math.pow(math.pi, 2.0)) * (angle * angle))) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 2.5e-35) tmp = Float64(b * b); else tmp = Float64(Float64(b * b) + Float64(3.08641975308642e-5 * Float64(Float64(Float64(a * a) * (pi ^ 2.0)) * Float64(angle * angle)))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 2.5e-35) tmp = b * b; else tmp = (b * b) + (3.08641975308642e-5 * (((a * a) * (pi ^ 2.0)) * (angle * angle))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 2.5e-35], N[(b * b), $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[(3.08641975308642e-5 * N[(N[(N[(a * a), $MachinePrecision] * N[Power[Pi, 2.0], $MachinePrecision]), $MachinePrecision] * N[(angle * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.5 \cdot 10^{-35}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + 3.08641975308642 \cdot 10^{-5} \cdot \left(\left(\left(a \cdot a\right) \cdot {\pi}^{2}\right) \cdot \left(angle \cdot angle\right)\right)\\
\end{array}
\end{array}
if a < 2.49999999999999982e-35Initial program 75.9%
associate-*l/75.9%
associate-*r/76.0%
associate-*l/76.0%
associate-*r/76.1%
Simplified76.1%
Taylor expanded in angle around 0 76.4%
Taylor expanded in angle around 0 67.1%
*-commutative67.1%
unpow-prod-down67.2%
*-commutative67.2%
*-commutative67.2%
associate-*l*67.2%
metadata-eval67.2%
Applied egg-rr67.2%
Taylor expanded in a around 0 61.6%
unpow261.6%
Simplified61.6%
if 2.49999999999999982e-35 < a Initial program 88.4%
associate-*l/88.6%
associate-*r/88.7%
associate-*l/88.7%
associate-*r/88.7%
Simplified88.7%
Taylor expanded in angle around 0 88.8%
Taylor expanded in angle around 0 85.7%
*-commutative85.7%
unpow-prod-down85.7%
*-commutative85.7%
*-commutative85.7%
associate-*l*85.7%
metadata-eval85.7%
Applied egg-rr85.7%
Taylor expanded in a around 0 69.6%
unpow269.6%
+-commutative69.6%
unpow269.6%
associate-*r*69.6%
Simplified69.6%
Final simplification63.9%
(FPCore (a b angle) :precision binary64 (* b b))
double code(double a, double b, double angle) {
return b * b;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b * b
end function
public static double code(double a, double b, double angle) {
return b * b;
}
def code(a, b, angle): return b * b
function code(a, b, angle) return Float64(b * b) end
function tmp = code(a, b, angle) tmp = b * b; end
code[a_, b_, angle_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b
\end{array}
Initial program 79.5%
associate-*l/79.5%
associate-*r/79.6%
associate-*l/79.7%
associate-*r/79.7%
Simplified79.7%
Taylor expanded in angle around 0 80.0%
Taylor expanded in angle around 0 72.4%
*-commutative72.4%
unpow-prod-down72.4%
*-commutative72.4%
*-commutative72.4%
associate-*l*72.4%
metadata-eval72.4%
Applied egg-rr72.4%
Taylor expanded in a around 0 57.0%
unpow257.0%
Simplified57.0%
Final simplification57.0%
herbie shell --seed 2023208
(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)))