
(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))) (t_1 (* (/ a1 b1) (/ a2 b2))))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -5e-314)
t_0
(if (<= t_0 0.0)
(/ a1 (/ b2 (/ a2 b1)))
(if (<= t_0 5e+274) 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 = (a1 / b1) * (a2 / b2);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -5e-314) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = a1 / (b2 / (a2 / b1));
} else if (t_0 <= 5e+274) {
tmp = t_0;
} else {
tmp = t_1;
}
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 t_1 = (a1 / b1) * (a2 / b2);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= -5e-314) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = a1 / (b2 / (a2 / b1));
} else if (t_0 <= 5e+274) {
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 = (a1 / b1) * (a2 / b2) tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= -5e-314: tmp = t_0 elif t_0 <= 0.0: tmp = a1 / (b2 / (a2 / b1)) elif t_0 <= 5e+274: 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(a1 / b1) * Float64(a2 / b2)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -5e-314) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(a1 / Float64(b2 / Float64(a2 / b1))); elseif (t_0 <= 5e+274) 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 = (a1 / b1) * (a2 / b2);
tmp = 0.0;
if (t_0 <= -Inf)
tmp = t_1;
elseif (t_0 <= -5e-314)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = a1 / (b2 / (a2 / b1));
elseif (t_0 <= 5e+274)
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[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -5e-314], t$95$0, If[LessEqual[t$95$0, 0.0], N[(a1 / N[(b2 / N[(a2 / b1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+274], 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{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-314}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+274}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or 4.9999999999999998e274 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 78.3%
times-frac95.5%
Simplified95.5%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999982e-314 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999998e274Initial program 99.4%
if -4.99999999982e-314 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0Initial program 77.2%
associate-/l*84.0%
*-commutative84.0%
associate-/l*90.0%
Simplified90.0%
Final simplification96.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) (- INFINITY))
(and (not (<= (* b1 b2) -2e-254))
(or (<= (* b1 b2) 0.0) (not (<= (* b1 b2) 2e+157)))))
(* (/ 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) <= -((double) INFINITY)) || (!((b1 * b2) <= -2e-254) && (((b1 * b2) <= 0.0) || !((b1 * b2) <= 2e+157)))) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a2 * (a1 / (b1 * b2));
}
return tmp;
}
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -Double.POSITIVE_INFINITY) || (!((b1 * b2) <= -2e-254) && (((b1 * b2) <= 0.0) || !((b1 * b2) <= 2e+157)))) {
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) <= -math.inf) or (not ((b1 * b2) <= -2e-254) and (((b1 * b2) <= 0.0) or not ((b1 * b2) <= 2e+157))): 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) <= Float64(-Inf)) || (!(Float64(b1 * b2) <= -2e-254) && ((Float64(b1 * b2) <= 0.0) || !(Float64(b1 * b2) <= 2e+157)))) 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) <= -Inf) || (~(((b1 * b2) <= -2e-254)) && (((b1 * b2) <= 0.0) || ~(((b1 * b2) <= 2e+157)))))
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], (-Infinity)], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-254]], $MachinePrecision], Or[LessEqual[N[(b1 * b2), $MachinePrecision], 0.0], N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+157]], $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 -\infty \lor \neg \left(b1 \cdot b2 \leq -2 \cdot 10^{-254}\right) \land \left(b1 \cdot b2 \leq 0 \lor \neg \left(b1 \cdot b2 \leq 2 \cdot 10^{+157}\right)\right):\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -inf.0 or -1.9999999999999998e-254 < (*.f64 b1 b2) < -0.0 or 1.99999999999999997e157 < (*.f64 b1 b2) Initial program 75.4%
times-frac89.1%
Simplified89.1%
if -inf.0 < (*.f64 b1 b2) < -1.9999999999999998e-254 or -0.0 < (*.f64 b1 b2) < 1.99999999999999997e157Initial program 96.2%
associate-/l*96.0%
*-commutative96.0%
associate-/l*90.0%
Simplified90.0%
associate-/l*96.0%
*-commutative96.0%
associate-/r/93.7%
Applied egg-rr93.7%
Final simplification91.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
(let* ((t_0 (* a2 (/ a1 (* b1 b2)))) (t_1 (* (/ a2 b1) (/ a1 b2))))
(if (<= (* b1 b2) -1e+290)
t_1
(if (<= (* b1 b2) -4e-285)
t_0
(if (<= (* b1 b2) 5e-214)
t_1
(if (<= (* b1 b2) 2e+157) 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 = a2 * (a1 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+290) {
tmp = t_1;
} else if ((b1 * b2) <= -4e-285) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-214) {
tmp = t_1;
} else if ((b1 * b2) <= 2e+157) {
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) :: t_1
real(8) :: tmp
t_0 = a2 * (a1 / (b1 * b2))
t_1 = (a2 / b1) * (a1 / b2)
if ((b1 * b2) <= (-1d+290)) then
tmp = t_1
else if ((b1 * b2) <= (-4d-285)) then
tmp = t_0
else if ((b1 * b2) <= 5d-214) then
tmp = t_1
else if ((b1 * b2) <= 2d+157) 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 = a2 * (a1 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+290) {
tmp = t_1;
} else if ((b1 * b2) <= -4e-285) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-214) {
tmp = t_1;
} else if ((b1 * b2) <= 2e+157) {
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 = a2 * (a1 / (b1 * b2)) t_1 = (a2 / b1) * (a1 / b2) tmp = 0 if (b1 * b2) <= -1e+290: tmp = t_1 elif (b1 * b2) <= -4e-285: tmp = t_0 elif (b1 * b2) <= 5e-214: tmp = t_1 elif (b1 * b2) <= 2e+157: 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(a2 * Float64(a1 / Float64(b1 * b2))) t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2)) tmp = 0.0 if (Float64(b1 * b2) <= -1e+290) tmp = t_1; elseif (Float64(b1 * b2) <= -4e-285) tmp = t_0; elseif (Float64(b1 * b2) <= 5e-214) tmp = t_1; elseif (Float64(b1 * b2) <= 2e+157) 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 = a2 * (a1 / (b1 * b2));
t_1 = (a2 / b1) * (a1 / b2);
tmp = 0.0;
if ((b1 * b2) <= -1e+290)
tmp = t_1;
elseif ((b1 * b2) <= -4e-285)
tmp = t_0;
elseif ((b1 * b2) <= 5e-214)
tmp = t_1;
elseif ((b1 * b2) <= 2e+157)
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[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -1e+290], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -4e-285], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-214], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+157], 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 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+290}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq -4 \cdot 10^{-285}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-214}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+157}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -1.00000000000000006e290 or -4.0000000000000003e-285 < (*.f64 b1 b2) < 4.9999999999999998e-214Initial program 77.1%
associate-/l*77.3%
*-commutative77.3%
associate-/l*86.0%
Simplified86.0%
associate-/r/98.5%
*-commutative98.5%
Applied egg-rr98.5%
if -1.00000000000000006e290 < (*.f64 b1 b2) < -4.0000000000000003e-285 or 4.9999999999999998e-214 < (*.f64 b1 b2) < 1.99999999999999997e157Initial program 96.0%
associate-/l*95.8%
*-commutative95.8%
associate-/l*89.6%
Simplified89.6%
associate-/l*95.8%
*-commutative95.8%
associate-/r/94.1%
Applied egg-rr94.1%
if 1.99999999999999997e157 < (*.f64 b1 b2) Initial program 76.9%
times-frac84.8%
Simplified84.8%
Final simplification93.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
(let* ((t_0 (* (/ a2 b1) (/ a1 b2))))
(if (<= (* b1 b2) -1e+290)
t_0
(if (<= (* b1 b2) -4e-285)
(* a2 (/ a1 (* b1 b2)))
(if (<= (* b1 b2) 0.0)
t_0
(if (<= (* b1 b2) 5e+282)
(* a1 (/ a2 (* b1 b2)))
(* (/ a1 b1) (/ a2 b2))))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+290) {
tmp = t_0;
} else if ((b1 * b2) <= -4e-285) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 0.0) {
tmp = t_0;
} else if ((b1 * b2) <= 5e+282) {
tmp = a1 * (a2 / (b1 * b2));
} 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 = (a2 / b1) * (a1 / b2)
if ((b1 * b2) <= (-1d+290)) then
tmp = t_0
else if ((b1 * b2) <= (-4d-285)) then
tmp = a2 * (a1 / (b1 * b2))
else if ((b1 * b2) <= 0.0d0) then
tmp = t_0
else if ((b1 * b2) <= 5d+282) then
tmp = a1 * (a2 / (b1 * b2))
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 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+290) {
tmp = t_0;
} else if ((b1 * b2) <= -4e-285) {
tmp = a2 * (a1 / (b1 * b2));
} else if ((b1 * b2) <= 0.0) {
tmp = t_0;
} else if ((b1 * b2) <= 5e+282) {
tmp = a1 * (a2 / (b1 * b2));
} 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 = (a2 / b1) * (a1 / b2) tmp = 0 if (b1 * b2) <= -1e+290: tmp = t_0 elif (b1 * b2) <= -4e-285: tmp = a2 * (a1 / (b1 * b2)) elif (b1 * b2) <= 0.0: tmp = t_0 elif (b1 * b2) <= 5e+282: tmp = a1 * (a2 / (b1 * b2)) 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(a2 / b1) * Float64(a1 / b2)) tmp = 0.0 if (Float64(b1 * b2) <= -1e+290) tmp = t_0; elseif (Float64(b1 * b2) <= -4e-285) tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2))); elseif (Float64(b1 * b2) <= 0.0) tmp = t_0; elseif (Float64(b1 * b2) <= 5e+282) tmp = Float64(a1 * Float64(a2 / Float64(b1 * b2))); 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 = (a2 / b1) * (a1 / b2);
tmp = 0.0;
if ((b1 * b2) <= -1e+290)
tmp = t_0;
elseif ((b1 * b2) <= -4e-285)
tmp = a2 * (a1 / (b1 * b2));
elseif ((b1 * b2) <= 0.0)
tmp = t_0;
elseif ((b1 * b2) <= 5e+282)
tmp = a1 * (a2 / (b1 * b2));
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[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -1e+290], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], -4e-285], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 0.0], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e+282], N[(a1 * N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+290}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq -4 \cdot 10^{-285}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 0:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{+282}:\\
\;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -1.00000000000000006e290 or -4.0000000000000003e-285 < (*.f64 b1 b2) < -0.0Initial program 74.4%
associate-/l*74.7%
*-commutative74.7%
associate-/l*84.4%
Simplified84.4%
associate-/r/98.4%
*-commutative98.4%
Applied egg-rr98.4%
if -1.00000000000000006e290 < (*.f64 b1 b2) < -4.0000000000000003e-285Initial program 92.2%
associate-/l*97.2%
*-commutative97.2%
associate-/l*92.0%
Simplified92.0%
associate-/l*97.2%
*-commutative97.2%
associate-/r/92.2%
Applied egg-rr92.2%
if -0.0 < (*.f64 b1 b2) < 4.99999999999999978e282Initial program 97.8%
associate-/l*92.1%
*-commutative92.1%
associate-/l*86.4%
Simplified86.4%
clear-num86.4%
associate-/r/86.4%
clear-num86.6%
associate-/l/92.3%
*-commutative92.3%
Applied egg-rr92.3%
if 4.99999999999999978e282 < (*.f64 b1 b2) Initial program 68.3%
times-frac88.9%
Simplified88.9%
Final simplification93.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
(let* ((t_0 (* a2 (/ a1 (* b1 b2)))) (t_1 (* (/ a2 b1) (/ a1 b2))))
(if (<= (* b1 b2) -1e+290)
t_1
(if (<= (* b1 b2) -4e-285)
t_0
(if (<= (* b1 b2) 5e-214)
t_1
(if (<= (* b1 b2) 1e+71) t_0 (/ a1 (/ b2 (/ a2 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 t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+290) {
tmp = t_1;
} else if ((b1 * b2) <= -4e-285) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-214) {
tmp = t_1;
} else if ((b1 * b2) <= 1e+71) {
tmp = t_0;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = a2 * (a1 / (b1 * b2))
t_1 = (a2 / b1) * (a1 / b2)
if ((b1 * b2) <= (-1d+290)) then
tmp = t_1
else if ((b1 * b2) <= (-4d-285)) then
tmp = t_0
else if ((b1 * b2) <= 5d-214) then
tmp = t_1
else if ((b1 * b2) <= 1d+71) then
tmp = t_0
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 t_0 = a2 * (a1 / (b1 * b2));
double t_1 = (a2 / b1) * (a1 / b2);
double tmp;
if ((b1 * b2) <= -1e+290) {
tmp = t_1;
} else if ((b1 * b2) <= -4e-285) {
tmp = t_0;
} else if ((b1 * b2) <= 5e-214) {
tmp = t_1;
} else if ((b1 * b2) <= 1e+71) {
tmp = t_0;
} else {
tmp = a1 / (b2 / (a2 / 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)) t_1 = (a2 / b1) * (a1 / b2) tmp = 0 if (b1 * b2) <= -1e+290: tmp = t_1 elif (b1 * b2) <= -4e-285: tmp = t_0 elif (b1 * b2) <= 5e-214: tmp = t_1 elif (b1 * b2) <= 1e+71: tmp = t_0 else: tmp = a1 / (b2 / (a2 / 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))) t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2)) tmp = 0.0 if (Float64(b1 * b2) <= -1e+290) tmp = t_1; elseif (Float64(b1 * b2) <= -4e-285) tmp = t_0; elseif (Float64(b1 * b2) <= 5e-214) tmp = t_1; elseif (Float64(b1 * b2) <= 1e+71) tmp = t_0; 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)
t_0 = a2 * (a1 / (b1 * b2));
t_1 = (a2 / b1) * (a1 / b2);
tmp = 0.0;
if ((b1 * b2) <= -1e+290)
tmp = t_1;
elseif ((b1 * b2) <= -4e-285)
tmp = t_0;
elseif ((b1 * b2) <= 5e-214)
tmp = t_1;
elseif ((b1 * b2) <= 1e+71)
tmp = t_0;
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_] := Block[{t$95$0 = N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -1e+290], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -4e-285], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-214], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], 1e+71], t$95$0, 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}
t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+290}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq -4 \cdot 10^{-285}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-214}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b1 \cdot b2 \leq 10^{+71}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -1.00000000000000006e290 or -4.0000000000000003e-285 < (*.f64 b1 b2) < 4.9999999999999998e-214Initial program 77.1%
associate-/l*77.3%
*-commutative77.3%
associate-/l*86.0%
Simplified86.0%
associate-/r/98.5%
*-commutative98.5%
Applied egg-rr98.5%
if -1.00000000000000006e290 < (*.f64 b1 b2) < -4.0000000000000003e-285 or 4.9999999999999998e-214 < (*.f64 b1 b2) < 1e71Initial program 95.5%
associate-/l*96.8%
*-commutative96.8%
associate-/l*89.6%
Simplified89.6%
associate-/l*96.8%
*-commutative96.8%
associate-/r/94.1%
Applied egg-rr94.1%
if 1e71 < (*.f64 b1 b2) Initial program 84.0%
associate-/l*79.0%
*-commutative79.0%
associate-/l*82.7%
Simplified82.7%
Final simplification92.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 (* (/ 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 88.1%
times-frac82.3%
Simplified82.3%
Final simplification82.3%
(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 2023181
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))