
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= x_m 1.6e-44) (fma (/ x_m z) y x_m) (fma (/ y z) x_m x_m))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 1.6e-44) {
tmp = fma((x_m / z), y, x_m);
} else {
tmp = fma((y / z), x_m, x_m);
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 1.6e-44) tmp = fma(Float64(x_m / z), y, x_m); else tmp = fma(Float64(y / z), x_m, x_m); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 1.6e-44], N[(N[(x$95$m / z), $MachinePrecision] * y + x$95$m), $MachinePrecision], N[(N[(y / z), $MachinePrecision] * x$95$m + x$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 1.6 \cdot 10^{-44}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x\_m}{z}, y, x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x\_m, x\_m\right)\\
\end{array}
\end{array}
if x < 1.59999999999999997e-44Initial program 88.0%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites94.3%
Taylor expanded in x around 0
distribute-lft-inN/A
div-addN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-/.f6492.4
Applied rewrites92.4%
if 1.59999999999999997e-44 < x Initial program 79.7%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites99.9%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(let* ((t_0 (/ (* x_m (+ y z)) z)))
(*
x_s
(if (<= t_0 0.0)
(* x_m (/ y z))
(if (<= t_0 1e+151) (/ (* z x_m) z) (/ (* y x_m) z))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double t_0 = (x_m * (y + z)) / z;
double tmp;
if (t_0 <= 0.0) {
tmp = x_m * (y / z);
} else if (t_0 <= 1e+151) {
tmp = (z * x_m) / z;
} else {
tmp = (y * x_m) / z;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x_m * (y + z)) / z
if (t_0 <= 0.0d0) then
tmp = x_m * (y / z)
else if (t_0 <= 1d+151) then
tmp = (z * x_m) / z
else
tmp = (y * x_m) / z
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double t_0 = (x_m * (y + z)) / z;
double tmp;
if (t_0 <= 0.0) {
tmp = x_m * (y / z);
} else if (t_0 <= 1e+151) {
tmp = (z * x_m) / z;
} else {
tmp = (y * x_m) / z;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): t_0 = (x_m * (y + z)) / z tmp = 0 if t_0 <= 0.0: tmp = x_m * (y / z) elif t_0 <= 1e+151: tmp = (z * x_m) / z else: tmp = (y * x_m) / z return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) t_0 = Float64(Float64(x_m * Float64(y + z)) / z) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(x_m * Float64(y / z)); elseif (t_0 <= 1e+151) tmp = Float64(Float64(z * x_m) / z); else tmp = Float64(Float64(y * x_m) / z); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) t_0 = (x_m * (y + z)) / z; tmp = 0.0; if (t_0 <= 0.0) tmp = x_m * (y / z); elseif (t_0 <= 1e+151) tmp = (z * x_m) / z; else tmp = (y * x_m) / z; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(N[(x$95$m * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, 0.0], N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+151], N[(N[(z * x$95$m), $MachinePrecision] / z), $MachinePrecision], N[(N[(y * x$95$m), $MachinePrecision] / z), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := \frac{x\_m \cdot \left(y + z\right)}{z}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;x\_m \cdot \frac{y}{z}\\
\mathbf{elif}\;t\_0 \leq 10^{+151}:\\
\;\;\;\;\frac{z \cdot x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x\_m}{z}\\
\end{array}
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < 0.0Initial program 83.2%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites95.9%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6449.6
Applied rewrites49.6%
Applied rewrites51.5%
if 0.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.00000000000000002e151Initial program 99.5%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6462.9
Applied rewrites62.9%
if 1.00000000000000002e151 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 75.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6472.2
Applied rewrites72.2%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= (/ (* x_m (+ y z)) z) -2e-104)
(* x_m (/ y z))
(fma (/ x_m z) y x_m))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (((x_m * (y + z)) / z) <= -2e-104) {
tmp = x_m * (y / z);
} else {
tmp = fma((x_m / z), y, x_m);
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(Float64(x_m * Float64(y + z)) / z) <= -2e-104) tmp = Float64(x_m * Float64(y / z)); else tmp = fma(Float64(x_m / z), y, x_m); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(N[(x$95$m * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], -2e-104], N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m / z), $MachinePrecision] * y + x$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{x\_m \cdot \left(y + z\right)}{z} \leq -2 \cdot 10^{-104}:\\
\;\;\;\;x\_m \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x\_m}{z}, y, x\_m\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < -1.99999999999999985e-104Initial program 87.1%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites94.8%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6456.0
Applied rewrites56.0%
Applied rewrites58.4%
if -1.99999999999999985e-104 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 84.8%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites96.6%
Taylor expanded in x around 0
distribute-lft-inN/A
div-addN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-/.f6495.0
Applied rewrites95.0%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= (/ (* x_m (+ y z)) z) 5e-129) (* x_m (/ y z)) (/ (* y x_m) z))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (((x_m * (y + z)) / z) <= 5e-129) {
tmp = x_m * (y / z);
} else {
tmp = (y * x_m) / z;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((x_m * (y + z)) / z) <= 5d-129) then
tmp = x_m * (y / z)
else
tmp = (y * x_m) / z
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (((x_m * (y + z)) / z) <= 5e-129) {
tmp = x_m * (y / z);
} else {
tmp = (y * x_m) / z;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if ((x_m * (y + z)) / z) <= 5e-129: tmp = x_m * (y / z) else: tmp = (y * x_m) / z return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(Float64(x_m * Float64(y + z)) / z) <= 5e-129) tmp = Float64(x_m * Float64(y / z)); else tmp = Float64(Float64(y * x_m) / z); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (((x_m * (y + z)) / z) <= 5e-129) tmp = x_m * (y / z); else tmp = (y * x_m) / z; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(N[(x$95$m * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], 5e-129], N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(y * x$95$m), $MachinePrecision] / z), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{x\_m \cdot \left(y + z\right)}{z} \leq 5 \cdot 10^{-129}:\\
\;\;\;\;x\_m \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot x\_m}{z}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < 5.00000000000000027e-129Initial program 85.8%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites96.6%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6443.3
Applied rewrites43.3%
Applied rewrites45.5%
if 5.00000000000000027e-129 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 85.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6465.7
Applied rewrites65.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= x_m 2e+26) (* (/ x_m z) y) (* x_m (/ y z)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 2e+26) {
tmp = (x_m / z) * y;
} else {
tmp = x_m * (y / z);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x_m <= 2d+26) then
tmp = (x_m / z) * y
else
tmp = x_m * (y / z)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (x_m <= 2e+26) {
tmp = (x_m / z) * y;
} else {
tmp = x_m * (y / z);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if x_m <= 2e+26: tmp = (x_m / z) * y else: tmp = x_m * (y / z) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (x_m <= 2e+26) tmp = Float64(Float64(x_m / z) * y); else tmp = Float64(x_m * Float64(y / z)); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (x_m <= 2e+26) tmp = (x_m / z) * y; else tmp = x_m * (y / z); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 2e+26], N[(N[(x$95$m / z), $MachinePrecision] * y), $MachinePrecision], N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 2 \cdot 10^{+26}:\\
\;\;\;\;\frac{x\_m}{z} \cdot y\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \frac{y}{z}\\
\end{array}
\end{array}
if x < 2.0000000000000001e26Initial program 88.6%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites94.8%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6449.6
Applied rewrites49.6%
if 2.0000000000000001e26 < x Initial program 74.7%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites99.9%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6449.1
Applied rewrites49.1%
Applied rewrites65.1%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (* x_m (/ y z))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m * (y / z));
}
x\_m = private
x\_s = private
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_s, x_m, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * (x_m * (y / z))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
return x_s * (x_m * (y / z));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): return x_s * (x_m * (y / z))
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) return Float64(x_s * Float64(x_m * Float64(y / z))) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m, y, z) tmp = x_s * (x_m * (y / z)); end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * N[(x$95$m * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \left(x\_m \cdot \frac{y}{z}\right)
\end{array}
Initial program 85.8%
Taylor expanded in x around 0
distribute-lft-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
associate-*l*N/A
*-commutativeN/A
associate-*r/N/A
associate-*r*N/A
associate-/l*N/A
*-commutativeN/A
distribute-rgt-out--N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-lft-neg-inN/A
Applied rewrites95.8%
Taylor expanded in y around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6449.5
Applied rewrites49.5%
Applied rewrites50.9%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (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 / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2025017
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (/ x (/ z (+ y z))))
(/ (* x (+ y z)) z))