
(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 5 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: a1 and a2 should be sorted in increasing order before calling this function.
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))))
(if (<= t_0 -1e+247)
(/ (/ a2 b2) (/ b1 a1))
(if (<= t_0 -5e-322)
t_0
(if (<= t_0 5e-260)
(/ (* a2 (/ a1 b1)) b2)
(if (<= t_0 4e+290) t_0 (* (/ a2 b2) (/ a1 b1))))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -1e+247) {
tmp = (a2 / b2) / (b1 / a1);
} else if (t_0 <= -5e-322) {
tmp = t_0;
} else if (t_0 <= 5e-260) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 4e+290) {
tmp = t_0;
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
if (t_0 <= (-1d+247)) then
tmp = (a2 / b2) / (b1 / a1)
else if (t_0 <= (-5d-322)) then
tmp = t_0
else if (t_0 <= 5d-260) then
tmp = (a2 * (a1 / b1)) / b2
else if (t_0 <= 4d+290) then
tmp = t_0
else
tmp = (a2 / b2) * (a1 / b1)
end if
code = tmp
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -1e+247) {
tmp = (a2 / b2) / (b1 / a1);
} else if (t_0 <= -5e-322) {
tmp = t_0;
} else if (t_0 <= 5e-260) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 4e+290) {
tmp = t_0;
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) tmp = 0 if t_0 <= -1e+247: tmp = (a2 / b2) / (b1 / a1) elif t_0 <= -5e-322: tmp = t_0 elif t_0 <= 5e-260: tmp = (a2 * (a1 / b1)) / b2 elif t_0 <= 4e+290: tmp = t_0 else: tmp = (a2 / b2) * (a1 / b1) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_0 <= -1e+247) tmp = Float64(Float64(a2 / b2) / Float64(b1 / a1)); elseif (t_0 <= -5e-322) tmp = t_0; elseif (t_0 <= 5e-260) tmp = Float64(Float64(a2 * Float64(a1 / b1)) / b2); elseif (t_0 <= 4e+290) tmp = t_0; else tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); end return tmp end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= -1e+247)
tmp = (a2 / b2) / (b1 / a1);
elseif (t_0 <= -5e-322)
tmp = t_0;
elseif (t_0 <= 5e-260)
tmp = (a2 * (a1 / b1)) / b2;
elseif (t_0 <= 4e+290)
tmp = t_0;
else
tmp = (a2 / b2) * (a1 / b1);
end
tmp_2 = tmp;
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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]}, If[LessEqual[t$95$0, -1e+247], N[(N[(a2 / b2), $MachinePrecision] / N[(b1 / a1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e-322], t$95$0, If[LessEqual[t$95$0, 5e-260], N[(N[(a2 * N[(a1 / b1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[t$95$0, 4e+290], t$95$0, N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+247}:\\
\;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-322}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-260}:\\
\;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+290}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -9.99999999999999952e246Initial program 78.6%
times-frac97.2%
Simplified97.2%
*-commutative97.2%
clear-num97.1%
un-div-inv97.2%
Applied egg-rr97.2%
if -9.99999999999999952e246 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99006e-322 or 5.0000000000000003e-260 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.00000000000000025e290Initial program 99.5%
if -4.99006e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 5.0000000000000003e-260Initial program 70.5%
times-frac93.1%
Simplified93.1%
associate-*r/83.2%
Applied egg-rr83.2%
if 4.00000000000000025e290 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 69.3%
times-frac97.8%
Simplified97.8%
Final simplification94.7%
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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))))
(if (<= t_0 (- INFINITY))
(/ a1 (/ b2 (/ a2 b1)))
(if (or (<= t_0 -5e-322) (and (not (<= t_0 0.0)) (<= t_0 4e+290)))
t_0
(* (/ a2 b2) (/ a1 b1))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = a1 / (b2 / (a2 / b1));
} else if ((t_0 <= -5e-322) || (!(t_0 <= 0.0) && (t_0 <= 4e+290))) {
tmp = t_0;
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = a1 / (b2 / (a2 / b1));
} else if ((t_0 <= -5e-322) || (!(t_0 <= 0.0) && (t_0 <= 4e+290))) {
tmp = t_0;
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) tmp = 0 if t_0 <= -math.inf: tmp = a1 / (b2 / (a2 / b1)) elif (t_0 <= -5e-322) or (not (t_0 <= 0.0) and (t_0 <= 4e+290)): tmp = t_0 else: tmp = (a2 / b2) * (a1 / b1) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(a1 / Float64(b2 / Float64(a2 / b1))); elseif ((t_0 <= -5e-322) || (!(t_0 <= 0.0) && (t_0 <= 4e+290))) tmp = t_0; else tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); end return tmp end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= -Inf)
tmp = a1 / (b2 / (a2 / b1));
elseif ((t_0 <= -5e-322) || (~((t_0 <= 0.0)) && (t_0 <= 4e+290)))
tmp = t_0;
else
tmp = (a2 / b2) * (a1 / b1);
end
tmp_2 = tmp;
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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]}, If[LessEqual[t$95$0, (-Infinity)], N[(a1 / N[(b2 / N[(a2 / b1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$0, -5e-322], And[N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision], LessEqual[t$95$0, 4e+290]]], t$95$0, N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-322} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 4 \cdot 10^{+290}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0Initial program 77.3%
associate-/l*91.3%
*-commutative91.3%
associate-/l*94.2%
Simplified94.2%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99006e-322 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.00000000000000025e290Initial program 99.0%
if -4.99006e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0 or 4.00000000000000025e290 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 69.1%
times-frac96.3%
Simplified96.3%
Final simplification97.3%
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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))))
(if (<= t_0 (- INFINITY))
(/ a1 (/ b2 (/ a2 b1)))
(if (<= t_0 -5e-322)
t_0
(if (<= t_0 5e-260)
(/ (* a2 (/ a1 b1)) b2)
(if (<= t_0 4e+290) t_0 (* (/ a2 b2) (/ a1 b1))))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = a1 / (b2 / (a2 / b1));
} else if (t_0 <= -5e-322) {
tmp = t_0;
} else if (t_0 <= 5e-260) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 4e+290) {
tmp = t_0;
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = a1 / (b2 / (a2 / b1));
} else if (t_0 <= -5e-322) {
tmp = t_0;
} else if (t_0 <= 5e-260) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 4e+290) {
tmp = t_0;
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) tmp = 0 if t_0 <= -math.inf: tmp = a1 / (b2 / (a2 / b1)) elif t_0 <= -5e-322: tmp = t_0 elif t_0 <= 5e-260: tmp = (a2 * (a1 / b1)) / b2 elif t_0 <= 4e+290: tmp = t_0 else: tmp = (a2 / b2) * (a1 / b1) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(a1 / Float64(b2 / Float64(a2 / b1))); elseif (t_0 <= -5e-322) tmp = t_0; elseif (t_0 <= 5e-260) tmp = Float64(Float64(a2 * Float64(a1 / b1)) / b2); elseif (t_0 <= 4e+290) tmp = t_0; else tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); end return tmp end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= -Inf)
tmp = a1 / (b2 / (a2 / b1));
elseif (t_0 <= -5e-322)
tmp = t_0;
elseif (t_0 <= 5e-260)
tmp = (a2 * (a1 / b1)) / b2;
elseif (t_0 <= 4e+290)
tmp = t_0;
else
tmp = (a2 / b2) * (a1 / b1);
end
tmp_2 = tmp;
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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]}, If[LessEqual[t$95$0, (-Infinity)], N[(a1 / N[(b2 / N[(a2 / b1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e-322], t$95$0, If[LessEqual[t$95$0, 5e-260], N[(N[(a2 * N[(a1 / b1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[t$95$0, 4e+290], t$95$0, N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-322}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{-260}:\\
\;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+290}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0Initial program 77.3%
associate-/l*91.3%
*-commutative91.3%
associate-/l*94.2%
Simplified94.2%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99006e-322 or 5.0000000000000003e-260 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.00000000000000025e290Initial program 99.5%
if -4.99006e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 5.0000000000000003e-260Initial program 70.5%
times-frac93.1%
Simplified93.1%
associate-*r/83.2%
Applied egg-rr83.2%
if 4.00000000000000025e290 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 69.3%
times-frac97.8%
Simplified97.8%
Final simplification94.3%
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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) -1e+246)
(not
(or (<= (* b1 b2) -2e-241)
(and (not (<= (* b1 b2) 0.0)) (<= (* b1 b2) 6e+218)))))
(* (/ a2 b2) (/ a1 b1))
(* a2 (/ a1 (* b1 b2)))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -1e+246) || !(((b1 * b2) <= -2e-241) || (!((b1 * b2) <= 0.0) && ((b1 * b2) <= 6e+218)))) {
tmp = (a2 / b2) * (a1 / b1);
} else {
tmp = a2 * (a1 / (b1 * b2));
}
return tmp;
}
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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) <= (-1d+246)) .or. (.not. ((b1 * b2) <= (-2d-241)) .or. (.not. ((b1 * b2) <= 0.0d0)) .and. ((b1 * b2) <= 6d+218))) then
tmp = (a2 / b2) * (a1 / b1)
else
tmp = a2 * (a1 / (b1 * b2))
end if
code = tmp
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -1e+246) || !(((b1 * b2) <= -2e-241) || (!((b1 * b2) <= 0.0) && ((b1 * b2) <= 6e+218)))) {
tmp = (a2 / b2) * (a1 / b1);
} else {
tmp = a2 * (a1 / (b1 * b2));
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if ((b1 * b2) <= -1e+246) or not (((b1 * b2) <= -2e-241) or (not ((b1 * b2) <= 0.0) and ((b1 * b2) <= 6e+218))): tmp = (a2 / b2) * (a1 / b1) else: tmp = a2 * (a1 / (b1 * b2)) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if ((Float64(b1 * b2) <= -1e+246) || !((Float64(b1 * b2) <= -2e-241) || (!(Float64(b1 * b2) <= 0.0) && (Float64(b1 * b2) <= 6e+218)))) tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); else tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); end return tmp end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
tmp = 0.0;
if (((b1 * b2) <= -1e+246) || ~((((b1 * b2) <= -2e-241) || (~(((b1 * b2) <= 0.0)) && ((b1 * b2) <= 6e+218)))))
tmp = (a2 / b2) * (a1 / b1);
else
tmp = a2 * (a1 / (b1 * b2));
end
tmp_2 = tmp;
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function. 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], -1e+246], N[Not[Or[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-241], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 0.0]], $MachinePrecision], LessEqual[N[(b1 * b2), $MachinePrecision], 6e+218]]]], $MachinePrecision]], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+246} \lor \neg \left(b1 \cdot b2 \leq -2 \cdot 10^{-241} \lor \neg \left(b1 \cdot b2 \leq 0\right) \land b1 \cdot b2 \leq 6 \cdot 10^{+218}\right):\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\mathbf{else}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -1.00000000000000007e246 or -1.9999999999999999e-241 < (*.f64 b1 b2) < -0.0 or 6.0000000000000001e218 < (*.f64 b1 b2) Initial program 72.2%
times-frac95.5%
Simplified95.5%
if -1.00000000000000007e246 < (*.f64 b1 b2) < -1.9999999999999999e-241 or -0.0 < (*.f64 b1 b2) < 6.0000000000000001e218Initial program 90.3%
associate-/l*92.3%
*-commutative92.3%
associate-/l*86.4%
Simplified86.4%
associate-/l*92.3%
*-commutative92.3%
associate-/r/95.1%
Applied egg-rr95.1%
Final simplification95.2%
NOTE: a1 and a2 should be sorted in increasing order before calling this function. NOTE: b1 and b2 should be sorted in increasing order before calling this function. (FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a2 b2) (/ a1 b1)))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return (a2 / b2) * (a1 / b1);
}
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
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 = (a2 / b2) * (a1 / b1)
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return (a2 / b2) * (a1 / b1);
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): return (a2 / b2) * (a1 / b1)
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) return Float64(Float64(a2 / b2) * Float64(a1 / b1)) end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = (a2 / b2) * (a1 / b1);
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function. NOTE: b1 and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\frac{a2}{b2} \cdot \frac{a1}{b1}
\end{array}
Initial program 84.0%
times-frac82.1%
Simplified82.1%
Final simplification82.1%
(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 2023171
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))