
(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)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
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 7 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)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
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)) a))
(t_1 (* (PI) (/ angle 180.0)))
(t_2 (sin t_1))
(t_3 (cos t_1))
(t_4
(/
(/ (* t_3 (* t_2 (* (- (pow b 2.0) (pow a 2.0)) 2.0))) x-scale)
y-scale)))
(if (<=
(-
(* t_4 t_4)
(*
(/ (/ (+ (pow (* t_2 b) 2.0) (pow (* t_3 a) 2.0)) y-scale) y-scale)
(*
(/ (/ (+ (pow (* t_3 b) 2.0) (pow (* t_2 a) 2.0)) x-scale) x-scale)
4.0)))
0.0)
(* -4.0 (pow (* (/ b x-scale) (/ a y-scale)) 2.0))
(* (* t_0 -4.0) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{y-scale \cdot x-scale} \cdot a\\
t_1 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_2 := \sin t\_1\\
t_3 := \cos t\_1\\
t_4 := \frac{\frac{t\_3 \cdot \left(t\_2 \cdot \left(\left({b}^{2} - {a}^{2}\right) \cdot 2\right)\right)}{x-scale}}{y-scale}\\
\mathbf{if}\;t\_4 \cdot t\_4 - \frac{\frac{{\left(t\_2 \cdot b\right)}^{2} + {\left(t\_3 \cdot a\right)}^{2}}{y-scale}}{y-scale} \cdot \left(\frac{\frac{{\left(t\_3 \cdot b\right)}^{2} + {\left(t\_2 \cdot a\right)}^{2}}{x-scale}}{x-scale} \cdot 4\right) \leq 0:\\
\;\;\;\;-4 \cdot {\left(\frac{b}{x-scale} \cdot \frac{a}{y-scale}\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot -4\right) \cdot t\_0\\
\end{array}
\end{array}
if (-.f64 (*.f64 (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale) (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale)) (*.f64 (*.f64 #s(literal 4 binary64) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) x-scale) x-scale)) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) y-scale) y-scale))) < 0.0Initial program 68.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6465.9
Applied rewrites65.9%
Applied rewrites81.7%
Applied rewrites92.7%
Applied rewrites99.6%
if 0.0 < (-.f64 (*.f64 (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale) (/.f64 (/.f64 (*.f64 (*.f64 (*.f64 #s(literal 2 binary64) (-.f64 (pow.f64 b #s(literal 2 binary64)) (pow.f64 a #s(literal 2 binary64)))) (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) x-scale) y-scale)) (*.f64 (*.f64 #s(literal 4 binary64) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) x-scale) x-scale)) (/.f64 (/.f64 (+.f64 (pow.f64 (*.f64 a (cos.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64)) (pow.f64 (*.f64 b (sin.f64 (*.f64 (/.f64 angle #s(literal 180 binary64)) (PI.f64)))) #s(literal 2 binary64))) y-scale) y-scale))) Initial program 0.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6448.2
Applied rewrites48.2%
Applied rewrites67.3%
Applied rewrites95.1%
Applied rewrites95.1%
Final simplification96.6%
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (* (/ b (* y-scale x-scale)) a))) (* (* t_0 -4.0) 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)) * a;
return (t_0 * -4.0) * 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)) * a
code = (t_0 * (-4.0d0)) * 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)) * a;
return (t_0 * -4.0) * t_0;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (b / (y_45_scale * x_45_scale)) * a return (t_0 * -4.0) * t_0
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(b / Float64(y_45_scale * x_45_scale)) * a) return Float64(Float64(t_0 * -4.0) * t_0) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (b / (y_45_scale * x_45_scale)) * a; tmp = (t_0 * -4.0) * t_0; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * a), $MachinePrecision]}, N[(N[(t$95$0 * -4.0), $MachinePrecision] * t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{y-scale \cdot x-scale} \cdot a\\
\left(t\_0 \cdot -4\right) \cdot t\_0
\end{array}
\end{array}
Initial program 22.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Applied rewrites72.0%
Applied rewrites94.3%
Applied rewrites94.3%
Final simplification94.3%
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (/ b (* y-scale x-scale)))) (* (* (* (* t_0 a) t_0) a) -4.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) * t_0) * a) * -4.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) * t_0) * a) * (-4.0d0)
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) * t_0) * a) * -4.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) * t_0) * a) * -4.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(Float64(t_0 * a) * t_0) * a) * -4.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) * t_0) * a) * -4.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[(N[(t$95$0 * a), $MachinePrecision] * t$95$0), $MachinePrecision] * a), $MachinePrecision] * -4.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{y-scale \cdot x-scale}\\
\left(\left(\left(t\_0 \cdot a\right) \cdot t\_0\right) \cdot a\right) \cdot -4
\end{array}
\end{array}
Initial program 22.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Applied rewrites72.0%
Applied rewrites94.3%
Applied rewrites89.1%
Final simplification89.1%
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (/ b (* y-scale x-scale)))) (* (* (* (* a a) t_0) t_0) -4.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 (((a * a) * t_0) * t_0) * -4.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 = (((a * a) * t_0) * t_0) * (-4.0d0)
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 (((a * a) * t_0) * t_0) * -4.0;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = b / (y_45_scale * x_45_scale) return (((a * a) * t_0) * t_0) * -4.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(Float64(a * a) * t_0) * t_0) * -4.0) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = b / (y_45_scale * x_45_scale); tmp = (((a * a) * t_0) * t_0) * -4.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[(N[(a * a), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision] * -4.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{y-scale \cdot x-scale}\\
\left(\left(\left(a \cdot a\right) \cdot t\_0\right) \cdot t\_0\right) \cdot -4
\end{array}
\end{array}
Initial program 22.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Applied rewrites72.0%
Applied rewrites94.3%
Applied rewrites79.1%
Final simplification79.1%
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (/ b (* y-scale x-scale)))) (* (* t_0 t_0) (* (* a a) -4.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 * t_0) * ((a * a) * -4.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 * t_0) * ((a * a) * (-4.0d0))
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 * t_0) * ((a * a) * -4.0);
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = b / (y_45_scale * x_45_scale) return (t_0 * t_0) * ((a * a) * -4.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(t_0 * t_0) * Float64(Float64(a * a) * -4.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 * t_0) * ((a * a) * -4.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[(t$95$0 * t$95$0), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{y-scale \cdot x-scale}\\
\left(t\_0 \cdot t\_0\right) \cdot \left(\left(a \cdot a\right) \cdot -4\right)
\end{array}
\end{array}
Initial program 22.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Applied rewrites72.0%
Final simplification72.0%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (/ (* b b) (* (* y-scale x-scale) (* y-scale x-scale))) (* (* -4.0 a) a)))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((-4.0 * a) * a);
}
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 = ((b * b) / ((y_45scale * x_45scale) * (y_45scale * x_45scale))) * (((-4.0d0) * a) * a)
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((-4.0 * a) * a);
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((-4.0 * a) * a)
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(b * b) / Float64(Float64(y_45_scale * x_45_scale) * Float64(y_45_scale * x_45_scale))) * Float64(Float64(-4.0 * a) * a)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((-4.0 * a) * a); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(b * b), $MachinePrecision] / N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(-4.0 * a), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot b}{\left(y-scale \cdot x-scale\right) \cdot \left(y-scale \cdot x-scale\right)} \cdot \left(\left(-4 \cdot a\right) \cdot a\right)
\end{array}
Initial program 22.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Taylor expanded in b around 0
Applied rewrites58.0%
Applied rewrites58.0%
Final simplification58.0%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (/ (* b b) (* (* y-scale x-scale) (* y-scale x-scale))) (* (* a a) -4.0)))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((a * a) * -4.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
code = ((b * b) / ((y_45scale * x_45scale) * (y_45scale * x_45scale))) * ((a * a) * (-4.0d0))
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((a * a) * -4.0);
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((a * a) * -4.0)
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(b * b) / Float64(Float64(y_45_scale * x_45_scale) * Float64(y_45_scale * x_45_scale))) * Float64(Float64(a * a) * -4.0)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((b * b) / ((y_45_scale * x_45_scale) * (y_45_scale * x_45_scale))) * ((a * a) * -4.0); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(b * b), $MachinePrecision] / N[(N[(y$45$scale * x$45$scale), $MachinePrecision] * N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot b}{\left(y-scale \cdot x-scale\right) \cdot \left(y-scale \cdot x-scale\right)} \cdot \left(\left(a \cdot a\right) \cdot -4\right)
\end{array}
Initial program 22.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
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
Taylor expanded in b around 0
Applied rewrites58.0%
Final simplification58.0%
herbie shell --seed 2024278
(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))))