Average Error: 31.2 → 16.3
Time: 22.3s
Precision: 64
Internal precision: 128
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \le 0.99995974222954:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + {y}^2 \cdot 4.0} - \frac{{y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Target

Original31.2
Comparison31.3
Herbie16.3
\[ \begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\ \;\;\;\;\frac{{x}^2}{{x}^2 + {y}^2 \cdot 4.0} - \frac{{y}^2 \cdot 4.0}{{x}^2 + {y}^2 \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{{x}^2 + {y}^2 \cdot 4.0}}\right)}^2 - \frac{{y}^2 \cdot 4.0}{{x}^2 + {y}^2 \cdot 4.0}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes.
  2. if (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) < 0.99995974222954

    1. Initial program 0.0

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Applied simplify 0.0

      \[\leadsto \color{blue}{\frac{x \cdot x - {y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}}\]
    3. Using strategy rm
    4. Applied div-sub 0.0

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + {y}^2 \cdot 4.0} - \frac{{y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}}\]

    if 0.99995974222954 < (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y)))

    1. Initial program 41.8

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Applied simplify 41.8

      \[\leadsto \color{blue}{\frac{x \cdot x - {y}^2 \cdot 4.0}{x \cdot x + {y}^2 \cdot 4.0}}\]
    3. Applied taylor 21.7

      \[\leadsto 1\]
    4. Taylor expanded around inf 21.7

      \[\leadsto \color{blue}{1}\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 22.3s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(1124604979 3004756373 289015944 3802788677 3056753239 1938455670)'
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"

  :target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (sqr x) (+ (sqr x) (* (sqr y) 4.0))) (/ (* (sqr y) 4.0) (+ (sqr x) (* (sqr y) 4.0)))) (- (sqr (/ x (sqrt (+ (sqr x) (* (sqr y) 4.0))))) (/ (* (sqr y) 4.0) (+ (sqr x) (* (sqr y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))