Average Error: 0.0 → 0.0
Time: 4.2s
Precision: binary64
Cost: 6720
\[\frac{\left|x - y\right|}{\left|y\right|} \]
\[\left|\frac{y - x}{y}\right| \]
(FPCore (x y) :precision binary64 (/ (fabs (- x y)) (fabs y)))
(FPCore (x y) :precision binary64 (fabs (/ (- y x) y)))
double code(double x, double y) {
	return fabs((x - y)) / fabs(y);
}
double code(double x, double y) {
	return fabs(((y - 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(((y - 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(((y - x) / y));
}
def code(x, y):
	return math.fabs((x - y)) / math.fabs(y)
def code(x, y):
	return math.fabs(((y - x) / y))
function code(x, y)
	return Float64(abs(Float64(x - y)) / abs(y))
end
function code(x, y)
	return abs(Float64(Float64(y - x) / y))
end
function tmp = code(x, y)
	tmp = abs((x - y)) / abs(y);
end
function tmp = code(x, y)
	tmp = abs(((y - 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[(N[(y - x), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\frac{\left|x - y\right|}{\left|y\right|}
\left|\frac{y - x}{y}\right|

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 0.0

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

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

    \[\leadsto \color{blue}{\left|\frac{y - x}{y}\right|} \]
    Proof
    (fabs.f64 (/.f64 (-.f64 y x) y)): 0 points increase in error, 0 points decrease in error
    (Rewrite=> fabs-div_binary64 (/.f64 (fabs.f64 (-.f64 y x)) (fabs.f64 y))): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= fabs-neg_binary64 (fabs.f64 (neg.f64 (-.f64 y x)))) (fabs.f64 y)): 0 points increase in error, 0 points decrease in error
    (/.f64 (fabs.f64 (neg.f64 (Rewrite=> sub-neg_binary64 (+.f64 y (neg.f64 x))))) (fabs.f64 y)): 0 points increase in error, 0 points decrease in error
    (/.f64 (fabs.f64 (neg.f64 (+.f64 y (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x))))) (fabs.f64 y)): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error18.0
Cost6856
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{-17}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-19}:\\ \;\;\;\;\left|\frac{x}{y}\right|\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 2
Error26.0
Cost1115
\[\begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{-20} \lor \neg \left(y \leq -7.6 \cdot 10^{-55} \lor \neg \left(y \leq -7.8 \cdot 10^{-184}\right) \land \left(y \leq 2.22 \cdot 10^{-225} \lor \neg \left(y \leq 3.8 \cdot 10^{-105}\right) \land y \leq 4.5 \cdot 10^{-27}\right)\right):\\ \;\;\;\;\frac{y}{y + x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error26.4
Cost1113
\[\begin{array}{l} t_0 := \frac{y}{y + x}\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -9.4 \cdot 10^{-55}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq -3.05 \cdot 10^{-184}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-225}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{y + x}\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-104} \lor \neg \left(y \leq 4.5 \cdot 10^{-27}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 4
Error26.2
Cost1104
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{-20}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-55}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{-184}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-228}:\\ \;\;\;\;\frac{x \cdot \frac{x}{y}}{y + x}\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-27}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error49.0
Cost192
\[\frac{x}{y} \]
Alternative 6
Error63.1
Cost64
\[-1 \]

Error

Reproduce

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