
(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 4 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}
a1\_m = (fabs.f64 a1) a1\_s = (copysign.f64 #s(literal 1 binary64) a1) a2\_m = (fabs.f64 a2) a2\_s = (copysign.f64 #s(literal 1 binary64) a2) b1\_m = (fabs.f64 b1) b1\_s = (copysign.f64 #s(literal 1 binary64) b1) b2\_m = (fabs.f64 b2) b2\_s = (copysign.f64 #s(literal 1 binary64) b2) NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function. NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function. (FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m) :precision binary64 (* b2_s (* b1_s (* a2_s (* a1_s (/ (/ a1_m b1_m) (/ b2_m a2_m)))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) / (b2_m / a2_m)))));
}
a1\_m = abs(a1)
a1\_s = copysign(1.0d0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0d0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0d0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0d0, b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
real(8) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
real(8), intent (in) :: b2_s
real(8), intent (in) :: b1_s
real(8), intent (in) :: a2_s
real(8), intent (in) :: a1_s
real(8), intent (in) :: a1_m
real(8), intent (in) :: a2_m
real(8), intent (in) :: b1_m
real(8), intent (in) :: b2_m
code = b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) / (b2_m / a2_m)))))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) / (b2_m / a2_m)))));
}
a1\_m = math.fabs(a1) a1\_s = math.copysign(1.0, a1) a2\_m = math.fabs(a2) a2\_s = math.copysign(1.0, a2) b1\_m = math.fabs(b1) b1\_s = math.copysign(1.0, b1) b2\_m = math.fabs(b2) b2\_s = math.copysign(1.0, b2) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m): return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) / (b2_m / a2_m)))))
a1\_m = abs(a1) a1\_s = copysign(1.0, a1) a2\_m = abs(a2) a2\_s = copysign(1.0, a2) b1\_m = abs(b1) b1\_s = copysign(1.0, b1) b2\_m = abs(b2) b2\_s = copysign(1.0, b2) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m) return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * Float64(Float64(a1_m / b1_m) / Float64(b2_m / a2_m)))))) end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
tmp = b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) / (b2_m / a2_m)))));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * N[(N[(a1$95$m / b1$95$m), $MachinePrecision] / N[(b2$95$m / a2$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \frac{\frac{a1\_m}{b1\_m}}{\frac{b2\_m}{a2\_m}}\right)\right)\right)
\end{array}
Initial program 88.0%
associate-/l*88.3%
Simplified88.3%
associate-*r/88.0%
frac-times89.6%
clear-num89.1%
un-div-inv89.6%
Applied egg-rr89.6%
Final simplification89.6%
a1\_m = (fabs.f64 a1)
a1\_s = (copysign.f64 #s(literal 1 binary64) a1)
a2\_m = (fabs.f64 a2)
a2\_s = (copysign.f64 #s(literal 1 binary64) a2)
b1\_m = (fabs.f64 b1)
b1\_s = (copysign.f64 #s(literal 1 binary64) b1)
b2\_m = (fabs.f64 b2)
b2\_s = (copysign.f64 #s(literal 1 binary64) b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
(FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m)
:precision binary64
(*
b2_s
(*
b1_s
(*
a2_s
(*
a1_s
(if (or (<= (* b1_m b2_m) 5e-167) (not (<= (* b1_m b2_m) 4e+158)))
(* a1_m (/ (/ a2_m b1_m) b2_m))
(* a1_m (/ a2_m (* b1_m b2_m)))))))))a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
double tmp;
if (((b1_m * b2_m) <= 5e-167) || !((b1_m * b2_m) <= 4e+158)) {
tmp = a1_m * ((a2_m / b1_m) / b2_m);
} else {
tmp = a1_m * (a2_m / (b1_m * b2_m));
}
return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m = abs(a1)
a1\_s = copysign(1.0d0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0d0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0d0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0d0, b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
real(8) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
real(8), intent (in) :: b2_s
real(8), intent (in) :: b1_s
real(8), intent (in) :: a2_s
real(8), intent (in) :: a1_s
real(8), intent (in) :: a1_m
real(8), intent (in) :: a2_m
real(8), intent (in) :: b1_m
real(8), intent (in) :: b2_m
real(8) :: tmp
if (((b1_m * b2_m) <= 5d-167) .or. (.not. ((b1_m * b2_m) <= 4d+158))) then
tmp = a1_m * ((a2_m / b1_m) / b2_m)
else
tmp = a1_m * (a2_m / (b1_m * b2_m))
end if
code = b2_s * (b1_s * (a2_s * (a1_s * tmp)))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
double tmp;
if (((b1_m * b2_m) <= 5e-167) || !((b1_m * b2_m) <= 4e+158)) {
tmp = a1_m * ((a2_m / b1_m) / b2_m);
} else {
tmp = a1_m * (a2_m / (b1_m * b2_m));
}
return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m = math.fabs(a1) a1\_s = math.copysign(1.0, a1) a2\_m = math.fabs(a2) a2\_s = math.copysign(1.0, a2) b1\_m = math.fabs(b1) b1\_s = math.copysign(1.0, b1) b2\_m = math.fabs(b2) b2\_s = math.copysign(1.0, b2) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m): tmp = 0 if ((b1_m * b2_m) <= 5e-167) or not ((b1_m * b2_m) <= 4e+158): tmp = a1_m * ((a2_m / b1_m) / b2_m) else: tmp = a1_m * (a2_m / (b1_m * b2_m)) return b2_s * (b1_s * (a2_s * (a1_s * tmp)))
a1\_m = abs(a1) a1\_s = copysign(1.0, a1) a2\_m = abs(a2) a2\_s = copysign(1.0, a2) b1\_m = abs(b1) b1\_s = copysign(1.0, b1) b2\_m = abs(b2) b2\_s = copysign(1.0, b2) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m) tmp = 0.0 if ((Float64(b1_m * b2_m) <= 5e-167) || !(Float64(b1_m * b2_m) <= 4e+158)) tmp = Float64(a1_m * Float64(Float64(a2_m / b1_m) / b2_m)); else tmp = Float64(a1_m * Float64(a2_m / Float64(b1_m * b2_m))); end return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * tmp)))) end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp_2 = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
tmp = 0.0;
if (((b1_m * b2_m) <= 5e-167) || ~(((b1_m * b2_m) <= 4e+158)))
tmp = a1_m * ((a2_m / b1_m) / b2_m);
else
tmp = a1_m * (a2_m / (b1_m * b2_m));
end
tmp_2 = b2_s * (b1_s * (a2_s * (a1_s * tmp)));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * If[Or[LessEqual[N[(b1$95$m * b2$95$m), $MachinePrecision], 5e-167], N[Not[LessEqual[N[(b1$95$m * b2$95$m), $MachinePrecision], 4e+158]], $MachinePrecision]], N[(a1$95$m * N[(N[(a2$95$m / b1$95$m), $MachinePrecision] / b2$95$m), $MachinePrecision]), $MachinePrecision], N[(a1$95$m * N[(a2$95$m / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l}
\mathbf{if}\;b1\_m \cdot b2\_m \leq 5 \cdot 10^{-167} \lor \neg \left(b1\_m \cdot b2\_m \leq 4 \cdot 10^{+158}\right):\\
\;\;\;\;a1\_m \cdot \frac{\frac{a2\_m}{b1\_m}}{b2\_m}\\
\mathbf{else}:\\
\;\;\;\;a1\_m \cdot \frac{a2\_m}{b1\_m \cdot b2\_m}\\
\end{array}\right)\right)\right)
\end{array}
if (*.f64 b1 b2) < 5.0000000000000002e-167 or 3.99999999999999981e158 < (*.f64 b1 b2) Initial program 85.4%
associate-/l*86.6%
associate-/r*88.6%
Simplified88.6%
if 5.0000000000000002e-167 < (*.f64 b1 b2) < 3.99999999999999981e158Initial program 97.9%
associate-/l*94.5%
Simplified94.5%
Final simplification89.8%
a1\_m = (fabs.f64 a1) a1\_s = (copysign.f64 #s(literal 1 binary64) a1) a2\_m = (fabs.f64 a2) a2\_s = (copysign.f64 #s(literal 1 binary64) a2) b1\_m = (fabs.f64 b1) b1\_s = (copysign.f64 #s(literal 1 binary64) b1) b2\_m = (fabs.f64 b2) b2\_s = (copysign.f64 #s(literal 1 binary64) b2) NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function. NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function. (FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m) :precision binary64 (* b2_s (* b1_s (* a2_s (* a1_s (* a1_m (/ a2_m (* b1_m b2_m))))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
return b2_s * (b1_s * (a2_s * (a1_s * (a1_m * (a2_m / (b1_m * b2_m))))));
}
a1\_m = abs(a1)
a1\_s = copysign(1.0d0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0d0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0d0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0d0, b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
real(8) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
real(8), intent (in) :: b2_s
real(8), intent (in) :: b1_s
real(8), intent (in) :: a2_s
real(8), intent (in) :: a1_s
real(8), intent (in) :: a1_m
real(8), intent (in) :: a2_m
real(8), intent (in) :: b1_m
real(8), intent (in) :: b2_m
code = b2_s * (b1_s * (a2_s * (a1_s * (a1_m * (a2_m / (b1_m * b2_m))))))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
return b2_s * (b1_s * (a2_s * (a1_s * (a1_m * (a2_m / (b1_m * b2_m))))));
}
a1\_m = math.fabs(a1) a1\_s = math.copysign(1.0, a1) a2\_m = math.fabs(a2) a2\_s = math.copysign(1.0, a2) b1\_m = math.fabs(b1) b1\_s = math.copysign(1.0, b1) b2\_m = math.fabs(b2) b2\_s = math.copysign(1.0, b2) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m): return b2_s * (b1_s * (a2_s * (a1_s * (a1_m * (a2_m / (b1_m * b2_m))))))
a1\_m = abs(a1) a1\_s = copysign(1.0, a1) a2\_m = abs(a2) a2\_s = copysign(1.0, a2) b1\_m = abs(b1) b1\_s = copysign(1.0, b1) b2\_m = abs(b2) b2\_s = copysign(1.0, b2) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m) return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * Float64(a1_m * Float64(a2_m / Float64(b1_m * b2_m))))))) end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
tmp = b2_s * (b1_s * (a2_s * (a1_s * (a1_m * (a2_m / (b1_m * b2_m))))));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * N[(a1$95$m * N[(a2$95$m / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \left(a1\_m \cdot \frac{a2\_m}{b1\_m \cdot b2\_m}\right)\right)\right)\right)
\end{array}
Initial program 88.0%
associate-/l*88.3%
Simplified88.3%
Final simplification88.3%
a1\_m = (fabs.f64 a1) a1\_s = (copysign.f64 #s(literal 1 binary64) a1) a2\_m = (fabs.f64 a2) a2\_s = (copysign.f64 #s(literal 1 binary64) a2) b1\_m = (fabs.f64 b1) b1\_s = (copysign.f64 #s(literal 1 binary64) b1) b2\_m = (fabs.f64 b2) b2\_s = (copysign.f64 #s(literal 1 binary64) b2) NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function. NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function. (FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m) :precision binary64 (* b2_s (* b1_s (* a2_s (* a1_s (* (/ a1_m b1_m) (/ a2_m b2_m)))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) * (a2_m / b2_m)))));
}
a1\_m = abs(a1)
a1\_s = copysign(1.0d0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0d0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0d0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0d0, b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
real(8) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
real(8), intent (in) :: b2_s
real(8), intent (in) :: b1_s
real(8), intent (in) :: a2_s
real(8), intent (in) :: a1_s
real(8), intent (in) :: a1_m
real(8), intent (in) :: a2_m
real(8), intent (in) :: b1_m
real(8), intent (in) :: b2_m
code = b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) * (a2_m / b2_m)))))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) * (a2_m / b2_m)))));
}
a1\_m = math.fabs(a1) a1\_s = math.copysign(1.0, a1) a2\_m = math.fabs(a2) a2\_s = math.copysign(1.0, a2) b1\_m = math.fabs(b1) b1\_s = math.copysign(1.0, b1) b2\_m = math.fabs(b2) b2\_s = math.copysign(1.0, b2) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) [a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m]) def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m): return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) * (a2_m / b2_m)))))
a1\_m = abs(a1) a1\_s = copysign(1.0, a1) a2\_m = abs(a2) a2\_s = copysign(1.0, a2) b1\_m = abs(b1) b1\_s = copysign(1.0, b1) b2\_m = abs(b2) b2\_s = copysign(1.0, b2) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m]) function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m) return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * Float64(Float64(a1_m / b1_m) * Float64(a2_m / b2_m)))))) end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
tmp = b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / b1_m) * (a2_m / b2_m)))));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * N[(N[(a1$95$m / b1$95$m), $MachinePrecision] * N[(a2$95$m / b2$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \left(\frac{a1\_m}{b1\_m} \cdot \frac{a2\_m}{b2\_m}\right)\right)\right)\right)
\end{array}
Initial program 88.0%
times-frac89.6%
Simplified89.6%
Final simplification89.6%
(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 2024066
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:alt
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))