
(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
(*
(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 86.2%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
times-fracN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6485.9%
Applied rewrites85.9%
(FPCore (a1 a2 b1 b2)
:precision binary64
(let* ((t_0 (/ (* (fabs a1) (fabs a2)) (* (fabs b1) (fabs b2))))
(t_1 (* (/ (fabs a2) (fabs b1)) (/ (fabs a1) (fabs b2)))))
(*
(copysign 1.0 a1)
(*
(copysign 1.0 a2)
(*
(copysign 1.0 b1)
(*
(copysign 1.0 b2)
(if (<= t_0 0.0) t_1 (if (<= t_0 1e+305) t_0 t_1))))))))double code(double a1, double a2, double b1, double b2) {
double t_0 = (fabs(a1) * fabs(a2)) / (fabs(b1) * fabs(b2));
double t_1 = (fabs(a2) / fabs(b1)) * (fabs(a1) / fabs(b2));
double tmp;
if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 1e+305) {
tmp = t_0;
} else {
tmp = 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 = (Math.abs(a1) * Math.abs(a2)) / (Math.abs(b1) * Math.abs(b2));
double t_1 = (Math.abs(a2) / Math.abs(b1)) * (Math.abs(a1) / Math.abs(b2));
double tmp;
if (t_0 <= 0.0) {
tmp = t_1;
} else if (t_0 <= 1e+305) {
tmp = t_0;
} else {
tmp = 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 = (math.fabs(a1) * math.fabs(a2)) / (math.fabs(b1) * math.fabs(b2)) t_1 = (math.fabs(a2) / math.fabs(b1)) * (math.fabs(a1) / math.fabs(b2)) tmp = 0 if t_0 <= 0.0: tmp = t_1 elif t_0 <= 1e+305: tmp = t_0 else: tmp = 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 = Float64(Float64(abs(a1) * abs(a2)) / Float64(abs(b1) * abs(b2))) t_1 = Float64(Float64(abs(a2) / abs(b1)) * Float64(abs(a1) / abs(b2))) tmp = 0.0 if (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 1e+305) tmp = t_0; else tmp = 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 = (abs(a1) * abs(a2)) / (abs(b1) * abs(b2)); t_1 = (abs(a2) / abs(b1)) * (abs(a1) / abs(b2)); tmp = 0.0; if (t_0 <= 0.0) tmp = t_1; elseif (t_0 <= 1e+305) tmp = t_0; else tmp = 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[(N[(N[Abs[a1], $MachinePrecision] * N[Abs[a2], $MachinePrecision]), $MachinePrecision] / N[(N[Abs[b1], $MachinePrecision] * N[Abs[b2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Abs[a2], $MachinePrecision] / N[Abs[b1], $MachinePrecision]), $MachinePrecision] * N[(N[Abs[a1], $MachinePrecision] / N[Abs[b2], $MachinePrecision]), $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$0, 0.0], t$95$1, If[LessEqual[t$95$0, 1e+305], t$95$0, t$95$1]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \frac{\left|a1\right| \cdot \left|a2\right|}{\left|b1\right| \cdot \left|b2\right|}\\
t_1 := \frac{\left|a2\right|}{\left|b1\right|} \cdot \frac{\left|a1\right|}{\left|b2\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\_0 \leq 0:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+305}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\right)\right)\right)
\end{array}
if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0 or 9.9999999999999994e304 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 86.2%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6486.2%
Applied rewrites86.2%
if 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999994e304Initial program 86.2%
(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))) 8e+37)
(* (/ 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))) <= 8e+37) {
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))) <= 8e+37) {
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))) <= 8e+37: 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))) <= 8e+37) 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))) <= 8e+37) 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], 8e+37], 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 8 \cdot 10^{+37}:\\
\;\;\;\;\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)) < 7.9999999999999996e37Initial program 86.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6486.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.3%
Applied rewrites86.3%
if 7.9999999999999996e37 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) Initial program 86.2%
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.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.3%
Applied rewrites86.3%
(FPCore (a1 a2 b1 b2) :precision binary64 (* (copysign 1.0 a1) (* (/ (fmin (fabs a1) a2) (* b2 b1)) (fmax (fabs a1) a2))))
double code(double a1, double a2, double b1, double b2) {
return copysign(1.0, a1) * ((fmin(fabs(a1), a2) / (b2 * b1)) * fmax(fabs(a1), a2));
}
public static double code(double a1, double a2, double b1, double b2) {
return Math.copySign(1.0, a1) * ((fmin(Math.abs(a1), a2) / (b2 * b1)) * fmax(Math.abs(a1), a2));
}
def code(a1, a2, b1, b2): return math.copysign(1.0, a1) * ((fmin(math.fabs(a1), a2) / (b2 * b1)) * fmax(math.fabs(a1), a2))
function code(a1, a2, b1, b2) return Float64(copysign(1.0, a1) * Float64(Float64(fmin(abs(a1), a2) / Float64(b2 * b1)) * fmax(abs(a1), a2))) end
function tmp = code(a1, a2, b1, b2) tmp = (sign(a1) * abs(1.0)) * ((min(abs(a1), a2) / (b2 * b1)) * max(abs(a1), a2)); 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[(N[Min[N[Abs[a1], $MachinePrecision], a2], $MachinePrecision] / N[(b2 * b1), $MachinePrecision]), $MachinePrecision] * N[Max[N[Abs[a1], $MachinePrecision], a2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, a1\right) \cdot \left(\frac{\mathsf{min}\left(\left|a1\right|, a2\right)}{b2 \cdot b1} \cdot \mathsf{max}\left(\left|a1\right|, a2\right)\right)
Initial program 86.2%
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.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6486.3%
Applied rewrites86.3%
(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 2025260
(FPCore (a1 a2 b1 b2)
:name "Quotient of products"
:precision binary64
:alt
(! :herbie-platform c (* (/ a1 b1) (/ a2 b2)))
(/ (* a1 a2) (* b1 b2)))