Average Error: 31.9 → 13.1
Time: 3.1s
Precision: binary64
Cost: 3652
\[\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 \leq 1.55715602789528 \cdot 10^{-289}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.622883590444815 \cdot 10^{-225}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 3.938995416799686 \cdot 10^{-128}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \cdot x \leq 9.560203192398091 \cdot 10^{+187}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \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 \leq 1.55715602789528 \cdot 10^{-289}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \leq 1.622883590444815 \cdot 10^{-225}:\\
\;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\

\mathbf{elif}\;x \cdot x \leq 3.938995416799686 \cdot 10^{-128}:\\
\;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\

\mathbf{elif}\;x \cdot x \leq 9.560203192398091 \cdot 10^{+187}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\

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

\end{array}
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (if (<= (* x x) 1.55715602789528e-289)
   -1.0
   (if (<= (* x x) 1.622883590444815e-225)
     (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
     (if (<= (* x x) 3.938995416799686e-128)
       (+ -1.0 (* 0.5 (/ (* x x) (* y y))))
       (if (<= (* x x) 9.560203192398091e+187)
         (-
          (/ (* x x) (+ (* x x) (* y (* y 4.0))))
          (/ (* y (* y 4.0)) (+ (* x x) (* y (* y 4.0)))))
         1.0)))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	double tmp;
	if ((x * x) <= 1.55715602789528e-289) {
		tmp = -1.0;
	} else if ((x * x) <= 1.622883590444815e-225) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if ((x * x) <= 3.938995416799686e-128) {
		tmp = -1.0 + (0.5 * ((x * x) / (y * y)));
	} else if ((x * x) <= 9.560203192398091e+187) {
		tmp = ((x * x) / ((x * x) + (y * (y * 4.0)))) - ((y * (y * 4.0)) / ((x * x) + (y * (y * 4.0))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}

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.9
Target31.6
Herbie13.1
\[\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} < 0.9743233849626781:\\ \;\;\;\;\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}\]

Alternatives

Alternative 1
Error13.0
Cost3140
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 1.314293898980315 \cdot 10^{-289}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.8503167553059872 \cdot 10^{-225}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 1.4341416860597047 \cdot 10^{-128}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \cdot x \leq 6.158001543763689 \cdot 10^{+187}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 2
Error13.1
Cost3012
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 1.476201984923625 \cdot 10^{-289}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.9701073345171666 \cdot 10^{-225}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 2.3419485415457023 \cdot 10^{-127}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \cdot x \leq 9.560203192398091 \cdot 10^{+187}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 3
Error16.2
Cost706
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1465352812211946 \cdot 10^{-46}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1459981.196274432:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 4
Error31.9
Cost64
\[1\]

Error

Derivation

  1. Split input into 5 regimes
  2. if (*.f64 x x) < 1.5571560278952801e-289

    1. Initial program 8.2

      \[-1\]

    if 1.5571560278952801e-289 < (*.f64 x x) < 1.6228835904448149e-225

    1. Initial program 13.8

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified13.8

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

    if 1.6228835904448149e-225 < (*.f64 x x) < 3.9389954167996858e-128

    1. Initial program 17.4

      \[\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 22.3

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1}\]
    3. Simplified22.3

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}}\]
    4. Simplified22.3

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}}\]

    if 3.9389954167996858e-128 < (*.f64 x x) < 9.5602031923980912e187

    1. Initial program 17.3

      \[\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-sub_binary64_1849717.3

      \[\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}}\]
    4. Simplified17.3

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

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

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

    if 9.5602031923980912e187 < (*.f64 x x)

    1. Initial program 11.4

      \[1\]
  3. Recombined 5 regimes into one program.
  4. Final simplification13.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 1.55715602789528 \cdot 10^{-289}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 1.622883590444815 \cdot 10^{-225}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 3.938995416799686 \cdot 10^{-128}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \cdot x \leq 9.560203192398091 \cdot 10^{+187}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2021044 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :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))))