
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180)))) (+ (pow (* a (cos t_0)) 2) (pow (* b (sin t_0)) 2))))
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), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]]
\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}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180)))) (+ (pow (* a (cos t_0)) 2) (pow (* b (sin t_0)) 2))))
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), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]]
\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}
(FPCore (a b angle) :precision binary64 (+ (* (+ 1/2 (* 1/2 (sin (- (* 1/90 (* PI (fabs angle))) (* -1/2 PI))))) (* a a)) (pow (* b (sin (* (* 1/180 PI) (fabs angle)))) 2)))
double code(double a, double b, double angle) {
return ((0.5 + (0.5 * sin(((0.011111111111111112 * (((double) M_PI) * fabs(angle))) - (-0.5 * ((double) M_PI)))))) * (a * a)) + pow((b * sin(((0.005555555555555556 * ((double) M_PI)) * fabs(angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return ((0.5 + (0.5 * Math.sin(((0.011111111111111112 * (Math.PI * Math.abs(angle))) - (-0.5 * Math.PI))))) * (a * a)) + Math.pow((b * Math.sin(((0.005555555555555556 * Math.PI) * Math.abs(angle)))), 2.0);
}
def code(a, b, angle): return ((0.5 + (0.5 * math.sin(((0.011111111111111112 * (math.pi * math.fabs(angle))) - (-0.5 * math.pi))))) * (a * a)) + math.pow((b * math.sin(((0.005555555555555556 * math.pi) * math.fabs(angle)))), 2.0)
function code(a, b, angle) return Float64(Float64(Float64(0.5 + Float64(0.5 * sin(Float64(Float64(0.011111111111111112 * Float64(pi * abs(angle))) - Float64(-0.5 * pi))))) * Float64(a * a)) + (Float64(b * sin(Float64(Float64(0.005555555555555556 * pi) * abs(angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((0.5 + (0.5 * sin(((0.011111111111111112 * (pi * abs(angle))) - (-0.5 * pi))))) * (a * a)) + ((b * sin(((0.005555555555555556 * pi) * abs(angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(N[(1/2 + N[(1/2 * N[Sin[N[(N[(1/90 * N[(Pi * N[Abs[angle], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-1/2 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(1/180 * Pi), $MachinePrecision] * N[Abs[angle], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\frac{1}{90} \cdot \left(\pi \cdot \left|angle\right|\right) - \frac{-1}{2} \cdot \pi\right)\right) \cdot \left(a \cdot a\right) + {\left(b \cdot \sin \left(\left(\frac{1}{180} \cdot \pi\right) \cdot \left|angle\right|\right)\right)}^{2}
Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1%
Applied rewrites80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.2%
Applied rewrites80.2%
Applied rewrites80.2%
lift-cos.f64N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f64N/A
lower-sin.f64N/A
add-flipN/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
distribute-lft-neg-outN/A
Applied rewrites80.1%
(FPCore (a b angle) :precision binary64 (+ (* (- 1 (- 1/2 (* (cos (* 1/90 (* PI angle))) 1/2))) (* a a)) (pow (* b (sin (* (* 1/180 PI) angle))) 2)))
double code(double a, double b, double angle) {
return ((1.0 - (0.5 - (cos((0.011111111111111112 * (((double) M_PI) * angle))) * 0.5))) * (a * a)) + pow((b * sin(((0.005555555555555556 * ((double) M_PI)) * angle))), 2.0);
}
public static double code(double a, double b, double angle) {
return ((1.0 - (0.5 - (Math.cos((0.011111111111111112 * (Math.PI * angle))) * 0.5))) * (a * a)) + Math.pow((b * Math.sin(((0.005555555555555556 * Math.PI) * angle))), 2.0);
}
def code(a, b, angle): return ((1.0 - (0.5 - (math.cos((0.011111111111111112 * (math.pi * angle))) * 0.5))) * (a * a)) + math.pow((b * math.sin(((0.005555555555555556 * math.pi) * angle))), 2.0)
function code(a, b, angle) return Float64(Float64(Float64(1.0 - Float64(0.5 - Float64(cos(Float64(0.011111111111111112 * Float64(pi * angle))) * 0.5))) * Float64(a * a)) + (Float64(b * sin(Float64(Float64(0.005555555555555556 * pi) * angle))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((1.0 - (0.5 - (cos((0.011111111111111112 * (pi * angle))) * 0.5))) * (a * a)) + ((b * sin(((0.005555555555555556 * pi) * angle))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(N[(1 - N[(1/2 - N[(N[Cos[N[(1/90 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(1/180 * Pi), $MachinePrecision] * angle), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]
\left(1 - \left(\frac{1}{2} - \cos \left(\frac{1}{90} \cdot \left(\pi \cdot angle\right)\right) \cdot \frac{1}{2}\right)\right) \cdot \left(a \cdot a\right) + {\left(b \cdot \sin \left(\left(\frac{1}{180} \cdot \pi\right) \cdot angle\right)\right)}^{2}
Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1%
Applied rewrites80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.2%
Applied rewrites80.2%
Applied rewrites80.2%
Applied rewrites80.2%
(FPCore (a b angle) :precision binary64 (+ (* (+ 1/2 1/2) (* a a)) (pow (* b (sin (* (* 1/180 PI) angle))) 2)))
double code(double a, double b, double angle) {
return ((0.5 + 0.5) * (a * a)) + pow((b * sin(((0.005555555555555556 * ((double) M_PI)) * angle))), 2.0);
}
public static double code(double a, double b, double angle) {
return ((0.5 + 0.5) * (a * a)) + Math.pow((b * Math.sin(((0.005555555555555556 * Math.PI) * angle))), 2.0);
}
def code(a, b, angle): return ((0.5 + 0.5) * (a * a)) + math.pow((b * math.sin(((0.005555555555555556 * math.pi) * angle))), 2.0)
function code(a, b, angle) return Float64(Float64(Float64(0.5 + 0.5) * Float64(a * a)) + (Float64(b * sin(Float64(Float64(0.005555555555555556 * pi) * angle))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((0.5 + 0.5) * (a * a)) + ((b * sin(((0.005555555555555556 * pi) * angle))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(N[(1/2 + 1/2), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(1/180 * Pi), $MachinePrecision] * angle), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{2} + \frac{1}{2}\right) \cdot \left(a \cdot a\right) + {\left(b \cdot \sin \left(\left(\frac{1}{180} \cdot \pi\right) \cdot angle\right)\right)}^{2}
Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1%
Applied rewrites80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.2%
Applied rewrites80.2%
Applied rewrites80.2%
Taylor expanded in angle around 0
Applied rewrites80.1%
(FPCore (a b angle)
:precision binary64
(if (<=
(fabs a)
3950954765291961/253266331108459042877954581524118722595974501479640924072000569439126758509088631982403994686712878069348015540240526683495797795130113239006767262824338603946605334680267915264)
(* (* b b) (pow (sin (* 1/180 (* angle PI))) 2))
(+
(* (* (- 1/2 (* 1/2 (cos (* 1/90 (* angle PI))))) b) b)
(* (* (+ 1/2 1/2) (fabs a)) (fabs a)))))double code(double a, double b, double angle) {
double tmp;
if (fabs(a) <= 1.56e-161) {
tmp = (b * b) * pow(sin((0.005555555555555556 * (angle * ((double) M_PI)))), 2.0);
} else {
tmp = (((0.5 - (0.5 * cos((0.011111111111111112 * (angle * ((double) M_PI)))))) * b) * b) + (((0.5 + 0.5) * fabs(a)) * fabs(a));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (Math.abs(a) <= 1.56e-161) {
tmp = (b * b) * Math.pow(Math.sin((0.005555555555555556 * (angle * Math.PI))), 2.0);
} else {
tmp = (((0.5 - (0.5 * Math.cos((0.011111111111111112 * (angle * Math.PI))))) * b) * b) + (((0.5 + 0.5) * Math.abs(a)) * Math.abs(a));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if math.fabs(a) <= 1.56e-161: tmp = (b * b) * math.pow(math.sin((0.005555555555555556 * (angle * math.pi))), 2.0) else: tmp = (((0.5 - (0.5 * math.cos((0.011111111111111112 * (angle * math.pi))))) * b) * b) + (((0.5 + 0.5) * math.fabs(a)) * math.fabs(a)) return tmp
function code(a, b, angle) tmp = 0.0 if (abs(a) <= 1.56e-161) tmp = Float64(Float64(b * b) * (sin(Float64(0.005555555555555556 * Float64(angle * pi))) ^ 2.0)); else tmp = Float64(Float64(Float64(Float64(0.5 - Float64(0.5 * cos(Float64(0.011111111111111112 * Float64(angle * pi))))) * b) * b) + Float64(Float64(Float64(0.5 + 0.5) * abs(a)) * abs(a))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (abs(a) <= 1.56e-161) tmp = (b * b) * (sin((0.005555555555555556 * (angle * pi))) ^ 2.0); else tmp = (((0.5 - (0.5 * cos((0.011111111111111112 * (angle * pi))))) * b) * b) + (((0.5 + 0.5) * abs(a)) * abs(a)); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[N[Abs[a], $MachinePrecision], 3950954765291961/253266331108459042877954581524118722595974501479640924072000569439126758509088631982403994686712878069348015540240526683495797795130113239006767262824338603946605334680267915264], N[(N[(b * b), $MachinePrecision] * N[Power[N[Sin[N[(1/180 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(1/2 - N[(1/2 * N[Cos[N[(1/90 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision] + N[(N[(N[(1/2 + 1/2), $MachinePrecision] * N[Abs[a], $MachinePrecision]), $MachinePrecision] * N[Abs[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|a\right| \leq \frac{3950954765291961}{253266331108459042877954581524118722595974501479640924072000569439126758509088631982403994686712878069348015540240526683495797795130113239006767262824338603946605334680267915264}:\\
\;\;\;\;\left(b \cdot b\right) \cdot {\sin \left(\frac{1}{180} \cdot \left(angle \cdot \pi\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(\frac{1}{90} \cdot \left(angle \cdot \pi\right)\right)\right) \cdot b\right) \cdot b + \left(\left(\frac{1}{2} + \frac{1}{2}\right) \cdot \left|a\right|\right) \cdot \left|a\right|\\
\end{array}
if a < 1.56e-161Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1%
Applied rewrites80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.2%
Applied rewrites80.2%
Taylor expanded in a around 0
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6434.6%
Applied rewrites34.6%
lift-pow.f64N/A
unpow2N/A
lower-*.f6434.6%
Applied rewrites34.6%
if 1.56e-161 < a Initial program 80.1%
Applied rewrites68.7%
Taylor expanded in angle around 0
Applied rewrites57.3%
Taylor expanded in angle around 0
Applied rewrites57.4%
Taylor expanded in angle around inf
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6468.6%
Applied rewrites68.6%
(FPCore (a b angle) :precision binary64 (+ (* (* (- 1/2 (* 1/2 (cos (* 1/90 (* angle PI))))) b) b) (* (* (+ 1/2 1/2) a) a)))
double code(double a, double b, double angle) {
return (((0.5 - (0.5 * cos((0.011111111111111112 * (angle * ((double) M_PI)))))) * b) * b) + (((0.5 + 0.5) * a) * a);
}
public static double code(double a, double b, double angle) {
return (((0.5 - (0.5 * Math.cos((0.011111111111111112 * (angle * Math.PI))))) * b) * b) + (((0.5 + 0.5) * a) * a);
}
def code(a, b, angle): return (((0.5 - (0.5 * math.cos((0.011111111111111112 * (angle * math.pi))))) * b) * b) + (((0.5 + 0.5) * a) * a)
function code(a, b, angle) return Float64(Float64(Float64(Float64(0.5 - Float64(0.5 * cos(Float64(0.011111111111111112 * Float64(angle * pi))))) * b) * b) + Float64(Float64(Float64(0.5 + 0.5) * a) * a)) end
function tmp = code(a, b, angle) tmp = (((0.5 - (0.5 * cos((0.011111111111111112 * (angle * pi))))) * b) * b) + (((0.5 + 0.5) * a) * a); end
code[a_, b_, angle_] := N[(N[(N[(N[(1/2 - N[(1/2 * N[Cos[N[(1/90 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision] + N[(N[(N[(1/2 + 1/2), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]
\left(\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(\frac{1}{90} \cdot \left(angle \cdot \pi\right)\right)\right) \cdot b\right) \cdot b + \left(\left(\frac{1}{2} + \frac{1}{2}\right) \cdot a\right) \cdot a
Initial program 80.1%
Applied rewrites68.7%
Taylor expanded in angle around 0
Applied rewrites57.3%
Taylor expanded in angle around 0
Applied rewrites57.4%
Taylor expanded in angle around inf
lower--.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6468.6%
Applied rewrites68.6%
(FPCore (a b angle)
:precision binary64
(if (<=
(fabs b)
45000000000000001093790020844307659491309099240666167757791051529882576298935378714552136028009316752614990502760270500706746399264931364234169536023864079809685017457168411131102292168329892380638610266183315693802356736)
(+ (* (* (- 1/2 1/2) (fabs b)) (fabs b)) (* (* (+ 1/2 1/2) a) a))
(*
(fabs b)
(+
(* -1/2 (* (fabs b) (cos (* -1/90 (* angle PI)))))
(* 1/2 (fabs b))))))double code(double a, double b, double angle) {
double tmp;
if (fabs(b) <= 4.5e+220) {
tmp = (((0.5 - 0.5) * fabs(b)) * fabs(b)) + (((0.5 + 0.5) * a) * a);
} else {
tmp = fabs(b) * ((-0.5 * (fabs(b) * cos((-0.011111111111111112 * (angle * ((double) M_PI)))))) + (0.5 * fabs(b)));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (Math.abs(b) <= 4.5e+220) {
tmp = (((0.5 - 0.5) * Math.abs(b)) * Math.abs(b)) + (((0.5 + 0.5) * a) * a);
} else {
tmp = Math.abs(b) * ((-0.5 * (Math.abs(b) * Math.cos((-0.011111111111111112 * (angle * Math.PI))))) + (0.5 * Math.abs(b)));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if math.fabs(b) <= 4.5e+220: tmp = (((0.5 - 0.5) * math.fabs(b)) * math.fabs(b)) + (((0.5 + 0.5) * a) * a) else: tmp = math.fabs(b) * ((-0.5 * (math.fabs(b) * math.cos((-0.011111111111111112 * (angle * math.pi))))) + (0.5 * math.fabs(b))) return tmp
function code(a, b, angle) tmp = 0.0 if (abs(b) <= 4.5e+220) tmp = Float64(Float64(Float64(Float64(0.5 - 0.5) * abs(b)) * abs(b)) + Float64(Float64(Float64(0.5 + 0.5) * a) * a)); else tmp = Float64(abs(b) * Float64(Float64(-0.5 * Float64(abs(b) * cos(Float64(-0.011111111111111112 * Float64(angle * pi))))) + Float64(0.5 * abs(b)))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (abs(b) <= 4.5e+220) tmp = (((0.5 - 0.5) * abs(b)) * abs(b)) + (((0.5 + 0.5) * a) * a); else tmp = abs(b) * ((-0.5 * (abs(b) * cos((-0.011111111111111112 * (angle * pi))))) + (0.5 * abs(b))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[N[Abs[b], $MachinePrecision], 45000000000000001093790020844307659491309099240666167757791051529882576298935378714552136028009316752614990502760270500706746399264931364234169536023864079809685017457168411131102292168329892380638610266183315693802356736], N[(N[(N[(N[(1/2 - 1/2), $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1/2 + 1/2), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision], N[(N[Abs[b], $MachinePrecision] * N[(N[(-1/2 * N[(N[Abs[b], $MachinePrecision] * N[Cos[N[(-1/90 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1/2 * N[Abs[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|b\right| \leq 45000000000000001093790020844307659491309099240666167757791051529882576298935378714552136028009316752614990502760270500706746399264931364234169536023864079809685017457168411131102292168329892380638610266183315693802356736:\\
\;\;\;\;\left(\left(\frac{1}{2} - \frac{1}{2}\right) \cdot \left|b\right|\right) \cdot \left|b\right| + \left(\left(\frac{1}{2} + \frac{1}{2}\right) \cdot a\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left|b\right| \cdot \left(\frac{-1}{2} \cdot \left(\left|b\right| \cdot \cos \left(\frac{-1}{90} \cdot \left(angle \cdot \pi\right)\right)\right) + \frac{1}{2} \cdot \left|b\right|\right)\\
\end{array}
if b < 4.5000000000000001e220Initial program 80.1%
Applied rewrites68.7%
Taylor expanded in angle around 0
Applied rewrites57.3%
Taylor expanded in angle around 0
Applied rewrites57.4%
if 4.5000000000000001e220 < b Initial program 80.1%
Applied rewrites68.7%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-inN/A
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval68.6%
lift-cos.f64N/A
cos-neg-revN/A
lower-cos.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval68.6%
Applied rewrites68.6%
Taylor expanded in a around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower-*.f6427.1%
Applied rewrites27.1%
(FPCore (a b angle)
:precision binary64
(if (<=
(fabs b)
45000000000000001093790020844307659491309099240666167757791051529882576298935378714552136028009316752614990502760270500706746399264931364234169536023864079809685017457168411131102292168329892380638610266183315693802356736)
(+ (* (* (- 1/2 1/2) (fabs b)) (fabs b)) (* (* (+ 1/2 1/2) a) a))
(*
(- 1/2 (* (cos (* 1/90 (* PI angle))) 1/2))
(* (fabs b) (fabs b)))))double code(double a, double b, double angle) {
double tmp;
if (fabs(b) <= 4.5e+220) {
tmp = (((0.5 - 0.5) * fabs(b)) * fabs(b)) + (((0.5 + 0.5) * a) * a);
} else {
tmp = (0.5 - (cos((0.011111111111111112 * (((double) M_PI) * angle))) * 0.5)) * (fabs(b) * fabs(b));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (Math.abs(b) <= 4.5e+220) {
tmp = (((0.5 - 0.5) * Math.abs(b)) * Math.abs(b)) + (((0.5 + 0.5) * a) * a);
} else {
tmp = (0.5 - (Math.cos((0.011111111111111112 * (Math.PI * angle))) * 0.5)) * (Math.abs(b) * Math.abs(b));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if math.fabs(b) <= 4.5e+220: tmp = (((0.5 - 0.5) * math.fabs(b)) * math.fabs(b)) + (((0.5 + 0.5) * a) * a) else: tmp = (0.5 - (math.cos((0.011111111111111112 * (math.pi * angle))) * 0.5)) * (math.fabs(b) * math.fabs(b)) return tmp
function code(a, b, angle) tmp = 0.0 if (abs(b) <= 4.5e+220) tmp = Float64(Float64(Float64(Float64(0.5 - 0.5) * abs(b)) * abs(b)) + Float64(Float64(Float64(0.5 + 0.5) * a) * a)); else tmp = Float64(Float64(0.5 - Float64(cos(Float64(0.011111111111111112 * Float64(pi * angle))) * 0.5)) * Float64(abs(b) * abs(b))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (abs(b) <= 4.5e+220) tmp = (((0.5 - 0.5) * abs(b)) * abs(b)) + (((0.5 + 0.5) * a) * a); else tmp = (0.5 - (cos((0.011111111111111112 * (pi * angle))) * 0.5)) * (abs(b) * abs(b)); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[N[Abs[b], $MachinePrecision], 45000000000000001093790020844307659491309099240666167757791051529882576298935378714552136028009316752614990502760270500706746399264931364234169536023864079809685017457168411131102292168329892380638610266183315693802356736], N[(N[(N[(N[(1/2 - 1/2), $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1/2 + 1/2), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision], N[(N[(1/2 - N[(N[Cos[N[(1/90 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision] * N[(N[Abs[b], $MachinePrecision] * N[Abs[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|b\right| \leq 45000000000000001093790020844307659491309099240666167757791051529882576298935378714552136028009316752614990502760270500706746399264931364234169536023864079809685017457168411131102292168329892380638610266183315693802356736:\\
\;\;\;\;\left(\left(\frac{1}{2} - \frac{1}{2}\right) \cdot \left|b\right|\right) \cdot \left|b\right| + \left(\left(\frac{1}{2} + \frac{1}{2}\right) \cdot a\right) \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{2} - \cos \left(\frac{1}{90} \cdot \left(\pi \cdot angle\right)\right) \cdot \frac{1}{2}\right) \cdot \left(\left|b\right| \cdot \left|b\right|\right)\\
\end{array}
if b < 4.5000000000000001e220Initial program 80.1%
Applied rewrites68.7%
Taylor expanded in angle around 0
Applied rewrites57.3%
Taylor expanded in angle around 0
Applied rewrites57.4%
if 4.5000000000000001e220 < b Initial program 80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.1%
Applied rewrites80.1%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
metadata-eval80.2%
Applied rewrites80.2%
Taylor expanded in a around 0
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6434.6%
Applied rewrites34.6%
Applied rewrites26.8%
(FPCore (a b angle) :precision binary64 (+ (* (* (- 1/2 1/2) b) b) (* (* (+ 1/2 1/2) a) a)))
double code(double a, double b, double angle) {
return (((0.5 - 0.5) * b) * b) + (((0.5 + 0.5) * a) * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, angle)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = (((0.5d0 - 0.5d0) * b) * b) + (((0.5d0 + 0.5d0) * a) * a)
end function
public static double code(double a, double b, double angle) {
return (((0.5 - 0.5) * b) * b) + (((0.5 + 0.5) * a) * a);
}
def code(a, b, angle): return (((0.5 - 0.5) * b) * b) + (((0.5 + 0.5) * a) * a)
function code(a, b, angle) return Float64(Float64(Float64(Float64(0.5 - 0.5) * b) * b) + Float64(Float64(Float64(0.5 + 0.5) * a) * a)) end
function tmp = code(a, b, angle) tmp = (((0.5 - 0.5) * b) * b) + (((0.5 + 0.5) * a) * a); end
code[a_, b_, angle_] := N[(N[(N[(N[(1/2 - 1/2), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision] + N[(N[(N[(1/2 + 1/2), $MachinePrecision] * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]
\left(\left(\frac{1}{2} - \frac{1}{2}\right) \cdot b\right) \cdot b + \left(\left(\frac{1}{2} + \frac{1}{2}\right) \cdot a\right) \cdot a
Initial program 80.1%
Applied rewrites68.7%
Taylor expanded in angle around 0
Applied rewrites57.3%
Taylor expanded in angle around 0
Applied rewrites57.4%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* PI (/ angle 180)))) 2) (pow (* b (sin (* PI (/ angle 180)))) 2)))