
(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 7 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 (* (sin (* 0.005555555555555556 (* angle PI))) a) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
return pow((sin((0.005555555555555556 * (angle * ((double) M_PI)))) * a), 2.0) + pow(b, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((Math.sin((0.005555555555555556 * (angle * Math.PI))) * a), 2.0) + Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow((math.sin((0.005555555555555556 * (angle * math.pi))) * a), 2.0) + math.pow(b, 2.0)
function code(a, b, angle) return Float64((Float64(sin(Float64(0.005555555555555556 * Float64(angle * pi))) * a) ^ 2.0) + (b ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((sin((0.005555555555555556 * (angle * pi))) * a) ^ 2.0) + (b ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * a), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right) \cdot a\right)}^{2} + {b}^{2}
\end{array}
Initial program 78.9%
Taylor expanded in angle around 0
Simplified78.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-sin.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6479.0
Simplified79.0%
Final simplification79.0%
(FPCore (a b angle) :precision binary64 (+ (pow b 2.0) (pow (* a (sin (* angle (* 0.005555555555555556 PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(b, 2.0) + pow((a * sin((angle * (0.005555555555555556 * ((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((angle * (0.005555555555555556 * Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(b, 2.0) + math.pow((a * math.sin((angle * (0.005555555555555556 * math.pi)))), 2.0)
function code(a, b, angle) return Float64((b ^ 2.0) + (Float64(a * sin(Float64(angle * Float64(0.005555555555555556 * pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (b ^ 2.0) + ((a * sin((angle * (0.005555555555555556 * pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[b, 2.0], $MachinePrecision] + N[Power[N[(a * N[Sin[N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{b}^{2} + {\left(a \cdot \sin \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 78.9%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6478.9
Simplified78.9%
Taylor expanded in angle around 0
Simplified78.9%
Final simplification78.9%
(FPCore (a b angle) :precision binary64 (if (<= a 3.3e-19) (* b b) (+ (pow b 2.0) (pow (* 0.005555555555555556 (* PI (* angle a))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 3.3e-19) {
tmp = b * b;
} else {
tmp = pow(b, 2.0) + pow((0.005555555555555556 * (((double) M_PI) * (angle * a))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 3.3e-19) {
tmp = b * b;
} else {
tmp = Math.pow(b, 2.0) + Math.pow((0.005555555555555556 * (Math.PI * (angle * a))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 3.3e-19: tmp = b * b else: tmp = math.pow(b, 2.0) + math.pow((0.005555555555555556 * (math.pi * (angle * a))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 3.3e-19) tmp = Float64(b * b); else tmp = Float64((b ^ 2.0) + (Float64(0.005555555555555556 * Float64(pi * Float64(angle * a))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 3.3e-19) tmp = b * b; else tmp = (b ^ 2.0) + ((0.005555555555555556 * (pi * (angle * a))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 3.3e-19], N[(b * b), $MachinePrecision], N[(N[Power[b, 2.0], $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(Pi * N[(angle * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.3 \cdot 10^{-19}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{b}^{2} + {\left(0.005555555555555556 \cdot \left(\pi \cdot \left(angle \cdot a\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 3.2999999999999998e-19Initial program 78.4%
Taylor expanded in angle around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
Simplified53.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.4
Simplified64.4%
if 3.2999999999999998e-19 < a Initial program 80.1%
Taylor expanded in angle around 0
Simplified79.8%
Taylor expanded in angle around 0
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6476.8
Simplified76.8%
Taylor expanded in a around 0
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
*-commutativeN/A
lower-*.f6476.8
Simplified76.8%
Final simplification68.3%
(FPCore (a b angle) :precision binary64 (+ (pow b 2.0) (* angle (* (* angle (* PI PI)) (* (* a a) 3.08641975308642e-5)))))
double code(double a, double b, double angle) {
return pow(b, 2.0) + (angle * ((angle * (((double) M_PI) * ((double) M_PI))) * ((a * a) * 3.08641975308642e-5)));
}
public static double code(double a, double b, double angle) {
return Math.pow(b, 2.0) + (angle * ((angle * (Math.PI * Math.PI)) * ((a * a) * 3.08641975308642e-5)));
}
def code(a, b, angle): return math.pow(b, 2.0) + (angle * ((angle * (math.pi * math.pi)) * ((a * a) * 3.08641975308642e-5)))
function code(a, b, angle) return Float64((b ^ 2.0) + Float64(angle * Float64(Float64(angle * Float64(pi * pi)) * Float64(Float64(a * a) * 3.08641975308642e-5)))) end
function tmp = code(a, b, angle) tmp = (b ^ 2.0) + (angle * ((angle * (pi * pi)) * ((a * a) * 3.08641975308642e-5))); end
code[a_, b_, angle_] := N[(N[Power[b, 2.0], $MachinePrecision] + N[(angle * N[(N[(angle * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] * 3.08641975308642e-5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{b}^{2} + angle \cdot \left(\left(angle \cdot \left(\pi \cdot \pi\right)\right) \cdot \left(\left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}\right)\right)
\end{array}
Initial program 78.9%
Taylor expanded in angle around 0
Simplified78.9%
Taylor expanded in angle around 0
Simplified69.1%
Final simplification69.1%
(FPCore (a b angle)
:precision binary64
(if (<= a 7.2e-40)
(* b b)
(fma
(* angle (* angle (* PI PI)))
(* (* a a) 3.08641975308642e-5)
(* b b))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 7.2e-40) {
tmp = b * b;
} else {
tmp = fma((angle * (angle * (((double) M_PI) * ((double) M_PI)))), ((a * a) * 3.08641975308642e-5), (b * b));
}
return tmp;
}
function code(a, b, angle) tmp = 0.0 if (a <= 7.2e-40) tmp = Float64(b * b); else tmp = fma(Float64(angle * Float64(angle * Float64(pi * pi))), Float64(Float64(a * a) * 3.08641975308642e-5), Float64(b * b)); end return tmp end
code[a_, b_, angle_] := If[LessEqual[a, 7.2e-40], N[(b * b), $MachinePrecision], N[(N[(angle * N[(angle * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] * 3.08641975308642e-5), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7.2 \cdot 10^{-40}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(angle \cdot \left(angle \cdot \left(\pi \cdot \pi\right)\right), \left(a \cdot a\right) \cdot 3.08641975308642 \cdot 10^{-5}, b \cdot b\right)\\
\end{array}
\end{array}
if a < 7.2e-40Initial program 78.6%
Taylor expanded in angle around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
Simplified53.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6464.5
Simplified64.5%
if 7.2e-40 < a Initial program 79.6%
Taylor expanded in angle around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
Simplified33.7%
Taylor expanded in angle around 0
Simplified38.5%
Taylor expanded in a around inf
lower-*.f64N/A
unpow2N/A
lower-*.f6460.2
Simplified60.2%
Final simplification63.1%
(FPCore (a b angle) :precision binary64 (if (<= a 2.3e+153) (* b b) (* (* angle angle) (* (* a a) (* 3.08641975308642e-5 (* PI PI))))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.3e+153) {
tmp = b * b;
} else {
tmp = (angle * angle) * ((a * a) * (3.08641975308642e-5 * (((double) M_PI) * ((double) M_PI))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.3e+153) {
tmp = b * b;
} else {
tmp = (angle * angle) * ((a * a) * (3.08641975308642e-5 * (Math.PI * Math.PI)));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 2.3e+153: tmp = b * b else: tmp = (angle * angle) * ((a * a) * (3.08641975308642e-5 * (math.pi * math.pi))) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 2.3e+153) tmp = Float64(b * b); else tmp = Float64(Float64(angle * angle) * Float64(Float64(a * a) * Float64(3.08641975308642e-5 * Float64(pi * pi)))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 2.3e+153) tmp = b * b; else tmp = (angle * angle) * ((a * a) * (3.08641975308642e-5 * (pi * pi))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 2.3e+153], N[(b * b), $MachinePrecision], N[(N[(angle * angle), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] * N[(3.08641975308642e-5 * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.3 \cdot 10^{+153}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(angle \cdot angle\right) \cdot \left(\left(a \cdot a\right) \cdot \left(3.08641975308642 \cdot 10^{-5} \cdot \left(\pi \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if a < 2.3000000000000001e153Initial program 75.6%
Taylor expanded in angle around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
Simplified51.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.8
Simplified60.8%
if 2.3000000000000001e153 < a Initial program 97.6%
Taylor expanded in angle around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
Simplified21.5%
Taylor expanded in angle around 0
Simplified55.3%
Taylor expanded in a around inf
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-PI.f6470.7
Simplified70.7%
Final simplification62.3%
(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 78.9%
Taylor expanded in angle around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
Simplified46.8%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.3
Simplified54.3%
herbie shell --seed 2024215
(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)))