?

Average Error: 0.02% → 0.01%
Time: 6.4s
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
Error38.06%
Cost1181
\[\begin{array}{l} t_0 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{+193}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -100000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-101}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 8.6 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3 \cdot 10^{+66} \lor \neg \left(y \leq 2.9 \cdot 10^{+175}\right) \land y \leq 2.7 \cdot 10^{+265}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error40.68%
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+44}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-75}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-93}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-31}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4200000000:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error25.66%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -7.8 \cdot 10^{-115} \lor \neg \left(x \leq 2.9 \cdot 10^{-92}\right) \land \left(x \leq 1.55 \cdot 10^{-46} \lor \neg \left(x \leq 0.015\right)\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 4
Error21.78%
Cost849
\[\begin{array}{l} t_0 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1.1 \cdot 10^{-105}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.45 \cdot 10^{-91}:\\ \;\;\;\;y \cdot \left(z - x\right)\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-46} \lor \neg \left(x \leq 0.015\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]
Alternative 5
Error1.39%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\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.96%
Cost64
\[x \]

Error

Reproduce?

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