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

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.9
Target2.0
Herbie2.0
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Initial program 6.9

    \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  2. Simplified6.7

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

    \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{y \cdot x}{t}} \]
  4. Simplified2.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)} \]
  5. Final simplification2.0

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

Reproduce

herbie shell --seed 2022133 
(FPCore (x y z t)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
  :precision binary64

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

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