Average Error: 31.9 → 12.7
Time: 2.4s
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 -7.413866609077746 \cdot 10^{+103}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;y \leq -2.7183403829409112 \cdot 10^{-102}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \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 4.472181259931087 \cdot 10^{-75}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.2199607436705692 \cdot 10^{+119}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\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}\;y \leq -7.413866609077746 \cdot 10^{+103}:\\
\;\;\;\;-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\

\mathbf{elif}\;y \leq -2.7183403829409112 \cdot 10^{-102}:\\
\;\;\;\;\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \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 4.472181259931087 \cdot 10^{-75}:\\
\;\;\;\;1\\

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

\mathbf{else}:\\
\;\;\;\;-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\

\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 -7.413866609077746e+103)
   (+ -1.0 (* 0.5 (* (/ x y) (/ x y))))
   (if (<= y -2.7183403829409112e-102)
     (cbrt
      (*
       (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
       (*
        (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
        (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0)))))))
     (if (<= y 4.472181259931087e-75)
       1.0
       (if (<= y 3.2199607436705692e+119)
         (/
          (/ (- (* x x) (* y (* y 4.0))) (sqrt (+ (* x x) (* y (* y 4.0)))))
          (sqrt (+ (* x x) (* y (* y 4.0)))))
         (+ -1.0 (* 0.5 (* (/ x y) (/ x y)))))))))
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 <= -7.413866609077746e+103) {
		tmp = -1.0 + (0.5 * ((x / y) * (x / y)));
	} else if (y <= -2.7183403829409112e-102) {
		tmp = cbrt((((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))) * ((((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))) * (((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0))))));
	} else if (y <= 4.472181259931087e-75) {
		tmp = 1.0;
	} else if (y <= 3.2199607436705692e+119) {
		tmp = (((x * x) - (y * (y * 4.0))) / sqrt((x * x) + (y * (y * 4.0)))) / sqrt((x * x) + (y * (y * 4.0)));
	} else {
		tmp = -1.0 + (0.5 * ((x / y) * (x / y)));
	}
	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
Herbie12.7
\[\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 4 regimes
  2. if y < -7.4138666090777461e103 or 3.2199607436705692e119 < y

    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 0 16.5

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

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}}\]
    4. Using strategy rm
    5. Applied times-frac_binary64_161119.9

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

    if -7.4138666090777461e103 < y < -2.7183403829409112e-102

    1. Initial program 16.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 add-cbrt-cube_binary64_1614116.4

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

    if -2.7183403829409112e-102 < y < 4.47218125993108705e-75

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

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

    if 4.47218125993108705e-75 < y < 3.2199607436705692e119

    1. Initial program 15.9

      \[\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_binary64_1612715.9

      \[\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*_binary64_1604916.0

      \[\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}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.413866609077746 \cdot 10^{+103}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;y \leq -2.7183403829409112 \cdot 10^{-102}:\\ \;\;\;\;\sqrt[3]{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \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 4.472181259931087 \cdot 10^{-75}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.2199607436705692 \cdot 10^{+119}:\\ \;\;\;\;\frac{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}}{\sqrt{x \cdot x + y \cdot \left(y \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-1 + 0.5 \cdot \left(\frac{x}{y} \cdot \frac{x}{y}\right)\\ \end{array}\]

Reproduce

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