Average Error: 2.0 → 1.4
Time: 3.4s
Precision: binary64
\[\frac{x}{y} \cdot \left(z - t\right) + t\]
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5747647500589528 \cdot 10^{+20}:\\ \;\;\;\;\left(z \cdot \frac{x}{y} + t\right) + t \cdot \left(x \cdot \frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 7.139296702863165 \cdot 10^{-108}:\\ \;\;\;\;t + \frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\ \end{array}\]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;y \leq -1.5747647500589528 \cdot 10^{+20}:\\
\;\;\;\;\left(z \cdot \frac{x}{y} + t\right) + t \cdot \left(x \cdot \frac{-1}{y}\right)\\

\mathbf{elif}\;y \leq 7.139296702863165 \cdot 10^{-108}:\\
\;\;\;\;t + \frac{x \cdot \left(z - t\right)}{y}\\

\mathbf{else}:\\
\;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\

\end{array}
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (if (<= y -1.5747647500589528e+20)
   (+ (+ (* z (/ x y)) t) (* t (* x (/ -1.0 y))))
   (if (<= y 7.139296702863165e-108)
     (+ t (/ (* x (- z t)) y))
     (+ t (* (/ x y) (- z t))))))
double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -1.5747647500589528e+20) {
		tmp = ((z * (x / y)) + t) + (t * (x * (-1.0 / y)));
	} else if (y <= 7.139296702863165e-108) {
		tmp = t + ((x * (z - t)) / y);
	} else {
		tmp = t + ((x / y) * (z - t));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.0
Target2.3
Herbie1.4
\[\begin{array}{l} \mathbf{if}\;z < 2.759456554562692 \cdot 10^{-282}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \mathbf{elif}\;z < 2.326994450874436 \cdot 10^{-110}:\\ \;\;\;\;x \cdot \frac{z - t}{y} + t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if y < -157476475005895279000

    1. Initial program 1.1

      \[\frac{x}{y} \cdot \left(z - t\right) + t\]
    2. Using strategy rm
    3. Applied sub-neg_binary641.1

      \[\leadsto \frac{x}{y} \cdot \color{blue}{\left(z + \left(-t\right)\right)} + t\]
    4. Applied distribute-rgt-in_binary641.1

      \[\leadsto \color{blue}{\left(z \cdot \frac{x}{y} + \left(-t\right) \cdot \frac{x}{y}\right)} + t\]
    5. Applied associate-+l+_binary641.1

      \[\leadsto \color{blue}{z \cdot \frac{x}{y} + \left(\left(-t\right) \cdot \frac{x}{y} + t\right)}\]
    6. Simplified1.1

      \[\leadsto z \cdot \frac{x}{y} + \color{blue}{\left(t - \frac{x}{y} \cdot t\right)}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity_binary641.1

      \[\leadsto z \cdot \frac{x}{y} + \left(\color{blue}{1 \cdot t} - \frac{x}{y} \cdot t\right)\]
    9. Applied distribute-rgt-out--_binary641.1

      \[\leadsto z \cdot \frac{x}{y} + \color{blue}{t \cdot \left(1 - \frac{x}{y}\right)}\]
    10. Using strategy rm
    11. Applied div-inv_binary641.1

      \[\leadsto z \cdot \frac{x}{y} + t \cdot \left(1 - \color{blue}{x \cdot \frac{1}{y}}\right)\]
    12. Applied cancel-sign-sub-inv_binary641.1

      \[\leadsto z \cdot \frac{x}{y} + t \cdot \color{blue}{\left(1 + \left(-x\right) \cdot \frac{1}{y}\right)}\]
    13. Applied distribute-rgt-in_binary641.1

      \[\leadsto z \cdot \frac{x}{y} + \color{blue}{\left(1 \cdot t + \left(\left(-x\right) \cdot \frac{1}{y}\right) \cdot t\right)}\]
    14. Applied associate-+r+_binary641.1

      \[\leadsto \color{blue}{\left(z \cdot \frac{x}{y} + 1 \cdot t\right) + \left(\left(-x\right) \cdot \frac{1}{y}\right) \cdot t}\]
    15. Simplified1.1

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

    if -157476475005895279000 < y < 7.13929670286316481e-108

    1. Initial program 4.0

      \[\frac{x}{y} \cdot \left(z - t\right) + t\]
    2. Using strategy rm
    3. Applied associate-*l/_binary642.1

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

    if 7.13929670286316481e-108 < y

    1. Initial program 1.2

      \[\frac{x}{y} \cdot \left(z - t\right) + t\]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.5747647500589528 \cdot 10^{+20}:\\ \;\;\;\;\left(z \cdot \frac{x}{y} + t\right) + t \cdot \left(x \cdot \frac{-1}{y}\right)\\ \mathbf{elif}\;y \leq 7.139296702863165 \cdot 10^{-108}:\\ \;\;\;\;t + \frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020273 
(FPCore (x y z t)
  :name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
  :precision binary64

  :herbie-target
  (if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))

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