
(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 13 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}
(FPCore (d1 d2 d3 d4) :precision binary64 (let* ((t_0 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))) (if (<= t_0 INFINITY) t_0 (* (- (fma -1.0 d1 d4) d3) d1))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = (fma(-1.0, d1, d4) - d3) * d1;
}
return tmp;
}
function code(d1, d2, d3, d4) t_0 = Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64(Float64(fma(-1.0, d1, d4) - d3) * d1); end return tmp end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(N[(N[(-1.0 * d1 + d4), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < +inf.0Initial program 100.0%
if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) Initial program 0.0%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6479.3
Applied rewrites79.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6489.7
Applied rewrites89.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)) INFINITY) (- (* d1 (+ d4 d2)) (fma d3 d1 (* d1 d1))) (* (- (fma -1.0 d1 d4) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (((((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)) <= ((double) INFINITY)) {
tmp = (d1 * (d4 + d2)) - fma(d3, d1, (d1 * d1));
} else {
tmp = (fma(-1.0, d1, d4) - d3) * d1;
}
return tmp;
}
function code(d1, d2, d3, d4) tmp = 0.0 if (Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1)) <= Inf) tmp = Float64(Float64(d1 * Float64(d4 + d2)) - fma(d3, d1, Float64(d1 * d1))); else tmp = Float64(Float64(fma(-1.0, d1, d4) - d3) * d1); end return tmp end
code[d1_, d2_, d3_, d4_] := If[LessEqual[N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(d1 * N[(d4 + d2), $MachinePrecision]), $MachinePrecision] - N[(d3 * d1 + N[(d1 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-1.0 * d1 + d4), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \leq \infty:\\
\;\;\;\;d1 \cdot \left(d4 + d2\right) - \mathsf{fma}\left(d3, d1, d1 \cdot d1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) < +inf.0Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-+r+N/A
lift-*.f64N/A
pow2N/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-sign-invN/A
associate--r+N/A
lower--.f64N/A
Applied rewrites100.0%
if +inf.0 < (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1)) Initial program 0.0%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6479.3
Applied rewrites79.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6489.7
Applied rewrites89.7%
(FPCore (d1 d2 d3 d4)
:precision binary64
(let* ((t_0 (* (- d1) d1)))
(if (<= d1 -4.3e+28)
t_0
(if (<= d1 4.6e-200)
(* (- d2 d3) d1)
(if (<= d1 1.35e+156) (* (+ d2 d4) d1) t_0)))))
double code(double d1, double d2, double d3, double d4) {
double t_0 = -d1 * d1;
double tmp;
if (d1 <= -4.3e+28) {
tmp = t_0;
} else if (d1 <= 4.6e-200) {
tmp = (d2 - d3) * d1;
} else if (d1 <= 1.35e+156) {
tmp = (d2 + d4) * d1;
} else {
tmp = t_0;
}
return tmp;
}
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 = -d1 * d1
if (d1 <= (-4.3d+28)) then
tmp = t_0
else if (d1 <= 4.6d-200) then
tmp = (d2 - d3) * d1
else if (d1 <= 1.35d+156) then
tmp = (d2 + d4) * d1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double t_0 = -d1 * d1;
double tmp;
if (d1 <= -4.3e+28) {
tmp = t_0;
} else if (d1 <= 4.6e-200) {
tmp = (d2 - d3) * d1;
} else if (d1 <= 1.35e+156) {
tmp = (d2 + d4) * d1;
} else {
tmp = t_0;
}
return tmp;
}
def code(d1, d2, d3, d4): t_0 = -d1 * d1 tmp = 0 if d1 <= -4.3e+28: tmp = t_0 elif d1 <= 4.6e-200: tmp = (d2 - d3) * d1 elif d1 <= 1.35e+156: tmp = (d2 + d4) * d1 else: tmp = t_0 return tmp
function code(d1, d2, d3, d4) t_0 = Float64(Float64(-d1) * d1) tmp = 0.0 if (d1 <= -4.3e+28) tmp = t_0; elseif (d1 <= 4.6e-200) tmp = Float64(Float64(d2 - d3) * d1); elseif (d1 <= 1.35e+156) tmp = Float64(Float64(d2 + d4) * d1); else tmp = t_0; end return tmp end
function tmp_2 = code(d1, d2, d3, d4) t_0 = -d1 * d1; tmp = 0.0; if (d1 <= -4.3e+28) tmp = t_0; elseif (d1 <= 4.6e-200) tmp = (d2 - d3) * d1; elseif (d1 <= 1.35e+156) tmp = (d2 + d4) * d1; else tmp = t_0; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := Block[{t$95$0 = N[((-d1) * d1), $MachinePrecision]}, If[LessEqual[d1, -4.3e+28], t$95$0, If[LessEqual[d1, 4.6e-200], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 1.35e+156], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-d1\right) \cdot d1\\
\mathbf{if}\;d1 \leq -4.3 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d1 \leq 4.6 \cdot 10^{-200}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{elif}\;d1 \leq 1.35 \cdot 10^{+156}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d1 < -4.29999999999999975e28 or 1.35e156 < d1 Initial program 71.6%
Taylor expanded in d1 around inf
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6482.6
Applied rewrites82.6%
if -4.29999999999999975e28 < d1 < 4.60000000000000015e-200Initial program 100.0%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6494.8
Applied rewrites94.8%
Taylor expanded in d2 around inf
Applied rewrites66.6%
if 4.60000000000000015e-200 < d1 < 1.35e156Initial program 96.9%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6486.5
Applied rewrites86.5%
Taylor expanded in d3 around 0
lower-+.f6464.4
Applied rewrites64.4%
(FPCore (d1 d2 d3 d4)
:precision binary64
(if (<= d2 -4.1e+107)
(* d2 d1)
(if (<= d2 -2.7e-164)
(* (- d1) d1)
(if (<= d2 2.4e-305) (* (- d3) d1) (* d4 d1)))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4.1e+107) {
tmp = d2 * d1;
} else if (d2 <= -2.7e-164) {
tmp = -d1 * d1;
} else if (d2 <= 2.4e-305) {
tmp = -d3 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
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 <= (-4.1d+107)) then
tmp = d2 * d1
else if (d2 <= (-2.7d-164)) then
tmp = -d1 * d1
else if (d2 <= 2.4d-305) then
tmp = -d3 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4.1e+107) {
tmp = d2 * d1;
} else if (d2 <= -2.7e-164) {
tmp = -d1 * d1;
} else if (d2 <= 2.4e-305) {
tmp = -d3 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -4.1e+107: tmp = d2 * d1 elif d2 <= -2.7e-164: tmp = -d1 * d1 elif d2 <= 2.4e-305: tmp = -d3 * d1 else: tmp = d4 * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -4.1e+107) tmp = Float64(d2 * d1); elseif (d2 <= -2.7e-164) tmp = Float64(Float64(-d1) * d1); elseif (d2 <= 2.4e-305) tmp = Float64(Float64(-d3) * d1); else tmp = Float64(d4 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -4.1e+107) tmp = d2 * d1; elseif (d2 <= -2.7e-164) tmp = -d1 * d1; elseif (d2 <= 2.4e-305) tmp = -d3 * d1; else tmp = d4 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.1e+107], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, -2.7e-164], N[((-d1) * d1), $MachinePrecision], If[LessEqual[d2, 2.4e-305], N[((-d3) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.1 \cdot 10^{+107}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{elif}\;d2 \leq -2.7 \cdot 10^{-164}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{elif}\;d2 \leq 2.4 \cdot 10^{-305}:\\
\;\;\;\;\left(-d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -4.0999999999999999e107Initial program 81.3%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6472.6
Applied rewrites72.6%
if -4.0999999999999999e107 < d2 < -2.7000000000000001e-164Initial program 95.2%
Taylor expanded in d1 around inf
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6444.6
Applied rewrites44.6%
if -2.7000000000000001e-164 < d2 < 2.40000000000000019e-305Initial program 91.3%
Taylor expanded in d3 around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6440.8
Applied rewrites40.8%
if 2.40000000000000019e-305 < d2 Initial program 86.9%
Taylor expanded in d4 around inf
*-commutativeN/A
lift-*.f6430.2
Applied rewrites30.2%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d1 -2.25e+29) (* (- (- d1) d3) d1) (if (<= d1 1.35e+156) (* (- (+ d4 d2) d3) d1) (* (fma -1.0 d1 d4) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d1 <= -2.25e+29) {
tmp = (-d1 - d3) * d1;
} else if (d1 <= 1.35e+156) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = fma(-1.0, d1, d4) * d1;
}
return tmp;
}
function code(d1, d2, d3, d4) tmp = 0.0 if (d1 <= -2.25e+29) tmp = Float64(Float64(Float64(-d1) - d3) * d1); elseif (d1 <= 1.35e+156) tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); else tmp = Float64(fma(-1.0, d1, d4) * d1); end return tmp end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d1, -2.25e+29], N[(N[((-d1) - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d1, 1.35e+156], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(-1.0 * d1 + d4), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -2.25 \cdot 10^{+29}:\\
\;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\
\mathbf{elif}\;d1 \leq 1.35 \cdot 10^{+156}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, d1, d4\right) \cdot d1\\
\end{array}
\end{array}
if d1 < -2.2500000000000001e29Initial program 79.1%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6487.8
Applied rewrites87.8%
Taylor expanded in d1 around inf
mul-1-negN/A
lower-neg.f6485.4
Applied rewrites85.4%
if -2.2500000000000001e29 < d1 < 1.35e156Initial program 98.7%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6491.5
Applied rewrites91.5%
if 1.35e156 < d1 Initial program 63.0%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6493.5
Applied rewrites93.5%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6497.8
Applied rewrites97.8%
Taylor expanded in d3 around 0
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-fma.f6495.7
Applied rewrites95.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.05e+116) (* (- d2 d3) d1) (if (<= d2 1.9e-304) (* (- (- d1) d3) d1) (* (fma -1.0 d1 d4) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.05e+116) {
tmp = (d2 - d3) * d1;
} else if (d2 <= 1.9e-304) {
tmp = (-d1 - d3) * d1;
} else {
tmp = fma(-1.0, d1, d4) * d1;
}
return tmp;
}
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.05e+116) tmp = Float64(Float64(d2 - d3) * d1); elseif (d2 <= 1.9e-304) tmp = Float64(Float64(Float64(-d1) - d3) * d1); else tmp = Float64(fma(-1.0, d1, d4) * d1); end return tmp end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.05e+116], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, 1.9e-304], N[(N[((-d1) - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(-1.0 * d1 + d4), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.05 \cdot 10^{+116}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{elif}\;d2 \leq 1.9 \cdot 10^{-304}:\\
\;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, d1, d4\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.0500000000000001e116Initial program 81.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6493.5
Applied rewrites93.5%
Taylor expanded in d2 around inf
Applied rewrites90.0%
if -1.0500000000000001e116 < d2 < 1.8999999999999998e-304Initial program 94.2%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6493.5
Applied rewrites93.5%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6493.5
Applied rewrites93.5%
Taylor expanded in d1 around inf
mul-1-negN/A
lower-neg.f6471.7
Applied rewrites71.7%
if 1.8999999999999998e-304 < d2 Initial program 86.9%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6479.5
Applied rewrites79.5%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6480.9
Applied rewrites80.9%
Taylor expanded in d3 around 0
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lift-fma.f6459.3
Applied rewrites59.3%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.05e+116) (* (- d2 d3) d1) (if (<= d2 2.15e-174) (* (- (- d1) d3) d1) (* (- d4 d3) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.05e+116) {
tmp = (d2 - d3) * d1;
} else if (d2 <= 2.15e-174) {
tmp = (-d1 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
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.05d+116)) then
tmp = (d2 - d3) * d1
else if (d2 <= 2.15d-174) then
tmp = (-d1 - d3) * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.05e+116) {
tmp = (d2 - d3) * d1;
} else if (d2 <= 2.15e-174) {
tmp = (-d1 - d3) * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.05e+116: tmp = (d2 - d3) * d1 elif d2 <= 2.15e-174: tmp = (-d1 - d3) * d1 else: tmp = (d4 - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.05e+116) tmp = Float64(Float64(d2 - d3) * d1); elseif (d2 <= 2.15e-174) tmp = Float64(Float64(Float64(-d1) - d3) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -1.05e+116) tmp = (d2 - d3) * d1; elseif (d2 <= 2.15e-174) tmp = (-d1 - d3) * d1; else tmp = (d4 - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.05e+116], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, 2.15e-174], N[(N[((-d1) - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.05 \cdot 10^{+116}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{elif}\;d2 \leq 2.15 \cdot 10^{-174}:\\
\;\;\;\;\left(\left(-d1\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.0500000000000001e116Initial program 81.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6493.5
Applied rewrites93.5%
Taylor expanded in d2 around inf
Applied rewrites90.0%
if -1.0500000000000001e116 < d2 < 2.1500000000000002e-174Initial program 91.7%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6494.6
Applied rewrites94.6%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6495.4
Applied rewrites95.4%
Taylor expanded in d1 around inf
mul-1-negN/A
lower-neg.f6474.3
Applied rewrites74.3%
if 2.1500000000000002e-174 < d2 Initial program 87.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6478.2
Applied rewrites78.2%
Taylor expanded in d2 around 0
Applied rewrites51.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (or (<= d1 -2.25e+29) (not (<= d1 1.35e+156))) (* (- d1) d1) (* (+ d2 d4) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d1 <= -2.25e+29) || !(d1 <= 1.35e+156)) {
tmp = -d1 * d1;
} else {
tmp = (d2 + d4) * d1;
}
return tmp;
}
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 <= (-2.25d+29)) .or. (.not. (d1 <= 1.35d+156))) then
tmp = -d1 * d1
else
tmp = (d2 + d4) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if ((d1 <= -2.25e+29) || !(d1 <= 1.35e+156)) {
tmp = -d1 * d1;
} else {
tmp = (d2 + d4) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if (d1 <= -2.25e+29) or not (d1 <= 1.35e+156): tmp = -d1 * d1 else: tmp = (d2 + d4) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if ((d1 <= -2.25e+29) || !(d1 <= 1.35e+156)) tmp = Float64(Float64(-d1) * d1); else tmp = Float64(Float64(d2 + d4) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if ((d1 <= -2.25e+29) || ~((d1 <= 1.35e+156))) tmp = -d1 * d1; else tmp = (d2 + d4) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[Or[LessEqual[d1, -2.25e+29], N[Not[LessEqual[d1, 1.35e+156]], $MachinePrecision]], N[((-d1) * d1), $MachinePrecision], N[(N[(d2 + d4), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq -2.25 \cdot 10^{+29} \lor \neg \left(d1 \leq 1.35 \cdot 10^{+156}\right):\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d2 + d4\right) \cdot d1\\
\end{array}
\end{array}
if d1 < -2.2500000000000001e29 or 1.35e156 < d1 Initial program 71.3%
Taylor expanded in d1 around inf
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6483.4
Applied rewrites83.4%
if -2.2500000000000001e29 < d1 < 1.35e156Initial program 98.7%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6491.5
Applied rewrites91.5%
Taylor expanded in d3 around 0
lower-+.f6460.6
Applied rewrites60.6%
Final simplification69.0%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.95e-7) (* (- d2 d3) d1) (if (<= d2 -6.2e-117) (* (- d1) d1) (* (- d4 d3) d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.95e-7) {
tmp = (d2 - d3) * d1;
} else if (d2 <= -6.2e-117) {
tmp = -d1 * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
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.95d-7)) then
tmp = (d2 - d3) * d1
else if (d2 <= (-6.2d-117)) then
tmp = -d1 * d1
else
tmp = (d4 - d3) * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.95e-7) {
tmp = (d2 - d3) * d1;
} else if (d2 <= -6.2e-117) {
tmp = -d1 * d1;
} else {
tmp = (d4 - d3) * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -1.95e-7: tmp = (d2 - d3) * d1 elif d2 <= -6.2e-117: tmp = -d1 * d1 else: tmp = (d4 - d3) * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.95e-7) tmp = Float64(Float64(d2 - d3) * d1); elseif (d2 <= -6.2e-117) tmp = Float64(Float64(-d1) * d1); else tmp = Float64(Float64(d4 - d3) * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -1.95e-7) tmp = (d2 - d3) * d1; elseif (d2 <= -6.2e-117) tmp = -d1 * d1; else tmp = (d4 - d3) * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.95e-7], N[(N[(d2 - d3), $MachinePrecision] * d1), $MachinePrecision], If[LessEqual[d2, -6.2e-117], N[((-d1) * d1), $MachinePrecision], N[(N[(d4 - d3), $MachinePrecision] * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.95 \cdot 10^{-7}:\\
\;\;\;\;\left(d2 - d3\right) \cdot d1\\
\mathbf{elif}\;d2 \leq -6.2 \cdot 10^{-117}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(d4 - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.95000000000000012e-7Initial program 86.5%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6490.4
Applied rewrites90.4%
Taylor expanded in d2 around inf
Applied rewrites77.2%
if -1.95000000000000012e-7 < d2 < -6.20000000000000022e-117Initial program 93.0%
Taylor expanded in d1 around inf
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6457.3
Applied rewrites57.3%
if -6.20000000000000022e-117 < d2 Initial program 88.5%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6472.0
Applied rewrites72.0%
Taylor expanded in d2 around 0
Applied rewrites56.3%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -1.05e+116) (* (- (+ d4 d2) d3) d1) (* (- (fma -1.0 d1 d4) d3) d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -1.05e+116) {
tmp = ((d4 + d2) - d3) * d1;
} else {
tmp = (fma(-1.0, d1, d4) - d3) * d1;
}
return tmp;
}
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -1.05e+116) tmp = Float64(Float64(Float64(d4 + d2) - d3) * d1); else tmp = Float64(Float64(fma(-1.0, d1, d4) - d3) * d1); end return tmp end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -1.05e+116], N[(N[(N[(d4 + d2), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision], N[(N[(N[(-1.0 * d1 + d4), $MachinePrecision] - d3), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -1.05 \cdot 10^{+116}:\\
\;\;\;\;\left(\left(d4 + d2\right) - d3\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{fma}\left(-1, d1, d4\right) - d3\right) \cdot d1\\
\end{array}
\end{array}
if d2 < -1.0500000000000001e116Initial program 81.3%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6493.5
Applied rewrites93.5%
if -1.0500000000000001e116 < d2 Initial program 89.7%
Taylor expanded in d2 around 0
associate--r+N/A
pow2N/A
fp-cancel-sub-sign-invN/A
distribute-lft-out--N/A
distribute-lft-neg-inN/A
pow2N/A
lower-fma.f64N/A
lower--.f64N/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6484.9
Applied rewrites84.9%
Taylor expanded in d1 around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-fma.f6485.8
Applied rewrites85.8%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -4.1e+107) (* d2 d1) (if (<= d2 2e-165) (* (- d1) d1) (* d4 d1))))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4.1e+107) {
tmp = d2 * d1;
} else if (d2 <= 2e-165) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
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 <= (-4.1d+107)) then
tmp = d2 * d1
else if (d2 <= 2d-165) then
tmp = -d1 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -4.1e+107) {
tmp = d2 * d1;
} else if (d2 <= 2e-165) {
tmp = -d1 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -4.1e+107: tmp = d2 * d1 elif d2 <= 2e-165: tmp = -d1 * d1 else: tmp = d4 * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -4.1e+107) tmp = Float64(d2 * d1); elseif (d2 <= 2e-165) tmp = Float64(Float64(-d1) * d1); else tmp = Float64(d4 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -4.1e+107) tmp = d2 * d1; elseif (d2 <= 2e-165) tmp = -d1 * d1; else tmp = d4 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -4.1e+107], N[(d2 * d1), $MachinePrecision], If[LessEqual[d2, 2e-165], N[((-d1) * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -4.1 \cdot 10^{+107}:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{elif}\;d2 \leq 2 \cdot 10^{-165}:\\
\;\;\;\;\left(-d1\right) \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -4.0999999999999999e107Initial program 81.3%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6472.6
Applied rewrites72.6%
if -4.0999999999999999e107 < d2 < 2e-165Initial program 91.8%
Taylor expanded in d1 around inf
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6447.8
Applied rewrites47.8%
if 2e-165 < d2 Initial program 87.2%
Taylor expanded in d4 around inf
*-commutativeN/A
lift-*.f6431.5
Applied rewrites31.5%
(FPCore (d1 d2 d3 d4) :precision binary64 (if (<= d2 -0.00192) (* d2 d1) (* d4 d1)))
double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -0.00192) {
tmp = d2 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
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 <= (-0.00192d0)) then
tmp = d2 * d1
else
tmp = d4 * d1
end if
code = tmp
end function
public static double code(double d1, double d2, double d3, double d4) {
double tmp;
if (d2 <= -0.00192) {
tmp = d2 * d1;
} else {
tmp = d4 * d1;
}
return tmp;
}
def code(d1, d2, d3, d4): tmp = 0 if d2 <= -0.00192: tmp = d2 * d1 else: tmp = d4 * d1 return tmp
function code(d1, d2, d3, d4) tmp = 0.0 if (d2 <= -0.00192) tmp = Float64(d2 * d1); else tmp = Float64(d4 * d1); end return tmp end
function tmp_2 = code(d1, d2, d3, d4) tmp = 0.0; if (d2 <= -0.00192) tmp = d2 * d1; else tmp = d4 * d1; end tmp_2 = tmp; end
code[d1_, d2_, d3_, d4_] := If[LessEqual[d2, -0.00192], N[(d2 * d1), $MachinePrecision], N[(d4 * d1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d2 \leq -0.00192:\\
\;\;\;\;d2 \cdot d1\\
\mathbf{else}:\\
\;\;\;\;d4 \cdot d1\\
\end{array}
\end{array}
if d2 < -0.00192000000000000005Initial program 86.3%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6458.5
Applied rewrites58.5%
if -0.00192000000000000005 < d2 Initial program 89.2%
Taylor expanded in d4 around inf
*-commutativeN/A
lift-*.f6430.7
Applied rewrites30.7%
(FPCore (d1 d2 d3 d4) :precision binary64 (* d2 d1))
double code(double d1, double d2, double d3, double d4) {
return d2 * 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 = d2 * d1
end function
public static double code(double d1, double d2, double d3, double d4) {
return d2 * d1;
}
def code(d1, d2, d3, d4): return d2 * d1
function code(d1, d2, d3, d4) return Float64(d2 * d1) end
function tmp = code(d1, d2, d3, d4) tmp = d2 * d1; end
code[d1_, d2_, d3_, d4_] := N[(d2 * d1), $MachinePrecision]
\begin{array}{l}
\\
d2 \cdot d1
\end{array}
Initial program 88.6%
Taylor expanded in d2 around inf
*-commutativeN/A
lower-*.f6426.7
Applied rewrites26.7%
herbie shell --seed 2025085
(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)))