
(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:
Herbie found 19 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -4.99999999999999965e-304Initial program 92.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
neg-sub0N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
associate--r+N/A
neg-sub0N/A
remove-double-negN/A
lower--.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6496.9
Applied rewrites96.9%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
clear-numN/A
metadata-evalN/A
lower-/.f64N/A
metadata-evalN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6497.0
Applied rewrites97.0%
if -4.99999999999999965e-304 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.8%
Taylor expanded in z around inf
+-commutativeN/A
associate--l+N/A
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
associate-+r+N/A
associate-/l*N/A
associate-/l*N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-fma.f64N/A
Applied rewrites99.8%
if 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 92.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
frac-2negN/A
div-invN/A
associate-*l*N/A
lower-fma.f64N/A
neg-sub0N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
associate--r+N/A
neg-sub0N/A
remove-double-negN/A
lower--.f64N/A
lower-*.f64N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f6496.3
Applied rewrites96.3%
Final simplification97.0%
(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}
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.9999999999999998e293Initial program 92.6%
if -2.0000000000000001e-168 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 14.8%
Taylor expanded in z around inf
+-commutativeN/A
associate--l+N/A
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
associate-+r+N/A
associate-/l*N/A
associate-/l*N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-fma.f64N/A
Applied rewrites85.5%
Applied rewrites84.7%
if 1.9999999999999998e293 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 86.1%
Taylor expanded in z around inf
lower--.f648.1
Applied rewrites8.1%
Taylor expanded in y around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f6485.6
Applied rewrites85.6%
Final simplification90.8%
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)))))