
(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 10 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 (if (or (<= z -4.4e+102) (not (<= z 4.2e-231))) (+ x (* z (/ (- y x) t))) (+ x (/ (* z (- y x)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.4e+102) || !(z <= 4.2e-231)) {
tmp = x + (z * ((y - x) / t));
} else {
tmp = x + ((z * (y - x)) / t);
}
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 <= (-4.4d+102)) .or. (.not. (z <= 4.2d-231))) then
tmp = x + (z * ((y - x) / t))
else
tmp = x + ((z * (y - x)) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.4e+102) || !(z <= 4.2e-231)) {
tmp = x + (z * ((y - x) / t));
} else {
tmp = x + ((z * (y - x)) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.4e+102) or not (z <= 4.2e-231): tmp = x + (z * ((y - x) / t)) else: tmp = x + ((z * (y - x)) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.4e+102) || !(z <= 4.2e-231)) tmp = Float64(x + Float64(z * Float64(Float64(y - x) / t))); else tmp = Float64(x + Float64(Float64(z * Float64(y - x)) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.4e+102) || ~((z <= 4.2e-231))) tmp = x + (z * ((y - x) / t)); else tmp = x + ((z * (y - x)) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.4e+102], N[Not[LessEqual[z, 4.2e-231]], $MachinePrecision]], N[(x + N[(z * N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.4 \cdot 10^{+102} \lor \neg \left(z \leq 4.2 \cdot 10^{-231}\right):\\
\;\;\;\;x + z \cdot \frac{y - x}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot \left(y - x\right)}{t}\\
\end{array}
\end{array}
if z < -4.40000000000000015e102 or 4.19999999999999978e-231 < z Initial program 83.8%
associate-*l/99.8%
Applied egg-rr99.8%
if -4.40000000000000015e102 < z < 4.19999999999999978e-231Initial program 98.8%
Final simplification99.4%
(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 89.8%
+-commutative89.8%
*-commutative89.8%
associate-*l/98.3%
fma-def98.3%
Simplified98.3%
Final simplification98.3%
(FPCore (x y z t) :precision binary64 (if (or (<= x -6.2e-47) (not (<= x 1.25e-21))) (* x (- 1.0 (/ z t))) (+ x (* z (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -6.2e-47) || !(x <= 1.25e-21)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + (z * (y / t));
}
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 <= (-6.2d-47)) .or. (.not. (x <= 1.25d-21))) then
tmp = x * (1.0d0 - (z / t))
else
tmp = x + (z * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -6.2e-47) || !(x <= 1.25e-21)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -6.2e-47) or not (x <= 1.25e-21): tmp = x * (1.0 - (z / t)) else: tmp = x + (z * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -6.2e-47) || !(x <= 1.25e-21)) tmp = Float64(x * Float64(1.0 - Float64(z / t))); else tmp = Float64(x + Float64(z * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -6.2e-47) || ~((x <= 1.25e-21))) tmp = x * (1.0 - (z / t)); else tmp = x + (z * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -6.2e-47], N[Not[LessEqual[x, 1.25e-21]], $MachinePrecision]], N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-47} \lor \neg \left(x \leq 1.25 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -6.1999999999999996e-47 or 1.24999999999999993e-21 < x Initial program 89.0%
Taylor expanded in x around inf 89.6%
mul-1-neg89.6%
unsub-neg89.6%
Simplified89.6%
if -6.1999999999999996e-47 < x < 1.24999999999999993e-21Initial program 90.9%
Taylor expanded in y around inf 83.6%
associate-/l*90.6%
associate-/r/88.4%
Simplified88.4%
Final simplification89.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -9.6e-47) (not (<= x 1.26e-21))) (* x (- 1.0 (/ z t))) (+ x (* (/ z t) y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -9.6e-47) || !(x <= 1.26e-21)) {
tmp = x * (1.0 - (z / 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 ((x <= (-9.6d-47)) .or. (.not. (x <= 1.26d-21))) then
tmp = x * (1.0d0 - (z / 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 ((x <= -9.6e-47) || !(x <= 1.26e-21)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + ((z / t) * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -9.6e-47) or not (x <= 1.26e-21): tmp = x * (1.0 - (z / t)) else: tmp = x + ((z / t) * y) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -9.6e-47) || !(x <= 1.26e-21)) tmp = Float64(x * Float64(1.0 - Float64(z / t))); else tmp = Float64(x + Float64(Float64(z / t) * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -9.6e-47) || ~((x <= 1.26e-21))) tmp = x * (1.0 - (z / t)); else tmp = x + ((z / t) * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -9.6e-47], N[Not[LessEqual[x, 1.26e-21]], $MachinePrecision]], N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.6 \cdot 10^{-47} \lor \neg \left(x \leq 1.26 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{t} \cdot y\\
\end{array}
\end{array}
if x < -9.5999999999999998e-47 or 1.26e-21 < x Initial program 89.0%
Taylor expanded in x around inf 89.6%
mul-1-neg89.6%
unsub-neg89.6%
Simplified89.6%
if -9.5999999999999998e-47 < x < 1.26e-21Initial program 90.9%
Taylor expanded in y around inf 83.6%
associate-/l*90.6%
associate-/r/88.4%
Simplified88.4%
associate-*l/83.6%
associate-/l*90.6%
Applied egg-rr90.6%
clear-num90.7%
associate-/r/90.6%
clear-num90.7%
Applied egg-rr90.7%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (<= t -1.8e-56) x (if (<= t 3.6e+25) (* (/ z t) (- x)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.8e-56) {
tmp = x;
} else if (t <= 3.6e+25) {
tmp = (z / t) * -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 (t <= (-1.8d-56)) then
tmp = x
else if (t <= 3.6d+25) then
tmp = (z / t) * -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 (t <= -1.8e-56) {
tmp = x;
} else if (t <= 3.6e+25) {
tmp = (z / t) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -1.8e-56: tmp = x elif t <= 3.6e+25: tmp = (z / t) * -x else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -1.8e-56) tmp = x; elseif (t <= 3.6e+25) tmp = Float64(Float64(z / t) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -1.8e-56) tmp = x; elseif (t <= 3.6e+25) tmp = (z / t) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -1.8e-56], x, If[LessEqual[t, 3.6e+25], N[(N[(z / t), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.8 \cdot 10^{-56}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 3.6 \cdot 10^{+25}:\\
\;\;\;\;\frac{z}{t} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -1.79999999999999989e-56 or 3.60000000000000015e25 < t Initial program 82.4%
Taylor expanded in z around 0 58.4%
if -1.79999999999999989e-56 < t < 3.60000000000000015e25Initial program 98.2%
Taylor expanded in x around inf 66.5%
mul-1-neg66.5%
unsub-neg66.5%
Simplified66.5%
Taylor expanded in z around inf 52.8%
mul-1-neg52.8%
*-commutative52.8%
associate-*r/51.6%
distribute-rgt-neg-in51.6%
distribute-neg-frac51.6%
Simplified51.6%
Taylor expanded in z around 0 52.8%
mul-1-neg52.8%
associate-*l/51.6%
distribute-rgt-neg-out51.6%
associate-*l/52.8%
associate-*r/53.7%
Simplified53.7%
Final simplification56.2%
(FPCore (x y z t) :precision binary64 (+ x (* z (/ (- y x) t))))
double code(double x, double y, double z, double t) {
return x + (z * ((y - x) / 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 + (z * ((y - x) / t))
end function
public static double code(double x, double y, double z, double t) {
return x + (z * ((y - x) / t));
}
def code(x, y, z, t): return x + (z * ((y - x) / t))
function code(x, y, z, t) return Float64(x + Float64(z * Float64(Float64(y - x) / t))) end
function tmp = code(x, y, z, t) tmp = x + (z * ((y - x) / t)); end
code[x_, y_, z_, t_] := N[(x + N[(z * N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \frac{y - x}{t}
\end{array}
Initial program 89.8%
associate-*l/95.0%
Applied egg-rr95.0%
Final simplification95.0%
(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 89.8%
associate-/l*98.2%
Simplified98.2%
Final simplification98.2%
(FPCore (x y z t) :precision binary64 (+ x (* (/ z t) (- y x))))
double code(double x, double y, double z, double t) {
return x + ((z / t) * (y - 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 + ((z / t) * (y - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z / t) * (y - x));
}
def code(x, y, z, t): return x + ((z / t) * (y - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(z / t) * Float64(y - x))) end
function tmp = code(x, y, z, t) tmp = x + ((z / t) * (y - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z / t), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z}{t} \cdot \left(y - x\right)
\end{array}
Initial program 89.8%
+-commutative89.8%
*-commutative89.8%
associate-*l/98.3%
fma-def98.3%
Simplified98.3%
fma-udef98.3%
*-commutative98.3%
Applied egg-rr98.3%
Final simplification98.3%
(FPCore (x y z t) :precision binary64 (* x (- 1.0 (/ z t))))
double code(double x, double y, double z, double t) {
return x * (1.0 - (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 * (1.0d0 - (z / t))
end function
public static double code(double x, double y, double z, double t) {
return x * (1.0 - (z / t));
}
def code(x, y, z, t): return x * (1.0 - (z / t))
function code(x, y, z, t) return Float64(x * Float64(1.0 - Float64(z / t))) end
function tmp = code(x, y, z, t) tmp = x * (1.0 - (z / t)); end
code[x_, y_, z_, t_] := N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{z}{t}\right)
\end{array}
Initial program 89.8%
Taylor expanded in x around inf 66.6%
mul-1-neg66.6%
unsub-neg66.6%
Simplified66.6%
Final simplification66.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 89.8%
Taylor expanded in z around 0 37.8%
Final simplification37.8%
(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 2024027
(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)))