
(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 98.7%
*-commutative98.7%
clear-num98.7%
un-div-inv98.8%
Applied egg-rr98.8%
Final simplification98.8%
(FPCore (x y z t) :precision binary64 (if (or (<= (/ x y) -10000000000.0) (not (<= (/ x y) 5e-5))) (* (- x) (/ t y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if (((x / y) <= -10000000000.0) || !((x / y) <= 5e-5)) {
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 / y) <= (-10000000000.0d0)) .or. (.not. ((x / y) <= 5d-5))) 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 / y) <= -10000000000.0) || !((x / y) <= 5e-5)) {
tmp = -x * (t / y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((x / y) <= -10000000000.0) or not ((x / y) <= 5e-5): tmp = -x * (t / y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(x / y) <= -10000000000.0) || !(Float64(x / y) <= 5e-5)) tmp = Float64(Float64(-x) * Float64(t / y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((x / y) <= -10000000000.0) || ~(((x / y) <= 5e-5))) tmp = -x * (t / y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x / y), $MachinePrecision], -10000000000.0], N[Not[LessEqual[N[(x / y), $MachinePrecision], 5e-5]], $MachinePrecision]], N[((-x) * N[(t / y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{y} \leq -10000000000 \lor \neg \left(\frac{x}{y} \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;\left(-x\right) \cdot \frac{t}{y}\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if (/.f64 x y) < -1e10 or 5.00000000000000024e-5 < (/.f64 x y) Initial program 99.1%
fma-def99.1%
Simplified99.1%
Taylor expanded in z around 0 48.9%
mul-1-neg48.9%
unsub-neg48.9%
*-rgt-identity48.9%
associate-*r/54.0%
distribute-lft-out--54.0%
Simplified54.0%
Taylor expanded in x around inf 53.9%
mul-1-neg53.9%
distribute-frac-neg53.9%
Simplified53.9%
associate-*r/48.9%
distribute-rgt-neg-in48.9%
distribute-frac-neg48.9%
add-sqr-sqrt25.0%
sqrt-unprod24.0%
sqr-neg24.0%
sqrt-unprod4.6%
add-sqr-sqrt5.4%
associate-/l*5.5%
associate-/r/4.8%
add-sqr-sqrt3.9%
sqrt-unprod23.5%
sqr-neg23.5%
sqrt-unprod24.9%
add-sqr-sqrt47.4%
Applied egg-rr47.4%
if -1e10 < (/.f64 x y) < 5.00000000000000024e-5Initial program 98.4%
fma-def98.4%
Simplified98.4%
Taylor expanded in x around 0 80.4%
Final simplification64.0%
(FPCore (x y z t) :precision binary64 (if (or (<= (/ x y) -10000000000.0) (not (<= (/ x y) 5e-5))) (* t (/ (- x) y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if (((x / y) <= -10000000000.0) || !((x / y) <= 5e-5)) {
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 (((x / y) <= (-10000000000.0d0)) .or. (.not. ((x / y) <= 5d-5))) 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 (((x / y) <= -10000000000.0) || !((x / y) <= 5e-5)) {
tmp = t * (-x / y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((x / y) <= -10000000000.0) or not ((x / y) <= 5e-5): tmp = t * (-x / y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(x / y) <= -10000000000.0) || !(Float64(x / y) <= 5e-5)) tmp = Float64(t * Float64(Float64(-x) / y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((x / y) <= -10000000000.0) || ~(((x / y) <= 5e-5))) tmp = t * (-x / y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x / y), $MachinePrecision], -10000000000.0], N[Not[LessEqual[N[(x / y), $MachinePrecision], 5e-5]], $MachinePrecision]], N[(t * N[((-x) / y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{y} \leq -10000000000 \lor \neg \left(\frac{x}{y} \leq 5 \cdot 10^{-5}\right):\\
\;\;\;\;t \cdot \frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if (/.f64 x y) < -1e10 or 5.00000000000000024e-5 < (/.f64 x y) Initial program 99.1%
fma-def99.1%
Simplified99.1%
Taylor expanded in z around 0 48.9%
mul-1-neg48.9%
unsub-neg48.9%
*-rgt-identity48.9%
associate-*r/54.0%
distribute-lft-out--54.0%
Simplified54.0%
Taylor expanded in x around inf 53.9%
mul-1-neg53.9%
distribute-frac-neg53.9%
Simplified53.9%
if -1e10 < (/.f64 x y) < 5.00000000000000024e-5Initial program 98.4%
fma-def98.4%
Simplified98.4%
Taylor expanded in x around 0 80.4%
Final simplification67.2%
(FPCore (x y z t) :precision binary64 (if (or (<= t -440000000.0) (not (<= t 1.25e+15))) (+ t (/ t (/ (- y) x))) (+ t (* z (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -440000000.0) || !(t <= 1.25e+15)) {
tmp = t + (t / (-y / x));
} 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 <= (-440000000.0d0)) .or. (.not. (t <= 1.25d+15))) then
tmp = t + (t / (-y / x))
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 <= -440000000.0) || !(t <= 1.25e+15)) {
tmp = t + (t / (-y / x));
} else {
tmp = t + (z * (x / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -440000000.0) or not (t <= 1.25e+15): tmp = t + (t / (-y / x)) else: tmp = t + (z * (x / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -440000000.0) || !(t <= 1.25e+15)) tmp = Float64(t + Float64(t / Float64(Float64(-y) / x))); 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 <= -440000000.0) || ~((t <= 1.25e+15))) tmp = t + (t / (-y / x)); else tmp = t + (z * (x / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -440000000.0], N[Not[LessEqual[t, 1.25e+15]], $MachinePrecision]], N[(t + N[(t / N[((-y) / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -440000000 \lor \neg \left(t \leq 1.25 \cdot 10^{+15}\right):\\
\;\;\;\;t + \frac{t}{\frac{-y}{x}}\\
\mathbf{else}:\\
\;\;\;\;t + z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if t < -4.4e8 or 1.25e15 < t Initial program 99.9%
Taylor expanded in z around 0 84.5%
associate-*r/84.5%
mul-1-neg84.5%
*-commutative84.5%
distribute-rgt-neg-out84.5%
associate-*r/85.4%
Simplified85.4%
*-commutative85.4%
div-inv85.4%
associate-*l*91.4%
add-sqr-sqrt47.1%
sqrt-unprod41.9%
sqr-neg41.9%
sqrt-unprod27.1%
add-sqr-sqrt55.9%
associate-/r/55.9%
div-inv55.9%
frac-2neg55.9%
add-sqr-sqrt28.7%
sqrt-unprod40.5%
sqr-neg40.5%
sqrt-unprod44.3%
add-sqr-sqrt91.5%
distribute-neg-frac91.5%
Applied egg-rr91.5%
if -4.4e8 < t < 1.25e15Initial program 97.4%
Taylor expanded in z around inf 86.2%
associate-/l*85.4%
associate-/r/90.1%
Applied egg-rr90.1%
Final simplification90.9%
(FPCore (x y z t) :precision binary64 (if (or (<= t -2.75e-18) (not (<= t 3.1e+15))) (* t (- 1.0 (/ x y))) (+ t (* z (/ x y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -2.75e-18) || !(t <= 3.1e+15)) {
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 <= (-2.75d-18)) .or. (.not. (t <= 3.1d+15))) 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 <= -2.75e-18) || !(t <= 3.1e+15)) {
tmp = t * (1.0 - (x / y));
} else {
tmp = t + (z * (x / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -2.75e-18) or not (t <= 3.1e+15): 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 <= -2.75e-18) || !(t <= 3.1e+15)) 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 <= -2.75e-18) || ~((t <= 3.1e+15))) 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, -2.75e-18], N[Not[LessEqual[t, 3.1e+15]], $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 -2.75 \cdot 10^{-18} \lor \neg \left(t \leq 3.1 \cdot 10^{+15}\right):\\
\;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;t + z \cdot \frac{x}{y}\\
\end{array}
\end{array}
if t < -2.75e-18 or 3.1e15 < t Initial program 99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around 0 83.3%
mul-1-neg83.3%
unsub-neg83.3%
*-rgt-identity83.3%
associate-*r/90.5%
distribute-lft-out--90.5%
Simplified90.5%
if -2.75e-18 < t < 3.1e15Initial program 97.2%
Taylor expanded in z around inf 87.0%
associate-/l*87.1%
associate-/r/91.3%
Applied egg-rr91.3%
Final simplification90.8%
(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 98.7%
Final simplification98.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 98.7%
fma-def98.8%
Simplified98.8%
Taylor expanded in z around 0 61.5%
mul-1-neg61.5%
unsub-neg61.5%
*-rgt-identity61.5%
associate-*r/67.5%
distribute-lft-out--67.4%
Simplified67.4%
Final simplification67.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 98.7%
fma-def98.8%
Simplified98.8%
Taylor expanded in x around 0 41.8%
Final simplification41.8%
(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 2023321
(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))