
(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 (- INFINITY))
(/ a1 (* b1 (/ b2 a2)))
(if (<= t_0 -5e-279)
t_0
(if (<= t_0 0.0)
(* (/ a1 b1) (/ a2 b2))
(if (<= t_0 1e+293) t_0 (/ (* a1 (/ (- a2) b2)) (- 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 <= -((double) INFINITY)) {
tmp = a1 / (b1 * (b2 / a2));
} else if (t_0 <= -5e-279) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+293) {
tmp = t_0;
} else {
tmp = (a1 * (-a2 / b2)) / -b1;
}
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 tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = a1 / (b1 * (b2 / a2));
} else if (t_0 <= -5e-279) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+293) {
tmp = t_0;
} else {
tmp = (a1 * (-a2 / b2)) / -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 <= -math.inf: tmp = a1 / (b1 * (b2 / a2)) elif t_0 <= -5e-279: tmp = t_0 elif t_0 <= 0.0: tmp = (a1 / b1) * (a2 / b2) elif t_0 <= 1e+293: tmp = t_0 else: tmp = (a1 * (-a2 / b2)) / -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 <= Float64(-Inf)) tmp = Float64(a1 / Float64(b1 * Float64(b2 / a2))); elseif (t_0 <= -5e-279) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); elseif (t_0 <= 1e+293) tmp = t_0; else tmp = Float64(Float64(a1 * Float64(Float64(-a2) / b2)) / Float64(-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 <= -Inf)
tmp = a1 / (b1 * (b2 / a2));
elseif (t_0 <= -5e-279)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a1 / b1) * (a2 / b2);
elseif (t_0 <= 1e+293)
tmp = t_0;
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_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(a1 / N[(b1 * N[(b2 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e-279], 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+293], t$95$0, N[(N[(a1 * N[((-a2) / b2), $MachinePrecision]), $MachinePrecision] / (-b1)), $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 -\infty:\\
\;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-279}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+293}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1 \cdot \frac{-a2}{b2}}{-b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0Initial program 79.0%
times-frac91.4%
associate-*l/95.6%
associate-*r/91.8%
Simplified91.8%
associate-*r/95.6%
associate-*l/91.4%
*-commutative91.4%
clear-num91.4%
frac-times91.9%
*-un-lft-identity91.9%
Applied egg-rr91.9%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999999999969e-279 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999992e292Initial program 99.1%
if -4.99999999999999969e-279 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0Initial program 70.3%
times-frac93.3%
Simplified93.3%
if 9.9999999999999992e292 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 62.8%
times-frac92.2%
associate-*l/95.9%
associate-*r/90.3%
Simplified90.3%
*-commutative90.3%
frac-2neg90.3%
associate-*l/95.9%
distribute-neg-frac95.9%
Applied egg-rr95.9%
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))) (t_1 (/ a1 (* b1 (/ b2 a2)))))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -5e-279)
t_0
(if (<= t_0 0.0)
(* (/ a1 b1) (/ a2 b2))
(if (<= t_0 1e+293) 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 * (b2 / a2));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -5e-279) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+293) {
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 * (b2 / a2));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= -5e-279) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+293) {
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 * (b2 / a2)) tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= -5e-279: tmp = t_0 elif t_0 <= 0.0: tmp = (a1 / b1) * (a2 / b2) elif t_0 <= 1e+293: 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(a1 / Float64(b1 * Float64(b2 / a2))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -5e-279) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); elseif (t_0 <= 1e+293) 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 * (b2 / a2));
tmp = 0.0;
if (t_0 <= -Inf)
tmp = t_1;
elseif (t_0 <= -5e-279)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a1 / b1) * (a2 / b2);
elseif (t_0 <= 1e+293)
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[(a1 / N[(b1 * N[(b2 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -5e-279], 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+293], 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{b2}{a2}}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-279}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+293}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or 9.9999999999999992e292 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 67.7%
times-frac92.0%
associate-*l/95.8%
associate-*r/90.8%
Simplified90.8%
associate-*r/95.8%
associate-*l/92.0%
*-commutative92.0%
clear-num92.0%
frac-times90.8%
*-un-lft-identity90.8%
Applied egg-rr90.8%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999999999969e-279 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999992e292Initial program 99.1%
if -4.99999999999999969e-279 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0Initial program 70.3%
times-frac93.3%
Simplified93.3%
Final simplification95.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 (/ (* a1 a2) (* b1 b2))))
(if (<= t_0 (- INFINITY))
(/ a1 (* b1 (/ b2 a2)))
(if (<= t_0 -5e-279)
t_0
(if (<= t_0 0.0)
(* (/ a1 b1) (/ a2 b2))
(if (<= t_0 1e+293) 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 <= -((double) INFINITY)) {
tmp = a1 / (b1 * (b2 / a2));
} else if (t_0 <= -5e-279) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+293) {
tmp = t_0;
} else {
tmp = (a1 / (b2 / a2)) / b1;
}
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 tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = a1 / (b1 * (b2 / a2));
} else if (t_0 <= -5e-279) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = (a1 / b1) * (a2 / b2);
} else if (t_0 <= 1e+293) {
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 <= -math.inf: tmp = a1 / (b1 * (b2 / a2)) elif t_0 <= -5e-279: tmp = t_0 elif t_0 <= 0.0: tmp = (a1 / b1) * (a2 / b2) elif t_0 <= 1e+293: 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 <= Float64(-Inf)) tmp = Float64(a1 / Float64(b1 * Float64(b2 / a2))); elseif (t_0 <= -5e-279) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); elseif (t_0 <= 1e+293) tmp = t_0; else tmp = Float64(Float64(a1 / Float64(b2 / 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 <= -Inf)
tmp = a1 / (b1 * (b2 / a2));
elseif (t_0 <= -5e-279)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = (a1 / b1) * (a2 / b2);
elseif (t_0 <= 1e+293)
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, (-Infinity)], N[(a1 / N[(b1 * N[(b2 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e-279], 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+293], t$95$0, N[(N[(a1 / N[(b2 / a2), $MachinePrecision]), $MachinePrecision] / b1), $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 -\infty:\\
\;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-279}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{elif}\;t_0 \leq 10^{+293}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{a1}{\frac{b2}{a2}}}{b1}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0Initial program 79.0%
times-frac91.4%
associate-*l/95.6%
associate-*r/91.8%
Simplified91.8%
associate-*r/95.6%
associate-*l/91.4%
*-commutative91.4%
clear-num91.4%
frac-times91.9%
*-un-lft-identity91.9%
Applied egg-rr91.9%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.99999999999999969e-279 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999992e292Initial program 99.1%
if -4.99999999999999969e-279 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0Initial program 70.3%
times-frac93.3%
Simplified93.3%
if 9.9999999999999992e292 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 62.8%
times-frac92.2%
associate-*l/95.9%
associate-*r/90.3%
Simplified90.3%
associate-*r/95.9%
clear-num95.9%
un-div-inv97.3%
Applied egg-rr97.3%
Final simplification96.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 (<= a1 -7.5e+23) (* (/ a1 b1) (/ a2 b2)) (* (/ a2 b1) (/ a1 b2))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (a1 <= -7.5e+23) {
tmp = (a1 / b1) * (a2 / 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 (a1 <= (-7.5d+23)) then
tmp = (a1 / b1) * (a2 / 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 (a1 <= -7.5e+23) {
tmp = (a1 / b1) * (a2 / 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 a1 <= -7.5e+23: tmp = (a1 / b1) * (a2 / 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 (a1 <= -7.5e+23) tmp = Float64(Float64(a1 / b1) * Float64(a2 / 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 (a1 <= -7.5e+23)
tmp = (a1 / b1) * (a2 / 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[LessEqual[a1, -7.5e+23], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $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}\;a1 \leq -7.5 \cdot 10^{+23}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if a1 < -7.49999999999999987e23Initial program 77.8%
times-frac82.4%
Simplified82.4%
if -7.49999999999999987e23 < a1 Initial program 85.4%
times-frac85.2%
associate-*l/87.9%
associate-*r/84.6%
Simplified84.6%
Taylor expanded in a1 around 0 85.4%
*-commutative85.4%
times-frac88.2%
Simplified88.2%
Final simplification86.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 (* 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 83.6%
times-frac84.5%
associate-*l/88.8%
associate-*r/84.1%
Simplified84.1%
Final simplification84.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 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 83.6%
times-frac84.5%
Simplified84.5%
Final simplification84.5%
(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 2023305
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))