
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * 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, 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 * 3.0d0))) + (t / ((z * 3.0d0) * y))
end function
public static double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
def code(x, y, z, t): return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y))
function code(x, y, z, t) return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y))) end
function tmp = code(x, y, z, t) tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y)); end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * 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, 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 * 3.0d0))) + (t / ((z * 3.0d0) * y))
end function
public static double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
def code(x, y, z, t): return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y))
function code(x, y, z, t) return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y))) end
function tmp = code(x, y, z, t) tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y)); end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y (* z 3.0)))))
(if (<= (+ t_1 (/ t (* (* z 3.0) y))) 1e+251)
(+ t_1 (/ (/ t (* 3.0 z)) y))
(fma (/ (- (/ t y) y) z) 0.3333333333333333 x))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / (z * 3.0));
double tmp;
if ((t_1 + (t / ((z * 3.0) * y))) <= 1e+251) {
tmp = t_1 + ((t / (3.0 * z)) / y);
} else {
tmp = fma((((t / y) - y) / z), 0.3333333333333333, x);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / Float64(z * 3.0))) tmp = 0.0 if (Float64(t_1 + Float64(t / Float64(Float64(z * 3.0) * y))) <= 1e+251) tmp = Float64(t_1 + Float64(Float64(t / Float64(3.0 * z)) / y)); else tmp = fma(Float64(Float64(Float64(t / y) - y) / z), 0.3333333333333333, x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+251], N[(t$95$1 + N[(N[(t / N[(3.0 * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision] / z), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z \cdot 3}\\
\mathbf{if}\;t\_1 + \frac{t}{\left(z \cdot 3\right) \cdot y} \leq 10^{+251}:\\
\;\;\;\;t\_1 + \frac{\frac{t}{3 \cdot z}}{y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{y} - y}{z}, 0.3333333333333333, x\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 x (/.f64 y (*.f64 z #s(literal 3 binary64)))) (/.f64 t (*.f64 (*.f64 z #s(literal 3 binary64)) y))) < 1e251Initial program 94.3%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f6498.8
Applied rewrites98.8%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/l/N/A
associate-*l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
if 1e251 < (+.f64 (-.f64 x (/.f64 y (*.f64 z #s(literal 3 binary64)))) (/.f64 t (*.f64 (*.f64 z #s(literal 3 binary64)) y))) Initial program 84.5%
Taylor expanded in x around 0
associate--l+N/A
distribute-lft-out--N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-/r*N/A
sub-divN/A
associate-/l*N/A
distribute-lft-out--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
Applied rewrites98.3%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ y (* z 3.0)))))
(if (<= (+ t_1 (/ t (* (* z 3.0) y))) 1e+251)
(+ t_1 (/ (/ t z) (* 3.0 y)))
(fma (/ (- (/ t y) y) z) 0.3333333333333333 x))))
double code(double x, double y, double z, double t) {
double t_1 = x - (y / (z * 3.0));
double tmp;
if ((t_1 + (t / ((z * 3.0) * y))) <= 1e+251) {
tmp = t_1 + ((t / z) / (3.0 * y));
} else {
tmp = fma((((t / y) - y) / z), 0.3333333333333333, x);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / Float64(z * 3.0))) tmp = 0.0 if (Float64(t_1 + Float64(t / Float64(Float64(z * 3.0) * y))) <= 1e+251) tmp = Float64(t_1 + Float64(Float64(t / z) / Float64(3.0 * y))); else tmp = fma(Float64(Float64(Float64(t / y) - y) / z), 0.3333333333333333, x); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e+251], N[(t$95$1 + N[(N[(t / z), $MachinePrecision] / N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision] / z), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{y}{z \cdot 3}\\
\mathbf{if}\;t\_1 + \frac{t}{\left(z \cdot 3\right) \cdot y} \leq 10^{+251}:\\
\;\;\;\;t\_1 + \frac{\frac{t}{z}}{3 \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{y} - y}{z}, 0.3333333333333333, x\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 x (/.f64 y (*.f64 z #s(literal 3 binary64)))) (/.f64 t (*.f64 (*.f64 z #s(literal 3 binary64)) y))) < 1e251Initial program 94.3%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f6498.8
Applied rewrites98.8%
if 1e251 < (+.f64 (-.f64 x (/.f64 y (*.f64 z #s(literal 3 binary64)))) (/.f64 t (*.f64 (*.f64 z #s(literal 3 binary64)) y))) Initial program 84.5%
Taylor expanded in x around 0
associate--l+N/A
distribute-lft-out--N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-/r*N/A
sub-divN/A
associate-/l*N/A
distribute-lft-out--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
Applied rewrites98.3%
(FPCore (x y z t) :precision binary64 (if (<= z 3e+39) (fma (/ (- (/ t y) y) z) 0.3333333333333333 x) (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3e+39) {
tmp = fma((((t / y) - y) / z), 0.3333333333333333, x);
} else {
tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 3e+39) tmp = fma(Float64(Float64(Float64(t / y) - y) / z), 0.3333333333333333, x); else tmp = Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 3e+39], N[(N[(N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision] / z), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision], N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3 \cdot 10^{+39}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{y} - y}{z}, 0.3333333333333333, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\
\end{array}
\end{array}
if z < 3e39Initial program 89.8%
Taylor expanded in x around 0
associate--l+N/A
distribute-lft-out--N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-/r*N/A
sub-divN/A
associate-/l*N/A
distribute-lft-out--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
Applied rewrites97.3%
if 3e39 < z Initial program 99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e+67) (not (<= y 29000.0))) (fma -0.3333333333333333 (/ y z) x) (+ x (/ (/ t (* 3.0 z)) y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e+67) || !(y <= 29000.0)) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else {
tmp = x + ((t / (3.0 * z)) / y);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e+67) || !(y <= 29000.0)) tmp = fma(-0.3333333333333333, Float64(y / z), x); else tmp = Float64(x + Float64(Float64(t / Float64(3.0 * z)) / y)); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e+67], N[Not[LessEqual[y, 29000.0]], $MachinePrecision]], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[(t / N[(3.0 * z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+67} \lor \neg \left(y \leq 29000\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{\frac{t}{3 \cdot z}}{y}\\
\end{array}
\end{array}
if y < -3.0000000000000001e67 or 29000 < y Initial program 97.7%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
if -3.0000000000000001e67 < y < 29000Initial program 88.7%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f6497.9
Applied rewrites97.9%
Taylor expanded in x around inf
Applied rewrites91.2%
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
associate-*r*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6491.3
Applied rewrites91.3%
Final simplification93.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e+67) (not (<= y 29000.0))) (fma -0.3333333333333333 (/ y z) x) (+ x (/ (/ t z) (* 3.0 y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e+67) || !(y <= 29000.0)) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else {
tmp = x + ((t / z) / (3.0 * y));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e+67) || !(y <= 29000.0)) tmp = fma(-0.3333333333333333, Float64(y / z), x); else tmp = Float64(x + Float64(Float64(t / z) / Float64(3.0 * y))); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e+67], N[Not[LessEqual[y, 29000.0]], $MachinePrecision]], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[(t / z), $MachinePrecision] / N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+67} \lor \neg \left(y \leq 29000\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{\frac{t}{z}}{3 \cdot y}\\
\end{array}
\end{array}
if y < -3.0000000000000001e67 or 29000 < y Initial program 97.7%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
if -3.0000000000000001e67 < y < 29000Initial program 88.7%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f6497.9
Applied rewrites97.9%
Taylor expanded in x around inf
Applied rewrites91.2%
Final simplification93.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e+67) (not (<= y 29000.0))) (fma -0.3333333333333333 (/ y z) x) (fma (/ (/ t y) z) 0.3333333333333333 x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e+67) || !(y <= 29000.0)) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else {
tmp = fma(((t / y) / z), 0.3333333333333333, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e+67) || !(y <= 29000.0)) tmp = fma(-0.3333333333333333, Float64(y / z), x); else tmp = fma(Float64(Float64(t / y) / z), 0.3333333333333333, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e+67], N[Not[LessEqual[y, 29000.0]], $MachinePrecision]], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(t / y), $MachinePrecision] / z), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+67} \lor \neg \left(y \leq 29000\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{y}}{z}, 0.3333333333333333, x\right)\\
\end{array}
\end{array}
if y < -3.0000000000000001e67 or 29000 < y Initial program 97.7%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
if -3.0000000000000001e67 < y < 29000Initial program 88.7%
Taylor expanded in x around 0
associate--l+N/A
distribute-lft-out--N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-/r*N/A
sub-divN/A
associate-/l*N/A
distribute-lft-out--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
Applied rewrites93.7%
Taylor expanded in y around 0
associate-/r*N/A
lower-/.f64N/A
lift-/.f6485.8
Applied rewrites85.8%
Final simplification89.8%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e+67) (not (<= y 29000.0))) (fma -0.3333333333333333 (/ y z) x) (+ x (/ t (* (* z 3.0) y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e+67) || !(y <= 29000.0)) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else {
tmp = x + (t / ((z * 3.0) * y));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e+67) || !(y <= 29000.0)) tmp = fma(-0.3333333333333333, Float64(y / z), x); else tmp = Float64(x + Float64(t / Float64(Float64(z * 3.0) * y))); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e+67], N[Not[LessEqual[y, 29000.0]], $MachinePrecision]], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+67} \lor \neg \left(y \leq 29000\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{t}{\left(z \cdot 3\right) \cdot y}\\
\end{array}
\end{array}
if y < -3.0000000000000001e67 or 29000 < y Initial program 97.7%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
if -3.0000000000000001e67 < y < 29000Initial program 88.7%
Taylor expanded in x around inf
Applied rewrites84.0%
Final simplification88.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e+67) (not (<= y 29000.0))) (fma -0.3333333333333333 (/ y z) x) (+ x (/ t (* z (* 3.0 y))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e+67) || !(y <= 29000.0)) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else {
tmp = x + (t / (z * (3.0 * y)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e+67) || !(y <= 29000.0)) tmp = fma(-0.3333333333333333, Float64(y / z), x); else tmp = Float64(x + Float64(t / Float64(z * Float64(3.0 * y)))); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e+67], N[Not[LessEqual[y, 29000.0]], $MachinePrecision]], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(t / N[(z * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+67} \lor \neg \left(y \leq 29000\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{t}{z \cdot \left(3 \cdot y\right)}\\
\end{array}
\end{array}
if y < -3.0000000000000001e67 or 29000 < y Initial program 97.7%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.4
Applied rewrites96.4%
if -3.0000000000000001e67 < y < 29000Initial program 88.7%
Taylor expanded in x around inf
Applied rewrites84.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6484.0
Applied rewrites84.0%
Final simplification88.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.6e-68) (not (<= y 300.0))) (fma -0.3333333333333333 (/ y z) x) (* (/ t (* z y)) 0.3333333333333333)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.6e-68) || !(y <= 300.0)) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else {
tmp = (t / (z * y)) * 0.3333333333333333;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.6e-68) || !(y <= 300.0)) tmp = fma(-0.3333333333333333, Float64(y / z), x); else tmp = Float64(Float64(t / Float64(z * y)) * 0.3333333333333333); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.6e-68], N[Not[LessEqual[y, 300.0]], $MachinePrecision]], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], N[(N[(t / N[(z * y), $MachinePrecision]), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{-68} \lor \neg \left(y \leq 300\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t}{z \cdot y} \cdot 0.3333333333333333\\
\end{array}
\end{array}
if y < -4.59999999999999994e-68 or 300 < y Initial program 96.0%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.5
Applied rewrites90.5%
if -4.59999999999999994e-68 < y < 300Initial program 88.2%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6463.1
Applied rewrites63.1%
Final simplification76.8%
(FPCore (x y z t) :precision binary64 (fma (/ (- (/ t y) y) z) 0.3333333333333333 x))
double code(double x, double y, double z, double t) {
return fma((((t / y) - y) / z), 0.3333333333333333, x);
}
function code(x, y, z, t) return fma(Float64(Float64(Float64(t / y) - y) / z), 0.3333333333333333, x) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision] / z), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\frac{t}{y} - y}{z}, 0.3333333333333333, x\right)
\end{array}
Initial program 92.1%
Taylor expanded in x around 0
associate--l+N/A
distribute-lft-out--N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
associate-/r*N/A
sub-divN/A
associate-/l*N/A
distribute-lft-out--N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
Applied rewrites96.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.8e-75) (not (<= x 1.4e+60))) x (/ (* -0.3333333333333333 y) z)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.8e-75) || !(x <= 1.4e+60)) {
tmp = x;
} else {
tmp = (-0.3333333333333333 * y) / 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.8d-75)) .or. (.not. (x <= 1.4d+60))) then
tmp = x
else
tmp = ((-0.3333333333333333d0) * y) / z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.8e-75) || !(x <= 1.4e+60)) {
tmp = x;
} else {
tmp = (-0.3333333333333333 * y) / z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.8e-75) or not (x <= 1.4e+60): tmp = x else: tmp = (-0.3333333333333333 * y) / z return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.8e-75) || !(x <= 1.4e+60)) tmp = x; else tmp = Float64(Float64(-0.3333333333333333 * y) / z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.8e-75) || ~((x <= 1.4e+60))) tmp = x; else tmp = (-0.3333333333333333 * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.8e-75], N[Not[LessEqual[x, 1.4e+60]], $MachinePrecision]], x, N[(N[(-0.3333333333333333 * y), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-75} \lor \neg \left(x \leq 1.4 \cdot 10^{+60}\right):\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.3333333333333333 \cdot y}{z}\\
\end{array}
\end{array}
if x < -1.8e-75 or 1.4e60 < x Initial program 91.1%
Taylor expanded in x around inf
Applied rewrites52.0%
if -1.8e-75 < x < 1.4e60Initial program 93.2%
Taylor expanded in x around 0
associate-/r*N/A
associate-*r/N/A
associate-*r/N/A
div-subN/A
lower-/.f64N/A
distribute-lft-out--N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-/.f6492.0
Applied rewrites92.0%
Taylor expanded in y around inf
lower-*.f6445.9
Applied rewrites45.9%
Final simplification49.2%
(FPCore (x y z t) :precision binary64 (if (<= x -1.8e-75) x (if (<= x 1.4e+60) (* -0.3333333333333333 (/ y z)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.8e-75) {
tmp = x;
} else if (x <= 1.4e+60) {
tmp = -0.3333333333333333 * (y / z);
} 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 (x <= (-1.8d-75)) then
tmp = x
else if (x <= 1.4d+60) then
tmp = (-0.3333333333333333d0) * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.8e-75) {
tmp = x;
} else if (x <= 1.4e+60) {
tmp = -0.3333333333333333 * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.8e-75: tmp = x elif x <= 1.4e+60: tmp = -0.3333333333333333 * (y / z) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.8e-75) tmp = x; elseif (x <= 1.4e+60) tmp = Float64(-0.3333333333333333 * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.8e-75) tmp = x; elseif (x <= 1.4e+60) tmp = -0.3333333333333333 * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.8e-75], x, If[LessEqual[x, 1.4e+60], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{-75}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+60}:\\
\;\;\;\;-0.3333333333333333 \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.8e-75 or 1.4e60 < x Initial program 91.1%
Taylor expanded in x around inf
Applied rewrites52.0%
if -1.8e-75 < x < 1.4e60Initial program 93.2%
Taylor expanded in y around inf
lower-*.f64N/A
lower-/.f6445.9
Applied rewrites45.9%
(FPCore (x y z t) :precision binary64 (fma -0.3333333333333333 (/ y z) x))
double code(double x, double y, double z, double t) {
return fma(-0.3333333333333333, (y / z), x);
}
function code(x, y, z, t) return fma(-0.3333333333333333, Float64(y / z), x) end
code[x_, y_, z_, t_] := N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)
\end{array}
Initial program 92.1%
Taylor expanded in t around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6460.8
Applied rewrites60.8%
(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.1%
Taylor expanded in x around inf
Applied rewrites30.7%
(FPCore (x y z t) :precision binary64 (+ (- x (/ y (* z 3.0))) (/ (/ t (* z 3.0)) y)))
double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + ((t / (z * 3.0)) / 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, 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 * 3.0d0))) + ((t / (z * 3.0d0)) / y)
end function
public static double code(double x, double y, double z, double t) {
return (x - (y / (z * 3.0))) + ((t / (z * 3.0)) / y);
}
def code(x, y, z, t): return (x - (y / (z * 3.0))) + ((t / (z * 3.0)) / y)
function code(x, y, z, t) return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(Float64(t / Float64(z * 3.0)) / y)) end
function tmp = code(x, y, z, t) tmp = (x - (y / (z * 3.0))) + ((t / (z * 3.0)) / y); end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(t / N[(z * 3.0), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y}
\end{array}
herbie shell --seed 2025057
(FPCore (x y z t)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, H"
:precision binary64
:alt
(! :herbie-platform default (+ (- x (/ y (* z 3))) (/ (/ t (* z 3)) y)))
(+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))