
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (- (+ x y) z) (* t 2.0)))
double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x + y) - z) / (t * 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return ((x + y) - z) / (t * 2.0);
}
def code(x, y, z, t): return ((x + y) - z) / (t * 2.0)
function code(x, y, z, t) return Float64(Float64(Float64(x + y) - z) / Float64(t * 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x + y) - z) / (t * 2.0); end
code[x_, y_, z_, t_] := N[(N[(N[(x + y), $MachinePrecision] - z), $MachinePrecision] / N[(t * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x + y\right) - z}{t \cdot 2}
\end{array}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (/ (+ (- y z) x) (+ t t)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
return ((y - z) + x) / (t + t);
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((y - z) + x) / (t + t)
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
return ((y - z) + x) / (t + t);
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): return ((y - z) + x) / (t + t)
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) return Float64(Float64(Float64(y - z) + x) / Float64(t + t)) end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
tmp = ((y - z) + x) / (t + t);
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(N[(y - z), $MachinePrecision] + x), $MachinePrecision] / N[(t + t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\frac{\left(y - z\right) + x}{t + t}
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f64100.0
Applied rewrites100.0%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (or (<= (+ x y) -4e-67) (not (<= (+ x y) 2e-19))) (/ (+ x y) (+ t t)) (/ (* -0.5 z) t)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if (((x + y) <= -4e-67) || !((x + y) <= 2e-19)) {
tmp = (x + y) / (t + t);
} else {
tmp = (-0.5 * z) / t;
}
return tmp;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (((x + y) <= (-4d-67)) .or. (.not. ((x + y) <= 2d-19))) then
tmp = (x + y) / (t + t)
else
tmp = ((-0.5d0) * z) / t
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if (((x + y) <= -4e-67) || !((x + y) <= 2e-19)) {
tmp = (x + y) / (t + t);
} else {
tmp = (-0.5 * z) / t;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if ((x + y) <= -4e-67) or not ((x + y) <= 2e-19): tmp = (x + y) / (t + t) else: tmp = (-0.5 * z) / t return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if ((Float64(x + y) <= -4e-67) || !(Float64(x + y) <= 2e-19)) tmp = Float64(Float64(x + y) / Float64(t + t)); else tmp = Float64(Float64(-0.5 * z) / t); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if (((x + y) <= -4e-67) || ~(((x + y) <= 2e-19)))
tmp = (x + y) / (t + t);
else
tmp = (-0.5 * z) / t;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x + y), $MachinePrecision], -4e-67], N[Not[LessEqual[N[(x + y), $MachinePrecision], 2e-19]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / N[(t + t), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * z), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -4 \cdot 10^{-67} \lor \neg \left(x + y \leq 2 \cdot 10^{-19}\right):\\
\;\;\;\;\frac{x + y}{t + t}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot z}{t}\\
\end{array}
\end{array}
if (+.f64 x y) < -3.99999999999999977e-67 or 2e-19 < (+.f64 x y) Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
lower-+.f6483.6
Applied rewrites83.6%
if -3.99999999999999977e-67 < (+.f64 x y) < 2e-19Initial program 100.0%
Taylor expanded in z around inf
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6488.7
Applied rewrites88.7%
Applied rewrites88.9%
Final simplification84.5%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (+ x y) -4e-67) (* (/ x t) 0.5) (if (<= (+ x y) 2e-19) (/ (* -0.5 z) t) (* (/ y t) 0.5))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -4e-67) {
tmp = (x / t) * 0.5;
} else if ((x + y) <= 2e-19) {
tmp = (-0.5 * z) / t;
} else {
tmp = (y / t) * 0.5;
}
return tmp;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x + y) <= (-4d-67)) then
tmp = (x / t) * 0.5d0
else if ((x + y) <= 2d-19) then
tmp = ((-0.5d0) * z) / t
else
tmp = (y / t) * 0.5d0
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -4e-67) {
tmp = (x / t) * 0.5;
} else if ((x + y) <= 2e-19) {
tmp = (-0.5 * z) / t;
} else {
tmp = (y / t) * 0.5;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (x + y) <= -4e-67: tmp = (x / t) * 0.5 elif (x + y) <= 2e-19: tmp = (-0.5 * z) / t else: tmp = (y / t) * 0.5 return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(x + y) <= -4e-67) tmp = Float64(Float64(x / t) * 0.5); elseif (Float64(x + y) <= 2e-19) tmp = Float64(Float64(-0.5 * z) / t); else tmp = Float64(Float64(y / t) * 0.5); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((x + y) <= -4e-67)
tmp = (x / t) * 0.5;
elseif ((x + y) <= 2e-19)
tmp = (-0.5 * z) / t;
else
tmp = (y / t) * 0.5;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(x + y), $MachinePrecision], -4e-67], N[(N[(x / t), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], 2e-19], N[(N[(-0.5 * z), $MachinePrecision] / t), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -4 \cdot 10^{-67}:\\
\;\;\;\;\frac{x}{t} \cdot 0.5\\
\mathbf{elif}\;x + y \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{-0.5 \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t} \cdot 0.5\\
\end{array}
\end{array}
if (+.f64 x y) < -3.99999999999999977e-67Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6433.3
Applied rewrites33.3%
if -3.99999999999999977e-67 < (+.f64 x y) < 2e-19Initial program 100.0%
Taylor expanded in z around inf
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6488.7
Applied rewrites88.7%
Applied rewrites88.9%
if 2e-19 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around 0
div-add-revN/A
*-commutativeN/A
lower-*.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6488.5
Applied rewrites88.5%
Taylor expanded in x around 0
Applied rewrites45.4%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (+ x y) -4e-67) (* (/ x t) 0.5) (if (<= (+ x y) 2e-19) (* (/ -0.5 t) z) (* (/ y t) 0.5))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -4e-67) {
tmp = (x / t) * 0.5;
} else if ((x + y) <= 2e-19) {
tmp = (-0.5 / t) * z;
} else {
tmp = (y / t) * 0.5;
}
return tmp;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x + y) <= (-4d-67)) then
tmp = (x / t) * 0.5d0
else if ((x + y) <= 2d-19) then
tmp = ((-0.5d0) / t) * z
else
tmp = (y / t) * 0.5d0
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -4e-67) {
tmp = (x / t) * 0.5;
} else if ((x + y) <= 2e-19) {
tmp = (-0.5 / t) * z;
} else {
tmp = (y / t) * 0.5;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (x + y) <= -4e-67: tmp = (x / t) * 0.5 elif (x + y) <= 2e-19: tmp = (-0.5 / t) * z else: tmp = (y / t) * 0.5 return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(x + y) <= -4e-67) tmp = Float64(Float64(x / t) * 0.5); elseif (Float64(x + y) <= 2e-19) tmp = Float64(Float64(-0.5 / t) * z); else tmp = Float64(Float64(y / t) * 0.5); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((x + y) <= -4e-67)
tmp = (x / t) * 0.5;
elseif ((x + y) <= 2e-19)
tmp = (-0.5 / t) * z;
else
tmp = (y / t) * 0.5;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(x + y), $MachinePrecision], -4e-67], N[(N[(x / t), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], 2e-19], N[(N[(-0.5 / t), $MachinePrecision] * z), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -4 \cdot 10^{-67}:\\
\;\;\;\;\frac{x}{t} \cdot 0.5\\
\mathbf{elif}\;x + y \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{-0.5}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t} \cdot 0.5\\
\end{array}
\end{array}
if (+.f64 x y) < -3.99999999999999977e-67Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6433.3
Applied rewrites33.3%
if -3.99999999999999977e-67 < (+.f64 x y) < 2e-19Initial program 100.0%
Taylor expanded in z around inf
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6488.7
Applied rewrites88.7%
if 2e-19 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around 0
div-add-revN/A
*-commutativeN/A
lower-*.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6488.5
Applied rewrites88.5%
Taylor expanded in x around 0
Applied rewrites45.4%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (+ x y) -1e-178) (/ (- x z) (+ t t)) (/ (- y z) (+ t t))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -1e-178) {
tmp = (x - z) / (t + t);
} else {
tmp = (y - z) / (t + t);
}
return tmp;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x + y) <= (-1d-178)) then
tmp = (x - z) / (t + t)
else
tmp = (y - z) / (t + t)
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= -1e-178) {
tmp = (x - z) / (t + t);
} else {
tmp = (y - z) / (t + t);
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (x + y) <= -1e-178: tmp = (x - z) / (t + t) else: tmp = (y - z) / (t + t) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(x + y) <= -1e-178) tmp = Float64(Float64(x - z) / Float64(t + t)); else tmp = Float64(Float64(y - z) / Float64(t + t)); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((x + y) <= -1e-178)
tmp = (x - z) / (t + t);
else
tmp = (y - z) / (t + t);
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-178], N[(N[(x - z), $MachinePrecision] / N[(t + t), $MachinePrecision]), $MachinePrecision], N[(N[(y - z), $MachinePrecision] / N[(t + t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{-178}:\\
\;\;\;\;\frac{x - z}{t + t}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - z}{t + t}\\
\end{array}
\end{array}
if (+.f64 x y) < -9.9999999999999995e-179Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
lower-+.f6474.9
Applied rewrites74.9%
Taylor expanded in y around 0
lower--.f6456.5
Applied rewrites56.5%
if -9.9999999999999995e-179 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
lower--.f6468.9
Applied rewrites68.9%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6468.9
Applied rewrites68.9%
Final simplification62.8%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (+ x y) 2e-19) (/ (- x z) (+ t t)) (/ (+ x y) (+ t t))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= 2e-19) {
tmp = (x - z) / (t + t);
} else {
tmp = (x + y) / (t + t);
}
return tmp;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x + y) <= 2d-19) then
tmp = (x - z) / (t + t)
else
tmp = (x + y) / (t + t)
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= 2e-19) {
tmp = (x - z) / (t + t);
} else {
tmp = (x + y) / (t + t);
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (x + y) <= 2e-19: tmp = (x - z) / (t + t) else: tmp = (x + y) / (t + t) return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(x + y) <= 2e-19) tmp = Float64(Float64(x - z) / Float64(t + t)); else tmp = Float64(Float64(x + y) / Float64(t + t)); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((x + y) <= 2e-19)
tmp = (x - z) / (t + t);
else
tmp = (x + y) / (t + t);
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(x + y), $MachinePrecision], 2e-19], N[(N[(x - z), $MachinePrecision] / N[(t + t), $MachinePrecision]), $MachinePrecision], N[(N[(x + y), $MachinePrecision] / N[(t + t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{x - z}{t + t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x + y}{t + t}\\
\end{array}
\end{array}
if (+.f64 x y) < 2e-19Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
lower-+.f6463.4
Applied rewrites63.4%
Taylor expanded in y around 0
lower--.f6464.3
Applied rewrites64.3%
if 2e-19 < (+.f64 x y) Initial program 100.0%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
+-commutativeN/A
lower-+.f64N/A
lower--.f64100.0
Applied rewrites100.0%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
lower-+.f6488.5
Applied rewrites88.5%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (if (<= (+ x y) 2e-19) (* (/ -0.5 t) z) (* (/ y t) 0.5)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= 2e-19) {
tmp = (-0.5 / t) * z;
} else {
tmp = (y / t) * 0.5;
}
return tmp;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x + y) <= 2d-19) then
tmp = ((-0.5d0) / t) * z
else
tmp = (y / t) * 0.5d0
end if
code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x + y) <= 2e-19) {
tmp = (-0.5 / t) * z;
} else {
tmp = (y / t) * 0.5;
}
return tmp;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): tmp = 0 if (x + y) <= 2e-19: tmp = (-0.5 / t) * z else: tmp = (y / t) * 0.5 return tmp
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) tmp = 0.0 if (Float64(x + y) <= 2e-19) tmp = Float64(Float64(-0.5 / t) * z); else tmp = Float64(Float64(y / t) * 0.5); end return tmp end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
tmp = 0.0;
if ((x + y) <= 2e-19)
tmp = (-0.5 / t) * z;
else
tmp = (y / t) * 0.5;
end
tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := If[LessEqual[N[(x + y), $MachinePrecision], 2e-19], N[(N[(-0.5 / t), $MachinePrecision] * z), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq 2 \cdot 10^{-19}:\\
\;\;\;\;\frac{-0.5}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t} \cdot 0.5\\
\end{array}
\end{array}
if (+.f64 x y) < 2e-19Initial program 100.0%
Taylor expanded in z around inf
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6442.6
Applied rewrites42.6%
if 2e-19 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around 0
div-add-revN/A
*-commutativeN/A
lower-*.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6488.5
Applied rewrites88.5%
Taylor expanded in x around 0
Applied rewrites45.4%
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x y z t) :precision binary64 (* (/ y t) 0.5))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
return (y / t) * 0.5;
}
NOTE: x, y, z, and t 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(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (y / t) * 0.5d0
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
return (y / t) * 0.5;
}
[x, y, z, t] = sort([x, y, z, t]) def code(x, y, z, t): return (y / t) * 0.5
x, y, z, t = sort([x, y, z, t]) function code(x, y, z, t) return Float64(Float64(y / t) * 0.5) end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
tmp = (y / t) * 0.5;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function. code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\frac{y}{t} \cdot 0.5
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
div-add-revN/A
*-commutativeN/A
lower-*.f64N/A
div-add-revN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6473.0
Applied rewrites73.0%
Taylor expanded in x around 0
Applied rewrites42.6%
herbie shell --seed 2025015
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, B"
:precision binary64
(/ (- (+ x y) z) (* t 2.0)))