Average Error: 0.0 → 0.0
Time: 4.3s
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
Error24.9
Cost1180
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{+96}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -114672239854.52312:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.423695109329987 \cdot 10^{-105}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.8371282529814475 \cdot 10^{-57}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 5.3 \cdot 10^{+42}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+107}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.06 \cdot 10^{+201}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error16.1
Cost584
\[\begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -9.361948743394583 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.4092068392300965 \cdot 10^{-95}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error7.0
Cost584
\[\begin{array}{l} t_0 := z + y \cdot x\\ \mathbf{if}\;x \leq -1.0313355878424595 \cdot 10^{-131}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.188548355433791 \cdot 10^{-77}:\\ \;\;\;\;z - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.9
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -406.53821263036303:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.032211548072597 \cdot 10^{-5}:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.9
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -406.53821263036303:\\ \;\;\;\;y \cdot x - y \cdot z\\ \mathbf{elif}\;y \leq 2.032211548072597 \cdot 10^{-5}:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \end{array} \]
Alternative 6
Error25.5
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.423695109329987 \cdot 10^{-105}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.8371282529814475 \cdot 10^{-57}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 8
Error34.5
Cost64
\[z \]

Error

Reproduce

herbie shell --seed 2022217 
(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))))