
(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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a1, a2, b1, b2)
use fmin_fmax_functions
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]
\frac{a1 \cdot a2}{b1 \cdot b2}
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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a1, a2, b1, b2)
use fmin_fmax_functions
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]
\frac{a1 \cdot a2}{b1 \cdot b2}
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (fmax (fabs a1) (fabs a2)))
(t_1 (fmin (fabs a1) (fabs a2)))
(t_2 (* (/ t_0 (fabs b1)) (/ t_1 (fabs b2))))
(t_3 (* (fabs b1) (fabs b2)))
(t_4 (* (fabs b2) (fabs b1))))
(*
(copysign 1.0 a1)
(*
(copysign 1.0 a2)
(*
(copysign 1.0 b1)
(*
(copysign 1.0 b2)
(if (<= t_3 1e-300)
t_2
(if (<= t_3 5000000000.0)
(* (/ t_1 t_4) t_0)
(if (<= t_3 2e+296) (* (/ t_0 t_4) t_1) t_2)))))))))double code(double a1, double a2, double b1, double b2) {
double t_0 = fmax(fabs(a1), fabs(a2));
double t_1 = fmin(fabs(a1), fabs(a2));
double t_2 = (t_0 / fabs(b1)) * (t_1 / fabs(b2));
double t_3 = fabs(b1) * fabs(b2);
double t_4 = fabs(b2) * fabs(b1);
double tmp;
if (t_3 <= 1e-300) {
tmp = t_2;
} else if (t_3 <= 5000000000.0) {
tmp = (t_1 / t_4) * t_0;
} else if (t_3 <= 2e+296) {
tmp = (t_0 / t_4) * t_1;
} else {
tmp = t_2;
}
return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * tmp)));
}
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = fmax(Math.abs(a1), Math.abs(a2));
double t_1 = fmin(Math.abs(a1), Math.abs(a2));
double t_2 = (t_0 / Math.abs(b1)) * (t_1 / Math.abs(b2));
double t_3 = Math.abs(b1) * Math.abs(b2);
double t_4 = Math.abs(b2) * Math.abs(b1);
double tmp;
if (t_3 <= 1e-300) {
tmp = t_2;
} else if (t_3 <= 5000000000.0) {
tmp = (t_1 / t_4) * t_0;
} else if (t_3 <= 2e+296) {
tmp = (t_0 / t_4) * t_1;
} else {
tmp = t_2;
}
return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * tmp)));
}
def code(a1, a2, b1, b2): t_0 = fmax(math.fabs(a1), math.fabs(a2)) t_1 = fmin(math.fabs(a1), math.fabs(a2)) t_2 = (t_0 / math.fabs(b1)) * (t_1 / math.fabs(b2)) t_3 = math.fabs(b1) * math.fabs(b2) t_4 = math.fabs(b2) * math.fabs(b1) tmp = 0 if t_3 <= 1e-300: tmp = t_2 elif t_3 <= 5000000000.0: tmp = (t_1 / t_4) * t_0 elif t_3 <= 2e+296: tmp = (t_0 / t_4) * t_1 else: tmp = t_2 return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * tmp)))
function code(a1, a2, b1, b2) t_0 = fmax(abs(a1), abs(a2)) t_1 = fmin(abs(a1), abs(a2)) t_2 = Float64(Float64(t_0 / abs(b1)) * Float64(t_1 / abs(b2))) t_3 = Float64(abs(b1) * abs(b2)) t_4 = Float64(abs(b2) * abs(b1)) tmp = 0.0 if (t_3 <= 1e-300) tmp = t_2; elseif (t_3 <= 5000000000.0) tmp = Float64(Float64(t_1 / t_4) * t_0); elseif (t_3 <= 2e+296) tmp = Float64(Float64(t_0 / t_4) * t_1); else tmp = t_2; end return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * tmp)))) end
function tmp_2 = code(a1, a2, b1, b2) t_0 = max(abs(a1), abs(a2)); t_1 = min(abs(a1), abs(a2)); t_2 = (t_0 / abs(b1)) * (t_1 / abs(b2)); t_3 = abs(b1) * abs(b2); t_4 = abs(b2) * abs(b1); tmp = 0.0; if (t_3 <= 1e-300) tmp = t_2; elseif (t_3 <= 5000000000.0) tmp = (t_1 / t_4) * t_0; elseif (t_3 <= 2e+296) tmp = (t_0 / t_4) * t_1; else tmp = t_2; end tmp_2 = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * tmp))); end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[Max[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Min[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$0 / N[Abs[b1], $MachinePrecision]), $MachinePrecision] * N[(t$95$1 / N[Abs[b2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Abs[b1], $MachinePrecision] * N[Abs[b2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Abs[b2], $MachinePrecision] * N[Abs[b1], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 1e-300], t$95$2, If[LessEqual[t$95$3, 5000000000.0], N[(N[(t$95$1 / t$95$4), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[t$95$3, 2e+296], N[(N[(t$95$0 / t$95$4), $MachinePrecision] * t$95$1), $MachinePrecision], t$95$2]]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)\\
t_1 := \mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)\\
t_2 := \frac{t\_0}{\left|b1\right|} \cdot \frac{t\_1}{\left|b2\right|}\\
t_3 := \left|b1\right| \cdot \left|b2\right|\\
t_4 := \left|b2\right| \cdot \left|b1\right|\\
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_3 \leq 10^{-300}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_3 \leq 5000000000:\\
\;\;\;\;\frac{t\_1}{t\_4} \cdot t\_0\\
\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+296}:\\
\;\;\;\;\frac{t\_0}{t\_4} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}\right)\right)\right)
\end{array}
if (*.f64 b1 b2) < 1e-300 or 2e296 < (*.f64 b1 b2) Initial program 85.8%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6486.0%
Applied rewrites86.0%
if 1e-300 < (*.f64 b1 b2) < 5e9Initial program 85.8%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6486.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.1%
Applied rewrites86.1%
if 5e9 < (*.f64 b1 b2) < 2e296Initial program 85.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6485.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6485.8%
Applied rewrites85.8%
(FPCore (a1 a2 b1 b2)
:precision binary64
(*
(copysign 1.0 a1)
(*
(copysign 1.0 a2)
(*
(copysign 1.0 b1)
(*
(copysign 1.0 b2)
(*
(/ (fmax (fabs a1) (fabs a2)) (fmax (fabs b1) (fabs b2)))
(/ (fmin (fabs a1) (fabs a2)) (fmin (fabs b1) (fabs b2)))))))))double code(double a1, double a2, double b1, double b2) {
return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * ((fmax(fabs(a1), fabs(a2)) / fmax(fabs(b1), fabs(b2))) * (fmin(fabs(a1), fabs(a2)) / fmin(fabs(b1), fabs(b2)))))));
}
public static double code(double a1, double a2, double b1, double b2) {
return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * ((fmax(Math.abs(a1), Math.abs(a2)) / fmax(Math.abs(b1), Math.abs(b2))) * (fmin(Math.abs(a1), Math.abs(a2)) / fmin(Math.abs(b1), Math.abs(b2)))))));
}
def code(a1, a2, b1, b2): return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * ((fmax(math.fabs(a1), math.fabs(a2)) / fmax(math.fabs(b1), math.fabs(b2))) * (fmin(math.fabs(a1), math.fabs(a2)) / fmin(math.fabs(b1), math.fabs(b2)))))))
function code(a1, a2, b1, b2) return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * Float64(Float64(fmax(abs(a1), abs(a2)) / fmax(abs(b1), abs(b2))) * Float64(fmin(abs(a1), abs(a2)) / fmin(abs(b1), abs(b2)))))))) end
function tmp = code(a1, a2, b1, b2) tmp = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * ((max(abs(a1), abs(a2)) / max(abs(b1), abs(b2))) * (min(abs(a1), abs(a2)) / min(abs(b1), abs(b2))))))); end
code[a1_, a2_, b1_, b2_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[(N[Max[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision] / N[Max[N[Abs[b1], $MachinePrecision], N[Abs[b2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Min[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision] / N[Min[N[Abs[b1], $MachinePrecision], N[Abs[b2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \left(\frac{\mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)}{\mathsf{max}\left(\left|b1\right|, \left|b2\right|\right)} \cdot \frac{\mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)}{\mathsf{min}\left(\left|b1\right|, \left|b2\right|\right)}\right)\right)\right)\right)
Initial program 85.8%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6486.6%
Applied rewrites86.6%
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (fmin (fabs a1) (fabs a2)))
(t_1 (fmax (fabs a1) (fabs a2)))
(t_2 (* (fabs b2) (fabs b1))))
(*
(copysign 1.0 a1)
(*
(copysign 1.0 a2)
(*
(copysign 1.0 b1)
(*
(copysign 1.0 b2)
(if (<= (/ (* t_0 t_1) (* (fabs b1) (fabs b2))) 1e-17)
(* (/ t_1 t_2) t_0)
(* (/ t_0 t_2) t_1))))))))double code(double a1, double a2, double b1, double b2) {
double t_0 = fmin(fabs(a1), fabs(a2));
double t_1 = fmax(fabs(a1), fabs(a2));
double t_2 = fabs(b2) * fabs(b1);
double tmp;
if (((t_0 * t_1) / (fabs(b1) * fabs(b2))) <= 1e-17) {
tmp = (t_1 / t_2) * t_0;
} else {
tmp = (t_0 / t_2) * t_1;
}
return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * tmp)));
}
public static double code(double a1, double a2, double b1, double b2) {
double t_0 = fmin(Math.abs(a1), Math.abs(a2));
double t_1 = fmax(Math.abs(a1), Math.abs(a2));
double t_2 = Math.abs(b2) * Math.abs(b1);
double tmp;
if (((t_0 * t_1) / (Math.abs(b1) * Math.abs(b2))) <= 1e-17) {
tmp = (t_1 / t_2) * t_0;
} else {
tmp = (t_0 / t_2) * t_1;
}
return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * tmp)));
}
def code(a1, a2, b1, b2): t_0 = fmin(math.fabs(a1), math.fabs(a2)) t_1 = fmax(math.fabs(a1), math.fabs(a2)) t_2 = math.fabs(b2) * math.fabs(b1) tmp = 0 if ((t_0 * t_1) / (math.fabs(b1) * math.fabs(b2))) <= 1e-17: tmp = (t_1 / t_2) * t_0 else: tmp = (t_0 / t_2) * t_1 return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * tmp)))
function code(a1, a2, b1, b2) t_0 = fmin(abs(a1), abs(a2)) t_1 = fmax(abs(a1), abs(a2)) t_2 = Float64(abs(b2) * abs(b1)) tmp = 0.0 if (Float64(Float64(t_0 * t_1) / Float64(abs(b1) * abs(b2))) <= 1e-17) tmp = Float64(Float64(t_1 / t_2) * t_0); else tmp = Float64(Float64(t_0 / t_2) * t_1); end return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * tmp)))) end
function tmp_2 = code(a1, a2, b1, b2) t_0 = min(abs(a1), abs(a2)); t_1 = max(abs(a1), abs(a2)); t_2 = abs(b2) * abs(b1); tmp = 0.0; if (((t_0 * t_1) / (abs(b1) * abs(b2))) <= 1e-17) tmp = (t_1 / t_2) * t_0; else tmp = (t_0 / t_2) * t_1; end tmp_2 = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * tmp))); end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[Min[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Abs[b2], $MachinePrecision] * N[Abs[b1], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(t$95$0 * t$95$1), $MachinePrecision] / N[(N[Abs[b1], $MachinePrecision] * N[Abs[b2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-17], N[(N[(t$95$1 / t$95$2), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[(t$95$0 / t$95$2), $MachinePrecision] * t$95$1), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)\\
t_1 := \mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)\\
t_2 := \left|b2\right| \cdot \left|b1\right|\\
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_0 \cdot t\_1}{\left|b1\right| \cdot \left|b2\right|} \leq 10^{-17}:\\
\;\;\;\;\frac{t\_1}{t\_2} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{t\_2} \cdot t\_1\\
\end{array}\right)\right)\right)
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-17Initial program 85.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6485.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6485.8%
Applied rewrites85.8%
if 1.0000000000000001e-17 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 85.8%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6486.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.1%
Applied rewrites86.1%
(FPCore (a1 a2 b1 b2) :precision binary64 (* (/ (fmin a1 a2) (* b2 b1)) (fmax a1 a2)))
double code(double a1, double a2, double b1, double b2) {
return (fmin(a1, a2) / (b2 * b1)) * fmax(a1, a2);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a1, a2, b1, b2)
use fmin_fmax_functions
real(8), intent (in) :: a1
real(8), intent (in) :: a2
real(8), intent (in) :: b1
real(8), intent (in) :: b2
code = (fmin(a1, a2) / (b2 * b1)) * fmax(a1, a2)
end function
public static double code(double a1, double a2, double b1, double b2) {
return (fmin(a1, a2) / (b2 * b1)) * fmax(a1, a2);
}
def code(a1, a2, b1, b2): return (fmin(a1, a2) / (b2 * b1)) * fmax(a1, a2)
function code(a1, a2, b1, b2) return Float64(Float64(fmin(a1, a2) / Float64(b2 * b1)) * fmax(a1, a2)) end
function tmp = code(a1, a2, b1, b2) tmp = (min(a1, a2) / (b2 * b1)) * max(a1, a2); end
code[a1_, a2_, b1_, b2_] := N[(N[(N[Min[a1, a2], $MachinePrecision] / N[(b2 * b1), $MachinePrecision]), $MachinePrecision] * N[Max[a1, a2], $MachinePrecision]), $MachinePrecision]
\frac{\mathsf{min}\left(a1, a2\right)}{b2 \cdot b1} \cdot \mathsf{max}\left(a1, a2\right)
Initial program 85.8%
lift-/.f64N/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6486.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.1%
Applied rewrites86.1%
(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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a1, a2, b1, b2)
use fmin_fmax_functions
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]
\frac{a1}{b1} \cdot \frac{a2}{b2}
herbie shell --seed 2025191
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:alt
(! :herbie-platform c (* (/ a1 b1) (/ a2 b2)))
(/ (* a1 a2) (* b1 b2)))