
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2): return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 * a2) / Float64(b1 * b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 * a2) / (b1 * b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2): return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2) return Float64(Float64(a1 * a2) / Float64(b1 * b2)) end
function tmp = code(a1, a2, b1, b2) tmp = (a1 * a2) / (b1 * b2); end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* a1 a2) (* b2 b1))))
(if (<= t_0 -2e+118)
(/ a2 (* b2 (/ b1 a1)))
(if (or (<= t_0 -1e-252) (and (not (<= t_0 0.0)) (<= t_0 5e+267)))
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) / (b2 * b1);
double tmp;
if (t_0 <= -2e+118) {
tmp = a2 / (b2 * (b1 / a1));
} else if ((t_0 <= -1e-252) || (!(t_0 <= 0.0) && (t_0 <= 5e+267))) {
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) / (b2 * b1)
if (t_0 <= (-2d+118)) then
tmp = a2 / (b2 * (b1 / a1))
else if ((t_0 <= (-1d-252)) .or. (.not. (t_0 <= 0.0d0)) .and. (t_0 <= 5d+267)) 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) / (b2 * b1);
double tmp;
if (t_0 <= -2e+118) {
tmp = a2 / (b2 * (b1 / a1));
} else if ((t_0 <= -1e-252) || (!(t_0 <= 0.0) && (t_0 <= 5e+267))) {
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) / (b2 * b1) tmp = 0 if t_0 <= -2e+118: tmp = a2 / (b2 * (b1 / a1)) elif (t_0 <= -1e-252) or (not (t_0 <= 0.0) and (t_0 <= 5e+267)): 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(b2 * b1)) tmp = 0.0 if (t_0 <= -2e+118) tmp = Float64(a2 / Float64(b2 * Float64(b1 / a1))); elseif ((t_0 <= -1e-252) || (!(t_0 <= 0.0) && (t_0 <= 5e+267))) 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) / (b2 * b1);
tmp = 0.0;
if (t_0 <= -2e+118)
tmp = a2 / (b2 * (b1 / a1));
elseif ((t_0 <= -1e-252) || (~((t_0 <= 0.0)) && (t_0 <= 5e+267)))
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[(b2 * b1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+118], N[(a2 / N[(b2 * N[(b1 / a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$0, -1e-252], And[N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision], LessEqual[t$95$0, 5e+267]]], 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}{b2 \cdot b1}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+118}:\\
\;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\
\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-252} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 5 \cdot 10^{+267}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999993e118Initial program 88.7%
times-frac87.5%
associate-*l/89.9%
associate-*r/89.9%
Simplified89.9%
associate-*r/89.9%
associate-*l/87.5%
clear-num87.5%
frac-times87.5%
*-un-lft-identity87.5%
Applied egg-rr87.5%
if -1.99999999999999993e118 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -9.99999999999999943e-253 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999999e267Initial program 98.6%
if -9.99999999999999943e-253 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0 or 4.9999999999999999e267 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 76.1%
times-frac98.8%
Simplified98.8%
Final simplification97.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 (<= (* a1 a2) -2e+119)
(/ (/ a1 (/ b2 a2)) b1)
(if (<= (* a1 a2) -4e-244)
(/ (* a1 a2) (* b2 b1))
(if (<= (* a1 a2) 4e-234)
(/ a2 (* b2 (/ b1 a1)))
(/ (/ (* a1 a2) b1) b2)))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if ((a1 * a2) <= -2e+119) {
tmp = (a1 / (b2 / a2)) / b1;
} else if ((a1 * a2) <= -4e-244) {
tmp = (a1 * a2) / (b2 * b1);
} else if ((a1 * a2) <= 4e-234) {
tmp = a2 / (b2 * (b1 / a1));
} 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 ((a1 * a2) <= (-2d+119)) then
tmp = (a1 / (b2 / a2)) / b1
else if ((a1 * a2) <= (-4d-244)) then
tmp = (a1 * a2) / (b2 * b1)
else if ((a1 * a2) <= 4d-234) then
tmp = a2 / (b2 * (b1 / a1))
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 ((a1 * a2) <= -2e+119) {
tmp = (a1 / (b2 / a2)) / b1;
} else if ((a1 * a2) <= -4e-244) {
tmp = (a1 * a2) / (b2 * b1);
} else if ((a1 * a2) <= 4e-234) {
tmp = a2 / (b2 * (b1 / a1));
} 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 (a1 * a2) <= -2e+119: tmp = (a1 / (b2 / a2)) / b1 elif (a1 * a2) <= -4e-244: tmp = (a1 * a2) / (b2 * b1) elif (a1 * a2) <= 4e-234: tmp = a2 / (b2 * (b1 / a1)) 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(a1 * a2) <= -2e+119) tmp = Float64(Float64(a1 / Float64(b2 / a2)) / b1); elseif (Float64(a1 * a2) <= -4e-244) tmp = Float64(Float64(a1 * a2) / Float64(b2 * b1)); elseif (Float64(a1 * a2) <= 4e-234) tmp = Float64(a2 / Float64(b2 * Float64(b1 / a1))); else tmp = Float64(Float64(Float64(a1 * a2) / 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 ((a1 * a2) <= -2e+119)
tmp = (a1 / (b2 / a2)) / b1;
elseif ((a1 * a2) <= -4e-244)
tmp = (a1 * a2) / (b2 * b1);
elseif ((a1 * a2) <= 4e-234)
tmp = a2 / (b2 * (b1 / a1));
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[LessEqual[N[(a1 * a2), $MachinePrecision], -2e+119], N[(N[(a1 / N[(b2 / a2), $MachinePrecision]), $MachinePrecision] / b1), $MachinePrecision], If[LessEqual[N[(a1 * a2), $MachinePrecision], -4e-244], N[(N[(a1 * a2), $MachinePrecision] / N[(b2 * b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a1 * a2), $MachinePrecision], 4e-234], N[(a2 / N[(b2 * N[(b1 / a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a1 * a2), $MachinePrecision] / b1), $MachinePrecision] / b2), $MachinePrecision]]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;a1 \cdot a2 \leq -2 \cdot 10^{+119}:\\
\;\;\;\;\frac{\frac{a1}{\frac{b2}{a2}}}{b1}\\
\mathbf{elif}\;a1 \cdot a2 \leq -4 \cdot 10^{-244}:\\
\;\;\;\;\frac{a1 \cdot a2}{b2 \cdot b1}\\
\mathbf{elif}\;a1 \cdot a2 \leq 4 \cdot 10^{-234}:\\
\;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a1 \cdot a2}{b1}}{b2}\\
\end{array}
\end{array}
if (*.f64 a1 a2) < -1.99999999999999989e119Initial program 71.9%
times-frac96.8%
associate-*l/97.7%
associate-*r/91.6%
Simplified91.6%
associate-*r/97.7%
clear-num97.5%
un-div-inv97.6%
Applied egg-rr97.6%
if -1.99999999999999989e119 < (*.f64 a1 a2) < -3.9999999999999997e-244Initial program 99.7%
if -3.9999999999999997e-244 < (*.f64 a1 a2) < 3.9999999999999998e-234Initial program 77.3%
times-frac95.9%
associate-*l/90.9%
associate-*r/95.7%
Simplified95.7%
associate-*r/90.9%
associate-*l/95.9%
clear-num95.9%
frac-times93.1%
*-un-lft-identity93.1%
Applied egg-rr93.1%
if 3.9999999999999998e-234 < (*.f64 a1 a2) Initial program 89.0%
times-frac85.7%
associate-*l/88.7%
associate-*r/83.9%
Simplified83.9%
associate-/l/86.3%
associate-*r/89.0%
associate-/r*92.7%
Applied egg-rr92.7%
Final simplification95.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 (<= b1 -1.9e+84) (* a1 (/ (/ a2 b2) b1)) (* (/ a1 b1) (/ a2 b2))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b1 <= -1.9e+84) {
tmp = a1 * ((a2 / b2) / b1);
} 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) :: tmp
if (b1 <= (-1.9d+84)) then
tmp = a1 * ((a2 / b2) / b1)
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 tmp;
if (b1 <= -1.9e+84) {
tmp = a1 * ((a2 / b2) / b1);
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if b1 <= -1.9e+84: tmp = a1 * ((a2 / b2) / b1) else: tmp = (a1 / b1) * (a2 / b2) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (b1 <= -1.9e+84) tmp = Float64(a1 * Float64(Float64(a2 / b2) / b1)); 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)
tmp = 0.0;
if (b1 <= -1.9e+84)
tmp = a1 * ((a2 / b2) / b1);
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_] := If[LessEqual[b1, -1.9e+84], N[(a1 * N[(N[(a2 / b2), $MachinePrecision] / b1), $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}
\mathbf{if}\;b1 \leq -1.9 \cdot 10^{+84}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if b1 < -1.9e84Initial program 87.2%
times-frac82.9%
associate-*l/86.7%
associate-*r/82.9%
Simplified82.9%
if -1.9e84 < b1 Initial program 85.8%
times-frac87.8%
Simplified87.8%
Final simplification86.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 (if (<= a2 1.7e+199) (/ a2 (* b2 (/ b1 a1))) (* (/ a1 b1) (/ a2 b2))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (a2 <= 1.7e+199) {
tmp = a2 / (b2 * (b1 / a1));
} 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) :: tmp
if (a2 <= 1.7d+199) then
tmp = a2 / (b2 * (b1 / a1))
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 tmp;
if (a2 <= 1.7e+199) {
tmp = a2 / (b2 * (b1 / a1));
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if a2 <= 1.7e+199: tmp = a2 / (b2 * (b1 / a1)) else: tmp = (a1 / b1) * (a2 / b2) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (a2 <= 1.7e+199) tmp = Float64(a2 / Float64(b2 * Float64(b1 / a1))); 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)
tmp = 0.0;
if (a2 <= 1.7e+199)
tmp = a2 / (b2 * (b1 / a1));
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_] := If[LessEqual[a2, 1.7e+199], N[(a2 / N[(b2 * N[(b1 / a1), $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}
\mathbf{if}\;a2 \leq 1.7 \cdot 10^{+199}:\\
\;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if a2 < 1.7e199Initial program 86.4%
times-frac88.2%
associate-*l/88.3%
associate-*r/87.1%
Simplified87.1%
associate-*r/88.3%
associate-*l/88.2%
clear-num88.1%
frac-times87.0%
*-un-lft-identity87.0%
Applied egg-rr87.0%
if 1.7e199 < a2 Initial program 83.0%
times-frac72.8%
Simplified72.8%
Final simplification85.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 (* a1 (/ (/ a2 b2) b1)))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return a1 * ((a2 / b2) / 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 = a1 * ((a2 / b2) / b1)
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return a1 * ((a2 / b2) / b1);
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): return a1 * ((a2 / b2) / b1)
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) return Float64(a1 * Float64(Float64(a2 / b2) / b1)) end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = a1 * ((a2 / b2) / 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[(a1 * N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
a1 \cdot \frac{\frac{a2}{b2}}{b1}
\end{array}
Initial program 86.1%
times-frac86.8%
associate-*l/87.5%
associate-*r/86.3%
Simplified86.3%
Final simplification86.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 2023333
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))