
(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))))
(if (<= t_0 -5e+270)
(* a2 (/ (/ a1 b2) b1))
(if (<= t_0 -2e-309)
t_0
(if (<= t_0 0.0)
(* (/ a1 b1) (/ a2 b2))
(if (<= t_0 1e+275) t_0 (/ (/ a1 b2) (/ b1 a2))))))))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+270) {
tmp = a2 * ((a1 / b2) / b1);
} else if (t_0 <= -2e-309) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+275) {
tmp = t_0;
} else {
tmp = (a1 / b2) / (b1 / a2);
}
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+270)) then
tmp = a2 * ((a1 / b2) / b1)
else if (t_0 <= (-2d-309)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = (a1 / b1) * (a2 / b2)
else if (t_0 <= 1d+275) then
tmp = t_0
else
tmp = (a1 / b2) / (b1 / a2)
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+270) {
tmp = a2 * ((a1 / b2) / b1);
} else if (t_0 <= -2e-309) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+275) {
tmp = t_0;
} else {
tmp = (a1 / b2) / (b1 / a2);
}
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+270: tmp = a2 * ((a1 / b2) / b1) elif t_0 <= -2e-309: tmp = t_0 elif t_0 <= 0.0: tmp = (a1 / b1) * (a2 / b2) elif t_0 <= 1e+275: tmp = t_0 else: tmp = (a1 / b2) / (b1 / a2) 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+270) tmp = Float64(a2 * Float64(Float64(a1 / b2) / b1)); elseif (t_0 <= -2e-309) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); elseif (t_0 <= 1e+275) tmp = t_0; else tmp = Float64(Float64(a1 / b2) / Float64(b1 / a2)); 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+270)
tmp = a2 * ((a1 / b2) / b1);
elseif (t_0 <= -2e-309)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a1 / b1) * (a2 / b2);
elseif (t_0 <= 1e+275)
tmp = t_0;
else
tmp = (a1 / b2) / (b1 / a2);
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+270], N[(a2 * N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -2e-309], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+275], t$95$0, N[(N[(a1 / b2), $MachinePrecision] / N[(b1 / a2), $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^{+270}:\\
\;\;\;\;a2 \cdot \frac{\frac{a1}{b2}}{b1}\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-309}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+275}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999999999976e270Initial program 81.3%
times-frac95.8%
Simplified95.8%
frac-times81.3%
*-commutative81.3%
frac-times92.0%
clear-num92.0%
un-div-inv94.5%
Applied egg-rr94.5%
Taylor expanded in a1 around 0 81.3%
associate-*l/87.6%
*-commutative87.6%
associate-/r*97.9%
Simplified97.9%
if -4.99999999999999976e270 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.9999999999999988e-309 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999996e274Initial program 98.8%
if -1.9999999999999988e-309 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0Initial program 75.4%
times-frac98.1%
Simplified98.1%
if 9.9999999999999996e274 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 59.1%
times-frac97.7%
Simplified97.7%
frac-times59.1%
*-commutative59.1%
frac-times97.7%
clear-num97.8%
un-div-inv97.7%
Applied egg-rr97.7%
Final simplification98.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 a2) (* b1 b2))))
(if (<= t_0 -5e+270)
(* a2 (/ (/ a1 b2) b1))
(if (<= t_0 -2e-309)
t_0
(if (<= t_0 0.0)
(* (/ a1 b1) (/ a2 b2))
(if (<= t_0 1e+275) 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 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -5e+270) {
tmp = a2 * ((a1 / b2) / b1);
} else if (t_0 <= -2e-309) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+275) {
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) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
if (t_0 <= (-5d+270)) then
tmp = a2 * ((a1 / b2) / b1)
else if (t_0 <= (-2d-309)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = (a1 / b1) * (a2 / b2)
else if (t_0 <= 1d+275) 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 = (a1 * a2) / (b1 * b2);
double tmp;
if (t_0 <= -5e+270) {
tmp = a2 * ((a1 / b2) / b1);
} else if (t_0 <= -2e-309) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+275) {
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 = (a1 * a2) / (b1 * b2) tmp = 0 if t_0 <= -5e+270: tmp = a2 * ((a1 / b2) / b1) elif t_0 <= -2e-309: tmp = t_0 elif t_0 <= 0.0: tmp = (a1 / b1) * (a2 / b2) elif t_0 <= 1e+275: 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(Float64(a1 * a2) / Float64(b1 * b2)) tmp = 0.0 if (t_0 <= -5e+270) tmp = Float64(a2 * Float64(Float64(a1 / b2) / b1)); elseif (t_0 <= -2e-309) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); elseif (t_0 <= 1e+275) tmp = t_0; else tmp = Float64(Float64(a1 / 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 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if (t_0 <= -5e+270)
tmp = a2 * ((a1 / b2) / b1);
elseif (t_0 <= -2e-309)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a1 / b1) * (a2 / b2);
elseif (t_0 <= 1e+275)
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[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+270], N[(a2 * N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -2e-309], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+275], t$95$0, N[(N[(a1 / b2), $MachinePrecision] * N[(a2 / b1), $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^{+270}:\\
\;\;\;\;a2 \cdot \frac{\frac{a1}{b2}}{b1}\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-309}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+275}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b2} \cdot \frac{a2}{b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999999999976e270Initial program 81.3%
times-frac95.8%
Simplified95.8%
frac-times81.3%
*-commutative81.3%
frac-times92.0%
clear-num92.0%
un-div-inv94.5%
Applied egg-rr94.5%
Taylor expanded in a1 around 0 81.3%
associate-*l/87.6%
*-commutative87.6%
associate-/r*97.9%
Simplified97.9%
if -4.99999999999999976e270 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.9999999999999988e-309 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999996e274Initial program 98.8%
if -1.9999999999999988e-309 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0Initial program 75.4%
times-frac98.1%
Simplified98.1%
if 9.9999999999999996e274 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 59.1%
associate-/l*62.2%
*-commutative62.2%
associate-/l*97.7%
Simplified97.7%
associate-/r/97.7%
*-commutative97.7%
Applied egg-rr97.7%
Final simplification98.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 (<= b2 3.4e+207) (* a2 (/ (/ a1 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 (b2 <= 3.4e+207) {
tmp = a2 * ((a1 / 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 (b2 <= 3.4d+207) then
tmp = a2 * ((a1 / 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 (b2 <= 3.4e+207) {
tmp = a2 * ((a1 / 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 b2 <= 3.4e+207: tmp = a2 * ((a1 / 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 (b2 <= 3.4e+207) tmp = Float64(a2 * Float64(Float64(a1 / 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 (b2 <= 3.4e+207)
tmp = a2 * ((a1 / 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[b2, 3.4e+207], N[(a2 * N[(N[(a1 / 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}\;b2 \leq 3.4 \cdot 10^{+207}:\\
\;\;\;\;a2 \cdot \frac{\frac{a1}{b2}}{b1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if b2 < 3.3999999999999998e207Initial program 84.1%
times-frac88.3%
Simplified88.3%
frac-times84.1%
*-commutative84.1%
frac-times90.1%
clear-num90.1%
un-div-inv90.5%
Applied egg-rr90.5%
Taylor expanded in a1 around 0 84.1%
associate-*l/85.3%
*-commutative85.3%
associate-/r*89.1%
Simplified89.1%
if 3.3999999999999998e207 < b2 Initial program 78.6%
times-frac73.9%
Simplified73.9%
Final simplification88.0%
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 3.8e+195) (* (/ a1 b2) (/ a2 b1)) (* (/ a1 b1) (/ a2 b2))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b2 <= 3.8e+195) {
tmp = (a1 / b2) * (a2 / 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 (b2 <= 3.8d+195) then
tmp = (a1 / b2) * (a2 / 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 (b2 <= 3.8e+195) {
tmp = (a1 / b2) * (a2 / 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 b2 <= 3.8e+195: tmp = (a1 / b2) * (a2 / 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 (b2 <= 3.8e+195) tmp = Float64(Float64(a1 / b2) * Float64(a2 / 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 (b2 <= 3.8e+195)
tmp = (a1 / b2) * (a2 / 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[b2, 3.8e+195], N[(N[(a1 / b2), $MachinePrecision] * N[(a2 / 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}\;b2 \leq 3.8 \cdot 10^{+195}:\\
\;\;\;\;\frac{a1}{b2} \cdot \frac{a2}{b1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if b2 < 3.8e195Initial program 83.8%
associate-/l*81.4%
*-commutative81.4%
associate-/l*87.8%
Simplified87.8%
associate-/r/90.8%
*-commutative90.8%
Applied egg-rr90.8%
if 3.8e195 < b2 Initial program 82.4%
times-frac74.3%
Simplified74.3%
Final simplification89.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 (* a2 (/ (/ a1 b2) b1)))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
return a2 * ((a1 / 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 = a2 * ((a1 / b2) / b1)
end function
assert a1 < a2;
assert b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
return a2 * ((a1 / b2) / b1);
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): return a2 * ((a1 / b2) / b1)
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) return Float64(a2 * Float64(Float64(a1 / b2) / b1)) end
a1, a2 = num2cell(sort([a1, a2])){:}
b1, b2 = num2cell(sort([b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
tmp = a2 * ((a1 / 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[(a2 * N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
a2 \cdot \frac{\frac{a1}{b2}}{b1}
\end{array}
Initial program 83.7%
times-frac87.3%
Simplified87.3%
frac-times83.7%
*-commutative83.7%
frac-times90.6%
clear-num90.5%
un-div-inv91.0%
Applied egg-rr91.0%
Taylor expanded in a1 around 0 83.7%
associate-*l/84.8%
*-commutative84.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 2023185
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))