
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - 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 = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - 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 = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -7e+22) (fma (/ (- x) z) y y) (if (<= y 410.0) (/ (fma (- z x) y x) z) (- y (* (/ x z) y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+22) {
tmp = fma((-x / z), y, y);
} else if (y <= 410.0) {
tmp = fma((z - x), y, x) / z;
} else {
tmp = y - ((x / z) * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -7e+22) tmp = fma(Float64(Float64(-x) / z), y, y); elseif (y <= 410.0) tmp = Float64(fma(Float64(z - x), y, x) / z); else tmp = Float64(y - Float64(Float64(x / z) * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -7e+22], N[(N[((-x) / z), $MachinePrecision] * y + y), $MachinePrecision], If[LessEqual[y, 410.0], N[(N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision] / z), $MachinePrecision], N[(y - N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+22}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-x}{z}, y, y\right)\\
\mathbf{elif}\;y \leq 410:\\
\;\;\;\;\frac{\mathsf{fma}\left(z - x, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z} \cdot y\\
\end{array}
\end{array}
if y < -7e22Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lift-*.f64N/A
add-to-fraction-revN/A
distribute-neg-fracN/A
+-commutativeN/A
distribute-neg-fracN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-/l*N/A
mult-flipN/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mult-flipN/A
lift-/.f64N/A
lower-fma.f64N/A
Applied rewrites67.1%
if -7e22 < y < 410Initial program 88.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6488.1
Applied rewrites88.1%
if 410 < y Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
add-flipN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lift-/.f64N/A
associate-*l/N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
distribute-neg-fracN/A
distribute-neg-frac2N/A
distribute-frac-negN/A
frac-2negN/A
lower--.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6467.1
Applied rewrites67.1%
(FPCore (x y z) :precision binary64 (if (<= y 4e-269) (fma (/ (- z x) z) y (/ x z)) (fma x (/ (- 1.0 y) z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 4e-269) {
tmp = fma(((z - x) / z), y, (x / z));
} else {
tmp = fma(x, ((1.0 - y) / z), y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 4e-269) tmp = fma(Float64(Float64(z - x) / z), y, Float64(x / z)); else tmp = fma(x, Float64(Float64(1.0 - y) / z), y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 4e-269], N[(N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision] * y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4 \cdot 10^{-269}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{z}, y, \frac{x}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{1 - y}{z}, y\right)\\
\end{array}
\end{array}
if y < 3.9999999999999998e-269Initial program 88.1%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
div-addN/A
common-denominatorN/A
div-addN/A
Applied rewrites93.8%
if 3.9999999999999998e-269 < y Initial program 88.1%
lift-/.f64N/A
mult-flipN/A
associate-*r/N/A
*-rgt-identityN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
associate--l+N/A
add-to-fraction-revN/A
lower-+.f64N/A
sub-divN/A
frac-2neg-revN/A
distribute-lft-neg-outN/A
frac-2neg-revN/A
remove-double-negN/A
sub-divN/A
sub-negate-revN/A
frac-2neg-revN/A
Applied rewrites95.9%
lift-+.f64N/A
lift-/.f64N/A
add-to-fractionN/A
+-commutativeN/A
div-addN/A
lift--.f64N/A
div-subN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
distribute-lft-out--N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6496.1
Applied rewrites96.1%
(FPCore (x y z) :precision binary64 (if (<= y -1e+50) (- y (* (/ x z) y)) (fma x (/ (- 1.0 y) z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e+50) {
tmp = y - ((x / z) * y);
} else {
tmp = fma(x, ((1.0 - y) / z), y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1e+50) tmp = Float64(y - Float64(Float64(x / z) * y)); else tmp = fma(x, Float64(Float64(1.0 - y) / z), y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1e+50], N[(y - N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+50}:\\
\;\;\;\;y - \frac{x}{z} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{1 - y}{z}, y\right)\\
\end{array}
\end{array}
if y < -1.0000000000000001e50Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
add-flipN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lift-/.f64N/A
associate-*l/N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
distribute-neg-fracN/A
distribute-neg-frac2N/A
distribute-frac-negN/A
frac-2negN/A
lower--.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6467.1
Applied rewrites67.1%
if -1.0000000000000001e50 < y Initial program 88.1%
lift-/.f64N/A
mult-flipN/A
associate-*r/N/A
*-rgt-identityN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
associate--l+N/A
add-to-fraction-revN/A
lower-+.f64N/A
sub-divN/A
frac-2neg-revN/A
distribute-lft-neg-outN/A
frac-2neg-revN/A
remove-double-negN/A
sub-divN/A
sub-negate-revN/A
frac-2neg-revN/A
Applied rewrites95.9%
lift-+.f64N/A
lift-/.f64N/A
add-to-fractionN/A
+-commutativeN/A
div-addN/A
lift--.f64N/A
div-subN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
distribute-lft-out--N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6496.1
Applied rewrites96.1%
(FPCore (x y z) :precision binary64 (if (<= y -0.88) (fma (/ (- x) z) y y) (if (<= y 1.0) (/ (fma z y x) z) (- y (* (/ x z) y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.88) {
tmp = fma((-x / z), y, y);
} else if (y <= 1.0) {
tmp = fma(z, y, x) / z;
} else {
tmp = y - ((x / z) * y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -0.88) tmp = fma(Float64(Float64(-x) / z), y, y); elseif (y <= 1.0) tmp = Float64(fma(z, y, x) / z); else tmp = Float64(y - Float64(Float64(x / z) * y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -0.88], N[(N[((-x) / z), $MachinePrecision] * y + y), $MachinePrecision], If[LessEqual[y, 1.0], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], N[(y - N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.88:\\
\;\;\;\;\mathsf{fma}\left(\frac{-x}{z}, y, y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;y - \frac{x}{z} \cdot y\\
\end{array}
\end{array}
if y < -0.880000000000000004Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
*-commutativeN/A
lift-*.f64N/A
add-to-fraction-revN/A
distribute-neg-fracN/A
+-commutativeN/A
distribute-neg-fracN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-/l*N/A
mult-flipN/A
*-commutativeN/A
associate-*r*N/A
distribute-lft-neg-inN/A
mult-flipN/A
lift-/.f64N/A
lower-fma.f64N/A
Applied rewrites67.1%
if -0.880000000000000004 < y < 1Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites69.7%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
*-commutativeN/A
remove-double-negN/A
lower-fma.f6469.7
Applied rewrites69.7%
if 1 < y Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
add-flipN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lift-/.f64N/A
associate-*l/N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
distribute-neg-fracN/A
distribute-neg-frac2N/A
distribute-frac-negN/A
frac-2negN/A
lower--.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6467.1
Applied rewrites67.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- y (* (/ x z) y)))) (if (<= y -0.88) t_0 (if (<= y 1.0) (/ (fma z y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = y - ((x / z) * y);
double tmp;
if (y <= -0.88) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(z, y, x) / z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y - Float64(Float64(x / z) * y)) tmp = 0.0 if (y <= -0.88) tmp = t_0; elseif (y <= 1.0) tmp = Float64(fma(z, y, x) / z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y - N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.88], t$95$0, If[LessEqual[y, 1.0], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y - \frac{x}{z} \cdot y\\
\mathbf{if}\;y \leq -0.88:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.880000000000000004 or 1 < y Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
add-flipN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lift-/.f64N/A
associate-*l/N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
distribute-neg-fracN/A
distribute-neg-frac2N/A
distribute-frac-negN/A
frac-2negN/A
lower--.f64N/A
lift-*.f64N/A
associate-/l*N/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6467.1
Applied rewrites67.1%
if -0.880000000000000004 < y < 1Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites69.7%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
*-commutativeN/A
remove-double-negN/A
lower-fma.f6469.7
Applied rewrites69.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (/ y z) (- z x)))) (if (<= y -1.0) t_0 (if (<= y 1.0) (/ (fma z y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y / z) * (z - x);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(z, y, x) / z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y / z) * Float64(z - x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 1.0) tmp = Float64(fma(z, y, x) / z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y / z), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 1.0], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{z} \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6456.1
Applied rewrites56.1%
if -1 < y < 1Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites69.7%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
*-commutativeN/A
remove-double-negN/A
lower-fma.f6469.7
Applied rewrites69.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (/ (- 1.0 y) z)))) (if (<= x -2.4e+66) t_0 (if (<= x 3e+38) (fma x (/ 1.0 z) y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * ((1.0 - y) / z);
double tmp;
if (x <= -2.4e+66) {
tmp = t_0;
} else if (x <= 3e+38) {
tmp = fma(x, (1.0 / z), y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(Float64(1.0 - y) / z)) tmp = 0.0 if (x <= -2.4e+66) tmp = t_0; elseif (x <= 3e+38) tmp = fma(x, Float64(1.0 / z), y); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(N[(1.0 - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.4e+66], t$95$0, If[LessEqual[x, 3e+38], N[(x * N[(1.0 / z), $MachinePrecision] + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{1 - y}{z}\\
\mathbf{if}\;x \leq -2.4 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{1}{z}, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.4000000000000002e66 or 3.0000000000000001e38 < x Initial program 88.1%
lift-/.f64N/A
mult-flipN/A
associate-*r/N/A
*-rgt-identityN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
associate--l+N/A
add-to-fraction-revN/A
lower-+.f64N/A
sub-divN/A
frac-2neg-revN/A
distribute-lft-neg-outN/A
frac-2neg-revN/A
remove-double-negN/A
sub-divN/A
sub-negate-revN/A
frac-2neg-revN/A
Applied rewrites95.9%
lift-+.f64N/A
lift-/.f64N/A
add-to-fractionN/A
+-commutativeN/A
div-addN/A
lift--.f64N/A
div-subN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
distribute-lft-out--N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6496.1
Applied rewrites96.1%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6487.8
Applied rewrites87.8%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6458.8
Applied rewrites58.8%
if -2.4000000000000002e66 < x < 3.0000000000000001e38Initial program 88.1%
lift-/.f64N/A
mult-flipN/A
associate-*r/N/A
*-rgt-identityN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
associate--l+N/A
add-to-fraction-revN/A
lower-+.f64N/A
sub-divN/A
frac-2neg-revN/A
distribute-lft-neg-outN/A
frac-2neg-revN/A
remove-double-negN/A
sub-divN/A
sub-negate-revN/A
frac-2neg-revN/A
Applied rewrites95.9%
lift-+.f64N/A
lift-/.f64N/A
add-to-fractionN/A
+-commutativeN/A
div-addN/A
lift--.f64N/A
div-subN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
distribute-lft-out--N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6496.1
Applied rewrites96.1%
Taylor expanded in y around 0
Applied rewrites78.8%
(FPCore (x y z) :precision binary64 (if (<= y -7.8e+127) y (if (<= y 1.0) (/ (fma z y x) z) (* (/ y z) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.8e+127) {
tmp = y;
} else if (y <= 1.0) {
tmp = fma(z, y, x) / z;
} else {
tmp = (y / z) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -7.8e+127) tmp = y; elseif (y <= 1.0) tmp = Float64(fma(z, y, x) / z); else tmp = Float64(Float64(y / z) * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -7.8e+127], y, If[LessEqual[y, 1.0], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], N[(N[(y / z), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+127}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z} \cdot z\\
\end{array}
\end{array}
if y < -7.79999999999999962e127Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites41.2%
if -7.79999999999999962e127 < y < 1Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites69.7%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
*-commutativeN/A
remove-double-negN/A
lower-fma.f6469.7
Applied rewrites69.7%
if 1 < y Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6456.1
Applied rewrites56.1%
Taylor expanded in x around 0
Applied rewrites37.4%
(FPCore (x y z) :precision binary64 (fma x (/ 1.0 z) y))
double code(double x, double y, double z) {
return fma(x, (1.0 / z), y);
}
function code(x, y, z) return fma(x, Float64(1.0 / z), y) end
code[x_, y_, z_] := N[(x * N[(1.0 / z), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \frac{1}{z}, y\right)
\end{array}
Initial program 88.1%
lift-/.f64N/A
mult-flipN/A
associate-*r/N/A
*-rgt-identityN/A
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lift-*.f64N/A
lift--.f64N/A
sub-flipN/A
distribute-lft-inN/A
associate--l+N/A
add-to-fraction-revN/A
lower-+.f64N/A
sub-divN/A
frac-2neg-revN/A
distribute-lft-neg-outN/A
frac-2neg-revN/A
remove-double-negN/A
sub-divN/A
sub-negate-revN/A
frac-2neg-revN/A
Applied rewrites95.9%
lift-+.f64N/A
lift-/.f64N/A
add-to-fractionN/A
+-commutativeN/A
div-addN/A
lift--.f64N/A
div-subN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
distribute-lft-out--N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
lower-fma.f64N/A
lift-/.f64N/A
sub-divN/A
lower-/.f64N/A
lower--.f6496.1
Applied rewrites96.1%
Taylor expanded in y around 0
Applied rewrites78.8%
(FPCore (x y z) :precision binary64 (if (<= y -0.000245) y (if (<= y 1.25e-37) (/ x z) (* (/ y z) z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.000245) {
tmp = y;
} else if (y <= 1.25e-37) {
tmp = x / z;
} else {
tmp = (y / z) * 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 <= (-0.000245d0)) then
tmp = y
else if (y <= 1.25d-37) then
tmp = x / z
else
tmp = (y / z) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.000245) {
tmp = y;
} else if (y <= 1.25e-37) {
tmp = x / z;
} else {
tmp = (y / z) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.000245: tmp = y elif y <= 1.25e-37: tmp = x / z else: tmp = (y / z) * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.000245) tmp = y; elseif (y <= 1.25e-37) tmp = Float64(x / z); else tmp = Float64(Float64(y / z) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.000245) tmp = y; elseif (y <= 1.25e-37) tmp = x / z; else tmp = (y / z) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.000245], y, If[LessEqual[y, 1.25e-37], N[(x / z), $MachinePrecision], N[(N[(y / z), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000245:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-37}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z} \cdot z\\
\end{array}
\end{array}
if y < -2.4499999999999999e-4Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites41.2%
if -2.4499999999999999e-4 < y < 1.2499999999999999e-37Initial program 88.1%
Taylor expanded in y around 0
lower-/.f6440.2
Applied rewrites40.2%
if 1.2499999999999999e-37 < y Initial program 88.1%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
lower--.f6453.6
Applied rewrites53.6%
lift-/.f64N/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
lower-*.f6456.1
Applied rewrites56.1%
Taylor expanded in x around 0
Applied rewrites37.4%
(FPCore (x y z) :precision binary64 (if (<= y -0.000245) y (if (<= y 1.25e-37) (/ x z) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.000245) {
tmp = y;
} else if (y <= 1.25e-37) {
tmp = x / z;
} else {
tmp = 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 <= (-0.000245d0)) then
tmp = y
else if (y <= 1.25d-37) then
tmp = x / z
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -0.000245) {
tmp = y;
} else if (y <= 1.25e-37) {
tmp = x / z;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.000245: tmp = y elif y <= 1.25e-37: tmp = x / z else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.000245) tmp = y; elseif (y <= 1.25e-37) tmp = Float64(x / z); else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -0.000245) tmp = y; elseif (y <= 1.25e-37) tmp = x / z; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.000245], y, If[LessEqual[y, 1.25e-37], N[(x / z), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000245:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-37}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.4499999999999999e-4 or 1.2499999999999999e-37 < y Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites41.2%
if -2.4499999999999999e-4 < y < 1.2499999999999999e-37Initial program 88.1%
Taylor expanded in y around 0
lower-/.f6440.2
Applied rewrites40.2%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return 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 = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 88.1%
Taylor expanded in x around 0
Applied rewrites41.2%
herbie shell --seed 2025143
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
(/ (+ x (* y (- z x))) z))