
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ (fma (- z) (+ x y) y) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(-z, (x + y), y) + x;
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(fma(Float64(-z), Float64(x + y), y) + x) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[((-z) * N[(x + y), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(-z, x + y, y\right) + x
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-64) (* x (- z)) (if (<= (+ x y) 2e-283) (+ y x) (fma (- y) z y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-64) {
tmp = x * -z;
} else if ((x + y) <= 2e-283) {
tmp = y + x;
} else {
tmp = fma(-y, z, y);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e-64) tmp = Float64(x * Float64(-z)); elseif (Float64(x + y) <= 2e-283) tmp = Float64(y + x); else tmp = fma(Float64(-y), z, y); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-64], N[(x * (-z)), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], 2e-283], N[(y + x), $MachinePrecision], N[((-y) * z + y), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{-64}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;x + y \leq 2 \cdot 10^{-283}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, z, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -9.99999999999999965e-65Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites48.8%
Taylor expanded in z around 0
Applied rewrites22.8%
Taylor expanded in z around inf
mul-1-negN/A
lift-neg.f6427.6
Applied rewrites27.6%
if -9.99999999999999965e-65 < (+.f64 x y) < 1.99999999999999989e-283Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6456.8
Applied rewrites56.8%
if 1.99999999999999989e-283 < (+.f64 x y) Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6448.0
Applied rewrites48.0%
Final simplification41.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (- 1.0 z) -2000.0) (not (<= (- 1.0 z) 5000000000.0))) (* x (- z)) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -2000.0) || !((1.0 - z) <= 5000000000.0)) {
tmp = x * -z;
} else {
tmp = y + x;
}
return tmp;
}
NOTE: x, y, and z 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((1.0d0 - z) <= (-2000.0d0)) .or. (.not. ((1.0d0 - z) <= 5000000000.0d0))) then
tmp = x * -z
else
tmp = y + x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((1.0 - z) <= -2000.0) || !((1.0 - z) <= 5000000000.0)) {
tmp = x * -z;
} else {
tmp = y + x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((1.0 - z) <= -2000.0) or not ((1.0 - z) <= 5000000000.0): tmp = x * -z else: tmp = y + x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(1.0 - z) <= -2000.0) || !(Float64(1.0 - z) <= 5000000000.0)) tmp = Float64(x * Float64(-z)); else tmp = Float64(y + x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((1.0 - z) <= -2000.0) || ~(((1.0 - z) <= 5000000000.0)))
tmp = x * -z;
else
tmp = y + x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[N[(1.0 - z), $MachinePrecision], -2000.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 5000000000.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -2000 \lor \neg \left(1 - z \leq 5000000000\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -2e3 or 5e9 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites51.2%
Taylor expanded in z around 0
Applied rewrites2.9%
Taylor expanded in z around inf
mul-1-negN/A
lift-neg.f6450.8
Applied rewrites50.8%
if -2e3 < (-.f64 #s(literal 1 binary64) z) < 5e9Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6494.8
Applied rewrites94.8%
Final simplification72.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (- 1.0 z) -2000.0) (* x (- z)) (if (<= (- 1.0 z) 2.0) (+ y x) (* y (- z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= -2000.0) {
tmp = x * -z;
} else if ((1.0 - z) <= 2.0) {
tmp = y + x;
} else {
tmp = y * -z;
}
return tmp;
}
NOTE: x, y, and z 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((1.0d0 - z) <= (-2000.0d0)) then
tmp = x * -z
else if ((1.0d0 - z) <= 2.0d0) then
tmp = y + x
else
tmp = y * -z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((1.0 - z) <= -2000.0) {
tmp = x * -z;
} else if ((1.0 - z) <= 2.0) {
tmp = y + x;
} else {
tmp = y * -z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (1.0 - z) <= -2000.0: tmp = x * -z elif (1.0 - z) <= 2.0: tmp = y + x else: tmp = y * -z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(1.0 - z) <= -2000.0) tmp = Float64(x * Float64(-z)); elseif (Float64(1.0 - z) <= 2.0) tmp = Float64(y + x); else tmp = Float64(y * Float64(-z)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((1.0 - z) <= -2000.0)
tmp = x * -z;
elseif ((1.0 - z) <= 2.0)
tmp = y + x;
else
tmp = y * -z;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(1.0 - z), $MachinePrecision], -2000.0], N[(x * (-z)), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 2.0], N[(y + x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 - z \leq -2000:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;1 - z \leq 2:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) z) < -2e3Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites46.6%
Taylor expanded in z around 0
Applied rewrites1.6%
Taylor expanded in z around inf
mul-1-negN/A
lift-neg.f6445.7
Applied rewrites45.7%
if -2e3 < (-.f64 #s(literal 1 binary64) z) < 2Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.5
Applied rewrites97.5%
if 2 < (-.f64 #s(literal 1 binary64) z) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites44.1%
Taylor expanded in z around 0
Applied rewrites4.3%
Taylor expanded in z around inf
mul-1-negN/A
lift-neg.f6443.9
Applied rewrites43.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -4e-300) (fma (- z) x x) (fma (- y) z y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -4e-300) {
tmp = fma(-z, x, x);
} else {
tmp = fma(-y, z, y);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -4e-300) tmp = fma(Float64(-z), x, x); else tmp = fma(Float64(-y), z, y); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -4e-300], N[((-z) * x + x), $MachinePrecision], N[((-y) * z + y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -4 \cdot 10^{-300}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, z, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -4.0000000000000001e-300Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f6448.5
Applied rewrites48.5%
if -4.0000000000000001e-300 < (+.f64 x y) Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6448.0
Applied rewrites48.0%
Final simplification48.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* (+ x y) (- 1.0 z)) -5e-227) x y))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -5e-227) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
NOTE: x, y, and z 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((x + y) * (1.0d0 - z)) <= (-5d-227)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -5e-227) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((x + y) * (1.0 - z)) <= -5e-227: tmp = x else: tmp = y return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(Float64(x + y) * Float64(1.0 - z)) <= -5e-227) tmp = x; else tmp = y; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (((x + y) * (1.0 - z)) <= -5e-227)
tmp = x;
else
tmp = y;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], -5e-227], x, y]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) \cdot \left(1 - z\right) \leq -5 \cdot 10^{-227}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -4.99999999999999961e-227Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f6448.0
Applied rewrites48.0%
Taylor expanded in z around 0
Applied rewrites24.5%
if -4.99999999999999961e-227 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6447.9
Applied rewrites47.9%
Taylor expanded in z around 0
Applied rewrites24.2%
Final simplification24.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
NOTE: x, y, and z 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (1.0d0 - z)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x + y) * (1.0 - z)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x + y) * (1.0 - z);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Initial program 100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ y x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y + x;
}
NOTE: x, y, and z 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y + x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y + x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y + x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y + x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y + x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6448.5
Applied rewrites48.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 y)
assert(x < y && y < z);
double code(double x, double y, double z) {
return y;
}
NOTE: x, y, and z 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y
x, y, z = sort([x, y, z]) function code(x, y, z) return y end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := y
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt1-inN/A
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
lift-+.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
associate-+r+N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lift-neg.f64N/A
lift-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
mul-1-negN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6449.9
Applied rewrites49.9%
Taylor expanded in z around 0
Applied rewrites25.6%
Final simplification25.6%
herbie shell --seed 2025080
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))