Average Error: 0.0 → 0.0
Time: 14.9s
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
    (fma.f64 (-.f64 y z) (-.f64 t x) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y z) (-.f64 t x)) x)): 2 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (-.f64 y z) (-.f64 t x)))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error18.5
Cost1112
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x - z \cdot t\\ \mathbf{if}\;y \leq -1835688735862209.3:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.208019825239669 \cdot 10^{-51}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq -4.519078243590432 \cdot 10^{-100}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq -3.2820679115395877 \cdot 10^{-175}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.9734763258488398 \cdot 10^{-220}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;y \leq 4.0608742101895496 \cdot 10^{-24}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error18.5
Cost1112
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x - z \cdot t\\ \mathbf{if}\;y \leq -1835688735862209.3:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.208019825239669 \cdot 10^{-51}:\\ \;\;\;\;y \cdot t - z \cdot t\\ \mathbf{elif}\;y \leq -4.519078243590432 \cdot 10^{-100}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq -3.2820679115395877 \cdot 10^{-175}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.9734763258488398 \cdot 10^{-220}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;y \leq 4.0608742101895496 \cdot 10^{-24}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error38.6
Cost1048
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+84}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.6201892309483175 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.3768113014192407 \cdot 10^{-264}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5.196518449126992 \cdot 10^{-276}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 8.342555390793396 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2.2533371114491533 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 4
Error17.3
Cost976
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := x + x \cdot \left(z - y\right)\\ \mathbf{if}\;x \leq -6.781098480773828 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3112571328983433 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.4537731466248407 \cdot 10^{-82}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.351887022771739 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error38.2
Cost784
\[\begin{array}{l} \mathbf{if}\;y \leq -2.408034525165828 \cdot 10^{-48}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 4.0608742101895496 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3147577253297284600:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+236}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 6
Error39.1
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -1453351.342971835:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -2.3768113014192407 \cdot 10^{-264}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 5.196518449126992 \cdot 10^{-276}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 0.48967129904992285:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 7
Error27.6
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{+84}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.3019813980844087 \cdot 10^{-7}:\\ \;\;\;\;t \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+50}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 8
Error27.3
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{+84}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -1.3019813980844087 \cdot 10^{-7}:\\ \;\;\;\;t \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq 0.05893900090288899:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot x\\ \end{array} \]
Alternative 9
Error11.3
Cost712
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.3019813980844087 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.342555390793396 \cdot 10^{-24}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error10.7
Cost712
\[\begin{array}{l} t_1 := x + z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.3019813980844087 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.3751734163422565 \cdot 10^{-42}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error18.4
Cost584
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.3019813980844087 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.342555390793396 \cdot 10^{-24}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 13
Error38.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1453351.342971835:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 0.48967129904992285:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 14
Error47.5
Cost64
\[x \]

Error

Reproduce

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