
(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 6 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 (if (<= y 1.6e-199) (+ t (* (/ x y) (- z t))) (+ t (* x (/ (- z t) y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.6e-199) {
tmp = t + ((x / y) * (z - t));
} else {
tmp = t + (x * ((z - 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 (y <= 1.6d-199) then
tmp = t + ((x / y) * (z - t))
else
tmp = t + (x * ((z - t) / y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.6e-199) {
tmp = t + ((x / y) * (z - t));
} else {
tmp = t + (x * ((z - t) / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.6e-199: tmp = t + ((x / y) * (z - t)) else: tmp = t + (x * ((z - t) / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.6e-199) tmp = Float64(t + Float64(Float64(x / y) * Float64(z - t))); else tmp = Float64(t + Float64(x * Float64(Float64(z - t) / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.6e-199) tmp = t + ((x / y) * (z - t)); else tmp = t + (x * ((z - t) / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.6e-199], N[(t + N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.6 \cdot 10^{-199}:\\
\;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\
\mathbf{else}:\\
\;\;\;\;t + x \cdot \frac{z - t}{y}\\
\end{array}
\end{array}
if y < 1.6e-199Initial program 99.2%
if 1.6e-199 < y Initial program 93.7%
Taylor expanded in x around 0 91.1%
associate-*r/98.9%
Simplified98.9%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (if (<= z -2.7e-52) (+ t (/ x (/ y z))) (if (<= z 1.5e-135) (- t (/ (* x t) y)) (+ t (* (/ x y) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.7e-52) {
tmp = t + (x / (y / z));
} else if (z <= 1.5e-135) {
tmp = t - ((x * t) / 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 (z <= (-2.7d-52)) then
tmp = t + (x / (y / z))
else if (z <= 1.5d-135) then
tmp = t - ((x * t) / 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 (z <= -2.7e-52) {
tmp = t + (x / (y / z));
} else if (z <= 1.5e-135) {
tmp = t - ((x * t) / y);
} else {
tmp = t + ((x / y) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.7e-52: tmp = t + (x / (y / z)) elif z <= 1.5e-135: tmp = t - ((x * t) / y) else: tmp = t + ((x / y) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.7e-52) tmp = Float64(t + Float64(x / Float64(y / z))); elseif (z <= 1.5e-135) tmp = Float64(t - Float64(Float64(x * t) / 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 (z <= -2.7e-52) tmp = t + (x / (y / z)); elseif (z <= 1.5e-135) tmp = t - ((x * t) / y); else tmp = t + ((x / y) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.7e-52], N[(t + N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.5e-135], N[(t - N[(N[(x * t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(t + N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{-52}:\\
\;\;\;\;t + \frac{x}{\frac{y}{z}}\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-135}:\\
\;\;\;\;t - \frac{x \cdot t}{y}\\
\mathbf{else}:\\
\;\;\;\;t + \frac{x}{y} \cdot z\\
\end{array}
\end{array}
if z < -2.70000000000000009e-52Initial program 97.1%
associate-*l/87.2%
associate-/l*95.8%
Applied egg-rr95.8%
Taylor expanded in z around inf 87.8%
if -2.70000000000000009e-52 < z < 1.50000000000000006e-135Initial program 94.9%
Taylor expanded in z around 0 90.0%
mul-1-neg90.0%
*-commutative90.0%
Simplified90.0%
if 1.50000000000000006e-135 < z Initial program 99.6%
Taylor expanded in z around inf 85.4%
associate-*l/91.3%
*-commutative91.3%
Simplified91.3%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (<= z -3.4e-53) (+ t (/ x (/ y z))) (if (<= z 2.8e-94) (- t (* x (/ t y))) (+ t (* (/ x y) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.4e-53) {
tmp = t + (x / (y / z));
} else if (z <= 2.8e-94) {
tmp = t - (x * (t / 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 (z <= (-3.4d-53)) then
tmp = t + (x / (y / z))
else if (z <= 2.8d-94) then
tmp = t - (x * (t / 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 (z <= -3.4e-53) {
tmp = t + (x / (y / z));
} else if (z <= 2.8e-94) {
tmp = t - (x * (t / y));
} else {
tmp = t + ((x / y) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -3.4e-53: tmp = t + (x / (y / z)) elif z <= 2.8e-94: tmp = t - (x * (t / y)) else: tmp = t + ((x / y) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -3.4e-53) tmp = Float64(t + Float64(x / Float64(y / z))); elseif (z <= 2.8e-94) tmp = Float64(t - Float64(x * Float64(t / 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 (z <= -3.4e-53) tmp = t + (x / (y / z)); elseif (z <= 2.8e-94) tmp = t - (x * (t / y)); else tmp = t + ((x / y) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.4e-53], N[(t + N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.8e-94], N[(t - N[(x * N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-53}:\\
\;\;\;\;t + \frac{x}{\frac{y}{z}}\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{-94}:\\
\;\;\;\;t - x \cdot \frac{t}{y}\\
\mathbf{else}:\\
\;\;\;\;t + \frac{x}{y} \cdot z\\
\end{array}
\end{array}
if z < -3.4e-53Initial program 97.1%
associate-*l/87.2%
associate-/l*95.8%
Applied egg-rr95.8%
Taylor expanded in z around inf 87.8%
if -3.4e-53 < z < 2.7999999999999998e-94Initial program 95.2%
associate-*l/94.4%
associate-/l*99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 87.7%
mul-1-neg87.7%
associate-*l/92.4%
*-commutative92.4%
distribute-rgt-neg-in92.4%
Simplified92.4%
if 2.7999999999999998e-94 < z Initial program 99.5%
Taylor expanded in z around inf 87.7%
associate-*l/93.9%
*-commutative93.9%
Simplified93.9%
Final simplification91.6%
(FPCore (x y z t) :precision binary64 (+ t (* x (/ (- z t) y))))
double code(double x, double y, double z, double t) {
return t + (x * ((z - t) / 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 + (x * ((z - t) / y))
end function
public static double code(double x, double y, double z, double t) {
return t + (x * ((z - t) / y));
}
def code(x, y, z, t): return t + (x * ((z - t) / y))
function code(x, y, z, t) return Float64(t + Float64(x * Float64(Float64(z - t) / y))) end
function tmp = code(x, y, z, t) tmp = t + (x * ((z - t) / y)); end
code[x_, y_, z_, t_] := N[(t + N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + x \cdot \frac{z - t}{y}
\end{array}
Initial program 97.2%
Taylor expanded in x around 0 91.7%
associate-*r/96.2%
Simplified96.2%
Final simplification96.2%
(FPCore (x y z t) :precision binary64 (+ t (* x (/ z y))))
double code(double x, double y, double z, double t) {
return t + (x * (z / 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 + (x * (z / y))
end function
public static double code(double x, double y, double z, double t) {
return t + (x * (z / y));
}
def code(x, y, z, t): return t + (x * (z / y))
function code(x, y, z, t) return Float64(t + Float64(x * Float64(z / y))) end
function tmp = code(x, y, z, t) tmp = t + (x * (z / y)); end
code[x_, y_, z_, t_] := N[(t + N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + x \cdot \frac{z}{y}
\end{array}
Initial program 97.2%
Taylor expanded in z around inf 72.5%
*-commutative72.5%
associate-*l/74.8%
*-commutative74.8%
Simplified74.8%
Final simplification74.8%
(FPCore (x y z t) :precision binary64 (+ t (* (/ x y) z)))
double code(double x, double y, double z, double t) {
return t + ((x / y) * z);
}
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)
end function
public static double code(double x, double y, double z, double t) {
return t + ((x / y) * z);
}
def code(x, y, z, t): return t + ((x / y) * z)
function code(x, y, z, t) return Float64(t + Float64(Float64(x / y) * z)) end
function tmp = code(x, y, z, t) tmp = t + ((x / y) * z); end
code[x_, y_, z_, t_] := N[(t + N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \frac{x}{y} \cdot z
\end{array}
Initial program 97.2%
Taylor expanded in z around inf 72.5%
associate-*l/77.3%
*-commutative77.3%
Simplified77.3%
Final simplification77.3%
(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 2024026
(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))