?

Average Accuracy: 100.0% → 100.0%
Time: 5.3s
Precision: binary64
Cost: 6720

?

\[\frac{\left|x - y\right|}{\left|y\right|} \]
\[\left|1 - \frac{x}{y}\right| \]
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
(FPCore (x y) :precision binary64 (fabs (- 1.0 (/ x y))))
double code(double x, double y) {
	return fabs((x - y)) / fabs(y);
}
double code(double x, double y) {
	return fabs((1.0 - (x / y)));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = abs((x - y)) / abs(y)
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = abs((1.0d0 - (x / y)))
end function
public static double code(double x, double y) {
	return Math.abs((x - y)) / Math.abs(y);
}
public static double code(double x, double y) {
	return Math.abs((1.0 - (x / y)));
}
def code(x, y):
	return math.fabs((x - y)) / math.fabs(y)
def code(x, y):
	return math.fabs((1.0 - (x / y)))
function code(x, y)
	return Float64(abs(Float64(x - y)) / abs(y))
end
function code(x, y)
	return abs(Float64(1.0 - Float64(x / y)))
end
function tmp = code(x, y)
	tmp = abs((x - y)) / abs(y);
end
function tmp = code(x, y)
	tmp = abs((1.0 - (x / y)));
end
code[x_, y_] := N[(N[Abs[N[(x - y), $MachinePrecision]], $MachinePrecision] / N[Abs[y], $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[Abs[N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\frac{\left|x - y\right|}{\left|y\right|}
\left|1 - \frac{x}{y}\right|

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 100.0%

    \[\frac{\left|x - y\right|}{\left|y\right|} \]
  2. Taylor expanded in x around -inf 100.0%

    \[\leadsto \color{blue}{\frac{\left|-\left(y + -1 \cdot x\right)\right|}{\left|y\right|}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\left|\frac{y - x}{y}\right|} \]
    Proof

    [Start]100.0

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

    mul-1-neg [=>]100.0

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

    sub-neg [<=]100.0

    \[ \frac{\left|-\color{blue}{\left(y - x\right)}\right|}{\left|y\right|} \]

    fabs-neg [=>]100.0

    \[ \frac{\color{blue}{\left|y - x\right|}}{\left|y\right|} \]

    fabs-div [<=]100.0

    \[ \color{blue}{\left|\frac{y - x}{y}\right|} \]
  4. Taylor expanded in y around 0 100.0%

    \[\leadsto \left|\color{blue}{1 + -1 \cdot \frac{x}{y}}\right| \]
  5. Simplified100.0%

    \[\leadsto \left|\color{blue}{1 - \frac{x}{y}}\right| \]
    Proof

    [Start]100.0

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

    mul-1-neg [=>]100.0

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

    sub-neg [<=]100.0

    \[ \left|\color{blue}{1 - \frac{x}{y}}\right| \]
  6. Final simplification100.0%

    \[\leadsto \left|1 - \frac{x}{y}\right| \]

Alternatives

Alternative 1
Accuracy70.0%
Cost7517
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ t_1 := \frac{y}{x + y}\\ \mathbf{if}\;x \leq -1.65 \cdot 10^{+157}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.7 \cdot 10^{+44}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-34}:\\ \;\;\;\;\frac{1}{y} \cdot \left(y \cdot t_1\right)\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-98} \lor \neg \left(x \leq 4.7 \cdot 10^{-51}\right) \land x \leq 1.75 \cdot 10^{+27}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy59.3%
Cost452
\[\begin{array}{l} \mathbf{if}\;x \leq -2.8 \cdot 10^{+229}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x + y}\\ \end{array} \]
Alternative 3
Accuracy59.8%
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{+227}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Accuracy22.9%
Cost192
\[\frac{x}{y} \]
Alternative 5
Accuracy1.4%
Cost64
\[-1 \]

Error

Reproduce?

herbie shell --seed 2023141 
(FPCore (x y)
  :name "Numeric.LinearAlgebra.Util:formatSparse from hmatrix-0.16.1.5"
  :precision binary64
  (/ (fabs (- x y)) (fabs y)))