
(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
(if (or (<= (* b1 b2) -1e+293)
(and (not (<= (* b1 b2) -1e-209))
(or (<= (* b1 b2) 1.5e-109) (not (<= (* b1 b2) 5e+203)))))
(* (/ a1 b1) (/ a2 b2))
(* a1 (/ a2 (* b1 b2)))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -1e+293) || (!((b1 * b2) <= -1e-209) && (((b1 * b2) <= 1.5e-109) || !((b1 * b2) <= 5e+203)))) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a1 * (a2 / (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+293)) .or. (.not. ((b1 * b2) <= (-1d-209))) .and. ((b1 * b2) <= 1.5d-109) .or. (.not. ((b1 * b2) <= 5d+203))) then
tmp = (a1 / b1) * (a2 / b2)
else
tmp = a1 * (a2 / (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+293) || (!((b1 * b2) <= -1e-209) && (((b1 * b2) <= 1.5e-109) || !((b1 * b2) <= 5e+203)))) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a1 * (a2 / (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+293) or (not ((b1 * b2) <= -1e-209) and (((b1 * b2) <= 1.5e-109) or not ((b1 * b2) <= 5e+203))): tmp = (a1 / b1) * (a2 / b2) else: tmp = a1 * (a2 / (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+293) || (!(Float64(b1 * b2) <= -1e-209) && ((Float64(b1 * b2) <= 1.5e-109) || !(Float64(b1 * b2) <= 5e+203)))) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); else tmp = Float64(a1 * Float64(a2 / 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+293) || (~(((b1 * b2) <= -1e-209)) && (((b1 * b2) <= 1.5e-109) || ~(((b1 * b2) <= 5e+203)))))
tmp = (a1 / b1) * (a2 / b2);
else
tmp = a1 * (a2 / (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+293], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], -1e-209]], $MachinePrecision], Or[LessEqual[N[(b1 * b2), $MachinePrecision], 1.5e-109], N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 5e+203]], $MachinePrecision]]]], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], N[(a1 * N[(a2 / 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^{+293} \lor \neg \left(b1 \cdot b2 \leq -1 \cdot 10^{-209}\right) \land \left(b1 \cdot b2 \leq 1.5 \cdot 10^{-109} \lor \neg \left(b1 \cdot b2 \leq 5 \cdot 10^{+203}\right)\right):\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -9.9999999999999992e292 or -1e-209 < (*.f64 b1 b2) < 1.50000000000000011e-109 or 4.99999999999999994e203 < (*.f64 b1 b2) Initial program 74.7%
times-frac93.4%
Simplified93.4%
if -9.9999999999999992e292 < (*.f64 b1 b2) < -1e-209 or 1.50000000000000011e-109 < (*.f64 b1 b2) < 4.99999999999999994e203Initial program 93.7%
associate-/l*95.6%
*-commutative95.6%
associate-/l*85.2%
Simplified85.2%
clear-num84.4%
associate-/r/85.2%
clear-num85.2%
associate-/l/95.4%
*-commutative95.4%
Applied egg-rr95.4%
Final simplification94.6%
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 -5e-264)
t_0
(if (<= t_0 2e-301)
(/ (* a2 (/ a1 b1)) b2)
(if (<= t_0 1e+302) t_0 (/ (/ a2 b2) (/ b1 a1)))))))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 <= -5e-264) {
tmp = t_0;
} else if (t_0 <= 2e-301) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 1e+302) {
tmp = t_0;
} else {
tmp = (a2 / b2) / (b1 / a1);
}
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 <= (-5d-264)) then
tmp = t_0
else if (t_0 <= 2d-301) then
tmp = (a2 * (a1 / b1)) / b2
else if (t_0 <= 1d+302) then
tmp = t_0
else
tmp = (a2 / b2) / (b1 / a1)
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 <= -5e-264) {
tmp = t_0;
} else if (t_0 <= 2e-301) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 1e+302) {
tmp = t_0;
} else {
tmp = (a2 / b2) / (b1 / a1);
}
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 <= -5e-264: tmp = t_0 elif t_0 <= 2e-301: tmp = (a2 * (a1 / b1)) / b2 elif t_0 <= 1e+302: tmp = t_0 else: tmp = (a2 / b2) / (b1 / a1) 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 <= -5e-264) tmp = t_0; elseif (t_0 <= 2e-301) tmp = Float64(Float64(a2 * Float64(a1 / b1)) / b2); elseif (t_0 <= 1e+302) tmp = t_0; else tmp = Float64(Float64(a2 / b2) / Float64(b1 / a1)); 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 <= -5e-264)
tmp = t_0;
elseif (t_0 <= 2e-301)
tmp = (a2 * (a1 / b1)) / b2;
elseif (t_0 <= 1e+302)
tmp = t_0;
else
tmp = (a2 / b2) / (b1 / a1);
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, -5e-264], t$95$0, If[LessEqual[t$95$0, 2e-301], N[(N[(a2 * N[(a1 / b1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[t$95$0, 1e+302], t$95$0, N[(N[(a2 / b2), $MachinePrecision] / N[(b1 / a1), $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 -5 \cdot 10^{-264}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-301}:\\
\;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+302}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -5.0000000000000001e-264 or 2.00000000000000013e-301 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e302Initial program 95.8%
if -5.0000000000000001e-264 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.00000000000000013e-301Initial program 83.1%
times-frac93.0%
Simplified93.0%
associate-*r/95.7%
Applied egg-rr95.7%
if 1.0000000000000001e302 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 59.8%
times-frac97.7%
Simplified97.7%
*-commutative97.7%
clear-num97.6%
un-div-inv97.8%
Applied egg-rr97.8%
Final simplification96.1%
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 -5e-264)
t_0
(if (<= t_0 2e-301)
(/ (* a2 (/ a1 b1)) b2)
(if (<= t_0 1e+302) t_0 (* (/ a1 b1) (/ a2 b2)))))))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 <= -5e-264) {
tmp = t_0;
} else if (t_0 <= 2e-301) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 1e+302) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / 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) :: t_0
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
if (t_0 <= (-5d-264)) then
tmp = t_0
else if (t_0 <= 2d-301) then
tmp = (a2 * (a1 / b1)) / b2
else if (t_0 <= 1d+302) then
tmp = t_0
else
tmp = (a1 / b1) * (a2 / 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 t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -5e-264) {
tmp = t_0;
} else if (t_0 <= 2e-301) {
tmp = (a2 * (a1 / b1)) / b2;
} else if (t_0 <= 1e+302) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / b2);
}
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 <= -5e-264: tmp = t_0 elif t_0 <= 2e-301: tmp = (a2 * (a1 / b1)) / b2 elif t_0 <= 1e+302: tmp = t_0 else: tmp = (a1 / b1) * (a2 / b2) 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 <= -5e-264) tmp = t_0; elseif (t_0 <= 2e-301) tmp = Float64(Float64(a2 * Float64(a1 / b1)) / b2); elseif (t_0 <= 1e+302) tmp = t_0; else tmp = Float64(Float64(a1 / b1) * Float64(a2 / 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)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= -5e-264)
tmp = t_0;
elseif (t_0 <= 2e-301)
tmp = (a2 * (a1 / b1)) / b2;
elseif (t_0 <= 1e+302)
tmp = t_0;
else
tmp = (a1 / b1) * (a2 / 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_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-264], t$95$0, If[LessEqual[t$95$0, 2e-301], N[(N[(a2 * N[(a1 / b1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[t$95$0, 1e+302], t$95$0, N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $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 -5 \cdot 10^{-264}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-301}:\\
\;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+302}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -5.0000000000000001e-264 or 2.00000000000000013e-301 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e302Initial program 95.8%
if -5.0000000000000001e-264 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.00000000000000013e-301Initial program 83.1%
times-frac93.0%
Simplified93.0%
associate-*r/95.7%
Applied egg-rr95.7%
if 1.0000000000000001e302 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 59.8%
times-frac97.7%
Simplified97.7%
Final simplification96.1%
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+293)
(not
(or (<= (* b1 b2) -1e-110)
(and (not (<= (* b1 b2) 1.5e-109)) (<= (* b1 b2) 1e+99)))))
(* (/ a1 b1) (/ a2 b2))
(* 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+293) || !(((b1 * b2) <= -1e-110) || (!((b1 * b2) <= 1.5e-109) && ((b1 * b2) <= 1e+99)))) {
tmp = (a1 / b1) * (a2 / b2);
} 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+293)) .or. (.not. ((b1 * b2) <= (-1d-110)) .or. (.not. ((b1 * b2) <= 1.5d-109)) .and. ((b1 * b2) <= 1d+99))) then
tmp = (a1 / b1) * (a2 / b2)
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+293) || !(((b1 * b2) <= -1e-110) || (!((b1 * b2) <= 1.5e-109) && ((b1 * b2) <= 1e+99)))) {
tmp = (a1 / b1) * (a2 / b2);
} 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+293) or not (((b1 * b2) <= -1e-110) or (not ((b1 * b2) <= 1.5e-109) and ((b1 * b2) <= 1e+99))): tmp = (a1 / b1) * (a2 / b2) 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+293) || !((Float64(b1 * b2) <= -1e-110) || (!(Float64(b1 * b2) <= 1.5e-109) && (Float64(b1 * b2) <= 1e+99)))) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); 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+293) || ~((((b1 * b2) <= -1e-110) || (~(((b1 * b2) <= 1.5e-109)) && ((b1 * b2) <= 1e+99)))))
tmp = (a1 / b1) * (a2 / b2);
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+293], N[Not[Or[LessEqual[N[(b1 * b2), $MachinePrecision], -1e-110], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 1.5e-109]], $MachinePrecision], LessEqual[N[(b1 * b2), $MachinePrecision], 1e+99]]]], $MachinePrecision]], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $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^{+293} \lor \neg \left(b1 \cdot b2 \leq -1 \cdot 10^{-110} \lor \neg \left(b1 \cdot b2 \leq 1.5 \cdot 10^{-109}\right) \land b1 \cdot b2 \leq 10^{+99}\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) < -9.9999999999999992e292 or -1.0000000000000001e-110 < (*.f64 b1 b2) < 1.50000000000000011e-109 or 9.9999999999999997e98 < (*.f64 b1 b2) Initial program 79.7%
times-frac90.3%
Simplified90.3%
if -9.9999999999999992e292 < (*.f64 b1 b2) < -1.0000000000000001e-110 or 1.50000000000000011e-109 < (*.f64 b1 b2) < 9.9999999999999997e98Initial program 93.5%
associate-/l*95.9%
*-commutative95.9%
associate-/l*86.1%
Simplified86.1%
associate-/l*95.9%
*-commutative95.9%
associate-/r/95.6%
Applied egg-rr95.6%
Final simplification92.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 (* (/ a1 b1) (/ a2 b2)))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return (a1 / b1) * (a2 / b2);
}
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 = (a1 / b1) * (a2 / b2)
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return (a1 / b1) * (a2 / b2);
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): return (a1 / b1) * (a2 / b2)
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) return Float64(Float64(a1 / b1) * Float64(a2 / b2)) end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = (a1 / b1) * (a2 / b2);
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[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\frac{a1}{b1} \cdot \frac{a2}{b2}
\end{array}
Initial program 86.0%
times-frac84.0%
Simplified84.0%
Final simplification84.0%
(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 2023175
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))