
(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%
*-commutative97.7%
clear-num97.6%
un-div-inv97.7%
Applied egg-rr97.7%
Final simplification97.7%
(FPCore (x y z t) :precision binary64 (if (or (<= t -3.3e+131) (not (<= t 0.116))) (* t (- 1.0 (/ x y))) (+ t (* z (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.3e+131) || !(t <= 0.116)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + (z * (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 ((t <= (-3.3d+131)) .or. (.not. (t <= 0.116d0))) then
tmp = t * (1.0d0 - (x / y))
else
tmp = t + (z * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -3.3e+131) || !(t <= 0.116)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + (z * (x / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -3.3e+131) or not (t <= 0.116): tmp = t * (1.0 - (x / y)) else: tmp = t + (z * (x / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -3.3e+131) || !(t <= 0.116)) tmp = Float64(t * Float64(1.0 - Float64(x / y))); else tmp = Float64(t + Float64(z * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -3.3e+131) || ~((t <= 0.116))) tmp = t * (1.0 - (x / y)); else tmp = t + (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -3.3e+131], N[Not[LessEqual[t, 0.116]], $MachinePrecision]], N[(t * N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3.3 \cdot 10^{+131} \lor \neg \left(t \leq 0.116\right):\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;t + z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if t < -3.2999999999999998e131 or 0.116000000000000006 < t Initial program 99.9%
Taylor expanded in z around 0 86.2%
mul-1-neg86.2%
unsub-neg86.2%
*-rgt-identity86.2%
associate-*r/95.0%
distribute-lft-out--95.0%
Simplified95.0%
if -3.2999999999999998e131 < t < 0.116000000000000006Initial program 96.4%
Taylor expanded in z around inf 84.4%
associate-*l/85.6%
*-commutative85.6%
Simplified85.6%
Final simplification89.2%
(FPCore (x y z t) :precision binary64 (if (or (<= t -4.3e+130) (not (<= t 0.235))) (- t (* t (/ x y))) (+ t (* z (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.3e+130) || !(t <= 0.235)) {
tmp = t - (t * (x / y));
} else {
tmp = t + (z * (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 ((t <= (-4.3d+130)) .or. (.not. (t <= 0.235d0))) then
tmp = t - (t * (x / y))
else
tmp = t + (z * (x / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4.3e+130) || !(t <= 0.235)) {
tmp = t - (t * (x / y));
} else {
tmp = t + (z * (x / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -4.3e+130) or not (t <= 0.235): tmp = t - (t * (x / y)) else: tmp = t + (z * (x / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -4.3e+130) || !(t <= 0.235)) tmp = Float64(t - Float64(t * Float64(x / y))); else tmp = Float64(t + Float64(z * Float64(x / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -4.3e+130) || ~((t <= 0.235))) tmp = t - (t * (x / y)); else tmp = t + (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -4.3e+130], N[Not[LessEqual[t, 0.235]], $MachinePrecision]], N[(t - N[(t * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.3 \cdot 10^{+130} \lor \neg \left(t \leq 0.235\right):\\
\;\;\;\;t - t \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t + z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if t < -4.29999999999999984e130 or 0.23499999999999999 < t Initial program 99.9%
*-commutative99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Taylor expanded in z around 0 86.2%
mul-1-neg86.2%
associate-*r/95.0%
sub-neg95.0%
Simplified95.0%
if -4.29999999999999984e130 < t < 0.23499999999999999Initial program 96.4%
Taylor expanded in z around inf 84.4%
associate-*l/85.6%
*-commutative85.6%
Simplified85.6%
Final simplification89.2%
(FPCore (x y z t) :precision binary64 (if (or (<= x -5.2e+102) (not (<= x 7.4))) (* x (/ (- t) y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -5.2e+102) || !(x <= 7.4)) {
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 <= (-5.2d+102)) .or. (.not. (x <= 7.4d0))) 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 <= -5.2e+102) || !(x <= 7.4)) {
tmp = x * (-t / y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -5.2e+102) or not (x <= 7.4): tmp = x * (-t / y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -5.2e+102) || !(x <= 7.4)) tmp = Float64(x * Float64(Float64(-t) / y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -5.2e+102) || ~((x <= 7.4))) tmp = x * (-t / y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -5.2e+102], N[Not[LessEqual[x, 7.4]], $MachinePrecision]], N[(x * N[((-t) / y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+102} \lor \neg \left(x \leq 7.4\right):\\
\;\;\;\;x \cdot \frac{-t}{y}\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if x < -5.20000000000000013e102 or 7.4000000000000004 < x Initial program 97.3%
*-commutative97.3%
clear-num97.2%
un-div-inv97.6%
Applied egg-rr97.6%
Taylor expanded in z around 0 45.3%
mul-1-neg45.3%
associate-*r/55.2%
sub-neg55.2%
Simplified55.2%
*-commutative55.2%
add-sqr-sqrt30.2%
sqrt-unprod28.9%
sqr-neg28.9%
sqrt-unprod5.8%
add-sqr-sqrt15.7%
associate-/r/14.1%
add-sqr-sqrt5.9%
sqrt-unprod27.9%
sqr-neg27.9%
sqrt-unprod29.2%
add-sqr-sqrt51.6%
Applied egg-rr51.6%
Taylor expanded in x around inf 42.1%
associate-*r/42.1%
*-commutative42.1%
neg-mul-142.1%
distribute-rgt-neg-out42.1%
associate-*r/44.6%
Simplified44.6%
if -5.20000000000000013e102 < x < 7.4000000000000004Initial program 98.0%
Taylor expanded in x around 0 60.3%
Final simplification53.6%
(FPCore (x y z t) :precision binary64 (if (<= x -3.3e+103) (/ x (/ (- y) t)) (if (<= x 12.2) t (* x (/ (- t) y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.3e+103) {
tmp = x / (-y / t);
} else if (x <= 12.2) {
tmp = t;
} else {
tmp = x * (-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 <= (-3.3d+103)) then
tmp = x / (-y / t)
else if (x <= 12.2d0) then
tmp = t
else
tmp = x * (-t / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.3e+103) {
tmp = x / (-y / t);
} else if (x <= 12.2) {
tmp = t;
} else {
tmp = x * (-t / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3.3e+103: tmp = x / (-y / t) elif x <= 12.2: tmp = t else: tmp = x * (-t / y) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3.3e+103) tmp = Float64(x / Float64(Float64(-y) / t)); elseif (x <= 12.2) tmp = t; else tmp = Float64(x * Float64(Float64(-t) / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -3.3e+103) tmp = x / (-y / t); elseif (x <= 12.2) tmp = t; else tmp = x * (-t / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.3e+103], N[(x / N[((-y) / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 12.2], t, N[(x * N[((-t) / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+103}:\\
\;\;\;\;\frac{x}{\frac{-y}{t}}\\
\mathbf{elif}\;x \leq 12.2:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{-t}{y}\\
\end{array}
\end{array}
if x < -3.30000000000000009e103Initial program 98.0%
*-commutative98.0%
clear-num97.9%
un-div-inv97.9%
Applied egg-rr97.9%
Taylor expanded in z around 0 50.6%
mul-1-neg50.6%
associate-*r/56.7%
sub-neg56.7%
Simplified56.7%
*-commutative56.7%
add-sqr-sqrt0.0%
sqrt-unprod11.0%
sqr-neg11.0%
sqrt-unprod13.2%
add-sqr-sqrt13.2%
associate-/r/13.4%
add-sqr-sqrt13.4%
sqrt-unprod10.9%
sqr-neg10.9%
sqrt-unprod0.0%
add-sqr-sqrt50.8%
Applied egg-rr50.8%
Taylor expanded in x around inf 47.5%
associate-*r/47.5%
*-commutative47.5%
neg-mul-147.5%
distribute-rgt-neg-out47.5%
associate-*r/48.6%
neg-mul-148.6%
associate-/l*48.6%
metadata-eval48.6%
associate-/r*48.6%
neg-mul-148.6%
associate-*r/48.7%
*-rgt-identity48.7%
distribute-neg-frac48.7%
Simplified48.7%
if -3.30000000000000009e103 < x < 12.199999999999999Initial program 98.0%
Taylor expanded in x around 0 60.3%
if 12.199999999999999 < x Initial program 96.8%
*-commutative96.8%
clear-num96.7%
un-div-inv97.4%
Applied egg-rr97.4%
Taylor expanded in z around 0 41.2%
mul-1-neg41.2%
associate-*r/53.9%
sub-neg53.9%
Simplified53.9%
*-commutative53.9%
add-sqr-sqrt53.9%
sqrt-unprod43.0%
sqr-neg43.0%
sqrt-unprod0.0%
add-sqr-sqrt17.7%
associate-/r/14.6%
add-sqr-sqrt0.0%
sqrt-unprod41.3%
sqr-neg41.3%
sqrt-unprod52.1%
add-sqr-sqrt52.2%
Applied egg-rr52.2%
Taylor expanded in x around inf 37.9%
associate-*r/37.9%
*-commutative37.9%
neg-mul-137.9%
distribute-rgt-neg-out37.9%
associate-*r/41.4%
Simplified41.4%
Final simplification53.6%
(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%
Taylor expanded in z around 0 61.9%
mul-1-neg61.9%
unsub-neg61.9%
*-rgt-identity61.9%
associate-*r/66.8%
distribute-lft-out--66.8%
Simplified66.8%
Final simplification66.8%
(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%
Taylor expanded in x around 0 38.5%
Final simplification38.5%
(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 2024021
(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))