
(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 (+ (* (- t x) (- y z)) x))
double code(double x, double y, double z, double t) {
return ((t - x) * (y - z)) + 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 = ((t - x) * (y - z)) + x
end function
public static double code(double x, double y, double z, double t) {
return ((t - x) * (y - z)) + x;
}
def code(x, y, z, t): return ((t - x) * (y - z)) + x
function code(x, y, z, t) return Float64(Float64(Float64(t - x) * Float64(y - z)) + x) end
function tmp = code(x, y, z, t) tmp = ((t - x) * (y - z)) + x; end
code[x_, y_, z_, t_] := N[(N[(N[(t - x), $MachinePrecision] * N[(y - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(t - x\right) \cdot \left(y - z\right) + x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(if (<= y -2.6e+60)
(* t y)
(if (<= y 45000000000000.0)
(fma x z x)
(if (<= y 5.4e+150) (* (- x) y) (* t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.6e+60) {
tmp = t * y;
} else if (y <= 45000000000000.0) {
tmp = fma(x, z, x);
} else if (y <= 5.4e+150) {
tmp = -x * y;
} else {
tmp = t * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -2.6e+60) tmp = Float64(t * y); elseif (y <= 45000000000000.0) tmp = fma(x, z, x); elseif (y <= 5.4e+150) tmp = Float64(Float64(-x) * y); else tmp = Float64(t * y); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.6e+60], N[(t * y), $MachinePrecision], If[LessEqual[y, 45000000000000.0], N[(x * z + x), $MachinePrecision], If[LessEqual[y, 5.4e+150], N[((-x) * y), $MachinePrecision], N[(t * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+60}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;y \leq 45000000000000:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+150}:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t \cdot y\\
\end{array}
\end{array}
if y < -2.60000000000000008e60 or 5.40000000000000015e150 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.3
Applied rewrites91.3%
Taylor expanded in x around 0
Applied rewrites56.9%
if -2.60000000000000008e60 < y < 4.5e13Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/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--.f6463.1
Applied rewrites63.1%
Taylor expanded in y around 0
Applied rewrites61.4%
if 4.5e13 < y < 5.40000000000000015e150Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6472.2
Applied rewrites72.2%
Taylor expanded in x around inf
Applied rewrites49.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- t x) y)))
(if (<= y -1.52e+41)
t_1
(if (<= y 2200000000000.0) (fma (- x t) z x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * y;
double tmp;
if (y <= -1.52e+41) {
tmp = t_1;
} else if (y <= 2200000000000.0) {
tmp = fma((x - t), 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 <= -1.52e+41) tmp = t_1; elseif (y <= 2200000000000.0) tmp = fma(Float64(x - t), 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, -1.52e+41], t$95$1, If[LessEqual[y, 2200000000000.0], N[(N[(x - t), $MachinePrecision] * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot y\\
\mathbf{if}\;y \leq -1.52 \cdot 10^{+41}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2200000000000:\\
\;\;\;\;\mathsf{fma}\left(x - t, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.52000000000000002e41 or 2.2e12 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6484.9
Applied rewrites84.9%
if -1.52000000000000002e41 < y < 2.2e12Initial 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--.f6490.0
Applied rewrites90.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- t x) y))) (if (<= y -4.3e+18) t_1 (if (<= y 1.95e-15) (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 <= -4.3e+18) {
tmp = t_1;
} else if (y <= 1.95e-15) {
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 <= -4.3e+18) tmp = t_1; elseif (y <= 1.95e-15) 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, -4.3e+18], t$95$1, If[LessEqual[y, 1.95e-15], 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 -4.3 \cdot 10^{+18}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.95 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.3e18 or 1.95000000000000013e-15 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6481.3
Applied rewrites81.3%
if -4.3e18 < y < 1.95000000000000013e-15Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/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--.f6465.3
Applied rewrites65.3%
Taylor expanded in y around 0
Applied rewrites65.3%
(FPCore (x y z t) :precision binary64 (if (<= y -2.6e+60) (* t y) (if (<= y 4.8e+105) (fma x z x) (* t y))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.6e+60) {
tmp = t * y;
} else if (y <= 4.8e+105) {
tmp = fma(x, z, x);
} else {
tmp = t * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -2.6e+60) tmp = Float64(t * y); elseif (y <= 4.8e+105) tmp = fma(x, z, x); else tmp = Float64(t * y); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.6e+60], N[(t * y), $MachinePrecision], If[LessEqual[y, 4.8e+105], N[(x * z + x), $MachinePrecision], N[(t * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+60}:\\
\;\;\;\;t \cdot y\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+105}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot y\\
\end{array}
\end{array}
if y < -2.60000000000000008e60 or 4.7999999999999995e105 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6490.4
Applied rewrites90.4%
Taylor expanded in x around 0
Applied rewrites52.8%
if -2.60000000000000008e60 < y < 4.7999999999999995e105Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/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--.f6463.2
Applied rewrites63.2%
Taylor expanded in y around 0
Applied rewrites58.2%
(FPCore (x y z t) :precision binary64 (if (<= z -3.3e+20) (* z x) (if (<= z 4.1e+30) (* t y) (* z x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.3e+20) {
tmp = z * x;
} else if (z <= 4.1e+30) {
tmp = t * y;
} else {
tmp = z * 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 (z <= (-3.3d+20)) then
tmp = z * x
else if (z <= 4.1d+30) then
tmp = t * y
else
tmp = z * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.3e+20) {
tmp = z * x;
} else if (z <= 4.1e+30) {
tmp = t * y;
} else {
tmp = z * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -3.3e+20: tmp = z * x elif z <= 4.1e+30: tmp = t * y else: tmp = z * x return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -3.3e+20) tmp = Float64(z * x); elseif (z <= 4.1e+30) tmp = Float64(t * y); else tmp = Float64(z * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -3.3e+20) tmp = z * x; elseif (z <= 4.1e+30) tmp = t * y; else tmp = z * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.3e+20], N[(z * x), $MachinePrecision], If[LessEqual[z, 4.1e+30], N[(t * y), $MachinePrecision], N[(z * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+20}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{+30}:\\
\;\;\;\;t \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot x\\
\end{array}
\end{array}
if z < -3.3e20 or 4.10000000000000005e30 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/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--.f6459.2
Applied rewrites59.2%
Taylor expanded in z around inf
Applied rewrites47.6%
if -3.3e20 < z < 4.10000000000000005e30Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6457.5
Applied rewrites57.5%
Taylor expanded in x around 0
Applied rewrites36.2%
Final simplification41.1%
(FPCore (x y z t) :precision binary64 (* t y))
double code(double x, double y, double z, double t) {
return t * y;
}
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 = t * y
end function
public static double code(double x, double y, double z, double t) {
return t * y;
}
def code(x, y, z, t): return t * y
function code(x, y, z, t) return Float64(t * y) end
function tmp = code(x, y, z, t) tmp = t * y; end
code[x_, y_, z_, t_] := N[(t * y), $MachinePrecision]
\begin{array}{l}
\\
t \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6446.0
Applied rewrites46.0%
Taylor expanded in x around 0
Applied rewrites28.4%
(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 2024294
(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))))