?

Average Error: 2.25% → 2.19%
Time: 10.1s
Precision: binary64
Cost: 7241

?

\[x + y \cdot \frac{z - t}{a - t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -2 \cdot 10^{-284} \lor \neg \left(t \leq 5.5 \cdot 10^{-257}\right):\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z - t, \frac{y}{a - t}, x\right)\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- a t)))))
(FPCore (x y z t a)
 :precision binary64
 (if (or (<= t -2e-284) (not (<= t 5.5e-257)))
   (+ x (* y (/ (- z t) (- a t))))
   (fma (- z t) (/ y (- a t)) x)))
double code(double x, double y, double z, double t, double a) {
	return x + (y * ((z - t) / (a - t)));
}
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((t <= -2e-284) || !(t <= 5.5e-257)) {
		tmp = x + (y * ((z - t) / (a - t)));
	} else {
		tmp = fma((z - t), (y / (a - t)), x);
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(a - t))))
end
function code(x, y, z, t, a)
	tmp = 0.0
	if ((t <= -2e-284) || !(t <= 5.5e-257))
		tmp = Float64(x + Float64(y * Float64(Float64(z - t) / Float64(a - t))));
	else
		tmp = fma(Float64(z - t), Float64(y / Float64(a - t)), x);
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -2e-284], N[Not[LessEqual[t, 5.5e-257]], $MachinePrecision]], N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z - t), $MachinePrecision] * N[(y / N[(a - t), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
x + y \cdot \frac{z - t}{a - t}
\begin{array}{l}
\mathbf{if}\;t \leq -2 \cdot 10^{-284} \lor \neg \left(t \leq 5.5 \cdot 10^{-257}\right):\\
\;\;\;\;x + y \cdot \frac{z - t}{a - t}\\

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


\end{array}

Error?

Target

Original2.25%
Target0.63%
Herbie2.19%
\[\begin{array}{l} \mathbf{if}\;y < -8.508084860551241 \cdot 10^{-17}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \left(y \cdot \left(z - t\right)\right) \cdot \frac{1}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if t < -2.00000000000000007e-284 or 5.50000000000000025e-257 < t

    1. Initial program 1.99

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

    if -2.00000000000000007e-284 < t < 5.50000000000000025e-257

    1. Initial program 7

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Simplified5.82

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

      [Start]7

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

      +-commutative [=>]7

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

      associate-*r/ [=>]4.57

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

      associate-*l/ [<=]5.82

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

      *-commutative [=>]5.82

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

      fma-def [=>]5.82

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -2 \cdot 10^{-284} \lor \neg \left(t \leq 5.5 \cdot 10^{-257}\right):\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z - t, \frac{y}{a - t}, x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error16.67%
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -1.12 \cdot 10^{+114}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 1.32 \cdot 10^{+45}:\\ \;\;\;\;x + y \cdot \frac{z}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Error15.45%
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -6.8 \cdot 10^{+48}:\\ \;\;\;\;x + \left(y - z \cdot \frac{y}{t}\right)\\ \mathbf{elif}\;t \leq 2.4 \cdot 10^{+45}:\\ \;\;\;\;x + y \cdot \frac{z}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 3
Error13.69%
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -2.2 \cdot 10^{+46}:\\ \;\;\;\;x + \left(y - z \cdot \frac{y}{t}\right)\\ \mathbf{elif}\;t \leq 3.35 \cdot 10^{+44}:\\ \;\;\;\;x + y \cdot \frac{z}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot \frac{t}{a - t}\\ \end{array} \]
Alternative 4
Error22.47%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -2.5 \cdot 10^{-47}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{-14}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 5
Error2.25%
Cost704
\[x + y \cdot \frac{z - t}{a - t} \]
Alternative 6
Error30.97%
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -9.5 \cdot 10^{-69}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 2.45 \cdot 10^{-24}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 7
Error42.45%
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-159}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-103}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error44.47%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023090 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisLine from plot-0.2.3.4, B"
  :precision binary64

  :herbie-target
  (if (< y -8.508084860551241e-17) (+ x (* y (/ (- z t) (- a t)))) (if (< y 2.894426862792089e-49) (+ x (* (* y (- z t)) (/ 1.0 (- a t)))) (+ x (* y (/ (- z t) (- a t))))))

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