Average Error: 1.9 → 2.1
Time: 11.4s
Precision: binary64
Cost: 7245
\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+76} \lor \neg \left(x \leq 2.9 \cdot 10^{-45}\right) \land x \leq 5.2 \cdot 10^{+216}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot z}{y} + \left(t - t \cdot \frac{x}{y}\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (if (or (<= x -6.5e+76) (and (not (<= x 2.9e-45)) (<= x 5.2e+216)))
   (fma x (/ (- z t) y) t)
   (+ (/ (* x z) y) (- t (* t (/ x y))))))
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 ((x <= -6.5e+76) || (!(x <= 2.9e-45) && (x <= 5.2e+216))) {
		tmp = fma(x, ((z - t) / y), t);
	} else {
		tmp = ((x * z) / y) + (t - (t * (x / y)));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(Float64(x / y) * Float64(z - t)) + t)
end
function code(x, y, z, t)
	tmp = 0.0
	if ((x <= -6.5e+76) || (!(x <= 2.9e-45) && (x <= 5.2e+216)))
		tmp = fma(x, Float64(Float64(z - t) / y), t);
	else
		tmp = Float64(Float64(Float64(x * z) / y) + Float64(t - Float64(t * Float64(x / y))));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -6.5e+76], And[N[Not[LessEqual[x, 2.9e-45]], $MachinePrecision], LessEqual[x, 5.2e+216]]], N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision] + t), $MachinePrecision], N[(N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision] + N[(t - N[(t * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{+76} \lor \neg \left(x \leq 2.9 \cdot 10^{-45}\right) \land x \leq 5.2 \cdot 10^{+216}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\

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


\end{array}

Error

Target

Original1.9
Target2.2
Herbie2.1
\[\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 2 regimes
  2. if x < -6.5000000000000005e76 or 2.9e-45 < x < 5.1999999999999997e216

    1. Initial program 3.2

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

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

    if -6.5000000000000005e76 < x < 2.9e-45 or 5.1999999999999997e216 < x

    1. Initial program 1.3

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

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

      \[\leadsto \color{blue}{\frac{z \cdot x}{y} + \left(\frac{x}{y} \cdot \left(-t\right) + t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{+76} \lor \neg \left(x \leq 2.9 \cdot 10^{-45}\right) \land x \leq 5.2 \cdot 10^{+216}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot z}{y} + \left(t - t \cdot \frac{x}{y}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error21.9
Cost2204
\[\begin{array}{l} t_1 := \frac{-t}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{+153}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{+87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-32}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 4 \cdot 10^{+83}:\\ \;\;\;\;z \cdot \frac{x}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{+210}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \end{array} \]
Alternative 2
Error21.9
Cost2204
\[\begin{array}{l} t_1 := t \cdot \frac{-x}{y}\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{+153}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{+87}:\\ \;\;\;\;\frac{-t}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-32}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 4 \cdot 10^{+83}:\\ \;\;\;\;z \cdot \frac{x}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{+210}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \end{array} \]
Alternative 3
Error5.3
Cost1488
\[\begin{array}{l} t_1 := t + \frac{x \cdot z}{y}\\ \mathbf{if}\;\frac{x}{y} \leq -200000000000:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{-176}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(z - t\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 4
Error11.7
Cost1229
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -\infty:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-32} \lor \neg \left(\frac{x}{y} \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\left(z - t\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 5
Error3.8
Cost1229
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -\infty:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -4 \cdot 10^{-9} \lor \neg \left(\frac{x}{y} \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\left(z - t\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 6
Error4.1
Cost1229
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -\infty:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -40 \lor \neg \left(\frac{x}{y} \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\left(z - t\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{x \cdot z}{y}\\ \end{array} \]
Alternative 7
Error2.0
Cost1229
\[\begin{array}{l} \mathbf{if}\;x \leq -1500 \lor \neg \left(x \leq 10^{-26}\right) \land x \leq 5.2 \cdot 10^{+216}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot z}{y} + \left(t - t \cdot \frac{x}{y}\right)\\ \end{array} \]
Alternative 8
Error2.7
Cost973
\[\begin{array}{l} \mathbf{if}\;x \leq -3.7 \cdot 10^{+173} \lor \neg \left(x \leq 9.6 \cdot 10^{+140}\right) \land x \leq 1.1 \cdot 10^{+199}:\\ \;\;\;\;x \cdot \left(\frac{z}{y} - \frac{t}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t + \left(z - t\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 9
Error2.1
Cost973
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+176}:\\ \;\;\;\;x \cdot \left(\frac{z}{y} - \frac{t}{y}\right)\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-46} \lor \neg \left(x \leq 1.6 \cdot 10^{+211}\right):\\ \;\;\;\;t + \left(z - t\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \end{array} \]
Alternative 10
Error21.8
Cost841
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -8.4 \cdot 10^{-32} \lor \neg \left(\frac{x}{y} \leq 1.6 \cdot 10^{-10}\right):\\ \;\;\;\;z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 11
Error23.1
Cost841
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{-32} \lor \neg \left(\frac{x}{y} \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 12
Error22.5
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{-29}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{x}{y}\\ \end{array} \]
Alternative 13
Error22.5
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{-29}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 14
Error31.7
Cost64
\[t \]

Error

Reproduce

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