
(FPCore (x y z) :precision binary64 (+ (+ x y) z))
double code(double x, double y, double z) {
return (x + y) + 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) + z
end function
public static double code(double x, double y, double z) {
return (x + y) + z;
}
def code(x, y, z): return (x + y) + z
function code(x, y, z) return Float64(Float64(x + y) + z) end
function tmp = code(x, y, z) tmp = (x + y) + z; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]
\left(x + y\right) + z
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x y) z))
double code(double x, double y, double z) {
return (x + y) + 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) + z
end function
public static double code(double x, double y, double z) {
return (x + y) + z;
}
def code(x, y, z): return (x + y) + z
function code(x, y, z) return Float64(Float64(x + y) + z) end
function tmp = code(x, y, z) tmp = (x + y) + z; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + z), $MachinePrecision]
\left(x + y\right) + z
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (fmin x z) (fmin y (fmax x z))))
(t_1 (fmax y (fmax x z))))
(if (<= (+ t_0 t_1) -1e-249) t_0 t_1)))double code(double x, double y, double z) {
double t_0 = fmin(x, z) + fmin(y, fmax(x, z));
double t_1 = fmax(y, fmax(x, z));
double tmp;
if ((t_0 + t_1) <= -1e-249) {
tmp = t_0;
} else {
tmp = t_1;
}
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(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = fmin(x, z) + fmin(y, fmax(x, z))
t_1 = fmax(y, fmax(x, z))
if ((t_0 + t_1) <= (-1d-249)) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = fmin(x, z) + fmin(y, fmax(x, z));
double t_1 = fmax(y, fmax(x, z));
double tmp;
if ((t_0 + t_1) <= -1e-249) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = fmin(x, z) + fmin(y, fmax(x, z)) t_1 = fmax(y, fmax(x, z)) tmp = 0 if (t_0 + t_1) <= -1e-249: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(fmin(x, z) + fmin(y, fmax(x, z))) t_1 = fmax(y, fmax(x, z)) tmp = 0.0 if (Float64(t_0 + t_1) <= -1e-249) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = min(x, z) + min(y, max(x, z)); t_1 = max(y, max(x, z)); tmp = 0.0; if ((t_0 + t_1) <= -1e-249) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Min[x, z], $MachinePrecision] + N[Min[y, N[Max[x, z], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Max[y, N[Max[x, z], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(t$95$0 + t$95$1), $MachinePrecision], -1e-249], t$95$0, t$95$1]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(x, z\right) + \mathsf{min}\left(y, \mathsf{max}\left(x, z\right)\right)\\
t_1 := \mathsf{max}\left(y, \mathsf{max}\left(x, z\right)\right)\\
\mathbf{if}\;t\_0 + t\_1 \leq -1 \cdot 10^{-249}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (+.f64 (+.f64 x y) z) < -1.0000000000000001e-249Initial program 100.0%
Taylor expanded in y around 0
lower-+.f6466.9%
Applied rewrites66.9%
Taylor expanded in x around 0
Applied rewrites33.3%
Taylor expanded in z around 0
lower-+.f6467.7%
Applied rewrites67.7%
if -1.0000000000000001e-249 < (+.f64 (+.f64 x y) z) Initial program 100.0%
Taylor expanded in y around 0
lower-+.f6466.9%
Applied rewrites66.9%
Taylor expanded in x around 0
Applied rewrites33.3%
(FPCore (x y z) :precision binary64 (+ (fmin (fmin x y) z) (fmax (fmax x y) (fmax (fmin x y) z))))
double code(double x, double y, double z) {
return fmin(fmin(x, y), z) + fmax(fmax(x, y), fmax(fmin(x, y), 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 = fmin(fmin(x, y), z) + fmax(fmax(x, y), fmax(fmin(x, y), z))
end function
public static double code(double x, double y, double z) {
return fmin(fmin(x, y), z) + fmax(fmax(x, y), fmax(fmin(x, y), z));
}
def code(x, y, z): return fmin(fmin(x, y), z) + fmax(fmax(x, y), fmax(fmin(x, y), z))
function code(x, y, z) return Float64(fmin(fmin(x, y), z) + fmax(fmax(x, y), fmax(fmin(x, y), z))) end
function tmp = code(x, y, z) tmp = min(min(x, y), z) + max(max(x, y), max(min(x, y), z)); end
code[x_, y_, z_] := N[(N[Min[N[Min[x, y], $MachinePrecision], z], $MachinePrecision] + N[Max[N[Max[x, y], $MachinePrecision], N[Max[N[Min[x, y], $MachinePrecision], z], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\mathsf{min}\left(\mathsf{min}\left(x, y\right), z\right) + \mathsf{max}\left(\mathsf{max}\left(x, y\right), \mathsf{max}\left(\mathsf{min}\left(x, y\right), z\right)\right)
Initial program 100.0%
Taylor expanded in y around 0
lower-+.f6466.9%
Applied rewrites66.9%
(FPCore (x y z) :precision binary64 (fmax y (fmax x z)))
double code(double x, double y, double z) {
return fmax(y, fmax(x, 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 = fmax(y, fmax(x, z))
end function
public static double code(double x, double y, double z) {
return fmax(y, fmax(x, z));
}
def code(x, y, z): return fmax(y, fmax(x, z))
function code(x, y, z) return fmax(y, fmax(x, z)) end
function tmp = code(x, y, z) tmp = max(y, max(x, z)); end
code[x_, y_, z_] := N[Max[y, N[Max[x, z], $MachinePrecision]], $MachinePrecision]
\mathsf{max}\left(y, \mathsf{max}\left(x, z\right)\right)
Initial program 100.0%
Taylor expanded in y around 0
lower-+.f6466.9%
Applied rewrites66.9%
Taylor expanded in x around 0
Applied rewrites33.3%
(FPCore (x y z) :precision binary64 (fmin y z))
double code(double x, double y, double z) {
return fmin(y, 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 = fmin(y, z)
end function
public static double code(double x, double y, double z) {
return fmin(y, z);
}
def code(x, y, z): return fmin(y, z)
function code(x, y, z) return fmin(y, z) end
function tmp = code(x, y, z) tmp = min(y, z); end
code[x_, y_, z_] := N[Min[y, z], $MachinePrecision]
\mathsf{min}\left(y, z\right)
Initial program 100.0%
Taylor expanded in y around 0
lower-+.f6466.9%
Applied rewrites66.9%
Taylor expanded in x around 0
Applied rewrites33.3%
Taylor expanded in y around inf
Applied rewrites34.2%
herbie shell --seed 2025258
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, I"
:precision binary64
(+ (+ x y) z))