Average Error: 31.6 → 13.5
Time: 3.7s
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}\;y \cdot \left(y \cdot 4\right) \leq 4.128199703734893 \cdot 10^{-265}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.7964701659325815 \cdot 10^{+63}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 7.047919430961226 \cdot 10^{+149}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.869400425093727 \cdot 10^{+203}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \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}\;y \cdot \left(y \cdot 4\right) \leq 4.128199703734893 \cdot 10^{-265}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 7.047919430961226 \cdot 10^{+149}:\\
\;\;\;\;1\\

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

\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 (<= (* y (* y 4.0)) 4.128199703734893e-265)
   1.0
   (if (<= (* y (* y 4.0)) 5.7964701659325815e+63)
     (/ (- (* x x) (* y (* y 4.0))) (+ (* y (* y 4.0)) (* x x)))
     (if (<= (* y (* y 4.0)) 7.047919430961226e+149)
       1.0
       (if (<= (* y (* y 4.0)) 2.869400425093727e+203)
         (/ (- (* x x) (* y (* y 4.0))) (+ (* y (* y 4.0)) (* x x)))
         -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 ((y * (y * 4.0)) <= 4.128199703734893e-265) {
		tmp = 1.0;
	} else if ((y * (y * 4.0)) <= 5.7964701659325815e+63) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((y * (y * 4.0)) + (x * x));
	} else if ((y * (y * 4.0)) <= 7.047919430961226e+149) {
		tmp = 1.0;
	} else if ((y * (y * 4.0)) <= 2.869400425093727e+203) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((y * (y * 4.0)) + (x * x));
	} 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.6
Target31.3
Herbie13.5
\[\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 3 regimes
  2. if (*.f64 (*.f64 y 4) y) < 4.12819970373489311e-265 or 5.79647016593258151e63 < (*.f64 (*.f64 y 4) y) < 7.04791943096122566e149

    1. Initial program 26.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 inf 14.8

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

    if 4.12819970373489311e-265 < (*.f64 (*.f64 y 4) y) < 5.79647016593258151e63 or 7.04791943096122566e149 < (*.f64 (*.f64 y 4) y) < 2.86940042509372711e203

    1. Initial program 15.4

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

    if 2.86940042509372711e203 < (*.f64 (*.f64 y 4) y)

    1. Initial program 51.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 10.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 4.128199703734893 \cdot 10^{-265}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 5.7964701659325815 \cdot 10^{+63}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 7.047919430961226 \cdot 10^{+149}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.869400425093727 \cdot 10^{+203}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2021019 
(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))))