?

Average Error: 0.02% → 0.02%
Time: 5.3s
Precision: binary64
Cost: 6848

?

\[x \cdot y + z \cdot \left(1 - y\right) \]
\[\mathsf{fma}\left(z, 1 - y, y \cdot x\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
(FPCore (x y z) :precision binary64 (fma z (- 1.0 y) (* y x)))
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(z, (1.0 - y), (y * x));
}
function code(x, y, z)
	return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y)))
end
function code(x, y, z)
	return fma(z, Float64(1.0 - y), Float64(y * x))
end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(z * N[(1.0 - y), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]
x \cdot y + z \cdot \left(1 - y\right)
\mathsf{fma}\left(z, 1 - y, y \cdot x\right)

Error?

Target

Original0.02%
Target0.02%
Herbie0.02%
\[z - \left(z - x\right) \cdot y \]

Derivation?

  1. Initial program 0.02

    \[x \cdot y + z \cdot \left(1 - y\right) \]
  2. Simplified0.02

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

    [Start]0.02

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

    +-commutative [=>]0.02

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

    fma-def [=>]0.02

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

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

Alternatives

Alternative 1
Error37.65%
Cost1578
\[\begin{array}{l} t_0 := z \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+123}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{+18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.65 \cdot 10^{-56}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-80}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{-65}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 0.0016:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+43} \lor \neg \left(y \leq 1.55 \cdot 10^{+88}\right) \land \left(y \leq 3.1 \cdot 10^{+197} \lor \neg \left(y \leq 3.3 \cdot 10^{+248}\right)\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error19.75%
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -2.65 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-80}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-66}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 0.0016:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.62%
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -2.4 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-80}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-66}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 900:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error37.19%
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{-56}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-80}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-65}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 0.0016:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Error1.39%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -520000000 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 6
Error0.02%
Cost576
\[z \cdot \left(1 - y\right) + y \cdot x \]
Alternative 7
Error0.02%
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 8
Error55.08%
Cost64
\[z \]

Error

Reproduce?

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