?

Average Error: 0.0 → 0.0
Time: 12.2s
Precision: binary64
Cost: 6848

?

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

Error?

Target

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

Derivation?

  1. Initial program 0.0

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

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

    [Start]0.0

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

    +-commutative [=>]0.0

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

    fma-def [=>]0.0

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

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

Alternatives

Alternative 1
Error23.1
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ t_3 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -6 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.3 \cdot 10^{-120}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-149}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq -1.75 \cdot 10^{-221}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.15 \cdot 10^{-295}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-303}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{-254}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-8}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error29.4
Cost1361
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -1 \cdot 10^{+75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{+19}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y - z \leq -5 \cdot 10^{-5} \lor \neg \left(y - z \leq 10^{-10}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error38.8
Cost1248
\[\begin{array}{l} t_1 := -z \cdot t\\ \mathbf{if}\;z \leq -2 \cdot 10^{+51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1750000:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.02 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{-122}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-149}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-303}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{-254}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 4
Error38.5
Cost984
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-123}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-149}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-304}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{-248}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 5
Error26.6
Cost850
\[\begin{array}{l} \mathbf{if}\;t \leq -4 \cdot 10^{-137} \lor \neg \left(t \leq 1.18 \cdot 10^{-26}\right) \land \left(t \leq 9.5 \cdot 10^{+19} \lor \neg \left(t \leq 2.65 \cdot 10^{+42}\right)\right):\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \end{array} \]
Alternative 6
Error21.9
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -4 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-121}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{-149}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq 5.05 \cdot 10^{-8}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error18.5
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ \mathbf{if}\;z \leq -6 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{-187}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-71}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error0.0
Cost832
\[x + \left(y \cdot \left(t - x\right) + z \cdot \left(x - t\right)\right) \]
Alternative 9
Error10.8
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{-10} \lor \neg \left(z \leq 5.2 \cdot 10^{-5}\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 10
Error10.2
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{-13} \lor \neg \left(z \leq 5.1 \cdot 10^{-6}\right):\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 12
Error38.1
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{-45}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Error47.0
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023018 
(FPCore (x y z t)
  :name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
  :precision binary64

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

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