Average Error: 31.5 → 13.9
Time: 2.7s
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}\;\left(y \cdot 4\right) \cdot y \le 1.6369934943455741 \cdot 10^{-236}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.67683447431044356 \cdot 10^{-195}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.59799826269274119 \cdot 10^{-107}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.0411044840266384 \cdot 10^{-43}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.21092149843973852 \cdot 10^{30}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.4934131972492307 \cdot 10^{149}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \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}\;\left(y \cdot 4\right) \cdot y \le 1.6369934943455741 \cdot 10^{-236}:\\
\;\;\;\;\log \left(e^{1}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.67683447431044356 \cdot 10^{-195}:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.59799826269274119 \cdot 10^{-107}:\\
\;\;\;\;\log \left(e^{1}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.0411044840266384 \cdot 10^{-43}:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.21092149843973852 \cdot 10^{30}:\\
\;\;\;\;\log \left(e^{1}\right)\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.4934131972492307 \cdot 10^{149}:\\
\;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{-1}\right)\\

\end{array}
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 temp;
	if ((((y * 4.0) * y) <= 1.636993494345574e-236)) {
		temp = log(exp(1.0));
	} else {
		double temp_1;
		if ((((y * 4.0) * y) <= 5.6768344743104436e-195)) {
			temp_1 = log((sqrt(exp((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))))) * sqrt(exp((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)))))));
		} else {
			double temp_2;
			if ((((y * 4.0) * y) <= 4.597998262692741e-107)) {
				temp_2 = log(exp(1.0));
			} else {
				double temp_3;
				if ((((y * 4.0) * y) <= 2.0411044840266384e-43)) {
					temp_3 = log((sqrt(exp((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))))) * sqrt(exp((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)))))));
				} else {
					double temp_4;
					if ((((y * 4.0) * y) <= 1.2109214984397385e+30)) {
						temp_4 = log(exp(1.0));
					} else {
						double temp_5;
						if ((((y * 4.0) * y) <= 1.4934131972492307e+149)) {
							temp_5 = log((sqrt(exp((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))))) * sqrt(exp((((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y)))))));
						} else {
							temp_5 = log(exp(-1.0));
						}
						temp_4 = temp_5;
					}
					temp_3 = temp_4;
				}
				temp_2 = temp_3;
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

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.5
Target31.3
Herbie13.9
\[\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.974323384962678118:\\ \;\;\;\;\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.0) y) < 1.636993494345574e-236 or 5.6768344743104436e-195 < (* (* y 4.0) y) < 4.597998262692741e-107 or 2.0411044840266384e-43 < (* (* y 4.0) y) < 1.2109214984397385e+30

    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. Using strategy rm
    3. Applied add-log-exp24.2

      \[\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. Taylor expanded around inf 15.3

      \[\leadsto \log \left(e^{\color{blue}{1}}\right)\]

    if 1.636993494345574e-236 < (* (* y 4.0) y) < 5.6768344743104436e-195 or 4.597998262692741e-107 < (* (* y 4.0) y) < 2.0411044840266384e-43 or 1.2109214984397385e+30 < (* (* y 4.0) y) < 1.4934131972492307e+149

    1. Initial program 14.7

      \[\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-exp14.7

      \[\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. Using strategy rm
    5. Applied add-sqr-sqrt14.7

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

    if 1.4934131972492307e+149 < (* (* y 4.0) y)

    1. Initial program 48.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 add-log-exp48.1

      \[\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. Taylor expanded around 0 11.8

      \[\leadsto \log \left(e^{\color{blue}{-1}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.6369934943455741 \cdot 10^{-236}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.67683447431044356 \cdot 10^{-195}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 4.59799826269274119 \cdot 10^{-107}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.0411044840266384 \cdot 10^{-43}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.21092149843973852 \cdot 10^{30}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.4934131972492307 \cdot 10^{149}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \cdot \sqrt{e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \end{array}\]

Reproduce

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

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

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