
(FPCore (d1 d2 d3 d4) :precision binary64 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4): return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4) return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) end
function tmp = code(d1, d2, d3, d4) tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1); end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (d1 d2 d3 d4) :precision binary64 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
def code(d1, d2, d3, d4): return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
function code(d1, d2, d3, d4) return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) end
function tmp = code(d1, d2, d3, d4) tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1); end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\end{array}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d1 -1.35e+154) (* (- (- d2 d3) d1) d1) (fma d2 d1 (fma (- d1) d3 (* d1 (- d4 d1))))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d1 <= -1.35e+154) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = fma(d2, d1, fma(-d1, d3, (d1 * (d4 - d1))));
}
return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d1 <= -1.35e+154) tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1); else tmp = fma(d2, d1, fma(Float64(-d1), d3, Float64(d1 * Float64(d4 - d1)))); end return tmp end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -1.35e+154], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(d2 * d1 + N[((-d1) * d3 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(d2, d1, \mathsf{fma}\left(-d1, d3, d1 \cdot \left(d4 - d1\right)\right)\right)\\
\end{array}
\end{array}
if d1 < -1.35000000000000003e154Initial program 48.5%
Taylor expanded in d4 around 0
Applied rewrites90.9%
if -1.35000000000000003e154 < d1 Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
associate-+l+N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower--.f6499.0
Applied rewrites99.0%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* (- d2 d3) d1)))
(if (<= d3 -4.5e+51)
t_0
(if (<= d3 -1.5e-146)
(* (- d2 d1) d1)
(if (<= d3 3.6e+50) (* (+ d2 d4) d1) t_0)))))assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d3) * d1;
double tmp;
if (d3 <= -4.5e+51) {
tmp = t_0;
} else if (d3 <= -1.5e-146) {
tmp = (d2 - d1) * d1;
} else if (d3 <= 3.6e+50) {
tmp = (d2 + d4) * d1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: tmp
t_0 = (d2 - d3) * d1
if (d3 <= (-4.5d+51)) then
tmp = t_0
else if (d3 <= (-1.5d-146)) then
tmp = (d2 - d1) * d1
else if (d3 <= 3.6d+50) then
tmp = (d2 + d4) * d1
else
tmp = t_0
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d3) * d1;
double tmp;
if (d3 <= -4.5e+51) {
tmp = t_0;
} else if (d3 <= -1.5e-146) {
tmp = (d2 - d1) * d1;
} else if (d3 <= 3.6e+50) {
tmp = (d2 + d4) * d1;
} else {
tmp = t_0;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): t_0 = (d2 - d3) * d1 tmp = 0 if d3 <= -4.5e+51: tmp = t_0 elif d3 <= -1.5e-146: tmp = (d2 - d1) * d1 elif d3 <= 3.6e+50: tmp = (d2 + d4) * d1 else: tmp = t_0 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) t_0 = Float64(Float64(d2 - d3) * d1) tmp = 0.0 if (d3 <= -4.5e+51) tmp = t_0; elseif (d3 <= -1.5e-146) tmp = Float64(Float64(d2 - d1) * d1); elseif (d3 <= 3.6e+50) tmp = Float64(Float64(d2 + d4) * d1); else tmp = t_0; end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
t_0 = (d2 - d3) * d1;
tmp = 0.0;
if (d3 <= -4.5e+51)
tmp = t_0;
elseif (d3 <= -1.5e-146)
tmp = (d2 - d1) * d1;
elseif (d3 <= 3.6e+50)
tmp = (d2 + d4) * d1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -4.5e+51], t$95$0, If[LessEqual[d3, -1.5e-146], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 3.6e+50], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := \left(d2 - d3\right) \cdot d1\\
\mathbf{if}\;d3 \leq -4.5 \cdot 10^{+51}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d3 \leq -1.5 \cdot 10^{-146}:\\
\;\;\;\;\left(d2 - d1\right) \cdot d1\\
\mathbf{elif}\;d3 \leq 3.6 \cdot 10^{+50}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d3 < -4.5e51 or 3.59999999999999986e50 < d3 Initial program 89.2%
Taylor expanded in d1 around 0
Applied rewrites93.8%
Taylor expanded in d2 around inf
Applied rewrites82.8%
if -4.5e51 < d3 < -1.50000000000000009e-146Initial program 92.5%
Taylor expanded in d4 around 0
Applied rewrites81.8%
Taylor expanded in d2 around inf
Applied rewrites74.3%
if -1.50000000000000009e-146 < d3 < 3.59999999999999986e50Initial program 90.2%
Taylor expanded in d1 around 0
Applied rewrites77.6%
Taylor expanded in d3 around 0
Applied rewrites73.9%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* (- d2 d3) d1)))
(if (<= d3 -14000.0)
t_0
(if (<= d3 -1e-145)
(* (- d4 d1) d1)
(if (<= d3 3.6e+50) (* (+ d2 d4) d1) t_0)))))assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d3) * d1;
double tmp;
if (d3 <= -14000.0) {
tmp = t_0;
} else if (d3 <= -1e-145) {
tmp = (d4 - d1) * d1;
} else if (d3 <= 3.6e+50) {
tmp = (d2 + d4) * d1;
} else {
tmp = t_0;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: t_0
real(8) :: tmp
t_0 = (d2 - d3) * d1
if (d3 <= (-14000.0d0)) then
tmp = t_0
else if (d3 <= (-1d-145)) then
tmp = (d4 - d1) * d1
else if (d3 <= 3.6d+50) then
tmp = (d2 + d4) * d1
else
tmp = t_0
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = (d2 - d3) * d1;
double tmp;
if (d3 <= -14000.0) {
tmp = t_0;
} else if (d3 <= -1e-145) {
tmp = (d4 - d1) * d1;
} else if (d3 <= 3.6e+50) {
tmp = (d2 + d4) * d1;
} else {
tmp = t_0;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): t_0 = (d2 - d3) * d1 tmp = 0 if d3 <= -14000.0: tmp = t_0 elif d3 <= -1e-145: tmp = (d4 - d1) * d1 elif d3 <= 3.6e+50: tmp = (d2 + d4) * d1 else: tmp = t_0 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) t_0 = Float64(Float64(d2 - d3) * d1) tmp = 0.0 if (d3 <= -14000.0) tmp = t_0; elseif (d3 <= -1e-145) tmp = Float64(Float64(d4 - d1) * d1); elseif (d3 <= 3.6e+50) tmp = Float64(Float64(d2 + d4) * d1); else tmp = t_0; end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
t_0 = (d2 - d3) * d1;
tmp = 0.0;
if (d3 <= -14000.0)
tmp = t_0;
elseif (d3 <= -1e-145)
tmp = (d4 - d1) * d1;
elseif (d3 <= 3.6e+50)
tmp = (d2 + d4) * d1;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision]}, If[LessEqual[d3, -14000.0], t$95$0, If[LessEqual[d3, -1e-145], N[(N[(d4 - d1), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d3, 3.6e+50], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
t_0 := \left(d2 - d3\right) \cdot d1\\
\mathbf{if}\;d3 \leq -14000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d3 \leq -1 \cdot 10^{-145}:\\
\;\;\;\;\left(d4 - d1\right) \cdot d1\\
\mathbf{elif}\;d3 \leq 3.6 \cdot 10^{+50}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d3 < -14000 or 3.59999999999999986e50 < d3 Initial program 90.3%
Taylor expanded in d1 around 0
Applied rewrites92.7%
Taylor expanded in d2 around inf
Applied rewrites82.1%
if -14000 < d3 < -9.99999999999999915e-146Initial program 89.3%
Taylor expanded in d2 around 0
Applied rewrites89.7%
Taylor expanded in d3 around 0
Applied rewrites83.6%
if -9.99999999999999915e-146 < d3 < 3.59999999999999986e50Initial program 90.2%
Taylor expanded in d1 around 0
Applied rewrites77.6%
Taylor expanded in d3 around 0
Applied rewrites73.9%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d1 -3.7e+134) (not (<= d1 4.5e+62))) (* (- d2 d1) d1) (* (- (+ d4 d2) d3) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d1 <= -3.7e+134) || !(d1 <= 4.5e+62)) {
tmp = (d2 - d1) * d1;
} else {
tmp = ((d4 + d2) - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if ((d1 <= (-3.7d+134)) .or. (.not. (d1 <= 4.5d+62))) then
tmp = (d2 - d1) * d1
else
tmp = ((d4 + d2) - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d1 <= -3.7e+134) || !(d1 <= 4.5e+62)) {
tmp = (d2 - d1) * d1;
} else {
tmp = ((d4 + d2) - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if (d1 <= -3.7e+134) or not (d1 <= 4.5e+62): tmp = (d2 - d1) * d1 else: tmp = ((d4 + d2) - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if ((d1 <= -3.7e+134) || !(d1 <= 4.5e+62)) tmp = Float64(Float64(d2 - d1) * d1); else tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if ((d1 <= -3.7e+134) || ~((d1 <= 4.5e+62)))
tmp = (d2 - d1) * d1;
else
tmp = ((d4 + d2) - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -3.7e+134], N[Not[LessEqual[d1, 4.5e+62]], $MachinePrecision]], N[(N[(d2 - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -3.7 \cdot 10^{+134} \lor \neg \left(d1 \leq 4.5 \cdot 10^{+62}\right):\\
\;\;\;\;\left(d2 - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if d1 < -3.70000000000000013e134 or 4.49999999999999999e62 < d1 Initial program 66.2%
Taylor expanded in d4 around 0
Applied rewrites94.0%
Taylor expanded in d2 around inf
Applied rewrites88.0%
if -3.70000000000000013e134 < d1 < 4.49999999999999999e62Initial program 99.9%
Taylor expanded in d1 around 0
Applied rewrites94.1%
Final simplification92.3%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d1 -1.35e+154) (* (- (- d2 d3) d1) d1) (fma (- d2 d3) d1 (* d1 (- d4 d1)))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d1 <= -1.35e+154) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = fma((d2 - d3), d1, (d1 * (d4 - d1)));
}
return tmp;
}
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d1 <= -1.35e+154) tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1); else tmp = fma(Float64(d2 - d3), d1, Float64(d1 * Float64(d4 - d1))); end return tmp end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -1.35e+154], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d2 - d3), $MachinePrecision] * d1 + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(d2 - d3, d1, d1 \cdot \left(d4 - d1\right)\right)\\
\end{array}
\end{array}
if d1 < -1.35000000000000003e154Initial program 48.5%
Taylor expanded in d4 around 0
Applied rewrites90.9%
if -1.35000000000000003e154 < d1 Initial program 96.3%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower--.f6499.1
Applied rewrites99.1%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.45e-24) (* (- d2 d3) d1) (if (<= d2 7.2e-204) (* (- (- d1) d3) d1) (* (- d4 d3) d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.45e-24) {
tmp = (d2 - d3) * d1;
} else if (d2 <= 7.2e-204) {
tmp = (-d1 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-1.45d-24)) then
tmp = (d2 - d3) * d1
else if (d2 <= 7.2d-204) then
tmp = (-d1 - d3) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.45e-24) {
tmp = (d2 - d3) * d1;
} else if (d2 <= 7.2e-204) {
tmp = (-d1 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.45e-24: tmp = (d2 - d3) * d1 elif d2 <= 7.2e-204: tmp = (-d1 - d3) * d1 else: tmp = (d4 - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.45e-24) tmp = Float64(Float64(d2 - d3) * d1); elseif (d2 <= 7.2e-204) tmp = Float64(Float64(Float64(-d1) - d3) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.45e-24)
tmp = (d2 - d3) * d1;
elseif (d2 <= 7.2e-204)
tmp = (-d1 - d3) * d1;
else
tmp = (d4 - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.45e-24], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, 7.2e-204], N[(N[((-d1) - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.45 \cdot 10^{-24}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{elif}\;d2 \leq 7.2 \cdot 10^{-204}:\\
\;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.4499999999999999e-24Initial program 86.7%
Taylor expanded in d1 around 0
Applied rewrites89.7%
Taylor expanded in d2 around inf
Applied rewrites75.8%
if -1.4499999999999999e-24 < d2 < 7.1999999999999993e-204Initial program 94.2%
Taylor expanded in d2 around 0
Applied rewrites99.9%
Taylor expanded in d1 around inf
Applied rewrites76.8%
if 7.1999999999999993e-204 < d2 Initial program 89.0%
Taylor expanded in d2 around 0
Applied rewrites73.3%
Taylor expanded in d1 around 0
Applied rewrites53.3%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d3 -7.5e+123) (not (<= d3 2e+69))) (* (- d3) d1) (* (+ d2 d4) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -7.5e+123) || !(d3 <= 2e+69)) {
tmp = -d3 * d1;
} else {
tmp = (d2 + d4) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if ((d3 <= (-7.5d+123)) .or. (.not. (d3 <= 2d+69))) then
tmp = -d3 * d1
else
tmp = (d2 + d4) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d3 <= -7.5e+123) || !(d3 <= 2e+69)) {
tmp = -d3 * d1;
} else {
tmp = (d2 + d4) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if (d3 <= -7.5e+123) or not (d3 <= 2e+69): tmp = -d3 * d1 else: tmp = (d2 + d4) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if ((d3 <= -7.5e+123) || !(d3 <= 2e+69)) tmp = Float64(Float64(-d3) * d1); else tmp = Float64(Float64(d2 + d4) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if ((d3 <= -7.5e+123) || ~((d3 <= 2e+69)))
tmp = -d3 * d1;
else
tmp = (d2 + d4) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d3, -7.5e+123], N[Not[LessEqual[d3, 2e+69]], $MachinePrecision]], N[((-d3) * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d3 \leq -7.5 \cdot 10^{+123} \lor \neg \left(d3 \leq 2 \cdot 10^{+69}\right):\\
\;\;\;\;\left(-d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\
\end{array}
\end{array}
if d3 < -7.4999999999999999e123 or 2.0000000000000001e69 < d3 Initial program 87.5%
Taylor expanded in d3 around inf
Applied rewrites74.4%
if -7.4999999999999999e123 < d3 < 2.0000000000000001e69Initial program 91.4%
Taylor expanded in d1 around 0
Applied rewrites77.4%
Taylor expanded in d3 around 0
Applied rewrites69.7%
Final simplification71.2%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.48e+35) (* d2 d1) (if (<= d2 -4e-294) (* (- d3) d1) (* d4 d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.48e+35) {
tmp = d2 * d1;
} else if (d2 <= -4e-294) {
tmp = -d3 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-1.48d+35)) then
tmp = d2 * d1
else if (d2 <= (-4d-294)) then
tmp = -d3 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.48e+35) {
tmp = d2 * d1;
} else if (d2 <= -4e-294) {
tmp = -d3 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.48e+35: tmp = d2 * d1 elif d2 <= -4e-294: tmp = -d3 * d1 else: tmp = d4 * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.48e+35) tmp = Float64(d2 * d1); elseif (d2 <= -4e-294) tmp = Float64(Float64(-d3) * d1); else tmp = Float64(d4 * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.48e+35)
tmp = d2 * d1;
elseif (d2 <= -4e-294)
tmp = -d3 * d1;
else
tmp = d4 * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.48e+35], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -4e-294], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.48 \cdot 10^{+35}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{elif}\;d2 \leq -4 \cdot 10^{-294}:\\
\;\;\;\;\left(-d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -1.48000000000000003e35Initial program 85.9%
Taylor expanded in d2 around inf
Applied rewrites61.0%
if -1.48000000000000003e35 < d2 < -4.00000000000000007e-294Initial program 94.1%
Taylor expanded in d3 around inf
Applied rewrites50.9%
if -4.00000000000000007e-294 < d2 Initial program 90.2%
Taylor expanded in d4 around inf
Applied rewrites34.2%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -6e-30) (* d2 d1) (if (<= d2 4e-202) (* (- d1) d1) (* d4 d1))))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -6e-30) {
tmp = d2 * d1;
} else if (d2 <= 4e-202) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-6d-30)) then
tmp = d2 * d1
else if (d2 <= 4d-202) then
tmp = -d1 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -6e-30) {
tmp = d2 * d1;
} else if (d2 <= 4e-202) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -6e-30: tmp = d2 * d1 elif d2 <= 4e-202: tmp = -d1 * d1 else: tmp = d4 * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -6e-30) tmp = Float64(d2 * d1); elseif (d2 <= 4e-202) tmp = Float64(Float64(-d1) * d1); else tmp = Float64(d4 * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -6e-30)
tmp = d2 * d1;
elseif (d2 <= 4e-202)
tmp = -d1 * d1;
else
tmp = d4 * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -6e-30], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 4e-202], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -6 \cdot 10^{-30}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{elif}\;d2 \leq 4 \cdot 10^{-202}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -5.9999999999999998e-30Initial program 86.9%
Taylor expanded in d2 around inf
Applied rewrites58.2%
if -5.9999999999999998e-30 < d2 < 4.0000000000000001e-202Initial program 94.1%
Taylor expanded in d1 around inf
Applied rewrites38.0%
if 4.0000000000000001e-202 < d2 Initial program 89.0%
Taylor expanded in d4 around inf
Applied rewrites32.6%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.8e-8) (* (- (- d2 d3) d1) d1) (* (- (- d4 d1) d3) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e-8) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = ((d4 - d1) - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-1.8d-8)) then
tmp = ((d2 - d3) - d1) * d1
else
tmp = ((d4 - d1) - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e-8) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = ((d4 - d1) - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.8e-8: tmp = ((d2 - d3) - d1) * d1 else: tmp = ((d4 - d1) - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.8e-8) tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1); else tmp = Float64(Float64(Float64(d4 - d1) - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.8e-8)
tmp = ((d2 - d3) - d1) * d1;
else
tmp = ((d4 - d1) - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e-8], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 - d1), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.8 \cdot 10^{-8}:\\
\;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(d4 - d1\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.79999999999999991e-8Initial program 86.5%
Taylor expanded in d4 around 0
Applied rewrites88.8%
if -1.79999999999999991e-8 < d2 Initial program 91.5%
Taylor expanded in d2 around 0
Applied rewrites85.7%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d4 1.75e+24) (* (- (- d2 d3) d1) d1) (* (- (+ d4 d2) d3) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= 1.75e+24) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = ((d4 + d2) - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d4 <= 1.75d+24) then
tmp = ((d2 - d3) - d1) * d1
else
tmp = ((d4 + d2) - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d4 <= 1.75e+24) {
tmp = ((d2 - d3) - d1) * d1;
} else {
tmp = ((d4 + d2) - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d4 <= 1.75e+24: tmp = ((d2 - d3) - d1) * d1 else: tmp = ((d4 + d2) - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d4 <= 1.75e+24) tmp = Float64(Float64(Float64(d2 - d3) - d1) * d1); else tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d4 <= 1.75e+24)
tmp = ((d2 - d3) - d1) * d1;
else
tmp = ((d4 + d2) - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d4, 1.75e+24], N[(N[(N[(d2 - d3), $MachinePrecision] - d1), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d4 \leq 1.75 \cdot 10^{+24}:\\
\;\;\;\;\left(\left(d2 - d3\right) - d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if d4 < 1.7500000000000001e24Initial program 89.6%
Taylor expanded in d4 around 0
Applied rewrites84.3%
if 1.7500000000000001e24 < d4 Initial program 92.0%
Taylor expanded in d1 around 0
Applied rewrites90.1%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.8e-8) (* (- d2 d3) d1) (* (- d4 d3) d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e-8) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-1.8d-8)) then
tmp = (d2 - d3) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e-8) {
tmp = (d2 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.8e-8: tmp = (d2 - d3) * d1 else: tmp = (d4 - d3) * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.8e-8) tmp = Float64(Float64(d2 - d3) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.8e-8)
tmp = (d2 - d3) * d1;
else
tmp = (d4 - d3) * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e-8], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.8 \cdot 10^{-8}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.79999999999999991e-8Initial program 86.5%
Taylor expanded in d1 around 0
Applied rewrites89.5%
Taylor expanded in d2 around inf
Applied rewrites76.9%
if -1.79999999999999991e-8 < d2 Initial program 91.5%
Taylor expanded in d2 around 0
Applied rewrites85.7%
Taylor expanded in d1 around 0
Applied rewrites63.0%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.8e-52) (* d2 d1) (* d4 d1)))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e-52) {
tmp = d2 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
real(8) :: tmp
if (d2 <= (-1.8d-52)) then
tmp = d2 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.8e-52) {
tmp = d2 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.8e-52: tmp = d2 * d1 else: tmp = d4 * d1 return tmp
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.8e-52) tmp = Float64(d2 * d1); else tmp = Float64(d4 * d1); end return tmp end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp_2 = code(d1, d2, d3, d4)
tmp = 0.0;
if (d2 <= -1.8e-52)
tmp = d2 * d1;
else
tmp = d4 * d1;
end
tmp_2 = tmp;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.8e-52], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.8 \cdot 10^{-52}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -1.79999999999999994e-52Initial program 87.5%
Taylor expanded in d2 around inf
Applied rewrites56.0%
if -1.79999999999999994e-52 < d2 Initial program 91.2%
Taylor expanded in d4 around inf
Applied rewrites33.1%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
return d2 * d1;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d2 * d1
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
return d2 * d1;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): return d2 * d1
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) return Float64(d2 * d1) end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp = code(d1, d2, d3, d4)
tmp = d2 * d1;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
d2 \cdot d1
\end{array}
Initial program 90.2%
Taylor expanded in d2 around inf
Applied rewrites32.5%
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. (FPCore (d1 d2 d3 d4) :precision binary64 (* d1 d1))
assert(d1 < d2 && d2 < d3 && d3 < d4);
double code(double d1, double d2, double d3, double d4) {
return d1 * d1;
}
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function.
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * d1
end function
assert d1 < d2 && d2 < d3 && d3 < d4;
public static double code(double d1, double d2, double d3, double d4) {
return d1 * d1;
}
[d1, d2, d3, d4] = sort([d1, d2, d3, d4]) def code(d1, d2, d3, d4): return d1 * d1
d1, d2, d3, d4 = sort([d1, d2, d3, d4]) function code(d1, d2, d3, d4) return Float64(d1 * d1) end
d1, d2, d3, d4 = num2cell(sort([d1, d2, d3, d4])){:}
function tmp = code(d1, d2, d3, d4)
tmp = d1 * d1;
end
NOTE: d1, d2, d3, and d4 should be sorted in increasing order before calling this function. code[d1_, d2_, d3_, d4_] := N[(d1 * d1), $MachinePrecision]
\begin{array}{l}
[d1, d2, d3, d4] = \mathsf{sort}([d1, d2, d3, d4])\\
\\
d1 \cdot d1
\end{array}
Initial program 90.2%
Taylor expanded in d1 around inf
Applied rewrites29.5%
Applied rewrites6.1%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d1 (- (+ (- d2 d3) d4) d1)))
double code(double d1, double d2, double d3, double d4) {
return d1 * (((d2 - d3) + d4) - d1);
}
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(d1, d2, d3, d4)
use fmin_fmax_functions
real(8), intent (in) :: d1
real(8), intent (in) :: d2
real(8), intent (in) :: d3
real(8), intent (in) :: d4
code = d1 * (((d2 - d3) + d4) - d1)
end function
public static double code(double d1, double d2, double d3, double d4) {
return d1 * (((d2 - d3) + d4) - d1);
}
def code(d1, d2, d3, d4): return d1 * (((d2 - d3) + d4) - d1)
function code(d1, d2, d3, d4) return Float64(d1 * Float64(Float64(Float64(d2 - d3) + d4) - d1)) end
function tmp = code(d1, d2, d3, d4) tmp = d1 * (((d2 - d3) + d4) - d1); end
code[d1_, d2_, d3_, d4_] := N[(d1 * N[(N[(N[(d2 - d3), $MachinePrecision] + d4), $MachinePrecision] - d1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right)
\end{array}
herbie shell --seed 2025019
(FPCore (d1 d2 d3 d4)
:name "FastMath dist4"
:precision binary64
:alt
(! :herbie-platform default (* d1 (- (+ (- d2 d3) d4) d1)))
(- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))