Average Error: 32.5 → 0
Time: 3.3s
Precision: binary64
Cost: 6720
\[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
\[1 - \frac{\left|x\right|}{x} \]
(FPCore (x) :precision binary64 (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))
(FPCore (x) :precision binary64 (- 1.0 (/ (fabs x) x)))
double code(double x) {
	return (x / x) - ((1.0 / x) * sqrt((x * x)));
}
double code(double x) {
	return 1.0 - (fabs(x) / x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x / x) - ((1.0d0 / x) * sqrt((x * x)))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (abs(x) / x)
end function
public static double code(double x) {
	return (x / x) - ((1.0 / x) * Math.sqrt((x * x)));
}
public static double code(double x) {
	return 1.0 - (Math.abs(x) / x);
}
def code(x):
	return (x / x) - ((1.0 / x) * math.sqrt((x * x)))
def code(x):
	return 1.0 - (math.fabs(x) / x)
function code(x)
	return Float64(Float64(x / x) - Float64(Float64(1.0 / x) * sqrt(Float64(x * x))))
end
function code(x)
	return Float64(1.0 - Float64(abs(x) / x))
end
function tmp = code(x)
	tmp = (x / x) - ((1.0 / x) * sqrt((x * x)));
end
function tmp = code(x)
	tmp = 1.0 - (abs(x) / x);
end
code[x_] := N[(N[(x / x), $MachinePrecision] - N[(N[(1.0 / x), $MachinePrecision] * N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 - N[(N[Abs[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x}
1 - \frac{\left|x\right|}{x}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.5
Target0
Herbie0
\[\begin{array}{l} \mathbf{if}\;x < 0:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Derivation

  1. Initial program 32.5

    \[\frac{x}{x} - \frac{1}{x} \cdot \sqrt{x \cdot x} \]
  2. Simplified0

    \[\leadsto \color{blue}{1 - \frac{\left|x\right|}{x}} \]
    Proof
    (-.f64 1 (/.f64 (fabs.f64 x) x)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= *-inverses_binary64 (/.f64 x x)) (/.f64 (fabs.f64 x) x)): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (/.f64 (Rewrite<= rem-sqrt-square_binary64 (sqrt.f64 (*.f64 x x))) x)): 135 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (/.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (sqrt.f64 (*.f64 x x))))) x)): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (neg.f64 (sqrt.f64 (*.f64 x x))))) x)): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 -1 x) (neg.f64 (sqrt.f64 (*.f64 x x)))))): 5 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (*.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 1)) x) (neg.f64 (sqrt.f64 (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (*.f64 (/.f64 (neg.f64 (Rewrite<= *-inverses_binary64 (/.f64 x x))) x) (neg.f64 (sqrt.f64 (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (*.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (/.f64 x x) x))) (neg.f64 (sqrt.f64 (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x x) (*.f64 (neg.f64 (/.f64 (Rewrite=> *-inverses_binary64 1) x)) (neg.f64 (sqrt.f64 (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> cancel-sign-sub_binary64 (+.f64 (/.f64 x x) (*.f64 (/.f64 1 x) (neg.f64 (sqrt.f64 (*.f64 x x)))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (/.f64 x x) (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (/.f64 1 x) (sqrt.f64 (*.f64 x x)))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 x x) (*.f64 (/.f64 1 x) (sqrt.f64 (*.f64 x x))))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0

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

Reproduce

herbie shell --seed 2022302 
(FPCore (x)
  :name "sqrt sqr"
  :precision binary64

  :herbie-target
  (if (< x 0.0) 2.0 0.0)

  (- (/ x x) (* (/ 1.0 x) (sqrt (* x x)))))