Average Error: 0.0 → 0.0
Time: 18.3s
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)): 4 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
Error32.6
Cost1576
\[\begin{array}{l} t_1 := x - y \cdot x\\ t_2 := t \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -9 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -27333242142430776:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -4.2639266358459603 \cdot 10^{-38}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.707731469368165 \cdot 10^{-249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.9953223320530253 \cdot 10^{-275}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 6.285836421106061 \cdot 10^{-279}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.287880415110765 \cdot 10^{-250}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq 974.1585910149532:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+78}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+86}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 2
Error40.1
Cost1312
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -1.0929092677532016 \cdot 10^{-17}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -1.8046586632987013 \cdot 10^{-236}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.0783798613577392 \cdot 10^{-256}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.672665252247644 \cdot 10^{-296}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.603206918980996 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.168536305781518 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.725795680363493 \cdot 10^{+22}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+74}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 3
Error19.1
Cost1240
\[\begin{array}{l} t_1 := x + y \cdot t\\ t_2 := \left(y - z\right) \cdot t\\ t_3 := x + x \cdot \left(z - y\right)\\ \mathbf{if}\;t \leq -3.8 \cdot 10^{+75}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -396863541848.92395:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.8634304916030509 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4.043733290272684 \cdot 10^{-84}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -2.501562771751601 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.751147846242511 \cdot 10^{-67}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error31.7
Cost1112
\[\begin{array}{l} t_1 := x + y \cdot t\\ t_2 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;t \leq -1.8634304916030509 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -6.1253058092683645 \cdot 10^{-61}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.501562771751601 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.6268324697022955 \cdot 10^{-229}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.0211797162069412 \cdot 10^{-91}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;t \leq 8.8 \cdot 10^{+70}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-z\right)\\ \end{array} \]
Alternative 5
Error11.8
Cost976
\[\begin{array}{l} t_1 := x + x \cdot \left(z - y\right)\\ t_2 := x + \left(y - z\right) \cdot t\\ \mathbf{if}\;t \leq -1.8634304916030509 \cdot 10^{-13}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -4.043733290272684 \cdot 10^{-84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.501562771751601 \cdot 10^{-127}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.4112263516040276 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error27.9
Cost916
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -9 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -27333242142430776:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -6.393020503804921 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5867379082486357 \cdot 10^{-32}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 7
Error19.3
Cost848
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -3.6248184983166162 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5867379082486357 \cdot 10^{-32}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;z \leq 6.4 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{+114}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error0.0
Cost832
\[x + \left(x \cdot \left(z - y\right) + \left(y - z\right) \cdot t\right) \]
Alternative 9
Error39.1
Cost784
\[\begin{array}{l} \mathbf{if}\;y \leq -1.0929092677532016 \cdot 10^{-17}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1.168536305781518 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.725795680363493 \cdot 10^{+22}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 4.8 \cdot 10^{+74}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 10
Error19.4
Cost716
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -6.117468417710365 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.168536305781518 \cdot 10^{-79}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 9.693468110927702 \cdot 10^{+21}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error38.9
Cost588
\[\begin{array}{l} \mathbf{if}\;y \leq -1.0929092677532016 \cdot 10^{-17}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 1.168536305781518 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.725795680363493 \cdot 10^{+22}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 12
Error18.5
Cost584
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -3.6248184983166162 \cdot 10^{-6}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5867379082486357 \cdot 10^{-32}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error0.0
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 14
Error39.1
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -3.6248184983166162 \cdot 10^{-6}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 2.3860898821604816 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 15
Error47.5
Cost64
\[x \]

Error

Reproduce

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