Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5

?

Percentage Accurate: 97.9% → 100.0%
Time: 3.9s
Precision: binary64
Cost: 6720

?

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

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 7 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Target

Original97.9%
Target100.0%
Herbie100.0%
\[y - x \cdot \left(y - z\right) \]

Derivation?

  1. Initial program 98.4%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, y\right)} \]
    Step-by-step derivation

    [Start]98.4

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

    sub-neg [=>]98.4

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

    +-commutative [=>]98.4

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

    distribute-rgt1-in [<=]98.4

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

    associate-+l+ [=>]98.4

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

    +-commutative [=>]98.4

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

    *-commutative [=>]98.4

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

    neg-mul-1 [=>]98.4

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

    associate-*r* [=>]98.4

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

    *-commutative [=>]98.4

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

    distribute-rgt-out [=>]100.0

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

    fma-def [=>]100.0

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

    +-commutative [=>]100.0

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

    *-commutative [=>]100.0

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

    neg-mul-1 [<=]100.0

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

    unsub-neg [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy60.8%
Cost1313
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-15}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-41}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-98}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.56 \cdot 10^{-71}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 430000000000:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+50} \lor \neg \left(x \leq 1.22 \cdot 10^{+191}\right) \land x \leq 3.2 \cdot 10^{+266}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 2
Accuracy83.8%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-16} \lor \neg \left(x \leq -5.2 \cdot 10^{-41}\right) \land \left(x \leq -1.65 \cdot 10^{-97} \lor \neg \left(x \leq 3.3 \cdot 10^{-72}\right)\right):\\ \;\;\;\;x \cdot \left(z - y\right)\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 3
Accuracy60.4%
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -9.6 \cdot 10^{-18}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-40}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-97}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq 1.56 \cdot 10^{-71}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 4
Accuracy75.2%
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -5.8 \cdot 10^{+49}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{+17}:\\ \;\;\;\;y \cdot \left(1 - x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
Alternative 5
Accuracy97.9%
Cost576
\[x \cdot z + y \cdot \left(1 - x\right) \]
Alternative 6
Accuracy36.4%
Cost64
\[y \]

Reproduce?

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