
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) PI))
(t_1 (sin t_0))
(t_2 (cos t_0))
(t_3
(/
(/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_1) t_2) x-scale)
y-scale)))
(-
(* t_3 t_3)
(*
(*
4.0
(/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) x-scale) x-scale))
(/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) y-scale) y-scale)))))
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 = sin(t_0);
double t_2 = cos(t_0);
double t_3 = ((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
return (t_3 * t_3) - ((4.0 * (((pow((a * t_1), 2.0) + pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((pow((a * t_2), 2.0) + pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
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.sin(t_0);
double t_2 = Math.cos(t_0);
double t_3 = ((((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
return (t_3 * t_3) - ((4.0 * (((Math.pow((a * t_1), 2.0) + Math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((Math.pow((a * t_2), 2.0) + Math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (angle / 180.0) * math.pi t_1 = math.sin(t_0) t_2 = math.cos(t_0) t_3 = ((((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale return (t_3 * t_3) - ((4.0 * (((math.pow((a * t_1), 2.0) + math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((math.pow((a * t_2), 2.0) + math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale))
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(angle / 180.0) * pi) t_1 = sin(t_0) t_2 = cos(t_0) t_3 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale) return Float64(Float64(t_3 * t_3) - Float64(Float64(4.0 * Float64(Float64(Float64((Float64(a * t_1) ^ 2.0) + (Float64(b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * Float64(Float64(Float64((Float64(a * t_2) ^ 2.0) + (Float64(b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale))) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (angle / 180.0) * pi; t_1 = sin(t_0); t_2 = cos(t_0); t_3 = ((((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale; tmp = (t_3 * t_3) - ((4.0 * (((((a * t_1) ^ 2.0) + ((b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * (((((a * t_2) ^ 2.0) + ((b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale)); 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[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[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$1), $MachinePrecision] * t$95$2), $MachinePrecision] / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(4.0 * 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] / x$45$scale), $MachinePrecision] / x$45$scale), $MachinePrecision]), $MachinePrecision] * 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] / y$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_1\right) \cdot t\_2}{x-scale}}{y-scale}\\
t\_3 \cdot t\_3 - \left(4 \cdot \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{y-scale}}{y-scale}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ angle 180.0) PI))
(t_1 (sin t_0))
(t_2 (cos t_0))
(t_3
(/
(/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_1) t_2) x-scale)
y-scale)))
(-
(* t_3 t_3)
(*
(*
4.0
(/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) x-scale) x-scale))
(/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) y-scale) y-scale)))))
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 = sin(t_0);
double t_2 = cos(t_0);
double t_3 = ((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
return (t_3 * t_3) - ((4.0 * (((pow((a * t_1), 2.0) + pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((pow((a * t_2), 2.0) + pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
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.sin(t_0);
double t_2 = Math.cos(t_0);
double t_3 = ((((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
return (t_3 * t_3) - ((4.0 * (((Math.pow((a * t_1), 2.0) + Math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((Math.pow((a * t_2), 2.0) + Math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (angle / 180.0) * math.pi t_1 = math.sin(t_0) t_2 = math.cos(t_0) t_3 = ((((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale return (t_3 * t_3) - ((4.0 * (((math.pow((a * t_1), 2.0) + math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((math.pow((a * t_2), 2.0) + math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale))
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(angle / 180.0) * pi) t_1 = sin(t_0) t_2 = cos(t_0) t_3 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale) return Float64(Float64(t_3 * t_3) - Float64(Float64(4.0 * Float64(Float64(Float64((Float64(a * t_1) ^ 2.0) + (Float64(b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * Float64(Float64(Float64((Float64(a * t_2) ^ 2.0) + (Float64(b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale))) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (angle / 180.0) * pi; t_1 = sin(t_0); t_2 = cos(t_0); t_3 = ((((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale; tmp = (t_3 * t_3) - ((4.0 * (((((a * t_1) ^ 2.0) + ((b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * (((((a * t_2) ^ 2.0) + ((b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale)); 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[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[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$1), $MachinePrecision] * t$95$2), $MachinePrecision] / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(4.0 * 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] / x$45$scale), $MachinePrecision] / x$45$scale), $MachinePrecision]), $MachinePrecision] * 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] / y$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
t_1 := \sin t\_0\\
t_2 := \cos t\_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_1\right) \cdot t\_2}{x-scale}}{y-scale}\\
t\_3 \cdot t\_3 - \left(4 \cdot \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{y-scale}}{y-scale}
\end{array}
\end{array}
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (/ b (* y-scale x-scale)))) (* (* (* t_0 a) (* -4.0 a)) t_0)))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b / (y_45_scale * x_45_scale);
return ((t_0 * a) * (-4.0 * a)) * t_0;
}
real(8) function code(a, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: t_0
t_0 = b / (y_45scale * x_45scale)
code = ((t_0 * a) * ((-4.0d0) * a)) * t_0
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b / (y_45_scale * x_45_scale);
return ((t_0 * a) * (-4.0 * a)) * t_0;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = b / (y_45_scale * x_45_scale) return ((t_0 * a) * (-4.0 * a)) * t_0
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(b / Float64(y_45_scale * x_45_scale)) return Float64(Float64(Float64(t_0 * a) * Float64(-4.0 * a)) * t_0) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = b / (y_45_scale * x_45_scale); tmp = ((t_0 * a) * (-4.0 * a)) * t_0; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(b / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(t$95$0 * a), $MachinePrecision] * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{y-scale \cdot x-scale}\\
\left(\left(t\_0 \cdot a\right) \cdot \left(-4 \cdot a\right)\right) \cdot t\_0
\end{array}
\end{array}
Initial program 23.8%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6455.0
Applied rewrites55.0%
Applied rewrites79.2%
Applied rewrites92.6%
Final simplification92.6%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(if (<= b 1.65e-152)
(* (/ (* (* (* a a) -4.0) (/ b (* y-scale x-scale))) (* y-scale x-scale)) b)
(if (<= b 1.75e+155)
(*
(/ (* b b) (* y-scale x-scale))
(* (/ a (* y-scale x-scale)) (* -4.0 a)))
(*
(/ (* (* (* -4.0 a) b) a) (* (* y-scale x-scale) (* y-scale x-scale)))
b))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (b <= 1.65e-152) {
tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b;
} else if (b <= 1.75e+155) {
tmp = ((b * b) / (y_45_scale * x_45_scale)) * ((a / (y_45_scale * x_45_scale)) * (-4.0 * a));
} else {
tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
}
return tmp;
}
real(8) function code(a, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: tmp
if (b <= 1.65d-152) then
tmp = ((((a * a) * (-4.0d0)) * (b / (y_45scale * x_45scale))) / (y_45scale * x_45scale)) * b
else if (b <= 1.75d+155) then
tmp = ((b * b) / (y_45scale * x_45scale)) * ((a / (y_45scale * x_45scale)) * ((-4.0d0) * a))
else
tmp = (((((-4.0d0) * a) * b) * a) / ((y_45scale * x_45scale) * (y_45scale * x_45scale))) * b
end if
code = tmp
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (b <= 1.65e-152) {
tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b;
} else if (b <= 1.75e+155) {
tmp = ((b * b) / (y_45_scale * x_45_scale)) * ((a / (y_45_scale * x_45_scale)) * (-4.0 * a));
} else {
tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): tmp = 0 if b <= 1.65e-152: tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b elif b <= 1.75e+155: tmp = ((b * b) / (y_45_scale * x_45_scale)) * ((a / (y_45_scale * x_45_scale)) * (-4.0 * a)) else: tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b return tmp
function code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0 if (b <= 1.65e-152) tmp = Float64(Float64(Float64(Float64(Float64(a * a) * -4.0) * Float64(b / Float64(y_45_scale * x_45_scale))) / Float64(y_45_scale * x_45_scale)) * b); elseif (b <= 1.75e+155) tmp = Float64(Float64(Float64(b * b) / Float64(y_45_scale * x_45_scale)) * Float64(Float64(a / Float64(y_45_scale * x_45_scale)) * Float64(-4.0 * a))); else tmp = Float64(Float64(Float64(Float64(Float64(-4.0 * a) * b) * a) / Float64(Float64(y_45_scale * x_45_scale) * Float64(y_45_scale * x_45_scale))) * b); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; if (b <= 1.65e-152) tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b; elseif (b <= 1.75e+155) tmp = ((b * b) / (y_45_scale * x_45_scale)) * ((a / (y_45_scale * x_45_scale)) * (-4.0 * a)); else tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b; end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[b, 1.65e-152], N[(N[(N[(N[(N[(a * a), $MachinePrecision] * -4.0), $MachinePrecision] * N[(b / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[b, 1.75e+155], N[(N[(N[(b * b), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(a / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(-4.0 * a), $MachinePrecision] * b), $MachinePrecision] * a), $MachinePrecision] / N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.65 \cdot 10^{-152}:\\
\;\;\;\;\frac{\left(\left(a \cdot a\right) \cdot -4\right) \cdot \frac{b}{y-scale \cdot x-scale}}{y-scale \cdot x-scale} \cdot b\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{+155}:\\
\;\;\;\;\frac{b \cdot b}{y-scale \cdot x-scale} \cdot \left(\frac{a}{y-scale \cdot x-scale} \cdot \left(-4 \cdot a\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(-4 \cdot a\right) \cdot b\right) \cdot a}{\left(y-scale \cdot x-scale\right) \cdot \left(y-scale \cdot x-scale\right)} \cdot b\\
\end{array}
\end{array}
if b < 1.64999999999999999e-152Initial program 30.3%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6452.1
Applied rewrites52.1%
Applied rewrites61.1%
Taylor expanded in b around 0
Applied rewrites68.8%
Applied rewrites80.8%
if 1.64999999999999999e-152 < b < 1.74999999999999992e155Initial program 20.2%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6465.0
Applied rewrites65.0%
Applied rewrites82.5%
Applied rewrites90.5%
if 1.74999999999999992e155 < b Initial program 0.0%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6450.3
Applied rewrites50.3%
Applied rewrites62.6%
Taylor expanded in b around 0
Applied rewrites71.3%
Applied rewrites84.5%
Final simplification83.7%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(if (<= a 3.55e-161)
(* (/ (* (* (* -4.0 a) b) a) (* (* y-scale x-scale) (* y-scale x-scale))) b)
(if (<= a 1.3e+156)
(*
(/ (* (* (* a a) -4.0) (/ b (* y-scale x-scale))) (* y-scale x-scale))
b)
(*
(* (* (/ b (* (* (* y-scale x-scale) y-scale) x-scale)) b) (* -4.0 a))
a))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (a <= 3.55e-161) {
tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
} else if (a <= 1.3e+156) {
tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b;
} else {
tmp = (((b / (((y_45_scale * x_45_scale) * y_45_scale) * x_45_scale)) * b) * (-4.0 * a)) * a;
}
return tmp;
}
real(8) function code(a, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: tmp
if (a <= 3.55d-161) then
tmp = (((((-4.0d0) * a) * b) * a) / ((y_45scale * x_45scale) * (y_45scale * x_45scale))) * b
else if (a <= 1.3d+156) then
tmp = ((((a * a) * (-4.0d0)) * (b / (y_45scale * x_45scale))) / (y_45scale * x_45scale)) * b
else
tmp = (((b / (((y_45scale * x_45scale) * y_45scale) * x_45scale)) * b) * ((-4.0d0) * a)) * a
end if
code = tmp
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (a <= 3.55e-161) {
tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
} else if (a <= 1.3e+156) {
tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b;
} else {
tmp = (((b / (((y_45_scale * x_45_scale) * y_45_scale) * x_45_scale)) * b) * (-4.0 * a)) * a;
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): tmp = 0 if a <= 3.55e-161: tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b elif a <= 1.3e+156: tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b else: tmp = (((b / (((y_45_scale * x_45_scale) * y_45_scale) * x_45_scale)) * b) * (-4.0 * a)) * a return tmp
function code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0 if (a <= 3.55e-161) tmp = Float64(Float64(Float64(Float64(Float64(-4.0 * a) * b) * a) / Float64(Float64(y_45_scale * x_45_scale) * Float64(y_45_scale * x_45_scale))) * b); elseif (a <= 1.3e+156) tmp = Float64(Float64(Float64(Float64(Float64(a * a) * -4.0) * Float64(b / Float64(y_45_scale * x_45_scale))) / Float64(y_45_scale * x_45_scale)) * b); else tmp = Float64(Float64(Float64(Float64(b / Float64(Float64(Float64(y_45_scale * x_45_scale) * y_45_scale) * x_45_scale)) * b) * Float64(-4.0 * a)) * a); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; if (a <= 3.55e-161) tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b; elseif (a <= 1.3e+156) tmp = ((((a * a) * -4.0) * (b / (y_45_scale * x_45_scale))) / (y_45_scale * x_45_scale)) * b; else tmp = (((b / (((y_45_scale * x_45_scale) * y_45_scale) * x_45_scale)) * b) * (-4.0 * a)) * a; end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[a, 3.55e-161], N[(N[(N[(N[(N[(-4.0 * a), $MachinePrecision] * b), $MachinePrecision] * a), $MachinePrecision] / N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], If[LessEqual[a, 1.3e+156], N[(N[(N[(N[(N[(a * a), $MachinePrecision] * -4.0), $MachinePrecision] * N[(b / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(N[(N[(N[(b / N[(N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * y$45$scale), $MachinePrecision] * x$45$scale), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.55 \cdot 10^{-161}:\\
\;\;\;\;\frac{\left(\left(-4 \cdot a\right) \cdot b\right) \cdot a}{\left(y-scale \cdot x-scale\right) \cdot \left(y-scale \cdot x-scale\right)} \cdot b\\
\mathbf{elif}\;a \leq 1.3 \cdot 10^{+156}:\\
\;\;\;\;\frac{\left(\left(a \cdot a\right) \cdot -4\right) \cdot \frac{b}{y-scale \cdot x-scale}}{y-scale \cdot x-scale} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\frac{b}{\left(\left(y-scale \cdot x-scale\right) \cdot y-scale\right) \cdot x-scale} \cdot b\right) \cdot \left(-4 \cdot a\right)\right) \cdot a\\
\end{array}
\end{array}
if a < 3.55e-161Initial program 30.4%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6452.7
Applied rewrites52.7%
Applied rewrites61.9%
Taylor expanded in b around 0
Applied rewrites71.8%
Applied rewrites80.1%
if 3.55e-161 < a < 1.30000000000000009e156Initial program 19.2%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.4
Applied rewrites63.4%
Applied rewrites68.0%
Taylor expanded in b around 0
Applied rewrites77.6%
Applied rewrites93.5%
if 1.30000000000000009e156 < a Initial program 0.0%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6442.7
Applied rewrites42.7%
Applied rewrites66.3%
Applied rewrites74.0%
Final simplification83.6%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (/ (* (* (* -4.0 a) b) a) (* (* y-scale x-scale) (* y-scale x-scale))) b))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
}
real(8) function code(a, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
code = (((((-4.0d0) * a) * b) * a) / ((y_45scale * x_45scale) * (y_45scale * x_45scale))) * b
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(Float64(Float64(-4.0 * a) * b) * a) / Float64(Float64(y_45_scale * x_45_scale) * Float64(y_45_scale * x_45_scale))) * b) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((((-4.0 * a) * b) * a) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(N[(N[(-4.0 * a), $MachinePrecision] * b), $MachinePrecision] * a), $MachinePrecision] / N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(-4 \cdot a\right) \cdot b\right) \cdot a}{\left(y-scale \cdot x-scale\right) \cdot \left(y-scale \cdot x-scale\right)} \cdot b
\end{array}
Initial program 23.8%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6455.0
Applied rewrites55.0%
Applied rewrites62.2%
Taylor expanded in b around 0
Applied rewrites71.4%
Applied rewrites77.1%
Final simplification77.1%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (/ (* (* (* a a) -4.0) b) (* (* y-scale x-scale) (* y-scale x-scale))) b))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((((a * a) * -4.0) * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
}
real(8) function code(a, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
code = ((((a * a) * (-4.0d0)) * b) / ((y_45scale * x_45scale) * (y_45scale * x_45scale))) * b
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((((a * a) * -4.0) * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b;
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((((a * a) * -4.0) * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(Float64(Float64(a * a) * -4.0) * b) / Float64(Float64(y_45_scale * x_45_scale) * Float64(y_45_scale * x_45_scale))) * b) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((((a * a) * -4.0) * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * b; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(N[(N[(a * a), $MachinePrecision] * -4.0), $MachinePrecision] * b), $MachinePrecision] / N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(a \cdot a\right) \cdot -4\right) \cdot b}{\left(y-scale \cdot x-scale\right) \cdot \left(y-scale \cdot x-scale\right)} \cdot b
\end{array}
Initial program 23.8%
Taylor expanded in angle around 0
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6455.0
Applied rewrites55.0%
Applied rewrites62.2%
Taylor expanded in b around 0
Applied rewrites71.4%
Final simplification71.4%
herbie shell --seed 2024235
(FPCore (a b angle x-scale y-scale)
:name "Simplification of discriminant from scale-rotated-ellipse"
:precision binary64
(- (* (/ (/ (* (* (* 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 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI))) (cos (* (/ angle 180.0) PI))) x-scale) y-scale)) (* (* 4.0 (/ (/ (+ (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))))