
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* x x) (* x x)))
(t_1 (* t_0 (* x x)))
(t_2 (* t_1 (* x x)))
(t_3 (* t_2 (* x x))))
(*
(/
(+
(+
(+
(+ (+ 1.0 (* 0.1049934947 (* x x))) (* 0.0424060604 t_0))
(* 0.0072644182 t_1))
(* 0.0005064034 t_2))
(* 0.0001789971 t_3))
(+
(+
(+
(+
(+ (+ 1.0 (* 0.7715471019 (* x x))) (* 0.2909738639 t_0))
(* 0.0694555761 t_1))
(* 0.0140005442 t_2))
(* 0.0008327945 t_3))
(* (* 2.0 0.0001789971) (* t_3 (* x x)))))
x)))
double code(double x) {
double t_0 = (x * x) * (x * x);
double t_1 = t_0 * (x * x);
double t_2 = t_1 * (x * x);
double t_3 = t_2 * (x * x);
return ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * 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
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
t_0 = (x * x) * (x * x)
t_1 = t_0 * (x * x)
t_2 = t_1 * (x * x)
t_3 = t_2 * (x * x)
code = ((((((1.0d0 + (0.1049934947d0 * (x * x))) + (0.0424060604d0 * t_0)) + (0.0072644182d0 * t_1)) + (0.0005064034d0 * t_2)) + (0.0001789971d0 * t_3)) / ((((((1.0d0 + (0.7715471019d0 * (x * x))) + (0.2909738639d0 * t_0)) + (0.0694555761d0 * t_1)) + (0.0140005442d0 * t_2)) + (0.0008327945d0 * t_3)) + ((2.0d0 * 0.0001789971d0) * (t_3 * (x * x))))) * x
end function
public static double code(double x) {
double t_0 = (x * x) * (x * x);
double t_1 = t_0 * (x * x);
double t_2 = t_1 * (x * x);
double t_3 = t_2 * (x * x);
return ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * x))))) * x;
}
def code(x): t_0 = (x * x) * (x * x) t_1 = t_0 * (x * x) t_2 = t_1 * (x * x) t_3 = t_2 * (x * x) return ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * x))))) * x
function code(x) t_0 = Float64(Float64(x * x) * Float64(x * x)) t_1 = Float64(t_0 * Float64(x * x)) t_2 = Float64(t_1 * Float64(x * x)) t_3 = Float64(t_2 * Float64(x * x)) return Float64(Float64(Float64(Float64(Float64(Float64(Float64(1.0 + Float64(0.1049934947 * Float64(x * x))) + Float64(0.0424060604 * t_0)) + Float64(0.0072644182 * t_1)) + Float64(0.0005064034 * t_2)) + Float64(0.0001789971 * t_3)) / Float64(Float64(Float64(Float64(Float64(Float64(1.0 + Float64(0.7715471019 * Float64(x * x))) + Float64(0.2909738639 * t_0)) + Float64(0.0694555761 * t_1)) + Float64(0.0140005442 * t_2)) + Float64(0.0008327945 * t_3)) + Float64(Float64(2.0 * 0.0001789971) * Float64(t_3 * Float64(x * x))))) * x) end
function tmp = code(x) t_0 = (x * x) * (x * x); t_1 = t_0 * (x * x); t_2 = t_1 * (x * x); t_3 = t_2 * (x * x); tmp = ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * x))))) * x; end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(N[(N[(N[(1.0 + N[(0.1049934947 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.0424060604 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(0.0072644182 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(0.0005064034 * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(0.0001789971 * t$95$3), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[(N[(N[(1.0 + N[(0.7715471019 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.2909738639 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(0.0694555761 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(0.0140005442 * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(0.0008327945 * t$95$3), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * 0.0001789971), $MachinePrecision] * N[(t$95$3 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \left(x \cdot x\right)\\
t_1 := t\_0 \cdot \left(x \cdot x\right)\\
t_2 := t\_1 \cdot \left(x \cdot x\right)\\
t_3 := t\_2 \cdot \left(x \cdot x\right)\\
\frac{\left(\left(\left(\left(1 + 0.1049934947 \cdot \left(x \cdot x\right)\right) + 0.0424060604 \cdot t\_0\right) + 0.0072644182 \cdot t\_1\right) + 0.0005064034 \cdot t\_2\right) + 0.0001789971 \cdot t\_3}{\left(\left(\left(\left(\left(1 + 0.7715471019 \cdot \left(x \cdot x\right)\right) + 0.2909738639 \cdot t\_0\right) + 0.0694555761 \cdot t\_1\right) + 0.0140005442 \cdot t\_2\right) + 0.0008327945 \cdot t\_3\right) + \left(2 \cdot 0.0001789971\right) \cdot \left(t\_3 \cdot \left(x \cdot x\right)\right)} \cdot x
\end{array}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* x x) (* x x)))
(t_1 (* t_0 (* x x)))
(t_2 (* t_1 (* x x)))
(t_3 (* t_2 (* x x))))
(*
(/
(+
(+
(+
(+ (+ 1.0 (* 0.1049934947 (* x x))) (* 0.0424060604 t_0))
(* 0.0072644182 t_1))
(* 0.0005064034 t_2))
(* 0.0001789971 t_3))
(+
(+
(+
(+
(+ (+ 1.0 (* 0.7715471019 (* x x))) (* 0.2909738639 t_0))
(* 0.0694555761 t_1))
(* 0.0140005442 t_2))
(* 0.0008327945 t_3))
(* (* 2.0 0.0001789971) (* t_3 (* x x)))))
x)))
double code(double x) {
double t_0 = (x * x) * (x * x);
double t_1 = t_0 * (x * x);
double t_2 = t_1 * (x * x);
double t_3 = t_2 * (x * x);
return ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * 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
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
t_0 = (x * x) * (x * x)
t_1 = t_0 * (x * x)
t_2 = t_1 * (x * x)
t_3 = t_2 * (x * x)
code = ((((((1.0d0 + (0.1049934947d0 * (x * x))) + (0.0424060604d0 * t_0)) + (0.0072644182d0 * t_1)) + (0.0005064034d0 * t_2)) + (0.0001789971d0 * t_3)) / ((((((1.0d0 + (0.7715471019d0 * (x * x))) + (0.2909738639d0 * t_0)) + (0.0694555761d0 * t_1)) + (0.0140005442d0 * t_2)) + (0.0008327945d0 * t_3)) + ((2.0d0 * 0.0001789971d0) * (t_3 * (x * x))))) * x
end function
public static double code(double x) {
double t_0 = (x * x) * (x * x);
double t_1 = t_0 * (x * x);
double t_2 = t_1 * (x * x);
double t_3 = t_2 * (x * x);
return ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * x))))) * x;
}
def code(x): t_0 = (x * x) * (x * x) t_1 = t_0 * (x * x) t_2 = t_1 * (x * x) t_3 = t_2 * (x * x) return ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * x))))) * x
function code(x) t_0 = Float64(Float64(x * x) * Float64(x * x)) t_1 = Float64(t_0 * Float64(x * x)) t_2 = Float64(t_1 * Float64(x * x)) t_3 = Float64(t_2 * Float64(x * x)) return Float64(Float64(Float64(Float64(Float64(Float64(Float64(1.0 + Float64(0.1049934947 * Float64(x * x))) + Float64(0.0424060604 * t_0)) + Float64(0.0072644182 * t_1)) + Float64(0.0005064034 * t_2)) + Float64(0.0001789971 * t_3)) / Float64(Float64(Float64(Float64(Float64(Float64(1.0 + Float64(0.7715471019 * Float64(x * x))) + Float64(0.2909738639 * t_0)) + Float64(0.0694555761 * t_1)) + Float64(0.0140005442 * t_2)) + Float64(0.0008327945 * t_3)) + Float64(Float64(2.0 * 0.0001789971) * Float64(t_3 * Float64(x * x))))) * x) end
function tmp = code(x) t_0 = (x * x) * (x * x); t_1 = t_0 * (x * x); t_2 = t_1 * (x * x); t_3 = t_2 * (x * x); tmp = ((((((1.0 + (0.1049934947 * (x * x))) + (0.0424060604 * t_0)) + (0.0072644182 * t_1)) + (0.0005064034 * t_2)) + (0.0001789971 * t_3)) / ((((((1.0 + (0.7715471019 * (x * x))) + (0.2909738639 * t_0)) + (0.0694555761 * t_1)) + (0.0140005442 * t_2)) + (0.0008327945 * t_3)) + ((2.0 * 0.0001789971) * (t_3 * (x * x))))) * x; end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(N[(N[(N[(1.0 + N[(0.1049934947 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.0424060604 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(0.0072644182 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(0.0005064034 * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(0.0001789971 * t$95$3), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[(N[(N[(1.0 + N[(0.7715471019 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.2909738639 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(0.0694555761 * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(0.0140005442 * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(0.0008327945 * t$95$3), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * 0.0001789971), $MachinePrecision] * N[(t$95$3 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \left(x \cdot x\right)\\
t_1 := t\_0 \cdot \left(x \cdot x\right)\\
t_2 := t\_1 \cdot \left(x \cdot x\right)\\
t_3 := t\_2 \cdot \left(x \cdot x\right)\\
\frac{\left(\left(\left(\left(1 + 0.1049934947 \cdot \left(x \cdot x\right)\right) + 0.0424060604 \cdot t\_0\right) + 0.0072644182 \cdot t\_1\right) + 0.0005064034 \cdot t\_2\right) + 0.0001789971 \cdot t\_3}{\left(\left(\left(\left(\left(1 + 0.7715471019 \cdot \left(x \cdot x\right)\right) + 0.2909738639 \cdot t\_0\right) + 0.0694555761 \cdot t\_1\right) + 0.0140005442 \cdot t\_2\right) + 0.0008327945 \cdot t\_3\right) + \left(2 \cdot 0.0001789971\right) \cdot \left(t\_3 \cdot \left(x \cdot x\right)\right)} \cdot x
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* x x) x))
(t_1 (* (* t_0 t_0) (* x x)))
(t_2 (* t_1 (* x x))))
(if (<= x -2e+22)
(/ 0.5 x)
(if (<= x 5000000.0)
(/
(*
(fma
t_2
0.0001789971
(fma
t_1
0.0005064034
(fma
(fma (fma (* x x) 0.0072644182 0.0424060604) (* x x) 0.1049934947)
(* x x)
1.0)))
x)
(fma
(* t_2 (* x x))
0.0003579942
(fma
t_2
0.0008327945
(fma
t_1
0.0140005442
(fma
(fma (fma (* x x) 0.0694555761 0.2909738639) (* x x) 0.7715471019)
(* x x)
1.0)))))
(/ 0.5 x)))))
double code(double x) {
double t_0 = (x * x) * x;
double t_1 = (t_0 * t_0) * (x * x);
double t_2 = t_1 * (x * x);
double tmp;
if (x <= -2e+22) {
tmp = 0.5 / x;
} else if (x <= 5000000.0) {
tmp = (fma(t_2, 0.0001789971, fma(t_1, 0.0005064034, fma(fma(fma((x * x), 0.0072644182, 0.0424060604), (x * x), 0.1049934947), (x * x), 1.0))) * x) / fma((t_2 * (x * x)), 0.0003579942, fma(t_2, 0.0008327945, fma(t_1, 0.0140005442, fma(fma(fma((x * x), 0.0694555761, 0.2909738639), (x * x), 0.7715471019), (x * x), 1.0))));
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) t_0 = Float64(Float64(x * x) * x) t_1 = Float64(Float64(t_0 * t_0) * Float64(x * x)) t_2 = Float64(t_1 * Float64(x * x)) tmp = 0.0 if (x <= -2e+22) tmp = Float64(0.5 / x); elseif (x <= 5000000.0) tmp = Float64(Float64(fma(t_2, 0.0001789971, fma(t_1, 0.0005064034, fma(fma(fma(Float64(x * x), 0.0072644182, 0.0424060604), Float64(x * x), 0.1049934947), Float64(x * x), 1.0))) * x) / fma(Float64(t_2 * Float64(x * x)), 0.0003579942, fma(t_2, 0.0008327945, fma(t_1, 0.0140005442, fma(fma(fma(Float64(x * x), 0.0694555761, 0.2909738639), Float64(x * x), 0.7715471019), Float64(x * x), 1.0))))); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * t$95$0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2e+22], N[(0.5 / x), $MachinePrecision], If[LessEqual[x, 5000000.0], N[(N[(N[(t$95$2 * 0.0001789971 + N[(t$95$1 * 0.0005064034 + N[(N[(N[(N[(x * x), $MachinePrecision] * 0.0072644182 + 0.0424060604), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.1049934947), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] / N[(N[(t$95$2 * N[(x * x), $MachinePrecision]), $MachinePrecision] * 0.0003579942 + N[(t$95$2 * 0.0008327945 + N[(t$95$1 * 0.0140005442 + N[(N[(N[(N[(x * x), $MachinePrecision] * 0.0694555761 + 0.2909738639), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.7715471019), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot x\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot \left(x \cdot x\right)\\
t_2 := t\_1 \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -2 \cdot 10^{+22}:\\
\;\;\;\;\frac{0.5}{x}\\
\mathbf{elif}\;x \leq 5000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(t\_2, 0.0001789971, \mathsf{fma}\left(t\_1, 0.0005064034, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0072644182, 0.0424060604\right), x \cdot x, 0.1049934947\right), x \cdot x, 1\right)\right)\right) \cdot x}{\mathsf{fma}\left(t\_2 \cdot \left(x \cdot x\right), 0.0003579942, \mathsf{fma}\left(t\_2, 0.0008327945, \mathsf{fma}\left(t\_1, 0.0140005442, \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.0694555761, 0.2909738639\right), x \cdot x, 0.7715471019\right), x \cdot x, 1\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -2e22 or 5e6 < x Initial program 4.0%
Taylor expanded in x around inf
lower-/.f64100.0
Applied rewrites100.0%
if -2e22 < x < 5e6Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
pow2N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
pow2N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.9%
(FPCore (x)
:precision binary64
(if (<= x -1.46)
(-
(/
(-
(-
(/
(+ (/ 11.259630434457211 (* x x)) 0.15298196345929074)
(* (* (* x x) x) x)))
(/
(- (/ 0.06321096047386739 (* (* x x) (* x x))) 0.25)
(- (/ 0.2514179000665374 (* x x)) 0.5)))
x))
(if (<= x 0.88)
(* (fma (- (* 0.265709700396151 (* x x)) 0.6665536072) (* x x) 1.0) x)
(/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -1.46) {
tmp = -((-(((11.259630434457211 / (x * x)) + 0.15298196345929074) / (((x * x) * x) * x)) - (((0.06321096047386739 / ((x * x) * (x * x))) - 0.25) / ((0.2514179000665374 / (x * x)) - 0.5))) / x);
} else if (x <= 0.88) {
tmp = fma(((0.265709700396151 * (x * x)) - 0.6665536072), (x * x), 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.46) tmp = Float64(-Float64(Float64(Float64(-Float64(Float64(Float64(11.259630434457211 / Float64(x * x)) + 0.15298196345929074) / Float64(Float64(Float64(x * x) * x) * x))) - Float64(Float64(Float64(0.06321096047386739 / Float64(Float64(x * x) * Float64(x * x))) - 0.25) / Float64(Float64(0.2514179000665374 / Float64(x * x)) - 0.5))) / x)); elseif (x <= 0.88) tmp = Float64(fma(Float64(Float64(0.265709700396151 * Float64(x * x)) - 0.6665536072), Float64(x * x), 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -1.46], (-N[(N[((-N[(N[(N[(11.259630434457211 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.15298196345929074), $MachinePrecision] / N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]) - N[(N[(N[(0.06321096047386739 / N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision] / N[(N[(0.2514179000665374 / N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), If[LessEqual[x, 0.88], N[(N[(N[(N[(0.265709700396151 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.6665536072), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.46:\\
\;\;\;\;-\frac{\left(-\frac{\frac{11.259630434457211}{x \cdot x} + 0.15298196345929074}{\left(\left(x \cdot x\right) \cdot x\right) \cdot x}\right) - \frac{\frac{0.06321096047386739}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)} - 0.25}{\frac{0.2514179000665374}{x \cdot x} - 0.5}}{x}\\
\mathbf{elif}\;x \leq 0.88:\\
\;\;\;\;\mathsf{fma}\left(0.265709700396151 \cdot \left(x \cdot x\right) - 0.6665536072, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -1.46Initial program 10.1%
Taylor expanded in x around -inf
Applied rewrites99.6%
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
flip-+N/A
lower-/.f64N/A
Applied rewrites99.6%
if -1.46 < x < 0.880000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites99.7%
if 0.880000000000000004 < x Initial program 7.8%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (x)
:precision binary64
(if (<= x -1.46)
(-
(/
(-
(-
(/
(+ (/ 11.259630434457211 (* x x)) 0.15298196345929074)
(* (* (* x x) x) x)))
(+ (/ 0.2514179000665374 (* x x)) 0.5))
x))
(if (<= x 0.88)
(* (fma (- (* 0.265709700396151 (* x x)) 0.6665536072) (* x x) 1.0) x)
(/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -1.46) {
tmp = -((-(((11.259630434457211 / (x * x)) + 0.15298196345929074) / (((x * x) * x) * x)) - ((0.2514179000665374 / (x * x)) + 0.5)) / x);
} else if (x <= 0.88) {
tmp = fma(((0.265709700396151 * (x * x)) - 0.6665536072), (x * x), 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.46) tmp = Float64(-Float64(Float64(Float64(-Float64(Float64(Float64(11.259630434457211 / Float64(x * x)) + 0.15298196345929074) / Float64(Float64(Float64(x * x) * x) * x))) - Float64(Float64(0.2514179000665374 / Float64(x * x)) + 0.5)) / x)); elseif (x <= 0.88) tmp = Float64(fma(Float64(Float64(0.265709700396151 * Float64(x * x)) - 0.6665536072), Float64(x * x), 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -1.46], (-N[(N[((-N[(N[(N[(11.259630434457211 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.15298196345929074), $MachinePrecision] / N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]) - N[(N[(0.2514179000665374 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), If[LessEqual[x, 0.88], N[(N[(N[(N[(0.265709700396151 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.6665536072), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.46:\\
\;\;\;\;-\frac{\left(-\frac{\frac{11.259630434457211}{x \cdot x} + 0.15298196345929074}{\left(\left(x \cdot x\right) \cdot x\right) \cdot x}\right) - \left(\frac{0.2514179000665374}{x \cdot x} + 0.5\right)}{x}\\
\mathbf{elif}\;x \leq 0.88:\\
\;\;\;\;\mathsf{fma}\left(0.265709700396151 \cdot \left(x \cdot x\right) - 0.6665536072, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -1.46Initial program 10.1%
Taylor expanded in x around -inf
Applied rewrites99.6%
if -1.46 < x < 0.880000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites99.7%
if 0.880000000000000004 < x Initial program 7.8%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (x)
:precision binary64
(if (<= x -1.15)
(-
(/
(-
(/ -0.15298196345929074 (* (* x x) (* x x)))
(+ (/ 0.2514179000665374 (* x x)) 0.5))
x))
(if (<= x 0.88)
(* (fma (- (* 0.265709700396151 (* x x)) 0.6665536072) (* x x) 1.0) x)
(/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -1.15) {
tmp = -(((-0.15298196345929074 / ((x * x) * (x * x))) - ((0.2514179000665374 / (x * x)) + 0.5)) / x);
} else if (x <= 0.88) {
tmp = fma(((0.265709700396151 * (x * x)) - 0.6665536072), (x * x), 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.15) tmp = Float64(-Float64(Float64(Float64(-0.15298196345929074 / Float64(Float64(x * x) * Float64(x * x))) - Float64(Float64(0.2514179000665374 / Float64(x * x)) + 0.5)) / x)); elseif (x <= 0.88) tmp = Float64(fma(Float64(Float64(0.265709700396151 * Float64(x * x)) - 0.6665536072), Float64(x * x), 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -1.15], (-N[(N[(N[(-0.15298196345929074 / N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(0.2514179000665374 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), If[LessEqual[x, 0.88], N[(N[(N[(N[(0.265709700396151 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.6665536072), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15:\\
\;\;\;\;-\frac{\frac{-0.15298196345929074}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)} - \left(\frac{0.2514179000665374}{x \cdot x} + 0.5\right)}{x}\\
\mathbf{elif}\;x \leq 0.88:\\
\;\;\;\;\mathsf{fma}\left(0.265709700396151 \cdot \left(x \cdot x\right) - 0.6665536072, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -1.1499999999999999Initial program 10.2%
Taylor expanded in x around -inf
Applied rewrites99.6%
Taylor expanded in x around inf
lower-/.f64N/A
metadata-evalN/A
pow-plusN/A
pow3N/A
associate-*r*N/A
lower-*.f64N/A
lift-*.f64N/A
lift-*.f6499.5
Applied rewrites99.5%
if -1.1499999999999999 < x < 0.880000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites99.7%
if 0.880000000000000004 < x Initial program 7.8%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (x)
:precision binary64
(if (<= x -1.15)
(-
(/
(-
(- (/ (+ (/ 0.15298196345929074 (* x x)) 0.2514179000665374) (* x x)))
0.5)
x))
(if (<= x 0.88)
(* (fma (- (* 0.265709700396151 (* x x)) 0.6665536072) (* x x) 1.0) x)
(/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -1.15) {
tmp = -((-(((0.15298196345929074 / (x * x)) + 0.2514179000665374) / (x * x)) - 0.5) / x);
} else if (x <= 0.88) {
tmp = fma(((0.265709700396151 * (x * x)) - 0.6665536072), (x * x), 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.15) tmp = Float64(-Float64(Float64(Float64(-Float64(Float64(Float64(0.15298196345929074 / Float64(x * x)) + 0.2514179000665374) / Float64(x * x))) - 0.5) / x)); elseif (x <= 0.88) tmp = Float64(fma(Float64(Float64(0.265709700396151 * Float64(x * x)) - 0.6665536072), Float64(x * x), 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -1.15], (-N[(N[((-N[(N[(N[(0.15298196345929074 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.2514179000665374), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]) - 0.5), $MachinePrecision] / x), $MachinePrecision]), If[LessEqual[x, 0.88], N[(N[(N[(N[(0.265709700396151 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.6665536072), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15:\\
\;\;\;\;-\frac{\left(-\frac{\frac{0.15298196345929074}{x \cdot x} + 0.2514179000665374}{x \cdot x}\right) - 0.5}{x}\\
\mathbf{elif}\;x \leq 0.88:\\
\;\;\;\;\mathsf{fma}\left(0.265709700396151 \cdot \left(x \cdot x\right) - 0.6665536072, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -1.1499999999999999Initial program 10.2%
Taylor expanded in x around -inf
Applied rewrites99.5%
if -1.1499999999999999 < x < 0.880000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites99.7%
if 0.880000000000000004 < x Initial program 7.8%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (x)
:precision binary64
(if (<= x -1.1)
(/ (+ (/ 0.2514179000665374 (* x x)) 0.5) x)
(if (<= x 0.88)
(* (fma (- (* 0.265709700396151 (* x x)) 0.6665536072) (* x x) 1.0) x)
(/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -1.1) {
tmp = ((0.2514179000665374 / (x * x)) + 0.5) / x;
} else if (x <= 0.88) {
tmp = fma(((0.265709700396151 * (x * x)) - 0.6665536072), (x * x), 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -1.1) tmp = Float64(Float64(Float64(0.2514179000665374 / Float64(x * x)) + 0.5) / x); elseif (x <= 0.88) tmp = Float64(fma(Float64(Float64(0.265709700396151 * Float64(x * x)) - 0.6665536072), Float64(x * x), 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -1.1], N[(N[(N[(0.2514179000665374 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 0.88], N[(N[(N[(N[(0.265709700396151 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.6665536072), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1:\\
\;\;\;\;\frac{\frac{0.2514179000665374}{x \cdot x} + 0.5}{x}\\
\mathbf{elif}\;x \leq 0.88:\\
\;\;\;\;\mathsf{fma}\left(0.265709700396151 \cdot \left(x \cdot x\right) - 0.6665536072, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -1.1000000000000001Initial program 10.2%
Taylor expanded in x around inf
lower-/.f64N/A
Applied rewrites99.4%
if -1.1000000000000001 < x < 0.880000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites99.7%
if 0.880000000000000004 < x Initial program 7.8%
Taylor expanded in x around inf
lower-/.f6499.1
Applied rewrites99.1%
(FPCore (x)
:precision binary64
(if (<= x -0.88)
(/ 0.5 x)
(if (<= x 0.88)
(* (fma (- (* 0.265709700396151 (* x x)) 0.6665536072) (* x x) 1.0) x)
(/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -0.88) {
tmp = 0.5 / x;
} else if (x <= 0.88) {
tmp = fma(((0.265709700396151 * (x * x)) - 0.6665536072), (x * x), 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -0.88) tmp = Float64(0.5 / x); elseif (x <= 0.88) tmp = Float64(fma(Float64(Float64(0.265709700396151 * Float64(x * x)) - 0.6665536072), Float64(x * x), 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -0.88], N[(0.5 / x), $MachinePrecision], If[LessEqual[x, 0.88], N[(N[(N[(N[(0.265709700396151 * N[(x * x), $MachinePrecision]), $MachinePrecision] - 0.6665536072), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.88:\\
\;\;\;\;\frac{0.5}{x}\\
\mathbf{elif}\;x \leq 0.88:\\
\;\;\;\;\mathsf{fma}\left(0.265709700396151 \cdot \left(x \cdot x\right) - 0.6665536072, x \cdot x, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -0.880000000000000004 or 0.880000000000000004 < x Initial program 9.0%
Taylor expanded in x around inf
lower-/.f6498.9
Applied rewrites98.9%
if -0.880000000000000004 < x < 0.880000000000000004Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites99.7%
(FPCore (x) :precision binary64 (if (<= x -0.78) (/ 0.5 x) (if (<= x 0.78) (* (fma (* x x) -0.6665536072 1.0) x) (/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -0.78) {
tmp = 0.5 / x;
} else if (x <= 0.78) {
tmp = fma((x * x), -0.6665536072, 1.0) * x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -0.78) tmp = Float64(0.5 / x); elseif (x <= 0.78) tmp = Float64(fma(Float64(x * x), -0.6665536072, 1.0) * x); else tmp = Float64(0.5 / x); end return tmp end
code[x_] := If[LessEqual[x, -0.78], N[(0.5 / x), $MachinePrecision], If[LessEqual[x, 0.78], N[(N[(N[(x * x), $MachinePrecision] * -0.6665536072 + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.78:\\
\;\;\;\;\frac{0.5}{x}\\
\mathbf{elif}\;x \leq 0.78:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, -0.6665536072, 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -0.78000000000000003 or 0.78000000000000003 < x Initial program 9.0%
Taylor expanded in x around inf
lower-/.f6498.9
Applied rewrites98.9%
if -0.78000000000000003 < x < 0.78000000000000003Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.6%
(FPCore (x) :precision binary64 (if (<= x -0.7) (/ 0.5 x) (if (<= x 0.7) x (/ 0.5 x))))
double code(double x) {
double tmp;
if (x <= -0.7) {
tmp = 0.5 / x;
} else if (x <= 0.7) {
tmp = x;
} else {
tmp = 0.5 / 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 <= (-0.7d0)) then
tmp = 0.5d0 / x
else if (x <= 0.7d0) then
tmp = x
else
tmp = 0.5d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -0.7) {
tmp = 0.5 / x;
} else if (x <= 0.7) {
tmp = x;
} else {
tmp = 0.5 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -0.7: tmp = 0.5 / x elif x <= 0.7: tmp = x else: tmp = 0.5 / x return tmp
function code(x) tmp = 0.0 if (x <= -0.7) tmp = Float64(0.5 / x); elseif (x <= 0.7) tmp = x; else tmp = Float64(0.5 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.7) tmp = 0.5 / x; elseif (x <= 0.7) tmp = x; else tmp = 0.5 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -0.7], N[(0.5 / x), $MachinePrecision], If[LessEqual[x, 0.7], x, N[(0.5 / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.7:\\
\;\;\;\;\frac{0.5}{x}\\
\mathbf{elif}\;x \leq 0.7:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < -0.69999999999999996 or 0.69999999999999996 < x Initial program 9.0%
Taylor expanded in x around inf
lower-/.f6498.9
Applied rewrites98.9%
if -0.69999999999999996 < x < 0.69999999999999996Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites99.0%
(FPCore (x) :precision binary64 x)
double code(double x) {
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)
use fmin_fmax_functions
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 54.5%
Taylor expanded in x around 0
Applied rewrites51.4%
herbie shell --seed 2025092
(FPCore (x)
:name "Jmat.Real.dawson"
:precision binary64
(* (/ (+ (+ (+ (+ (+ 1.0 (* 0.1049934947 (* x x))) (* 0.0424060604 (* (* x x) (* x x)))) (* 0.0072644182 (* (* (* x x) (* x x)) (* x x)))) (* 0.0005064034 (* (* (* (* x x) (* x x)) (* x x)) (* x x)))) (* 0.0001789971 (* (* (* (* (* x x) (* x x)) (* x x)) (* x x)) (* x x)))) (+ (+ (+ (+ (+ (+ 1.0 (* 0.7715471019 (* x x))) (* 0.2909738639 (* (* x x) (* x x)))) (* 0.0694555761 (* (* (* x x) (* x x)) (* x x)))) (* 0.0140005442 (* (* (* (* x x) (* x x)) (* x x)) (* x x)))) (* 0.0008327945 (* (* (* (* (* x x) (* x x)) (* x x)) (* x x)) (* x x)))) (* (* 2.0 0.0001789971) (* (* (* (* (* (* x x) (* x x)) (* x x)) (* x x)) (* x x)) (* x x))))) x))