Average Error: 0.0 → 0.0
Time: 3.9s
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
    (fma.f64 y (-.f64 x z) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (-.f64 x (Rewrite<= *-lft-identity_binary64 (*.f64 1 z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (Rewrite=> cancel-sign-sub-inv_binary64 (+.f64 x (*.f64 (neg.f64 1) z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (+.f64 x (*.f64 (Rewrite=> metadata-eval -1) z)) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (+.f64 x (Rewrite<= *-commutative_binary64 (*.f64 z -1))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 z -1) x)) z): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (+.f64 (*.f64 z -1) x)) z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (*.f64 z -1) y) (*.f64 x y))) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 z (*.f64 -1 y))) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 z (Rewrite<= neg-mul-1_binary64 (neg.f64 y))) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 y) z)) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 z (+.f64 (*.f64 (neg.f64 y) z) (*.f64 x y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 z)) (+.f64 (*.f64 (neg.f64 y) z) (*.f64 x y))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 1 z) (*.f64 (neg.f64 y) z)) (*.f64 x y))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 z (+.f64 1 (neg.f64 y)))) (*.f64 x y)): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 z (Rewrite<= sub-neg_binary64 (-.f64 1 y))) (*.f64 x y)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x y) (*.f64 z (-.f64 1 y)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error23.9
Cost916
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -5.2 \cdot 10^{+65}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -27000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-20}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error12.1
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{-20} \lor \neg \left(y \leq 0.0019\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error14.8
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -4.2 \cdot 10^{+37} \lor \neg \left(z \leq 1.2 \cdot 10^{-172}\right):\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \end{array} \]
Alternative 4
Error23.2
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{-20}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 0.00085:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Error0.0
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 6
Error35.2
Cost64
\[z \]

Error

Reproduce

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