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

Error

Target

Original0.0
Target0.0
Herbie0.0
\[z - \left(z - x\right) \cdot y \]

Derivation

  1. Initial program 0.0

    \[x \cdot y + z \cdot \left(1 - y\right) \]
  2. Simplified0.0

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

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

Alternatives

Alternative 1
Error17.7
Cost1112
\[\begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -2.5038571055156836 \cdot 10^{-27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.397015299728275 \cdot 10^{-75}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -2.142898990248836 \cdot 10^{-149}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.3293971760662845 \cdot 10^{-212}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 2.6290663705422513 \cdot 10^{-162}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3664895809646704 \cdot 10^{-55}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error25.2
Cost1048
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -5.1 \cdot 10^{+36}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -25797787656.342686:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -5.593767511656747 \cdot 10^{-123}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 5.841420377191197 \cdot 10^{-17}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+75}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+144}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 3
Error9.2
Cost848
\[\begin{array}{l} t_0 := z - y \cdot z\\ t_1 := z + y \cdot x\\ \mathbf{if}\;z \leq -1.3132551898705475 \cdot 10^{+74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.6820249479386225 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.119207062164188 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.1407871930028805 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.0
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -25797787656.342686:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.009758804437583346:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[z \cdot \left(1 - y\right) + y \cdot x \]
Alternative 6
Error25.0
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -5.593767511656747 \cdot 10^{-123}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 5.841420377191197 \cdot 10^{-17}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 7
Error35.3
Cost64
\[z \]

Error

Reproduce

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

  :herbie-target
  (- z (* (- z x) y))

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