
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
double code(double x, double y, double z, double t) {
return x + (((y - x) * z) / 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 = x + (((y - x) * z) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + (((y - x) * z) / t);
}
def code(x, y, z, t): return x + (((y - x) * z) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(Float64(y - x) * z) / t)) end
function tmp = code(x, y, z, t) tmp = x + (((y - x) * z) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left(y - x\right) \cdot z}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
double code(double x, double y, double z, double t) {
return x + (((y - x) * z) / 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 = x + (((y - x) * z) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + (((y - x) * z) / t);
}
def code(x, y, z, t): return x + (((y - x) * z) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(Float64(y - x) * z) / t)) end
function tmp = code(x, y, z, t) tmp = x + (((y - x) * z) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left(y - x\right) \cdot z}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (fma (/ z t) (- y x) x))
double code(double x, double y, double z, double t) {
return fma((z / t), (y - x), x);
}
function code(x, y, z, t) return fma(Float64(z / t), Float64(y - x), x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y - x, x\right)
\end{array}
Initial program 92.4%
+-commutative92.4%
*-commutative92.4%
associate-*l/98.5%
fma-def98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x y z t) :precision binary64 (if (<= t -3.1e+218) (+ x (* (/ z t) y)) (if (<= t 1.3e+56) (+ x (/ (* z (- y x)) t)) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3.1e+218) {
tmp = x + ((z / t) * y);
} else if (t <= 1.3e+56) {
tmp = x + ((z * (y - x)) / t);
} else {
tmp = x + (z / (t / y));
}
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 <= (-3.1d+218)) then
tmp = x + ((z / t) * y)
else if (t <= 1.3d+56) then
tmp = x + ((z * (y - x)) / t)
else
tmp = x + (z / (t / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3.1e+218) {
tmp = x + ((z / t) * y);
} else if (t <= 1.3e+56) {
tmp = x + ((z * (y - x)) / t);
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3.1e+218: tmp = x + ((z / t) * y) elif t <= 1.3e+56: tmp = x + ((z * (y - x)) / t) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3.1e+218) tmp = Float64(x + Float64(Float64(z / t) * y)); elseif (t <= 1.3e+56) tmp = Float64(x + Float64(Float64(z * Float64(y - x)) / t)); else tmp = Float64(x + Float64(z / Float64(t / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -3.1e+218) tmp = x + ((z / t) * y); elseif (t <= 1.3e+56) tmp = x + ((z * (y - x)) / t); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3.1e+218], N[(x + N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.3e+56], N[(x + N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.1 \cdot 10^{+218}:\\
\;\;\;\;x + \frac{z}{t} \cdot y\\
\mathbf{elif}\;t \leq 1.3 \cdot 10^{+56}:\\
\;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if t < -3.1000000000000002e218Initial program 77.0%
Taylor expanded in y around inf 86.7%
associate-*r/100.0%
Simplified100.0%
if -3.1000000000000002e218 < t < 1.30000000000000005e56Initial program 97.4%
if 1.30000000000000005e56 < t Initial program 79.1%
Taylor expanded in y around inf 83.1%
associate-*r/89.9%
Simplified89.9%
Taylor expanded in y around 0 83.1%
*-commutative83.1%
associate-/l*90.7%
Simplified90.7%
Final simplification96.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.65e-115) (not (<= y 2.75e-73))) (+ x (* (/ z t) y)) (- x (* (/ z t) x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.65e-115) || !(y <= 2.75e-73)) {
tmp = x + ((z / t) * y);
} else {
tmp = x - ((z / t) * 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 <= (-1.65d-115)) .or. (.not. (y <= 2.75d-73))) then
tmp = x + ((z / t) * y)
else
tmp = x - ((z / t) * x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.65e-115) || !(y <= 2.75e-73)) {
tmp = x + ((z / t) * y);
} else {
tmp = x - ((z / t) * x);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.65e-115) or not (y <= 2.75e-73): tmp = x + ((z / t) * y) else: tmp = x - ((z / t) * x) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.65e-115) || !(y <= 2.75e-73)) tmp = Float64(x + Float64(Float64(z / t) * y)); else tmp = Float64(x - Float64(Float64(z / t) * x)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.65e-115) || ~((y <= 2.75e-73))) tmp = x + ((z / t) * y); else tmp = x - ((z / t) * x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.65e-115], N[Not[LessEqual[y, 2.75e-73]], $MachinePrecision]], N[(x + N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(z / t), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-115} \lor \neg \left(y \leq 2.75 \cdot 10^{-73}\right):\\
\;\;\;\;x + \frac{z}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot x\\
\end{array}
\end{array}
if y < -1.64999999999999995e-115 or 2.75000000000000003e-73 < y Initial program 90.9%
Taylor expanded in y around inf 85.6%
associate-*r/90.2%
Simplified90.2%
if -1.64999999999999995e-115 < y < 2.75000000000000003e-73Initial program 95.4%
Taylor expanded in x around inf 90.0%
*-commutative90.0%
distribute-rgt-in90.0%
*-lft-identity90.0%
mul-1-neg90.0%
cancel-sign-sub-inv90.0%
*-commutative90.0%
Simplified90.0%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -8000000.0) (not (<= z 4.7e-57))) (* z (/ y t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8000000.0) || !(z <= 4.7e-57)) {
tmp = z * (y / t);
} 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 ((z <= (-8000000.0d0)) .or. (.not. (z <= 4.7d-57))) then
tmp = z * (y / t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8000000.0) || !(z <= 4.7e-57)) {
tmp = z * (y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8000000.0) or not (z <= 4.7e-57): tmp = z * (y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8000000.0) || !(z <= 4.7e-57)) tmp = Float64(z * Float64(y / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -8000000.0) || ~((z <= 4.7e-57))) tmp = z * (y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8000000.0], N[Not[LessEqual[z, 4.7e-57]], $MachinePrecision]], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8000000 \lor \neg \left(z \leq 4.7 \cdot 10^{-57}\right):\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8e6 or 4.6999999999999998e-57 < z Initial program 86.4%
associate-/l*97.7%
div-sub88.0%
associate-+r-88.0%
div-inv88.0%
clear-num88.0%
div-inv88.0%
clear-num88.0%
Applied egg-rr88.0%
Taylor expanded in t around 0 70.9%
Taylor expanded in y around inf 47.9%
*-commutative47.9%
Simplified47.9%
associate-/l*52.8%
clear-num52.8%
associate-/r/52.8%
clear-num53.1%
Applied egg-rr53.1%
if -8e6 < z < 4.6999999999999998e-57Initial program 98.4%
Taylor expanded in z around 0 63.2%
Final simplification58.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.2e+37) (not (<= y 3.2e-9))) (* (/ z t) y) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.2e+37) || !(y <= 3.2e-9)) {
tmp = (z / t) * y;
} 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 <= (-2.2d+37)) .or. (.not. (y <= 3.2d-9))) then
tmp = (z / t) * y
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 <= -2.2e+37) || !(y <= 3.2e-9)) {
tmp = (z / t) * y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.2e+37) or not (y <= 3.2e-9): tmp = (z / t) * y else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.2e+37) || !(y <= 3.2e-9)) tmp = Float64(Float64(z / t) * y); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -2.2e+37) || ~((y <= 3.2e-9))) tmp = (z / t) * y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.2e+37], N[Not[LessEqual[y, 3.2e-9]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+37} \lor \neg \left(y \leq 3.2 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{z}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.2000000000000001e37 or 3.20000000000000012e-9 < y Initial program 91.6%
associate-/l*99.1%
div-sub93.5%
associate-+r-93.5%
div-inv93.5%
clear-num93.8%
div-inv93.8%
clear-num93.8%
Applied egg-rr93.8%
Taylor expanded in t around 0 62.4%
Taylor expanded in y around inf 58.7%
*-commutative58.7%
Simplified58.7%
associate-*l/64.1%
Applied egg-rr64.1%
if -2.2000000000000001e37 < y < 3.20000000000000012e-9Initial program 93.2%
Taylor expanded in z around 0 55.0%
Final simplification59.5%
(FPCore (x y z t) :precision binary64 (+ x (/ (- y x) (/ t z))))
double code(double x, double y, double z, double t) {
return x + ((y - x) / (t / 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 + ((y - x) / (t / z))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - x) / (t / z));
}
def code(x, y, z, t): return x + ((y - x) / (t / z))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - x) / Float64(t / z))) end
function tmp = code(x, y, z, t) tmp = x + ((y - x) / (t / z)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{\frac{t}{z}}
\end{array}
Initial program 92.4%
associate-/l*98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z t) :precision binary64 (+ x (* (/ z t) y)))
double code(double x, double y, double z, double t) {
return x + ((z / 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 = x + ((z / t) * y)
end function
public static double code(double x, double y, double z, double t) {
return x + ((z / t) * y);
}
def code(x, y, z, t): return x + ((z / t) * y)
function code(x, y, z, t) return Float64(x + Float64(Float64(z / t) * y)) end
function tmp = code(x, y, z, t) tmp = x + ((z / t) * y); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z}{t} \cdot y
\end{array}
Initial program 92.4%
Taylor expanded in y around inf 76.8%
associate-*r/80.6%
Simplified80.6%
Final simplification80.6%
(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}
Initial program 92.4%
Taylor expanded in z around 0 42.7%
Final simplification42.7%
(FPCore (x y z t)
:precision binary64
(if (< x -9.025511195533005e-135)
(- x (* (/ z t) (- x y)))
(if (< x 4.275032163700715e-250)
(+ x (* (/ (- y x) t) z))
(+ x (/ (- y x) (/ t z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x < -9.025511195533005e-135) {
tmp = x - ((z / t) * (x - y));
} else if (x < 4.275032163700715e-250) {
tmp = x + (((y - x) / t) * z);
} else {
tmp = x + ((y - x) / (t / 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 (x < (-9.025511195533005d-135)) then
tmp = x - ((z / t) * (x - y))
else if (x < 4.275032163700715d-250) then
tmp = x + (((y - x) / t) * z)
else
tmp = x + ((y - x) / (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x < -9.025511195533005e-135) {
tmp = x - ((z / t) * (x - y));
} else if (x < 4.275032163700715e-250) {
tmp = x + (((y - x) / t) * z);
} else {
tmp = x + ((y - x) / (t / z));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x < -9.025511195533005e-135: tmp = x - ((z / t) * (x - y)) elif x < 4.275032163700715e-250: tmp = x + (((y - x) / t) * z) else: tmp = x + ((y - x) / (t / z)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x < -9.025511195533005e-135) tmp = Float64(x - Float64(Float64(z / t) * Float64(x - y))); elseif (x < 4.275032163700715e-250) tmp = Float64(x + Float64(Float64(Float64(y - x) / t) * z)); else tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x < -9.025511195533005e-135) tmp = x - ((z / t) * (x - y)); elseif (x < 4.275032163700715e-250) tmp = x + (((y - x) / t) * z); else tmp = x + ((y - x) / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Less[x, -9.025511195533005e-135], N[(x - N[(N[(z / t), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Less[x, 4.275032163700715e-250], N[(x + N[(N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\
\;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\
\mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\
\;\;\;\;x + \frac{y - x}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\
\end{array}
\end{array}
herbie shell --seed 2023228
(FPCore (x y z t)
:name "Numeric.Histogram:binBounds from Chart-1.5.3"
:precision binary64
:herbie-target
(if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))
(+ x (/ (* (- y x) z) t)))