
(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 10 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 (if (or (<= z -8e+103) (not (<= z 1e-92))) (+ (- x (/ y (* z 3.0))) (/ t (* (* y z) 3.0))) (- x (/ (/ (- y (/ t y)) 3.0) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8e+103) || !(z <= 1e-92)) {
tmp = (x - (y / (z * 3.0))) + (t / ((y * z) * 3.0));
} else {
tmp = x - (((y - (t / y)) / 3.0) / 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 ((z <= (-8d+103)) .or. (.not. (z <= 1d-92))) then
tmp = (x - (y / (z * 3.0d0))) + (t / ((y * z) * 3.0d0))
else
tmp = x - (((y - (t / y)) / 3.0d0) / z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -8e+103) || !(z <= 1e-92)) {
tmp = (x - (y / (z * 3.0))) + (t / ((y * z) * 3.0));
} else {
tmp = x - (((y - (t / y)) / 3.0) / z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -8e+103) or not (z <= 1e-92): tmp = (x - (y / (z * 3.0))) + (t / ((y * z) * 3.0)) else: tmp = x - (((y - (t / y)) / 3.0) / z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -8e+103) || !(z <= 1e-92)) tmp = Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(y * z) * 3.0))); else tmp = Float64(x - Float64(Float64(Float64(y - Float64(t / y)) / 3.0) / z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -8e+103) || ~((z <= 1e-92))) tmp = (x - (y / (z * 3.0))) + (t / ((y * z) * 3.0)); else tmp = x - (((y - (t / y)) / 3.0) / z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -8e+103], N[Not[LessEqual[z, 1e-92]], $MachinePrecision]], N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(y * z), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / 3.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+103} \lor \neg \left(z \leq 10^{-92}\right):\\
\;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(y \cdot z\right) \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\frac{y - \frac{t}{y}}{3}}{z}\\
\end{array}
\end{array}
if z < -8e103 or 9.99999999999999988e-93 < z Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
if -8e103 < z < 9.99999999999999988e-93Initial program 91.8%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.2e+23) (not (<= z 3000000000000.0))) (+ (fma -0.3333333333333333 (/ y z) x) (/ t (* (* z 3.0) y))) (- x (/ (- y (/ t y)) (* 3.0 z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.2e+23) || !(z <= 3000000000000.0)) {
tmp = fma(-0.3333333333333333, (y / z), x) + (t / ((z * 3.0) * y));
} else {
tmp = x - ((y - (t / y)) / (3.0 * z));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -5.2e+23) || !(z <= 3000000000000.0)) tmp = Float64(fma(-0.3333333333333333, Float64(y / z), x) + Float64(t / Float64(Float64(z * 3.0) * y))); else tmp = Float64(x - Float64(Float64(y - Float64(t / y)) / Float64(3.0 * z))); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -5.2e+23], N[Not[LessEqual[z, 3000000000000.0]], $MachinePrecision]], N[(N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(3.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+23} \lor \neg \left(z \leq 3000000000000\right):\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y - \frac{t}{y}}{3 \cdot z}\\
\end{array}
\end{array}
if z < -5.19999999999999983e23 or 3e12 < z Initial program 99.8%
Taylor expanded in x around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
if -5.19999999999999983e23 < z < 3e12Initial program 92.0%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Final simplification99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- y (/ t y))))
(if (<= y -2.1e-48)
(- x (/ t_1 (* 3.0 z)))
(if (<= y 6e-100)
(fma (/ (/ t z) y) 0.3333333333333333 x)
(- x (/ (/ t_1 3.0) z))))))
double code(double x, double y, double z, double t) {
double t_1 = y - (t / y);
double tmp;
if (y <= -2.1e-48) {
tmp = x - (t_1 / (3.0 * z));
} else if (y <= 6e-100) {
tmp = fma(((t / z) / y), 0.3333333333333333, x);
} else {
tmp = x - ((t_1 / 3.0) / z);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y - Float64(t / y)) tmp = 0.0 if (y <= -2.1e-48) tmp = Float64(x - Float64(t_1 / Float64(3.0 * z))); elseif (y <= 6e-100) tmp = fma(Float64(Float64(t / z) / y), 0.3333333333333333, x); else tmp = Float64(x - Float64(Float64(t_1 / 3.0) / z)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.1e-48], N[(x - N[(t$95$1 / N[(3.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6e-100], N[(N[(N[(t / z), $MachinePrecision] / y), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision], N[(x - N[(N[(t$95$1 / 3.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y - \frac{t}{y}\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{-48}:\\
\;\;\;\;x - \frac{t\_1}{3 \cdot z}\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-100}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{z}}{y}, 0.3333333333333333, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\frac{t\_1}{3}}{z}\\
\end{array}
\end{array}
if y < -2.09999999999999989e-48Initial program 95.4%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6498.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
if -2.09999999999999989e-48 < y < 6.0000000000000001e-100Initial program 94.1%
Taylor expanded in x around 0
Applied rewrites89.1%
Taylor expanded in y around 0
Applied rewrites94.1%
Applied rewrites98.5%
if 6.0000000000000001e-100 < y Initial program 98.5%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.1e-48) (not (<= y 6e-100))) (- x (/ (- y (/ t y)) (* 3.0 z))) (fma (/ (/ t z) y) 0.3333333333333333 x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.1e-48) || !(y <= 6e-100)) {
tmp = x - ((y - (t / y)) / (3.0 * z));
} else {
tmp = fma(((t / z) / y), 0.3333333333333333, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.1e-48) || !(y <= 6e-100)) tmp = Float64(x - Float64(Float64(y - Float64(t / y)) / Float64(3.0 * z))); else tmp = fma(Float64(Float64(t / z) / y), 0.3333333333333333, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.1e-48], N[Not[LessEqual[y, 6e-100]], $MachinePrecision]], N[(x - N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(3.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t / z), $MachinePrecision] / y), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{-48} \lor \neg \left(y \leq 6 \cdot 10^{-100}\right):\\
\;\;\;\;x - \frac{y - \frac{t}{y}}{3 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{z}}{y}, 0.3333333333333333, x\right)\\
\end{array}
\end{array}
if y < -2.09999999999999989e-48 or 6.0000000000000001e-100 < y Initial program 97.1%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6499.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
if -2.09999999999999989e-48 < y < 6.0000000000000001e-100Initial program 94.1%
Taylor expanded in x around 0
Applied rewrites89.1%
Taylor expanded in y around 0
Applied rewrites94.1%
Applied rewrites98.5%
Final simplification98.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.1e-48) (not (<= y 6e-100))) (fma (/ (- (/ t y) y) z) 0.3333333333333333 x) (fma (/ (/ t z) y) 0.3333333333333333 x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.1e-48) || !(y <= 6e-100)) {
tmp = fma((((t / y) - y) / z), 0.3333333333333333, x);
} else {
tmp = fma(((t / z) / y), 0.3333333333333333, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.1e-48) || !(y <= 6e-100)) tmp = fma(Float64(Float64(Float64(t / y) - y) / z), 0.3333333333333333, x); else tmp = fma(Float64(Float64(t / z) / y), 0.3333333333333333, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.1e-48], N[Not[LessEqual[y, 6e-100]], $MachinePrecision]], N[(N[(N[(N[(t / y), $MachinePrecision] - y), $MachinePrecision] / z), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision], N[(N[(N[(t / z), $MachinePrecision] / y), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{-48} \lor \neg \left(y \leq 6 \cdot 10^{-100}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{y} - y}{z}, 0.3333333333333333, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{z}}{y}, 0.3333333333333333, x\right)\\
\end{array}
\end{array}
if y < -2.09999999999999989e-48 or 6.0000000000000001e-100 < y Initial program 97.1%
Taylor expanded in x around 0
Applied rewrites99.0%
if -2.09999999999999989e-48 < y < 6.0000000000000001e-100Initial program 94.1%
Taylor expanded in x around 0
Applied rewrites89.1%
Taylor expanded in y around 0
Applied rewrites94.1%
Applied rewrites98.5%
Final simplification98.8%
(FPCore (x y z t)
:precision binary64
(if (<= y -2.8e+104)
(fma -0.3333333333333333 (/ y z) x)
(if (<= y 9e+77)
(fma (/ (/ t z) y) 0.3333333333333333 x)
(- x (/ (* 0.3333333333333333 y) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.8e+104) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else if (y <= 9e+77) {
tmp = fma(((t / z) / y), 0.3333333333333333, x);
} else {
tmp = x - ((0.3333333333333333 * y) / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -2.8e+104) tmp = fma(-0.3333333333333333, Float64(y / z), x); elseif (y <= 9e+77) tmp = fma(Float64(Float64(t / z) / y), 0.3333333333333333, x); else tmp = Float64(x - Float64(Float64(0.3333333333333333 * y) / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.8e+104], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 9e+77], N[(N[(N[(t / z), $MachinePrecision] / y), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision], N[(x - N[(N[(0.3333333333333333 * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+77}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{t}{z}}{y}, 0.3333333333333333, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{0.3333333333333333 \cdot y}{z}\\
\end{array}
\end{array}
if y < -2.8e104Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites98.1%
if -2.8e104 < y < 9.00000000000000049e77Initial program 93.8%
Taylor expanded in x around 0
Applied rewrites92.2%
Taylor expanded in y around 0
Applied rewrites89.0%
Applied rewrites90.8%
if 9.00000000000000049e77 < y Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites97.3%
Applied rewrites97.3%
Applied rewrites97.4%
(FPCore (x y z t)
:precision binary64
(if (<= y -2.8e+104)
(fma -0.3333333333333333 (/ y z) x)
(if (<= y 9e+77)
(fma (/ t (* z y)) 0.3333333333333333 x)
(- x (/ (* 0.3333333333333333 y) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.8e+104) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else if (y <= 9e+77) {
tmp = fma((t / (z * y)), 0.3333333333333333, x);
} else {
tmp = x - ((0.3333333333333333 * y) / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -2.8e+104) tmp = fma(-0.3333333333333333, Float64(y / z), x); elseif (y <= 9e+77) tmp = fma(Float64(t / Float64(z * y)), 0.3333333333333333, x); else tmp = Float64(x - Float64(Float64(0.3333333333333333 * y) / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.8e+104], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 9e+77], N[(N[(t / N[(z * y), $MachinePrecision]), $MachinePrecision] * 0.3333333333333333 + x), $MachinePrecision], N[(x - N[(N[(0.3333333333333333 * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+104}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+77}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{z \cdot y}, 0.3333333333333333, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{0.3333333333333333 \cdot y}{z}\\
\end{array}
\end{array}
if y < -2.8e104Initial program 99.9%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites98.1%
if -2.8e104 < y < 9.00000000000000049e77Initial program 93.8%
Taylor expanded in x around 0
Applied rewrites92.2%
Taylor expanded in y around 0
Applied rewrites89.0%
if 9.00000000000000049e77 < y Initial program 99.8%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites97.3%
Applied rewrites97.3%
Applied rewrites97.4%
(FPCore (x y z t)
:precision binary64
(if (<= y -8.8e-86)
(fma -0.3333333333333333 (/ y z) x)
(if (<= y 2.3e-100)
(* (/ t (* z y)) 0.3333333333333333)
(- x (/ (* 0.3333333333333333 y) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -8.8e-86) {
tmp = fma(-0.3333333333333333, (y / z), x);
} else if (y <= 2.3e-100) {
tmp = (t / (z * y)) * 0.3333333333333333;
} else {
tmp = x - ((0.3333333333333333 * y) / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -8.8e-86) tmp = fma(-0.3333333333333333, Float64(y / z), x); elseif (y <= 2.3e-100) tmp = Float64(Float64(t / Float64(z * y)) * 0.3333333333333333); else tmp = Float64(x - Float64(Float64(0.3333333333333333 * y) / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -8.8e-86], N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[y, 2.3e-100], N[(N[(t / N[(z * y), $MachinePrecision]), $MachinePrecision] * 0.3333333333333333), $MachinePrecision], N[(x - N[(N[(0.3333333333333333 * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{-86}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right)\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-100}:\\
\;\;\;\;\frac{t}{z \cdot y} \cdot 0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;x - \frac{0.3333333333333333 \cdot y}{z}\\
\end{array}
\end{array}
if y < -8.8000000000000006e-86Initial program 94.8%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites80.1%
if -8.8000000000000006e-86 < y < 2.29999999999999994e-100Initial program 94.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6467.0
Applied rewrites67.0%
if 2.29999999999999994e-100 < y Initial program 98.5%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites78.5%
Applied rewrites78.5%
Applied rewrites78.6%
(FPCore (x y z t) :precision binary64 (- x (/ (* 0.3333333333333333 y) z)))
double code(double x, double y, double z, double t) {
return x - ((0.3333333333333333 * 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, 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 - ((0.3333333333333333d0 * y) / z)
end function
public static double code(double x, double y, double z, double t) {
return x - ((0.3333333333333333 * y) / z);
}
def code(x, y, z, t): return x - ((0.3333333333333333 * y) / z)
function code(x, y, z, t) return Float64(x - Float64(Float64(0.3333333333333333 * y) / z)) end
function tmp = code(x, y, z, t) tmp = x - ((0.3333333333333333 * y) / z); end
code[x_, y_, z_, t_] := N[(x - N[(N[(0.3333333333333333 * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{0.3333333333333333 \cdot y}{z}
\end{array}
Initial program 95.7%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites59.5%
Applied rewrites59.5%
Applied rewrites59.5%
(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 95.7%
Taylor expanded in y around inf
*-commutativeN/A
fp-cancel-sub-sign-invN/A
remove-double-negN/A
mul-1-negN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
mul-1-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
+-commutativeN/A
distribute-neg-inN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-outN/A
fp-cancel-sub-signN/A
Applied rewrites59.5%
(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 2024364
(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))))