
(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 5 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 2.2e-301)
(/ y (/ z x))
(if (<= t_0 2e+299) t_0 (/ x (/ z y))))))assert(x < y);
double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (t_0 <= 2.2e-301) {
tmp = y / (z / x);
} else if (t_0 <= 2e+299) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (x * y) / z
if (t_0 <= 2.2d-301) then
tmp = y / (z / x)
else if (t_0 <= 2d+299) then
tmp = t_0
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 t_0 = (x * y) / z;
double tmp;
if (t_0 <= 2.2e-301) {
tmp = y / (z / x);
} else if (t_0 <= 2e+299) {
tmp = t_0;
} else {
tmp = x / (z / y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): t_0 = (x * y) / z tmp = 0 if t_0 <= 2.2e-301: tmp = y / (z / x) elif t_0 <= 2e+299: tmp = t_0 else: tmp = x / (z / y) 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 <= 2.2e-301) tmp = Float64(y / Float64(z / x)); elseif (t_0 <= 2e+299) tmp = t_0; else tmp = Float64(x / Float64(z / y)); 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 <= 2.2e-301)
tmp = y / (z / x);
elseif (t_0 <= 2e+299)
tmp = t_0;
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_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, 2.2e-301], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+299], t$95$0, N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]]
\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.2 \cdot 10^{-301}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+299}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x y) z) < 2.2e-301Initial program 91.6%
associate-*r/94.6%
*-commutative94.6%
Simplified94.6%
associate-*l/91.6%
associate-/l*94.3%
Applied egg-rr94.3%
if 2.2e-301 < (/.f64 (*.f64 x y) z) < 2.0000000000000001e299Initial program 98.4%
if 2.0000000000000001e299 < (/.f64 (*.f64 x y) z) Initial program 81.5%
associate-/l*98.3%
Simplified98.3%
Final simplification96.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y 4.2e-286) (not (<= y 1.7e-50))) (* y (/ x z)) (* x (/ y z))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((y <= 4.2e-286) || !(y <= 1.7e-50)) {
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 ((y <= 4.2d-286) .or. (.not. (y <= 1.7d-50))) 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 ((y <= 4.2e-286) || !(y <= 1.7e-50)) {
tmp = y * (x / z);
} else {
tmp = x * (y / z);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if (y <= 4.2e-286) or not (y <= 1.7e-50): 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 ((y <= 4.2e-286) || !(y <= 1.7e-50)) 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 ((y <= 4.2e-286) || ~((y <= 1.7e-50)))
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[Or[LessEqual[y, 4.2e-286], N[Not[LessEqual[y, 1.7e-50]], $MachinePrecision]], 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}\;y \leq 4.2 \cdot 10^{-286} \lor \neg \left(y \leq 1.7 \cdot 10^{-50}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < 4.19999999999999977e-286 or 1.70000000000000007e-50 < y Initial program 93.1%
associate-/l*91.4%
Simplified91.4%
associate-/r/94.8%
Applied egg-rr94.8%
if 4.19999999999999977e-286 < y < 1.70000000000000007e-50Initial program 87.4%
associate-*r/98.6%
*-commutative98.6%
Simplified98.6%
Final simplification95.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z 1.14e-243) (not (<= z 3.6e+175))) (* y (/ x z)) (/ x (/ z y))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if ((z <= 1.14e-243) || !(z <= 3.6e+175)) {
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 <= 1.14d-243) .or. (.not. (z <= 3.6d+175))) 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 <= 1.14e-243) || !(z <= 3.6e+175)) {
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 <= 1.14e-243) or not (z <= 3.6e+175): 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 <= 1.14e-243) || !(z <= 3.6e+175)) 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 <= 1.14e-243) || ~((z <= 3.6e+175)))
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[Or[LessEqual[z, 1.14e-243], N[Not[LessEqual[z, 3.6e+175]], $MachinePrecision]], 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 1.14 \cdot 10^{-243} \lor \neg \left(z \leq 3.6 \cdot 10^{+175}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if z < 1.14000000000000002e-243 or 3.60000000000000034e175 < z Initial program 90.5%
associate-/l*93.6%
Simplified93.6%
associate-/r/94.3%
Applied egg-rr94.3%
if 1.14000000000000002e-243 < z < 3.60000000000000034e175Initial program 95.3%
associate-/l*90.3%
Simplified90.3%
Final simplification93.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 4.1e-206) (/ y (/ z x)) (if (<= z 1.75e+174) (/ x (/ z y)) (* y (/ x z)))))
assert(x < y);
double code(double x, double y, double z) {
double tmp;
if (z <= 4.1e-206) {
tmp = y / (z / x);
} else if (z <= 1.75e+174) {
tmp = x / (z / y);
} else {
tmp = y * (x / 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 <= 4.1d-206) then
tmp = y / (z / x)
else if (z <= 1.75d+174) then
tmp = x / (z / y)
else
tmp = y * (x / z)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
double tmp;
if (z <= 4.1e-206) {
tmp = y / (z / x);
} else if (z <= 1.75e+174) {
tmp = x / (z / y);
} else {
tmp = y * (x / z);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y, z): tmp = 0 if z <= 4.1e-206: tmp = y / (z / x) elif z <= 1.75e+174: tmp = x / (z / y) else: tmp = y * (x / z) return tmp
x, y = sort([x, y]) function code(x, y, z) tmp = 0.0 if (z <= 4.1e-206) tmp = Float64(y / Float64(z / x)); elseif (z <= 1.75e+174) tmp = Float64(x / Float64(z / y)); else tmp = Float64(y * Float64(x / z)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (z <= 4.1e-206)
tmp = y / (z / x);
elseif (z <= 1.75e+174)
tmp = x / (z / y);
else
tmp = y * (x / 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, 4.1e-206], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.75e+174], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.1 \cdot 10^{-206}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;z \leq 1.75 \cdot 10^{+174}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if z < 4.10000000000000016e-206Initial program 92.0%
associate-*r/91.5%
*-commutative91.5%
Simplified91.5%
associate-*l/92.0%
associate-/l*95.2%
Applied egg-rr95.2%
if 4.10000000000000016e-206 < z < 1.7500000000000001e174Initial program 95.0%
associate-/l*91.7%
Simplified91.7%
if 1.7500000000000001e174 < z Initial program 80.1%
associate-/l*96.6%
Simplified96.6%
associate-/r/94.8%
Applied egg-rr94.8%
Final simplification94.1%
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 92.0%
associate-/l*92.6%
Simplified92.6%
associate-/r/94.6%
Applied egg-rr94.6%
Final simplification94.6%
(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 2023290
(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))