?

Average Error: 0.0 → 0.0
Time: 4.5s
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.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(z, 1 - y, x \cdot y\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} \]

    fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error23.8
Cost1180
\[\begin{array}{l} t_0 := z \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -3.05 \cdot 10^{+100}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{+64}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{+41}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{-61}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{-54}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+68}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+187}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error12.0
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{-61} \lor \neg \left(y \leq 1.7 \cdot 10^{-15}\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error12.0
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{-61} \lor \neg \left(y \leq 4.4 \cdot 10^{-15}\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(1 - y\right)\\ \end{array} \]
Alternative 4
Error0.9
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.0006\right):\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[z \cdot \left(1 - y\right) + y \cdot x \]
Alternative 6
Error23.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{-61}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-54}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[z + y \cdot \left(x - z\right) \]
Alternative 8
Error33.9
Cost64
\[z \]

Error

Reproduce?

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