
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((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 = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((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 = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((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 = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= (exp (* y y)) 2.0) x (* x (* y y))))
double code(double x, double y) {
double tmp;
if (exp((y * y)) <= 2.0) {
tmp = x;
} else {
tmp = x * (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 (exp((y * y)) <= 2.0d0) then
tmp = x
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (Math.exp((y * y)) <= 2.0) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if math.exp((y * y)) <= 2.0: tmp = x else: tmp = x * (y * y) return tmp
function code(x, y) tmp = 0.0 if (exp(Float64(y * y)) <= 2.0) tmp = x; else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (exp((y * y)) <= 2.0) tmp = x; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision], 2.0], x, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{y \cdot y} \leq 2:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (exp.f64 (*.f64 y y)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.6%
if 2 < (exp.f64 (*.f64 y y)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
lower-fma.f6468.2
Applied rewrites68.2%
Taylor expanded in y around inf
pow2N/A
lift-*.f6468.2
Applied rewrites68.2%
(FPCore (x y) :precision binary64 (* x (fma (fma (* (fma (* 0.16666666666666666 y) y 0.5) y) y 1.0) (* y y) 1.0)))
double code(double x, double y) {
return x * fma(fma((fma((0.16666666666666666 * y), y, 0.5) * y), y, 1.0), (y * y), 1.0);
}
function code(x, y) return Float64(x * fma(fma(Float64(fma(Float64(0.16666666666666666 * y), y, 0.5) * y), y, 1.0), Float64(y * y), 1.0)) end
code[x_, y_] := N[(x * N[(N[(N[(N[(N[(0.16666666666666666 * y), $MachinePrecision] * y + 0.5), $MachinePrecision] * y), $MachinePrecision] * y + 1.0), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666 \cdot y, y, 0.5\right) \cdot y, y, 1\right), y \cdot y, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
lower-fma.f6482.5
Applied rewrites82.5%
Taylor expanded in y around inf
pow2N/A
lift-*.f6439.7
Applied rewrites39.7%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
*-commutativeN/A
pow2N/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
pow2N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites95.6%
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6495.6
Applied rewrites95.6%
(FPCore (x y) :precision binary64 (* x (fma (fma (* 0.16666666666666666 (* y y)) (* y y) 1.0) (* y y) 1.0)))
double code(double x, double y) {
return x * fma(fma((0.16666666666666666 * (y * y)), (y * y), 1.0), (y * y), 1.0);
}
function code(x, y) return Float64(x * fma(fma(Float64(0.16666666666666666 * Float64(y * y)), Float64(y * y), 1.0), Float64(y * y), 1.0)) end
code[x_, y_] := N[(x * N[(N[(N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666 \cdot \left(y \cdot y\right), y \cdot y, 1\right), y \cdot y, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
lower-fma.f6482.5
Applied rewrites82.5%
Taylor expanded in y around inf
pow2N/A
lift-*.f6439.7
Applied rewrites39.7%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
*-commutativeN/A
pow2N/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
pow2N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites95.6%
Taylor expanded in y around inf
pow2N/A
lower-*.f64N/A
lift-*.f6495.6
Applied rewrites95.6%
Final simplification95.6%
(FPCore (x y) :precision binary64 (fma (* (* (fma (* 0.16666666666666666 (* y y)) (* y y) 1.0) x) y) y x))
double code(double x, double y) {
return fma(((fma((0.16666666666666666 * (y * y)), (y * y), 1.0) * x) * y), y, x);
}
function code(x, y) return fma(Float64(Float64(fma(Float64(0.16666666666666666 * Float64(y * y)), Float64(y * y), 1.0) * x) * y), y, x) end
code[x_, y_] := N[(N[(N[(N[(N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(0.16666666666666666 \cdot \left(y \cdot y\right), y \cdot y, 1\right) \cdot x\right) \cdot y, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6493.8
Applied rewrites93.8%
Applied rewrites94.1%
Taylor expanded in y around inf
pow2N/A
lower-*.f64N/A
lift-*.f6494.1
Applied rewrites94.1%
(FPCore (x y) :precision binary64 (* x (fma (fma 0.5 (* y y) 1.0) (* y y) 1.0)))
double code(double x, double y) {
return x * fma(fma(0.5, (y * y), 1.0), (y * y), 1.0);
}
function code(x, y) return Float64(x * fma(fma(0.5, Float64(y * y), 1.0), Float64(y * y), 1.0)) end
code[x_, y_] := N[(x * N[(N[(0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.5, y \cdot y, 1\right), y \cdot y, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
lower-fma.f6482.5
Applied rewrites82.5%
Taylor expanded in y around inf
pow2N/A
lift-*.f6439.7
Applied rewrites39.7%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f6490.5
Applied rewrites90.5%
(FPCore (x y) :precision binary64 (fma (* (* (fma (* y y) 0.5 1.0) x) y) y x))
double code(double x, double y) {
return fma(((fma((y * y), 0.5, 1.0) * x) * y), y, x);
}
function code(x, y) return fma(Float64(Float64(fma(Float64(y * y), 0.5, 1.0) * x) * y), y, x) end
code[x_, y_] := N[(N[(N[(N[(N[(y * y), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(y \cdot y, 0.5, 1\right) \cdot x\right) \cdot y, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6488.3
Applied rewrites88.3%
lift-*.f64N/A
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites88.3%
(FPCore (x y) :precision binary64 (fma (* (* (* y y) x) 0.5) (* y y) x))
double code(double x, double y) {
return fma((((y * y) * x) * 0.5), (y * y), x);
}
function code(x, y) return fma(Float64(Float64(Float64(y * y) * x) * 0.5), Float64(y * y), x) end
code[x_, y_] := N[(N[(N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision] * 0.5), $MachinePrecision] * N[(y * y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\left(y \cdot y\right) \cdot x\right) \cdot 0.5, y \cdot y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6488.3
Applied rewrites88.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
pow2N/A
lift-*.f64N/A
lift-*.f6488.1
Applied rewrites88.1%
(FPCore (x y) :precision binary64 (if (<= y 1e+15) (fma (* x y) y x) (* x (* y y))))
double code(double x, double y) {
double tmp;
if (y <= 1e+15) {
tmp = fma((x * y), y, x);
} else {
tmp = x * (y * y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 1e+15) tmp = fma(Float64(x * y), y, x); else tmp = Float64(x * Float64(y * y)); end return tmp end
code[x_, y_] := If[LessEqual[y, 1e+15], N[(N[(x * y), $MachinePrecision] * y + x), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot y, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 1e15Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6496.0
Applied rewrites96.0%
Applied rewrites96.0%
Taylor expanded in y around 0
Applied rewrites82.1%
if 1e15 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
lower-fma.f6471.0
Applied rewrites71.0%
Taylor expanded in y around inf
pow2N/A
lift-*.f6471.0
Applied rewrites71.0%
(FPCore (x y) :precision binary64 (* x (fma y y 1.0)))
double code(double x, double y) {
return x * fma(y, y, 1.0);
}
function code(x, y) return Float64(x * fma(y, y, 1.0)) end
code[x_, y_] := N[(x * N[(y * y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(y, y, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
pow2N/A
lower-fma.f6482.5
Applied rewrites82.5%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
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
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites46.9%
(FPCore (x y) :precision binary64 (* x (pow (exp y) y)))
double code(double x, double y) {
return x * pow(exp(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 = x * (exp(y) ** y)
end function
public static double code(double x, double y) {
return x * Math.pow(Math.exp(y), y);
}
def code(x, y): return x * math.pow(math.exp(y), y)
function code(x, y) return Float64(x * (exp(y) ^ y)) end
function tmp = code(x, y) tmp = x * (exp(y) ^ y); end
code[x_, y_] := N[(x * N[Power[N[Exp[y], $MachinePrecision], y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot {\left(e^{y}\right)}^{y}
\end{array}
herbie shell --seed 2025051
(FPCore (x y)
:name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
:precision binary64
:alt
(! :herbie-platform default (* x (pow (exp y) y)))
(* x (exp (* y y))))