
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ z y) x (- z)))
double code(double x, double y, double z) {
return fma((z + y), x, -z);
}
function code(x, y, z) return fma(Float64(z + y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(z + y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + y, x, -z\right)
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.15e-34)
(* y x)
(if (<= x 2.6e-11)
(- z)
(if (or (<= x 2.3e+28) (not (<= x 8.5e+125))) (* y x) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-34) {
tmp = y * x;
} else if (x <= 2.6e-11) {
tmp = -z;
} else if ((x <= 2.3e+28) || !(x <= 8.5e+125)) {
tmp = y * x;
} else {
tmp = x * z;
}
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 (x <= (-1.15d-34)) then
tmp = y * x
else if (x <= 2.6d-11) then
tmp = -z
else if ((x <= 2.3d+28) .or. (.not. (x <= 8.5d+125))) then
tmp = y * x
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-34) {
tmp = y * x;
} else if (x <= 2.6e-11) {
tmp = -z;
} else if ((x <= 2.3e+28) || !(x <= 8.5e+125)) {
tmp = y * x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.15e-34: tmp = y * x elif x <= 2.6e-11: tmp = -z elif (x <= 2.3e+28) or not (x <= 8.5e+125): tmp = y * x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.15e-34) tmp = Float64(y * x); elseif (x <= 2.6e-11) tmp = Float64(-z); elseif ((x <= 2.3e+28) || !(x <= 8.5e+125)) tmp = Float64(y * x); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.15e-34) tmp = y * x; elseif (x <= 2.6e-11) tmp = -z; elseif ((x <= 2.3e+28) || ~((x <= 8.5e+125))) tmp = y * x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.15e-34], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.6e-11], (-z), If[Or[LessEqual[x, 2.3e+28], N[Not[LessEqual[x, 8.5e+125]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-34}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{-11}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+28} \lor \neg \left(x \leq 8.5 \cdot 10^{+125}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.15000000000000006e-34 or 2.6000000000000001e-11 < x < 2.29999999999999984e28 or 8.49999999999999974e125 < x Initial program 97.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.6
Applied rewrites96.6%
Applied rewrites95.7%
Taylor expanded in y around 0
Applied rewrites36.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6465.7
Applied rewrites65.7%
if -1.15000000000000006e-34 < x < 2.6000000000000001e-11Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6480.1
Applied rewrites80.1%
if 2.29999999999999984e28 < x < 8.49999999999999974e125Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites77.1%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.15e-34) (not (<= x 5.7e-8))) (* (+ z y) x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e-34) || !(x <= 5.7e-8)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
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 ((x <= (-1.15d-34)) .or. (.not. (x <= 5.7d-8))) then
tmp = (z + y) * x
else
tmp = ((-1.0d0) + x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e-34) || !(x <= 5.7e-8)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.15e-34) or not (x <= 5.7e-8): tmp = (z + y) * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.15e-34) || !(x <= 5.7e-8)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(-1.0 + x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.15e-34) || ~((x <= 5.7e-8))) tmp = (z + y) * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.15e-34], N[Not[LessEqual[x, 5.7e-8]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-34} \lor \neg \left(x \leq 5.7 \cdot 10^{-8}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -1.15000000000000006e-34 or 5.70000000000000009e-8 < x Initial program 97.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.1
Applied rewrites97.1%
if -1.15000000000000006e-34 < x < 5.70000000000000009e-8Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6480.3
Applied rewrites80.3%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.2e+121) (not (<= y 1.15e+44))) (* y x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2e+121) || !(y <= 1.15e+44)) {
tmp = y * x;
} else {
tmp = (-1.0 + x) * z;
}
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 <= (-1.2d+121)) .or. (.not. (y <= 1.15d+44))) then
tmp = y * x
else
tmp = ((-1.0d0) + x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.2e+121) || !(y <= 1.15e+44)) {
tmp = y * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.2e+121) or not (y <= 1.15e+44): tmp = y * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.2e+121) || !(y <= 1.15e+44)) tmp = Float64(y * x); else tmp = Float64(Float64(-1.0 + x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.2e+121) || ~((y <= 1.15e+44))) tmp = y * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.2e+121], N[Not[LessEqual[y, 1.15e+44]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+121} \lor \neg \left(y \leq 1.15 \cdot 10^{+44}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if y < -1.2e121 or 1.15000000000000002e44 < y Initial program 97.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6479.2
Applied rewrites79.2%
Applied rewrites78.3%
Taylor expanded in y around 0
Applied rewrites11.2%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6474.2
Applied rewrites74.2%
if -1.2e121 < y < 1.15000000000000002e44Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6483.9
Applied rewrites83.9%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.15e-34) (fma z x (* y x)) (if (<= x 5.7e-8) (* (+ -1.0 x) z) (* (+ z y) x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-34) {
tmp = fma(z, x, (y * x));
} else if (x <= 5.7e-8) {
tmp = (-1.0 + x) * z;
} else {
tmp = (z + y) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.15e-34) tmp = fma(z, x, Float64(y * x)); elseif (x <= 5.7e-8) tmp = Float64(Float64(-1.0 + x) * z); else tmp = Float64(Float64(z + y) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.15e-34], N[(z * x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5.7e-8], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-34}:\\
\;\;\;\;\mathsf{fma}\left(z, x, y \cdot x\right)\\
\mathbf{elif}\;x \leq 5.7 \cdot 10^{-8}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(z + y\right) \cdot x\\
\end{array}
\end{array}
if x < -1.15000000000000006e-34Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6494.9
Applied rewrites94.9%
Applied rewrites95.0%
if -1.15000000000000006e-34 < x < 5.70000000000000009e-8Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6480.3
Applied rewrites80.3%
if 5.70000000000000009e-8 < x Initial program 95.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.000195))) (* x z) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.000195)) {
tmp = x * z;
} else {
tmp = -z;
}
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 ((x <= (-1.0d0)) .or. (.not. (x <= 0.000195d0))) then
tmp = x * z
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.000195)) {
tmp = x * z;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 0.000195): tmp = x * z else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.000195)) tmp = Float64(x * z); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.000195))) tmp = x * z; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.000195]], $MachinePrecision]], N[(x * z), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.000195\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1 or 1.94999999999999996e-4 < x Initial program 97.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.1
Applied rewrites99.1%
Applied rewrites98.3%
Taylor expanded in y around 0
Applied rewrites45.7%
if -1 < x < 1.94999999999999996e-4Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6475.5
Applied rewrites75.5%
Final simplification61.4%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -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 = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6441.1
Applied rewrites41.1%
herbie shell --seed 2024364
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))