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

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.3
Target0.4
Herbie2.0
\[\frac{x + \left(\frac{y}{t - \frac{x}{z}} - \frac{x}{t \cdot z - x}\right)}{x + 1} \]

Derivation

  1. Initial program 7.3

    \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
  2. Taylor expanded in y around 0 7.3

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{t \cdot z - x}, \frac{x - \frac{x}{t \cdot z - x}}{x + 1}\right)} \]
  4. Applied *-un-lft-identity_binary642.0

    \[\leadsto \mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{t \cdot z - \color{blue}{1 \cdot x}}, \frac{x - \frac{x}{t \cdot z - x}}{x + 1}\right) \]
  5. Applied prod-diff_binary642.0

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

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

Reproduce

herbie shell --seed 2022131 
(FPCore (x y z t)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, A"
  :precision binary64

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

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