
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * 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 = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))
double code(double x, double y, double z) {
return fabs((((x + 4.0) / y) - ((x / y) * 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 = abs((((x + 4.0d0) / y) - ((x / y) * z)))
end function
public static double code(double x, double y, double z) {
return Math.abs((((x + 4.0) / y) - ((x / y) * z)));
}
def code(x, y, z): return math.fabs((((x + 4.0) / y) - ((x / y) * z)))
function code(x, y, z) return abs(Float64(Float64(Float64(x + 4.0) / y) - Float64(Float64(x / y) * z))) end
function tmp = code(x, y, z) tmp = abs((((x + 4.0) / y) - ((x / y) * z))); end
code[x_, y_, z_] := N[Abs[N[(N[(N[(x + 4.0), $MachinePrecision] / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e+93) (not (<= x 2.6e+67))) (fabs (* (- 1.0 z) (/ x y))) (fabs (/ (fma z x (- -4.0 x)) y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e+93) || !(x <= 2.6e+67)) {
tmp = fabs(((1.0 - z) * (x / y)));
} else {
tmp = fabs((fma(z, x, (-4.0 - x)) / y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e+93) || !(x <= 2.6e+67)) tmp = abs(Float64(Float64(1.0 - z) * Float64(x / y))); else tmp = abs(Float64(fma(z, x, Float64(-4.0 - x)) / y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e+93], N[Not[LessEqual[x, 2.6e+67]], $MachinePrecision]], N[Abs[N[(N[(1.0 - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(z * x + N[(-4.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+93} \lor \neg \left(x \leq 2.6 \cdot 10^{+67}\right):\\
\;\;\;\;\left|\left(1 - z\right) \cdot \frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{y}\right|\\
\end{array}
\end{array}
if x < -3.10000000000000019e93 or 2.6e67 < x Initial program 84.0%
Taylor expanded in x around inf
Applied rewrites99.9%
if -3.10000000000000019e93 < x < 2.6e67Initial program 94.3%
Taylor expanded in x around 0
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y 6e+90) (fabs (/ (fma z x (- -4.0 x)) y)) (fabs (fma (- x) (/ z y) (/ (+ 4.0 x) y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 6e+90) {
tmp = fabs((fma(z, x, (-4.0 - x)) / y));
} else {
tmp = fabs(fma(-x, (z / y), ((4.0 + x) / y)));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 6e+90) tmp = abs(Float64(fma(z, x, Float64(-4.0 - x)) / y)); else tmp = abs(fma(Float64(-x), Float64(z / y), Float64(Float64(4.0 + x) / y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 6e+90], N[Abs[N[(N[(z * x + N[(-4.0 - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[((-x) * N[(z / y), $MachinePrecision] + N[(N[(4.0 + x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{+90}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4 - x\right)}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\mathsf{fma}\left(-x, \frac{z}{y}, \frac{4 + x}{y}\right)\right|\\
\end{array}
\end{array}
if y < 5.99999999999999957e90Initial program 90.0%
Taylor expanded in x around 0
Applied rewrites95.8%
if 5.99999999999999957e90 < y Initial program 94.1%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -10.2) (not (<= x 4.2))) (fabs (* (- 1.0 z) (/ x y))) (fabs (/ (fma z x -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -10.2) || !(x <= 4.2)) {
tmp = fabs(((1.0 - z) * (x / y)));
} else {
tmp = fabs((fma(z, x, -4.0) / y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -10.2) || !(x <= 4.2)) tmp = abs(Float64(Float64(1.0 - z) * Float64(x / y))); else tmp = abs(Float64(fma(z, x, -4.0) / y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -10.2], N[Not[LessEqual[x, 4.2]], $MachinePrecision]], N[Abs[N[(N[(1.0 - z), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(z * x + -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10.2 \lor \neg \left(x \leq 4.2\right):\\
\;\;\;\;\left|\left(1 - z\right) \cdot \frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4\right)}{y}\right|\\
\end{array}
\end{array}
if x < -10.199999999999999 or 4.20000000000000018 < x Initial program 88.3%
Taylor expanded in x around inf
Applied rewrites98.1%
if -10.199999999999999 < x < 4.20000000000000018Initial program 93.3%
Taylor expanded in x around 0
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.5%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -10.2) (not (<= x 4.0))) (fabs (/ (fma z x (- x)) y)) (fabs (/ (fma z x -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -10.2) || !(x <= 4.0)) {
tmp = fabs((fma(z, x, -x) / y));
} else {
tmp = fabs((fma(z, x, -4.0) / y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -10.2) || !(x <= 4.0)) tmp = abs(Float64(fma(z, x, Float64(-x)) / y)); else tmp = abs(Float64(fma(z, x, -4.0) / y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -10.2], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(N[(z * x + (-x)), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(z * x + -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10.2 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -x\right)}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4\right)}{y}\right|\\
\end{array}
\end{array}
if x < -10.199999999999999 or 4 < x Initial program 88.3%
Taylor expanded in x around 0
Applied rewrites89.0%
Taylor expanded in x around inf
Applied rewrites87.2%
if -10.199999999999999 < x < 4Initial program 93.3%
Taylor expanded in x around 0
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.5%
Final simplification93.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.7e+15) (not (<= z 0.16))) (fabs (/ (fma z x -4.0) y)) (fabs (/ (- x -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.7e+15) || !(z <= 0.16)) {
tmp = fabs((fma(z, x, -4.0) / y));
} else {
tmp = fabs(((x - -4.0) / y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -2.7e+15) || !(z <= 0.16)) tmp = abs(Float64(fma(z, x, -4.0) / y)); else tmp = abs(Float64(Float64(x - -4.0) / y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.7e+15], N[Not[LessEqual[z, 0.16]], $MachinePrecision]], N[Abs[N[(N[(z * x + -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x - -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+15} \lor \neg \left(z \leq 0.16\right):\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(z, x, -4\right)}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{x - -4}{y}\right|\\
\end{array}
\end{array}
if z < -2.7e15 or 0.160000000000000003 < z Initial program 86.9%
Taylor expanded in x around 0
Applied rewrites88.7%
Taylor expanded in x around 0
Applied rewrites88.2%
if -2.7e15 < z < 0.160000000000000003Initial program 94.5%
Taylor expanded in z around 0
Applied rewrites97.8%
Final simplification93.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -4e+26) (not (<= z 1.25e+111))) (fabs (* (/ x y) z)) (fabs (/ (- x -4.0) y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e+26) || !(z <= 1.25e+111)) {
tmp = fabs(((x / y) * z));
} else {
tmp = fabs(((x - -4.0) / 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 ((z <= (-4d+26)) .or. (.not. (z <= 1.25d+111))) then
tmp = abs(((x / y) * z))
else
tmp = abs(((x - (-4.0d0)) / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4e+26) || !(z <= 1.25e+111)) {
tmp = Math.abs(((x / y) * z));
} else {
tmp = Math.abs(((x - -4.0) / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e+26) or not (z <= 1.25e+111): tmp = math.fabs(((x / y) * z)) else: tmp = math.fabs(((x - -4.0) / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4e+26) || !(z <= 1.25e+111)) tmp = abs(Float64(Float64(x / y) * z)); else tmp = abs(Float64(Float64(x - -4.0) / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4e+26) || ~((z <= 1.25e+111))) tmp = abs(((x / y) * z)); else tmp = abs(((x - -4.0) / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4e+26], N[Not[LessEqual[z, 1.25e+111]], $MachinePrecision]], N[Abs[N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(x - -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+26} \lor \neg \left(z \leq 1.25 \cdot 10^{+111}\right):\\
\;\;\;\;\left|\frac{x}{y} \cdot z\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{x - -4}{y}\right|\\
\end{array}
\end{array}
if z < -4.00000000000000019e26 or 1.2499999999999999e111 < z Initial program 85.7%
Taylor expanded in x around 0
Applied rewrites86.0%
Taylor expanded in z around inf
Applied rewrites77.7%
Applied rewrites74.2%
if -4.00000000000000019e26 < z < 1.2499999999999999e111Initial program 94.1%
Taylor expanded in z around 0
Applied rewrites95.2%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (<= z -4e+26) (fabs (* (/ x y) z)) (if (<= z 1.25e+111) (fabs (/ (- x -4.0) y)) (fabs (* (/ z y) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4e+26) {
tmp = fabs(((x / y) * z));
} else if (z <= 1.25e+111) {
tmp = fabs(((x - -4.0) / y));
} else {
tmp = fabs(((z / y) * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-4d+26)) then
tmp = abs(((x / y) * z))
else if (z <= 1.25d+111) then
tmp = abs(((x - (-4.0d0)) / y))
else
tmp = abs(((z / y) * x))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4e+26) {
tmp = Math.abs(((x / y) * z));
} else if (z <= 1.25e+111) {
tmp = Math.abs(((x - -4.0) / y));
} else {
tmp = Math.abs(((z / y) * x));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4e+26: tmp = math.fabs(((x / y) * z)) elif z <= 1.25e+111: tmp = math.fabs(((x - -4.0) / y)) else: tmp = math.fabs(((z / y) * x)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4e+26) tmp = abs(Float64(Float64(x / y) * z)); elseif (z <= 1.25e+111) tmp = abs(Float64(Float64(x - -4.0) / y)); else tmp = abs(Float64(Float64(z / y) * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4e+26) tmp = abs(((x / y) * z)); elseif (z <= 1.25e+111) tmp = abs(((x - -4.0) / y)); else tmp = abs(((z / y) * x)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4e+26], N[Abs[N[(N[(x / y), $MachinePrecision] * z), $MachinePrecision]], $MachinePrecision], If[LessEqual[z, 1.25e+111], N[Abs[N[(N[(x - -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(z / y), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+26}:\\
\;\;\;\;\left|\frac{x}{y} \cdot z\right|\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{+111}:\\
\;\;\;\;\left|\frac{x - -4}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{z}{y} \cdot x\right|\\
\end{array}
\end{array}
if z < -4.00000000000000019e26Initial program 93.4%
Taylor expanded in x around 0
Applied rewrites90.0%
Taylor expanded in z around inf
Applied rewrites75.3%
Applied rewrites75.6%
if -4.00000000000000019e26 < z < 1.2499999999999999e111Initial program 94.1%
Taylor expanded in z around 0
Applied rewrites95.2%
if 1.2499999999999999e111 < z Initial program 76.0%
Taylor expanded in x around 0
Applied rewrites80.9%
Taylor expanded in z around inf
Applied rewrites80.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -10.5) (not (<= x 4.0))) (fabs (/ x y)) (fabs (/ 4.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -10.5) || !(x <= 4.0)) {
tmp = fabs((x / y));
} else {
tmp = fabs((4.0 / 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 ((x <= (-10.5d0)) .or. (.not. (x <= 4.0d0))) then
tmp = abs((x / y))
else
tmp = abs((4.0d0 / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -10.5) || !(x <= 4.0)) {
tmp = Math.abs((x / y));
} else {
tmp = Math.abs((4.0 / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -10.5) or not (x <= 4.0): tmp = math.fabs((x / y)) else: tmp = math.fabs((4.0 / y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -10.5) || !(x <= 4.0)) tmp = abs(Float64(x / y)); else tmp = abs(Float64(4.0 / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -10.5) || ~((x <= 4.0))) tmp = abs((x / y)); else tmp = abs((4.0 / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -10.5], N[Not[LessEqual[x, 4.0]], $MachinePrecision]], N[Abs[N[(x / y), $MachinePrecision]], $MachinePrecision], N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10.5 \lor \neg \left(x \leq 4\right):\\
\;\;\;\;\left|\frac{x}{y}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{4}{y}\right|\\
\end{array}
\end{array}
if x < -10.5 or 4 < x Initial program 88.3%
Taylor expanded in z around 0
Applied rewrites62.8%
Taylor expanded in x around inf
Applied rewrites61.0%
if -10.5 < x < 4Initial program 93.3%
Taylor expanded in x around 0
Applied rewrites74.9%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (fabs (/ (- x -4.0) y)))
double code(double x, double y, double z) {
return fabs(((x - -4.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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs(((x - (-4.0d0)) / y))
end function
public static double code(double x, double y, double z) {
return Math.abs(((x - -4.0) / y));
}
def code(x, y, z): return math.fabs(((x - -4.0) / y))
function code(x, y, z) return abs(Float64(Float64(x - -4.0) / y)) end
function tmp = code(x, y, z) tmp = abs(((x - -4.0) / y)); end
code[x_, y_, z_] := N[Abs[N[(N[(x - -4.0), $MachinePrecision] / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{x - -4}{y}\right|
\end{array}
Initial program 90.8%
Taylor expanded in z around 0
Applied rewrites69.0%
(FPCore (x y z) :precision binary64 (fabs (/ 4.0 y)))
double code(double x, double y, double z) {
return fabs((4.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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = abs((4.0d0 / y))
end function
public static double code(double x, double y, double z) {
return Math.abs((4.0 / y));
}
def code(x, y, z): return math.fabs((4.0 / y))
function code(x, y, z) return abs(Float64(4.0 / y)) end
function tmp = code(x, y, z) tmp = abs((4.0 / y)); end
code[x_, y_, z_] := N[Abs[N[(4.0 / y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{4}{y}\right|
\end{array}
Initial program 90.8%
Taylor expanded in x around 0
Applied rewrites39.9%
herbie shell --seed 2025018
(FPCore (x y z)
:name "fabs fraction 1"
:precision binary64
(fabs (- (/ (+ x 4.0) y) (* (/ x y) z))))