
(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 (- 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 94.7%
+-commutative94.7%
associate-/l*97.8%
fma-define97.8%
Simplified97.8%
Final simplification97.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.6e+68) (not (<= y 6.5e-83))) (+ x (* y (/ z t))) (* x (- 1.0 (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.6e+68) || !(y <= 6.5e-83)) {
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 <= (-1.6d+68)) .or. (.not. (y <= 6.5d-83))) 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 <= -1.6e+68) || !(y <= 6.5e-83)) {
tmp = x + (y * (z / t));
} else {
tmp = x * (1.0 - (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.6e+68) or not (y <= 6.5e-83): 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 <= -1.6e+68) || !(y <= 6.5e-83)) 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 <= -1.6e+68) || ~((y <= 6.5e-83))) 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, -1.6e+68], N[Not[LessEqual[y, 6.5e-83]], $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 -1.6 \cdot 10^{+68} \lor \neg \left(y \leq 6.5 \cdot 10^{-83}\right):\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\end{array}
\end{array}
if y < -1.59999999999999997e68 or 6.5e-83 < y Initial program 92.4%
associate-/l*97.9%
Simplified97.9%
Taylor expanded in y around inf 87.2%
associate-*r/92.0%
Simplified92.0%
if -1.59999999999999997e68 < y < 6.5e-83Initial program 97.0%
associate-/l*97.7%
Simplified97.7%
Taylor expanded in x around inf 89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
Final simplification90.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.8e-56) (not (<= z 1850000.0))) (* z (/ x (- t))) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.8e-56) || !(z <= 1850000.0)) {
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 ((z <= (-6.8d-56)) .or. (.not. (z <= 1850000.0d0))) 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 ((z <= -6.8e-56) || !(z <= 1850000.0)) {
tmp = z * (x / -t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.8e-56) or not (z <= 1850000.0): tmp = z * (x / -t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.8e-56) || !(z <= 1850000.0)) tmp = Float64(z * Float64(x / Float64(-t))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -6.8e-56) || ~((z <= 1850000.0))) tmp = z * (x / -t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.8e-56], N[Not[LessEqual[z, 1850000.0]], $MachinePrecision]], N[(z * N[(x / (-t)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{-56} \lor \neg \left(z \leq 1850000\right):\\
\;\;\;\;z \cdot \frac{x}{-t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.79999999999999964e-56 or 1.85e6 < z Initial program 90.7%
associate-/l*97.7%
Simplified97.7%
Taylor expanded in x around inf 63.8%
mul-1-neg63.8%
unsub-neg63.8%
Simplified63.8%
Taylor expanded in t around 0 51.9%
+-commutative51.9%
mul-1-neg51.9%
unsub-neg51.9%
*-commutative51.9%
distribute-lft-out--53.5%
Simplified53.5%
Taylor expanded in t around 0 46.9%
mul-1-neg46.9%
distribute-lft-neg-out46.9%
*-commutative46.9%
Simplified46.9%
Taylor expanded in z around 0 46.9%
mul-1-neg46.9%
associate-*l/49.0%
*-commutative49.0%
distribute-rgt-neg-in49.0%
distribute-neg-frac49.0%
Simplified49.0%
if -6.79999999999999964e-56 < z < 1.85e6Initial program 99.1%
associate-/l*97.9%
Simplified97.9%
Taylor expanded in z around 0 64.1%
Final simplification56.3%
(FPCore (x y z t) :precision binary64 (if (<= z -9e-56) (/ (* x (- z)) t) (if (<= z 16.5) x (* z (/ x (- t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9e-56) {
tmp = (x * -z) / t;
} else if (z <= 16.5) {
tmp = x;
} else {
tmp = z * (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 <= (-9d-56)) then
tmp = (x * -z) / t
else if (z <= 16.5d0) then
tmp = x
else
tmp = z * (x / -t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9e-56) {
tmp = (x * -z) / t;
} else if (z <= 16.5) {
tmp = x;
} else {
tmp = z * (x / -t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -9e-56: tmp = (x * -z) / t elif z <= 16.5: tmp = x else: tmp = z * (x / -t) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -9e-56) tmp = Float64(Float64(x * Float64(-z)) / t); elseif (z <= 16.5) tmp = x; else tmp = Float64(z * Float64(x / Float64(-t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -9e-56) tmp = (x * -z) / t; elseif (z <= 16.5) tmp = x; else tmp = z * (x / -t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -9e-56], N[(N[(x * (-z)), $MachinePrecision] / t), $MachinePrecision], If[LessEqual[z, 16.5], x, N[(z * N[(x / (-t)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-56}:\\
\;\;\;\;\frac{x \cdot \left(-z\right)}{t}\\
\mathbf{elif}\;z \leq 16.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{x}{-t}\\
\end{array}
\end{array}
if z < -9.0000000000000001e-56Initial program 94.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 63.0%
mul-1-neg63.0%
unsub-neg63.0%
Simplified63.0%
Taylor expanded in t around 0 49.7%
+-commutative49.7%
mul-1-neg49.7%
unsub-neg49.7%
*-commutative49.7%
distribute-lft-out--52.6%
Simplified52.6%
Taylor expanded in t around 0 48.5%
mul-1-neg48.5%
distribute-lft-neg-out48.5%
*-commutative48.5%
Simplified48.5%
if -9.0000000000000001e-56 < z < 16.5Initial program 99.1%
associate-/l*97.9%
Simplified97.9%
Taylor expanded in z around 0 64.1%
if 16.5 < z Initial program 86.2%
associate-/l*95.3%
Simplified95.3%
Taylor expanded in x around inf 64.7%
mul-1-neg64.7%
unsub-neg64.7%
Simplified64.7%
Taylor expanded in t around 0 54.3%
+-commutative54.3%
mul-1-neg54.3%
unsub-neg54.3%
*-commutative54.3%
distribute-lft-out--54.5%
Simplified54.5%
Taylor expanded in t around 0 45.1%
mul-1-neg45.1%
distribute-lft-neg-out45.1%
*-commutative45.1%
Simplified45.1%
Taylor expanded in z around 0 45.1%
mul-1-neg45.1%
associate-*l/49.6%
*-commutative49.6%
distribute-rgt-neg-in49.6%
distribute-neg-frac49.6%
Simplified49.6%
Final simplification56.3%
(FPCore (x y z t) :precision binary64 (if (<= x 1e+64) x (* t (/ x t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 1e+64) {
tmp = x;
} else {
tmp = t * (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 (x <= 1d+64) then
tmp = x
else
tmp = t * (x / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 1e+64) {
tmp = x;
} else {
tmp = t * (x / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 1e+64: tmp = x else: tmp = t * (x / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 1e+64) tmp = x; else tmp = Float64(t * Float64(x / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 1e+64) tmp = x; else tmp = t * (x / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 1e+64], x, N[(t * N[(x / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+64}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t \cdot \frac{x}{t}\\
\end{array}
\end{array}
if x < 1.00000000000000002e64Initial program 94.9%
associate-/l*97.4%
Simplified97.4%
Taylor expanded in z around 0 37.5%
if 1.00000000000000002e64 < x Initial program 93.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 84.6%
mul-1-neg84.6%
unsub-neg84.6%
Simplified84.6%
Taylor expanded in t around 0 63.7%
+-commutative63.7%
mul-1-neg63.7%
unsub-neg63.7%
*-commutative63.7%
distribute-lft-out--66.1%
Simplified66.1%
Taylor expanded in t around inf 27.3%
*-commutative27.3%
Simplified27.3%
*-commutative27.3%
associate-/l*50.4%
Applied egg-rr50.4%
Final simplification39.7%
(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 94.7%
associate-/l*97.8%
Simplified97.8%
Final simplification97.8%
(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 94.7%
associate-/l*97.8%
Simplified97.8%
Taylor expanded in x around inf 68.7%
mul-1-neg68.7%
unsub-neg68.7%
Simplified68.7%
Final simplification68.7%
(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 94.7%
associate-/l*97.8%
Simplified97.8%
Taylor expanded in z around 0 37.5%
Final simplification37.5%
(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 2024059
(FPCore (x y z t)
:name "Numeric.Histogram:binBounds from Chart-1.5.3"
:precision binary64
:alt
(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)))