?

Average Error: 0.0 → 0.0
Time: 12.1s
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
Error19.4
Cost1112
\[\begin{array}{l} t_1 := x + y \cdot t\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := y \cdot \left(t - x\right)\\ \mathbf{if}\;z \leq -2.45 \cdot 10^{+17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-37}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{-91}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.1 \cdot 10^{+28}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error31.2
Cost1100
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -1 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 0.02:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+100}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error23.8
Cost980
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.3 \cdot 10^{-46}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;x \leq -3.15 \cdot 10^{-102}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-118}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{+16}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error23.9
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{elif}\;x \leq -3.7 \cdot 10^{-45}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;x \leq -1.08 \cdot 10^{-105}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;x \leq -5.4 \cdot 10^{-118}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;x \leq 1.66 \cdot 10^{+16}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot x\\ \end{array} \]
Alternative 5
Error16.8
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-118} \lor \neg \left(x \leq 1.4 \cdot 10^{-67} \lor \neg \left(x \leq 2.95 \cdot 10^{-32}\right) \land x \leq 6.2 \cdot 10^{-6}\right):\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 6
Error24.0
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-9} \lor \neg \left(x \leq -7.6 \cdot 10^{-94} \lor \neg \left(x \leq -2.9 \cdot 10^{-118}\right) \land x \leq 1.55 \cdot 10^{+16}\right):\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \end{array} \]
Alternative 7
Error24.4
Cost848
\[\begin{array}{l} t_1 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;x \leq -1.56 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-105}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-118}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{+16}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error0.0
Cost832
\[\left(x + \left(y - z\right) \cdot t\right) + x \cdot \left(z - y\right) \]
Alternative 9
Error12.3
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1 \cdot 10^{-71} \lor \neg \left(t \leq 2 \cdot 10^{-184}\right):\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\ \end{array} \]
Alternative 10
Error12.3
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.7 \cdot 10^{-70} \lor \neg \left(t \leq 2 \cdot 10^{-184}\right):\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x - \left(y - z\right) \cdot x\\ \end{array} \]
Alternative 11
Error38.6
Cost652
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3 \cdot 10^{-36}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+100}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error38.6
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -3.6 \cdot 10^{-37}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 0.0175:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 14
Error47.6
Cost64
\[x \]

Error

Reproduce?

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