Average Error: 0.0 → 0.0
Time: 3.0s
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 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|1 - \frac{x}{y}\right|} \]
    Proof
    (fabs.f64 (-.f64 1 (/.f64 x y))): 0 points increase in error, 0 points decrease in error
    (fabs.f64 (-.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) (/.f64 x y))): 0 points increase in error, 0 points decrease in error
    (fabs.f64 (Rewrite<= div-sub_binary64 (/.f64 (-.f64 y x) y))): 5 points increase in error, 1 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 (fabs.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 (+.f64 y (Rewrite<= mul-1-neg_binary64 (*.f64 -1 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 (*.f64 -1 x))))) (fabs.f64 y)): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error19.1
Cost7120
\[\begin{array}{l} t_0 := \left|\frac{x}{y}\right|\\ \mathbf{if}\;x \leq -5.4 \cdot 10^{+54}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-96}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error25.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.1 \cdot 10^{+151}:\\ \;\;\;\;\frac{x}{y} + -1\\ \mathbf{elif}\;x \leq 7.4 \cdot 10^{+230}:\\ \;\;\;\;\frac{y}{x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error49.2
Cost192
\[\frac{x}{y} \]
Alternative 4
Error63.1
Cost64
\[-1 \]

Error

Reproduce

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