Average Error: 1.9 → 1.7
Time: 12.2s
Precision: binary64
Cost: 13768
\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} \mathbf{if}\;y \leq 10^{-280}:\\ \;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{elif}\;y \leq 4.374494269814032 \cdot 10^{+67}:\\ \;\;\;\;t + \frac{\frac{x \cdot \left(z - t\right)}{\sqrt{y}}}{\sqrt{y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, 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 1e-280)
   (+ t (* (/ x y) (- z t)))
   (if (<= y 4.374494269814032e+67)
     (+ t (/ (/ (* x (- z t)) (sqrt y)) (sqrt y)))
     (fma x (/ (- z t) y) 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 <= 1e-280) {
		tmp = t + ((x / y) * (z - t));
	} else if (y <= 4.374494269814032e+67) {
		tmp = t + (((x * (z - t)) / sqrt(y)) / sqrt(y));
	} else {
		tmp = fma(x, ((z - t) / y), t);
	}
	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 (y <= 1e-280)
		tmp = Float64(t + Float64(Float64(x / y) * Float64(z - t)));
	elseif (y <= 4.374494269814032e+67)
		tmp = Float64(t + Float64(Float64(Float64(x * Float64(z - t)) / sqrt(y)) / sqrt(y)));
	else
		tmp = fma(x, Float64(Float64(z - t) / y), t);
	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[LessEqual[y, 1e-280], N[(t + N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.374494269814032e+67], N[(t + N[(N[(N[(x * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[Sqrt[y], $MachinePrecision]), $MachinePrecision] / N[Sqrt[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision] + t), $MachinePrecision]]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;y \leq 10^{-280}:\\
\;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\


\end{array}

Error

Target

Original1.9
Target2.2
Herbie1.7
\[\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 < 9.9999999999999996e-281

    1. Initial program 2.1

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

    if 9.9999999999999996e-281 < y < 4.3744942698140319e67

    1. Initial program 2.4

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Applied egg-rr1.6

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

    if 4.3744942698140319e67 < y

    1. Initial program 1.2

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

      \[\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)): 2 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 (-.f64 z t) y) x)) t): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (-.f64 z t) x) y)) t): 37 points increase in error, 41 points decrease in error
      (+.f64 (Rewrite<= associate-*r/_binary64 (*.f64 (-.f64 z t) (/.f64 x y))) t): 28 points increase in error, 45 points decrease in error
      (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 x y) (-.f64 z t))) t): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 10^{-280}:\\ \;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{elif}\;y \leq 4.374494269814032 \cdot 10^{+67}:\\ \;\;\;\;t + \frac{\frac{x \cdot \left(z - t\right)}{\sqrt{y}}}{\sqrt{y}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\ \end{array} \]

Alternatives

Alternative 1
Error2.1
Cost7112
\[\begin{array}{l} t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;t \leq 4.605592088679634 \cdot 10^{-232}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.380798698040074 \cdot 10^{-152}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error22.0
Cost2204
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot \left(-t\right)\\ \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{+169}:\\ \;\;\;\;\frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-45}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{-84}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-73}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 0.005:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+120}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error22.0
Cost2204
\[\begin{array}{l} t_1 := t - \frac{t}{\frac{y}{x}}\\ t_2 := \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{+169}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-45}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{-84}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-73}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+120}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-t\right)\\ \end{array} \]
Alternative 4
Error12.5
Cost1488
\[\begin{array}{l} t_1 := \frac{z - t}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{-45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{-84}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-73}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 0.005:\\ \;\;\;\;t - \frac{t}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error22.9
Cost1360
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{-45}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{-84}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-73}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq 0.005:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 6
Error29.1
Cost1112
\[\begin{array}{l} t_1 := \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;x \leq -8 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1034114334988113 \cdot 10^{-24}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq -6.159901173418997 \cdot 10^{-53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.0045115587828868 \cdot 10^{-56}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+36}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error29.1
Cost1112
\[\begin{array}{l} t_1 := \frac{x \cdot z}{y}\\ t_2 := \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;x \leq -8 \cdot 10^{+68}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.1034114334988113 \cdot 10^{-24}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq -6.159901173418997 \cdot 10^{-53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.0045115587828868 \cdot 10^{-56}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+36}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error29.1
Cost1112
\[\begin{array}{l} t_1 := \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;x \leq -8 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.1034114334988113 \cdot 10^{-24}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq -6.159901173418997 \cdot 10^{-53}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;x \leq 1.0045115587828868 \cdot 10^{-56}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-7}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+36}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error29.2
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -8 \cdot 10^{+68}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;x \leq -1.1034114334988113 \cdot 10^{-24}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq -6.159901173418997 \cdot 10^{-53}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \mathbf{elif}\;x \leq 1.0045115587828868 \cdot 10^{-56}:\\ \;\;\;\;t\\ \mathbf{elif}\;x \leq 1.08 \cdot 10^{-7}:\\ \;\;\;\;\frac{x \cdot z}{y}\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{+36}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 10
Error4.2
Cost968
\[\begin{array}{l} t_1 := \frac{z - t}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -100000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 0.005:\\ \;\;\;\;t + \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error2.1
Cost840
\[\begin{array}{l} t_1 := t + \frac{z - t}{\frac{y}{x}}\\ \mathbf{if}\;t \leq 7.736705357099387 \cdot 10^{-250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.4662266463294765 \cdot 10^{-46}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error2.0
Cost840
\[\begin{array}{l} t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;t \leq 7.736705357099387 \cdot 10^{-250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.952679118870386 \cdot 10^{-77}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Error1.9
Cost576
\[t + \frac{z - t}{\frac{y}{x}} \]
Alternative 14
Error31.5
Cost64
\[t \]

Error

Reproduce

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