
(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}
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 (or (<= t_0 -2e-314) (and (not (<= t_0 0.0)) (<= t_0 2e+299)))
t_0
(* (/ a1 b1) (/ a2 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 tmp;
if ((t_0 <= -2e-314) || (!(t_0 <= 0.0) && (t_0 <= 2e+299))) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = (a1 * a2) / (b1 * b2)
if ((t_0 <= (-2d-314)) .or. (.not. (t_0 <= 0.0d0)) .and. (t_0 <= 2d+299)) then
tmp = t_0
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 t_0 = (a1 * a2) / (b1 * b2);
double tmp;
if ((t_0 <= -2e-314) || (!(t_0 <= 0.0) && (t_0 <= 2e+299))) {
tmp = t_0;
} else {
tmp = (a1 / b1) * (a2 / 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) tmp = 0 if (t_0 <= -2e-314) or (not (t_0 <= 0.0) and (t_0 <= 2e+299)): tmp = t_0 else: tmp = (a1 / b1) * (a2 / 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)) tmp = 0.0 if ((t_0 <= -2e-314) || (!(t_0 <= 0.0) && (t_0 <= 2e+299))) tmp = t_0; 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)
t_0 = (a1 * a2) / (b1 * b2);
tmp = 0.0;
if ((t_0 <= -2e-314) || (~((t_0 <= 0.0)) && (t_0 <= 2e+299)))
tmp = t_0;
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_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e-314], And[N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision], LessEqual[t$95$0, 2e+299]]], t$95$0, 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}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-314} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 2 \cdot 10^{+299}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.9999999999e-314 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 2.0000000000000001e299Initial program 99.2%
if -1.9999999999e-314 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0 or 2.0000000000000001e299 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 78.8%
times-frac97.1%
Simplified97.1%
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 (or (<= (* b1 b2) -2e-181)
(and (not (<= (* b1 b2) 5e-117)) (<= (* b1 b2) 5e+217)))
(* a1 (/ a2 (* b1 b2)))
(* (/ a1 b1) (/ a2 b2))))assert(a1 < a2);
assert(b1 < b2);
double code(double a1, double a2, double b1, double b2) {
double tmp;
if (((b1 * b2) <= -2e-181) || (!((b1 * b2) <= 5e-117) && ((b1 * b2) <= 5e+217))) {
tmp = a1 * (a2 / (b1 * b2));
} 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 (((b1 * b2) <= (-2d-181)) .or. (.not. ((b1 * b2) <= 5d-117)) .and. ((b1 * b2) <= 5d+217)) then
tmp = a1 * (a2 / (b1 * b2))
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 (((b1 * b2) <= -2e-181) || (!((b1 * b2) <= 5e-117) && ((b1 * b2) <= 5e+217))) {
tmp = a1 * (a2 / (b1 * b2));
} 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 ((b1 * b2) <= -2e-181) or (not ((b1 * b2) <= 5e-117) and ((b1 * b2) <= 5e+217)): tmp = a1 * (a2 / (b1 * b2)) 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 ((Float64(b1 * b2) <= -2e-181) || (!(Float64(b1 * b2) <= 5e-117) && (Float64(b1 * b2) <= 5e+217))) tmp = Float64(a1 * Float64(a2 / Float64(b1 * b2))); 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 (((b1 * b2) <= -2e-181) || (~(((b1 * b2) <= 5e-117)) && ((b1 * b2) <= 5e+217)))
tmp = a1 * (a2 / (b1 * b2));
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[Or[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-181], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-117]], $MachinePrecision], LessEqual[N[(b1 * b2), $MachinePrecision], 5e+217]]], N[(a1 * N[(a2 / N[(b1 * b2), $MachinePrecision]), $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}\;b1 \cdot b2 \leq -2 \cdot 10^{-181} \lor \neg \left(b1 \cdot b2 \leq 5 \cdot 10^{-117}\right) \land b1 \cdot b2 \leq 5 \cdot 10^{+217}:\\
\;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -2.00000000000000009e-181 or 5e-117 < (*.f64 b1 b2) < 5.00000000000000041e217Initial program 94.8%
associate-/l*92.4%
*-commutative92.4%
associate-/l*84.7%
Simplified84.7%
clear-num84.4%
associate-/r/84.7%
clear-num85.1%
associate-/l/93.2%
*-commutative93.2%
Applied egg-rr93.2%
if -2.00000000000000009e-181 < (*.f64 b1 b2) < 5e-117 or 5.00000000000000041e217 < (*.f64 b1 b2) Initial program 84.1%
times-frac89.9%
Simplified89.9%
Final simplification91.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
(if (<= (* b1 b2) -2e-181)
(* a1 (/ a2 (* b1 b2)))
(if (or (<= (* b1 b2) 5e-117) (not (<= (* b1 b2) 5e+198)))
(* (/ 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 ((b1 * b2) <= -2e-181) {
tmp = a1 * (a2 / (b1 * b2));
} else if (((b1 * b2) <= 5e-117) || !((b1 * b2) <= 5e+198)) {
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 ((b1 * b2) <= (-2d-181)) then
tmp = a1 * (a2 / (b1 * b2))
else if (((b1 * b2) <= 5d-117) .or. (.not. ((b1 * b2) <= 5d+198))) 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 ((b1 * b2) <= -2e-181) {
tmp = a1 * (a2 / (b1 * b2));
} else if (((b1 * b2) <= 5e-117) || !((b1 * b2) <= 5e+198)) {
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 (b1 * b2) <= -2e-181: tmp = a1 * (a2 / (b1 * b2)) elif ((b1 * b2) <= 5e-117) or not ((b1 * b2) <= 5e+198): 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 (Float64(b1 * b2) <= -2e-181) tmp = Float64(a1 * Float64(a2 / Float64(b1 * b2))); elseif ((Float64(b1 * b2) <= 5e-117) || !(Float64(b1 * b2) <= 5e+198)) tmp = Float64(Float64(a1 / b1) * Float64(a2 / b2)); else tmp = Float64(a1 / Float64(Float64(b1 * 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 ((b1 * b2) <= -2e-181)
tmp = a1 * (a2 / (b1 * b2));
elseif (((b1 * b2) <= 5e-117) || ~(((b1 * b2) <= 5e+198)))
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[N[(b1 * b2), $MachinePrecision], -2e-181], N[(a1 * N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-117], N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], 5e+198]], $MachinePrecision]], N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision], N[(a1 / N[(N[(b1 * b2), $MachinePrecision] / a2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[a1, a2] = \mathsf{sort}([a1, a2])\\
[b1, b2] = \mathsf{sort}([b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{-181}:\\
\;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\
\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-117} \lor \neg \left(b1 \cdot b2 \leq 5 \cdot 10^{+198}\right):\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\
\end{array}
\end{array}
if (*.f64 b1 b2) < -2.00000000000000009e-181Initial program 93.8%
associate-/l*89.7%
*-commutative89.7%
associate-/l*83.1%
Simplified83.1%
clear-num82.6%
associate-/r/83.2%
clear-num83.2%
associate-/l/90.4%
*-commutative90.4%
Applied egg-rr90.4%
if -2.00000000000000009e-181 < (*.f64 b1 b2) < 5e-117 or 5.00000000000000049e198 < (*.f64 b1 b2) Initial program 84.8%
times-frac90.4%
Simplified90.4%
if 5e-117 < (*.f64 b1 b2) < 5.00000000000000049e198Initial program 95.8%
associate-/l*97.8%
*-commutative97.8%
associate-/l*87.7%
Simplified87.7%
Taylor expanded in b2 around 0 97.8%
Final simplification92.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 90.7%
times-frac83.7%
Simplified83.7%
Final simplification83.7%
(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 2023194
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:herbie-target
(* (/ a1 b1) (/ a2 b2))
(/ (* a1 a2) (* b1 b2)))