
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2): return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 * a2) / Float64(b1 * b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 * a2) / (b1 * b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2): return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 * a2) / Float64(b1 * b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 * a2) / (b1 * b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* a1 a2) (* b1 b2))) (t_1 (* (/ a1 b1) (/ a2 b2))))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -2e-322)
t_0
(if (<= t_0 0.0)
t_1
(if (<= t_0 5e+297)
(* (* a1 a2) (/ (/ 1.0 b1) b2))
(* (/ a2 b1) (/ a1 b2))))))))assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 / b1) * (a2 / b2);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -2e-322) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 5e+297) {
tmp = (a1 * a2) * ((1.0 / b1) / b2);
} else {
tmp = (a2 / b1) * (a1 / b2);
}
return tmp;
}
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 / b1) * (a2 / b2);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= -2e-322) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 5e+297) {
tmp = (a1 * a2) * ((1.0 / b1) / b2);
} else {
tmp = (a2 / b1) * (a1 / b2);
}
return tmp;
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) t_1 = (a1 / b1) * (a2 / b2) tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= -2e-322: tmp = t_0 elif t_0 <= 0.0: tmp = t_1 elif t_0 <= 5e+297: tmp = (a1 * a2) * ((1.0 / b1) / b2) else: tmp = (a2 / b1) * (a1 / b2) return tmp
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) t_1 = Float64(Float64(a1 / b1) * Float64(a2 / b2)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -2e-322) tmp = t_0; elseif (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 5e+297) tmp = Float64(Float64(a1 * a2) * Float64(Float64(1.0 / b1) / b2)); else tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); end return tmp end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
t_1 = (a1 / b1) * (a2 / b2);
tmp = 0.0;
if (t_0 <= -Inf)
tmp = t_1;
elseif (t_0 <= -2e-322)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = t_1;
elseif (t_0 <= 5e+297)
tmp = (a1 * a2) * ((1.0 / b1) / b2);
else
tmp = (a2 / b1) * (a1 / b2);
end
tmp_2 = tmp;
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -2e-322], t$95$0, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 5e+297], N[(N[(a1 * a2), $MachinePrecision] * N[(N[(1.0 / b1), $MachinePrecision] / b2), $MachinePrecision]), $MachinePrecision], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-322}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+297}:\\
\;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b1}}{b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or -1.97626e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0Initial program 71.3%
times-frac92.9%
Simplified92.9%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.97626e-322Initial program 99.5%
if -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999998e297Initial program 99.2%
div-inv99.3%
*-commutative99.3%
associate-/r*99.4%
Applied egg-rr99.4%
if 4.9999999999999998e297 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 64.1%
*-commutative64.1%
times-frac99.6%
Applied egg-rr99.6%
Final simplification96.8%
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* a1 a2) (* b1 b2))) (t_1 (* (/ a1 b1) (/ a2 b2))))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -2e-322)
t_0
(if (<= t_0 0.0)
t_1
(if (<= t_0 5e+297) t_0 (* (/ a2 b1) (/ a1 b2))))))))assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 / b1) * (a2 / b2);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -2e-322) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 5e+297) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / b2);
}
return tmp;
}
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 / b1) * (a2 / b2);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= -2e-322) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 5e+297) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / b2);
}
return tmp;
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) t_1 = (a1 / b1) * (a2 / b2) tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= -2e-322: tmp = t_0 elif t_0 <= 0.0: tmp = t_1 elif t_0 <= 5e+297: tmp = t_0 else: tmp = (a2 / b1) * (a1 / b2) return tmp
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) t_1 = Float64(Float64(a1 / b1) * Float64(a2 / b2)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -2e-322) tmp = t_0; elseif (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 5e+297) tmp = t_0; else tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); end return tmp end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
t_1 = (a1 / b1) * (a2 / b2);
tmp = 0.0;
if (t_0 <= -Inf)
tmp = t_1;
elseif (t_0 <= -2e-322)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = t_1;
elseif (t_0 <= 5e+297)
tmp = t_0;
else
tmp = (a2 / b1) * (a1 / b2);
end
tmp_2 = tmp;
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -2e-322], t$95$0, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 5e+297], t$95$0, N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-322}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+297}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or -1.97626e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0Initial program 71.3%
times-frac92.9%
Simplified92.9%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.97626e-322 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999998e297Initial program 99.4%
if 4.9999999999999998e297 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 64.1%
*-commutative64.1%
times-frac99.6%
Applied egg-rr99.6%
Final simplification96.8%
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(if (or (<= (* b1 b2) -2e+153)
(and (not (<= (* b1 b2) -1e-172))
(or (<= (* b1 b2) 4e-190) (not (<= (* b1 b2) 5e+168)))))
(* (/ a1 b1) (/ a2 b2))
(* a2 (/ a1 (* b1 b2)))))assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -2e+153) || (!((b1 * b2) <= -1e-172) && (((b1 * b2) <= 4e-190) || !((b1 * b2) <= 5e+168)))) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a2 * (a1 / (b1 * b2));
}
return tmp;
}
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: tmp
if (((b1 * b2) <= (-2d+153)) .or. (.not. ((b1 * b2) <= (-1d-172))) .and. ((b1 * b2) <= 4d-190) .or. (.not. ((b1 * b2) <= 5d+168))) then
tmp = (a1 / b1) * (a2 / b2)
else
tmp = a2 * (a1 / (b1 * b2))
end if
code = tmp
end function
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -2e+153) || (!((b1 * b2) <= -1e-172) && (((b1 * b2) <= 4e-190) || !((b1 * b2) <= 5e+168)))) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a2 * (a1 / (b1 * b2));
}
return tmp;
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if ((b1 * b2) <= -2e+153) or (not ((b1 * b2) <= -1e-172) and (((b1 * b2) <= 4e-190) or not ((b1 * b2) <= 5e+168))): tmp = (a1 / b1) * (a2 / b2) else: tmp = a2 * (a1 / (b1 * b2)) return tmp
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if ((Float64(b1 * b2) <= -2e+153) || (!(Float64(b1 * b2) <= -1e-172) && ((Float64(b1 * b2) <= 4e-190) || !(Float64(b1 * b2) <= 5e+168)))) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); else tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); end return tmp end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
tmp = 0.0;
if (((b1 * b2) <= -2e+153) || (~(((b1 * b2) <= -1e-172)) && (((b1 * b2) <= 4e-190) || ~(((b1 * b2) <= 5e+168)))))
tmp = (a1 / b1) * (a2 / b2);
else
tmp = a2 * (a1 / (b1 * b2));
end
tmp_2 = tmp;
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := If[Or[LessEqual[N[(b1 * b2), $MachinePrecision], -2e+153], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], -1e-172]], $MachinePrecision], Or[LessEqual[N[(b1 * b2), $MachinePrecision], 4e-190], N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 5e+168]], $MachinePrecision]]]], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+153} \lor \neg \left(b1 \cdot b2 \leq -1 \cdot 10^{-172}\right) \land \left(b1 \cdot b2 \leq 4 \cdot 10^{-190} \lor \neg \left(b1 \cdot b2 \leq 5 \cdot 10^{+168}\right)\right):\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -2e153 or -1e-172 < (*.f64 b1 b2) < 4.0000000000000001e-190 or 4.99999999999999967e168 < (*.f64 b1 b2) Initial program 73.9%
times-frac92.3%
Simplified92.3%
if -2e153 < (*.f64 b1 b2) < -1e-172 or 4.0000000000000001e-190 < (*.f64 b1 b2) < 4.99999999999999967e168Initial program 91.9%
associate-*l/94.6%
*-commutative94.6%
Simplified94.6%
Final simplification93.4%
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (* a2 (/ a1 (* b1 b2)))) (t_1 (* (/ a2 b1) (/ a1 b2))))
(if (<= (* b1 b2) -1e+266)
t_1
(if (<= (* b1 b2) -2e-189)
t_0
(if (<= (* b1 b2) 5e-150)
t_1
(if (<= (* b1 b2) 5e+168) t_0 (* (/ a1 b1) (/ a2 b2))))))))assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = a2 * (a1 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+266) {
tmp = t_1;
} else if ((b1 * b2) <= -2e-189) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-150) {
tmp = t_1;
} else if ((b1 * b2) <= 5e+168) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = a2 * (a1 / (b1 * b2))
t_1 = (a2 / b1) * (a1 / b2)
if ((b1 * b2) <= (-1d+266)) then
tmp = t_1
else if ((b1 * b2) <= (-2d-189)) then
tmp = t_0
else if ((b1 * b2) <= 5d-150) then
tmp = t_1
else if ((b1 * b2) <= 5d+168) then
tmp = t_0
else
tmp = (a1 / b1) * (a2 / b2)
end if
code = tmp
end function
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = a2 * (a1 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+266) {
tmp = t_1;
} else if ((b1 * b2) <= -2e-189) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-150) {
tmp = t_1;
} else if ((b1 * b2) <= 5e+168) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = a2 * (a1 / (b1 * b2)) t_1 = (a2 / b1) * (a1 / b2) tmp = 0 if (b1 * b2) <= -1e+266: tmp = t_1 elif (b1 * b2) <= -2e-189: tmp = t_0 elif (b1 * b2) <= 5e-150: tmp = t_1 elif (b1 * b2) <= 5e+168: tmp = t_0 else: tmp = (a1 / b1) * (a2 / b2) return tmp
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(a2 * Float64(a1 / Float64(b1 * b2))) t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2)) tmp = 0.0 if (Float64(b1 * b2) <= -1e+266) tmp = t_1; elseif (Float64(b1 * b2) <= -2e-189) tmp = t_0; elseif (Float64(b1 * b2) <= 5e-150) tmp = t_1; elseif (Float64(b1 * b2) <= 5e+168) tmp = t_0; else tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); end return tmp end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = a2 * (a1 / (b1 * b2));
t_1 = (a2 / b1) * (a1 / b2);
tmp = 0.0;
if ((b1 * b2) <= -1e+266)
tmp = t_1;
elseif ((b1 * b2) <= -2e-189)
tmp = t_0;
elseif ((b1 * b2) <= 5e-150)
tmp = t_1;
elseif ((b1 * b2) <= 5e+168)
tmp = t_0;
else
tmp = (a1 / b1) * (a2 / b2);
end
tmp_2 = tmp;
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -1e+266], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-189], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-150], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e+168], t$95$0, N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+266}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-189}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-150}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{+168}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -1e266 or -2.00000000000000014e-189 < (*.f64 b1 b2) < 4.9999999999999999e-150Initial program 70.2%
*-commutative70.2%
times-frac93.1%
Applied egg-rr93.1%
if -1e266 < (*.f64 b1 b2) < -2.00000000000000014e-189 or 4.9999999999999999e-150 < (*.f64 b1 b2) < 4.99999999999999967e168Initial program 92.4%
associate-*l/92.8%
*-commutative92.8%
Simplified92.8%
if 4.99999999999999967e168 < (*.f64 b1 b2) Initial program 77.4%
times-frac95.0%
Simplified95.0%
Final simplification93.2%
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (* a1 (/ a2 (* b1 b2)))) (t_1 (* (/ a2 b1) (/ a1 b2))))
(if (<= (* b1 b2) (- INFINITY))
t_1
(if (<= (* b1 b2) -2e-199)
t_0
(if (<= (* b1 b2) 5e-222)
t_1
(if (<= (* b1 b2) 2e+149) t_0 (* (/ a1 b1) (/ a2 b2))))))))assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = a1 * (a2 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -((double) INFINITY)) {
tmp = t_1;
} else if ((b1 * b2) <= -2e-199) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-222) {
tmp = t_1;
} else if ((b1 * b2) <= 2e+149) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = a1 * (a2 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if ((b1 * b2) <= -2e-199) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-222) {
tmp = t_1;
} else if ((b1 * b2) <= 2e+149) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = a1 * (a2 / (b1 * b2)) t_1 = (a2 / b1) * (a1 / b2) tmp = 0 if (b1 * b2) <= -math.inf: tmp = t_1 elif (b1 * b2) <= -2e-199: tmp = t_0 elif (b1 * b2) <= 5e-222: tmp = t_1 elif (b1 * b2) <= 2e+149: tmp = t_0 else: tmp = (a1 / b1) * (a2 / b2) return tmp
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(a1 * Float64(a2 / Float64(b1 * b2))) t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2)) tmp = 0.0 if (Float64(b1 * b2) <= Float64(-Inf)) tmp = t_1; elseif (Float64(b1 * b2) <= -2e-199) tmp = t_0; elseif (Float64(b1 * b2) <= 5e-222) tmp = t_1; elseif (Float64(b1 * b2) <= 2e+149) tmp = t_0; else tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); end return tmp end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = a1 * (a2 / (b1 * b2));
t_1 = (a2 / b1) * (a1 / b2);
tmp = 0.0;
if ((b1 * b2) <= -Inf)
tmp = t_1;
elseif ((b1 * b2) <= -2e-199)
tmp = t_0;
elseif ((b1 * b2) <= 5e-222)
tmp = t_1;
elseif ((b1 * b2) <= 2e+149)
tmp = t_0;
else
tmp = (a1 / b1) * (a2 / b2);
end
tmp_2 = tmp;
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a1 * N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], (-Infinity)], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-199], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-222], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+149], t$95$0, N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := a1 \cdot \frac{a2}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-199}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-222}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+149}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -inf.0 or -1.99999999999999996e-199 < (*.f64 b1 b2) < 5.00000000000000008e-222Initial program 68.1%
*-commutative68.1%
times-frac97.0%
Applied egg-rr97.0%
if -inf.0 < (*.f64 b1 b2) < -1.99999999999999996e-199 or 5.00000000000000008e-222 < (*.f64 b1 b2) < 2.0000000000000001e149Initial program 90.1%
*-commutative90.1%
associate-*l/94.8%
*-commutative94.8%
Applied egg-rr94.8%
if 2.0000000000000001e149 < (*.f64 b1 b2) Initial program 78.5%
times-frac92.9%
Simplified92.9%
Final simplification95.1%
NOTE: b1 and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (if (<= b2 3.05e-263) (* a2 (/ a1 (* b1 b2))) (* a1 (/ (/ a2 b2) b1))))
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b2 <= 3.05e-263) {
tmp = a2 * (a1 / (b1 * b2));
} else {
tmp = a1 * ((a2 / b2) / b1);
}
return tmp;
}
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: tmp
if (b2 <= 3.05d-263) then
tmp = a2 * (a1 / (b1 * b2))
else
tmp = a1 * ((a2 / b2) / b1)
end if
code = tmp
end function
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b2 <= 3.05e-263) {
tmp = a2 * (a1 / (b1 * b2));
} else {
tmp = a1 * ((a2 / b2) / b1);
}
return tmp;
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if b2 <= 3.05e-263: tmp = a2 * (a1 / (b1 * b2)) else: tmp = a1 * ((a2 / b2) / b1) return tmp
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (b2 <= 3.05e-263) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); else tmp = Float64(a1 * Float64(Float64(a2 / b2) / b1)); end return tmp end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
tmp = 0.0;
if (b2 <= 3.05e-263)
tmp = a2 * (a1 / (b1 * b2));
else
tmp = a1 * ((a2 / b2) / b1);
end
tmp_2 = tmp;
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := If[LessEqual[b2, 3.05e-263], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a1 * N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;b2 \leq 3.05 \cdot 10^{-263}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\end{array}
\end{array}
if b2 < 3.0499999999999999e-263Initial program 82.9%
associate-*l/83.8%
*-commutative83.8%
Simplified83.8%
if 3.0499999999999999e-263 < b2 Initial program 81.7%
associate-*r/81.7%
associate-/l/82.8%
Simplified82.8%
Final simplification83.4%
NOTE: b1 and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (* a1 (/ (/ a2 b2) b1)))
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return a1 * ((a2 / b2) / b1);
}
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = a1 * ((a2 / b2) / b1)
end function
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return a1 * ((a2 / b2) / b1);
}
[b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): return a1 * ((a2 / b2) / b1)
b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) return Float64(a1 * Float64(Float64(a2 / b2) / b1)) end
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = a1 * ((a2 / b2) / b1);
end
NOTE: b1 and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := N[(a1 * N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
a1 \cdot \frac{\frac{a2}{b2}}{b1}
\end{array}
Initial program 82.4%
associate-*r/85.8%
associate-/l/86.2%
Simplified86.2%
Final simplification86.2%
(FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a1 b1) (/ a2 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 / b1) * (a2 / b2);
}
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 / b1) * (a2 / b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 / b1) * (a2 / b2);
}
def code(a1, a2, b1, b2): return (a1 / b1) * (a2 / b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 / b1) * Float64(a2 / b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 / b1) * (a2 / b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1}{b1} \cdot \frac{a2}{b2}
\end{array}
herbie shell --seed 2023301
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))