Average Error: 6.5 → 2.3
Time: 7.0s
Precision: binary64
Cost: 6848
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\mathsf{fma}\left(y - x, \frac{z}{t}, x\right) \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t) :precision binary64 (fma (- y x) (/ z t) x))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
double code(double x, double y, double z, double t) {
	return fma((y - x), (z / t), x);
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function code(x, y, z, t)
	return fma(Float64(y - x), Float64(z / t), x)
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
x + \frac{\left(y - x\right) \cdot z}{t}
\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)

Error

Target

Original6.5
Target2.1
Herbie2.3
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Initial program 6.5

    \[x + \frac{\left(y - x\right) \cdot z}{t} \]
  2. Simplified2.3

    \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    Proof
    (fma.f64 (-.f64 y x) (/.f64 z t) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y x) (/.f64 z t)) x)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 y x) z) t)) x): 49 points increase in error, 17 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))): 0 points increase in error, 0 points decrease in error
  3. Final simplification2.3

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

Alternatives

Alternative 1
Error0.9
Cost1864
\[\begin{array}{l} t_1 := x + z \cdot \frac{y - x}{t}\\ t_2 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+299}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error24.6
Cost1240
\[\begin{array}{l} t_1 := \left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{-16}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.5 \cdot 10^{-121}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{+86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error12.8
Cost844
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;t \leq -6.1 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{-52}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;t \leq 3 \cdot 10^{+23}:\\ \;\;\;\;x - x \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error12.8
Cost844
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;t \leq -6.6 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.4 \cdot 10^{-47}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{elif}\;t \leq 1.55 \cdot 10^{+26}:\\ \;\;\;\;x - \frac{z}{\frac{t}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error3.9
Cost840
\[\begin{array}{l} t_1 := x + z \cdot \frac{y - x}{t}\\ \mathbf{if}\;z \leq -1.9 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-124}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error12.0
Cost712
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;t \leq -7 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{-52}:\\ \;\;\;\;\left(y - x\right) \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error26.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85 \cdot 10^{-121}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-116}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error2.2
Cost576
\[x + \frac{y - x}{\frac{t}{z}} \]
Alternative 9
Error31.6
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022337 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

  (+ x (/ (* (- y x) z) t)))