Average Error: 31.6 → 13.4
Time: 4.8s
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 \leq -7.889294442251422 \cdot 10^{+82}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.0083469768504224 \cdot 10^{+35}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := x \cdot x + t_0\\ t_2 := \sqrt{t_1}\\ \mathbf{if}\;x \leq -2.224894635750053 \cdot 10^{+19}:\\ \;\;\;\;\frac{-x}{t_2}\\ \mathbf{elif}\;x \leq -3.0650910469135724 \cdot 10^{-18}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_3 := x \cdot x - t_0\\ \mathbf{if}\;x \leq -6.621764088875046 \cdot 10^{-123}:\\ \;\;\;\;\frac{t_3}{t_2 \cdot t_2}\\ \mathbf{elif}\;x \leq 1.6099882850021034 \cdot 10^{-142}:\\ \;\;\;\;\begin{array}{l} t_4 := \sqrt[3]{{\left(\frac{x}{y}\right)}^{2}}\\ -1 + 0.5 \cdot \left(t_4 \cdot \left(t_4 \cdot e^{\log t_4}\right)\right) \end{array}\\ \mathbf{elif}\;x \leq 3.818174199742958 \cdot 10^{-25}:\\ \;\;\;\;\frac{t_3}{t_1}\\ \mathbf{elif}\;x \leq 7.583644193178865 \cdot 10^{-12}:\\ \;\;\;\;-1 + 0.5 \cdot e^{\left(\log x + \log x\right) - \log \left(y \cdot y\right)}\\ \mathbf{elif}\;x \leq 1.9416524250748645 \cdot 10^{+139}:\\ \;\;\;\;\frac{1}{\frac{t_1}{t_3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\\ \end{array}\\ \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 \leq -7.889294442251422 \cdot 10^{+82}:\\
\;\;\;\;1\\

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

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := y \cdot \left(y \cdot 4\right)\\
t_1 := x \cdot x + t_0\\
t_2 := \sqrt{t_1}\\
\mathbf{if}\;x \leq -2.224894635750053 \cdot 10^{+19}:\\
\;\;\;\;\frac{-x}{t_2}\\

\mathbf{elif}\;x \leq -3.0650910469135724 \cdot 10^{-18}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := x \cdot x - t_0\\
\mathbf{if}\;x \leq -6.621764088875046 \cdot 10^{-123}:\\
\;\;\;\;\frac{t_3}{t_2 \cdot t_2}\\

\mathbf{elif}\;x \leq 1.6099882850021034 \cdot 10^{-142}:\\
\;\;\;\;\begin{array}{l}
t_4 := \sqrt[3]{{\left(\frac{x}{y}\right)}^{2}}\\
-1 + 0.5 \cdot \left(t_4 \cdot \left(t_4 \cdot e^{\log t_4}\right)\right)
\end{array}\\

\mathbf{elif}\;x \leq 3.818174199742958 \cdot 10^{-25}:\\
\;\;\;\;\frac{t_3}{t_1}\\

\mathbf{elif}\;x \leq 7.583644193178865 \cdot 10^{-12}:\\
\;\;\;\;-1 + 0.5 \cdot e^{\left(\log x + \log x\right) - \log \left(y \cdot y\right)}\\

\mathbf{elif}\;x \leq 1.9416524250748645 \cdot 10^{+139}:\\
\;\;\;\;\frac{1}{\frac{t_1}{t_3}}\\

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


\end{array}\\


\end{array}\\


\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 -7.889294442251422e+82)
   1.0
   (if (<= x -1.0083469768504224e+35)
     (+ -1.0 (* 0.5 (/ (* x x) (* y y))))
     (let* ((t_0 (* y (* y 4.0))) (t_1 (+ (* x x) t_0)) (t_2 (sqrt t_1)))
       (if (<= x -2.224894635750053e+19)
         (/ (- x) t_2)
         (if (<= x -3.0650910469135724e-18)
           -1.0
           (let* ((t_3 (- (* x x) t_0)))
             (if (<= x -6.621764088875046e-123)
               (/ t_3 (* t_2 t_2))
               (if (<= x 1.6099882850021034e-142)
                 (let* ((t_4 (cbrt (pow (/ x y) 2.0))))
                   (+ -1.0 (* 0.5 (* t_4 (* t_4 (exp (log t_4)))))))
                 (if (<= x 3.818174199742958e-25)
                   (/ t_3 t_1)
                   (if (<= x 7.583644193178865e-12)
                     (+
                      -1.0
                      (* 0.5 (exp (- (+ (log x) (log x)) (log (* y y))))))
                     (if (<= x 1.9416524250748645e+139)
                       (/ 1.0 (/ t_1 t_3))
                       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 <= -7.889294442251422e+82) {
		tmp = 1.0;
	} else if (x <= -1.0083469768504224e+35) {
		tmp = -1.0 + (0.5 * ((x * x) / (y * y)));
	} else {
		double t_0 = y * (y * 4.0);
		double t_1 = (x * x) + t_0;
		double t_2 = sqrt(t_1);
		double tmp_1;
		if (x <= -2.224894635750053e+19) {
			tmp_1 = -x / t_2;
		} else if (x <= -3.0650910469135724e-18) {
			tmp_1 = -1.0;
		} else {
			double t_3 = (x * x) - t_0;
			double tmp_2;
			if (x <= -6.621764088875046e-123) {
				tmp_2 = t_3 / (t_2 * t_2);
			} else if (x <= 1.6099882850021034e-142) {
				double t_4 = cbrt(pow((x / y), 2.0));
				tmp_2 = -1.0 + (0.5 * (t_4 * (t_4 * exp(log(t_4)))));
			} else if (x <= 3.818174199742958e-25) {
				tmp_2 = t_3 / t_1;
			} else if (x <= 7.583644193178865e-12) {
				tmp_2 = -1.0 + (0.5 * exp((log(x) + log(x)) - log(y * y)));
			} else if (x <= 1.9416524250748645e+139) {
				tmp_2 = 1.0 / (t_1 / t_3);
			} 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.6
Target31.3
Herbie13.4
\[\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 9 regimes
  2. if x < -7.88929444225142226e82 or 1.94165242507486451e139 < x

    1. Initial program 54.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 10.9

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

    if -7.88929444225142226e82 < x < -1.00834697685042239e35

    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} \]
    2. Taylor expanded around 0 37.9

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

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

    if -1.00834697685042239e35 < x < -22248946357500530700

    1. Initial program 17.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-sqr-sqrt_binary6417.7

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}} \]
    4. Applied associate-/r*_binary6417.7

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

      \[\leadsto \frac{\color{blue}{\frac{x \cdot x + \left(y \cdot y\right) \cdot -4}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
    6. Taylor expanded around -inf 28.5

      \[\leadsto \frac{\color{blue}{-1 \cdot x}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}} \]
    7. Simplified28.5

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

    if -22248946357500530700 < x < -3.0650910469135724e-18

    1. Initial program 19.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 28.3

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

    if -3.0650910469135724e-18 < x < -6.6217640888750464e-123

    1. Initial program 16.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-sqr-sqrt_binary6416.2

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

    if -6.6217640888750464e-123 < x < 1.6099882850021034e-142

    1. Initial program 28.0

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

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

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}} \]
    4. Using strategy rm
    5. Applied add-cube-cbrt_binary6415.4

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

      \[\leadsto -1 + 0.5 \cdot \left(\color{blue}{\left(\sqrt[3]{{\left(\frac{x}{y}\right)}^{2}} \cdot \sqrt[3]{{\left(\frac{x}{y}\right)}^{2}}\right)} \cdot \sqrt[3]{\frac{x \cdot x}{y \cdot y}}\right) \]
    7. Simplified8.2

      \[\leadsto -1 + 0.5 \cdot \left(\left(\sqrt[3]{{\left(\frac{x}{y}\right)}^{2}} \cdot \sqrt[3]{{\left(\frac{x}{y}\right)}^{2}}\right) \cdot \color{blue}{\sqrt[3]{{\left(\frac{x}{y}\right)}^{2}}}\right) \]
    8. Using strategy rm
    9. Applied add-exp-log_binary648.2

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

    if 1.6099882850021034e-142 < x < 3.8181741997429578e-25

    1. Initial program 14.2

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

    if 3.8181741997429578e-25 < x < 7.58364419317886489e-12

    1. Initial program 21.8

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

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

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}} \]
    4. Using strategy rm
    5. Applied add-exp-log_binary6425.6

      \[\leadsto -1 + 0.5 \cdot \frac{x \cdot x}{\color{blue}{e^{\log \left(y \cdot y\right)}}} \]
    6. Applied add-exp-log_binary6425.6

      \[\leadsto -1 + 0.5 \cdot \frac{x \cdot \color{blue}{e^{\log x}}}{e^{\log \left(y \cdot y\right)}} \]
    7. Applied add-exp-log_binary6425.6

      \[\leadsto -1 + 0.5 \cdot \frac{\color{blue}{e^{\log x}} \cdot e^{\log x}}{e^{\log \left(y \cdot y\right)}} \]
    8. Applied prod-exp_binary6425.6

      \[\leadsto -1 + 0.5 \cdot \frac{\color{blue}{e^{\log x + \log x}}}{e^{\log \left(y \cdot y\right)}} \]
    9. Applied div-exp_binary6425.6

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

    if 7.58364419317886489e-12 < x < 1.94165242507486451e139

    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} \]
    2. Using strategy rm
    3. Applied clear-num_binary6415.4

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}} \]
  3. Recombined 9 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.889294442251422 \cdot 10^{+82}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.0083469768504224 \cdot 10^{+35}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \leq -2.224894635750053 \cdot 10^{+19}:\\ \;\;\;\;\frac{-x}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}\\ \mathbf{elif}\;x \leq -3.0650910469135724 \cdot 10^{-18}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq -6.621764088875046 \cdot 10^{-123}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}\\ \mathbf{elif}\;x \leq 1.6099882850021034 \cdot 10^{-142}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\sqrt[3]{{\left(\frac{x}{y}\right)}^{2}} \cdot \left(\sqrt[3]{{\left(\frac{x}{y}\right)}^{2}} \cdot e^{\log \left(\sqrt[3]{{\left(\frac{x}{y}\right)}^{2}}\right)}\right)\right)\\ \mathbf{elif}\;x \leq 3.818174199742958 \cdot 10^{-25}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 7.583644193178865 \cdot 10^{-12}:\\ \;\;\;\;-1 + 0.5 \cdot e^{\left(\log x + \log x\right) - \log \left(y \cdot y\right)}\\ \mathbf{elif}\;x \leq 1.9416524250748645 \cdot 10^{+139}:\\ \;\;\;\;\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} \]

Reproduce

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