Average Error: 31.9 → 14.3
Time: 2.6s
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 \leq -4.41949527347075 \cdot 10^{+131}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.092213754992166 \cdot 10^{-158}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \leq 8.71219008979303 \cdot 10^{+20}:\\ \;\;\;\;1\\ \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 \leq -4.41949527347075 \cdot 10^{+131}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -3.092213754992166 \cdot 10^{-158}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\

\mathbf{elif}\;y \leq 8.71219008979303 \cdot 10^{+20}:\\
\;\;\;\;1\\

\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 -4.41949527347075e+131)
   -1.0
   (if (<= y -3.092213754992166e-158)
     (log (exp (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))))
     (if (<= y 8.71219008979303e+20) 1.0 -1.0))))
double code(double x, double y) {
	return (((double) (((double) (x * x)) - ((double) (((double) (y * 4.0)) * y)))) / ((double) (((double) (x * x)) + ((double) (((double) (y * 4.0)) * y)))));
}
double code(double x, double y) {
	double tmp;
	if ((y <= -4.41949527347075e+131)) {
		tmp = -1.0;
	} else {
		double tmp_1;
		if ((y <= -3.092213754992166e-158)) {
			tmp_1 = ((double) log(((double) exp((((double) (((double) (x * x)) - ((double) (y * ((double) (y * 4.0)))))) / ((double) (((double) (x * x)) + ((double) (y * ((double) (y * 4.0)))))))))));
		} else {
			double tmp_2;
			if ((y <= 8.71219008979303e+20)) {
				tmp_2 = 1.0;
			} else {
				tmp_2 = -1.0;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	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
Herbie14.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} < 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 y < -4.41949527347074966e131 or 871219008979303006000 < y

    1. Initial program Error: 47.9 bits

      \[\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 Error: 12.7 bits

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

    if -4.41949527347074966e131 < y < -3.09221375499216593e-158

    1. Initial program Error: 16.2 bits

      \[\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 add-log-expError: 16.2 bits

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. SimplifiedError: 16.2 bits

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

    if -3.09221375499216593e-158 < y < 871219008979303006000

    1. Initial program Error: 25.9 bits

      \[\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 Error: 14.6 bits

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplificationError: 14.3 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.41949527347075 \cdot 10^{+131}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.092213754992166 \cdot 10^{-158}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;y \leq 8.71219008979303 \cdot 10^{+20}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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