Numeric.Signal:interpolate from hsignal-0.2.7.1

Percentage Accurate: 80.7% → 95.3%
Time: 12.3s
Alternatives: 19
Speedup: 0.3×

Specification

?
\[\begin{array}{l} \\ x + \left(y - z\right) \cdot \frac{t - x}{a - z} \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (* (- y z) (/ (- t x) (- a z)))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y - z) * ((t - x) / (a - z)));
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = x + ((y - z) * ((t - x) / (a - z)))
end function
public static double code(double x, double y, double z, double t, double a) {
	return x + ((y - z) * ((t - x) / (a - z)));
}
def code(x, y, z, t, a):
	return x + ((y - z) * ((t - x) / (a - z)))
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z))))
end
function tmp = code(x, y, z, t, a)
	tmp = x + ((y - z) * ((t - x) / (a - z)));
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]
\begin{array}{l}

\\
x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 19 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 80.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \left(y - z\right) \cdot \frac{t - x}{a - z} \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (* (- y z) (/ (- t x) (- a z)))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y - z) * ((t - x) / (a - z)));
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = x + ((y - z) * ((t - x) / (a - z)))
end function
public static double code(double x, double y, double z, double t, double a) {
	return x + ((y - z) * ((t - x) / (a - z)));
}
def code(x, y, z, t, a):
	return x + ((y - z) * ((t - x) / (a - z)))
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z))))
end
function tmp = code(x, y, z, t, a)
	tmp = x + ((y - z) * ((t - x) / (a - z)));
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]
\begin{array}{l}

\\
x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\end{array}

Alternative 1: 95.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x - \frac{x - t}{a - z} \cdot \left(y - z\right)\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-304}:\\ \;\;\;\;\mathsf{fma}\left(x - t, \frac{-1}{\frac{z - a}{z - y}}, x\right)\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{t - x}{z}, a - y, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x - t, \frac{-1}{z - a} \cdot \left(z - y\right), x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- x (* (/ (- x t) (- a z)) (- y z)))))
   (if (<= t_1 -5e-304)
     (fma (- x t) (/ -1.0 (/ (- z a) (- z y))) x)
     (if (<= t_1 0.0)
       (fma (/ (- t x) z) (- a y) t)
       (fma (- x t) (* (/ -1.0 (- z a)) (- z y)) x)))))
double code(double x, double y, double z, double t, double a) {
	double t_1 = x - (((x - t) / (a - z)) * (y - z));
	double tmp;
	if (t_1 <= -5e-304) {
		tmp = fma((x - t), (-1.0 / ((z - a) / (z - y))), x);
	} else if (t_1 <= 0.0) {
		tmp = fma(((t - x) / z), (a - y), t);
	} else {
		tmp = fma((x - t), ((-1.0 / (z - a)) * (z - y)), x);
	}
	return tmp;
}
function code(x, y, z, t, a)
	t_1 = Float64(x - Float64(Float64(Float64(x - t) / Float64(a - z)) * Float64(y - z)))
	tmp = 0.0
	if (t_1 <= -5e-304)
		tmp = fma(Float64(x - t), Float64(-1.0 / Float64(Float64(z - a) / Float64(z - y))), x);
	elseif (t_1 <= 0.0)
		tmp = fma(Float64(Float64(t - x) / z), Float64(a - y), t);
	else
		tmp = fma(Float64(x - t), Float64(Float64(-1.0 / Float64(z - a)) * Float64(z - y)), x);
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x - N[(N[(N[(x - t), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e-304], N[(N[(x - t), $MachinePrecision] * N[(-1.0 / N[(N[(z - a), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(N[(t - x), $MachinePrecision] / z), $MachinePrecision] * N[(a - y), $MachinePrecision] + t), $MachinePrecision], N[(N[(x - t), $MachinePrecision] * N[(N[(-1.0 / N[(z - a), $MachinePrecision]), $MachinePrecision] * N[(z - y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x - \frac{x - t}{a - z} \cdot \left(y - z\right)\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-304}:\\
\;\;\;\;\mathsf{fma}\left(x - t, \frac{-1}{\frac{z - a}{z - y}}, x\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -4.99999999999999965e-304

    1. Initial program 92.5%

      \[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \left(y - z\right) \cdot \frac{t - x}{a - z}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z} + x} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z}} + x \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{t - x}{a - z} \cdot \left(y - z\right)} + x \]
      5. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{t - x}{a - z}} \cdot \left(y - z\right) + x \]
      6. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(t - x\right)\right)}{\mathsf{neg}\left(\left(a - z\right)\right)}} \cdot \left(y - z\right) + x \]
      7. div-invN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\left(t - x\right)\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)}\right)} \cdot \left(y - z\right) + x \]
      8. associate-*l*N/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(t - x\right)\right)\right) \cdot \left(\frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right)\right)} + x \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\left(t - x\right)\right), \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right)} \]
      10. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{0 - \left(t - x\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      11. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(0 - \color{blue}{\left(t - x\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      12. sub-negN/A

        \[\leadsto \mathsf{fma}\left(0 - \color{blue}{\left(t + \left(\mathsf{neg}\left(x\right)\right)\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(0 - \color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + t\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      14. associate--r+N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - \left(\mathsf{neg}\left(x\right)\right)\right) - t}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      15. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)} - t, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      16. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x} - t, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      17. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - t}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      18. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right)}, x\right) \]
      19. frac-2negN/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(a - z\right)\right)\right)\right)}} \cdot \left(y - z\right), x\right) \]
      20. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{\color{blue}{-1}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(a - z\right)\right)\right)\right)} \cdot \left(y - z\right), x\right) \]
      21. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{-1}{\color{blue}{a - z}} \cdot \left(y - z\right), x\right) \]
      22. lower-/.f6496.9

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{-1}{a - z}} \cdot \left(y - z\right), x\right) \]
    4. Applied rewrites96.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - t, \frac{-1}{a - z} \cdot \left(y - z\right), x\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{-1}{a - z} \cdot \left(y - z\right)}, x\right) \]
      2. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{-1}{a - z}} \cdot \left(y - z\right), x\right) \]
      3. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{-1 \cdot \left(y - z\right)}{a - z}}, x\right) \]
      4. clear-numN/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{1}{\frac{a - z}{-1 \cdot \left(y - z\right)}}}, x\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{\color{blue}{\mathsf{neg}\left(-1\right)}}{\frac{a - z}{-1 \cdot \left(y - z\right)}}, x\right) \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{\mathsf{neg}\left(-1\right)}{\frac{a - z}{-1 \cdot \left(y - z\right)}}}, x\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{\color{blue}{1}}{\frac{a - z}{-1 \cdot \left(y - z\right)}}, x\right) \]
      8. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{1}{\color{blue}{\frac{a - z}{-1 \cdot \left(y - z\right)}}}, x\right) \]
      9. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{1}{\frac{a - z}{\color{blue}{\mathsf{neg}\left(\left(y - z\right)\right)}}}, x\right) \]
      10. lower-neg.f6497.0

        \[\leadsto \mathsf{fma}\left(x - t, \frac{1}{\frac{a - z}{\color{blue}{-\left(y - z\right)}}}, x\right) \]
    6. Applied rewrites97.0%

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

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

    1. Initial program 3.8%

      \[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{\left(t + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}\right) - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right)} - -1 \cdot \frac{a \cdot \left(t - x\right)}{z} \]
      2. associate--l+N/A

        \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)} \]
      3. sub-negN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \color{blue}{\left(t + \left(\mathsf{neg}\left(-1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)\right)\right)} \]
      4. mul-1-negN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\frac{a \cdot \left(t - x\right)}{z}\right)\right)}\right)\right)\right) \]
      5. remove-double-negN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t + \color{blue}{\frac{a \cdot \left(t - x\right)}{z}}\right) \]
      6. +-commutativeN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \color{blue}{\left(\frac{a \cdot \left(t - x\right)}{z} + t\right)} \]
      7. associate-+r+N/A

        \[\leadsto \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \frac{a \cdot \left(t - x\right)}{z}\right) + t} \]
      8. associate-/l*N/A

        \[\leadsto \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \color{blue}{a \cdot \frac{t - x}{z}}\right) + t \]
      9. associate-/l*N/A

        \[\leadsto \left(-1 \cdot \color{blue}{\left(y \cdot \frac{t - x}{z}\right)} + a \cdot \frac{t - x}{z}\right) + t \]
      10. associate-*r*N/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot y\right) \cdot \frac{t - x}{z}} + a \cdot \frac{t - x}{z}\right) + t \]
      11. distribute-rgt-outN/A

        \[\leadsto \color{blue}{\frac{t - x}{z} \cdot \left(-1 \cdot y + a\right)} + t \]
      12. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{t - x}{z}, -1 \cdot y + a, t\right)} \]
    5. Applied rewrites99.8%

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

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

    1. Initial program 92.0%

      \[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \left(y - z\right) \cdot \frac{t - x}{a - z}} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z} + x} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z}} + x \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{t - x}{a - z} \cdot \left(y - z\right)} + x \]
      5. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{t - x}{a - z}} \cdot \left(y - z\right) + x \]
      6. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(t - x\right)\right)}{\mathsf{neg}\left(\left(a - z\right)\right)}} \cdot \left(y - z\right) + x \]
      7. div-invN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(\left(t - x\right)\right)\right) \cdot \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)}\right)} \cdot \left(y - z\right) + x \]
      8. associate-*l*N/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(t - x\right)\right)\right) \cdot \left(\frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right)\right)} + x \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(\left(t - x\right)\right), \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right)} \]
      10. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{0 - \left(t - x\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      11. lift--.f64N/A

        \[\leadsto \mathsf{fma}\left(0 - \color{blue}{\left(t - x\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      12. sub-negN/A

        \[\leadsto \mathsf{fma}\left(0 - \color{blue}{\left(t + \left(\mathsf{neg}\left(x\right)\right)\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      13. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(0 - \color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) + t\right)}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      14. associate--r+N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(0 - \left(\mathsf{neg}\left(x\right)\right)\right) - t}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      15. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right)} - t, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      16. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x} - t, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      17. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x - t}, \frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right), x\right) \]
      18. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{1}{\mathsf{neg}\left(\left(a - z\right)\right)} \cdot \left(y - z\right)}, x\right) \]
      19. frac-2negN/A

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{\mathsf{neg}\left(1\right)}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(a - z\right)\right)\right)\right)}} \cdot \left(y - z\right), x\right) \]
      20. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{\color{blue}{-1}}{\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(a - z\right)\right)\right)\right)} \cdot \left(y - z\right), x\right) \]
      21. remove-double-negN/A

        \[\leadsto \mathsf{fma}\left(x - t, \frac{-1}{\color{blue}{a - z}} \cdot \left(y - z\right), x\right) \]
      22. lower-/.f6496.3

        \[\leadsto \mathsf{fma}\left(x - t, \color{blue}{\frac{-1}{a - z}} \cdot \left(y - z\right), x\right) \]
    4. Applied rewrites96.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - t, \frac{-1}{a - z} \cdot \left(y - z\right), x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification97.0%

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

Alternative 2: 90.8% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_1 := x - \frac{x - t}{a - z} \cdot \left(y - z\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-168}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+293}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -2.0000000000000001e-168 or 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 1.9999999999999998e293

    1. Initial program 92.6%

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

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

    1. Initial program 14.8%

      \[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf

      \[\leadsto \color{blue}{\left(t + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}\right) - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right)} - -1 \cdot \frac{a \cdot \left(t - x\right)}{z} \]
      2. associate--l+N/A

        \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)} \]
      3. sub-negN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \color{blue}{\left(t + \left(\mathsf{neg}\left(-1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)\right)\right)} \]
      4. mul-1-negN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\frac{a \cdot \left(t - x\right)}{z}\right)\right)}\right)\right)\right) \]
      5. remove-double-negN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \left(t + \color{blue}{\frac{a \cdot \left(t - x\right)}{z}}\right) \]
      6. +-commutativeN/A

        \[\leadsto -1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \color{blue}{\left(\frac{a \cdot \left(t - x\right)}{z} + t\right)} \]
      7. associate-+r+N/A

        \[\leadsto \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \frac{a \cdot \left(t - x\right)}{z}\right) + t} \]
      8. associate-/l*N/A

        \[\leadsto \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + \color{blue}{a \cdot \frac{t - x}{z}}\right) + t \]
      9. associate-/l*N/A

        \[\leadsto \left(-1 \cdot \color{blue}{\left(y \cdot \frac{t - x}{z}\right)} + a \cdot \frac{t - x}{z}\right) + t \]
      10. associate-*r*N/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot y\right) \cdot \frac{t - x}{z}} + a \cdot \frac{t - x}{z}\right) + t \]
      11. distribute-rgt-outN/A

        \[\leadsto \color{blue}{\frac{t - x}{z} \cdot \left(-1 \cdot y + a\right)} + t \]
      12. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{t - x}{z}, -1 \cdot y + a, t\right)} \]
    5. Applied rewrites85.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{t - x}{z}, \left(-y\right) + a, t\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites84.7%

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

      if 1.9999999999999998e293 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z))))

      1. Initial program 86.1%

        \[x + \left(y - z\right) \cdot \frac{t - x}{a - z} \]
      2. Add Preprocessing
      3. Taylor expanded in z around inf

        \[\leadsto x + \color{blue}{\left(t - x\right)} \]
      4. Step-by-step derivation
        1. lower--.f648.1

          \[\leadsto x + \color{blue}{\left(t - x\right)} \]
      5. Applied rewrites8.1%

        \[\leadsto x + \color{blue}{\left(t - x\right)} \]
      6. Taylor expanded in y around inf

        \[\leadsto x + \color{blue}{\frac{y \cdot \left(t - x\right)}{a - z}} \]
      7. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto x + \color{blue}{\frac{y \cdot \left(t - x\right)}{a - z}} \]
        2. *-commutativeN/A

          \[\leadsto x + \frac{\color{blue}{\left(t - x\right) \cdot y}}{a - z} \]
        3. lower-*.f64N/A

          \[\leadsto x + \frac{\color{blue}{\left(t - x\right) \cdot y}}{a - z} \]
        4. lower--.f64N/A

          \[\leadsto x + \frac{\color{blue}{\left(t - x\right)} \cdot y}{a - z} \]
        5. lower--.f6485.6

          \[\leadsto x + \frac{\left(t - x\right) \cdot y}{\color{blue}{a - z}} \]
      8. Applied rewrites85.6%

        \[\leadsto x + \color{blue}{\frac{\left(t - x\right) \cdot y}{a - z}} \]
    7. Recombined 3 regimes into one program.
    8. Final simplification90.8%

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

    Reproduce

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