
(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 (/ (- a2) b2)) (- b1))))
(if (<= t_0 -5e+291)
t_1
(if (<= t_0 -2e-265)
t_0
(if (<= t_0 4e-268)
t_1
(if (<= t_0 5e+253) t_0 (* (/ a2 b1) (/ a1 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 * (-a2 / b2)) / -b1;
double tmp;
if (t_0 <= -5e+291) {
tmp = t_1;
} else if (t_0 <= -2e-265) {
tmp = t_0;
} else if (t_0 <= 4e-268) {
tmp = t_1;
} else if (t_0 <= 5e+253) {
tmp = t_0;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
t_1 = (a1 * (-a2 / b2)) / -b1
if (t_0 <= (-5d+291)) then
tmp = t_1
else if (t_0 <= (-2d-265)) then
tmp = t_0
else if (t_0 <= 4d-268) then
tmp = t_1
else if (t_0 <= 5d+253) then
tmp = t_0
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 t_0 = (a1 * a2) / (b1 * b2);
double t_1 = (a1 * (-a2 / b2)) / -b1;
double tmp;
if (t_0 <= -5e+291) {
tmp = t_1;
} else if (t_0 <= -2e-265) {
tmp = t_0;
} else if (t_0 <= 4e-268) {
tmp = t_1;
} else if (t_0 <= 5e+253) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / 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 * (-a2 / b2)) / -b1 tmp = 0 if t_0 <= -5e+291: tmp = t_1 elif t_0 <= -2e-265: tmp = t_0 elif t_0 <= 4e-268: tmp = t_1 elif t_0 <= 5e+253: tmp = t_0 else: tmp = (a2 / b1) * (a1 / 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(Float64(-a2) / b2)) / Float64(-b1)) tmp = 0.0 if (t_0 <= -5e+291) tmp = t_1; elseif (t_0 <= -2e-265) tmp = t_0; elseif (t_0 <= 4e-268) tmp = t_1; elseif (t_0 <= 5e+253) tmp = t_0; 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)
t_0 = (a1 * a2) / (b1 * b2);
t_1 = (a1 * (-a2 / b2)) / -b1;
tmp = 0.0;
if (t_0 <= -5e+291)
tmp = t_1;
elseif (t_0 <= -2e-265)
tmp = t_0;
elseif (t_0 <= 4e-268)
tmp = t_1;
elseif (t_0 <= 5e+253)
tmp = t_0;
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_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 * N[((-a2) / b2), $MachinePrecision]), $MachinePrecision] / (-b1)), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+291], t$95$1, If[LessEqual[t$95$0, -2e-265], t$95$0, If[LessEqual[t$95$0, 4e-268], t$95$1, If[LessEqual[t$95$0, 5e+253], t$95$0, 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}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a1 \cdot \frac{-a2}{b2}}{-b1}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+291}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-265}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-268}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+253}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -5.0000000000000001e291 or -1.99999999999999997e-265 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 3.99999999999999983e-268Initial program 79.6%
times-frac95.3%
associate-*l/98.1%
associate-*r/95.9%
Simplified95.9%
*-commutative95.9%
frac-2neg95.9%
associate-*l/98.1%
distribute-neg-frac98.1%
Applied egg-rr98.1%
if -5.0000000000000001e291 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999997e-265 or 3.99999999999999983e-268 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999997e253Initial program 98.7%
if 4.9999999999999997e253 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 57.1%
times-frac97.6%
associate-*l/89.0%
associate-*r/88.9%
Simplified88.9%
Taylor expanded in a1 around 0 57.1%
*-commutative57.1%
times-frac97.6%
Simplified97.6%
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))) (t_1 (* (/ a1 b1) (/ a2 b2))))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -2e-265)
t_0
(if (<= t_0 0.0)
t_1
(if (<= t_0 5e+253) t_0 (* (/ a2 b1) (/ a1 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 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -2e-265) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 5e+253) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / b2);
}
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 <= -2e-265) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 5e+253) {
tmp = t_0;
} else {
tmp = (a2 / b1) * (a1 / 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 <= -math.inf: tmp = t_1 elif t_0 <= -2e-265: tmp = t_0 elif t_0 <= 0.0: tmp = t_1 elif t_0 <= 5e+253: tmp = t_0 else: tmp = (a2 / b1) * (a1 / 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 / b1) * Float64(a2 / b2)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -2e-265) tmp = t_0; elseif (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 5e+253) tmp = t_0; 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)
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 <= -2e-265)
tmp = t_0;
elseif (t_0 <= 0.0)
tmp = t_1;
elseif (t_0 <= 5e+253)
tmp = t_0;
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_] := 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, -2e-265], t$95$0, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 5e+253], t$95$0, 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}
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 -2 \cdot 10^{-265}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+253}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or -1.99999999999999997e-265 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0Initial program 77.9%
times-frac95.9%
Simplified95.9%
if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999997e-265 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999997e253Initial program 98.7%
if 4.9999999999999997e253 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 57.1%
times-frac97.6%
associate-*l/89.0%
associate-*r/88.9%
Simplified88.9%
Taylor expanded in a1 around 0 57.1%
*-commutative57.1%
times-frac97.6%
Simplified97.6%
Final simplification97.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 (if (<= a2 5.8e+42) (* (/ a1 b1) (/ a2 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 <= 5.8e+42) {
tmp = (a1 / b1) * (a2 / 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 <= 5.8d+42) then
tmp = (a1 / b1) * (a2 / 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 <= 5.8e+42) {
tmp = (a1 / b1) * (a2 / 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 <= 5.8e+42: tmp = (a1 / b1) * (a2 / 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 <= 5.8e+42) tmp = Float64(Float64(a1 / b1) * Float64(a2 / 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 <= 5.8e+42)
tmp = (a1 / b1) * (a2 / 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, 5.8e+42], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / 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 5.8 \cdot 10^{+42}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\end{array}
\end{array}
if a2 < 5.79999999999999961e42Initial program 85.0%
times-frac88.7%
Simplified88.7%
if 5.79999999999999961e42 < a2 Initial program 80.8%
times-frac86.4%
associate-*l/89.1%
associate-*r/88.1%
Simplified88.1%
Final simplification88.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 (if (<= a2 8.2e+42) (* (/ a1 b1) (/ a2 b2)) (/ a1 (* b1 (/ b2 a2)))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (a2 <= 8.2e+42) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a1 / (b1 * (b2 / 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) :: tmp
if (a2 <= 8.2d+42) then
tmp = (a1 / b1) * (a2 / b2)
else
tmp = a1 / (b1 * (b2 / 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 tmp;
if (a2 <= 8.2e+42) {
tmp = (a1 / b1) * (a2 / b2);
} else {
tmp = a1 / (b1 * (b2 / a2));
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if a2 <= 8.2e+42: tmp = (a1 / b1) * (a2 / b2) else: tmp = a1 / (b1 * (b2 / a2)) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (a2 <= 8.2e+42) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); else tmp = Float64(a1 / Float64(b1 * Float64(b2 / 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)
tmp = 0.0;
if (a2 <= 8.2e+42)
tmp = (a1 / b1) * (a2 / b2);
else
tmp = a1 / (b1 * (b2 / 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_] := If[LessEqual[a2, 8.2e+42], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], N[(a1 / N[(b1 * N[(b2 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;a2 \leq 8.2 \cdot 10^{+42}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\
\end{array}
\end{array}
if a2 < 8.2000000000000001e42Initial program 85.0%
times-frac88.7%
Simplified88.7%
if 8.2000000000000001e42 < a2 Initial program 80.8%
times-frac86.4%
associate-*l/89.1%
associate-*r/88.1%
Simplified88.1%
associate-*r/89.1%
associate-*l/86.4%
*-commutative86.4%
clear-num86.2%
frac-times88.0%
*-un-lft-identity88.0%
Applied egg-rr88.0%
Final simplification88.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 (if (<= a2 23.0) (/ a2 (* b2 (/ b1 a1))) (/ a1 (* b1 (/ b2 a2)))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (a2 <= 23.0) {
tmp = a2 / (b2 * (b1 / a1));
} else {
tmp = a1 / (b1 * (b2 / 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) :: tmp
if (a2 <= 23.0d0) then
tmp = a2 / (b2 * (b1 / a1))
else
tmp = a1 / (b1 * (b2 / 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 tmp;
if (a2 <= 23.0) {
tmp = a2 / (b2 * (b1 / a1));
} else {
tmp = a1 / (b1 * (b2 / a2));
}
return tmp;
}
[a1, a2] = sort([a1, a2]) [b1, b2] = sort([b1, b2]) def code(a1, a2, b1, b2): tmp = 0 if a2 <= 23.0: tmp = a2 / (b2 * (b1 / a1)) else: tmp = a1 / (b1 * (b2 / a2)) return tmp
a1, a2 = sort([a1, a2]) b1, b2 = sort([b1, b2]) function code(a1, a2, b1, b2) tmp = 0.0 if (a2 <= 23.0) tmp = Float64(a2 / Float64(b2 * Float64(b1 / a1))); else tmp = Float64(a1 / Float64(b1 * Float64(b2 / 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)
tmp = 0.0;
if (a2 <= 23.0)
tmp = a2 / (b2 * (b1 / a1));
else
tmp = a1 / (b1 * (b2 / 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_] := If[LessEqual[a2, 23.0], N[(a2 / N[(b2 * N[(b1 / a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a1 / N[(b1 * N[(b2 / a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;a2 \leq 23:\\
\;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\
\end{array}
\end{array}
if a2 < 23Initial program 84.9%
times-frac87.9%
associate-*l/90.1%
associate-*r/84.7%
Simplified84.7%
associate-*r/90.1%
associate-*l/87.9%
clear-num87.6%
frac-times87.9%
*-un-lft-identity87.9%
Applied egg-rr87.9%
if 23 < a2 Initial program 82.0%
times-frac89.3%
associate-*l/87.0%
associate-*r/89.1%
Simplified89.1%
associate-*r/87.0%
associate-*l/89.3%
*-commutative89.3%
clear-num89.1%
frac-times89.1%
*-un-lft-identity89.1%
Applied egg-rr89.1%
Final simplification88.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 (* 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 84.2%
times-frac88.2%
associate-*l/89.4%
associate-*r/85.8%
Simplified85.8%
Final simplification85.8%
(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 2023310
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))