Average Error: 0.0 → 0.0
Time: 5.2s
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 (Rewrite<= unsub-neg_binary64 (+.f64 x (neg.f64 z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 y (+.f64 x (Rewrite=> neg-mul-1_binary64 (*.f64 -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)): 2 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): 3 points increase in error, 1 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 (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 x y) (*.f64 z (neg.f64 y)))) z): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 x y) (+.f64 (*.f64 z (neg.f64 y)) z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (+.f64 (*.f64 z (neg.f64 y)) (Rewrite<= *-rgt-identity_binary64 (*.f64 z 1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= distribute-lft-in_binary64 (*.f64 z (+.f64 (neg.f64 y) 1)))): 1 points increase in error, 1 points decrease in error
    (+.f64 (*.f64 x y) (*.f64 z (Rewrite<= +-commutative_binary64 (+.f64 1 (neg.f64 y))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (*.f64 z (Rewrite<= sub-neg_binary64 (-.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
Error16.6
Cost848
\[\begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -3.2933607638474874 \cdot 10^{-165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.1386915803324425 \cdot 10^{-155}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 1.4042606673334923 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.290828382452338 \cdot 10^{-50}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error16.6
Cost848
\[\begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -3.2933607638474874 \cdot 10^{-165}:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 4.1386915803324425 \cdot 10^{-155}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 1.4042606673334923 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.290828382452338 \cdot 10^{-50}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error13.9
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -5.260601477956649 \cdot 10^{-44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.1673765361379012 \cdot 10^{-91}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -2.2661590939021562 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1801996833229082 \cdot 10^{-62}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error13.9
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -5.260601477956649 \cdot 10^{-44}:\\ \;\;\;\;y \cdot x - y \cdot z\\ \mathbf{elif}\;y \leq -1.1673765361379012 \cdot 10^{-91}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -2.2661590939021562 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1801996833229082 \cdot 10^{-62}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error25.1
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -5.260601477956649 \cdot 10^{-44}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -1.1673765361379012 \cdot 10^{-91}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq -2.2661590939021562 \cdot 10^{-130}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.1801996833229082 \cdot 10^{-62}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error24.8
Cost652
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -5134819766.445983:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1801996833229082 \cdot 10^{-62}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+115}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 8
Error35.3
Cost64
\[z \]

Error

Reproduce

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