Average Error: 0.1 → 0.0
Time: 2.4s
Precision: binary64
\[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
\[\mathsf{fma}\left(4, \frac{x}{z} - \frac{y}{z}, -2\right) \]
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
(FPCore (x y z) :precision binary64 (fma 4.0 (- (/ x z) (/ y z)) -2.0))
double code(double x, double y, double z) {
	return (4.0 * ((x - y) - (z * 0.5))) / z;
}
double code(double x, double y, double z) {
	return fma(4.0, ((x / z) - (y / z)), -2.0);
}
function code(x, y, z)
	return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z)
end
function code(x, y, z)
	return fma(4.0, Float64(Float64(x / z) - Float64(y / z)), -2.0)
end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(4.0 * N[(N[(x / z), $MachinePrecision] - N[(y / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\mathsf{fma}\left(4, \frac{x}{z} - \frac{y}{z}, -2\right)

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Initial program 0.1

    \[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
  2. Simplified0.0

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

    \[\leadsto \mathsf{fma}\left(4, \color{blue}{\frac{x}{z} - \frac{y}{z}}, -2\right) \]
  4. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(4, \frac{x}{z} - \frac{y}{z}, -2\right) \]

Reproduce

herbie shell --seed 2022131 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, B"
  :precision binary64

  :herbie-target
  (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))

  (/ (* 4.0 (- (- x y) (* z 0.5))) z))