
(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 8 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 (+ 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 97.7%
Taylor expanded in x around 0 91.5%
associate-/l*94.0%
*-commutative94.0%
associate-/r/97.9%
Simplified97.9%
Final simplification97.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.5e-16) (not (<= z 1.2e-70))) (+ t (* x (/ z y))) (* t (- 1.0 (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.5e-16) || !(z <= 1.2e-70)) {
tmp = t + (x * (z / y));
} else {
tmp = t * (1.0 - (x / 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 ((z <= (-2.5d-16)) .or. (.not. (z <= 1.2d-70))) then
tmp = t + (x * (z / y))
else
tmp = t * (1.0d0 - (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.5e-16) || !(z <= 1.2e-70)) {
tmp = t + (x * (z / y));
} else {
tmp = t * (1.0 - (x / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.5e-16) or not (z <= 1.2e-70): tmp = t + (x * (z / y)) else: tmp = t * (1.0 - (x / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.5e-16) || !(z <= 1.2e-70)) tmp = Float64(t + Float64(x * Float64(z / y))); else tmp = Float64(t * Float64(1.0 - Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.5e-16) || ~((z <= 1.2e-70))) tmp = t + (x * (z / y)); else tmp = t * (1.0 - (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.5e-16], N[Not[LessEqual[z, 1.2e-70]], $MachinePrecision]], N[(t + N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \cdot 10^{-16} \lor \neg \left(z \leq 1.2 \cdot 10^{-70}\right):\\
\;\;\;\;t + x \cdot \frac{z}{y}\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\end{array}
\end{array}
if z < -2.5000000000000002e-16 or 1.2000000000000001e-70 < z Initial program 99.9%
Taylor expanded in z around inf 80.0%
associate-/l*88.1%
Simplified88.1%
if -2.5000000000000002e-16 < z < 1.2000000000000001e-70Initial program 95.3%
associate-*l/95.9%
associate-/l*92.9%
fma-define92.9%
Simplified92.9%
Taylor expanded in z around 0 84.7%
mul-1-neg84.7%
*-rgt-identity84.7%
associate-/l*87.2%
distribute-rgt-neg-in87.2%
mul-1-neg87.2%
distribute-lft-in87.2%
mul-1-neg87.2%
unsub-neg87.2%
Simplified87.2%
Final simplification87.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.2e-16) (not (<= z 1.05e-73))) (+ t (* z (/ x y))) (* t (- 1.0 (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.2e-16) || !(z <= 1.05e-73)) {
tmp = t + (z * (x / y));
} else {
tmp = t * (1.0 - (x / 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 ((z <= (-3.2d-16)) .or. (.not. (z <= 1.05d-73))) then
tmp = t + (z * (x / y))
else
tmp = t * (1.0d0 - (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.2e-16) || !(z <= 1.05e-73)) {
tmp = t + (z * (x / y));
} else {
tmp = t * (1.0 - (x / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.2e-16) or not (z <= 1.05e-73): tmp = t + (z * (x / y)) else: tmp = t * (1.0 - (x / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.2e-16) || !(z <= 1.05e-73)) tmp = Float64(t + Float64(z * Float64(x / y))); else tmp = Float64(t * Float64(1.0 - Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.2e-16) || ~((z <= 1.05e-73))) tmp = t + (z * (x / y)); else tmp = t * (1.0 - (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.2e-16], N[Not[LessEqual[z, 1.05e-73]], $MachinePrecision]], N[(t + N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{-16} \lor \neg \left(z \leq 1.05 \cdot 10^{-73}\right):\\
\;\;\;\;t + z \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\end{array}
\end{array}
if z < -3.20000000000000023e-16 or 1.0499999999999999e-73 < z Initial program 99.9%
Taylor expanded in z around inf 80.0%
associate-/l*88.1%
Simplified88.1%
clear-num88.1%
un-div-inv88.2%
Applied egg-rr88.2%
associate-/r/91.6%
Applied egg-rr91.6%
if -3.20000000000000023e-16 < z < 1.0499999999999999e-73Initial program 95.3%
associate-*l/95.9%
associate-/l*92.9%
fma-define92.9%
Simplified92.9%
Taylor expanded in z around 0 84.7%
mul-1-neg84.7%
*-rgt-identity84.7%
associate-/l*87.2%
distribute-rgt-neg-in87.2%
mul-1-neg87.2%
distribute-lft-in87.2%
mul-1-neg87.2%
unsub-neg87.2%
Simplified87.2%
Final simplification89.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.65e-16) (not (<= z 1.9e-69))) (+ t (* z (/ x y))) (- t (/ t (/ y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.65e-16) || !(z <= 1.9e-69)) {
tmp = t + (z * (x / y));
} else {
tmp = t - (t / (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 ((z <= (-1.65d-16)) .or. (.not. (z <= 1.9d-69))) then
tmp = t + (z * (x / y))
else
tmp = t - (t / (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.65e-16) || !(z <= 1.9e-69)) {
tmp = t + (z * (x / y));
} else {
tmp = t - (t / (y / x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -1.65e-16) or not (z <= 1.9e-69): tmp = t + (z * (x / y)) else: tmp = t - (t / (y / x)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.65e-16) || !(z <= 1.9e-69)) tmp = Float64(t + Float64(z * Float64(x / y))); else tmp = Float64(t - Float64(t / Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -1.65e-16) || ~((z <= 1.9e-69))) tmp = t + (z * (x / y)); else tmp = t - (t / (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.65e-16], N[Not[LessEqual[z, 1.9e-69]], $MachinePrecision]], N[(t + N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t - N[(t / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{-16} \lor \neg \left(z \leq 1.9 \cdot 10^{-69}\right):\\
\;\;\;\;t + z \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t - \frac{t}{\frac{y}{x}}\\
\end{array}
\end{array}
if z < -1.64999999999999994e-16 or 1.8999999999999999e-69 < z Initial program 99.9%
Taylor expanded in z around inf 80.0%
associate-/l*88.1%
Simplified88.1%
clear-num88.1%
un-div-inv88.2%
Applied egg-rr88.2%
associate-/r/91.6%
Applied egg-rr91.6%
if -1.64999999999999994e-16 < z < 1.8999999999999999e-69Initial program 95.3%
Taylor expanded in z around 0 84.7%
associate-*r/84.7%
mul-1-neg84.7%
*-commutative84.7%
distribute-rgt-neg-out84.7%
associate-/l*83.3%
distribute-neg-frac83.3%
distribute-neg-frac283.3%
Simplified83.3%
Taylor expanded in x around 0 84.7%
neg-mul-184.7%
sub-neg84.7%
associate-/l*87.2%
Simplified87.2%
clear-num87.1%
div-inv87.2%
Applied egg-rr87.2%
Final simplification89.6%
(FPCore (x y z t) :precision binary64 (if (or (<= x -2.7e-68) (not (<= x 9.4e+70))) (* x (/ t (- y))) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.7e-68) || !(x <= 9.4e+70)) {
tmp = x * (t / -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 ((x <= (-2.7d-68)) .or. (.not. (x <= 9.4d+70))) then
tmp = x * (t / -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 ((x <= -2.7e-68) || !(x <= 9.4e+70)) {
tmp = x * (t / -y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -2.7e-68) or not (x <= 9.4e+70): tmp = x * (t / -y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -2.7e-68) || !(x <= 9.4e+70)) tmp = Float64(x * Float64(t / Float64(-y))); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -2.7e-68) || ~((x <= 9.4e+70))) tmp = x * (t / -y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -2.7e-68], N[Not[LessEqual[x, 9.4e+70]], $MachinePrecision]], N[(x * N[(t / (-y)), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-68} \lor \neg \left(x \leq 9.4 \cdot 10^{+70}\right):\\
\;\;\;\;x \cdot \frac{t}{-y}\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if x < -2.7000000000000002e-68 or 9.3999999999999996e70 < x Initial program 96.0%
Taylor expanded in z around 0 53.7%
associate-*r/53.7%
mul-1-neg53.7%
*-commutative53.7%
distribute-rgt-neg-out53.7%
associate-/l*57.7%
distribute-neg-frac57.7%
distribute-neg-frac257.7%
Simplified57.7%
Taylor expanded in x around 0 53.7%
neg-mul-153.7%
sub-neg53.7%
associate-/l*62.4%
Simplified62.4%
clear-num62.3%
div-inv62.4%
Applied egg-rr62.4%
Taylor expanded in y around 0 41.8%
associate-*l/43.4%
associate-*r*43.4%
*-commutative43.4%
neg-mul-143.4%
distribute-frac-neg243.4%
Simplified43.4%
if -2.7000000000000002e-68 < x < 9.3999999999999996e70Initial program 99.9%
associate-*l/99.1%
associate-/l*89.3%
fma-define89.3%
Simplified89.3%
Taylor expanded in x around 0 70.1%
Final simplification55.2%
(FPCore (x y z t) :precision binary64 (+ t (* (- z t) (/ x y))))
double code(double x, double y, double z, double t) {
return t + ((z - t) * (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 + ((z - t) * (x / y))
end function
public static double code(double x, double y, double z, double t) {
return t + ((z - t) * (x / y));
}
def code(x, y, z, t): return t + ((z - t) * (x / y))
function code(x, y, z, t) return Float64(t + Float64(Float64(z - t) * Float64(x / y))) end
function tmp = code(x, y, z, t) tmp = t + ((z - t) * (x / y)); end
code[x_, y_, z_, t_] := N[(t + N[(N[(z - t), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \left(z - t\right) \cdot \frac{x}{y}
\end{array}
Initial program 97.7%
Final simplification97.7%
(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 97.7%
associate-*l/91.5%
associate-/l*94.0%
fma-define94.0%
Simplified94.0%
Taylor expanded in z around 0 66.2%
mul-1-neg66.2%
*-rgt-identity66.2%
associate-/l*71.0%
distribute-rgt-neg-in71.0%
mul-1-neg71.0%
distribute-lft-in71.0%
mul-1-neg71.0%
unsub-neg71.0%
Simplified71.0%
Final simplification71.0%
(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 97.7%
associate-*l/91.5%
associate-/l*94.0%
fma-define94.0%
Simplified94.0%
Taylor expanded in x around 0 40.1%
Final simplification40.1%
(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 2024071
(FPCore (x y z t)
:name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
:precision binary64
:alt
(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))