
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
double code(double x, double y) {
return ((x * 2.0) * y) / (x - 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) * y) / (x - y)
end function
public static double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
def code(x, y): return ((x * 2.0) * y) / (x - y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) end
function tmp = code(x, y) tmp = ((x * 2.0) * y) / (x - y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
double code(double x, double y) {
return ((x * 2.0) * y) / (x - 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) * y) / (x - y)
end function
public static double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
def code(x, y): return ((x * 2.0) * y) / (x - y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) end
function tmp = code(x, y) tmp = ((x * 2.0) * y) / (x - y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (+ x x) y) (- x y)))
(t_1 (/ (* (* x 2.0) y) (- x y)))
(t_2 (* (+ x x) (/ y (- x y)))))
(if (<= t_1 -1e+108)
t_2
(if (<= t_1 -2e-306)
t_0
(if (<= t_1 0.0) t_2 (if (<= t_1 4e+15) t_0 t_2))))))
double code(double x, double y) {
double t_0 = ((x + x) * y) / (x - y);
double t_1 = ((x * 2.0) * y) / (x - y);
double t_2 = (x + x) * (y / (x - y));
double tmp;
if (t_1 <= -1e+108) {
tmp = t_2;
} else if (t_1 <= -2e-306) {
tmp = t_0;
} else if (t_1 <= 0.0) {
tmp = t_2;
} else if (t_1 <= 4e+15) {
tmp = t_0;
} else {
tmp = t_2;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = ((x + x) * y) / (x - y)
t_1 = ((x * 2.0d0) * y) / (x - y)
t_2 = (x + x) * (y / (x - y))
if (t_1 <= (-1d+108)) then
tmp = t_2
else if (t_1 <= (-2d-306)) then
tmp = t_0
else if (t_1 <= 0.0d0) then
tmp = t_2
else if (t_1 <= 4d+15) then
tmp = t_0
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((x + x) * y) / (x - y);
double t_1 = ((x * 2.0) * y) / (x - y);
double t_2 = (x + x) * (y / (x - y));
double tmp;
if (t_1 <= -1e+108) {
tmp = t_2;
} else if (t_1 <= -2e-306) {
tmp = t_0;
} else if (t_1 <= 0.0) {
tmp = t_2;
} else if (t_1 <= 4e+15) {
tmp = t_0;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y): t_0 = ((x + x) * y) / (x - y) t_1 = ((x * 2.0) * y) / (x - y) t_2 = (x + x) * (y / (x - y)) tmp = 0 if t_1 <= -1e+108: tmp = t_2 elif t_1 <= -2e-306: tmp = t_0 elif t_1 <= 0.0: tmp = t_2 elif t_1 <= 4e+15: tmp = t_0 else: tmp = t_2 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(x + x) * y) / Float64(x - y)) t_1 = Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) t_2 = Float64(Float64(x + x) * Float64(y / Float64(x - y))) tmp = 0.0 if (t_1 <= -1e+108) tmp = t_2; elseif (t_1 <= -2e-306) tmp = t_0; elseif (t_1 <= 0.0) tmp = t_2; elseif (t_1 <= 4e+15) tmp = t_0; else tmp = t_2; end return tmp end
function tmp_2 = code(x, y) t_0 = ((x + x) * y) / (x - y); t_1 = ((x * 2.0) * y) / (x - y); t_2 = (x + x) * (y / (x - y)); tmp = 0.0; if (t_1 <= -1e+108) tmp = t_2; elseif (t_1 <= -2e-306) tmp = t_0; elseif (t_1 <= 0.0) tmp = t_2; elseif (t_1 <= 4e+15) tmp = t_0; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x + x), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + x), $MachinePrecision] * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+108], t$95$2, If[LessEqual[t$95$1, -2e-306], t$95$0, If[LessEqual[t$95$1, 0.0], t$95$2, If[LessEqual[t$95$1, 4e+15], t$95$0, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(x + x\right) \cdot y}{x - y}\\
t_1 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
t_2 := \left(x + x\right) \cdot \frac{y}{x - y}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+108}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq -2 \cdot 10^{-306}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -1e108 or -2.00000000000000006e-306 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -0.0 or 4e15 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) Initial program 24.8%
lift--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift--.f6499.5
Applied rewrites99.5%
lift-*.f64N/A
count-2-revN/A
lift-+.f6499.5
Applied rewrites99.5%
if -1e108 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -2.00000000000000006e-306 or -0.0 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < 4e15Initial program 99.1%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6499.1
Applied rewrites99.1%
(FPCore (x y) :precision binary64 (if (<= x -4.5e+176) (+ y y) (if (<= x 1.9e+151) (* (+ x x) (/ y (- x y))) (+ y y))))
double code(double x, double y) {
double tmp;
if (x <= -4.5e+176) {
tmp = y + y;
} else if (x <= 1.9e+151) {
tmp = (x + x) * (y / (x - y));
} else {
tmp = y + 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.5d+176)) then
tmp = y + y
else if (x <= 1.9d+151) then
tmp = (x + x) * (y / (x - y))
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.5e+176) {
tmp = y + y;
} else if (x <= 1.9e+151) {
tmp = (x + x) * (y / (x - y));
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.5e+176: tmp = y + y elif x <= 1.9e+151: tmp = (x + x) * (y / (x - y)) else: tmp = y + y return tmp
function code(x, y) tmp = 0.0 if (x <= -4.5e+176) tmp = Float64(y + y); elseif (x <= 1.9e+151) tmp = Float64(Float64(x + x) * Float64(y / Float64(x - y))); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.5e+176) tmp = y + y; elseif (x <= 1.9e+151) tmp = (x + x) * (y / (x - y)); else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.5e+176], N[(y + y), $MachinePrecision], If[LessEqual[x, 1.9e+151], N[(N[(x + x), $MachinePrecision] * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+176}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+151}:\\
\;\;\;\;\left(x + x\right) \cdot \frac{y}{x - y}\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -4.50000000000000003e176 or 1.9e151 < x Initial program 63.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6488.3
Applied rewrites88.3%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6488.3
Applied rewrites88.3%
if -4.50000000000000003e176 < x < 1.9e151Initial program 81.0%
lift--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift--.f6496.2
Applied rewrites96.2%
lift-*.f64N/A
count-2-revN/A
lift-+.f6496.2
Applied rewrites96.2%
(FPCore (x y) :precision binary64 (if (<= x -3.6e+35) (+ y y) (if (<= x 1.76e+18) (* (fma (/ x y) -2.0 -2.0) x) (+ y y))))
double code(double x, double y) {
double tmp;
if (x <= -3.6e+35) {
tmp = y + y;
} else if (x <= 1.76e+18) {
tmp = fma((x / y), -2.0, -2.0) * x;
} else {
tmp = y + y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -3.6e+35) tmp = Float64(y + y); elseif (x <= 1.76e+18) tmp = Float64(fma(Float64(x / y), -2.0, -2.0) * x); else tmp = Float64(y + y); end return tmp end
code[x_, y_] := If[LessEqual[x, -3.6e+35], N[(y + y), $MachinePrecision], If[LessEqual[x, 1.76e+18], N[(N[(N[(x / y), $MachinePrecision] * -2.0 + -2.0), $MachinePrecision] * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+35}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;x \leq 1.76 \cdot 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, -2, -2\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -3.6e35 or 1.76e18 < x Initial program 73.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6476.9
Applied rewrites76.9%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6476.9
Applied rewrites76.9%
if -3.6e35 < x < 1.76e18Initial program 79.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f6472.5
Applied rewrites72.5%
(FPCore (x y) :precision binary64 (if (<= x -4.5e+35) (+ y y) (if (<= x 1e+20) (* -2.0 x) (+ y y))))
double code(double x, double y) {
double tmp;
if (x <= -4.5e+35) {
tmp = y + y;
} else if (x <= 1e+20) {
tmp = -2.0 * x;
} else {
tmp = y + 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.5d+35)) then
tmp = y + y
else if (x <= 1d+20) then
tmp = (-2.0d0) * x
else
tmp = y + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.5e+35) {
tmp = y + y;
} else if (x <= 1e+20) {
tmp = -2.0 * x;
} else {
tmp = y + y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.5e+35: tmp = y + y elif x <= 1e+20: tmp = -2.0 * x else: tmp = y + y return tmp
function code(x, y) tmp = 0.0 if (x <= -4.5e+35) tmp = Float64(y + y); elseif (x <= 1e+20) tmp = Float64(-2.0 * x); else tmp = Float64(y + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.5e+35) tmp = y + y; elseif (x <= 1e+20) tmp = -2.0 * x; else tmp = y + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.5e+35], N[(y + y), $MachinePrecision], If[LessEqual[x, 1e+20], N[(-2.0 * x), $MachinePrecision], N[(y + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+35}:\\
\;\;\;\;y + y\\
\mathbf{elif}\;x \leq 10^{+20}:\\
\;\;\;\;-2 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + y\\
\end{array}
\end{array}
if x < -4.4999999999999997e35 or 1e20 < x Initial program 73.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6477.0
Applied rewrites77.0%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6477.0
Applied rewrites77.0%
if -4.4999999999999997e35 < x < 1e20Initial program 79.7%
Taylor expanded in x around 0
lower-*.f6472.4
Applied rewrites72.4%
(FPCore (x y) :precision binary64 (+ y y))
double code(double x, double y) {
return y + 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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + y
end function
public static double code(double x, double y) {
return y + y;
}
def code(x, y): return y + y
function code(x, y) return Float64(y + y) end
function tmp = code(x, y) tmp = y + y; end
code[x_, y_] := N[(y + y), $MachinePrecision]
\begin{array}{l}
\\
y + y
\end{array}
Initial program 76.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6450.9
Applied rewrites50.9%
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
lower-+.f6450.9
Applied rewrites50.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (/ (* 2.0 x) (- x y)) y)))
(if (< x -1.7210442634149447e+81)
t_0
(if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) t_0))))
double code(double x, double y) {
double t_0 = ((2.0 * x) / (x - y)) * y;
double tmp;
if (x < -1.7210442634149447e+81) {
tmp = t_0;
} else if (x < 83645045635564430.0) {
tmp = (x * 2.0) / ((x - y) / y);
} else {
tmp = t_0;
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = ((2.0d0 * x) / (x - y)) * y
if (x < (-1.7210442634149447d+81)) then
tmp = t_0
else if (x < 83645045635564430.0d0) then
tmp = (x * 2.0d0) / ((x - y) / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((2.0 * x) / (x - y)) * y;
double tmp;
if (x < -1.7210442634149447e+81) {
tmp = t_0;
} else if (x < 83645045635564430.0) {
tmp = (x * 2.0) / ((x - y) / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = ((2.0 * x) / (x - y)) * y tmp = 0 if x < -1.7210442634149447e+81: tmp = t_0 elif x < 83645045635564430.0: tmp = (x * 2.0) / ((x - y) / y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(2.0 * x) / Float64(x - y)) * y) tmp = 0.0 if (x < -1.7210442634149447e+81) tmp = t_0; elseif (x < 83645045635564430.0) tmp = Float64(Float64(x * 2.0) / Float64(Float64(x - y) / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = ((2.0 * x) / (x - y)) * y; tmp = 0.0; if (x < -1.7210442634149447e+81) tmp = t_0; elseif (x < 83645045635564430.0) tmp = (x * 2.0) / ((x - y) / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(2.0 * x), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[Less[x, -1.7210442634149447e+81], t$95$0, If[Less[x, 83645045635564430.0], N[(N[(x * 2.0), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot x}{x - y} \cdot y\\
\mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x < 83645045635564430:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
herbie shell --seed 2025089
(FPCore (x y)
:name "Linear.Projection:perspective from linear-1.19.1.3, B"
:precision binary64
:alt
(! :herbie-platform default (if (< x -1721044263414944700000000000000000000000000000000000000000000000000000000000000000) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564430) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y))))
(/ (* (* x 2.0) y) (- x y)))