
(FPCore (x y z) :precision binary64 (/ (* x y) z))
double code(double x, double y, double z) {
return (x * y) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) / z
end function
public static double code(double x, double y, double z) {
return (x * y) / z;
}
def code(x, y, z): return (x * y) / z
function code(x, y, z) return Float64(Float64(x * y) / z) end
function tmp = code(x, y, z) tmp = (x * y) / z; end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x y) z))
double code(double x, double y, double z) {
return (x * y) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) / z
end function
public static double code(double x, double y, double z) {
return (x * y) / z;
}
def code(x, y, z): return (x * y) / z
function code(x, y, z) return Float64(Float64(x * y) / z) end
function tmp = code(x, y, z) tmp = (x * y) / z; end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y}{z}
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x y) z)))
(if (<= t_0 -2e+177)
(* y (/ x z))
(if (or (<= t_0 2e-266) (not (<= t_0 2e+282))) (* x (/ y z)) t_0))))assert(x < y);
double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (t_0 <= -2e+177) {
tmp = y * (x / z);
} else if ((t_0 <= 2e-266) || !(t_0 <= 2e+282)) {
tmp = x * (y / z);
} else {
tmp = t_0;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * y) / z
if (t_0 <= (-2d+177)) then
tmp = y * (x / z)
else if ((t_0 <= 2d-266) .or. (.not. (t_0 <= 2d+282))) then
tmp = x * (y / z)
else
tmp = t_0
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (t_0 <= -2e+177) {
tmp = y * (x / z);
} else if ((t_0 <= 2e-266) || !(t_0 <= 2e+282)) {
tmp = x * (y / z);
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): t_0 = (x * y) / z tmp = 0 if t_0 <= -2e+177: tmp = y * (x / z) elif (t_0 <= 2e-266) or not (t_0 <= 2e+282): tmp = x * (y / z) else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y, z) t_0 = Float64(Float64(x * y) / z) tmp = 0.0 if (t_0 <= -2e+177) tmp = Float64(y * Float64(x / z)); elseif ((t_0 <= 2e-266) || !(t_0 <= 2e+282)) tmp = Float64(x * Float64(y / z)); else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
t_0 = (x * y) / z;
tmp = 0.0;
if (t_0 <= -2e+177)
tmp = y * (x / z);
elseif ((t_0 <= 2e-266) || ~((t_0 <= 2e+282)))
tmp = x * (y / z);
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+177], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$0, 2e-266], N[Not[LessEqual[t$95$0, 2e+282]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{z}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+177}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-266} \lor \neg \left(t_0 \leq 2 \cdot 10^{+282}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 x y) z) < -2e177Initial program 81.6%
associate-/l*88.6%
Simplified88.6%
associate-/r/97.5%
Applied egg-rr97.5%
if -2e177 < (/.f64 (*.f64 x y) z) < 2e-266 or 2.00000000000000007e282 < (/.f64 (*.f64 x y) z) Initial program 87.8%
associate-*r/95.5%
*-commutative95.5%
Simplified95.5%
if 2e-266 < (/.f64 (*.f64 x y) z) < 2.00000000000000007e282Initial program 99.5%
Final simplification96.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -7.5e-209) (* y (/ x z)) (* x (/ y z))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e-209) {
tmp = y * (x / z);
} else {
tmp = x * (y / z);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-7.5d-209)) then
tmp = y * (x / z)
else
tmp = x * (y / z)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e-209) {
tmp = y * (x / z);
} else {
tmp = x * (y / z);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -7.5e-209: tmp = y * (x / z) else: tmp = x * (y / z) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -7.5e-209) tmp = Float64(y * Float64(x / z)); else tmp = Float64(x * Float64(y / z)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -7.5e-209)
tmp = y * (x / z);
else
tmp = x * (y / z);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -7.5e-209], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-209}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if z < -7.49999999999999965e-209Initial program 90.7%
associate-/l*91.8%
Simplified91.8%
associate-/r/92.1%
Applied egg-rr92.1%
if -7.49999999999999965e-209 < z Initial program 89.2%
associate-*r/89.4%
*-commutative89.4%
Simplified89.4%
Final simplification90.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z -2.1e-203) (* y (/ x z)) (/ x (/ z y))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e-203) {
tmp = y * (x / z);
} else {
tmp = x / (z / y);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-2.1d-203)) then
tmp = y * (x / z)
else
tmp = x / (z / y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e-203) {
tmp = y * (x / z);
} else {
tmp = x / (z / y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= -2.1e-203: tmp = y * (x / z) else: tmp = x / (z / y) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= -2.1e-203) tmp = Float64(y * Float64(x / z)); else tmp = Float64(x / Float64(z / y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= -2.1e-203)
tmp = y * (x / z);
else
tmp = x / (z / y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[z, -2.1e-203], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{-203}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if z < -2.10000000000000002e-203Initial program 90.7%
associate-/l*91.8%
Simplified91.8%
associate-/r/92.1%
Applied egg-rr92.1%
if -2.10000000000000002e-203 < z Initial program 89.2%
associate-/l*89.3%
Simplified89.3%
Final simplification90.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* y (/ x z)))
assert(x < y);
double code(double x, double y, double z) {
return y * (x / z);
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * (x / z)
end function
assert x < y;
public static double code(double x, double y, double z) {
return y * (x / z);
}
[x, y] = sort([x, y]) def code(x, y, z): return y * (x / z)
x, y = sort([x, y]) function code(x, y, z) return Float64(y * Float64(x / z)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = y * (x / z);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y \cdot \frac{x}{z}
\end{array}
Initial program 89.9%
associate-/l*90.4%
Simplified90.4%
associate-/r/93.9%
Applied egg-rr93.9%
Final simplification93.9%
(FPCore (x y z) :precision binary64 (if (< z -4.262230790519429e-138) (/ (* x y) z) (if (< z 1.7042130660650472e-164) (/ x (/ z y)) (* (/ x z) y))))
double code(double x, double y, double z) {
double tmp;
if (z < -4.262230790519429e-138) {
tmp = (x * y) / z;
} else if (z < 1.7042130660650472e-164) {
tmp = x / (z / y);
} else {
tmp = (x / z) * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z < (-4.262230790519429d-138)) then
tmp = (x * y) / z
else if (z < 1.7042130660650472d-164) then
tmp = x / (z / y)
else
tmp = (x / z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z < -4.262230790519429e-138) {
tmp = (x * y) / z;
} else if (z < 1.7042130660650472e-164) {
tmp = x / (z / y);
} else {
tmp = (x / z) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z < -4.262230790519429e-138: tmp = (x * y) / z elif z < 1.7042130660650472e-164: tmp = x / (z / y) else: tmp = (x / z) * y return tmp
function code(x, y, z) tmp = 0.0 if (z < -4.262230790519429e-138) tmp = Float64(Float64(x * y) / z); elseif (z < 1.7042130660650472e-164) tmp = Float64(x / Float64(z / y)); else tmp = Float64(Float64(x / z) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z < -4.262230790519429e-138) tmp = (x * y) / z; elseif (z < 1.7042130660650472e-164) tmp = x / (z / y); else tmp = (x / z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[z, -4.262230790519429e-138], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[Less[z, 1.7042130660650472e-164], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z < -4.262230790519429 \cdot 10^{-138}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;z < 1.7042130660650472 \cdot 10^{-164}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot y\\
\end{array}
\end{array}
herbie shell --seed 2023274
(FPCore (x y z)
:name "Diagrams.Solve.Tridiagonal:solveCyclicTriDiagonal from diagrams-solve-0.1, A"
:precision binary64
:herbie-target
(if (< z -4.262230790519429e-138) (/ (* x y) z) (if (< z 1.7042130660650472e-164) (/ x (/ z y)) (* (/ x z) y)))
(/ (* x y) z))