
(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) (* b1 b2))) (t_1 (/ (/ a1 (/ b1 a2)) b2)))
(if (<= t_0 -1e+294)
t_1
(if (<= t_0 -2e-268)
t_0
(if (<= t_0 0.0)
t_1
(if (<= t_0 2e+244) t_0 (* (/ a1 b1) (/ a2 b2))))))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 / (b1 / a2)) / b2;
double tmp;
if (t_0 <= -1e+294) {
tmp = t_1;
} else if (t_0 <= -2e-268) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 2e+244) {
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 = (a1 * a2) / (b1 * b2)
t_1 = (a1 / (b1 / a2)) / b2
if (t_0 <= (-1d+294)) then
tmp = t_1
else if (t_0 <= (-2d-268)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = t_1
else if (t_0 <= 2d+244) then
tmp = t_0
else
tmp = (a1 / b1) * (a2 / b2)
end if
code = tmp
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 / (b1 / a2)) / b2;
double tmp;
if (t_0 <= -1e+294) {
tmp = t_1;
} else if (t_0 <= -2e-268) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 2e+244) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / b2);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): t_0 = (a1 * a2) / (b1 * b2) t_1 = (a1 / (b1 / a2)) / b2 tmp = 0 if t_0 <= -1e+294: tmp = t_1 elif t_0 <= -2e-268: tmp = t_0 elif t_0 <= 0.0: tmp = t_1 elif t_0 <= 2e+244: tmp = t_0 else: tmp = (a1 / b1) * (a2 / b2) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2)) t_1 = Float64(Float64(a1 / Float64(b1 / a2)) / b2) tmp = 0.0 if (t_0 <= -1e+294) tmp = t_1; elseif (t_0 <= -2e-268) tmp = t_0; elseif (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 2e+244) tmp = t_0; else tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); end return tmp end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
t_0 = (a1 * a2) / (b1 * b2);
t_1 = (a1 / (b1 / a2)) / b2;
tmp = 0.0;
if (t_0 <= -1e+294)
tmp = t_1;
elseif (t_0 <= -2e-268)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = t_1;
elseif (t_0 <= 2e+244)
tmp = t_0;
else
tmp = (a1 / b1) * (a2 / b2);
end
tmp_2 = tmp;
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 / N[(b1 / a2), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+294], t$95$1, If[LessEqual[t$95$0, -2e-268], t$95$0, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 2e+244], t$95$0, N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{\frac{a1}{\frac{b1}{a2}}}{b2}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+294}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-268}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+244}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.00000000000000007e294 or -1.99999999999999992e-268 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0Initial program 85.6%
frac-2neg85.6%
div-inv84.9%
*-commutative84.9%
distribute-rgt-neg-in84.9%
*-commutative84.9%
Applied egg-rr84.9%
un-div-inv85.6%
distribute-rgt-neg-out85.6%
frac-2neg85.6%
associate-/l/95.6%
associate-*l/97.5%
clear-num97.5%
associate-*l/97.5%
*-un-lft-identity97.5%
Applied egg-rr97.5%
if -1.00000000000000007e294 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999992e-268 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.00000000000000015e244Initial program 97.8%
if 2.00000000000000015e244 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 64.1%
times-frac99.8%
Simplified99.8%
Final simplification97.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 (/ (* a1 a2) (* b1 b2))))
(if (or (<= t_0 -1e+294)
(and (not (<= t_0 -2e-323))
(or (<= t_0 0.0) (not (<= t_0 2e+244)))))
(* (/ a1 b1) (/ a2 b2))
t_0)))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 <= -1e+294) || (!(t_0 <= -2e-323) && ((t_0 <= 0.0) || !(t_0 <= 2e+244)))) {
tmp = (a1 / b1) * (a2 / 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 * a2) / (b1 * b2)
if ((t_0 <= (-1d+294)) .or. (.not. (t_0 <= (-2d-323))) .and. (t_0 <= 0.0d0) .or. (.not. (t_0 <= 2d+244))) then
tmp = (a1 / b1) * (a2 / 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 * a2) / (b1 * b2);
double tmp;
if ((t_0 <= -1e+294) || (!(t_0 <= -2e-323) && ((t_0 <= 0.0) || !(t_0 <= 2e+244)))) {
tmp = (a1 / b1) * (a2 / 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 * a2) / (b1 * b2) tmp = 0 if (t_0 <= -1e+294) or (not (t_0 <= -2e-323) and ((t_0 <= 0.0) or not (t_0 <= 2e+244))): tmp = (a1 / b1) * (a2 / 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(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if ((t_0 <= -1e+294) || (!(t_0 <= -2e-323) && ((t_0 <= 0.0) || !(t_0 <= 2e+244)))) tmp = Float64(Float64(a1 / b1) * Float64(a2 / 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 * a2) / (b1 * b2);
tmp = 0.0;
if ((t_0 <= -1e+294) || (~((t_0 <= -2e-323)) && ((t_0 <= 0.0) || ~((t_0 <= 2e+244)))))
tmp = (a1 / b1) * (a2 / 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[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -1e+294], And[N[Not[LessEqual[t$95$0, -2e-323]], $MachinePrecision], Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 2e+244]], $MachinePrecision]]]], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / 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 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+294} \lor \neg \left(t_0 \leq -2 \cdot 10^{-323}\right) \land \left(t_0 \leq 0 \lor \neg \left(t_0 \leq 2 \cdot 10^{+244}\right)\right):\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.00000000000000007e294 or -1.97626e-323 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0 or 2.00000000000000015e244 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 79.9%
times-frac96.7%
Simplified96.7%
if -1.00000000000000007e294 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.97626e-323 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.00000000000000015e244Initial program 97.8%
Final simplification97.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 (if (<= a2 3.05e+136) (* (/ a1 b1) (/ a2 b2)) (if (<= a2 1.9e+273) (* (/ a2 b1) (/ a1 b2)) (* a1 (/ (/ a2 b2) b1)))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (a2 <= 3.05e+136) {
tmp = (a1 / b1) * (a2 / b2);
} else if (a2 <= 1.9e+273) {
tmp = (a2 / b1) * (a1 / b2);
} else {
tmp = a1 * ((a2 / b2) / 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 (a2 <= 3.05d+136) then
tmp = (a1 / b1) * (a2 / b2)
else if (a2 <= 1.9d+273) then
tmp = (a2 / b1) * (a1 / b2)
else
tmp = a1 * ((a2 / b2) / 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 (a2 <= 3.05e+136) {
tmp = (a1 / b1) * (a2 / b2);
} else if (a2 <= 1.9e+273) {
tmp = (a2 / b1) * (a1 / b2);
} else {
tmp = a1 * ((a2 / b2) / b1);
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if a2 <= 3.05e+136: tmp = (a1 / b1) * (a2 / b2) elif a2 <= 1.9e+273: tmp = (a2 / b1) * (a1 / b2) else: tmp = a1 * ((a2 / b2) / b1) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (a2 <= 3.05e+136) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); elseif (a2 <= 1.9e+273) tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2)); else tmp = Float64(a1 * Float64(Float64(a2 / b2) / 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 (a2 <= 3.05e+136)
tmp = (a1 / b1) * (a2 / b2);
elseif (a2 <= 1.9e+273)
tmp = (a2 / b1) * (a1 / b2);
else
tmp = a1 * ((a2 / b2) / 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[a2, 3.05e+136], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[a2, 1.9e+273], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], 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])\\
\\
\begin{array}{l}
\mathbf{if}\;a2 \leq 3.05 \cdot 10^{+136}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{elif}\;a2 \leq 1.9 \cdot 10^{+273}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\end{array}
\end{array}
if a2 < 3.0499999999999998e136Initial program 87.1%
times-frac89.0%
Simplified89.0%
if 3.0499999999999998e136 < a2 < 1.9e273Initial program 93.2%
*-commutative93.2%
times-frac90.1%
Applied egg-rr90.1%
if 1.9e273 < a2 Initial program 78.4%
times-frac88.7%
associate-*l/68.1%
associate-*r/89.0%
Simplified89.0%
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 (<= b2 20500.0) (* a1 (/ (/ a2 b2) b1)) (/ a2 (* b2 (/ b1 a1)))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b2 <= 20500.0) {
tmp = a1 * ((a2 / b2) / b1);
} else {
tmp = a2 / (b2 * (b1 / a1));
}
return tmp;
}
NOTE: a1 and a2 should be sorted in increasing order before calling this function.
NOTE: b1 and b2 should be sorted in increasing order before calling this function.
real(8) function code(a1, a2, b1, b2)
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
real(8) :: tmp
if (b2 <= 20500.0d0) then
tmp = a1 * ((a2 / b2) / b1)
else
tmp = a2 / (b2 * (b1 / a1))
end if
code = tmp
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b2 <= 20500.0) {
tmp = a1 * ((a2 / b2) / b1);
} else {
tmp = a2 / (b2 * (b1 / a1));
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if b2 <= 20500.0: tmp = a1 * ((a2 / b2) / b1) else: tmp = a2 / (b2 * (b1 / a1)) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (b2 <= 20500.0) tmp = Float64(a1 * Float64(Float64(a2 / b2) / b1)); else tmp = Float64(a2 / Float64(b2 * Float64(b1 / a1))); end return tmp end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
tmp = 0.0;
if (b2 <= 20500.0)
tmp = a1 * ((a2 / b2) / b1);
else
tmp = a2 / (b2 * (b1 / a1));
end
tmp_2 = tmp;
end
NOTE: a1 and a2 should be sorted in increasing order before calling this function. NOTE: b1 and b2 should be sorted in increasing order before calling this function. code[a1_, a2_, b1_, b2_] := If[LessEqual[b2, 20500.0], N[(a1 * N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision], N[(a2 / N[(b2 * N[(b1 / a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;b2 \leq 20500:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\
\end{array}
\end{array}
if b2 < 20500Initial program 87.6%
times-frac90.8%
associate-*l/88.4%
associate-*r/89.6%
Simplified89.6%
if 20500 < b2 Initial program 87.0%
times-frac85.0%
associate-*l/81.5%
associate-*r/88.1%
Simplified88.1%
associate-*r/81.5%
associate-*l/85.0%
clear-num84.9%
frac-times91.7%
*-un-lft-identity91.7%
Applied egg-rr91.7%
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 (* 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 87.5%
times-frac89.4%
associate-*l/86.8%
associate-*r/89.3%
Simplified89.3%
Final simplification89.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 2023312
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))