?

Average Error: 0.0 → 0.0
Time: 5.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)} \]
    Proof

    [Start]0.0

    \[ x \cdot y + z \cdot \left(1 - y\right) \]

    +-commutative [=>]0.0

    \[ \color{blue}{z \cdot \left(1 - y\right) + x \cdot y} \]

    sub-neg [=>]0.0

    \[ z \cdot \color{blue}{\left(1 + \left(-y\right)\right)} + x \cdot y \]

    distribute-rgt-in [=>]0.0

    \[ \color{blue}{\left(1 \cdot z + \left(-y\right) \cdot z\right)} + x \cdot y \]

    associate-+l+ [=>]0.0

    \[ \color{blue}{1 \cdot z + \left(\left(-y\right) \cdot z + x \cdot y\right)} \]

    *-lft-identity [=>]0.0

    \[ \color{blue}{z} + \left(\left(-y\right) \cdot z + x \cdot y\right) \]

    +-commutative [=>]0.0

    \[ \color{blue}{\left(\left(-y\right) \cdot z + x \cdot y\right) + z} \]

    *-commutative [=>]0.0

    \[ \left(\color{blue}{z \cdot \left(-y\right)} + x \cdot y\right) + z \]

    neg-mul-1 [=>]0.0

    \[ \left(z \cdot \color{blue}{\left(-1 \cdot y\right)} + x \cdot y\right) + z \]

    associate-*r* [=>]0.0

    \[ \left(\color{blue}{\left(z \cdot -1\right) \cdot y} + x \cdot y\right) + z \]

    distribute-rgt-out [=>]0.0

    \[ \color{blue}{y \cdot \left(z \cdot -1 + x\right)} + z \]

    fma-def [=>]0.0

    \[ \color{blue}{\mathsf{fma}\left(y, z \cdot -1 + x, z\right)} \]

    +-commutative [=>]0.0

    \[ \mathsf{fma}\left(y, \color{blue}{x + z \cdot -1}, z\right) \]

    *-commutative [=>]0.0

    \[ \mathsf{fma}\left(y, x + \color{blue}{-1 \cdot z}, z\right) \]

    metadata-eval [<=]0.0

    \[ \mathsf{fma}\left(y, x + \color{blue}{\left(-1\right)} \cdot z, z\right) \]

    cancel-sign-sub-inv [<=]0.0

    \[ \mathsf{fma}\left(y, \color{blue}{x - 1 \cdot z}, z\right) \]

    *-lft-identity [=>]0.0

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

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

Alternatives

Alternative 1
Error24.2
Cost1312
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -7.8 \cdot 10^{+235}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{+114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -0.00115:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-108}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-53}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-19}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+89}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+177}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error13.1
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -0.00115:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-108}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{-53}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{-23}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error13.0
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ t_1 := z \cdot \left(1 - y\right)\\ \mathbf{if}\;y \leq -0.0012:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.32 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-54}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 112000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error24.2
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -0.00115:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-108}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-54}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-25}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Error1.0
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1100000000 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 6
Error0.0
Cost576
\[z \cdot \left(1 - y\right) + y \cdot x \]
Alternative 7
Error0.0
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 8
Error34.5
Cost64
\[z \]

Error

Reproduce?

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