Average Error: 0.0 → 0.0
Time: 4.1s
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)): 5 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): 1 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)))): 2 points increase in error, 3 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
Error24.1
Cost1312
\[\begin{array}{l} t_0 := y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -2.25 \cdot 10^{+185}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -6.7 \cdot 10^{+97}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+60}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.550082791497305 \cdot 10^{-45}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 4.5286516582900093 \cdot 10^{-94}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3.595485129602634 \cdot 10^{-60}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 3.0452335094749948 \cdot 10^{-12}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+152}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error16.4
Cost848
\[\begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -3.985721612213249 \cdot 10^{-62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.7189083174769613 \cdot 10^{-125}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -1.91329596511521 \cdot 10^{-182}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.335730456448821 \cdot 10^{-76}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error16.4
Cost848
\[\begin{array}{l} t_0 := z - y \cdot z\\ \mathbf{if}\;z \leq -3.985721612213249 \cdot 10^{-62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.7189083174769613 \cdot 10^{-125}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -1.91329596511521 \cdot 10^{-182}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.335730456448821 \cdot 10^{-76}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \end{array} \]
Alternative 4
Error23.9
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -4.550082791497305 \cdot 10^{-45}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 4.5286516582900093 \cdot 10^{-94}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 3.595485129602634 \cdot 10^{-60}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 3.0452335094749948 \cdot 10^{-12}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Error7.3
Cost584
\[\begin{array}{l} t_0 := z + y \cdot x\\ \mathbf{if}\;x \leq -6.279646425765631 \cdot 10^{-57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.1477110863489958 \cdot 10^{-150}:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.9
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -22.024248586880475:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.017608957232609794:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.0
Cost576
\[z \cdot \left(1 - y\right) + y \cdot x \]
Alternative 8
Error0.0
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 9
Error35.0
Cost64
\[z \]

Error

Reproduce

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