Average Error: 0.0 → 0.0
Time: 3.7s
Precision: binary64
Cost: 6848
\[\left(1 - x\right) \cdot y + x \cdot z \]
\[\mathsf{fma}\left(1 - x, y, x \cdot z\right) \]
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
(FPCore (x y z) :precision binary64 (fma (- 1.0 x) y (* x z)))
double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
double code(double x, double y, double z) {
	return fma((1.0 - x), y, (x * z));
}
function code(x, y, z)
	return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z))
end
function code(x, y, z)
	return fma(Float64(1.0 - x), y, Float64(x * z))
end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(1.0 - x), $MachinePrecision] * y + N[(x * z), $MachinePrecision]), $MachinePrecision]
\left(1 - x\right) \cdot y + x \cdot z
\mathsf{fma}\left(1 - x, y, x \cdot z\right)

Error

Target

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

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(1 - x, y, x \cdot z\right)} \]
    Proof
    (fma.f64 (-.f64 1 x) y (*.f64 x z)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 1 x) y) (*.f64 x z))): 2 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost6720
\[\mathsf{fma}\left(x, z - y, y\right) \]
Alternative 2
Error24.0
Cost784
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{-16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-21}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 220000000:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 6 \cdot 10^{+58}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 3
Error12.0
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{-16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.3 \cdot 10^{-17}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.0
Cost584
\[\begin{array}{l} t_0 := x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.76 \cdot 10^{-12}:\\ \;\;\;\;y + x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.0
Cost576
\[\left(1 - x\right) \cdot y + x \cdot z \]
Alternative 6
Error23.7
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{-17}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 6 \cdot 10^{-24}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 7
Error0.0
Cost448
\[y + x \cdot \left(z - y\right) \]
Alternative 8
Error35.4
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 2022331 
(FPCore (x y z)
  :name "Diagrams.Color.HSV:lerp  from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (- y (* x (- y z)))

  (+ (* (- 1.0 x) y) (* x z)))