
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
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, a)
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), intent (in) :: a
code = x + ((y * (z - t)) / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / a)
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / a)) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / a); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
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, a)
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), intent (in) :: a
code = x + ((y * (z - t)) / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / a);
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / a)
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / a)) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / a); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a}
\end{array}
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (* y (- z t)))) (if (<= t_1 -5e+28) (fma (/ y a) (- z t) x) (+ x (/ t_1 a)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = y * (z - t);
double tmp;
if (t_1 <= -5e+28) {
tmp = fma((y / a), (z - t), x);
} else {
tmp = x + (t_1 / a);
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(y * Float64(z - t)) tmp = 0.0 if (t_1 <= -5e+28) tmp = fma(Float64(y / a), Float64(z - t), x); else tmp = Float64(x + Float64(t_1 / a)); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+28], N[(N[(y / a), $MachinePrecision] * N[(z - t), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(t$95$1 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z - t\right)\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+28}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{t\_1}{a}\\
\end{array}
\end{array}
if (*.f64 y (-.f64 z t)) < -4.99999999999999957e28Initial program 92.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
if -4.99999999999999957e28 < (*.f64 y (-.f64 z t)) Initial program 98.7%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) a)) (t_2 (/ (* (- z t) y) a)))
(if (<= t_1 -4e+86)
t_2
(if (<= t_1 5e-195)
(- x (* (/ t a) y))
(if (<= t_1 4e+165)
(+ x (/ (* z y) a))
(if (<= t_1 1e+305) t_2 (* (/ (- z t) a) y)))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double t_2 = ((z - t) * y) / a;
double tmp;
if (t_1 <= -4e+86) {
tmp = t_2;
} else if (t_1 <= 5e-195) {
tmp = x - ((t / a) * y);
} else if (t_1 <= 4e+165) {
tmp = x + ((z * y) / a);
} else if (t_1 <= 1e+305) {
tmp = t_2;
} else {
tmp = ((z - t) / a) * 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, t, a)
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), intent (in) :: a
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (y * (z - t)) / a
t_2 = ((z - t) * y) / a
if (t_1 <= (-4d+86)) then
tmp = t_2
else if (t_1 <= 5d-195) then
tmp = x - ((t / a) * y)
else if (t_1 <= 4d+165) then
tmp = x + ((z * y) / a)
else if (t_1 <= 1d+305) then
tmp = t_2
else
tmp = ((z - t) / a) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double t_2 = ((z - t) * y) / a;
double tmp;
if (t_1 <= -4e+86) {
tmp = t_2;
} else if (t_1 <= 5e-195) {
tmp = x - ((t / a) * y);
} else if (t_1 <= 4e+165) {
tmp = x + ((z * y) / a);
} else if (t_1 <= 1e+305) {
tmp = t_2;
} else {
tmp = ((z - t) / a) * y;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = (y * (z - t)) / a t_2 = ((z - t) * y) / a tmp = 0 if t_1 <= -4e+86: tmp = t_2 elif t_1 <= 5e-195: tmp = x - ((t / a) * y) elif t_1 <= 4e+165: tmp = x + ((z * y) / a) elif t_1 <= 1e+305: tmp = t_2 else: tmp = ((z - t) / a) * y return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(y * Float64(z - t)) / a) t_2 = Float64(Float64(Float64(z - t) * y) / a) tmp = 0.0 if (t_1 <= -4e+86) tmp = t_2; elseif (t_1 <= 5e-195) tmp = Float64(x - Float64(Float64(t / a) * y)); elseif (t_1 <= 4e+165) tmp = Float64(x + Float64(Float64(z * y) / a)); elseif (t_1 <= 1e+305) tmp = t_2; else tmp = Float64(Float64(Float64(z - t) / a) * y); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = (y * (z - t)) / a; t_2 = ((z - t) * y) / a; tmp = 0.0; if (t_1 <= -4e+86) tmp = t_2; elseif (t_1 <= 5e-195) tmp = x - ((t / a) * y); elseif (t_1 <= 4e+165) tmp = x + ((z * y) / a); elseif (t_1 <= 1e+305) tmp = t_2; else tmp = ((z - t) / a) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+86], t$95$2, If[LessEqual[t$95$1, 5e-195], N[(x - N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+165], N[(x + N[(N[(z * y), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+305], t$95$2, N[(N[(N[(z - t), $MachinePrecision] / a), $MachinePrecision] * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a}\\
t_2 := \frac{\left(z - t\right) \cdot y}{a}\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+86}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-195}:\\
\;\;\;\;x - \frac{t}{a} \cdot y\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+165}:\\
\;\;\;\;x + \frac{z \cdot y}{a}\\
\mathbf{elif}\;t\_1 \leq 10^{+305}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{z - t}{a} \cdot y\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) a) < -4.0000000000000001e86 or 3.9999999999999996e165 < (/.f64 (*.f64 y (-.f64 z t)) a) < 9.9999999999999994e304Initial program 96.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.6
Applied rewrites91.6%
if -4.0000000000000001e86 < (/.f64 (*.f64 y (-.f64 z t)) a) < 5.00000000000000009e-195Initial program 99.8%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
if 5.00000000000000009e-195 < (/.f64 (*.f64 y (-.f64 z t)) a) < 3.9999999999999996e165Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
if 9.9999999999999994e304 < (/.f64 (*.f64 y (-.f64 z t)) a) Initial program 83.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.5
Applied rewrites83.5%
Applied rewrites99.9%
Final simplification90.1%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (* y (- z t)) a)) (t_2 (/ (* (- z t) y) a)))
(if (<= t_1 -4e+86)
t_2
(if (<= t_1 5e-195)
(- x (* (/ t a) y))
(if (<= t_1 4e+165)
(fma (/ y a) z x)
(if (<= t_1 1e+305) t_2 (* (/ (- z t) a) y)))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y * (z - t)) / a;
double t_2 = ((z - t) * y) / a;
double tmp;
if (t_1 <= -4e+86) {
tmp = t_2;
} else if (t_1 <= 5e-195) {
tmp = x - ((t / a) * y);
} else if (t_1 <= 4e+165) {
tmp = fma((y / a), z, x);
} else if (t_1 <= 1e+305) {
tmp = t_2;
} else {
tmp = ((z - t) / a) * y;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y * Float64(z - t)) / a) t_2 = Float64(Float64(Float64(z - t) * y) / a) tmp = 0.0 if (t_1 <= -4e+86) tmp = t_2; elseif (t_1 <= 5e-195) tmp = Float64(x - Float64(Float64(t / a) * y)); elseif (t_1 <= 4e+165) tmp = fma(Float64(y / a), z, x); elseif (t_1 <= 1e+305) tmp = t_2; else tmp = Float64(Float64(Float64(z - t) / a) * y); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+86], t$95$2, If[LessEqual[t$95$1, 5e-195], N[(x - N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+165], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[t$95$1, 1e+305], t$95$2, N[(N[(N[(z - t), $MachinePrecision] / a), $MachinePrecision] * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a}\\
t_2 := \frac{\left(z - t\right) \cdot y}{a}\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+86}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-195}:\\
\;\;\;\;x - \frac{t}{a} \cdot y\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+165}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\mathbf{elif}\;t\_1 \leq 10^{+305}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{z - t}{a} \cdot y\\
\end{array}
\end{array}
if (/.f64 (*.f64 y (-.f64 z t)) a) < -4.0000000000000001e86 or 3.9999999999999996e165 < (/.f64 (*.f64 y (-.f64 z t)) a) < 9.9999999999999994e304Initial program 96.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.6
Applied rewrites91.6%
if -4.0000000000000001e86 < (/.f64 (*.f64 y (-.f64 z t)) a) < 5.00000000000000009e-195Initial program 99.8%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
if 5.00000000000000009e-195 < (/.f64 (*.f64 y (-.f64 z t)) a) < 3.9999999999999996e165Initial program 99.9%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6479.4
Applied rewrites79.4%
if 9.9999999999999994e304 < (/.f64 (*.f64 y (-.f64 z t)) a) Initial program 83.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6483.5
Applied rewrites83.5%
Applied rewrites99.9%
Final simplification89.5%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (fma (/ y a) z x)))
(if (<= z -4.5e-72)
t_1
(if (<= z 3.15e-77)
(- x (* (/ t a) y))
(if (<= z 5.1e-23) (/ (* (- z t) y) a) t_1)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma((y / a), z, x);
double tmp;
if (z <= -4.5e-72) {
tmp = t_1;
} else if (z <= 3.15e-77) {
tmp = x - ((t / a) * y);
} else if (z <= 5.1e-23) {
tmp = ((z - t) * y) / a;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(Float64(y / a), z, x) tmp = 0.0 if (z <= -4.5e-72) tmp = t_1; elseif (z <= 3.15e-77) tmp = Float64(x - Float64(Float64(t / a) * y)); elseif (z <= 5.1e-23) tmp = Float64(Float64(Float64(z - t) * y) / a); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -4.5e-72], t$95$1, If[LessEqual[z, 3.15e-77], N[(x - N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5.1e-23], N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / a), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\mathbf{if}\;z \leq -4.5 \cdot 10^{-72}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.15 \cdot 10^{-77}:\\
\;\;\;\;x - \frac{t}{a} \cdot y\\
\mathbf{elif}\;z \leq 5.1 \cdot 10^{-23}:\\
\;\;\;\;\frac{\left(z - t\right) \cdot y}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -4.5e-72 or 5.10000000000000011e-23 < z Initial program 96.5%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
if -4.5e-72 < z < 3.15e-77Initial program 96.0%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6488.6
Applied rewrites88.6%
if 3.15e-77 < z < 5.10000000000000011e-23Initial program 100.0%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.2
Applied rewrites86.2%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -1e-70) (not (<= z 3.9e-22))) (fma (/ y a) z x) (fma (/ y a) (- t) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -1e-70) || !(z <= 3.9e-22)) {
tmp = fma((y / a), z, x);
} else {
tmp = fma((y / a), -t, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -1e-70) || !(z <= 3.9e-22)) tmp = fma(Float64(y / a), z, x); else tmp = fma(Float64(y / a), Float64(-t), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -1e-70], N[Not[LessEqual[z, 3.9e-22]], $MachinePrecision]], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * (-t) + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-70} \lor \neg \left(z \leq 3.9 \cdot 10^{-22}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, -t, x\right)\\
\end{array}
\end{array}
if z < -9.99999999999999996e-71 or 3.89999999999999998e-22 < z Initial program 96.5%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
if -9.99999999999999996e-71 < z < 3.89999999999999998e-22Initial program 96.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.7
Applied rewrites95.7%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6487.5
Applied rewrites87.5%
Final simplification87.5%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -4.5e-72) (not (<= z 2.6e-22))) (fma (/ y a) z x) (- x (* (/ t a) y))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -4.5e-72) || !(z <= 2.6e-22)) {
tmp = fma((y / a), z, x);
} else {
tmp = x - ((t / a) * y);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -4.5e-72) || !(z <= 2.6e-22)) tmp = fma(Float64(y / a), z, x); else tmp = Float64(x - Float64(Float64(t / a) * y)); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -4.5e-72], N[Not[LessEqual[z, 2.6e-22]], $MachinePrecision]], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision], N[(x - N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-72} \lor \neg \left(z \leq 2.6 \cdot 10^{-22}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{t}{a} \cdot y\\
\end{array}
\end{array}
if z < -4.5e-72 or 2.6e-22 < z Initial program 96.5%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
if -4.5e-72 < z < 2.6e-22Initial program 96.5%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6484.3
Applied rewrites84.3%
Final simplification86.0%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -2.35e+222) (not (<= t 2.9e+190))) (* (- y) (/ t a)) (fma (/ y a) z x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -2.35e+222) || !(t <= 2.9e+190)) {
tmp = -y * (t / a);
} else {
tmp = fma((y / a), z, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -2.35e+222) || !(t <= 2.9e+190)) tmp = Float64(Float64(-y) * Float64(t / a)); else tmp = fma(Float64(y / a), z, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -2.35e+222], N[Not[LessEqual[t, 2.9e+190]], $MachinePrecision]], N[((-y) * N[(t / a), $MachinePrecision]), $MachinePrecision], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.35 \cdot 10^{+222} \lor \neg \left(t \leq 2.9 \cdot 10^{+190}\right):\\
\;\;\;\;\left(-y\right) \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\end{array}
\end{array}
if t < -2.3499999999999999e222 or 2.89999999999999989e190 < t Initial program 90.7%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
Taylor expanded in x around 0
Applied rewrites70.2%
if -2.3499999999999999e222 < t < 2.89999999999999989e190Initial program 97.7%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
Final simplification78.8%
(FPCore (x y z t a) :precision binary64 (if (<= t -2.35e+222) (* (- y) (/ t a)) (if (<= t 4.5e+188) (fma (/ y a) z x) (* (/ (- y) a) t))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -2.35e+222) {
tmp = -y * (t / a);
} else if (t <= 4.5e+188) {
tmp = fma((y / a), z, x);
} else {
tmp = (-y / a) * t;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -2.35e+222) tmp = Float64(Float64(-y) * Float64(t / a)); elseif (t <= 4.5e+188) tmp = fma(Float64(y / a), z, x); else tmp = Float64(Float64(Float64(-y) / a) * t); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -2.35e+222], N[((-y) * N[(t / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 4.5e+188], N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision], N[(N[((-y) / a), $MachinePrecision] * t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.35 \cdot 10^{+222}:\\
\;\;\;\;\left(-y\right) \cdot \frac{t}{a}\\
\mathbf{elif}\;t \leq 4.5 \cdot 10^{+188}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-y}{a} \cdot t\\
\end{array}
\end{array}
if t < -2.3499999999999999e222Initial program 90.5%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6495.7
Applied rewrites95.7%
Taylor expanded in x around 0
Applied rewrites77.5%
if -2.3499999999999999e222 < t < 4.5000000000000001e188Initial program 97.7%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
if 4.5000000000000001e188 < t Initial program 90.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.4
Applied rewrites95.4%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.9
Applied rewrites76.9%
Taylor expanded in z around 0
Applied rewrites63.0%
Taylor expanded in y around 0
Applied rewrites72.0%
Final simplification79.6%
(FPCore (x y z t a) :precision binary64 (fma (/ y a) (- z t) x))
double code(double x, double y, double z, double t, double a) {
return fma((y / a), (z - t), x);
}
function code(x, y, z, t, a) return fma(Float64(y / a), Float64(z - t), x) end
code[x_, y_, z_, t_, a_] := N[(N[(y / a), $MachinePrecision] * N[(z - t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{a}, z - t, x\right)
\end{array}
Initial program 96.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.2
Applied rewrites96.2%
(FPCore (x y z t a) :precision binary64 (fma (/ y a) z x))
double code(double x, double y, double z, double t, double a) {
return fma((y / a), z, x);
}
function code(x, y, z, t, a) return fma(Float64(y / a), z, x) end
code[x_, y_, z_, t_, a_] := N[(N[(y / a), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{a}, z, x\right)
\end{array}
Initial program 96.5%
Taylor expanded in t around 0
+-commutativeN/A
associate-*l/N/A
lower-fma.f64N/A
lower-/.f6472.2
Applied rewrites72.2%
(FPCore (x y z t a) :precision binary64 (* (/ y a) z))
double code(double x, double y, double z, double t, double a) {
return (y / a) * 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, a)
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), intent (in) :: a
code = (y / a) * z
end function
public static double code(double x, double y, double z, double t, double a) {
return (y / a) * z;
}
def code(x, y, z, t, a): return (y / a) * z
function code(x, y, z, t, a) return Float64(Float64(y / a) * z) end
function tmp = code(x, y, z, t, a) tmp = (y / a) * z; end
code[x_, y_, z_, t_, a_] := N[(N[(y / a), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{a} \cdot z
\end{array}
Initial program 96.5%
Taylor expanded in z around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6437.1
Applied rewrites37.1%
(FPCore (x y z t a) :precision binary64 (* y (/ z a)))
double code(double x, double y, double z, double t, double a) {
return y * (z / a);
}
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, a)
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), intent (in) :: a
code = y * (z / a)
end function
public static double code(double x, double y, double z, double t, double a) {
return y * (z / a);
}
def code(x, y, z, t, a): return y * (z / a)
function code(x, y, z, t, a) return Float64(y * Float64(z / a)) end
function tmp = code(x, y, z, t, a) tmp = y * (z / a); end
code[x_, y_, z_, t_, a_] := N[(y * N[(z / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{z}{a}
\end{array}
Initial program 96.5%
Taylor expanded in z around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6437.1
Applied rewrites37.1%
Applied rewrites33.3%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ a (- z t))))
(if (< y -1.0761266216389975e-10)
(+ x (/ 1.0 (/ t_1 y)))
(if (< y 2.894426862792089e-49)
(+ x (/ (* y (- z t)) a))
(+ x (/ y t_1))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = a / (z - t);
double tmp;
if (y < -1.0761266216389975e-10) {
tmp = x + (1.0 / (t_1 / y));
} else if (y < 2.894426862792089e-49) {
tmp = x + ((y * (z - t)) / a);
} else {
tmp = x + (y / t_1);
}
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, a)
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), intent (in) :: a
real(8) :: t_1
real(8) :: tmp
t_1 = a / (z - t)
if (y < (-1.0761266216389975d-10)) then
tmp = x + (1.0d0 / (t_1 / y))
else if (y < 2.894426862792089d-49) then
tmp = x + ((y * (z - t)) / a)
else
tmp = x + (y / t_1)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = a / (z - t);
double tmp;
if (y < -1.0761266216389975e-10) {
tmp = x + (1.0 / (t_1 / y));
} else if (y < 2.894426862792089e-49) {
tmp = x + ((y * (z - t)) / a);
} else {
tmp = x + (y / t_1);
}
return tmp;
}
def code(x, y, z, t, a): t_1 = a / (z - t) tmp = 0 if y < -1.0761266216389975e-10: tmp = x + (1.0 / (t_1 / y)) elif y < 2.894426862792089e-49: tmp = x + ((y * (z - t)) / a) else: tmp = x + (y / t_1) return tmp
function code(x, y, z, t, a) t_1 = Float64(a / Float64(z - t)) tmp = 0.0 if (y < -1.0761266216389975e-10) tmp = Float64(x + Float64(1.0 / Float64(t_1 / y))); elseif (y < 2.894426862792089e-49) tmp = Float64(x + Float64(Float64(y * Float64(z - t)) / a)); else tmp = Float64(x + Float64(y / t_1)); end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = a / (z - t); tmp = 0.0; if (y < -1.0761266216389975e-10) tmp = x + (1.0 / (t_1 / y)); elseif (y < 2.894426862792089e-49) tmp = x + ((y * (z - t)) / a); else tmp = x + (y / t_1); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(a / N[(z - t), $MachinePrecision]), $MachinePrecision]}, If[Less[y, -1.0761266216389975e-10], N[(x + N[(1.0 / N[(t$95$1 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Less[y, 2.894426862792089e-49], N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{a}{z - t}\\
\mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\
\;\;\;\;x + \frac{1}{\frac{t\_1}{y}}\\
\mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\
\;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t\_1}\\
\end{array}
\end{array}
herbie shell --seed 2024364
(FPCore (x y z t a)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
:precision binary64
:alt
(! :herbie-platform default (if (< y -430450648655599/4000000000000000000000000) (+ x (/ 1 (/ (/ a (- z t)) y))) (if (< y 2894426862792089/10000000000000000000000000000000000000000000000000000000000000000) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t)))))))
(+ x (/ (* y (- z t)) a)))