?

Average Error: 0.28% → 0.27%
Time: 5.7s
Precision: binary64
Cost: 6720

?

\[\left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y \]
\[\mathsf{fma}\left(x, 3, -0.41379310344827586\right) \cdot y \]
(FPCore (x y) :precision binary64 (* (* (- x (/ 16.0 116.0)) 3.0) y))
(FPCore (x y) :precision binary64 (* (fma x 3.0 -0.41379310344827586) y))
double code(double x, double y) {
	return ((x - (16.0 / 116.0)) * 3.0) * y;
}
double code(double x, double y) {
	return fma(x, 3.0, -0.41379310344827586) * y;
}
function code(x, y)
	return Float64(Float64(Float64(x - Float64(16.0 / 116.0)) * 3.0) * y)
end
function code(x, y)
	return Float64(fma(x, 3.0, -0.41379310344827586) * y)
end
code[x_, y_] := N[(N[(N[(x - N[(16.0 / 116.0), $MachinePrecision]), $MachinePrecision] * 3.0), $MachinePrecision] * y), $MachinePrecision]
code[x_, y_] := N[(N[(x * 3.0 + -0.41379310344827586), $MachinePrecision] * y), $MachinePrecision]
\left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y
\mathsf{fma}\left(x, 3, -0.41379310344827586\right) \cdot y

Error?

Target

Original0.28%
Target0.27%
Herbie0.27%
\[y \cdot \left(x \cdot 3 - 0.41379310344827586\right) \]

Derivation?

  1. Initial program 0.28

    \[\left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y \]
  2. Simplified0.27

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

    [Start]0.28

    \[ \left(\left(x - \frac{16}{116}\right) \cdot 3\right) \cdot y \]

    *-commutative [=>]0.28

    \[ \color{blue}{\left(3 \cdot \left(x - \frac{16}{116}\right)\right)} \cdot y \]

    sub-neg [=>]0.28

    \[ \left(3 \cdot \color{blue}{\left(x + \left(-\frac{16}{116}\right)\right)}\right) \cdot y \]

    distribute-lft-in [=>]0.27

    \[ \color{blue}{\left(3 \cdot x + 3 \cdot \left(-\frac{16}{116}\right)\right)} \cdot y \]

    *-commutative [=>]0.27

    \[ \left(\color{blue}{x \cdot 3} + 3 \cdot \left(-\frac{16}{116}\right)\right) \cdot y \]

    fma-def [=>]0.27

    \[ \color{blue}{\mathsf{fma}\left(x, 3, 3 \cdot \left(-\frac{16}{116}\right)\right)} \cdot y \]

    metadata-eval [=>]0.27

    \[ \mathsf{fma}\left(x, 3, 3 \cdot \left(-\color{blue}{0.13793103448275862}\right)\right) \cdot y \]

    metadata-eval [=>]0.27

    \[ \mathsf{fma}\left(x, 3, 3 \cdot \color{blue}{-0.13793103448275862}\right) \cdot y \]

    metadata-eval [=>]0.27

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

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

Alternatives

Alternative 1
Error2.85%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -0.14 \lor \neg \left(x \leq 0.14\right):\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;-0.41379310344827586 \cdot y\\ \end{array} \]
Alternative 2
Error2.85%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -0.14:\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;x \leq 0.14:\\ \;\;\;\;-0.41379310344827586 \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot 3\right)\\ \end{array} \]
Alternative 3
Error0.28%
Cost576
\[y \cdot \left(x \cdot 3\right) + -0.41379310344827586 \cdot y \]
Alternative 4
Error0.48%
Cost448
\[3 \cdot \left(y \cdot \left(x + -0.13793103448275862\right)\right) \]
Alternative 5
Error0.47%
Cost448
\[\left(3 \cdot y\right) \cdot \left(x + -0.13793103448275862\right) \]
Alternative 6
Error0.27%
Cost448
\[y \cdot \left(-0.41379310344827586 + x \cdot 3\right) \]
Alternative 7
Error42.79%
Cost192
\[-0.41379310344827586 \cdot y \]

Error

Reproduce?

herbie shell --seed 2023102 
(FPCore (x y)
  :name "Data.Colour.CIE:cieLAB from colour-2.3.3, A"
  :precision binary64

  :herbie-target
  (* y (- (* x 3.0) 0.41379310344827586))

  (* (* (- x (/ 16.0 116.0)) 3.0) y))