?

Average Accuracy: 67.9% → 100.0%
Time: 13.7s
Precision: binary64
Cost: 1216

?

\[\left(0 < x \land x < 1\right) \land y < 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
\[\frac{x - y}{\frac{y}{\frac{x + y}{y}} + x \cdot \frac{x}{x + y}} \]
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y)
 :precision binary64
 (/ (- x y) (+ (/ y (/ (+ x y) y)) (* x (/ x (+ x y))))))
double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
double code(double x, double y) {
	return (x - y) / ((y / ((x + y) / y)) + (x * (x / (x + y))));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x - y) * (x + y)) / ((x * x) + (y * y))
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x - y) / ((y / ((x + y) / y)) + (x * (x / (x + y))))
end function
public static double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
public static double code(double x, double y) {
	return (x - y) / ((y / ((x + y) / y)) + (x * (x / (x + y))));
}
def code(x, y):
	return ((x - y) * (x + y)) / ((x * x) + (y * y))
def code(x, y):
	return (x - y) / ((y / ((x + y) / y)) + (x * (x / (x + y))))
function code(x, y)
	return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
end
function code(x, y)
	return Float64(Float64(x - y) / Float64(Float64(y / Float64(Float64(x + y) / y)) + Float64(x * Float64(x / Float64(x + y)))))
end
function tmp = code(x, y)
	tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
end
function tmp = code(x, y)
	tmp = (x - y) / ((y / ((x + y) / y)) + (x * (x / (x + y))));
end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(N[(y / N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + N[(x * N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{x - y}{\frac{y}{\frac{x + y}{y}} + x \cdot \frac{x}{x + y}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original67.9%
Target99.9%
Herbie100.0%
\[\begin{array}{l} \mathbf{if}\;0.5 < \left|\frac{x}{y}\right| \land \left|\frac{x}{y}\right| < 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. Initial program 67.9%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Simplified67.8%

    \[\leadsto \color{blue}{\frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}}} \]
    Proof

    [Start]67.9

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

    associate-/l* [=>]67.8

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

    fma-def [=>]67.8

    \[ \frac{x - y}{\frac{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right)}}{x + y}} \]
  3. Applied egg-rr67.5%

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

    [Start]67.8

    \[ \frac{x - y}{\frac{\mathsf{fma}\left(x, x, y \cdot y\right)}{x + y}} \]

    div-inv [=>]67.5

    \[ \frac{x - y}{\color{blue}{\mathsf{fma}\left(x, x, y \cdot y\right) \cdot \frac{1}{x + y}}} \]

    *-commutative [=>]67.5

    \[ \frac{x - y}{\color{blue}{\frac{1}{x + y} \cdot \mathsf{fma}\left(x, x, y \cdot y\right)}} \]

    fma-udef [=>]67.5

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

    +-commutative [=>]67.5

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

    distribute-lft-in [=>]67.5

    \[ \frac{x - y}{\color{blue}{\frac{1}{x + y} \cdot \left(y \cdot y\right) + \frac{1}{x + y} \cdot \left(x \cdot x\right)}} \]
  4. Simplified67.5%

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

    [Start]67.5

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

    distribute-lft-out [=>]67.5

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

    +-commutative [=>]67.5

    \[ \frac{x - y}{\frac{1}{\color{blue}{y + x}} \cdot \left(y \cdot y + x \cdot x\right)} \]
  5. Applied egg-rr75.6%

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

    [Start]67.5

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

    distribute-rgt-in [=>]67.5

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

    un-div-inv [=>]67.7

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

    un-div-inv [=>]67.8

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

    associate-/l* [=>]75.6

    \[ \frac{x - y}{\frac{y \cdot y}{y + x} + \color{blue}{\frac{x}{\frac{y + x}{x}}}} \]
  6. Simplified100.0%

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

    [Start]75.6

    \[ \frac{x - y}{\frac{y \cdot y}{y + x} + \frac{x}{\frac{y + x}{x}}} \]

    associate-/l* [=>]100.0

    \[ \frac{x - y}{\color{blue}{\frac{y}{\frac{y + x}{y}}} + \frac{x}{\frac{y + x}{x}}} \]

    +-commutative [=>]100.0

    \[ \frac{x - y}{\frac{y}{\frac{\color{blue}{x + y}}{y}} + \frac{x}{\frac{y + x}{x}}} \]

    associate-/r/ [=>]100.0

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

    +-commutative [=>]100.0

    \[ \frac{x - y}{\frac{y}{\frac{x + y}{y}} + \frac{x}{\color{blue}{x + y}} \cdot x} \]
  7. Final simplification100.0%

    \[\leadsto \frac{x - y}{\frac{y}{\frac{x + y}{y}} + x \cdot \frac{x}{x + y}} \]

Alternatives

Alternative 1
Accuracy91.7%
Cost1620
\[\begin{array}{l} t_0 := 1 + \frac{\frac{y}{\frac{x}{y}} \cdot -2}{x}\\ t_1 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;y \leq -2 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-198}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-175}:\\ \;\;\;\;\frac{x - y}{\left(y - x\right) + \frac{x \cdot x}{y}}\\ \mathbf{elif}\;y \leq 8.8 \cdot 10^{-163}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy82.6%
Cost1362
\[\begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{-111} \lor \neg \left(y \leq 8.5 \cdot 10^{-198} \lor \neg \left(y \leq 3.2 \cdot 10^{-175}\right) \land y \leq 4 \cdot 10^{-133}\right):\\ \;\;\;\;\frac{x - y}{\left(y - x\right) + \frac{x \cdot x}{y}}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -2}{x}\\ \end{array} \]
Alternative 3
Accuracy82.3%
Cost1233
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{-110}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{-198} \lor \neg \left(y \leq 3.6 \cdot 10^{-175}\right) \land y \leq 3.3 \cdot 10^{-131}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -2}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Accuracy100.0%
Cost1216
\[\frac{x - y}{x \cdot \frac{x}{x + y} + \frac{y}{1 + \frac{x}{y}}} \]
Alternative 5
Accuracy82.1%
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -5.6 \cdot 10^{-137}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-198}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-175}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-133}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Accuracy66.8%
Cost64
\[-1 \]

Error

Reproduce?

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

  :herbie-target
  (if (and (< 0.5 (fabs (/ x y))) (< (fabs (/ x y)) 2.0)) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

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