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

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.3
Target0.0
Herbie0.0
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation

  1. Initial program 10.3

    \[\frac{x + y \cdot \left(z - x\right)}{z} \]
  2. Simplified10.3

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
  3. Applied *-un-lft-identity_binary6410.3

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

    \[\leadsto \frac{\color{blue}{1 \cdot \mathsf{fma}\left(y, z - x, x\right)}}{1 \cdot z} \]
  5. Applied times-frac_binary6410.3

    \[\leadsto \color{blue}{\frac{1}{1} \cdot \frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
  6. Simplified10.3

    \[\leadsto \color{blue}{1} \cdot \frac{\mathsf{fma}\left(y, z - x, x\right)}{z} \]
  7. Simplified3.4

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

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

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

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

Reproduce

herbie shell --seed 2022130 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

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

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