Data.Metrics.Snapshot:quantile from metrics-0.3.0.2

?

Percentage Accurate: 100.0% → 100.0%
Time: 9.0s
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)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 13 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Target

Original100.0%
Target96.2%
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. Simplified100.0%

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

    [Start]100.0%

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

    +-commutative [=>]100.0%

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

    fma-def [=>]100.0%

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

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

Alternatives

Alternative 1
Accuracy100.0%
Cost6848
\[\mathsf{fma}\left(y - z, t - x, x\right) \]
Alternative 2
Accuracy59.1%
Cost1112
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y \leq -9.8 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-308}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-266}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-245}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-63}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.35 \cdot 10^{+86}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy36.6%
Cost1048
\[\begin{array}{l} t_1 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{+244}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.4 \cdot 10^{+169}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -9.5 \cdot 10^{+101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-153}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.25 \cdot 10^{+81}:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy38.3%
Cost1048
\[\begin{array}{l} t_1 := z \cdot \left(-t\right)\\ t_2 := y \cdot \left(-x\right)\\ \mathbf{if}\;y \leq -7.4 \cdot 10^{+242}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{+160}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -9 \cdot 10^{+67}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-308}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.25 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{+82}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Accuracy53.8%
Cost848
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ t_2 := y \cdot \left(-x\right)\\ \mathbf{if}\;t \leq -2.05 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.8 \cdot 10^{-152}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -9.2 \cdot 10^{-216}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 3.4 \cdot 10^{-49}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy60.2%
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.76 \cdot 10^{-307}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-65}:\\ \;\;\;\;x + y \cdot t\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+85}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy76.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.58 \cdot 10^{+66} \lor \neg \left(y \leq 1.85 \cdot 10^{+86}\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \end{array} \]
Alternative 8
Accuracy80.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.35 \cdot 10^{-96} \lor \neg \left(t \leq 7.5 \cdot 10^{-29}\right):\\ \;\;\;\;x + \left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x - \left(y - z\right) \cdot x\\ \end{array} \]
Alternative 9
Accuracy84.8%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1750000000 \lor \neg \left(y \leq 6 \cdot 10^{+20}\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 10
Accuracy72.7%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -11600 \lor \neg \left(y \leq 26000000000000\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot t\\ \end{array} \]
Alternative 11
Accuracy100.0%
Cost576
\[x - \left(y - z\right) \cdot \left(x - t\right) \]
Alternative 12
Accuracy36.1%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{-153}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 13
Accuracy17.8%
Cost64
\[x \]

Reproduce?

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