
(FPCore (x) :precision binary64 (/ 10.0 (- 1.0 (* x x))))
double code(double x) {
return 10.0 / (1.0 - (x * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 10.0d0 / (1.0d0 - (x * x))
end function
public static double code(double x) {
return 10.0 / (1.0 - (x * x));
}
def code(x): return 10.0 / (1.0 - (x * x))
function code(x) return Float64(10.0 / Float64(1.0 - Float64(x * x))) end
function tmp = code(x) tmp = 10.0 / (1.0 - (x * x)); end
code[x_] := N[(10.0 / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{10}{1 - x \cdot x}
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ 10.0 (- 1.0 (* x x))))
double code(double x) {
return 10.0 / (1.0 - (x * 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 10.0d0 / (1.0d0 - (x * x))
end function
public static double code(double x) {
return 10.0 / (1.0 - (x * x));
}
def code(x): return 10.0 / (1.0 - (x * x))
function code(x) return Float64(10.0 / Float64(1.0 - Float64(x * x))) end
function tmp = code(x) tmp = 10.0 / (1.0 - (x * x)); end
code[x_] := N[(10.0 / N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{10}{1 - x \cdot x}
\end{array}
(FPCore (x) :precision binary64 (/ -10.0 (fma x x -1.0)))
double code(double x) {
return -10.0 / fma(x, x, -1.0);
}
function code(x) return Float64(-10.0 / fma(x, x, -1.0)) end
code[x_] := N[(-10.0 / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-10}{\mathsf{fma}\left(x, x, -1\right)}
\end{array}
Initial program 87.7%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
pow2N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.6
Applied rewrites99.6%
lift-/.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
lift-neg.f64N/A
distribute-neg-inN/A
lift-neg.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
mul-1-negN/A
sqr-neg-revN/A
metadata-evalN/A
lower-fma.f6499.6
Applied rewrites99.6%
(FPCore (x) :precision binary64 (if (<= x 1.0) (* (fma x x 1.0) 10.0) (/ -10.0 (* x x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = fma(x, x, 1.0) * 10.0;
} else {
tmp = -10.0 / (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(fma(x, x, 1.0) * 10.0); else tmp = Float64(-10.0 / Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[x, 1.0], N[(N[(x * x + 1.0), $MachinePrecision] * 10.0), $MachinePrecision], N[(-10.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\mathsf{fma}\left(x, x, 1\right) \cdot 10\\
\mathbf{else}:\\
\;\;\;\;\frac{-10}{x \cdot x}\\
\end{array}
\end{array}
if x < 1Initial program 88.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6413.7
Applied rewrites13.7%
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
distribute-lft1-inN/A
+-commutativeN/A
pow2N/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-outN/A
pow2N/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-outN/A
fp-cancel-sign-sub-invN/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f6413.7
Applied rewrites13.7%
if 1 < x Initial program 86.7%
Taylor expanded in x around inf
lower-/.f64N/A
pow2N/A
lift-*.f6413.5
Applied rewrites13.5%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ 10.0 x) (/ -10.0 (* x x))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 10.0 / x;
} else {
tmp = -10.0 / (x * x);
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = 10.0d0 / x
else
tmp = (-10.0d0) / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = 10.0 / x;
} else {
tmp = -10.0 / (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 10.0 / x else: tmp = -10.0 / (x * x) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(10.0 / x); else tmp = Float64(-10.0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 10.0 / x; else tmp = -10.0 / (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(10.0 / x), $MachinePrecision], N[(-10.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{10}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-10}{x \cdot x}\\
\end{array}
\end{array}
if x < 1Initial program 88.3%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
pow2N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.6
Applied rewrites99.6%
lift-/.f64N/A
lift-fma.f64N/A
+-commutativeN/A
lift-neg.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
difference-of-squares-revN/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift--.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.5
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites13.3%
Taylor expanded in x around inf
Applied rewrites13.5%
if 1 < x Initial program 86.7%
Taylor expanded in x around inf
lower-/.f64N/A
pow2N/A
lift-*.f6413.5
Applied rewrites13.5%
(FPCore (x) :precision binary64 (/ 10.0 x))
double code(double x) {
return 10.0 / 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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 10.0d0 / x
end function
public static double code(double x) {
return 10.0 / x;
}
def code(x): return 10.0 / x
function code(x) return Float64(10.0 / x) end
function tmp = code(x) tmp = 10.0 / x; end
code[x_] := N[(10.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{10}{x}
\end{array}
Initial program 87.7%
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
pow2N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
pow2N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.6
Applied rewrites99.6%
lift-/.f64N/A
lift-fma.f64N/A
+-commutativeN/A
lift-neg.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
difference-of-squares-revN/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift--.f64N/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f6499.4
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites9.4%
Taylor expanded in x around inf
Applied rewrites9.5%
(FPCore (x) :precision binary64 10.0)
double code(double x) {
return 10.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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 10.0d0
end function
public static double code(double x) {
return 10.0;
}
def code(x): return 10.0
function code(x) return 10.0 end
function tmp = code(x) tmp = 10.0; end
code[x_] := 10.0
\begin{array}{l}
\\
10
\end{array}
Initial program 87.7%
Taylor expanded in x around 0
Applied rewrites9.5%
herbie shell --seed 2025112
(FPCore (x)
:name "ENA, Section 1.4, Mentioned, B"
:precision binary64
:pre (and (<= 0.999 x) (<= x 1.001))
(/ 10.0 (- 1.0 (* x x))))