Average Error: 20.2 → 6.1
Time: 3.6s
Precision: 64
\[0.0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.3453816967374705 \cdot 10^{153}:\\ \;\;\;\;\log \left(\frac{1}{e}\right)\\ \mathbf{elif}\;y \le -1.2162082839611001 \cdot 10^{-151}:\\ \;\;\;\;\log \left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y}{\sqrt{x \cdot x + y \cdot y}}}}\right)\\ \mathbf{elif}\;y \le 6.95543461840908064 \cdot 10^{-213}:\\ \;\;\;\;\log e\\ \mathbf{elif}\;y \le 3.3722516347658366 \cdot 10^{-167}:\\ \;\;\;\;\log \left(\frac{1}{e}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -1.3453816967374705 \cdot 10^{153}:\\
\;\;\;\;\log \left(\frac{1}{e}\right)\\

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

\mathbf{elif}\;y \le 6.95543461840908064 \cdot 10^{-213}:\\
\;\;\;\;\log e\\

\mathbf{elif}\;y \le 3.3722516347658366 \cdot 10^{-167}:\\
\;\;\;\;\log \left(\frac{1}{e}\right)\\

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

\end{array}
double code(double x, double y) {
	return (((x - y) * (x + y)) / ((x * x) + (y * y)));
}
double code(double x, double y) {
	double VAR;
	if ((y <= -1.3453816967374705e+153)) {
		VAR = log((1.0 / ((double) M_E)));
	} else {
		double VAR_1;
		if ((y <= -1.2162082839611001e-151)) {
			VAR_1 = log((exp(((x * x) / ((x * x) + (y * y)))) / exp(((y / sqrt(((x * x) + (y * y)))) * (y / sqrt(((x * x) + (y * y))))))));
		} else {
			double VAR_2;
			if ((y <= 6.95543461840908e-213)) {
				VAR_2 = log(((double) M_E));
			} else {
				double VAR_3;
				if ((y <= 3.3722516347658366e-167)) {
					VAR_3 = log((1.0 / ((double) M_E)));
				} else {
					VAR_3 = ((((x - y) * (x + y)) / sqrt(((x * x) + (y * y)))) / sqrt(((x * x) + (y * y))));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.2
Target0.1
Herbie6.1
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if y < -1.3453816967374705e+153 or 6.95543461840908e-213 < y < 3.3722516347658366e-167

    1. Initial program 56.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt56.6

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

      \[\leadsto \color{blue}{\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-log-exp56.6

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

      \[\leadsto \log \color{blue}{\left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}}\right)}\]
    8. Taylor expanded around 0 8.7

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

    if -1.3453816967374705e+153 < y < -1.2162082839611001e-151

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.0

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

      \[\leadsto \color{blue}{\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.1

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

      \[\leadsto \log \color{blue}{\left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}}\right)}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt0.0

      \[\leadsto \log \left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y \cdot y}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}}}\right)\]
    10. Applied times-frac0.0

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

    if -1.2162082839611001e-151 < y < 6.95543461840908e-213

    1. Initial program 29.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt29.4

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

      \[\leadsto \color{blue}{\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Using strategy rm
    6. Applied add-log-exp29.4

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

      \[\leadsto \log \color{blue}{\left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y \cdot y}{x \cdot x + y \cdot y}}}\right)}\]
    8. Taylor expanded around inf 14.9

      \[\leadsto \log \color{blue}{e}\]

    if 3.3722516347658366e-167 < y

    1. Initial program 0.8

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3453816967374705 \cdot 10^{153}:\\ \;\;\;\;\log \left(\frac{1}{e}\right)\\ \mathbf{elif}\;y \le -1.2162082839611001 \cdot 10^{-151}:\\ \;\;\;\;\log \left(\frac{e^{\frac{x \cdot x}{x \cdot x + y \cdot y}}}{e^{\frac{y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y}{\sqrt{x \cdot x + y \cdot y}}}}\right)\\ \mathbf{elif}\;y \le 6.95543461840908064 \cdot 10^{-213}:\\ \;\;\;\;\log e\\ \mathbf{elif}\;y \le 3.3722516347658366 \cdot 10^{-167}:\\ \;\;\;\;\log \left(\frac{1}{e}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020075 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

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