?

Average Accuracy: 100.0% → 100.0%
Time: 16.7s
Precision: binary64
Cost: 7104

?

\[x + \left(y - z\right) \cdot \left(t - x\right) \]
\[\mathsf{fma}\left(\left(z - y\right) + 1, x, t \cdot \left(y - z\right)\right) \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
(FPCore (x y z t) :precision binary64 (fma (+ (- z y) 1.0) x (* t (- y z))))
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(((z - y) + 1.0), x, (t * (y - z)));
}
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(Float64(z - y) + 1.0), x, Float64(t * Float64(y - z)))
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[(N[(z - y), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x + \left(y - z\right) \cdot \left(t - x\right)
\mathsf{fma}\left(\left(z - y\right) + 1, x, t \cdot \left(y - z\right)\right)

Error?

Target

Original100.0%
Target100.0%
Herbie100.0%
\[x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right) \]

Derivation?

  1. Initial program 100.0%

    \[x + \left(y - z\right) \cdot \left(t - x\right) \]
  2. Applied egg-rr100.0%

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

    [Start]100.0

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

    *-commutative [=>]100.0

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

    sub-neg [=>]100.0

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

    distribute-lft-in [=>]100.0

    \[ x + \color{blue}{\left(\left(t - x\right) \cdot y + \left(t - x\right) \cdot \left(-z\right)\right)} \]
  3. Taylor expanded in t around -inf 100.0%

    \[\leadsto \color{blue}{z \cdot x + \left(-1 \cdot \left(y \cdot x\right) + \left(x + -1 \cdot \left(t \cdot \left(z + -1 \cdot y\right)\right)\right)\right)} \]
  4. Simplified100.0%

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

    [Start]100.0

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

    associate-+r+ [=>]100.0

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

    associate-*r* [=>]100.0

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

    distribute-rgt-in [<=]100.0

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

    mul-1-neg [=>]100.0

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

    sub-neg [<=]100.0

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

    mul-1-neg [=>]100.0

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

    unsub-neg [=>]100.0

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

    mul-1-neg [=>]100.0

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

    sub-neg [<=]100.0

    \[ x \cdot \left(z - y\right) + \left(x - t \cdot \color{blue}{\left(z - y\right)}\right) \]
  5. Applied egg-rr100.0%

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

    [Start]100.0

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

    associate-+r- [=>]100.0

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

    *-commutative [=>]100.0

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

    distribute-lft1-in [=>]100.0

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

    fma-neg [=>]100.0

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

    *-commutative [=>]100.0

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

    distribute-rgt-neg-in [=>]100.0

    \[ \mathsf{fma}\left(\left(z - y\right) + 1, x, \color{blue}{\left(z - y\right) \cdot \left(-t\right)}\right) \]
  6. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy100.0%
Cost6848
\[\mathsf{fma}\left(y - z, t - x, x\right) \]
Alternative 2
Accuracy46.8%
Cost1905
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ t_2 := x \cdot \left(-y\right)\\ \mathbf{if}\;t \leq -2.6 \cdot 10^{-191}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -9 \cdot 10^{-285}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.3 \cdot 10^{-306}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 10^{-274}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.2 \cdot 10^{-231}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{-200}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 10^{-164}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 4.4 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.8 \cdot 10^{-76}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;t \leq 2.1 \cdot 10^{-51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6.6 \cdot 10^{-21} \lor \neg \left(t \leq 0.0018\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy53.3%
Cost1376
\[\begin{array}{l} t_1 := x \cdot \left(-y\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -255000000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.55 \cdot 10^{-171}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{-227}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-273}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-296}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-79}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.8 \cdot 10^{-32}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{-10}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy68.0%
Cost1376
\[\begin{array}{l} t_1 := x + y \cdot t\\ t_2 := x - y \cdot x\\ t_3 := z \cdot \left(x - t\right)\\ t_4 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -260000000000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{-78}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{-118}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{-142}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq -9.5 \cdot 10^{-233}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{-139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-84}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-34}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Accuracy79.7%
Cost1240
\[\begin{array}{l} t_1 := t \cdot \left(y - z\right)\\ t_2 := z \cdot \left(x - t\right)\\ t_3 := x - y \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -1.2 \cdot 10^{+47}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-5}:\\ \;\;\;\;x - x \cdot \left(y - z\right)\\ \mathbf{elif}\;z \leq -2.5 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-122}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-34}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Accuracy65.8%
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ t_3 := t \cdot \left(y - z\right)\\ \mathbf{if}\;z \leq -500000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-75}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-231}:\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{-139}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-84}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy61.6%
Cost980
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := x \cdot \left(z + 1\right)\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -1.55 \cdot 10^{-248}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{elif}\;y \leq 2.95 \cdot 10^{-190}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+16}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy80.2%
Cost976
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x - y \cdot \left(x - t\right)\\ \mathbf{if}\;z \leq -75000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-122}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 8.5 \cdot 10^{-85}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{-34}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Accuracy37.9%
Cost916
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;y \leq -440000000:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq -9 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-246}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 10
Accuracy62.4%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -9.2 \cdot 10^{-42} \lor \neg \left(x \leq 2.9 \cdot 10^{-55}\right) \land \left(x \leq 4.5 \cdot 10^{+88} \lor \neg \left(x \leq 9.2 \cdot 10^{+126}\right)\right):\\ \;\;\;\;x \cdot \left(z + 1\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y - z\right)\\ \end{array} \]
Alternative 11
Accuracy100.0%
Cost832
\[\left(x + t \cdot \left(y - z\right)\right) - x \cdot \left(y - z\right) \]
Alternative 12
Accuracy36.8%
Cost784
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{-58}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -1.05 \cdot 10^{-247}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Accuracy83.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{-28} \lor \neg \left(y \leq 2.75 \cdot 10^{-61}\right):\\ \;\;\;\;x - y \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 14
Accuracy100.0%
Cost576
\[x + \left(z - y\right) \cdot \left(x - t\right) \]
Alternative 15
Accuracy40.3%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{-28}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 16
Accuracy27.0%
Cost64
\[x \]

Error

Reproduce?

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