
(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 6 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 -5e-288)
t_0
(if (<= t_0 2e-303)
(/ (/ a1 (/ b2 a2)) b1)
(if (<= t_0 2e+264) t_0 (* (/ a2 b1) (/ a1 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-288) {
tmp = t_0;
} else if (t_0 <= 2e-303) {
tmp = (a1 / (b2 / a2)) / b1;
} else if (t_0 <= 2e+264) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / 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-288)) then
tmp = t_0
else if (t_0 <= 2d-303) then
tmp = (a1 / (b2 / a2)) / b1
else if (t_0 <= 2d+264) then
tmp = t_0
else
tmp = (a2 / b1) * (a1 / 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-288) {
tmp = t_0;
} else if (t_0 <= 2e-303) {
tmp = (a1 / (b2 / a2)) / b1;
} else if (t_0 <= 2e+264) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / 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-288: tmp = t_0 elif t_0 <= 2e-303: tmp = (a1 / (b2 / a2)) / b1 elif t_0 <= 2e+264: tmp = t_0 else: tmp = (a2 / b1) * (a1 / 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-288) tmp = t_0; elseif (t_0 <= 2e-303) tmp = Float64(Float64(a1 / Float64(b2 / a2)) / b1); elseif (t_0 <= 2e+264) tmp = t_0; else tmp = Float64(Float64(a2 / b1) * Float64(a1 / 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-288)
tmp = t_0;
elseif (t_0 <= 2e-303)
tmp = (a1 / (b2 / a2)) / b1;
elseif (t_0 <= 2e+264)
tmp = t_0;
else
tmp = (a2 / b1) * (a1 / 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-288], t$95$0, If[LessEqual[t$95$0, 2e-303], N[(N[(a1 / N[(b2 / a2), $MachinePrecision]), $MachinePrecision] / b1), $MachinePrecision], If[LessEqual[t$95$0, 2e+264], t$95$0, N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / 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^{-288}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-303}:\\
\;\;\;\;\frac{\frac{a1}{\frac{b2}{a2}}}{b1}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+264}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -5.00000000000000011e-288 or 1.99999999999999986e-303 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.00000000000000009e264Initial program 97.7%
if -5.00000000000000011e-288 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999986e-303Initial program 83.9%
frac-2neg83.9%
div-inv84.0%
distribute-rgt-neg-in84.0%
distribute-rgt-neg-in84.0%
Applied egg-rr84.0%
associate-*r/83.9%
*-rgt-identity83.9%
associate-/l/91.7%
distribute-rgt-neg-out91.7%
*-commutative91.7%
distribute-rgt-neg-in91.7%
Simplified91.7%
Taylor expanded in a2 around 0 91.7%
associate-/l*94.5%
Simplified94.5%
if 2.00000000000000009e264 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 58.1%
*-commutative58.1%
times-frac95.5%
Applied egg-rr95.5%
Final simplification96.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))))
(if (<= t_0 -5e-288)
t_0
(if (<= t_0 2e-303)
(* (/ a2 b2) (/ a1 b1))
(if (<= t_0 2e+264) t_0 (* (/ a2 b1) (/ a1 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-288) {
tmp = t_0;
} else if (t_0 <= 2e-303) {
tmp = (a2 / b2) * (a1 / b1);
} else if (t_0 <= 2e+264) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / 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-288)) then
tmp = t_0
else if (t_0 <= 2d-303) then
tmp = (a2 / b2) * (a1 / b1)
else if (t_0 <= 2d+264) then
tmp = t_0
else
tmp = (a2 / b1) * (a1 / 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-288) {
tmp = t_0;
} else if (t_0 <= 2e-303) {
tmp = (a2 / b2) * (a1 / b1);
} else if (t_0 <= 2e+264) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / 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-288: tmp = t_0 elif t_0 <= 2e-303: tmp = (a2 / b2) * (a1 / b1) elif t_0 <= 2e+264: tmp = t_0 else: tmp = (a2 / b1) * (a1 / 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-288) tmp = t_0; elseif (t_0 <= 2e-303) tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); elseif (t_0 <= 2e+264) tmp = t_0; else tmp = Float64(Float64(a2 / b1) * Float64(a1 / 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-288)
tmp = t_0;
elseif (t_0 <= 2e-303)
tmp = (a2 / b2) * (a1 / b1);
elseif (t_0 <= 2e+264)
tmp = t_0;
else
tmp = (a2 / b1) * (a1 / 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-288], t$95$0, If[LessEqual[t$95$0, 2e-303], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+264], t$95$0, N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / 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^{-288}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-303}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+264}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -5.00000000000000011e-288 or 1.99999999999999986e-303 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.00000000000000009e264Initial program 97.7%
if -5.00000000000000011e-288 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999986e-303Initial program 83.9%
times-frac92.1%
*-commutative92.1%
Applied egg-rr92.1%
if 2.00000000000000009e264 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 58.1%
*-commutative58.1%
times-frac95.5%
Applied egg-rr95.5%
Final simplification95.9%
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-295)
(and (not (<= (* b1 b2) 0.0)) (<= (* b1 b2) 1e+168)))
(* a2 (/ a1 (* b1 b2)))
(* (/ a2 b1) (/ a1 b2))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -5e-295) || (!((b1 * b2) <= 0.0) && ((b1 * b2) <= 1e+168))) {
tmp = a2 * (a1 / (b1 * b2));
} else {
tmp = (a2 / b1) * (a1 / 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-295)) .or. (.not. ((b1 * b2) <= 0.0d0)) .and. ((b1 * b2) <= 1d+168)) then
tmp = a2 * (a1 / (b1 * b2))
else
tmp = (a2 / b1) * (a1 / 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-295) || (!((b1 * b2) <= 0.0) && ((b1 * b2) <= 1e+168))) {
tmp = a2 * (a1 / (b1 * b2));
} else {
tmp = (a2 / b1) * (a1 / 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-295) or (not ((b1 * b2) <= 0.0) and ((b1 * b2) <= 1e+168)): tmp = a2 * (a1 / (b1 * b2)) else: tmp = (a2 / b1) * (a1 / 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-295) || (!(Float64(b1 * b2) <= 0.0) && (Float64(b1 * b2) <= 1e+168))) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); else tmp = Float64(Float64(a2 / b1) * Float64(a1 / 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-295) || (~(((b1 * b2) <= 0.0)) && ((b1 * b2) <= 1e+168)))
tmp = a2 * (a1 / (b1 * b2));
else
tmp = (a2 / b1) * (a1 / 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-295], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 0.0]], $MachinePrecision], LessEqual[N[(b1 * b2), $MachinePrecision], 1e+168]]], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $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^{-295} \lor \neg \left(b1 \cdot b2 \leq 0\right) \land b1 \cdot b2 \leq 10^{+168}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -5.00000000000000008e-295 or 0.0 < (*.f64 b1 b2) < 9.9999999999999993e167Initial program 92.7%
associate-/l*92.3%
associate-/r/88.7%
Applied egg-rr88.7%
if -5.00000000000000008e-295 < (*.f64 b1 b2) < 0.0 or 9.9999999999999993e167 < (*.f64 b1 b2) Initial program 69.3%
*-commutative69.3%
times-frac95.6%
Applied egg-rr95.6%
Final simplification90.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
(let* ((t_0 (* a2 (/ a1 (* b1 b2)))))
(if (<= (* b1 b2) -5e-295)
t_0
(if (<= (* b1 b2) 0.0)
(* (/ a2 b1) (/ a1 b2))
(if (<= (* b1 b2) 2e+240) 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 = a2 * (a1 / (b1 * b2));
double tmp;
if ((b1 * b2) <= -5e-295) {
tmp = t_0;
} else if ((b1 * b2) <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if ((b1 * b2) <= 2e+240) {
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 = a2 * (a1 / (b1 * b2))
if ((b1 * b2) <= (-5d-295)) then
tmp = t_0
else if ((b1 * b2) <= 0.0d0) then
tmp = (a2 / b1) * (a1 / b2)
else if ((b1 * b2) <= 2d+240) 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 = a2 * (a1 / (b1 * b2));
double tmp;
if ((b1 * b2) <= -5e-295) {
tmp = t_0;
} else if ((b1 * b2) <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if ((b1 * b2) <= 2e+240) {
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 = a2 * (a1 / (b1 * b2)) tmp = 0 if (b1 * b2) <= -5e-295: tmp = t_0 elif (b1 * b2) <= 0.0: tmp = (a2 / b1) * (a1 / b2) elif (b1 * b2) <= 2e+240: 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(a2 * Float64(a1 / Float64(b1 * b2))) tmp = 0.0 if (Float64(b1 * b2) <= -5e-295) tmp = t_0; elseif (Float64(b1 * b2) <= 0.0) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); elseif (Float64(b1 * b2) <= 2e+240) 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 = a2 * (a1 / (b1 * b2));
tmp = 0.0;
if ((b1 * b2) <= -5e-295)
tmp = t_0;
elseif ((b1 * b2) <= 0.0)
tmp = (a2 / b1) * (a1 / b2);
elseif ((b1 * b2) <= 2e+240)
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[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -5e-295], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 0.0], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+240], 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 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -5 \cdot 10^{-295}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 0:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+240}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -5.00000000000000008e-295 or 0.0 < (*.f64 b1 b2) < 2.00000000000000003e240Initial program 92.4%
associate-/l*92.0%
associate-/r/88.5%
Applied egg-rr88.5%
if -5.00000000000000008e-295 < (*.f64 b1 b2) < 0.0Initial program 61.9%
*-commutative61.9%
times-frac99.9%
Applied egg-rr99.9%
if 2.00000000000000003e240 < (*.f64 b1 b2) Initial program 74.4%
times-frac91.9%
*-commutative91.9%
Applied egg-rr91.9%
Final simplification90.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-295)
(* a2 (/ a1 (* b1 b2)))
(if (<= (* b1 b2) 0.0)
(* (/ a2 b1) (/ a1 b2))
(if (<= (* b1 b2) 2e+240)
(/ a2 (/ (* b1 b2) a1))
(* (/ 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-295) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if ((b1 * b2) <= 2e+240) {
tmp = a2 / ((b1 * b2) / a1);
} 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-295)) then
tmp = a2 * (a1 / (b1 * b2))
else if ((b1 * b2) <= 0.0d0) then
tmp = (a2 / b1) * (a1 / b2)
else if ((b1 * b2) <= 2d+240) then
tmp = a2 / ((b1 * b2) / a1)
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-295) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 0.0) {
tmp = (a2 / b1) * (a1 / b2);
} else if ((b1 * b2) <= 2e+240) {
tmp = a2 / ((b1 * b2) / a1);
} 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-295: tmp = a2 * (a1 / (b1 * b2)) elif (b1 * b2) <= 0.0: tmp = (a2 / b1) * (a1 / b2) elif (b1 * b2) <= 2e+240: tmp = a2 / ((b1 * b2) / a1) 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-295) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); elseif (Float64(b1 * b2) <= 0.0) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); elseif (Float64(b1 * b2) <= 2e+240) tmp = Float64(a2 / Float64(Float64(b1 * b2) / a1)); 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-295)
tmp = a2 * (a1 / (b1 * b2));
elseif ((b1 * b2) <= 0.0)
tmp = (a2 / b1) * (a1 / b2);
elseif ((b1 * b2) <= 2e+240)
tmp = a2 / ((b1 * b2) / a1);
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-295], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 0.0], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+240], N[(a2 / N[(N[(b1 * b2), $MachinePrecision] / a1), $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^{-295}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 0:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+240}:\\
\;\;\;\;\frac{a2}{\frac{b1 \cdot b2}{a1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -5.00000000000000008e-295Initial program 91.9%
associate-/l*92.7%
associate-/r/86.2%
Applied egg-rr86.2%
if -5.00000000000000008e-295 < (*.f64 b1 b2) < 0.0Initial program 61.9%
*-commutative61.9%
times-frac99.9%
Applied egg-rr99.9%
if 0.0 < (*.f64 b1 b2) < 2.00000000000000003e240Initial program 93.4%
associate-/l*90.9%
associate-/r/92.8%
Applied egg-rr92.8%
*-commutative92.8%
clear-num91.9%
un-div-inv92.0%
Applied egg-rr92.0%
if 2.00000000000000003e240 < (*.f64 b1 b2) Initial program 74.4%
times-frac91.9%
*-commutative91.9%
Applied egg-rr91.9%
Final simplification89.8%
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 (/ a1 (* b1 b2))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return a2 * (a1 / (b1 * 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 = a2 * (a1 / (b1 * b2))
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return a2 * (a1 / (b1 * b2));
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): return a2 * (a1 / (b1 * b2))
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) return Float64(a2 * Float64(a1 / Float64(b1 * b2))) end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = a2 * (a1 / (b1 * 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[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
a2 \cdot \frac{a1}{b1 \cdot b2}
\end{array}
Initial program 87.6%
associate-/l*87.3%
associate-/r/84.1%
Applied egg-rr84.1%
Final simplification84.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 2023187
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))