
(FPCore (x y) :precision binary64 (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
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 = ((1.0d0 - x) * (3.0d0 - x)) / (y * 3.0d0)
end function
public static double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
def code(x, y): return ((1.0 - x) * (3.0 - x)) / (y * 3.0)
function code(x, y) return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0)) end
function tmp = code(x, y) tmp = ((1.0 - x) * (3.0 - x)) / (y * 3.0); end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
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 = ((1.0d0 - x) * (3.0d0 - x)) / (y * 3.0d0)
end function
public static double code(double x, double y) {
return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
def code(x, y): return ((1.0 - x) * (3.0 - x)) / (y * 3.0)
function code(x, y) return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0)) end
function tmp = code(x, y) tmp = ((1.0 - x) * (3.0 - x)) / (y * 3.0); end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\end{array}
(FPCore (x y) :precision binary64 (* (/ (/ (- x 3.0) 3.0) y) (- x 1.0)))
double code(double x, double y) {
return (((x - 3.0) / 3.0) / y) * (x - 1.0);
}
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 - 3.0d0) / 3.0d0) / y) * (x - 1.0d0)
end function
public static double code(double x, double y) {
return (((x - 3.0) / 3.0) / y) * (x - 1.0);
}
def code(x, y): return (((x - 3.0) / 3.0) / y) * (x - 1.0)
function code(x, y) return Float64(Float64(Float64(Float64(x - 3.0) / 3.0) / y) * Float64(x - 1.0)) end
function tmp = code(x, y) tmp = (((x - 3.0) / 3.0) / y) * (x - 1.0); end
code[x_, y_] := N[(N[(N[(N[(x - 3.0), $MachinePrecision] / 3.0), $MachinePrecision] / y), $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{x - 3}{3}}{y} \cdot \left(x - 1\right)
\end{array}
Initial program 93.7%
Applied rewrites99.6%
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (* (/ (- (* 0.3333333333333333 x) 1.0) y) (- x 1.0)))
double code(double x, double y) {
return (((0.3333333333333333 * x) - 1.0) / y) * (x - 1.0);
}
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 = (((0.3333333333333333d0 * x) - 1.0d0) / y) * (x - 1.0d0)
end function
public static double code(double x, double y) {
return (((0.3333333333333333 * x) - 1.0) / y) * (x - 1.0);
}
def code(x, y): return (((0.3333333333333333 * x) - 1.0) / y) * (x - 1.0)
function code(x, y) return Float64(Float64(Float64(Float64(0.3333333333333333 * x) - 1.0) / y) * Float64(x - 1.0)) end
function tmp = code(x, y) tmp = (((0.3333333333333333 * x) - 1.0) / y) * (x - 1.0); end
code[x_, y_] := N[(N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 1.0), $MachinePrecision] / y), $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.3333333333333333 \cdot x - 1}{y} \cdot \left(x - 1\right)
\end{array}
Initial program 93.7%
Applied rewrites99.6%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
(FPCore (x y) :precision binary64 (if (<= (* (- 1.0 x) (- 3.0 x)) 1e+242) (/ (fma (- x 4.0) x 3.0) (* y 3.0)) (* (* (/ 0.3333333333333333 y) x) (- x 1.0))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 1e+242) {
tmp = fma((x - 4.0), x, 3.0) / (y * 3.0);
} else {
tmp = ((0.3333333333333333 / y) * x) * (x - 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 1e+242) tmp = Float64(fma(Float64(x - 4.0), x, 3.0) / Float64(y * 3.0)); else tmp = Float64(Float64(Float64(0.3333333333333333 / y) * x) * Float64(x - 1.0)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 1e+242], N[(N[(N[(x - 4.0), $MachinePrecision] * x + 3.0), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.3333333333333333 / y), $MachinePrecision] * x), $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 10^{+242}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x - 4, x, 3\right)}{y \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{0.3333333333333333}{y} \cdot x\right) \cdot \left(x - 1\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 1.00000000000000005e242Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites93.7%
Applied rewrites93.8%
if 1.00000000000000005e242 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 93.7%
Applied rewrites99.6%
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites50.4%
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (* (* (/ (- 3.0 x) y) (- 1.0 x)) 0.3333333333333333))
double code(double x, double y) {
return (((3.0 - x) / y) * (1.0 - x)) * 0.3333333333333333;
}
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 = (((3.0d0 - x) / y) * (1.0d0 - x)) * 0.3333333333333333d0
end function
public static double code(double x, double y) {
return (((3.0 - x) / y) * (1.0 - x)) * 0.3333333333333333;
}
def code(x, y): return (((3.0 - x) / y) * (1.0 - x)) * 0.3333333333333333
function code(x, y) return Float64(Float64(Float64(Float64(3.0 - x) / y) * Float64(1.0 - x)) * 0.3333333333333333) end
function tmp = code(x, y) tmp = (((3.0 - x) / y) * (1.0 - x)) * 0.3333333333333333; end
code[x_, y_] := N[(N[(N[(N[(3.0 - x), $MachinePrecision] / y), $MachinePrecision] * N[(1.0 - x), $MachinePrecision]), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{3 - x}{y} \cdot \left(1 - x\right)\right) \cdot 0.3333333333333333
\end{array}
Initial program 93.7%
Taylor expanded in y around 0
Applied rewrites93.6%
Applied rewrites99.5%
(FPCore (x y) :precision binary64 (if (<= (* (- 1.0 x) (- 3.0 x)) 10.0) (fma -1.3333333333333333 (/ x y) (/ 1.0 y)) (* (/ (* 0.3333333333333333 x) y) (- x 1.0))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 10.0) {
tmp = fma(-1.3333333333333333, (x / y), (1.0 / y));
} else {
tmp = ((0.3333333333333333 * x) / y) * (x - 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 10.0) tmp = fma(-1.3333333333333333, Float64(x / y), Float64(1.0 / y)); else tmp = Float64(Float64(Float64(0.3333333333333333 * x) / y) * Float64(x - 1.0)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 10.0], N[(-1.3333333333333333 * N[(x / y), $MachinePrecision] + N[(1.0 / y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] / y), $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 10:\\
\;\;\;\;\mathsf{fma}\left(-1.3333333333333333, \frac{x}{y}, \frac{1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333 \cdot x}{y} \cdot \left(x - 1\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 10Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites57.6%
if 10 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 93.7%
Applied rewrites99.6%
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (if (<= (* (- 1.0 x) (- 3.0 x)) 10.0) (fma -1.3333333333333333 (/ x y) (/ 1.0 y)) (* (* 0.3333333333333333 (/ x y)) (- x 1.0))))
double code(double x, double y) {
double tmp;
if (((1.0 - x) * (3.0 - x)) <= 10.0) {
tmp = fma(-1.3333333333333333, (x / y), (1.0 / y));
} else {
tmp = (0.3333333333333333 * (x / y)) * (x - 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) * Float64(3.0 - x)) <= 10.0) tmp = fma(-1.3333333333333333, Float64(x / y), Float64(1.0 / y)); else tmp = Float64(Float64(0.3333333333333333 * Float64(x / y)) * Float64(x - 1.0)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision], 10.0], N[(-1.3333333333333333 * N[(x / y), $MachinePrecision] + N[(1.0 / y), $MachinePrecision]), $MachinePrecision], N[(N[(0.3333333333333333 * N[(x / y), $MachinePrecision]), $MachinePrecision] * N[(x - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) \cdot \left(3 - x\right) \leq 10:\\
\;\;\;\;\mathsf{fma}\left(-1.3333333333333333, \frac{x}{y}, \frac{1}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.3333333333333333 \cdot \frac{x}{y}\right) \cdot \left(x - 1\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) < 10Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites57.6%
if 10 < (*.f64 (-.f64 #s(literal 1 binary64) x) (-.f64 #s(literal 3 binary64) x)) Initial program 93.7%
Applied rewrites99.6%
Taylor expanded in x around inf
Applied rewrites50.4%
(FPCore (x y) :precision binary64 (if (<= x -0.75) (* -1.3333333333333333 (/ x y)) (/ 1.0 y)))
double code(double x, double y) {
double tmp;
if (x <= -0.75) {
tmp = -1.3333333333333333 * (x / y);
} else {
tmp = 1.0 / y;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.75d0)) then
tmp = (-1.3333333333333333d0) * (x / y)
else
tmp = 1.0d0 / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.75) {
tmp = -1.3333333333333333 * (x / y);
} else {
tmp = 1.0 / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.75: tmp = -1.3333333333333333 * (x / y) else: tmp = 1.0 / y return tmp
function code(x, y) tmp = 0.0 if (x <= -0.75) tmp = Float64(-1.3333333333333333 * Float64(x / y)); else tmp = Float64(1.0 / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.75) tmp = -1.3333333333333333 * (x / y); else tmp = 1.0 / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.75], N[(-1.3333333333333333 * N[(x / y), $MachinePrecision]), $MachinePrecision], N[(1.0 / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.75:\\
\;\;\;\;-1.3333333333333333 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y}\\
\end{array}
\end{array}
if x < -0.75Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites57.6%
Taylor expanded in x around inf
Applied rewrites9.9%
if -0.75 < x Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites51.9%
(FPCore (x y) :precision binary64 (fma -1.3333333333333333 (/ x y) (/ 1.0 y)))
double code(double x, double y) {
return fma(-1.3333333333333333, (x / y), (1.0 / y));
}
function code(x, y) return fma(-1.3333333333333333, Float64(x / y), Float64(1.0 / y)) end
code[x_, y_] := N[(-1.3333333333333333 * N[(x / y), $MachinePrecision] + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-1.3333333333333333, \frac{x}{y}, \frac{1}{y}\right)
\end{array}
Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites57.6%
(FPCore (x y) :precision binary64 (/ (fma x -1.3333333333333333 1.0) y))
double code(double x, double y) {
return fma(x, -1.3333333333333333, 1.0) / y;
}
function code(x, y) return Float64(fma(x, -1.3333333333333333, 1.0) / y) end
code[x_, y_] := N[(N[(x * -1.3333333333333333 + 1.0), $MachinePrecision] / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, -1.3333333333333333, 1\right)}{y}
\end{array}
Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites57.6%
Applied rewrites57.6%
(FPCore (x y) :precision binary64 (/ 1.0 y))
double code(double x, double y) {
return 1.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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / y
end function
public static double code(double x, double y) {
return 1.0 / y;
}
def code(x, y): return 1.0 / y
function code(x, y) return Float64(1.0 / y) end
function tmp = code(x, y) tmp = 1.0 / y; end
code[x_, y_] := N[(1.0 / y), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{y}
\end{array}
Initial program 93.7%
Taylor expanded in x around 0
Applied rewrites51.9%
herbie shell --seed 2025153
(FPCore (x y)
:name "Diagrams.TwoD.Arc:bezierFromSweepQ1 from diagrams-lib-1.3.0.3"
:precision binary64
(/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))