
(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: 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))) (t_1 (/ (/ a2 b2) (/ b1 a1))))
(if (<= t_0 -1e+276)
t_1
(if (<= t_0 -5e-58)
t_0
(if (<= t_0 0.0)
(* (/ a2 b1) (/ a1 b2))
(if (<= t_0 4e+292) t_0 t_1))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a2 / b2) / (b1 / a1);
double tmp;
if (t_0 <= -1e+276) {
tmp = t_1;
} else if (t_0 <= -5e-58) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if (t_0 <= 4e+292) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
t_1 = (a2 / b2) / (b1 / a1)
if (t_0 <= (-1d+276)) then
tmp = t_1
else if (t_0 <= (-5d-58)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = (a2 / b1) * (a1 / b2)
else if (t_0 <= 4d+292) then
tmp = t_0
else
tmp = t_1
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 t_1 = (a2 / b2) / (b1 / a1);
double tmp;
if (t_0 <= -1e+276) {
tmp = t_1;
} else if (t_0 <= -5e-58) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if (t_0 <= 4e+292) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) t_1 = (a2 / b2) / (b1 / a1) tmp = 0 if t_0 <= -1e+276: tmp = t_1 elif t_0 <= -5e-58: tmp = t_0 elif t_0 <= 0.0: tmp = (a2 / b1) * (a1 / b2) elif t_0 <= 4e+292: tmp = t_0 else: tmp = t_1 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)) t_1 = Float64(Float64(a2 / b2) / Float64(b1 / a1)) tmp = 0.0 if (t_0 <= -1e+276) tmp = t_1; elseif (t_0 <= -5e-58) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); elseif (t_0 <= 4e+292) tmp = t_0; else tmp = t_1; 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);
t_1 = (a2 / b2) / (b1 / a1);
tmp = 0.0;
if (t_0 <= -1e+276)
tmp = t_1;
elseif (t_0 <= -5e-58)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a2 / b1) * (a1 / b2);
elseif (t_0 <= 4e+292)
tmp = t_0;
else
tmp = t_1;
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]}, Block[{t$95$1 = N[(N[(a2 / b2), $MachinePrecision] / N[(b1 / a1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+276], t$95$1, If[LessEqual[t$95$0, -5e-58], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+292], t$95$0, t$95$1]]]]]]
\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}\\
t_1 := \frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+276}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-58}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+292}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.0000000000000001e276 or 4.0000000000000001e292 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 57.4%
times-frac93.7%
Simplified93.7%
*-commutative93.7%
clear-num93.7%
un-div-inv94.2%
Applied egg-rr94.2%
if -1.0000000000000001e276 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999999999977e-58 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.0000000000000001e292Initial program 98.7%
if -4.99999999999999977e-58 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0Initial program 86.2%
associate-/l*92.5%
*-commutative92.5%
associate-/l*90.4%
Simplified90.4%
associate-/r/91.0%
*-commutative91.0%
Applied egg-rr91.0%
Final simplification94.5%
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))) (t_1 (* (/ a2 b2) (/ a1 b1))))
(if (<= t_0 -1e+276)
t_1
(if (<= t_0 -2e-123)
t_0
(if (<= t_0 0.0)
(* (/ a2 b1) (/ a1 b2))
(if (<= t_0 5e+265) t_0 t_1))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a2 / b2) * (a1 / b1);
double tmp;
if (t_0 <= -1e+276) {
tmp = t_1;
} else if (t_0 <= -2e-123) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if (t_0 <= 5e+265) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
t_1 = (a2 / b2) * (a1 / b1)
if (t_0 <= (-1d+276)) then
tmp = t_1
else if (t_0 <= (-2d-123)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = (a2 / b1) * (a1 / b2)
else if (t_0 <= 5d+265) then
tmp = t_0
else
tmp = t_1
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 t_1 = (a2 / b2) * (a1 / b1);
double tmp;
if (t_0 <= -1e+276) {
tmp = t_1;
} else if (t_0 <= -2e-123) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if (t_0 <= 5e+265) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) t_1 = (a2 / b2) * (a1 / b1) tmp = 0 if t_0 <= -1e+276: tmp = t_1 elif t_0 <= -2e-123: tmp = t_0 elif t_0 <= 0.0: tmp = (a2 / b1) * (a1 / b2) elif t_0 <= 5e+265: tmp = t_0 else: tmp = t_1 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)) t_1 = Float64(Float64(a2 / b2) * Float64(a1 / b1)) tmp = 0.0 if (t_0 <= -1e+276) tmp = t_1; elseif (t_0 <= -2e-123) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); elseif (t_0 <= 5e+265) tmp = t_0; else tmp = t_1; 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);
t_1 = (a2 / b2) * (a1 / b1);
tmp = 0.0;
if (t_0 <= -1e+276)
tmp = t_1;
elseif (t_0 <= -2e-123)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a2 / b1) * (a1 / b2);
elseif (t_0 <= 5e+265)
tmp = t_0;
else
tmp = t_1;
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]}, Block[{t$95$1 = N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+276], t$95$1, If[LessEqual[t$95$0, -2e-123], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+265], t$95$0, t$95$1]]]]]]
\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}\\
t_1 := \frac{a2}{b2} \cdot \frac{a1}{b1}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+276}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-123}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+265}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.0000000000000001e276 or 5.0000000000000002e265 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 57.9%
times-frac92.6%
Simplified92.6%
if -1.0000000000000001e276 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-123 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 5.0000000000000002e265Initial program 98.7%
if -2.0000000000000001e-123 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0Initial program 84.9%
associate-/l*91.9%
*-commutative91.9%
associate-/l*90.7%
Simplified90.7%
associate-/r/91.3%
*-commutative91.3%
Applied egg-rr91.3%
Final simplification94.4%
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) -5e+207)
(and (not (<= (* b1 b2) -5e-172))
(or (<= (* b1 b2) 5e-132) (not (<= (* b1 b2) 2e+158)))))
(* (/ 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) <= -5e+207) || (!((b1 * b2) <= -5e-172) && (((b1 * b2) <= 5e-132) || !((b1 * b2) <= 2e+158)))) {
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) <= (-5d+207)) .or. (.not. ((b1 * b2) <= (-5d-172))) .and. ((b1 * b2) <= 5d-132) .or. (.not. ((b1 * b2) <= 2d+158))) 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) <= -5e+207) || (!((b1 * b2) <= -5e-172) && (((b1 * b2) <= 5e-132) || !((b1 * b2) <= 2e+158)))) {
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) <= -5e+207) or (not ((b1 * b2) <= -5e-172) and (((b1 * b2) <= 5e-132) or not ((b1 * b2) <= 2e+158))): 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) <= -5e+207) || (!(Float64(b1 * b2) <= -5e-172) && ((Float64(b1 * b2) <= 5e-132) || !(Float64(b1 * b2) <= 2e+158)))) 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) <= -5e+207) || (~(((b1 * b2) <= -5e-172)) && (((b1 * b2) <= 5e-132) || ~(((b1 * b2) <= 2e+158)))))
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], -5e+207], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], -5e-172]], $MachinePrecision], Or[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-132], N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+158]], $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 -5 \cdot 10^{+207} \lor \neg \left(b1 \cdot b2 \leq -5 \cdot 10^{-172}\right) \land \left(b1 \cdot b2 \leq 5 \cdot 10^{-132} \lor \neg \left(b1 \cdot b2 \leq 2 \cdot 10^{+158}\right)\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) < -4.9999999999999999e207 or -4.9999999999999999e-172 < (*.f64 b1 b2) < 4.9999999999999999e-132 or 1.99999999999999991e158 < (*.f64 b1 b2) Initial program 73.5%
times-frac92.0%
Simplified92.0%
if -4.9999999999999999e207 < (*.f64 b1 b2) < -4.9999999999999999e-172 or 4.9999999999999999e-132 < (*.f64 b1 b2) < 1.99999999999999991e158Initial program 90.2%
associate-/l*94.8%
*-commutative94.8%
associate-/l*82.6%
Simplified82.6%
associate-/l*94.8%
*-commutative94.8%
associate-/r/94.2%
Applied egg-rr94.2%
Final simplification93.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 (<= (* b1 b2) -5e+139)
(* (/ a2 b1) (/ a1 b2))
(if (or (<= (* b1 b2) -5e-172)
(and (not (<= (* b1 b2) 5e-132)) (<= (* b1 b2) 2e+158)))
(* a2 (/ a1 (* b1 b2)))
(* (/ a2 b2) (/ a1 b1)))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if ((b1 * b2) <= -5e+139) {
tmp = (a2 / b1) * (a1 / b2);
} else if (((b1 * b2) <= -5e-172) || (!((b1 * b2) <= 5e-132) && ((b1 * b2) <= 2e+158))) {
tmp = a2 * (a1 / (b1 * b2));
} 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) :: tmp
if ((b1 * b2) <= (-5d+139)) then
tmp = (a2 / b1) * (a1 / b2)
else if (((b1 * b2) <= (-5d-172)) .or. (.not. ((b1 * b2) <= 5d-132)) .and. ((b1 * b2) <= 2d+158)) then
tmp = a2 * (a1 / (b1 * b2))
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 tmp;
if ((b1 * b2) <= -5e+139) {
tmp = (a2 / b1) * (a1 / b2);
} else if (((b1 * b2) <= -5e-172) || (!((b1 * b2) <= 5e-132) && ((b1 * b2) <= 2e+158))) {
tmp = a2 * (a1 / (b1 * b2));
} else {
tmp = (a2 / b2) * (a1 / b1);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if (b1 * b2) <= -5e+139: tmp = (a2 / b1) * (a1 / b2) elif ((b1 * b2) <= -5e-172) or (not ((b1 * b2) <= 5e-132) and ((b1 * b2) <= 2e+158)): tmp = a2 * (a1 / (b1 * b2)) else: tmp = (a2 / b2) * (a1 / b1) 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) <= -5e+139) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); elseif ((Float64(b1 * b2) <= -5e-172) || (!(Float64(b1 * b2) <= 5e-132) && (Float64(b1 * b2) <= 2e+158))) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); 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)
tmp = 0.0;
if ((b1 * b2) <= -5e+139)
tmp = (a2 / b1) * (a1 / b2);
elseif (((b1 * b2) <= -5e-172) || (~(((b1 * b2) <= 5e-132)) && ((b1 * b2) <= 2e+158)))
tmp = a2 * (a1 / (b1 * b2));
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_] := If[LessEqual[N[(b1 * b2), $MachinePrecision], -5e+139], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(b1 * b2), $MachinePrecision], -5e-172], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-132]], $MachinePrecision], LessEqual[N[(b1 * b2), $MachinePrecision], 2e+158]]], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;b1 \cdot b2 \leq -5 \cdot 10^{+139}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq -5 \cdot 10^{-172} \lor \neg \left(b1 \cdot b2 \leq 5 \cdot 10^{-132}\right) \land b1 \cdot b2 \leq 2 \cdot 10^{+158}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -5.0000000000000003e139Initial program 75.8%
associate-/l*71.9%
*-commutative71.9%
associate-/l*84.3%
Simplified84.3%
associate-/r/87.2%
*-commutative87.2%
Applied egg-rr87.2%
if -5.0000000000000003e139 < (*.f64 b1 b2) < -4.9999999999999999e-172 or 4.9999999999999999e-132 < (*.f64 b1 b2) < 1.99999999999999991e158Initial program 91.1%
associate-/l*95.2%
*-commutative95.2%
associate-/l*82.9%
Simplified82.9%
associate-/l*95.2%
*-commutative95.2%
associate-/r/96.2%
Applied egg-rr96.2%
if -4.9999999999999999e-172 < (*.f64 b1 b2) < 4.9999999999999999e-132 or 1.99999999999999991e158 < (*.f64 b1 b2) Initial program 72.9%
times-frac92.5%
Simplified92.5%
Final simplification93.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 (* b2 (/ b1 a2)))))
(if (<= (* b1 b2) -5e+207)
t_0
(if (<= (* b1 b2) -5e-201)
(* a2 (/ a1 (* b1 b2)))
(if (<= (* b1 b2) 1e-249) (* (/ a2 b1) (/ a1 b2)) t_0)))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = a1 / (b2 * (b1 / a2));
double tmp;
if ((b1 * b2) <= -5e+207) {
tmp = t_0;
} else if ((b1 * b2) <= -5e-201) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 1e-249) {
tmp = (a2 / b1) * (a1 / b2);
} else {
tmp = t_0;
}
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 / (b2 * (b1 / a2))
if ((b1 * b2) <= (-5d+207)) then
tmp = t_0
else if ((b1 * b2) <= (-5d-201)) then
tmp = a2 * (a1 / (b1 * b2))
else if ((b1 * b2) <= 1d-249) then
tmp = (a2 / b1) * (a1 / b2)
else
tmp = t_0
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 / (b2 * (b1 / a2));
double tmp;
if ((b1 * b2) <= -5e+207) {
tmp = t_0;
} else if ((b1 * b2) <= -5e-201) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 1e-249) {
tmp = (a2 / b1) * (a1 / b2);
} else {
tmp = t_0;
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = a1 / (b2 * (b1 / a2)) tmp = 0 if (b1 * b2) <= -5e+207: tmp = t_0 elif (b1 * b2) <= -5e-201: tmp = a2 * (a1 / (b1 * b2)) elif (b1 * b2) <= 1e-249: tmp = (a2 / b1) * (a1 / b2) else: tmp = t_0 return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(a1 / Float64(b2 * Float64(b1 / a2))) tmp = 0.0 if (Float64(b1 * b2) <= -5e+207) tmp = t_0; elseif (Float64(b1 * b2) <= -5e-201) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); elseif (Float64(b1 * b2) <= 1e-249) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); else tmp = t_0; 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 / (b2 * (b1 / a2));
tmp = 0.0;
if ((b1 * b2) <= -5e+207)
tmp = t_0;
elseif ((b1 * b2) <= -5e-201)
tmp = a2 * (a1 / (b1 * b2));
elseif ((b1 * b2) <= 1e-249)
tmp = (a2 / b1) * (a1 / b2);
else
tmp = t_0;
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[(a1 / N[(b2 * N[(b1 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -5e+207], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], -5e-201], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 1e-249], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1}{b2 \cdot \frac{b1}{a2}}\\
\mathbf{if}\;b1 \cdot b2 \leq -5 \cdot 10^{+207}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq -5 \cdot 10^{-201}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 10^{-249}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -4.9999999999999999e207 or 1.00000000000000005e-249 < (*.f64 b1 b2) Initial program 86.3%
associate-/l*85.8%
*-commutative85.8%
associate-/l*86.1%
Simplified86.1%
clear-num86.1%
associate-/r/85.8%
clear-num85.8%
Applied egg-rr85.8%
if -4.9999999999999999e207 < (*.f64 b1 b2) < -4.9999999999999999e-201Initial program 87.6%
associate-/l*93.9%
*-commutative93.9%
associate-/l*83.5%
Simplified83.5%
associate-/l*93.9%
*-commutative93.9%
associate-/r/90.6%
Applied egg-rr90.6%
if -4.9999999999999999e-201 < (*.f64 b1 b2) < 1.00000000000000005e-249Initial program 59.7%
associate-/l*64.7%
*-commutative64.7%
associate-/l*86.5%
Simplified86.5%
associate-/r/95.7%
*-commutative95.7%
Applied egg-rr95.7%
Final simplification89.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 (<= (* b1 b2) -5e+207)
(/ a1 (* b2 (/ b1 a2)))
(if (<= (* b1 b2) -5e-201)
(* a2 (/ a1 (* b1 b2)))
(if (<= (* b1 b2) 1e-249)
(* (/ a2 b1) (/ a1 b2))
(/ a1 (/ b2 (/ a2 b1)))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if ((b1 * b2) <= -5e+207) {
tmp = a1 / (b2 * (b1 / a2));
} else if ((b1 * b2) <= -5e-201) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 1e-249) {
tmp = (a2 / b1) * (a1 / b2);
} else {
tmp = a1 / (b2 / (a2 / 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) :: tmp
if ((b1 * b2) <= (-5d+207)) then
tmp = a1 / (b2 * (b1 / a2))
else if ((b1 * b2) <= (-5d-201)) then
tmp = a2 * (a1 / (b1 * b2))
else if ((b1 * b2) <= 1d-249) then
tmp = (a2 / b1) * (a1 / b2)
else
tmp = a1 / (b2 / (a2 / 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 tmp;
if ((b1 * b2) <= -5e+207) {
tmp = a1 / (b2 * (b1 / a2));
} else if ((b1 * b2) <= -5e-201) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 1e-249) {
tmp = (a2 / b1) * (a1 / b2);
} else {
tmp = a1 / (b2 / (a2 / b1));
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if (b1 * b2) <= -5e+207: tmp = a1 / (b2 * (b1 / a2)) elif (b1 * b2) <= -5e-201: tmp = a2 * (a1 / (b1 * b2)) elif (b1 * b2) <= 1e-249: tmp = (a2 / b1) * (a1 / b2) else: tmp = a1 / (b2 / (a2 / b1)) 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) <= -5e+207) tmp = Float64(a1 / Float64(b2 * Float64(b1 / a2))); elseif (Float64(b1 * b2) <= -5e-201) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); elseif (Float64(b1 * b2) <= 1e-249) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); else tmp = Float64(a1 / Float64(b2 / Float64(a2 / 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)
tmp = 0.0;
if ((b1 * b2) <= -5e+207)
tmp = a1 / (b2 * (b1 / a2));
elseif ((b1 * b2) <= -5e-201)
tmp = a2 * (a1 / (b1 * b2));
elseif ((b1 * b2) <= 1e-249)
tmp = (a2 / b1) * (a1 / b2);
else
tmp = a1 / (b2 / (a2 / 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_] := If[LessEqual[N[(b1 * b2), $MachinePrecision], -5e+207], N[(a1 / N[(b2 * N[(b1 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], -5e-201], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 1e-249], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], N[(a1 / N[(b2 / N[(a2 / b1), $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 -5 \cdot 10^{+207}:\\
\;\;\;\;\frac{a1}{b2 \cdot \frac{b1}{a2}}\\
\mathbf{elif}\;b1 \cdot b2 \leq -5 \cdot 10^{-201}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 10^{-249}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -4.9999999999999999e207Initial program 75.0%
associate-/l*67.5%
*-commutative67.5%
associate-/l*85.7%
Simplified85.7%
clear-num85.6%
associate-/r/85.7%
clear-num85.6%
Applied egg-rr85.6%
if -4.9999999999999999e207 < (*.f64 b1 b2) < -4.9999999999999999e-201Initial program 87.6%
associate-/l*93.9%
*-commutative93.9%
associate-/l*83.5%
Simplified83.5%
associate-/l*93.9%
*-commutative93.9%
associate-/r/90.6%
Applied egg-rr90.6%
if -4.9999999999999999e-201 < (*.f64 b1 b2) < 1.00000000000000005e-249Initial program 59.7%
associate-/l*64.7%
*-commutative64.7%
associate-/l*86.5%
Simplified86.5%
associate-/r/95.7%
*-commutative95.7%
Applied egg-rr95.7%
if 1.00000000000000005e-249 < (*.f64 b1 b2) Initial program 90.5%
associate-/l*92.6%
*-commutative92.6%
associate-/l*86.3%
Simplified86.3%
Final simplification89.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 81.8%
times-frac87.6%
Simplified87.6%
Final simplification87.6%
(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 2023189
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))