?

Average Error: 0.02% → 0.01%
Time: 4.6s
Precision: binary64
Cost: 6720

?

\[x + y \cdot \left(z - x\right) \]
\[\mathsf{fma}\left(y, z - x, x\right) \]
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
(FPCore (x y z) :precision binary64 (fma y (- z x) x))
double code(double x, double y, double z) {
	return x + (y * (z - x));
}
double code(double x, double y, double z) {
	return fma(y, (z - x), x);
}
function code(x, y, z)
	return Float64(x + Float64(y * Float64(z - x)))
end
function code(x, y, z)
	return fma(y, Float64(z - x), x)
end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
x + y \cdot \left(z - x\right)
\mathsf{fma}\left(y, z - x, x\right)

Error?

Derivation?

  1. Initial program 0.02

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

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

    [Start]0.02

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

    +-commutative [=>]0.02

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

    fma-def [=>]0.01

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

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

Alternatives

Alternative 1
Error31.41%
Cost1114
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+183}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -4 \cdot 10^{+27} \lor \neg \left(z \leq -1.02 \cdot 10^{-14}\right) \land \left(z \leq 1.95 \cdot 10^{-14} \lor \neg \left(z \leq 9.7 \cdot 10^{+120}\right) \land z \leq 4.7 \cdot 10^{+160}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 2
Error29.31%
Cost1112
\[\begin{array}{l} t_0 := y \cdot \left(z - x\right)\\ t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+183}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.7 \cdot 10^{+120}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{+160}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 3
Error47.48%
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+183}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{+29}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-15}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9.2 \cdot 10^{+120}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 4.7 \cdot 10^{+160}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 4
Error38.42%
Cost588
\[\begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+72}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-74}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 5
Error1.56%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 7.6 \cdot 10^{-6}\right):\\ \;\;\;\;y \cdot \left(z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot z\\ \end{array} \]
Alternative 6
Error0.02%
Cost448
\[x + y \cdot \left(z - x\right) \]
Alternative 7
Error54.32%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023102 
(FPCore (x y z)
  :name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
  :precision binary64
  (+ x (* y (- z x))))