
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
(FPCore (x y z t) :precision binary64 (fma (- y z) (- t x) x))
double code(double x, double y, double z, double t) {
return fma((y - z), (t - x), x);
}
function code(x, y, z, t) return fma(Float64(y - z), Float64(t - x), x) end
code[x_, y_, z_, t_] := N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, t - x, x\right)
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (- t x))))
(if (<= y -170000000000.0)
t_1
(if (<= y 1.9e-144)
(- x (* z t))
(if (<= y 2.35e+67) (* x (- 1.0 (- y z))) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (t - x);
double tmp;
if (y <= -170000000000.0) {
tmp = t_1;
} else if (y <= 1.9e-144) {
tmp = x - (z * t);
} else if (y <= 2.35e+67) {
tmp = x * (1.0 - (y - z));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * (t - x)
if (y <= (-170000000000.0d0)) then
tmp = t_1
else if (y <= 1.9d-144) then
tmp = x - (z * t)
else if (y <= 2.35d+67) then
tmp = x * (1.0d0 - (y - z))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (t - x);
double tmp;
if (y <= -170000000000.0) {
tmp = t_1;
} else if (y <= 1.9e-144) {
tmp = x - (z * t);
} else if (y <= 2.35e+67) {
tmp = x * (1.0 - (y - z));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (t - x) tmp = 0 if y <= -170000000000.0: tmp = t_1 elif y <= 1.9e-144: tmp = x - (z * t) elif y <= 2.35e+67: tmp = x * (1.0 - (y - z)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(t - x)) tmp = 0.0 if (y <= -170000000000.0) tmp = t_1; elseif (y <= 1.9e-144) tmp = Float64(x - Float64(z * t)); elseif (y <= 2.35e+67) tmp = Float64(x * Float64(1.0 - Float64(y - z))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (t - x); tmp = 0.0; if (y <= -170000000000.0) tmp = t_1; elseif (y <= 1.9e-144) tmp = x - (z * t); elseif (y <= 2.35e+67) tmp = x * (1.0 - (y - z)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -170000000000.0], t$95$1, If[LessEqual[y, 1.9e-144], N[(x - N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.35e+67], N[(x * N[(1.0 - N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(t - x\right)\\
\mathbf{if}\;y \leq -170000000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-144}:\\
\;\;\;\;x - z \cdot t\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{+67}:\\
\;\;\;\;x \cdot \left(1 - \left(y - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (- t x))))
(if (<= y -600000000000.0)
t_1
(if (<= y 7.8e-144)
(- x (* z t))
(if (<= y 9e+14) (* x (+ z 1.0)) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (t - x);
double tmp;
if (y <= -600000000000.0) {
tmp = t_1;
} else if (y <= 7.8e-144) {
tmp = x - (z * t);
} else if (y <= 9e+14) {
tmp = x * (z + 1.0);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * (t - x)
if (y <= (-600000000000.0d0)) then
tmp = t_1
else if (y <= 7.8d-144) then
tmp = x - (z * t)
else if (y <= 9d+14) then
tmp = x * (z + 1.0d0)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (t - x);
double tmp;
if (y <= -600000000000.0) {
tmp = t_1;
} else if (y <= 7.8e-144) {
tmp = x - (z * t);
} else if (y <= 9e+14) {
tmp = x * (z + 1.0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (t - x) tmp = 0 if y <= -600000000000.0: tmp = t_1 elif y <= 7.8e-144: tmp = x - (z * t) elif y <= 9e+14: tmp = x * (z + 1.0) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(t - x)) tmp = 0.0 if (y <= -600000000000.0) tmp = t_1; elseif (y <= 7.8e-144) tmp = Float64(x - Float64(z * t)); elseif (y <= 9e+14) tmp = Float64(x * Float64(z + 1.0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (t - x); tmp = 0.0; if (y <= -600000000000.0) tmp = t_1; elseif (y <= 7.8e-144) tmp = x - (z * t); elseif (y <= 9e+14) tmp = x * (z + 1.0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -600000000000.0], t$95$1, If[LessEqual[y, 7.8e-144], N[(x - N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9e+14], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(t - x\right)\\
\mathbf{if}\;y \leq -600000000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-144}:\\
\;\;\;\;x - z \cdot t\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+14}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.85e+37) (not (<= t 2.6e-78))) (+ x (* (- y z) t)) (* x (- 1.0 (- y z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.85e+37) || !(t <= 2.6e-78)) {
tmp = x + ((y - z) * t);
} else {
tmp = x * (1.0 - (y - z));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((t <= (-1.85d+37)) .or. (.not. (t <= 2.6d-78))) then
tmp = x + ((y - z) * t)
else
tmp = x * (1.0d0 - (y - z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.85e+37) || !(t <= 2.6e-78)) {
tmp = x + ((y - z) * t);
} else {
tmp = x * (1.0 - (y - z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -1.85e+37) or not (t <= 2.6e-78): tmp = x + ((y - z) * t) else: tmp = x * (1.0 - (y - z)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.85e+37) || !(t <= 2.6e-78)) tmp = Float64(x + Float64(Float64(y - z) * t)); else tmp = Float64(x * Float64(1.0 - Float64(y - z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -1.85e+37) || ~((t <= 2.6e-78))) tmp = x + ((y - z) * t); else tmp = x * (1.0 - (y - z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.85e+37], N[Not[LessEqual[t, 2.6e-78]], $MachinePrecision]], N[(x + N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.85 \cdot 10^{+37} \lor \neg \left(t \leq 2.6 \cdot 10^{-78}\right):\\
\;\;\;\;x + \left(y - z\right) \cdot t\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \left(y - z\right)\right)\\
\end{array}
\end{array}
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.65e+45) (not (<= y 8e+66))) (* y (- x)) (* x (+ z 1.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.65e+45) || !(y <= 8e+66)) {
tmp = y * -x;
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-2.65d+45)) .or. (.not. (y <= 8d+66))) then
tmp = y * -x
else
tmp = x * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.65e+45) || !(y <= 8e+66)) {
tmp = y * -x;
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.65e+45) or not (y <= 8e+66): tmp = y * -x else: tmp = x * (z + 1.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.65e+45) || !(y <= 8e+66)) tmp = Float64(y * Float64(-x)); else tmp = Float64(x * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -2.65e+45) || ~((y <= 8e+66))) tmp = y * -x; else tmp = x * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.65e+45], N[Not[LessEqual[y, 8e+66]], $MachinePrecision]], N[(y * (-x)), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{+45} \lor \neg \left(y \leq 8 \cdot 10^{+66}\right):\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\end{array}
\end{array}
(FPCore (x y z t) :precision binary64 (if (or (<= y -15500000000.0) (not (<= y 82000000000000.0))) (* y (- t x)) (* x (+ z 1.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -15500000000.0) || !(y <= 82000000000000.0)) {
tmp = y * (t - x);
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-15500000000.0d0)) .or. (.not. (y <= 82000000000000.0d0))) then
tmp = y * (t - x)
else
tmp = x * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -15500000000.0) || !(y <= 82000000000000.0)) {
tmp = y * (t - x);
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -15500000000.0) or not (y <= 82000000000000.0): tmp = y * (t - x) else: tmp = x * (z + 1.0) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -15500000000.0) || !(y <= 82000000000000.0)) tmp = Float64(y * Float64(t - x)); else tmp = Float64(x * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -15500000000.0) || ~((y <= 82000000000000.0))) tmp = y * (t - x); else tmp = x * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -15500000000.0], N[Not[LessEqual[y, 82000000000000.0]], $MachinePrecision]], N[(y * N[(t - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -15500000000 \lor \neg \left(y \leq 82000000000000\right):\\
\;\;\;\;y \cdot \left(t - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\end{array}
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
(FPCore (x y z t) :precision binary64 (if (or (<= y -0.000175) (not (<= y 1.15e-30))) (* y (- x)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -0.000175) || !(y <= 1.15e-30)) {
tmp = y * -x;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((y <= (-0.000175d0)) .or. (.not. (y <= 1.15d-30))) then
tmp = y * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -0.000175) || !(y <= 1.15e-30)) {
tmp = y * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -0.000175) or not (y <= 1.15e-30): tmp = y * -x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -0.000175) || !(y <= 1.15e-30)) tmp = Float64(y * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -0.000175) || ~((y <= 1.15e-30))) tmp = y * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -0.000175], N[Not[LessEqual[y, 1.15e-30]], $MachinePrecision]], N[(y * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000175 \lor \neg \left(y \leq 1.15 \cdot 10^{-30}\right):\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((t * (y - z)) + (-x * (y - z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
def code(x, y, z, t): return x + ((t * (y - z)) + (-x * (y - z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(t * Float64(y - z)) + Float64(Float64(-x) * Float64(y - z)))) end
function tmp = code(x, y, z, t) tmp = x + ((t * (y - z)) + (-x * (y - z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right)
\end{array}
herbie shell --seed 2024010
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:herbie-target
(+ x (+ (* t (- y z)) (* (- x) (- y z))))
(+ x (* (- y z) (- t x))))