Average Error: 31.9 → 13.1
Time: 3.9s
Precision: binary64
\[\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 4.318107323633723 \cdot 10^{-290}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 6.546871147194143 \cdot 10^{-226}:\\ \;\;\;\;\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.4077435868477773 \cdot 10^{-128}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\\ \mathbf{elif}\;x \cdot x \leq 5.001370242576063 \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 4.318107323633723 \cdot 10^{-290}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \leq 6.546871147194143 \cdot 10^{-226}:\\
\;\;\;\;\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.4077435868477773 \cdot 10^{-128}:\\
\;\;\;\;-1 + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\\

\mathbf{elif}\;x \cdot x \leq 5.001370242576063 \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) 4.318107323633723e-290)
   -1.0
   (if (<= (* x x) 6.546871147194143e-226)
     (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
     (if (<= (* x x) 1.4077435868477773e-128)
       (+ -1.0 (* 0.5 (/ (pow x 2.0) (pow y 2.0))))
       (if (<= (* x x) 5.001370242576063e+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) <= 4.318107323633723e-290) {
		tmp = -1.0;
	} else if ((x * x) <= 6.546871147194143e-226) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if ((x * x) <= 1.4077435868477773e-128) {
		tmp = -1.0 + (0.5 * (pow(x, 2.0) / pow(y, 2.0)));
	} else if ((x * x) <= 5.001370242576063e+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}\]

Derivation

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

    1. Initial program 28.9

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

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

    if 4.31810732363372295e-290 < (*.f64 x x) < 6.54687114719414309e-226

    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}\]

    if 6.54687114719414309e-226 < (*.f64 x x) < 1.40774358684777733e-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.1

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

    if 1.40774358684777733e-128 < (*.f64 x x) < 5.00137024257606292e187

    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_1611017.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}}\]

    if 5.00137024257606292e187 < (*.f64 x x)

    1. Initial program 50.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 11.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 4.318107323633723 \cdot 10^{-290}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 6.546871147194143 \cdot 10^{-226}:\\ \;\;\;\;\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.4077435868477773 \cdot 10^{-128}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{{x}^{2}}{{y}^{2}}\\ \mathbf{elif}\;x \cdot x \leq 5.001370242576063 \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))))