Data.Metrics.Snapshot:quantile from metrics-0.3.0.2

?

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

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 16 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.3%
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
Accuracy51.7%
Cost1361
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot t\\ \mathbf{if}\;y - z \leq -5 \cdot 10^{-26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y - z \leq 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;y - z \leq 5 \cdot 10^{+174} \lor \neg \left(y - z \leq 2 \cdot 10^{+267}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Accuracy69.7%
Cost1244
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y \leq -1.76 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-14}:\\ \;\;\;\;x - y \cdot x\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-26}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-291}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-242}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{-121}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-11}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy37.4%
Cost1180
\[\begin{array}{l} t_1 := t \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -1.6 \cdot 10^{-17}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-285}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.4 \cdot 10^{-268}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;y \leq 6.1 \cdot 10^{-238}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-132}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{+63}:\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \end{array} \]
Alternative 5
Accuracy70.7%
Cost1112
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := x + y \cdot t\\ t_3 := x \cdot \left(1 - y\right)\\ \mathbf{if}\;z \leq -4.3 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{-75}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-128}:\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{elif}\;z \leq -4.2 \cdot 10^{-228}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-290}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1600000000:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy70.4%
Cost980
\[\begin{array}{l} t_1 := z \cdot \left(x - t\right)\\ t_2 := y \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -5.6 \cdot 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-290}:\\ \;\;\;\;x - z \cdot t\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-241}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-122}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Accuracy38.8%
Cost852
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+76}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{+39}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -5.5:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-75}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3400000000:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 8
Accuracy39.0%
Cost852
\[\begin{array}{l} \mathbf{if}\;z \leq -1.6 \cdot 10^{+75}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{+34}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;z \leq -175:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-75}:\\ \;\;\;\;y \cdot \left(-x\right)\\ \mathbf{elif}\;z \leq 750000000:\\ \;\;\;\;y \cdot t\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 9
Accuracy68.6%
Cost848
\[\begin{array}{l} t_1 := y \cdot \left(t - x\right)\\ t_2 := z \cdot \left(x - t\right)\\ \mathbf{if}\;y \leq -1.02 \cdot 10^{+27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-238}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-124}:\\ \;\;\;\;x + z \cdot x\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-11}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Accuracy83.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{-12} \lor \neg \left(z \leq 20000000\right):\\ \;\;\;\;z \cdot \left(x - t\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \end{array} \]
Alternative 11
Accuracy84.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{-17} \lor \neg \left(y \leq 3.1 \cdot 10^{-11}\right):\\ \;\;\;\;x + y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 12
Accuracy61.8%
Cost585
\[\begin{array}{l} \mathbf{if}\;t \leq -4.3 \cdot 10^{-103} \lor \neg \left(t \leq 2.05 \cdot 10^{+15}\right):\\ \;\;\;\;\left(y - z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - y\right)\\ \end{array} \]
Alternative 13
Accuracy68.8%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+24} \lor \neg \left(y \leq 7.8 \cdot 10^{-11}\right):\\ \;\;\;\;y \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x - t\right)\\ \end{array} \]
Alternative 14
Accuracy100.0%
Cost576
\[x + \left(y - z\right) \cdot \left(t - x\right) \]
Alternative 15
Accuracy36.6%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{-55}:\\ \;\;\;\;y \cdot t\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-111}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot t\\ \end{array} \]
Alternative 16
Accuracy18.1%
Cost64
\[x \]

Reproduce?

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