
(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 (if (<= y 1.7e-292) (* x (/ y z)) (if (<= y 1.15e+44) (/ y (/ z x)) (/ (* x y) z))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (y <= 1.7e-292) {
tmp = x * (y / z);
} else if (y <= 1.15e+44) {
tmp = y / (z / x);
} 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 (y <= 1.7d-292) then
tmp = x * (y / z)
else if (y <= 1.15d+44) then
tmp = y / (z / x)
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 (y <= 1.7e-292) {
tmp = x * (y / z);
} else if (y <= 1.15e+44) {
tmp = y / (z / x);
} else {
tmp = (x * y) / z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if y <= 1.7e-292: tmp = x * (y / z) elif y <= 1.15e+44: tmp = y / (z / x) else: tmp = (x * y) / z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (y <= 1.7e-292) tmp = Float64(x * Float64(y / z)); elseif (y <= 1.15e+44) tmp = Float64(y / Float64(z / x)); else tmp = Float64(Float64(x * y) / z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= 1.7e-292)
tmp = x * (y / z);
elseif (y <= 1.15e+44)
tmp = y / (z / x);
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[y, 1.7e-292], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15e+44], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.7 \cdot 10^{-292}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+44}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if y < 1.70000000000000009e-292Initial program 95.1%
associate-*r/95.7%
*-commutative95.7%
Simplified95.7%
if 1.70000000000000009e-292 < y < 1.15000000000000002e44Initial program 91.7%
associate-*r/96.6%
*-commutative96.6%
Simplified96.6%
associate-*l/91.7%
associate-/l*97.1%
Applied egg-rr97.1%
if 1.15000000000000002e44 < y Initial program 96.4%
Final simplification96.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* x y) 0.0) (* y (* x (/ 1.0 z))) (/ (* x y) z)))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((x * y) <= 0.0) {
tmp = y * (x * (1.0 / 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 ((x * y) <= 0.0d0) then
tmp = y * (x * (1.0d0 / 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 ((x * y) <= 0.0) {
tmp = y * (x * (1.0 / z));
} else {
tmp = (x * y) / z;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (x * y) <= 0.0: tmp = y * (x * (1.0 / z)) else: tmp = (x * y) / z return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (Float64(x * y) <= 0.0) tmp = Float64(y * Float64(x * Float64(1.0 / z))); else tmp = Float64(Float64(x * y) / z); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((x * y) <= 0.0)
tmp = y * (x * (1.0 / 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[N[(x * y), $MachinePrecision], 0.0], N[(y * N[(x * N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq 0:\\
\;\;\;\;y \cdot \left(x \cdot \frac{1}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if (*.f64 x y) < -0.0Initial program 91.7%
associate-/l*94.6%
Simplified94.6%
associate-/l*91.7%
*-commutative91.7%
associate-*l/94.6%
div-inv94.4%
associate-*l*93.1%
Applied egg-rr93.1%
if -0.0 < (*.f64 x y) Initial program 97.3%
Final simplification95.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 1.35e-295) (* x (/ y z)) (/ y (/ z x))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e-295) {
tmp = x * (y / z);
} else {
tmp = y / (z / x);
}
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 (y <= 1.35d-295) then
tmp = x * (y / z)
else
tmp = y / (z / x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e-295) {
tmp = x * (y / z);
} else {
tmp = y / (z / x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if y <= 1.35e-295: tmp = x * (y / z) else: tmp = y / (z / x) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (y <= 1.35e-295) tmp = Float64(x * Float64(y / z)); else tmp = Float64(y / Float64(z / x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= 1.35e-295)
tmp = x * (y / z);
else
tmp = y / (z / x);
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[y, 1.35e-295], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{-295}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < 1.35e-295Initial program 95.1%
associate-*r/95.7%
*-commutative95.7%
Simplified95.7%
if 1.35e-295 < y Initial program 93.6%
associate-*r/95.1%
*-commutative95.1%
Simplified95.1%
associate-*l/93.6%
associate-/l*94.0%
Applied egg-rr94.0%
Final simplification94.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x (/ y z)))
assert(x < y);
double code(double x, double y, double z) {
return x * (y / 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 = x * (y / z)
end function
assert x < y;
public static double code(double x, double y, double z) {
return x * (y / z);
}
[x, y] = sort([x, y]) def code(x, y, z): return x * (y / z)
x, y = sort([x, y]) function code(x, y, z) return Float64(x * Float64(y / z)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y, z)
tmp = x * (y / z);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot \frac{y}{z}
\end{array}
Initial program 94.3%
associate-*r/95.4%
*-commutative95.4%
Simplified95.4%
Final simplification95.4%
(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 2023305
(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))