
(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 11 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 (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (* PI (* 0.005555555555555556 angle)))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * cos((((double) M_PI) * (angle / 180.0)))), 2.0) + pow((b * sin((((double) M_PI) * (0.005555555555555556 * angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos((Math.PI * (angle / 180.0)))), 2.0) + Math.pow((b * Math.sin((Math.PI * (0.005555555555555556 * angle)))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.cos((math.pi * (angle / 180.0)))), 2.0) + math.pow((b * math.sin((math.pi * (0.005555555555555556 * angle)))), 2.0)
function code(a, b, angle) return Float64((Float64(a * cos(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(0.005555555555555556 * angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * cos((pi * (angle / 180.0)))) ^ 2.0) + ((b * sin((pi * (0.005555555555555556 * angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(0.005555555555555556 * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \left(0.005555555555555556 \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 76.7%
Taylor expanded in angle around 0
lower-*.f6476.7
Applied rewrites76.7%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (* (* PI angle) 0.005555555555555556))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * cos((((double) M_PI) * (angle / 180.0)))), 2.0) + pow((b * sin(((((double) M_PI) * angle) * 0.005555555555555556))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos((Math.PI * (angle / 180.0)))), 2.0) + Math.pow((b * Math.sin(((Math.PI * angle) * 0.005555555555555556))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.cos((math.pi * (angle / 180.0)))), 2.0) + math.pow((b * math.sin(((math.pi * angle) * 0.005555555555555556))), 2.0)
function code(a, b, angle) return Float64((Float64(a * cos(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + (Float64(b * sin(Float64(Float64(pi * angle) * 0.005555555555555556))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * cos((pi * (angle / 180.0)))) ^ 2.0) + ((b * sin(((pi * angle) * 0.005555555555555556))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\left(\pi \cdot angle\right) \cdot 0.005555555555555556\right)\right)}^{2}
\end{array}
Initial program 76.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6476.2
Applied rewrites76.2%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (/ (* PI angle) 180.0))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin(((((double) M_PI) * angle) / 180.0))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin(((Math.PI * angle) / 180.0))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin(((math.pi * angle) / 180.0))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(Float64(pi * angle) / 180.0))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin(((pi * angle) / 180.0))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(Pi * angle), $MachinePrecision] / 180.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(\frac{\pi \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 76.7%
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-PI.f6476.2
Applied rewrites76.2%
Applied rewrites27.8%
Applied rewrites19.3%
Taylor expanded in angle around 0
Applied rewrites76.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (fma (* 0.005555555555555556 angle) PI (* 0.5 PI))) a) 2.0) (pow (* (sin (* (* PI angle) 0.005555555555555556)) b) 2.0)))
double code(double a, double b, double angle) {
return pow((sin(fma((0.005555555555555556 * angle), ((double) M_PI), (0.5 * ((double) M_PI)))) * a), 2.0) + pow((sin(((((double) M_PI) * angle) * 0.005555555555555556)) * b), 2.0);
}
function code(a, b, angle) return Float64((Float64(sin(fma(Float64(0.005555555555555556 * angle), pi, Float64(0.5 * pi))) * a) ^ 2.0) + (Float64(sin(Float64(Float64(pi * angle) * 0.005555555555555556)) * b) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(N[Sin[N[(N[(0.005555555555555556 * angle), $MachinePrecision] * Pi + N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * a), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(N[Sin[N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\sin \left(\mathsf{fma}\left(0.005555555555555556 \cdot angle, \pi, 0.5 \cdot \pi\right)\right) \cdot a\right)}^{2} + {\left(\sin \left(\left(\pi \cdot angle\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2}
\end{array}
Initial program 76.7%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
Applied rewrites76.7%
Taylor expanded in angle around 0
Applied rewrites69.0%
Taylor expanded in a around 0
Applied rewrites76.0%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(if (<= a 1.6e-163)
(* (+ (/ (pow (* t_2 a) 2.0) (* b b)) (pow t_1 2.0)) (* b b))
(if (<= a 1.9e+130)
(*
(+
(/ (pow (* t_1 b) 2.0) (* a a))
(pow (fma (sin (fma 0.5 PI (/ PI 2.0))) t_1 t_2) 2.0))
(* a a))
(* a a)))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
double t_1 = sin(t_0);
double t_2 = cos(t_0);
double tmp;
if (a <= 1.6e-163) {
tmp = ((pow((t_2 * a), 2.0) / (b * b)) + pow(t_1, 2.0)) * (b * b);
} else if (a <= 1.9e+130) {
tmp = ((pow((t_1 * b), 2.0) / (a * a)) + pow(fma(sin(fma(0.5, ((double) M_PI), (((double) M_PI) / 2.0))), t_1, t_2), 2.0)) * (a * a);
} else {
tmp = a * a;
}
return tmp;
}
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) t_1 = sin(t_0) t_2 = cos(t_0) tmp = 0.0 if (a <= 1.6e-163) tmp = Float64(Float64(Float64((Float64(t_2 * a) ^ 2.0) / Float64(b * b)) + (t_1 ^ 2.0)) * Float64(b * b)); elseif (a <= 1.9e+130) tmp = Float64(Float64(Float64((Float64(t_1 * b) ^ 2.0) / Float64(a * a)) + (fma(sin(fma(0.5, pi, Float64(pi / 2.0))), t_1, t_2) ^ 2.0)) * Float64(a * a)); else tmp = Float64(a * a); end return tmp end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[t$95$0], $MachinePrecision]}, If[LessEqual[a, 1.6e-163], N[(N[(N[(N[Power[N[(t$95$2 * a), $MachinePrecision], 2.0], $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.9e+130], N[(N[(N[(N[Power[N[(t$95$1 * b), $MachinePrecision], 2.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[Sin[N[(0.5 * Pi + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$1 + t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], N[(a * a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{-163}:\\
\;\;\;\;\left(\frac{{\left(t\_2 \cdot a\right)}^{2}}{b \cdot b} + {t\_1}^{2}\right) \cdot \left(b \cdot b\right)\\
\mathbf{elif}\;a \leq 1.9 \cdot 10^{+130}:\\
\;\;\;\;\left(\frac{{\left(t\_1 \cdot b\right)}^{2}}{a \cdot a} + {\left(\mathsf{fma}\left(\sin \left(\mathsf{fma}\left(0.5, \pi, \frac{\pi}{2}\right)\right), t\_1, t\_2\right)\right)}^{2}\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.59999999999999994e-163Initial program 77.8%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites44.5%
if 1.59999999999999994e-163 < a < 1.9000000000000001e130Initial program 67.4%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
Applied rewrites67.4%
Applied rewrites67.4%
Taylor expanded in a around inf
Applied rewrites63.5%
lift-cos.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
lift-/.f64N/A
lift-PI.f64N/A
lower-fma.f64N/A
lift-PI.f6463.5
Applied rewrites63.5%
if 1.9000000000000001e130 < a Initial program 87.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Final simplification56.6%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(if (<= a 1.6e-163)
(* (+ (/ (pow (* t_2 a) 2.0) (* b b)) (pow t_1 2.0)) (* b b))
(if (<= a 1.9e+130)
(*
(+
(/ (pow (* t_1 b) 2.0) (* a a))
(pow (fma (cos (* 0.5 PI)) t_1 t_2) 2.0))
(* a a))
(* a a)))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
double t_1 = sin(t_0);
double t_2 = cos(t_0);
double tmp;
if (a <= 1.6e-163) {
tmp = ((pow((t_2 * a), 2.0) / (b * b)) + pow(t_1, 2.0)) * (b * b);
} else if (a <= 1.9e+130) {
tmp = ((pow((t_1 * b), 2.0) / (a * a)) + pow(fma(cos((0.5 * ((double) M_PI))), t_1, t_2), 2.0)) * (a * a);
} else {
tmp = a * a;
}
return tmp;
}
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) t_1 = sin(t_0) t_2 = cos(t_0) tmp = 0.0 if (a <= 1.6e-163) tmp = Float64(Float64(Float64((Float64(t_2 * a) ^ 2.0) / Float64(b * b)) + (t_1 ^ 2.0)) * Float64(b * b)); elseif (a <= 1.9e+130) tmp = Float64(Float64(Float64((Float64(t_1 * b) ^ 2.0) / Float64(a * a)) + (fma(cos(Float64(0.5 * pi)), t_1, t_2) ^ 2.0)) * Float64(a * a)); else tmp = Float64(a * a); end return tmp end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[t$95$0], $MachinePrecision]}, If[LessEqual[a, 1.6e-163], N[(N[(N[(N[Power[N[(t$95$2 * a), $MachinePrecision], 2.0], $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.9e+130], N[(N[(N[(N[Power[N[(t$95$1 * b), $MachinePrecision], 2.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[Cos[N[(0.5 * Pi), $MachinePrecision]], $MachinePrecision] * t$95$1 + t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], N[(a * a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{-163}:\\
\;\;\;\;\left(\frac{{\left(t\_2 \cdot a\right)}^{2}}{b \cdot b} + {t\_1}^{2}\right) \cdot \left(b \cdot b\right)\\
\mathbf{elif}\;a \leq 1.9 \cdot 10^{+130}:\\
\;\;\;\;\left(\frac{{\left(t\_1 \cdot b\right)}^{2}}{a \cdot a} + {\left(\mathsf{fma}\left(\cos \left(0.5 \cdot \pi\right), t\_1, t\_2\right)\right)}^{2}\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.59999999999999994e-163Initial program 77.8%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites44.5%
if 1.59999999999999994e-163 < a < 1.9000000000000001e130Initial program 67.4%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
Applied rewrites67.4%
Applied rewrites67.4%
Taylor expanded in a around inf
Applied rewrites63.5%
if 1.9000000000000001e130 < a Initial program 87.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Final simplification56.6%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556))
(t_1 (sin t_0))
(t_2 (cos t_0)))
(if (<= a 1.6e-163)
(* (+ (/ (pow (* t_2 a) 2.0) (* b b)) (pow t_1 2.0)) (* b b))
(if (<= a 1.9e+130)
(* (+ (/ (pow (* t_1 b) 2.0) (* a a)) (pow t_2 2.0)) (* a a))
(* a a)))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
double t_1 = sin(t_0);
double t_2 = cos(t_0);
double tmp;
if (a <= 1.6e-163) {
tmp = ((pow((t_2 * a), 2.0) / (b * b)) + pow(t_1, 2.0)) * (b * b);
} else if (a <= 1.9e+130) {
tmp = ((pow((t_1 * b), 2.0) / (a * a)) + pow(t_2, 2.0)) * (a * a);
} else {
tmp = a * a;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = (Math.PI * angle) * 0.005555555555555556;
double t_1 = Math.sin(t_0);
double t_2 = Math.cos(t_0);
double tmp;
if (a <= 1.6e-163) {
tmp = ((Math.pow((t_2 * a), 2.0) / (b * b)) + Math.pow(t_1, 2.0)) * (b * b);
} else if (a <= 1.9e+130) {
tmp = ((Math.pow((t_1 * b), 2.0) / (a * a)) + Math.pow(t_2, 2.0)) * (a * a);
} else {
tmp = a * a;
}
return tmp;
}
def code(a, b, angle): t_0 = (math.pi * angle) * 0.005555555555555556 t_1 = math.sin(t_0) t_2 = math.cos(t_0) tmp = 0 if a <= 1.6e-163: tmp = ((math.pow((t_2 * a), 2.0) / (b * b)) + math.pow(t_1, 2.0)) * (b * b) elif a <= 1.9e+130: tmp = ((math.pow((t_1 * b), 2.0) / (a * a)) + math.pow(t_2, 2.0)) * (a * a) else: tmp = a * a return tmp
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) t_1 = sin(t_0) t_2 = cos(t_0) tmp = 0.0 if (a <= 1.6e-163) tmp = Float64(Float64(Float64((Float64(t_2 * a) ^ 2.0) / Float64(b * b)) + (t_1 ^ 2.0)) * Float64(b * b)); elseif (a <= 1.9e+130) tmp = Float64(Float64(Float64((Float64(t_1 * b) ^ 2.0) / Float64(a * a)) + (t_2 ^ 2.0)) * Float64(a * a)); else tmp = Float64(a * a); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = (pi * angle) * 0.005555555555555556; t_1 = sin(t_0); t_2 = cos(t_0); tmp = 0.0; if (a <= 1.6e-163) tmp = ((((t_2 * a) ^ 2.0) / (b * b)) + (t_1 ^ 2.0)) * (b * b); elseif (a <= 1.9e+130) tmp = ((((t_1 * b) ^ 2.0) / (a * a)) + (t_2 ^ 2.0)) * (a * a); else tmp = a * a; end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[t$95$0], $MachinePrecision]}, If[LessEqual[a, 1.6e-163], N[(N[(N[(N[Power[N[(t$95$2 * a), $MachinePrecision], 2.0], $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.9e+130], N[(N[(N[(N[Power[N[(t$95$1 * b), $MachinePrecision], 2.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[t$95$2, 2.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], N[(a * a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{-163}:\\
\;\;\;\;\left(\frac{{\left(t\_2 \cdot a\right)}^{2}}{b \cdot b} + {t\_1}^{2}\right) \cdot \left(b \cdot b\right)\\
\mathbf{elif}\;a \leq 1.9 \cdot 10^{+130}:\\
\;\;\;\;\left(\frac{{\left(t\_1 \cdot b\right)}^{2}}{a \cdot a} + {t\_2}^{2}\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.59999999999999994e-163Initial program 77.8%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites44.5%
if 1.59999999999999994e-163 < a < 1.9000000000000001e130Initial program 67.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites63.5%
if 1.9000000000000001e130 < a Initial program 87.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Final simplification56.6%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556)))
(if (<= a 1.6e-163)
(* (+ (/ (pow (* (cos t_0) a) 2.0) (* b b)) (pow (sin t_0) 2.0)) (* b b))
(if (<= a 1.9e+130)
(*
(+
(/
(pow (* (sin (* (* 0.005555555555555556 angle) PI)) b) 2.0)
(* a a))
(pow (sin (fma (* 0.005555555555555556 angle) PI (* 0.5 PI))) 2.0))
(* a a))
(* a a)))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
double tmp;
if (a <= 1.6e-163) {
tmp = ((pow((cos(t_0) * a), 2.0) / (b * b)) + pow(sin(t_0), 2.0)) * (b * b);
} else if (a <= 1.9e+130) {
tmp = ((pow((sin(((0.005555555555555556 * angle) * ((double) M_PI))) * b), 2.0) / (a * a)) + pow(sin(fma((0.005555555555555556 * angle), ((double) M_PI), (0.5 * ((double) M_PI)))), 2.0)) * (a * a);
} else {
tmp = a * a;
}
return tmp;
}
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) tmp = 0.0 if (a <= 1.6e-163) tmp = Float64(Float64(Float64((Float64(cos(t_0) * a) ^ 2.0) / Float64(b * b)) + (sin(t_0) ^ 2.0)) * Float64(b * b)); elseif (a <= 1.9e+130) tmp = Float64(Float64(Float64((Float64(sin(Float64(Float64(0.005555555555555556 * angle) * pi)) * b) ^ 2.0) / Float64(a * a)) + (sin(fma(Float64(0.005555555555555556 * angle), pi, Float64(0.5 * pi))) ^ 2.0)) * Float64(a * a)); else tmp = Float64(a * a); end return tmp end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, If[LessEqual[a, 1.6e-163], N[(N[(N[(N[Power[N[(N[Cos[t$95$0], $MachinePrecision] * a), $MachinePrecision], 2.0], $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.9e+130], N[(N[(N[(N[Power[N[(N[Sin[N[(N[(0.005555555555555556 * angle), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[N[(N[(0.005555555555555556 * angle), $MachinePrecision] * Pi + N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], N[(a * a), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{-163}:\\
\;\;\;\;\left(\frac{{\left(\cos t\_0 \cdot a\right)}^{2}}{b \cdot b} + {\sin t\_0}^{2}\right) \cdot \left(b \cdot b\right)\\
\mathbf{elif}\;a \leq 1.9 \cdot 10^{+130}:\\
\;\;\;\;\left(\frac{{\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \pi\right) \cdot b\right)}^{2}}{a \cdot a} + {\sin \left(\mathsf{fma}\left(0.005555555555555556 \cdot angle, \pi, 0.5 \cdot \pi\right)\right)}^{2}\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.59999999999999994e-163Initial program 77.8%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites44.5%
if 1.59999999999999994e-163 < a < 1.9000000000000001e130Initial program 67.4%
lift-cos.f64N/A
sin-+PI/2-revN/A
sin-sumN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lower-fma.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-sin.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
Applied rewrites67.4%
Taylor expanded in a around inf
Applied rewrites63.6%
if 1.9000000000000001e130 < a Initial program 87.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Final simplification56.6%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (* PI angle) 0.005555555555555556)))
(if (<= b 1.1e-53)
(* a a)
(*
(+ (/ (pow (* (cos t_0) a) 2.0) (* b b)) (pow (sin t_0) 2.0))
(* b b)))))
double code(double a, double b, double angle) {
double t_0 = (((double) M_PI) * angle) * 0.005555555555555556;
double tmp;
if (b <= 1.1e-53) {
tmp = a * a;
} else {
tmp = ((pow((cos(t_0) * a), 2.0) / (b * b)) + pow(sin(t_0), 2.0)) * (b * b);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = (Math.PI * angle) * 0.005555555555555556;
double tmp;
if (b <= 1.1e-53) {
tmp = a * a;
} else {
tmp = ((Math.pow((Math.cos(t_0) * a), 2.0) / (b * b)) + Math.pow(Math.sin(t_0), 2.0)) * (b * b);
}
return tmp;
}
def code(a, b, angle): t_0 = (math.pi * angle) * 0.005555555555555556 tmp = 0 if b <= 1.1e-53: tmp = a * a else: tmp = ((math.pow((math.cos(t_0) * a), 2.0) / (b * b)) + math.pow(math.sin(t_0), 2.0)) * (b * b) return tmp
function code(a, b, angle) t_0 = Float64(Float64(pi * angle) * 0.005555555555555556) tmp = 0.0 if (b <= 1.1e-53) tmp = Float64(a * a); else tmp = Float64(Float64(Float64((Float64(cos(t_0) * a) ^ 2.0) / Float64(b * b)) + (sin(t_0) ^ 2.0)) * Float64(b * b)); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = (pi * angle) * 0.005555555555555556; tmp = 0.0; if (b <= 1.1e-53) tmp = a * a; else tmp = ((((cos(t_0) * a) ^ 2.0) / (b * b)) + (sin(t_0) ^ 2.0)) * (b * b); end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(Pi * angle), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]}, If[LessEqual[b, 1.1e-53], N[(a * a), $MachinePrecision], N[(N[(N[(N[Power[N[(N[Cos[t$95$0], $MachinePrecision] * a), $MachinePrecision], 2.0], $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[N[Sin[t$95$0], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot angle\right) \cdot 0.005555555555555556\\
\mathbf{if}\;b \leq 1.1 \cdot 10^{-53}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{{\left(\cos t\_0 \cdot a\right)}^{2}}{b \cdot b} + {\sin t\_0}^{2}\right) \cdot \left(b \cdot b\right)\\
\end{array}
\end{array}
if b < 1.10000000000000009e-53Initial program 74.9%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.3
Applied rewrites58.3%
if 1.10000000000000009e-53 < b Initial program 81.5%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.8%
Final simplification58.2%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return 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 = 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 76.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.6
Applied rewrites55.6%
Final simplification55.6%
(FPCore (a b angle) :precision binary64 (exp (* (log a) 2.0)))
double code(double a, double b, double angle) {
return exp((log(a) * 2.0));
}
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 = exp((log(a) * 2.0d0))
end function
public static double code(double a, double b, double angle) {
return Math.exp((Math.log(a) * 2.0));
}
def code(a, b, angle): return math.exp((math.log(a) * 2.0))
function code(a, b, angle) return exp(Float64(log(a) * 2.0)) end
function tmp = code(a, b, angle) tmp = exp((log(a) * 2.0)); end
code[a_, b_, angle_] := N[Exp[N[(N[Log[a], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log a \cdot 2}
\end{array}
Initial program 76.7%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.6
Applied rewrites55.6%
lift-*.f64N/A
pow2N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f6428.1
Applied rewrites28.1%
Final simplification28.1%
herbie shell --seed 2025057
(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)))