
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
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 - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
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 - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- z x) y x))
double code(double x, double y, double z) {
return fma((z - x), y, x);
}
function code(x, y, z) return fma(Float64(z - x), y, x) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, y, x\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift--.f64N/A
lower-+.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lift--.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -1.0) t_0 (if (<= y 1.0) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.0) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.0], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
lift--.f64N/A
flip--N/A
div-subN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
div-subN/A
*-lft-identityN/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
flip--N/A
fp-cancel-sign-sub-invN/A
distribute-rgt-outN/A
Applied rewrites99.1%
Taylor expanded in y around inf
flip-+N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
sqr-neg-revN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
*-lft-identityN/A
associate-*r/N/A
flip--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6464.6
Applied rewrites64.6%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.5
Applied rewrites76.5%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e+20) (* (- 1.0 y) x) (if (<= x 4.7e-8) (fma z y x) (- x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+20) {
tmp = (1.0 - y) * x;
} else if (x <= 4.7e-8) {
tmp = fma(z, y, x);
} else {
tmp = x - (y * x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.95e+20) tmp = Float64(Float64(1.0 - y) * x); elseif (x <= 4.7e-8) tmp = fma(z, y, x); else tmp = Float64(x - Float64(y * x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+20], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 4.7e-8], N[(z * y + x), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+20}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if x < -1.95e20Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
if -1.95e20 < x < 4.6999999999999997e-8Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.5
Applied rewrites76.5%
if 4.6999999999999997e-8 < x Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
lift-*.f64N/A
lift--.f64N/A
*-commutativeN/A
*-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
*-rgt-identityN/A
mul-1-negN/A
distribute-rgt-neg-outN/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.1
Applied rewrites62.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) x))) (if (<= x -1.95e+20) t_0 (if (<= x 4.7e-8) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * x;
double tmp;
if (x <= -1.95e+20) {
tmp = t_0;
} else if (x <= 4.7e-8) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * x) tmp = 0.0 if (x <= -1.95e+20) tmp = t_0; elseif (x <= 4.7e-8) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.95e+20], t$95$0, If[LessEqual[x, 4.7e-8], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot x\\
\mathbf{if}\;x \leq -1.95 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.95e20 or 4.6999999999999997e-8 < x Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
if -1.95e20 < x < 4.6999999999999997e-8Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.5
Applied rewrites76.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y) x)))
(if (<= y -2.2e+195)
(fma z y x)
(if (<= y -6.6e+22) t_0 (if (<= y 2.8e+139) (fma z y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -2.2e+195) {
tmp = fma(z, y, x);
} else if (y <= -6.6e+22) {
tmp = t_0;
} else if (y <= 2.8e+139) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (y <= -2.2e+195) tmp = fma(z, y, x); elseif (y <= -6.6e+22) tmp = t_0; elseif (y <= 2.8e+139) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[y, -2.2e+195], N[(z * y + x), $MachinePrecision], If[LessEqual[y, -6.6e+22], t$95$0, If[LessEqual[y, 2.8e+139], N[(z * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;y \leq -2.2 \cdot 10^{+195}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;y \leq -6.6 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2e195 or -6.5999999999999996e22 < y < 2.7999999999999998e139Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.5
Applied rewrites76.5%
if -2.2e195 < y < -6.5999999999999996e22 or 2.7999999999999998e139 < y Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6427.5
Applied rewrites27.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- y) x)))
(if (<= y -2.2e+195)
(* z y)
(if (<= y -6.5e+22)
t_0
(if (<= y -2.6e-21)
(* z y)
(if (<= y 2.55e-55) (* 1.0 x) (if (<= y 2.8e+139) (* z y) t_0)))))))
double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -2.2e+195) {
tmp = z * y;
} else if (y <= -6.5e+22) {
tmp = t_0;
} else if (y <= -2.6e-21) {
tmp = z * y;
} else if (y <= 2.55e-55) {
tmp = 1.0 * x;
} else if (y <= 2.8e+139) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(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) :: tmp
t_0 = -y * x
if (y <= (-2.2d+195)) then
tmp = z * y
else if (y <= (-6.5d+22)) then
tmp = t_0
else if (y <= (-2.6d-21)) then
tmp = z * y
else if (y <= 2.55d-55) then
tmp = 1.0d0 * x
else if (y <= 2.8d+139) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -y * x;
double tmp;
if (y <= -2.2e+195) {
tmp = z * y;
} else if (y <= -6.5e+22) {
tmp = t_0;
} else if (y <= -2.6e-21) {
tmp = z * y;
} else if (y <= 2.55e-55) {
tmp = 1.0 * x;
} else if (y <= 2.8e+139) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -y * x tmp = 0 if y <= -2.2e+195: tmp = z * y elif y <= -6.5e+22: tmp = t_0 elif y <= -2.6e-21: tmp = z * y elif y <= 2.55e-55: tmp = 1.0 * x elif y <= 2.8e+139: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (y <= -2.2e+195) tmp = Float64(z * y); elseif (y <= -6.5e+22) tmp = t_0; elseif (y <= -2.6e-21) tmp = Float64(z * y); elseif (y <= 2.55e-55) tmp = Float64(1.0 * x); elseif (y <= 2.8e+139) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -y * x; tmp = 0.0; if (y <= -2.2e+195) tmp = z * y; elseif (y <= -6.5e+22) tmp = t_0; elseif (y <= -2.6e-21) tmp = z * y; elseif (y <= 2.55e-55) tmp = 1.0 * x; elseif (y <= 2.8e+139) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * x), $MachinePrecision]}, If[LessEqual[y, -2.2e+195], N[(z * y), $MachinePrecision], If[LessEqual[y, -6.5e+22], t$95$0, If[LessEqual[y, -2.6e-21], N[(z * y), $MachinePrecision], If[LessEqual[y, 2.55e-55], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 2.8e+139], N[(z * y), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;y \leq -2.2 \cdot 10^{+195}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq -6.5 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-21}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-55}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+139}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2e195 or -6.49999999999999979e22 < y < -2.60000000000000017e-21 or 2.54999999999999998e-55 < y < 2.7999999999999998e139Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6441.8
Applied rewrites41.8%
if -2.2e195 < y < -6.49999999999999979e22 or 2.7999999999999998e139 < y Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6427.5
Applied rewrites27.5%
if -2.60000000000000017e-21 < y < 2.54999999999999998e-55Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
Taylor expanded in y around 0
Applied rewrites37.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.6e-21) (* z y) (if (<= y 2.55e-55) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e-21) {
tmp = z * y;
} else if (y <= 2.55e-55) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
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) :: tmp
if (y <= (-2.6d-21)) then
tmp = z * y
else if (y <= 2.55d-55) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e-21) {
tmp = z * y;
} else if (y <= 2.55e-55) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.6e-21: tmp = z * y elif y <= 2.55e-55: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.6e-21) tmp = Float64(z * y); elseif (y <= 2.55e-55) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.6e-21) tmp = z * y; elseif (y <= 2.55e-55) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.6e-21], N[(z * y), $MachinePrecision], If[LessEqual[y, 2.55e-55], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-21}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-55}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -2.60000000000000017e-21 or 2.54999999999999998e-55 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6441.8
Applied rewrites41.8%
if -2.60000000000000017e-21 < y < 2.54999999999999998e-55Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
*-commutativeN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
metadata-evalN/A
distribute-neg-outN/A
metadata-evalN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
Applied rewrites62.1%
Taylor expanded in y around 0
Applied rewrites37.1%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
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 = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6441.8
Applied rewrites41.8%
herbie shell --seed 2025138
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))