
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
double code(double x, double y, double z, double t) {
return ((x / y) * (z - t)) + 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) * (z - t)) + t
end function
public static double code(double x, double y, double z, double t) {
return ((x / y) * (z - t)) + t;
}
def code(x, y, z, t): return ((x / y) * (z - t)) + t
function code(x, y, z, t) return Float64(Float64(Float64(x / y) * Float64(z - t)) + t) end
function tmp = code(x, y, z, t) tmp = ((x / y) * (z - t)) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} \cdot \left(z - t\right) + t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
double code(double x, double y, double z, double t) {
return ((x / y) * (z - t)) + 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) * (z - t)) + t
end function
public static double code(double x, double y, double z, double t) {
return ((x / y) * (z - t)) + t;
}
def code(x, y, z, t): return ((x / y) * (z - t)) + t
function code(x, y, z, t) return Float64(Float64(Float64(x / y) * Float64(z - t)) + t) end
function tmp = code(x, y, z, t) tmp = ((x / y) * (z - t)) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} \cdot \left(z - t\right) + t
\end{array}
(FPCore (x y z t) :precision binary64 (fma (/ x y) (- z t) t))
double code(double x, double y, double z, double t) {
return fma((x / y), (z - t), t);
}
function code(x, y, z, t) return fma(Float64(x / y), Float64(z - t), t) end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (if (or (<= t -3.5e+58) (not (<= t 6e+130))) (* t (- 1.0 (/ x y))) (+ t (* (/ x y) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.5e+58) || !(t <= 6e+130)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + ((x / y) * 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 ((t <= (-3.5d+58)) .or. (.not. (t <= 6d+130))) then
tmp = t * (1.0d0 - (x / y))
else
tmp = t + ((x / y) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.5e+58) || !(t <= 6e+130)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + ((x / y) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -3.5e+58) or not (t <= 6e+130): tmp = t * (1.0 - (x / y)) else: tmp = t + ((x / y) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -3.5e+58) || !(t <= 6e+130)) tmp = Float64(t * Float64(1.0 - Float64(x / y))); else tmp = Float64(t + Float64(Float64(x / y) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -3.5e+58) || ~((t <= 6e+130))) tmp = t * (1.0 - (x / y)); else tmp = t + ((x / y) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -3.5e+58], N[Not[LessEqual[t, 6e+130]], $MachinePrecision]], N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.5 \cdot 10^{+58} \lor \neg \left(t \leq 6 \cdot 10^{+130}\right):\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;t + \frac{x}{y} \cdot z\\
\end{array}
\end{array}
if t < -3.4999999999999997e58 or 5.9999999999999999e130 < t Initial program 99.9%
Taylor expanded in z around 0 83.6%
mul-1-neg83.6%
unsub-neg83.6%
*-rgt-identity83.6%
associate-*r/93.3%
distribute-lft-out--93.3%
Simplified93.3%
if -3.4999999999999997e58 < t < 5.9999999999999999e130Initial program 99.7%
Taylor expanded in z around inf 79.5%
associate-*l/86.2%
*-commutative86.2%
Simplified86.2%
Final simplification88.6%
(FPCore (x y z t) :precision binary64 (if (or (<= t -4.5e+58) (not (<= t 1.25e+129))) (* t (- 1.0 (/ x y))) (+ t (/ z (/ y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.5e+58) || !(t <= 1.25e+129)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + (z / (y / 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 <= (-4.5d+58)) .or. (.not. (t <= 1.25d+129))) then
tmp = t * (1.0d0 - (x / y))
else
tmp = t + (z / (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.5e+58) || !(t <= 1.25e+129)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + (z / (y / x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -4.5e+58) or not (t <= 1.25e+129): tmp = t * (1.0 - (x / y)) else: tmp = t + (z / (y / x)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -4.5e+58) || !(t <= 1.25e+129)) tmp = Float64(t * Float64(1.0 - Float64(x / y))); else tmp = Float64(t + Float64(z / Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -4.5e+58) || ~((t <= 1.25e+129))) tmp = t * (1.0 - (x / y)); else tmp = t + (z / (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -4.5e+58], N[Not[LessEqual[t, 1.25e+129]], $MachinePrecision]], N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.5 \cdot 10^{+58} \lor \neg \left(t \leq 1.25 \cdot 10^{+129}\right):\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;t + \frac{z}{\frac{y}{x}}\\
\end{array}
\end{array}
if t < -4.4999999999999998e58 or 1.2500000000000001e129 < t Initial program 99.9%
Taylor expanded in z around 0 83.6%
mul-1-neg83.6%
unsub-neg83.6%
*-rgt-identity83.6%
associate-*r/93.3%
distribute-lft-out--93.3%
Simplified93.3%
if -4.4999999999999998e58 < t < 1.2500000000000001e129Initial program 99.7%
*-commutative99.7%
clear-num99.7%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in z around inf 79.5%
*-commutative79.5%
associate-/l*86.2%
Simplified86.2%
Final simplification88.6%
(FPCore (x y z t) :precision binary64 (if (<= t -2.9e+58) (* t (- 1.0 (/ x y))) (if (<= t 1.35e+129) (+ t (/ z (/ y x))) (- t (* (/ x y) t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.9e+58) {
tmp = t * (1.0 - (x / y));
} else if (t <= 1.35e+129) {
tmp = t + (z / (y / x));
} else {
tmp = t - ((x / 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 (t <= (-2.9d+58)) then
tmp = t * (1.0d0 - (x / y))
else if (t <= 1.35d+129) then
tmp = t + (z / (y / x))
else
tmp = t - ((x / y) * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.9e+58) {
tmp = t * (1.0 - (x / y));
} else if (t <= 1.35e+129) {
tmp = t + (z / (y / x));
} else {
tmp = t - ((x / y) * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.9e+58: tmp = t * (1.0 - (x / y)) elif t <= 1.35e+129: tmp = t + (z / (y / x)) else: tmp = t - ((x / y) * t) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.9e+58) tmp = Float64(t * Float64(1.0 - Float64(x / y))); elseif (t <= 1.35e+129) tmp = Float64(t + Float64(z / Float64(y / x))); else tmp = Float64(t - Float64(Float64(x / y) * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.9e+58) tmp = t * (1.0 - (x / y)); elseif (t <= 1.35e+129) tmp = t + (z / (y / x)); else tmp = t - ((x / y) * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.9e+58], N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.35e+129], N[(t + N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t - N[(N[(x / y), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.9 \cdot 10^{+58}:\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\mathbf{elif}\;t \leq 1.35 \cdot 10^{+129}:\\
\;\;\;\;t + \frac{z}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;t - \frac{x}{y} \cdot t\\
\end{array}
\end{array}
if t < -2.90000000000000002e58Initial program 99.9%
Taylor expanded in z around 0 81.1%
mul-1-neg81.1%
unsub-neg81.1%
*-rgt-identity81.1%
associate-*r/89.5%
distribute-lft-out--89.6%
Simplified89.6%
if -2.90000000000000002e58 < t < 1.35e129Initial program 99.7%
*-commutative99.7%
clear-num99.7%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in z around inf 79.5%
*-commutative79.5%
associate-/l*86.2%
Simplified86.2%
if 1.35e129 < t Initial program 100.0%
*-commutative100.0%
clear-num100.0%
un-div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in z around 0 87.9%
mul-1-neg87.9%
associate-*r/100.0%
distribute-lft-neg-in100.0%
cancel-sign-sub-inv100.0%
Simplified100.0%
Final simplification88.7%
(FPCore (x y z t) :precision binary64 (if (<= y -6e-24) t (if (<= y 5.2e+19) (* t (/ x (- y))) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6e-24) {
tmp = t;
} else if (y <= 5.2e+19) {
tmp = t * (x / -y);
} else {
tmp = 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 <= (-6d-24)) then
tmp = t
else if (y <= 5.2d+19) then
tmp = t * (x / -y)
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6e-24) {
tmp = t;
} else if (y <= 5.2e+19) {
tmp = t * (x / -y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -6e-24: tmp = t elif y <= 5.2e+19: tmp = t * (x / -y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -6e-24) tmp = t; elseif (y <= 5.2e+19) tmp = Float64(t * Float64(x / Float64(-y))); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -6e-24) tmp = t; elseif (y <= 5.2e+19) tmp = t * (x / -y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -6e-24], t, If[LessEqual[y, 5.2e+19], N[(t * N[(x / (-y)), $MachinePrecision]), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-24}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+19}:\\
\;\;\;\;t \cdot \frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -5.99999999999999991e-24 or 5.2e19 < y Initial program 99.8%
Taylor expanded in x around 0 59.4%
if -5.99999999999999991e-24 < y < 5.2e19Initial program 99.8%
*-commutative99.8%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 62.5%
mul-1-neg62.5%
associate-*r/63.9%
distribute-lft-neg-in63.9%
cancel-sign-sub-inv63.9%
Simplified63.9%
Taylor expanded in x around inf 50.2%
mul-1-neg50.2%
associate-*r/51.7%
distribute-rgt-neg-out51.7%
distribute-neg-frac51.7%
distribute-neg-frac51.7%
*-rgt-identity51.7%
*-commutative51.7%
metadata-eval51.7%
times-frac51.7%
neg-mul-151.7%
neg-mul-151.7%
distribute-frac-neg51.7%
remove-double-neg51.7%
Simplified51.7%
Final simplification55.6%
(FPCore (x y z t) :precision binary64 (+ t (* (/ x y) (- z t))))
double code(double x, double y, double z, double t) {
return t + ((x / y) * (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 = t + ((x / y) * (z - t))
end function
public static double code(double x, double y, double z, double t) {
return t + ((x / y) * (z - t));
}
def code(x, y, z, t): return t + ((x / y) * (z - t))
function code(x, y, z, t) return Float64(t + Float64(Float64(x / y) * Float64(z - t))) end
function tmp = code(x, y, z, t) tmp = t + ((x / y) * (z - t)); end
code[x_, y_, z_, t_] := N[(t + N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \frac{x}{y} \cdot \left(z - t\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (+ t (/ (- z t) (/ y x))))
double code(double x, double y, double z, double t) {
return t + ((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 = t + ((z - t) / (y / x))
end function
public static double code(double x, double y, double z, double t) {
return t + ((z - t) / (y / x));
}
def code(x, y, z, t): return t + ((z - t) / (y / x))
function code(x, y, z, t) return Float64(t + Float64(Float64(z - t) / Float64(y / x))) end
function tmp = code(x, y, z, t) tmp = t + ((z - t) / (y / x)); end
code[x_, y_, z_, t_] := N[(t + N[(N[(z - t), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \frac{z - t}{\frac{y}{x}}
\end{array}
Initial program 99.8%
*-commutative99.8%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (* t (- 1.0 (/ x y))))
double code(double x, double y, double z, double t) {
return t * (1.0 - (x / 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 * (1.0d0 - (x / y))
end function
public static double code(double x, double y, double z, double t) {
return t * (1.0 - (x / y));
}
def code(x, y, z, t): return t * (1.0 - (x / y))
function code(x, y, z, t) return Float64(t * Float64(1.0 - Float64(x / y))) end
function tmp = code(x, y, z, t) tmp = t * (1.0 - (x / y)); end
code[x_, y_, z_, t_] := N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t \cdot \left(1 - \frac{x}{y}\right)
\end{array}
Initial program 99.8%
Taylor expanded in z around 0 61.9%
mul-1-neg61.9%
unsub-neg61.9%
*-rgt-identity61.9%
associate-*r/66.4%
distribute-lft-out--66.4%
Simplified66.4%
Final simplification66.4%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return 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 = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 37.2%
Final simplification37.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ (* (/ x y) (- z t)) t)))
(if (< z 2.759456554562692e-282)
t_1
(if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = ((x / y) * (z - t)) + t;
double tmp;
if (z < 2.759456554562692e-282) {
tmp = t_1;
} else if (z < 2.326994450874436e-110) {
tmp = (x * ((z - t) / y)) + t;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = ((x / y) * (z - t)) + t
if (z < 2.759456554562692d-282) then
tmp = t_1
else if (z < 2.326994450874436d-110) then
tmp = (x * ((z - t) / y)) + t
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = ((x / y) * (z - t)) + t;
double tmp;
if (z < 2.759456554562692e-282) {
tmp = t_1;
} else if (z < 2.326994450874436e-110) {
tmp = (x * ((z - t) / y)) + t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = ((x / y) * (z - t)) + t tmp = 0 if z < 2.759456554562692e-282: tmp = t_1 elif z < 2.326994450874436e-110: tmp = (x * ((z - t) / y)) + t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x / y) * Float64(z - t)) + t) tmp = 0.0 if (z < 2.759456554562692e-282) tmp = t_1; elseif (z < 2.326994450874436e-110) tmp = Float64(Float64(x * Float64(Float64(z - t) / y)) + t); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = ((x / y) * (z - t)) + t; tmp = 0.0; if (z < 2.759456554562692e-282) tmp = t_1; elseif (z < 2.326994450874436e-110) tmp = (x * ((z - t) / y)) + t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]}, If[Less[z, 2.759456554562692e-282], t$95$1, If[Less[z, 2.326994450874436e-110], N[(N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x}{y} \cdot \left(z - t\right) + t\\
\mathbf{if}\;z < 2.759456554562692 \cdot 10^{-282}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z < 2.326994450874436 \cdot 10^{-110}:\\
\;\;\;\;x \cdot \frac{z - t}{y} + t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
herbie shell --seed 2024020
(FPCore (x y z t)
:name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
:precision binary64
:herbie-target
(if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))
(+ (* (/ x y) (- z t)) t))