
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * (z - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (fma (- z x) (/ y t) x))
double code(double x, double y, double z, double t) {
return fma((z - x), (y / t), x);
}
function code(x, y, z, t) return fma(Float64(z - x), Float64(y / t), x) end
code[x_, y_, z_, t_] := N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, \frac{y}{t}, x\right)
\end{array}
Initial program 92.0%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lift--.f64N/A
lower-/.f6498.0
Applied rewrites98.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.6e+19) (not (<= x 3.7e+106))) (* (- 1.0 (/ y t)) x) (+ x (* (/ y t) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.6e+19) || !(x <= 3.7e+106)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = x + ((y / t) * 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x <= (-1.6d+19)) .or. (.not. (x <= 3.7d+106))) then
tmp = (1.0d0 - (y / t)) * x
else
tmp = x + ((y / t) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.6e+19) || !(x <= 3.7e+106)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.6e+19) or not (x <= 3.7e+106): tmp = (1.0 - (y / t)) * x else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.6e+19) || !(x <= 3.7e+106)) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = Float64(x + Float64(Float64(y / t) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.6e+19) || ~((x <= 3.7e+106))) tmp = (1.0 - (y / t)) * x; else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.6e+19], N[Not[LessEqual[x, 3.7e+106]], $MachinePrecision]], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+19} \lor \neg \left(x \leq 3.7 \cdot 10^{+106}\right):\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if x < -1.6e19 or 3.69999999999999995e106 < x Initial program 92.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
cancel-sign-subN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6494.4
Applied rewrites94.4%
if -1.6e19 < x < 3.69999999999999995e106Initial program 91.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
associate-*r/N/A
associate-*r*N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
Taylor expanded in x around 0
lift-/.f6486.8
Applied rewrites86.8%
Final simplification89.9%
(FPCore (x y z t) :precision binary64 (if (or (<= t -1.18e-33) (not (<= t 11500.0))) (fma y (/ z t) x) (/ (* (- z x) y) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -1.18e-33) || !(t <= 11500.0)) {
tmp = fma(y, (z / t), x);
} else {
tmp = ((z - x) * y) / t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -1.18e-33) || !(t <= 11500.0)) tmp = fma(y, Float64(z / t), x); else tmp = Float64(Float64(Float64(z - x) * y) / t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -1.18e-33], N[Not[LessEqual[t, 11500.0]], $MachinePrecision]], N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.18 \cdot 10^{-33} \lor \neg \left(t \leq 11500\right):\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\
\end{array}
\end{array}
if t < -1.18e-33 or 11500 < t Initial program 86.5%
Taylor expanded in x around 0
Applied rewrites82.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
if -1.18e-33 < t < 11500Initial program 99.8%
Taylor expanded in y around inf
sub-divN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f6489.0
Applied rewrites89.0%
Final simplification88.1%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.7e-35) (not (<= z 2.8e-114))) (fma y (/ z t) x) (* (- 1.0 (/ y t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.7e-35) || !(z <= 2.8e-114)) {
tmp = fma(y, (z / t), x);
} else {
tmp = (1.0 - (y / t)) * x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.7e-35) || !(z <= 2.8e-114)) tmp = fma(y, Float64(z / t), x); else tmp = Float64(Float64(1.0 - Float64(y / t)) * x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -1.7e-35], N[Not[LessEqual[z, 2.8e-114]], $MachinePrecision]], N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-35} \lor \neg \left(z \leq 2.8 \cdot 10^{-114}\right):\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\end{array}
\end{array}
if z < -1.7000000000000001e-35 or 2.8000000000000001e-114 < z Initial program 89.6%
Taylor expanded in x around 0
Applied rewrites81.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6483.0
Applied rewrites83.0%
if -1.7000000000000001e-35 < z < 2.8000000000000001e-114Initial program 95.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
cancel-sign-subN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6491.8
Applied rewrites91.8%
Final simplification86.7%
(FPCore (x y z t) :precision binary64 (if (<= x -1.6e+19) (fma (- x) (/ y t) x) (if (<= x 3.7e+106) (+ x (* (/ y t) z)) (* (- 1.0 (/ y t)) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.6e+19) {
tmp = fma(-x, (y / t), x);
} else if (x <= 3.7e+106) {
tmp = x + ((y / t) * z);
} else {
tmp = (1.0 - (y / t)) * x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -1.6e+19) tmp = fma(Float64(-x), Float64(y / t), x); elseif (x <= 3.7e+106) tmp = Float64(x + Float64(Float64(y / t) * z)); else tmp = Float64(Float64(1.0 - Float64(y / t)) * x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.6e+19], N[((-x) * N[(y / t), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 3.7e+106], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(-x, \frac{y}{t}, x\right)\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{+106}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\end{array}
\end{array}
if x < -1.6e19Initial program 91.3%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lift--.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6491.2
Applied rewrites91.2%
if -1.6e19 < x < 3.69999999999999995e106Initial program 91.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
associate-*r/N/A
associate-*r*N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-/.f6482.4
Applied rewrites82.4%
Taylor expanded in x around 0
lift-/.f6486.8
Applied rewrites86.8%
if 3.69999999999999995e106 < x Initial program 94.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
cancel-sign-subN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Final simplification89.9%
(FPCore (x y z t) :precision binary64 (if (<= z -9.5e-88) (/ (* z y) t) (if (<= z 2.65e-110) x (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.5e-88) {
tmp = (z * y) / t;
} else if (z <= 2.65e-110) {
tmp = x;
} else {
tmp = y * (z / t);
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-9.5d-88)) then
tmp = (z * y) / t
else if (z <= 2.65d-110) then
tmp = x
else
tmp = y * (z / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.5e-88) {
tmp = (z * y) / t;
} else if (z <= 2.65e-110) {
tmp = x;
} else {
tmp = y * (z / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -9.5e-88: tmp = (z * y) / t elif z <= 2.65e-110: tmp = x else: tmp = y * (z / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -9.5e-88) tmp = Float64(Float64(z * y) / t); elseif (z <= 2.65e-110) tmp = x; else tmp = Float64(y * Float64(z / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -9.5e-88) tmp = (z * y) / t; elseif (z <= 2.65e-110) tmp = x; else tmp = y * (z / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -9.5e-88], N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision], If[LessEqual[z, 2.65e-110], x, N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-88}:\\
\;\;\;\;\frac{z \cdot y}{t}\\
\mathbf{elif}\;z \leq 2.65 \cdot 10^{-110}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if z < -9.5e-88Initial program 92.9%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6456.6
Applied rewrites56.6%
if -9.5e-88 < z < 2.65e-110Initial program 94.7%
Taylor expanded in y around 0
Applied rewrites59.1%
if 2.65e-110 < z Initial program 87.8%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lift--.f64N/A
lower-/.f6496.3
Applied rewrites96.3%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f6448.3
Applied rewrites48.3%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6456.8
Applied rewrites56.8%
Final simplification57.6%
(FPCore (x y z t) :precision binary64 (if (<= t -2.5e-51) x (if (<= t 26.0) (/ (* z y) t) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.5e-51) {
tmp = x;
} else if (t <= 26.0) {
tmp = (z * y) / t;
} else {
tmp = x;
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-2.5d-51)) then
tmp = x
else if (t <= 26.0d0) then
tmp = (z * y) / t
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.5e-51) {
tmp = x;
} else if (t <= 26.0) {
tmp = (z * y) / t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.5e-51: tmp = x elif t <= 26.0: tmp = (z * y) / t else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.5e-51) tmp = x; elseif (t <= 26.0) tmp = Float64(Float64(z * y) / t); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.5e-51) tmp = x; elseif (t <= 26.0) tmp = (z * y) / t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.5e-51], x, If[LessEqual[t, 26.0], N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.5 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 26:\\
\;\;\;\;\frac{z \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -2.50000000000000002e-51 or 26 < t Initial program 86.9%
Taylor expanded in y around 0
Applied rewrites58.2%
if -2.50000000000000002e-51 < t < 26Initial program 99.8%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6453.1
Applied rewrites53.1%
Final simplification56.2%
(FPCore (x y z t) :precision binary64 (if (<= y -5.2e+232) (* (/ (- y) t) x) (fma y (/ z t) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5.2e+232) {
tmp = (-y / t) * x;
} else {
tmp = fma(y, (z / t), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -5.2e+232) tmp = Float64(Float64(Float64(-y) / t) * x); else tmp = fma(y, Float64(z / t), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -5.2e+232], N[(N[((-y) / t), $MachinePrecision] * x), $MachinePrecision], N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+232}:\\
\;\;\;\;\frac{-y}{t} \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t}, x\right)\\
\end{array}
\end{array}
if y < -5.19999999999999947e232Initial program 76.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
cancel-sign-subN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6483.5
Applied rewrites83.5%
Taylor expanded in y around inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.5
Applied rewrites83.5%
if -5.19999999999999947e232 < y Initial program 92.8%
Taylor expanded in x around 0
Applied rewrites75.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6474.7
Applied rewrites74.7%
Final simplification75.1%
(FPCore (x y z t) :precision binary64 (fma y (/ z t) x))
double code(double x, double y, double z, double t) {
return fma(y, (z / t), x);
}
function code(x, y, z, t) return fma(y, Float64(z / t), x) end
code[x_, y_, z_, t_] := N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \frac{z}{t}, x\right)
\end{array}
Initial program 92.0%
Taylor expanded in x around 0
Applied rewrites73.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 92.0%
Taylor expanded in y around 0
Applied rewrites39.9%
Final simplification39.9%
(FPCore (x y z t) :precision binary64 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t): return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t)))) end
function tmp = code(x, y, z, t) tmp = x - ((x * (y / t)) + (-z * (y / t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}
herbie shell --seed 2025051
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:alt
(! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
(+ x (/ (* y (- z x)) t)))