Average Error: 14.9 → 3.6
Time: 13.7s
Precision: binary64
Cost: 8904
\[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(t - x, \frac{y - z}{a - z}, x\right)\\ t_2 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;t + \frac{a - y}{\frac{z}{t - x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (* (- y z) (/ (- t x) (- a z)))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (fma (- t x) (/ (- y z) (- a z)) x))
        (t_2 (+ x (* (- y z) (/ (- t x) (- a z))))))
   (if (<= t_2 -1e-307)
     t_1
     (if (<= t_2 0.0) (+ t (/ (- a y) (/ z (- t x)))) t_1))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y - z) * ((t - x) / (a - z)));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = fma((t - x), ((y - z) / (a - z)), x);
	double t_2 = x + ((y - z) * ((t - x) / (a - z)));
	double tmp;
	if (t_2 <= -1e-307) {
		tmp = t_1;
	} else if (t_2 <= 0.0) {
		tmp = t + ((a - y) / (z / (t - x)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z))))
end
function code(x, y, z, t, a)
	t_1 = fma(Float64(t - x), Float64(Float64(y - z) / Float64(a - z)), x)
	t_2 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z))))
	tmp = 0.0
	if (t_2 <= -1e-307)
		tmp = t_1;
	elseif (t_2 <= 0.0)
		tmp = Float64(t + Float64(Float64(a - y) / Float64(z / Float64(t - x))));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e-307], t$95$1, If[LessEqual[t$95$2, 0.0], N[(t + N[(N[(a - y), $MachinePrecision] / N[(z / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\begin{array}{l}
t_1 := \mathsf{fma}\left(t - x, \frac{y - z}{a - z}, x\right)\\
t_2 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{-307}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;t + \frac{a - y}{\frac{z}{t - x}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -9.99999999999999909e-308 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z))))

    1. Initial program 7.5

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

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

    if -9.99999999999999909e-308 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0

    1. Initial program 61.8

      \[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
    2. Simplified61.8

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

      \[\leadsto \mathsf{fma}\left(t - x, \color{blue}{{\left(\frac{a - z}{y - z}\right)}^{-1}}, x\right) \]
    4. Taylor expanded in z around inf 10.0

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

      \[\leadsto \color{blue}{t - \frac{y - a}{\frac{z}{t - x}}} \]
      Proof
      (-.f64 t (/.f64 (-.f64 y a) (/.f64 z (-.f64 t x)))): 0 points increase in error, 0 points decrease in error
      (-.f64 t (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (-.f64 y a) (-.f64 t x)) z))): 45 points increase in error, 29 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 t (neg.f64 (/.f64 (*.f64 (-.f64 y a) (-.f64 t x)) z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 t (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 (*.f64 (-.f64 y a) (-.f64 t x))) z))): 0 points increase in error, 0 points decrease in error
      (+.f64 t (/.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 (-.f64 y a) (-.f64 t x)))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 t (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 -1 (-.f64 y a)) (-.f64 t x))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 t (/.f64 (*.f64 (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 -1 y) (*.f64 -1 a))) (-.f64 t x)) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 (*.f64 (-.f64 (*.f64 -1 y) (*.f64 -1 a)) (-.f64 t x)) z) t)): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification3.6

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

Alternatives

Alternative 1
Error23.7
Cost1500
\[\begin{array}{l} t_1 := \frac{t}{\frac{a - z}{y - z}}\\ t_2 := t + x \cdot \frac{y - a}{z}\\ \mathbf{if}\;a \leq -3.93793398358717 \cdot 10^{+77}:\\ \;\;\;\;x + \frac{y - z}{\frac{a}{t}}\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6 \cdot 10^{-158}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 1.06 \cdot 10^{-153}:\\ \;\;\;\;\frac{y \cdot \left(t - x\right)}{a - z}\\ \mathbf{elif}\;a \leq 2.2 \cdot 10^{-58}:\\ \;\;\;\;x + t\\ \mathbf{elif}\;a \leq 2.204758912297863 \cdot 10^{-16}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 1539515385.335059:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot \frac{x - t}{a}\\ \end{array} \]
Alternative 2
Error35.8
Cost328
\[\begin{array}{l} \mathbf{if}\;a \leq -57479902.70451729:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq 1.2353027197531722 \cdot 10^{+35}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error45.6
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022291 
(FPCore (x y z t a)
  :name "Numeric.Signal:interpolate   from hsignal-0.2.7.1"
  :precision binary64
  (+ x (* (- y z) (/ (- t x) (- a z)))))