?

Average Error: 1.8 → 1.4
Time: 9.6s
Precision: binary64
Cost: 7364

?

\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq 4 \cdot 10^{+170}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{\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 (<= (/ x y) 4e+170)
   (fma (/ x y) (- z t) t)
   (/ 1.0 (/ 1.0 (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 ((x / y) <= 4e+170) {
		tmp = fma((x / y), (z - t), t);
	} else {
		tmp = 1.0 / (1.0 / 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 (Float64(x / y) <= 4e+170)
		tmp = fma(Float64(x / y), Float64(z - t), t);
	else
		tmp = Float64(1.0 / Float64(1.0 / 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[N[(x / y), $MachinePrecision], 4e+170], N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision] + t), $MachinePrecision], N[(1.0 / N[(1.0 / N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;\frac{x}{y} \leq 4 \cdot 10^{+170}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\

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


\end{array}

Error?

Target

Original1.8
Target2.0
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 2 regimes
  2. if (/.f64 x y) < 4.00000000000000014e170

    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

      [Start]1.3

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

      fma-def [=>]1.3

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

    if 4.00000000000000014e170 < (/.f64 x y)

    1. Initial program 14.8

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

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

      [Start]14.8

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

      associate-*l/ [=>]2.0

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

      associate-*r/ [<=]3.1

      \[ \color{blue}{x \cdot \frac{z - t}{y}} + t \]

      fma-def [=>]3.1

      \[ \color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)} \]
    3. Applied egg-rr54.4

      \[\leadsto \color{blue}{\frac{{t}^{3} + {\left(x \cdot \frac{z - t}{y}\right)}^{3}}{\left(x \cdot \frac{z - t}{y}\right) \cdot \left(x \cdot \frac{z - t}{y}\right) + \left(t \cdot t - t \cdot \left(x \cdot \frac{z - t}{y}\right)\right)}} \]
    4. Applied egg-rr3.2

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

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

      [Start]3.2

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

      unpow-1 [=>]3.2

      \[ \color{blue}{\frac{1}{\frac{1}{t + x \cdot \frac{z - t}{y}}}} \]

      +-commutative [<=]3.2

      \[ \frac{1}{\frac{1}{\color{blue}{x \cdot \frac{z - t}{y} + t}}} \]

      fma-def [=>]3.2

      \[ \frac{1}{\frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.4

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

Alternatives

Alternative 1
Error1.8
Cost6848
\[\mathsf{fma}\left(\frac{x}{y}, z - t, t\right) \]
Alternative 2
Error22.9
Cost1424
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot z\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-99}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 4 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{+183}:\\ \;\;\;\;\frac{-t}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \end{array} \]
Alternative 3
Error22.9
Cost1424
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot z\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-99}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 4 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{+183}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{z}{y}\\ \end{array} \]
Alternative 4
Error4.7
Cost969
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -5 \cdot 10^{+21} \lor \neg \left(\frac{x}{y} \leq 50000000\right):\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;t + \frac{x}{y} \cdot z\\ \end{array} \]
Alternative 5
Error22.9
Cost841
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-56} \lor \neg \left(\frac{x}{y} \leq 10^{-99}\right):\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 6
Error22.4
Cost840
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{-56}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 6 \cdot 10^{-65}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 7
Error7.9
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{-120} \lor \neg \left(z \leq 1.01 \cdot 10^{-137}\right):\\ \;\;\;\;t + \frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \end{array} \]
Alternative 8
Error20.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -0.062:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{+15}:\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 9
Error1.8
Cost576
\[t + \frac{x}{y} \cdot \left(z - t\right) \]
Alternative 10
Error31.5
Cost64
\[t \]

Error

Reproduce?

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