Average Error: 0.0 → 0.0
Time: 10.9s
Precision: binary64
Cost: 6720
\[x \cdot y + z \cdot \left(1 - y\right) \]
\[\mathsf{fma}\left(x - z, y, z\right) \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
(FPCore (x y z) :precision binary64 (fma (- x z) y 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((x - z), y, 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(Float64(x - z), y, 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[(N[(x - z), $MachinePrecision] * y + z), $MachinePrecision]
x \cdot y + z \cdot \left(1 - y\right)
\mathsf{fma}\left(x - z, y, 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. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{y \cdot x + z \cdot \left(1 - y\right)} \]
  3. Simplified0.0

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

Alternatives

Alternative 1
Error24.7
Cost1048
\[\begin{array}{l} t_0 := -y \cdot z\\ \mathbf{if}\;y \leq -3 \cdot 10^{+19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-18}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-126}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-41}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{-10}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+112}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error13.6
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{-63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-126}:\\ \;\;\;\;z\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-39}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-11}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error12.8
Cost584
\[\begin{array}{l} t_0 := \left(1 - y\right) \cdot z\\ \mathbf{if}\;z \leq -1.9 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.95 \cdot 10^{-61}:\\ \;\;\;\;y \cdot \left(x - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.8
Cost584
\[\begin{array}{l} t_0 := y \cdot \left(x - z\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[z + y \cdot \left(-1 \cdot z + x\right) \]
Alternative 6
Error24.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{-15}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 3 \cdot 10^{-61}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 7
Error34.9
Cost64
\[z \]

Error

Reproduce

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