
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) PI))
(t_1 (cos t_0))
(t_2 (sin t_0))
(t_3
(/
(/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_2) t_1) x-scale)
y-scale))
(t_4
(/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) y-scale) y-scale))
(t_5
(/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) x-scale) x-scale)))
(*
180.0
(/
(atan
(/ (- (- t_4 t_5) (sqrt (+ (pow (- t_5 t_4) 2.0) (pow t_3 2.0)))) t_3))
PI))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (angle / 180.0) * ((double) M_PI);
double t_1 = cos(t_0);
double t_2 = sin(t_0);
double t_3 = ((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale;
double t_4 = ((pow((a * t_1), 2.0) + pow((b * t_2), 2.0)) / y_45_scale) / y_45_scale;
double t_5 = ((pow((a * t_2), 2.0) + pow((b * t_1), 2.0)) / x_45_scale) / x_45_scale;
return 180.0 * (atan((((t_4 - t_5) - sqrt((pow((t_5 - t_4), 2.0) + pow(t_3, 2.0)))) / t_3)) / ((double) M_PI));
}
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (angle / 180.0) * Math.PI;
double t_1 = Math.cos(t_0);
double t_2 = Math.sin(t_0);
double t_3 = ((((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale;
double t_4 = ((Math.pow((a * t_1), 2.0) + Math.pow((b * t_2), 2.0)) / y_45_scale) / y_45_scale;
double t_5 = ((Math.pow((a * t_2), 2.0) + Math.pow((b * t_1), 2.0)) / x_45_scale) / x_45_scale;
return 180.0 * (Math.atan((((t_4 - t_5) - Math.sqrt((Math.pow((t_5 - t_4), 2.0) + Math.pow(t_3, 2.0)))) / t_3)) / Math.PI);
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (angle / 180.0) * math.pi t_1 = math.cos(t_0) t_2 = math.sin(t_0) t_3 = ((((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale t_4 = ((math.pow((a * t_1), 2.0) + math.pow((b * t_2), 2.0)) / y_45_scale) / y_45_scale t_5 = ((math.pow((a * t_2), 2.0) + math.pow((b * t_1), 2.0)) / x_45_scale) / x_45_scale return 180.0 * (math.atan((((t_4 - t_5) - math.sqrt((math.pow((t_5 - t_4), 2.0) + math.pow(t_3, 2.0)))) / t_3)) / math.pi)
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(angle / 180.0) * pi) t_1 = cos(t_0) t_2 = sin(t_0) t_3 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale) t_4 = Float64(Float64(Float64((Float64(a * t_1) ^ 2.0) + (Float64(b * t_2) ^ 2.0)) / y_45_scale) / y_45_scale) t_5 = Float64(Float64(Float64((Float64(a * t_2) ^ 2.0) + (Float64(b * t_1) ^ 2.0)) / x_45_scale) / x_45_scale) return Float64(180.0 * Float64(atan(Float64(Float64(Float64(t_4 - t_5) - sqrt(Float64((Float64(t_5 - t_4) ^ 2.0) + (t_3 ^ 2.0)))) / t_3)) / pi)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (angle / 180.0) * pi; t_1 = cos(t_0); t_2 = sin(t_0); t_3 = ((((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale; t_4 = ((((a * t_1) ^ 2.0) + ((b * t_2) ^ 2.0)) / y_45_scale) / y_45_scale; t_5 = ((((a * t_2) ^ 2.0) + ((b * t_1) ^ 2.0)) / x_45_scale) / x_45_scale; tmp = 180.0 * (atan((((t_4 - t_5) - sqrt((((t_5 - t_4) ^ 2.0) + (t_3 ^ 2.0)))) / t_3)) / pi); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, Block[{t$95$1 = N[Cos[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(2.0 * N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$1), $MachinePrecision] / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[Power[N[(a * t$95$1), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[(N[Power[N[(a * t$95$2), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / x$45$scale), $MachinePrecision] / x$45$scale), $MachinePrecision]}, N[(180.0 * N[(N[ArcTan[N[(N[(N[(t$95$4 - t$95$5), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(t$95$5 - t$95$4), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$3, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_2\right) \cdot t\_1}{x-scale}}{y-scale}\\
t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{y-scale}}{y-scale}\\
t_5 := \frac{\frac{{\left(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{x-scale}}{x-scale}\\
180 \cdot \frac{\tan^{-1} \left(\frac{\left(t\_4 - t\_5\right) - \sqrt{{\left(t\_5 - t\_4\right)}^{2} + {t\_3}^{2}}}{t\_3}\right)}{\pi}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) PI))
(t_1 (cos t_0))
(t_2 (sin t_0))
(t_3
(/
(/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_2) t_1) x-scale)
y-scale))
(t_4
(/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) y-scale) y-scale))
(t_5
(/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) x-scale) x-scale)))
(*
180.0
(/
(atan
(/ (- (- t_4 t_5) (sqrt (+ (pow (- t_5 t_4) 2.0) (pow t_3 2.0)))) t_3))
PI))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (angle / 180.0) * ((double) M_PI);
double t_1 = cos(t_0);
double t_2 = sin(t_0);
double t_3 = ((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale;
double t_4 = ((pow((a * t_1), 2.0) + pow((b * t_2), 2.0)) / y_45_scale) / y_45_scale;
double t_5 = ((pow((a * t_2), 2.0) + pow((b * t_1), 2.0)) / x_45_scale) / x_45_scale;
return 180.0 * (atan((((t_4 - t_5) - sqrt((pow((t_5 - t_4), 2.0) + pow(t_3, 2.0)))) / t_3)) / ((double) M_PI));
}
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (angle / 180.0) * Math.PI;
double t_1 = Math.cos(t_0);
double t_2 = Math.sin(t_0);
double t_3 = ((((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale;
double t_4 = ((Math.pow((a * t_1), 2.0) + Math.pow((b * t_2), 2.0)) / y_45_scale) / y_45_scale;
double t_5 = ((Math.pow((a * t_2), 2.0) + Math.pow((b * t_1), 2.0)) / x_45_scale) / x_45_scale;
return 180.0 * (Math.atan((((t_4 - t_5) - Math.sqrt((Math.pow((t_5 - t_4), 2.0) + Math.pow(t_3, 2.0)))) / t_3)) / Math.PI);
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (angle / 180.0) * math.pi t_1 = math.cos(t_0) t_2 = math.sin(t_0) t_3 = ((((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale t_4 = ((math.pow((a * t_1), 2.0) + math.pow((b * t_2), 2.0)) / y_45_scale) / y_45_scale t_5 = ((math.pow((a * t_2), 2.0) + math.pow((b * t_1), 2.0)) / x_45_scale) / x_45_scale return 180.0 * (math.atan((((t_4 - t_5) - math.sqrt((math.pow((t_5 - t_4), 2.0) + math.pow(t_3, 2.0)))) / t_3)) / math.pi)
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(angle / 180.0) * pi) t_1 = cos(t_0) t_2 = sin(t_0) t_3 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale) t_4 = Float64(Float64(Float64((Float64(a * t_1) ^ 2.0) + (Float64(b * t_2) ^ 2.0)) / y_45_scale) / y_45_scale) t_5 = Float64(Float64(Float64((Float64(a * t_2) ^ 2.0) + (Float64(b * t_1) ^ 2.0)) / x_45_scale) / x_45_scale) return Float64(180.0 * Float64(atan(Float64(Float64(Float64(t_4 - t_5) - sqrt(Float64((Float64(t_5 - t_4) ^ 2.0) + (t_3 ^ 2.0)))) / t_3)) / pi)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (angle / 180.0) * pi; t_1 = cos(t_0); t_2 = sin(t_0); t_3 = ((((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * t_2) * t_1) / x_45_scale) / y_45_scale; t_4 = ((((a * t_1) ^ 2.0) + ((b * t_2) ^ 2.0)) / y_45_scale) / y_45_scale; t_5 = ((((a * t_2) ^ 2.0) + ((b * t_1) ^ 2.0)) / x_45_scale) / x_45_scale; tmp = 180.0 * (atan((((t_4 - t_5) - sqrt((((t_5 - t_4) ^ 2.0) + (t_3 ^ 2.0)))) / t_3)) / pi); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, Block[{t$95$1 = N[Cos[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(2.0 * N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision] * t$95$1), $MachinePrecision] / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[Power[N[(a * t$95$1), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, Block[{t$95$5 = N[(N[(N[(N[Power[N[(a * t$95$2), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / x$45$scale), $MachinePrecision] / x$45$scale), $MachinePrecision]}, N[(180.0 * N[(N[ArcTan[N[(N[(N[(t$95$4 - t$95$5), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(t$95$5 - t$95$4), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$3, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
t_1 := \cos t\_0\\
t_2 := \sin t\_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_2\right) \cdot t\_1}{x-scale}}{y-scale}\\
t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{y-scale}}{y-scale}\\
t_5 := \frac{\frac{{\left(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{x-scale}}{x-scale}\\
180 \cdot \frac{\tan^{-1} \left(\frac{\left(t\_4 - t\_5\right) - \sqrt{{\left(t\_5 - t\_4\right)}^{2} + {t\_3}^{2}}}{t\_3}\right)}{\pi}
\end{array}
\end{array}
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle PI)))
(t_1 (* angle (* 0.005555555555555556 PI)))
(t_2 (cos (* 2.0 t_1))))
(if (<= b_m 1.3e-56)
(* 180.0 (/ (atan (/ (* y-scale (sin t_0)) (* x-scale (cos t_0)))) PI))
(if (<= b_m 1.5e+113)
(/
(*
180.0
(atan
(/
(*
-0.5
(*
(* 2.0 y-scale)
(fma
a
(* a (+ 0.5 (* -0.5 t_2)))
(* (fma 0.5 t_2 0.5) (* b_m b_m)))))
(* x-scale (* (* (cos t_1) (sin t_1)) (* (+ b_m a) (- b_m a)))))))
PI)
(*
180.0
(/
(atan
(/
-1.0
(*
(/ x-scale y-scale)
(tan (* PI (* angle 0.005555555555555556))))))
PI))))))b_m = fabs(b);
double code(double a, double b_m, double angle, double x_45_scale, double y_45_scale) {
double t_0 = 0.005555555555555556 * (angle * ((double) M_PI));
double t_1 = angle * (0.005555555555555556 * ((double) M_PI));
double t_2 = cos((2.0 * t_1));
double tmp;
if (b_m <= 1.3e-56) {
tmp = 180.0 * (atan(((y_45_scale * sin(t_0)) / (x_45_scale * cos(t_0)))) / ((double) M_PI));
} else if (b_m <= 1.5e+113) {
tmp = (180.0 * atan(((-0.5 * ((2.0 * y_45_scale) * fma(a, (a * (0.5 + (-0.5 * t_2))), (fma(0.5, t_2, 0.5) * (b_m * b_m))))) / (x_45_scale * ((cos(t_1) * sin(t_1)) * ((b_m + a) * (b_m - a))))))) / ((double) M_PI);
} else {
tmp = 180.0 * (atan((-1.0 / ((x_45_scale / y_45_scale) * tan((((double) M_PI) * (angle * 0.005555555555555556)))))) / ((double) M_PI));
}
return tmp;
}
b_m = abs(b) function code(a, b_m, angle, x_45_scale, y_45_scale) t_0 = Float64(0.005555555555555556 * Float64(angle * pi)) t_1 = Float64(angle * Float64(0.005555555555555556 * pi)) t_2 = cos(Float64(2.0 * t_1)) tmp = 0.0 if (b_m <= 1.3e-56) tmp = Float64(180.0 * Float64(atan(Float64(Float64(y_45_scale * sin(t_0)) / Float64(x_45_scale * cos(t_0)))) / pi)); elseif (b_m <= 1.5e+113) tmp = Float64(Float64(180.0 * atan(Float64(Float64(-0.5 * Float64(Float64(2.0 * y_45_scale) * fma(a, Float64(a * Float64(0.5 + Float64(-0.5 * t_2))), Float64(fma(0.5, t_2, 0.5) * Float64(b_m * b_m))))) / Float64(x_45_scale * Float64(Float64(cos(t_1) * sin(t_1)) * Float64(Float64(b_m + a) * Float64(b_m - a))))))) / pi); else tmp = Float64(180.0 * Float64(atan(Float64(-1.0 / Float64(Float64(x_45_scale / y_45_scale) * tan(Float64(pi * Float64(angle * 0.005555555555555556)))))) / pi)); end return tmp end
b_m = N[Abs[b], $MachinePrecision]
code[a_, b$95$m_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(2.0 * t$95$1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b$95$m, 1.3e-56], N[(180.0 * N[(N[ArcTan[N[(N[(y$45$scale * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] / N[(x$45$scale * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$m, 1.5e+113], N[(N[(180.0 * N[ArcTan[N[(N[(-0.5 * N[(N[(2.0 * y$45$scale), $MachinePrecision] * N[(a * N[(a * N[(0.5 + N[(-0.5 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * t$95$2 + 0.5), $MachinePrecision] * N[(b$95$m * b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x$45$scale * N[(N[(N[Cos[t$95$1], $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision] * N[(N[(b$95$m + a), $MachinePrecision] * N[(b$95$m - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], N[(180.0 * N[(N[ArcTan[N[(-1.0 / N[(N[(x$45$scale / y$45$scale), $MachinePrecision] * N[Tan[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \pi\right)\\
t_1 := angle \cdot \left(0.005555555555555556 \cdot \pi\right)\\
t_2 := \cos \left(2 \cdot t\_1\right)\\
\mathbf{if}\;b\_m \leq 1.3 \cdot 10^{-56}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale \cdot \sin t\_0}{x-scale \cdot \cos t\_0}\right)}{\pi}\\
\mathbf{elif}\;b\_m \leq 1.5 \cdot 10^{+113}:\\
\;\;\;\;\frac{180 \cdot \tan^{-1} \left(\frac{-0.5 \cdot \left(\left(2 \cdot y-scale\right) \cdot \mathsf{fma}\left(a, a \cdot \left(0.5 + -0.5 \cdot t\_2\right), \mathsf{fma}\left(0.5, t\_2, 0.5\right) \cdot \left(b\_m \cdot b\_m\right)\right)\right)}{x-scale \cdot \left(\left(\cos t\_1 \cdot \sin t\_1\right) \cdot \left(\left(b\_m + a\right) \cdot \left(b\_m - a\right)\right)\right)}\right)}{\pi}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-1}{\frac{x-scale}{y-scale} \cdot \tan \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)}\right)}{\pi}\\
\end{array}
\end{array}
if b < 1.29999999999999998e-56Initial program 28.1%
Taylor expanded in x-scale around 0
associate-*r/N/A
lower-/.f64N/A
Applied rewrites33.7%
Taylor expanded in b around 0
Applied rewrites66.2%
if 1.29999999999999998e-56 < b < 1.5e113Initial program 40.5%
Taylor expanded in x-scale around 0
associate-*r/N/A
lower-/.f64N/A
Applied rewrites65.7%
Applied rewrites74.0%
if 1.5e113 < b Initial program 3.7%
Taylor expanded in x-scale around 0
associate-*r/N/A
lower-/.f64N/A
Applied rewrites8.1%
Taylor expanded in b around inf
Applied rewrites70.3%
Applied rewrites69.4%
Applied rewrites72.7%
Final simplification70.3%
b_m = (fabs.f64 b)
(FPCore (a b_m angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* angle PI)))
(t_1 (* angle (* 0.005555555555555556 PI)))
(t_2 (cos (* 2.0 t_1))))
(if (<= b_m 1.4e-56)
(* 180.0 (/ (atan (/ (* y-scale (sin t_0)) (* x-scale (cos t_0)))) PI))
(if (<= b_m 7.2e+112)
(*
(/ 180.0 (sqrt PI))
(/
(atan
(/
(*
-0.5
(*
(* 2.0 y-scale)
(fma
a
(* a (+ 0.5 (* -0.5 t_2)))
(* (fma 0.5 t_2 0.5) (* b_m b_m)))))
(* x-scale (* (* (+ b_m a) (- b_m a)) (* (sin t_1) 1.0)))))
(sqrt PI)))
(*
180.0
(/
(atan
(/
-1.0
(*
(/ x-scale y-scale)
(tan (* PI (* angle 0.005555555555555556))))))
PI))))))b_m = fabs(b);
double code(double a, double b_m, double angle, double x_45_scale, double y_45_scale) {
double t_0 = 0.005555555555555556 * (angle * ((double) M_PI));
double t_1 = angle * (0.005555555555555556 * ((double) M_PI));
double t_2 = cos((2.0 * t_1));
double tmp;
if (b_m <= 1.4e-56) {
tmp = 180.0 * (atan(((y_45_scale * sin(t_0)) / (x_45_scale * cos(t_0)))) / ((double) M_PI));
} else if (b_m <= 7.2e+112) {
tmp = (180.0 / sqrt(((double) M_PI))) * (atan(((-0.5 * ((2.0 * y_45_scale) * fma(a, (a * (0.5 + (-0.5 * t_2))), (fma(0.5, t_2, 0.5) * (b_m * b_m))))) / (x_45_scale * (((b_m + a) * (b_m - a)) * (sin(t_1) * 1.0))))) / sqrt(((double) M_PI)));
} else {
tmp = 180.0 * (atan((-1.0 / ((x_45_scale / y_45_scale) * tan((((double) M_PI) * (angle * 0.005555555555555556)))))) / ((double) M_PI));
}
return tmp;
}
b_m = abs(b) function code(a, b_m, angle, x_45_scale, y_45_scale) t_0 = Float64(0.005555555555555556 * Float64(angle * pi)) t_1 = Float64(angle * Float64(0.005555555555555556 * pi)) t_2 = cos(Float64(2.0 * t_1)) tmp = 0.0 if (b_m <= 1.4e-56) tmp = Float64(180.0 * Float64(atan(Float64(Float64(y_45_scale * sin(t_0)) / Float64(x_45_scale * cos(t_0)))) / pi)); elseif (b_m <= 7.2e+112) tmp = Float64(Float64(180.0 / sqrt(pi)) * Float64(atan(Float64(Float64(-0.5 * Float64(Float64(2.0 * y_45_scale) * fma(a, Float64(a * Float64(0.5 + Float64(-0.5 * t_2))), Float64(fma(0.5, t_2, 0.5) * Float64(b_m * b_m))))) / Float64(x_45_scale * Float64(Float64(Float64(b_m + a) * Float64(b_m - a)) * Float64(sin(t_1) * 1.0))))) / sqrt(pi))); else tmp = Float64(180.0 * Float64(atan(Float64(-1.0 / Float64(Float64(x_45_scale / y_45_scale) * tan(Float64(pi * Float64(angle * 0.005555555555555556)))))) / pi)); end return tmp end
b_m = N[Abs[b], $MachinePrecision]
code[a_, b$95$m_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(2.0 * t$95$1), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b$95$m, 1.4e-56], N[(180.0 * N[(N[ArcTan[N[(N[(y$45$scale * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] / N[(x$45$scale * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$m, 7.2e+112], N[(N[(180.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(N[ArcTan[N[(N[(-0.5 * N[(N[(2.0 * y$45$scale), $MachinePrecision] * N[(a * N[(a * N[(0.5 + N[(-0.5 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * t$95$2 + 0.5), $MachinePrecision] * N[(b$95$m * b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x$45$scale * N[(N[(N[(b$95$m + a), $MachinePrecision] * N[(b$95$m - a), $MachinePrecision]), $MachinePrecision] * N[(N[Sin[t$95$1], $MachinePrecision] * 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(180.0 * N[(N[ArcTan[N[(-1.0 / N[(N[(x$45$scale / y$45$scale), $MachinePrecision] * N[Tan[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
b_m = \left|b\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \pi\right)\\
t_1 := angle \cdot \left(0.005555555555555556 \cdot \pi\right)\\
t_2 := \cos \left(2 \cdot t\_1\right)\\
\mathbf{if}\;b\_m \leq 1.4 \cdot 10^{-56}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{y-scale \cdot \sin t\_0}{x-scale \cdot \cos t\_0}\right)}{\pi}\\
\mathbf{elif}\;b\_m \leq 7.2 \cdot 10^{+112}:\\
\;\;\;\;\frac{180}{\sqrt{\pi}} \cdot \frac{\tan^{-1} \left(\frac{-0.5 \cdot \left(\left(2 \cdot y-scale\right) \cdot \mathsf{fma}\left(a, a \cdot \left(0.5 + -0.5 \cdot t\_2\right), \mathsf{fma}\left(0.5, t\_2, 0.5\right) \cdot \left(b\_m \cdot b\_m\right)\right)\right)}{x-scale \cdot \left(\left(\left(b\_m + a\right) \cdot \left(b\_m - a\right)\right) \cdot \left(\sin t\_1 \cdot 1\right)\right)}\right)}{\sqrt{\pi}}\\
\mathbf{else}:\\
\;\;\;\;180 \cdot \frac{\tan^{-1} \left(\frac{-1}{\frac{x-scale}{y-scale} \cdot \tan \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)}\right)}{\pi}\\
\end{array}
\end{array}
if b < 1.39999999999999997e-56Initial program 16.9%
Taylor expanded in x-scale around 0
associate-*r/N/A
lower-/.f64N/A
Applied rewrites29.9%
Taylor expanded in b around 0
Applied rewrites59.3%
if 1.39999999999999997e-56 < b < 7.20000000000000001e112Initial program 30.8%
Taylor expanded in x-scale around 0
associate-*r/N/A
lower-/.f64N/A
Applied rewrites48.2%
Applied rewrites52.5%
Taylor expanded in angle around 0
Applied rewrites51.8%
if 7.20000000000000001e112 < b Initial program 6.4%
Taylor expanded in x-scale around 0
associate-*r/N/A
lower-/.f64N/A
Applied rewrites10.9%
Taylor expanded in b around inf
Applied rewrites67.8%
Applied rewrites67.9%
Applied rewrites67.1%
Final simplification59.3%
herbie shell --seed 2024226
(FPCore (a b angle x-scale y-scale)
:name "raw-angle from scale-rotated-ellipse"
:precision binary64
(* 180.0 (/ (atan (/ (- (- (/ (/ (+ (pow (* a (cos (* (/ angle 180.0) PI))) 2.0) (pow (* b (sin (* (/ angle 180.0) PI))) 2.0)) y-scale) y-scale) (/ (/ (+ (pow (* a (sin (* (/ angle 180.0) PI))) 2.0) (pow (* b (cos (* (/ angle 180.0) PI))) 2.0)) x-scale) x-scale)) (sqrt (+ (pow (- (/ (/ (+ (pow (* a (sin (* (/ angle 180.0) PI))) 2.0) (pow (* b (cos (* (/ angle 180.0) PI))) 2.0)) x-scale) x-scale) (/ (/ (+ (pow (* a (cos (* (/ angle 180.0) PI))) 2.0) (pow (* b (sin (* (/ angle 180.0) PI))) 2.0)) y-scale) y-scale)) 2.0) (pow (/ (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI))) (cos (* (/ angle 180.0) PI))) x-scale) y-scale) 2.0)))) (/ (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI))) (cos (* (/ angle 180.0) PI))) x-scale) y-scale))) PI)))