Average Error: 9.7 → 1.6
Time: 3.1s
Precision: binary64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\frac{y}{\frac{z}{x}} + \left(\frac{x}{z} - x\right) \]
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z) :precision binary64 (+ (/ y (/ z x)) (- (/ x z) x)))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
	return (y / (z / x)) + ((x / z) - x);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * ((y - z) + 1.0d0)) / z
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (y / (z / x)) + ((x / z) - x)
end function
public static double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
public static double code(double x, double y, double z) {
	return (y / (z / x)) + ((x / z) - x);
}
def code(x, y, z):
	return (x * ((y - z) + 1.0)) / z
def code(x, y, z):
	return (y / (z / x)) + ((x / z) - x)
function code(x, y, z)
	return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z)
end
function code(x, y, z)
	return Float64(Float64(y / Float64(z / x)) + Float64(Float64(x / z) - x))
end
function tmp = code(x, y, z)
	tmp = (x * ((y - z) + 1.0)) / z;
end
function tmp = code(x, y, z)
	tmp = (y / (z / x)) + ((x / z) - x);
end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\frac{y}{\frac{z}{x}} + \left(\frac{x}{z} - x\right)

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.7
Target0.5
Herbie1.6
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Derivation

  1. Initial program 9.7

    \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
  2. Simplified3.4

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
  3. Taylor expanded in x around 0 3.5

    \[\leadsto \color{blue}{\left(\left(\frac{y}{z} + \frac{1}{z}\right) - 1\right) \cdot x} \]
  4. Applied egg-rr3.5

    \[\leadsto \color{blue}{\frac{y}{z} \cdot x + \left(\frac{1}{z} + -1\right) \cdot x} \]
  5. Applied egg-rr1.7

    \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} + \left(\frac{1}{z} + -1\right) \cdot x \]
  6. Taylor expanded in z around 0 1.6

    \[\leadsto \frac{y}{\frac{z}{x}} + \color{blue}{\left(\frac{x}{z} - x\right)} \]
  7. Final simplification1.6

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

Reproduce

herbie shell --seed 2022165 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

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