
(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 7 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 (- y x) (/ z t) x))
double code(double x, double y, double z, double t) {
return fma((y - x), (z / t), x);
}
function code(x, y, z, t) return fma(Float64(y - x), Float64(z / t), x) end
code[x_, y_, z_, t_] := N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)
\end{array}
Initial program 93.8%
+-commutative93.8%
associate-/l*98.5%
fma-define98.5%
Simplified98.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.7e-13) (not (<= y 2.7e-132))) (+ x (* y (/ z t))) (* x (- 1.0 (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.7e-13) || !(y <= 2.7e-132)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (z / 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 ((y <= (-3.7d-13)) .or. (.not. (y <= 2.7d-132))) then
tmp = x + (y * (z / t))
else
tmp = x * (1.0d0 - (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.7e-13) || !(y <= 2.7e-132)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.7e-13) or not (y <= 2.7e-132): tmp = x + (y * (z / t)) else: tmp = x * (1.0 - (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.7e-13) || !(y <= 2.7e-132)) tmp = Float64(x + Float64(y * Float64(z / t))); else tmp = Float64(x * Float64(1.0 - Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -3.7e-13) || ~((y <= 2.7e-132))) tmp = x + (y * (z / t)); else tmp = x * (1.0 - (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.7e-13], N[Not[LessEqual[y, 2.7e-132]], $MachinePrecision]], N[(x + N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-13} \lor \neg \left(y \leq 2.7 \cdot 10^{-132}\right):\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\end{array}
\end{array}
if y < -3.69999999999999989e-13 or 2.6999999999999999e-132 < y Initial program 93.6%
associate-/l*99.5%
Simplified99.5%
Taylor expanded in y around inf 89.0%
associate-*r/92.3%
Simplified92.3%
if -3.69999999999999989e-13 < y < 2.6999999999999999e-132Initial program 94.0%
associate-/l*97.1%
Simplified97.1%
Taylor expanded in x around inf 90.6%
mul-1-neg90.6%
unsub-neg90.6%
Simplified90.6%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (if (<= t -2.2e-17) x (if (<= t 1.45e-22) (* x (/ z (- t))) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.2e-17) {
tmp = x;
} else if (t <= 1.45e-22) {
tmp = x * (z / -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 (t <= (-2.2d-17)) then
tmp = x
else if (t <= 1.45d-22) then
tmp = x * (z / -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 (t <= -2.2e-17) {
tmp = x;
} else if (t <= 1.45e-22) {
tmp = x * (z / -t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.2e-17: tmp = x elif t <= 1.45e-22: tmp = x * (z / -t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.2e-17) tmp = x; elseif (t <= 1.45e-22) tmp = Float64(x * Float64(z / Float64(-t))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.2e-17) tmp = x; elseif (t <= 1.45e-22) tmp = x * (z / -t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.2e-17], x, If[LessEqual[t, 1.45e-22], N[(x * N[(z / (-t)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.2 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 1.45 \cdot 10^{-22}:\\
\;\;\;\;x \cdot \frac{z}{-t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -2.2e-17 or 1.4500000000000001e-22 < t Initial program 89.8%
associate-/l*99.4%
Simplified99.4%
Taylor expanded in z around 0 63.5%
if -2.2e-17 < t < 1.4500000000000001e-22Initial program 97.9%
associate-/l*97.6%
Simplified97.6%
Taylor expanded in x around inf 66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
Taylor expanded in z around inf 53.2%
neg-mul-153.2%
distribute-neg-frac253.2%
Simplified53.2%
(FPCore (x y z t) :precision binary64 (if (<= t -5.4e-20) x (if (<= t 9.6e-20) (* z (- (/ x t))) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -5.4e-20) {
tmp = x;
} else if (t <= 9.6e-20) {
tmp = z * -(x / 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 (t <= (-5.4d-20)) then
tmp = x
else if (t <= 9.6d-20) then
tmp = z * -(x / 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 (t <= -5.4e-20) {
tmp = x;
} else if (t <= 9.6e-20) {
tmp = z * -(x / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -5.4e-20: tmp = x elif t <= 9.6e-20: tmp = z * -(x / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -5.4e-20) tmp = x; elseif (t <= 9.6e-20) tmp = Float64(z * Float64(-Float64(x / t))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -5.4e-20) tmp = x; elseif (t <= 9.6e-20) tmp = z * -(x / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -5.4e-20], x, If[LessEqual[t, 9.6e-20], N[(z * (-N[(x / t), $MachinePrecision])), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.4 \cdot 10^{-20}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 9.6 \cdot 10^{-20}:\\
\;\;\;\;z \cdot \left(-\frac{x}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -5.3999999999999999e-20 or 9.59999999999999971e-20 < t Initial program 89.8%
associate-/l*99.4%
Simplified99.4%
Taylor expanded in z around 0 63.5%
if -5.3999999999999999e-20 < t < 9.59999999999999971e-20Initial program 97.9%
associate-/l*97.6%
Simplified97.6%
Taylor expanded in x around inf 66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
Taylor expanded in z around inf 53.2%
neg-mul-153.2%
distribute-neg-frac253.2%
Simplified53.2%
associate-*r/48.9%
*-commutative48.9%
distribute-frac-neg248.9%
associate-/l*47.0%
Applied egg-rr47.0%
Final simplification55.5%
(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(y - x) * Float64(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[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot \frac{z}{t}
\end{array}
Initial program 93.8%
associate-/l*98.5%
Simplified98.5%
(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 93.8%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in x around inf 70.6%
mul-1-neg70.6%
unsub-neg70.6%
Simplified70.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 93.8%
associate-/l*98.5%
Simplified98.5%
Taylor expanded in z around 0 39.1%
(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 2024146
(FPCore (x y z t)
:name "Numeric.Histogram:binBounds from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (if (< x -1805102239106601/200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- x (* (/ z t) (- x y))) (if (< x 855006432740143/2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z))))))
(+ x (/ (* (- y x) z) t)))