a from scale-rotated-ellipse

Percentage Accurate: 0.0% → 0.0%
Time: 17.4s
Alternatives: 1
Speedup: 1.0×

Specification

?
\[\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(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{y-scale}}{y-scale}\\ t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{x-scale}}{x-scale}\\ t_5 := \left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\\ t_6 := \frac{4 \cdot t\_5}{{\left(x-scale \cdot y-scale\right)}^{2}}\\ \frac{-\sqrt{\left(\left(2 \cdot t\_6\right) \cdot t\_5\right) \cdot \left(\left(t\_4 + t\_3\right) + \sqrt{{\left(t\_4 - t\_3\right)}^{2} + {\left(\frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_1\right) \cdot t\_2}{x-scale}}{y-scale}\right)}^{2}}\right)}}{t\_6} \end{array} \end{array} \]
(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
         (/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) y-scale) y-scale))
        (t_4
         (/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) x-scale) x-scale))
        (t_5 (* (* b a) (* b (- a))))
        (t_6 (/ (* 4.0 t_5) (pow (* x-scale y-scale) 2.0))))
   (/
    (-
     (sqrt
      (*
       (* (* 2.0 t_6) t_5)
       (+
        (+ t_4 t_3)
        (sqrt
         (+
          (pow (- t_4 t_3) 2.0)
          (pow
           (/
            (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_1) t_2) x-scale)
            y-scale)
           2.0)))))))
    t_6)))
\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(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{y-scale}}{y-scale}\\
t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{x-scale}}{x-scale}\\
t_5 := \left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\\
t_6 := \frac{4 \cdot t\_5}{{\left(x-scale \cdot y-scale\right)}^{2}}\\
\frac{-\sqrt{\left(\left(2 \cdot t\_6\right) \cdot t\_5\right) \cdot \left(\left(t\_4 + t\_3\right) + \sqrt{{\left(t\_4 - t\_3\right)}^{2} + {\left(\frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_1\right) \cdot t\_2}{x-scale}}{y-scale}\right)}^{2}}\right)}}{t\_6}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 1 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 0.0% accurate, 1.0× speedup?

\[\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(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{y-scale}}{y-scale}\\ t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{x-scale}}{x-scale}\\ t_5 := \left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\\ t_6 := \frac{4 \cdot t\_5}{{\left(x-scale \cdot y-scale\right)}^{2}}\\ \frac{-\sqrt{\left(\left(2 \cdot t\_6\right) \cdot t\_5\right) \cdot \left(\left(t\_4 + t\_3\right) + \sqrt{{\left(t\_4 - t\_3\right)}^{2} + {\left(\frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_1\right) \cdot t\_2}{x-scale}}{y-scale}\right)}^{2}}\right)}}{t\_6} \end{array} \end{array} \]
(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
         (/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) y-scale) y-scale))
        (t_4
         (/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) x-scale) x-scale))
        (t_5 (* (* b a) (* b (- a))))
        (t_6 (/ (* 4.0 t_5) (pow (* x-scale y-scale) 2.0))))
   (/
    (-
     (sqrt
      (*
       (* (* 2.0 t_6) t_5)
       (+
        (+ t_4 t_3)
        (sqrt
         (+
          (pow (- t_4 t_3) 2.0)
          (pow
           (/
            (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_1) t_2) x-scale)
            y-scale)
           2.0)))))))
    t_6)))
\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(a \cdot t\_2\right)}^{2} + {\left(b \cdot t\_1\right)}^{2}}{y-scale}}{y-scale}\\
t_4 := \frac{\frac{{\left(a \cdot t\_1\right)}^{2} + {\left(b \cdot t\_2\right)}^{2}}{x-scale}}{x-scale}\\
t_5 := \left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\\
t_6 := \frac{4 \cdot t\_5}{{\left(x-scale \cdot y-scale\right)}^{2}}\\
\frac{-\sqrt{\left(\left(2 \cdot t\_6\right) \cdot t\_5\right) \cdot \left(\left(t\_4 + t\_3\right) + \sqrt{{\left(t\_4 - t\_3\right)}^{2} + {\left(\frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t\_1\right) \cdot t\_2}{x-scale}}{y-scale}\right)}^{2}}\right)}}{t\_6}
\end{array}
\end{array}

Alternative 1: 0.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(a \cdot b\right) \cdot \left(a \cdot b\right)\\ t_1 := \frac{t\_0 \cdot 4}{{\left(y-scale \cdot x-scale\right)}^{2}}\\ t_2 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\ t_3 := \sin t\_2\\ t_4 := \cos t\_2\\ t_5 := \frac{\frac{{\left(t\_4 \cdot b\right)}^{2} + {\left(t\_3 \cdot a\right)}^{2}}{x-scale}}{x-scale}\\ t_6 := \frac{\frac{{\left(t\_3 \cdot b\right)}^{2} + {\left(t\_4 \cdot a\right)}^{2}}{y-scale}}{y-scale}\\ \frac{\sqrt{\left(\sqrt{{\left(\frac{\frac{\left(\left(\left({b}^{2} - {a}^{2}\right) \cdot 2\right) \cdot t\_3\right) \cdot t\_4}{x-scale}}{y-scale}\right)}^{2} + {\left(t\_5 - t\_6\right)}^{2}} + \left(t\_6 + t\_5\right)\right) \cdot \left(\left(t\_1 \cdot 2\right) \cdot t\_0\right)}}{t\_1} \end{array} \end{array} \]
(FPCore (a b angle x-scale y-scale)
 :precision binary64
 (let* ((t_0 (* (* a b) (* a b)))
        (t_1 (/ (* t_0 4.0) (pow (* y-scale x-scale) 2.0)))
        (t_2 (* (PI) (/ angle 180.0)))
        (t_3 (sin t_2))
        (t_4 (cos t_2))
        (t_5
         (/ (/ (+ (pow (* t_4 b) 2.0) (pow (* t_3 a) 2.0)) x-scale) x-scale))
        (t_6
         (/ (/ (+ (pow (* t_3 b) 2.0) (pow (* t_4 a) 2.0)) y-scale) y-scale)))
   (/
    (sqrt
     (*
      (+
       (sqrt
        (+
         (pow
          (/
           (/ (* (* (* (- (pow b 2.0) (pow a 2.0)) 2.0) t_3) t_4) x-scale)
           y-scale)
          2.0)
         (pow (- t_5 t_6) 2.0)))
       (+ t_6 t_5))
      (* (* t_1 2.0) t_0)))
    t_1)))
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(a \cdot b\right) \cdot \left(a \cdot b\right)\\
t_1 := \frac{t\_0 \cdot 4}{{\left(y-scale \cdot x-scale\right)}^{2}}\\
t_2 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
t_3 := \sin t\_2\\
t_4 := \cos t\_2\\
t_5 := \frac{\frac{{\left(t\_4 \cdot b\right)}^{2} + {\left(t\_3 \cdot a\right)}^{2}}{x-scale}}{x-scale}\\
t_6 := \frac{\frac{{\left(t\_3 \cdot b\right)}^{2} + {\left(t\_4 \cdot a\right)}^{2}}{y-scale}}{y-scale}\\
\frac{\sqrt{\left(\sqrt{{\left(\frac{\frac{\left(\left(\left({b}^{2} - {a}^{2}\right) \cdot 2\right) \cdot t\_3\right) \cdot t\_4}{x-scale}}{y-scale}\right)}^{2} + {\left(t\_5 - t\_6\right)}^{2}} + \left(t\_6 + t\_5\right)\right) \cdot \left(\left(t\_1 \cdot 2\right) \cdot t\_0\right)}}{t\_1}
\end{array}
\end{array}
Derivation
  1. Initial program 2.3%

    \[\frac{-\sqrt{\left(\left(2 \cdot \frac{4 \cdot \left(\left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\right)}{{\left(x-scale \cdot y-scale\right)}^{2}}\right) \cdot \left(\left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\right)\right) \cdot \left(\left(\frac{\frac{{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}}{x-scale}}{x-scale} + \frac{\frac{{\left(a \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}}{y-scale}}{y-scale}\right) + \sqrt{{\left(\frac{\frac{{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}}{x-scale}}{x-scale} - \frac{\frac{{\left(a \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right)}^{2}}{y-scale}}{y-scale}\right)}^{2} + {\left(\frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \sin \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \cos \left(\frac{angle}{180} \cdot \mathsf{PI}\left(\right)\right)}{x-scale}}{y-scale}\right)}^{2}}\right)}}{\frac{4 \cdot \left(\left(b \cdot a\right) \cdot \left(b \cdot \left(-a\right)\right)\right)}{{\left(x-scale \cdot y-scale\right)}^{2}}} \]
  2. Add Preprocessing
  3. Final simplification2.3%

    \[\leadsto \frac{\sqrt{\left(\sqrt{{\left(\frac{\frac{\left(\left(\left({b}^{2} - {a}^{2}\right) \cdot 2\right) \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)\right) \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right)}{x-scale}}{y-scale}\right)}^{2} + {\left(\frac{\frac{{\left(\cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2} + {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}}{x-scale}}{x-scale} - \frac{\frac{{\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2} + {\left(\cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}}{y-scale}}{y-scale}\right)}^{2}} + \left(\frac{\frac{{\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2} + {\left(\cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}}{y-scale}}{y-scale} + \frac{\frac{{\left(\cos \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot b\right)}^{2} + {\left(\sin \left(\mathsf{PI}\left(\right) \cdot \frac{angle}{180}\right) \cdot a\right)}^{2}}{x-scale}}{x-scale}\right)\right) \cdot \left(\left(\frac{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right) \cdot 4}{{\left(y-scale \cdot x-scale\right)}^{2}} \cdot 2\right) \cdot \left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)\right)}}{\frac{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right) \cdot 4}{{\left(y-scale \cdot x-scale\right)}^{2}}} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2024343 
(FPCore (a b angle x-scale y-scale)
  :name "a from scale-rotated-ellipse"
  :precision binary64
  (/ (- (sqrt (* (* (* 2.0 (/ (* 4.0 (* (* b a) (* b (- a)))) (pow (* x-scale y-scale) 2.0))) (* (* b a) (* b (- a)))) (+ (+ (/ (/ (+ (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)) (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))))))) (/ (* 4.0 (* (* b a) (* b (- a)))) (pow (* x-scale y-scale) 2.0))))