Average Error: 31.1 → 13.3
Time: 9.8s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x \le 2.474217005200442472341357463282609203046 \cdot 10^{-201}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.354236108762997383350198288921334328983 \cdot 10^{-102}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 5.880877246270694688154653410666269919282 \cdot 10^{-9}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 5.631796052196258562903200319313186965612 \cdot 10^{278}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;x \cdot x \le 2.474217005200442472341357463282609203046 \cdot 10^{-201}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 2.354236108762997383350198288921334328983 \cdot 10^{-102}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \cdot x \le 5.880877246270694688154653410666269919282 \cdot 10^{-9}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 5.631796052196258562903200319313186965612 \cdot 10^{278}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
double f(double x, double y) {
        double r26207156 = x;
        double r26207157 = r26207156 * r26207156;
        double r26207158 = y;
        double r26207159 = 4.0;
        double r26207160 = r26207158 * r26207159;
        double r26207161 = r26207160 * r26207158;
        double r26207162 = r26207157 - r26207161;
        double r26207163 = r26207157 + r26207161;
        double r26207164 = r26207162 / r26207163;
        return r26207164;
}

double f(double x, double y) {
        double r26207165 = x;
        double r26207166 = r26207165 * r26207165;
        double r26207167 = 2.4742170052004425e-201;
        bool r26207168 = r26207166 <= r26207167;
        double r26207169 = -1.0;
        double r26207170 = 2.3542361087629974e-102;
        bool r26207171 = r26207166 <= r26207170;
        double r26207172 = y;
        double r26207173 = 4.0;
        double r26207174 = r26207172 * r26207173;
        double r26207175 = r26207174 * r26207172;
        double r26207176 = r26207166 + r26207175;
        double r26207177 = r26207166 / r26207176;
        double r26207178 = r26207175 / r26207176;
        double r26207179 = r26207177 - r26207178;
        double r26207180 = 5.880877246270695e-09;
        bool r26207181 = r26207166 <= r26207180;
        double r26207182 = 5.6317960521962586e+278;
        bool r26207183 = r26207166 <= r26207182;
        double r26207184 = 1.0;
        double r26207185 = r26207183 ? r26207179 : r26207184;
        double r26207186 = r26207181 ? r26207169 : r26207185;
        double r26207187 = r26207171 ? r26207179 : r26207186;
        double r26207188 = r26207168 ? r26207169 : r26207187;
        return r26207188;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.1
Target30.8
Herbie13.3
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \lt 0.9743233849626781184483093056769575923681:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* x x) < 2.4742170052004425e-201 or 2.3542361087629974e-102 < (* x x) < 5.880877246270695e-09

    1. Initial program 24.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around 0 13.7

      \[\leadsto \color{blue}{-1}\]

    if 2.4742170052004425e-201 < (* x x) < 2.3542361087629974e-102 or 5.880877246270695e-09 < (* x x) < 5.6317960521962586e+278

    1. Initial program 16.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub16.1

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]

    if 5.6317960521962586e+278 < (* x x)

    1. Initial program 59.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around inf 9.3

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 2.474217005200442472341357463282609203046 \cdot 10^{-201}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.354236108762997383350198288921334328983 \cdot 10^{-102}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 5.880877246270694688154653410666269919282 \cdot 10^{-9}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 5.631796052196258562903200319313186965612 \cdot 10^{278}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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