
(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 (if (or (<= a2 -1.22e-138) (not (<= a2 3.8e-53))) (* (/ 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 <= -1.22e-138) || !(a2 <= 3.8e-53)) {
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 <= (-1.22d-138)) .or. (.not. (a2 <= 3.8d-53))) 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 <= -1.22e-138) || !(a2 <= 3.8e-53)) {
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 <= -1.22e-138) or not (a2 <= 3.8e-53): 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 <= -1.22e-138) || !(a2 <= 3.8e-53)) 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 <= -1.22e-138) || ~((a2 <= 3.8e-53)))
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[Or[LessEqual[a2, -1.22e-138], N[Not[LessEqual[a2, 3.8e-53]], $MachinePrecision]], 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 -1.22 \cdot 10^{-138} \lor \neg \left(a2 \leq 3.8 \cdot 10^{-53}\right):\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\end{array}
\end{array}
if a2 < -1.22e-138 or 3.7999999999999998e-53 < a2 Initial program 85.4%
times-frac91.4%
associate-*l/88.0%
associate-*r/90.3%
Simplified90.3%
Taylor expanded in a1 around 0 85.4%
*-commutative85.4%
times-frac90.3%
Simplified90.3%
if -1.22e-138 < a2 < 3.7999999999999998e-53Initial program 83.5%
times-frac82.3%
associate-*l/81.8%
associate-*r/85.3%
Simplified85.3%
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 (<= b1 -2.7e+161) (* (/ a2 b2) (/ a1 b1)) (if (<= b1 -2.75e-132) (* a2 (/ a1 (* b1 b2))) (* a1 (/ (/ a2 b2) b1)))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b1 <= -2.7e+161) {
tmp = (a2 / b2) * (a1 / b1);
} else if (b1 <= -2.75e-132) {
tmp = a2 * (a1 / (b1 * 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 (b1 <= (-2.7d+161)) then
tmp = (a2 / b2) * (a1 / b1)
else if (b1 <= (-2.75d-132)) then
tmp = a2 * (a1 / (b1 * 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 (b1 <= -2.7e+161) {
tmp = (a2 / b2) * (a1 / b1);
} else if (b1 <= -2.75e-132) {
tmp = a2 * (a1 / (b1 * 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 b1 <= -2.7e+161: tmp = (a2 / b2) * (a1 / b1) elif b1 <= -2.75e-132: tmp = a2 * (a1 / (b1 * 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 (b1 <= -2.7e+161) tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); elseif (b1 <= -2.75e-132) tmp = Float64(a2 * Float64(a1 / Float64(b1 * 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 (b1 <= -2.7e+161)
tmp = (a2 / b2) * (a1 / b1);
elseif (b1 <= -2.75e-132)
tmp = a2 * (a1 / (b1 * 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[b1, -2.7e+161], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[b1, -2.75e-132], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $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}\;b1 \leq -2.7 \cdot 10^{+161}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\mathbf{elif}\;b1 \leq -2.75 \cdot 10^{-132}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\end{array}
\end{array}
if b1 < -2.6999999999999998e161Initial program 69.9%
times-frac86.8%
Simplified86.8%
if -2.6999999999999998e161 < b1 < -2.75e-132Initial program 90.0%
associate-/l*92.3%
associate-/r/83.5%
*-commutative83.5%
Applied egg-rr83.5%
if -2.75e-132 < b1 Initial program 85.3%
times-frac88.8%
associate-*l/87.7%
associate-*r/91.9%
Simplified91.9%
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 (<= b1 -2.5e-176) (* (/ a2 b2) (/ a1 b1)) (* a1 (/ (/ a2 b2) b1))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (b1 <= -2.5e-176) {
tmp = (a2 / b2) * (a1 / b1);
} 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 (b1 <= (-2.5d-176)) then
tmp = (a2 / b2) * (a1 / b1)
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 (b1 <= -2.5e-176) {
tmp = (a2 / b2) * (a1 / b1);
} 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 b1 <= -2.5e-176: tmp = (a2 / b2) * (a1 / b1) 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 (b1 <= -2.5e-176) tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1)); 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 (b1 <= -2.5e-176)
tmp = (a2 / b2) * (a1 / b1);
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[b1, -2.5e-176], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $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}\;b1 \leq -2.5 \cdot 10^{-176}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\
\mathbf{else}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\
\end{array}
\end{array}
if b1 < -2.5e-176Initial program 84.2%
times-frac85.8%
Simplified85.8%
if -2.5e-176 < b1 Initial program 85.1%
times-frac89.8%
associate-*l/87.5%
associate-*r/91.9%
Simplified91.9%
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 (if (<= a2 2.1e-55) (/ a2 (* (/ b1 a1) b2)) (* (/ a2 b1) (/ a1 b2))))
assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (a2 <= 2.1e-55) {
tmp = a2 / ((b1 / a1) * 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 (a2 <= 2.1d-55) then
tmp = a2 / ((b1 / a1) * 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 (a2 <= 2.1e-55) {
tmp = a2 / ((b1 / a1) * 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 a2 <= 2.1e-55: tmp = a2 / ((b1 / a1) * 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 (a2 <= 2.1e-55) tmp = Float64(a2 / Float64(Float64(b1 / a1) * 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 (a2 <= 2.1e-55)
tmp = a2 / ((b1 / a1) * 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[a2, 2.1e-55], N[(a2 / N[(N[(b1 / a1), $MachinePrecision] * 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}\;a2 \leq 2.1 \cdot 10^{-55}:\\
\;\;\;\;\frac{a2}{\frac{b1}{a1} \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\
\end{array}
\end{array}
if a2 < 2.1000000000000002e-55Initial program 85.5%
times-frac86.8%
associate-*l/84.0%
associate-*r/87.8%
Simplified87.8%
associate-*r/84.0%
associate-*l/86.8%
clear-num86.7%
frac-times87.0%
*-un-lft-identity87.0%
Applied egg-rr87.0%
if 2.1000000000000002e-55 < a2 Initial program 82.6%
times-frac91.9%
associate-*l/90.8%
associate-*r/90.6%
Simplified90.6%
Taylor expanded in a1 around 0 82.6%
*-commutative82.6%
times-frac95.2%
Simplified95.2%
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 (* 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.7%
times-frac88.1%
associate-*l/85.8%
associate-*r/88.5%
Simplified88.5%
Final simplification88.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 2023313
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))