
(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 7 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 (+ 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}
Initial program 100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -3.3e+54)
t_1
(if (<= y -4.6e-35)
(* (- x t) z)
(if (<= y -6.5e-164)
(fma x z x)
(if (<= y 3.4e-251)
(fma (- t) z x)
(if (<= y 2.75e+20) (fma x z x) t_1)))))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -3.3e+54) {
tmp = t_1;
} else if (y <= -4.6e-35) {
tmp = (x - t) * z;
} else if (y <= -6.5e-164) {
tmp = fma(x, z, x);
} else if (y <= 3.4e-251) {
tmp = fma(-t, z, x);
} else if (y <= 2.75e+20) {
tmp = fma(x, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -3.3e+54) tmp = t_1; elseif (y <= -4.6e-35) tmp = Float64(Float64(x - t) * z); elseif (y <= -6.5e-164) tmp = fma(x, z, x); elseif (y <= 3.4e-251) tmp = fma(Float64(-t), z, x); elseif (y <= 2.75e+20) tmp = fma(x, z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -3.3e+54], t$95$1, If[LessEqual[y, -4.6e-35], N[(N[(x - t), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, -6.5e-164], N[(x * z + x), $MachinePrecision], If[LessEqual[y, 3.4e-251], N[((-t) * z + x), $MachinePrecision], If[LessEqual[y, 2.75e+20], N[(x * z + x), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{+54}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{-35}:\\
\;\;\;\;\left(x - t\right) \cdot z\\
\mathbf{elif}\;y \leq -6.5 \cdot 10^{-164}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-251}:\\
\;\;\;\;\mathsf{fma}\left(-t, z, x\right)\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.3e54 or 2.75e20 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.7
Applied rewrites82.7%
if -3.3e54 < y < -4.5999999999999998e-35Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6462.4
Applied rewrites62.4%
if -4.5999999999999998e-35 < y < -6.50000000000000004e-164 or 3.40000000000000017e-251 < y < 2.75e20Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6482.4
Applied rewrites82.4%
Taylor expanded in x around 0
Applied rewrites48.1%
Taylor expanded in x around inf
Applied rewrites66.6%
if -6.50000000000000004e-164 < y < 3.40000000000000017e-251Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites83.1%
Final simplification76.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -7.3e+53)
t_1
(if (<= y -6.5e-164)
(fma x z x)
(if (<= y 3.4e-251)
(fma (- t) z x)
(if (<= y 2.75e+20) (fma x z x) t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -7.3e+53) {
tmp = t_1;
} else if (y <= -6.5e-164) {
tmp = fma(x, z, x);
} else if (y <= 3.4e-251) {
tmp = fma(-t, z, x);
} else if (y <= 2.75e+20) {
tmp = fma(x, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * y) tmp = 0.0 if (y <= -7.3e+53) tmp = t_1; elseif (y <= -6.5e-164) tmp = fma(x, z, x); elseif (y <= 3.4e-251) tmp = fma(Float64(-t), z, x); elseif (y <= 2.75e+20) tmp = fma(x, z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -7.3e+53], t$95$1, If[LessEqual[y, -6.5e-164], N[(x * z + x), $MachinePrecision], If[LessEqual[y, 3.4e-251], N[((-t) * z + x), $MachinePrecision], If[LessEqual[y, 2.75e+20], N[(x * z + x), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -7.3 \cdot 10^{+53}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -6.5 \cdot 10^{-164}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-251}:\\
\;\;\;\;\mathsf{fma}\left(-t, z, x\right)\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -7.30000000000000016e53 or 2.75e20 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.7
Applied rewrites82.7%
if -7.30000000000000016e53 < y < -6.50000000000000004e-164 or 3.40000000000000017e-251 < y < 2.75e20Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6479.2
Applied rewrites79.2%
Taylor expanded in x around 0
Applied rewrites46.3%
Taylor expanded in x around inf
Applied rewrites61.3%
if -6.50000000000000004e-164 < y < 3.40000000000000017e-251Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites83.1%
Final simplification74.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.05e+103) (not (<= z 1.25e+48))) (* (- x t) z) (fma (- t x) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.05e+103) || !(z <= 1.25e+48)) {
tmp = (x - t) * z;
} else {
tmp = fma((t - x), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.05e+103) || !(z <= 1.25e+48)) tmp = Float64(Float64(x - t) * z); else tmp = fma(Float64(t - x), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.05e+103], N[Not[LessEqual[z, 1.25e+48]], $MachinePrecision]], N[(N[(x - t), $MachinePrecision] * z), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{+103} \lor \neg \left(z \leq 1.25 \cdot 10^{+48}\right):\\
\;\;\;\;\left(x - t\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, y, x\right)\\
\end{array}
\end{array}
if z < -1.0500000000000001e103 or 1.24999999999999993e48 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f6498.1
Applied rewrites98.1%
Taylor expanded in z around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6488.1
Applied rewrites88.1%
if -1.0500000000000001e103 < z < 1.24999999999999993e48Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6484.2
Applied rewrites84.2%
Final simplification85.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -7.3e+53) (not (<= y 2.75e+20))) (* (- t x) y) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.3e+53) || !(y <= 2.75e+20)) {
tmp = (t - x) * y;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.3e+53) || !(y <= 2.75e+20)) tmp = Float64(Float64(t - x) * y); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.3e+53], N[Not[LessEqual[y, 2.75e+20]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * y), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.3 \cdot 10^{+53} \lor \neg \left(y \leq 2.75 \cdot 10^{+20}\right):\\
\;\;\;\;\left(t - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -7.30000000000000016e53 or 2.75e20 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.7
Applied rewrites82.7%
if -7.30000000000000016e53 < y < 2.75e20Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6485.9
Applied rewrites85.9%
Taylor expanded in x around 0
Applied rewrites58.1%
Taylor expanded in x around inf
Applied rewrites56.8%
Final simplification68.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.92e+55) (not (<= y 1.12e+86))) (* y t) (fma x z x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.92e+55) || !(y <= 1.12e+86)) {
tmp = y * t;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.92e+55) || !(y <= 1.12e+86)) tmp = Float64(y * t); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.92e+55], N[Not[LessEqual[y, 1.12e+86]], $MachinePrecision]], N[(y * t), $MachinePrecision], N[(x * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.92 \cdot 10^{+55} \lor \neg \left(y \leq 1.12 \cdot 10^{+86}\right):\\
\;\;\;\;y \cdot t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if y < -1.91999999999999999e55 or 1.12e86 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6485.4
Applied rewrites85.4%
Taylor expanded in x around 0
Applied rewrites52.8%
if -1.91999999999999999e55 < y < 1.12e86Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
lower--.f6483.7
Applied rewrites83.7%
Taylor expanded in x around 0
Applied rewrites55.0%
Taylor expanded in x around inf
Applied rewrites55.8%
Final simplification54.6%
(FPCore (x y z t) :precision binary64 (* y t))
double code(double x, double y, double z, double t) {
return y * t;
}
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 = y * t
end function
public static double code(double x, double y, double z, double t) {
return y * t;
}
def code(x, y, z, t): return y * t
function code(x, y, z, t) return Float64(y * t) end
function tmp = code(x, y, z, t) tmp = y * t; end
code[x_, y_, z_, t_] := N[(y * t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot t
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6444.4
Applied rewrites44.4%
Taylor expanded in x around 0
Applied rewrites28.7%
Final simplification28.7%
(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 2024324
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
(+ x (* (- y z) (- t x))))