
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1.95e-43)
(- (/ c b))
(if (<= b 1e+143)
(/ (- (- b) (sqrt (fma (* -4.0 a) c (* b b)))) (+ a a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-43) {
tmp = -(c / b);
} else if (b <= 1e+143) {
tmp = (-b - sqrt(fma((-4.0 * a), c, (b * b)))) / (a + a);
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-43) tmp = Float64(-Float64(c / b)); elseif (b <= 1e+143) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(-4.0 * a), c, Float64(b * b)))) / Float64(a + a)); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-43], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1e+143], N[(N[((-b) - N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-43}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 10^{+143}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.95e-43Initial program 16.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
if -1.95e-43 < b < 1e143Initial program 79.9%
lift-*.f64N/A
lift--.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6479.9
lift-*.f64N/A
count-2-revN/A
lower-+.f6479.9
Applied rewrites79.9%
if 1e143 < b Initial program 43.2%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6496.8
Applied rewrites96.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e-43)
(- (/ c b))
(if (<= b 1.75e-93)
(* -0.5 (/ (+ (sqrt (* (* a -4.0) c)) b) a))
(+ (/ c b) (/ (- b) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-43) {
tmp = -(c / b);
} else if (b <= 1.75e-93) {
tmp = -0.5 * ((sqrt(((a * -4.0) * c)) + b) / a);
} else {
tmp = (c / b) + (-b / a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.15d-43)) then
tmp = -(c / b)
else if (b <= 1.75d-93) then
tmp = (-0.5d0) * ((sqrt(((a * (-4.0d0)) * c)) + b) / a)
else
tmp = (c / b) + (-b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-43) {
tmp = -(c / b);
} else if (b <= 1.75e-93) {
tmp = -0.5 * ((Math.sqrt(((a * -4.0) * c)) + b) / a);
} else {
tmp = (c / b) + (-b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.15e-43: tmp = -(c / b) elif b <= 1.75e-93: tmp = -0.5 * ((math.sqrt(((a * -4.0) * c)) + b) / a) else: tmp = (c / b) + (-b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.15e-43) tmp = Float64(-Float64(c / b)); elseif (b <= 1.75e-93) tmp = Float64(-0.5 * Float64(Float64(sqrt(Float64(Float64(a * -4.0) * c)) + b) / a)); else tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.15e-43) tmp = -(c / b); elseif (b <= 1.75e-93) tmp = -0.5 * ((sqrt(((a * -4.0) * c)) + b) / a); else tmp = (c / b) + (-b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-43], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.75e-93], N[(-0.5 * N[(N[(N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{-43}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-93}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{\left(a \cdot -4\right) \cdot c} + b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.1499999999999999e-43Initial program 16.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
if -1.1499999999999999e-43 < b < 1.75e-93Initial program 70.3%
Taylor expanded in a around inf
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6431.1
Applied rewrites31.1%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
sqrt-unprodN/A
*-commutativeN/A
associate-*r*N/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6466.6
Applied rewrites66.6%
if 1.75e-93 < b Initial program 70.9%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-44)
(- (/ c b))
(if (<= b 1.75e-93)
(/ (- (sqrt (* -4.0 (* c a)))) (* 2.0 a))
(+ (/ c b) (/ (- b) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-44) {
tmp = -(c / b);
} else if (b <= 1.75e-93) {
tmp = -sqrt((-4.0 * (c * a))) / (2.0 * a);
} else {
tmp = (c / b) + (-b / a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-9d-44)) then
tmp = -(c / b)
else if (b <= 1.75d-93) then
tmp = -sqrt(((-4.0d0) * (c * a))) / (2.0d0 * a)
else
tmp = (c / b) + (-b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-44) {
tmp = -(c / b);
} else if (b <= 1.75e-93) {
tmp = -Math.sqrt((-4.0 * (c * a))) / (2.0 * a);
} else {
tmp = (c / b) + (-b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-44: tmp = -(c / b) elif b <= 1.75e-93: tmp = -math.sqrt((-4.0 * (c * a))) / (2.0 * a) else: tmp = (c / b) + (-b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-44) tmp = Float64(-Float64(c / b)); elseif (b <= 1.75e-93) tmp = Float64(Float64(-sqrt(Float64(-4.0 * Float64(c * a)))) / Float64(2.0 * a)); else tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-44) tmp = -(c / b); elseif (b <= 1.75e-93) tmp = -sqrt((-4.0 * (c * a))) / (2.0 * a); else tmp = (c / b) + (-b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-44], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.75e-93], N[((-N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-44}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-93}:\\
\;\;\;\;\frac{-\sqrt{-4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.9999999999999997e-44Initial program 16.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
if -8.9999999999999997e-44 < b < 1.75e-93Initial program 70.4%
Taylor expanded in a around inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6465.8
Applied rewrites65.8%
if 1.75e-93 < b Initial program 70.9%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-44)
(- (/ c b))
(if (<= b 1.75e-93)
(* (/ (sqrt (* (* -4.0 a) c)) a) -0.5)
(+ (/ c b) (/ (- b) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-44) {
tmp = -(c / b);
} else if (b <= 1.75e-93) {
tmp = (sqrt(((-4.0 * a) * c)) / a) * -0.5;
} else {
tmp = (c / b) + (-b / a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-9d-44)) then
tmp = -(c / b)
else if (b <= 1.75d-93) then
tmp = (sqrt((((-4.0d0) * a) * c)) / a) * (-0.5d0)
else
tmp = (c / b) + (-b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-44) {
tmp = -(c / b);
} else if (b <= 1.75e-93) {
tmp = (Math.sqrt(((-4.0 * a) * c)) / a) * -0.5;
} else {
tmp = (c / b) + (-b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-44: tmp = -(c / b) elif b <= 1.75e-93: tmp = (math.sqrt(((-4.0 * a) * c)) / a) * -0.5 else: tmp = (c / b) + (-b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-44) tmp = Float64(-Float64(c / b)); elseif (b <= 1.75e-93) tmp = Float64(Float64(sqrt(Float64(Float64(-4.0 * a) * c)) / a) * -0.5); else tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-44) tmp = -(c / b); elseif (b <= 1.75e-93) tmp = (sqrt(((-4.0 * a) * c)) / a) * -0.5; else tmp = (c / b) + (-b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-44], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.75e-93], N[(N[(N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision] * -0.5), $MachinePrecision], N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-44}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{\left(-4 \cdot a\right) \cdot c}}{a} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.9999999999999997e-44Initial program 16.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.2
Applied rewrites88.2%
if -8.9999999999999997e-44 < b < 1.75e-93Initial program 70.4%
Taylor expanded in a around inf
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6431.1
Applied rewrites31.1%
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
*-commutativeN/A
sqrt-prodN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.1%
Taylor expanded in a around 0
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
sqrt-unprodN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lift-sqrt.f6466.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.6
Applied rewrites66.6%
Taylor expanded in a around inf
sqrt-unprodN/A
*-commutativeN/A
associate-*r*N/A
lift-*.f64N/A
lift-*.f64N/A
lift-sqrt.f6465.8
Applied rewrites65.8%
if 1.75e-93 < b Initial program 70.9%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-180)
(- (/ c b))
(if (<= b 1e-211)
(sqrt (- (/ c a)))
(if (<= b 4.2e-95)
(- (/ (sqrt (* c -1.0)) (sqrt a)))
(+ (/ c b) (/ (- b) a))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-180) {
tmp = -(c / b);
} else if (b <= 1e-211) {
tmp = sqrt(-(c / a));
} else if (b <= 4.2e-95) {
tmp = -(sqrt((c * -1.0)) / sqrt(a));
} else {
tmp = (c / b) + (-b / a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3d-180)) then
tmp = -(c / b)
else if (b <= 1d-211) then
tmp = sqrt(-(c / a))
else if (b <= 4.2d-95) then
tmp = -(sqrt((c * (-1.0d0))) / sqrt(a))
else
tmp = (c / b) + (-b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3e-180) {
tmp = -(c / b);
} else if (b <= 1e-211) {
tmp = Math.sqrt(-(c / a));
} else if (b <= 4.2e-95) {
tmp = -(Math.sqrt((c * -1.0)) / Math.sqrt(a));
} else {
tmp = (c / b) + (-b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-180: tmp = -(c / b) elif b <= 1e-211: tmp = math.sqrt(-(c / a)) elif b <= 4.2e-95: tmp = -(math.sqrt((c * -1.0)) / math.sqrt(a)) else: tmp = (c / b) + (-b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-180) tmp = Float64(-Float64(c / b)); elseif (b <= 1e-211) tmp = sqrt(Float64(-Float64(c / a))); elseif (b <= 4.2e-95) tmp = Float64(-Float64(sqrt(Float64(c * -1.0)) / sqrt(a))); else tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3e-180) tmp = -(c / b); elseif (b <= 1e-211) tmp = sqrt(-(c / a)); elseif (b <= 4.2e-95) tmp = -(sqrt((c * -1.0)) / sqrt(a)); else tmp = (c / b) + (-b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-180], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1e-211], N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision], If[LessEqual[b, 4.2e-95], (-N[(N[Sqrt[N[(c * -1.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[a], $MachinePrecision]), $MachinePrecision]), N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-180}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 10^{-211}:\\
\;\;\;\;\sqrt{-\frac{c}{a}}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-95}:\\
\;\;\;\;-\frac{\sqrt{c \cdot -1}}{\sqrt{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.0000000000000001e-180Initial program 24.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6477.5
Applied rewrites77.5%
if -3.0000000000000001e-180 < b < 1.00000000000000009e-211Initial program 72.3%
lift-*.f64N/A
lift--.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6472.4
lift-*.f64N/A
count-2-revN/A
lower-+.f6472.4
Applied rewrites72.4%
Taylor expanded in a around -inf
count-2-revN/A
pow2N/A
+-commutativeN/A
associate-*r*N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
pow2N/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
*-commutativeN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6439.6
Applied rewrites39.6%
Taylor expanded in a around inf
*-commutativeN/A
sqrt-prodN/A
lower-sqrt.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6439.3
Applied rewrites39.3%
if 1.00000000000000009e-211 < b < 4.2e-95Initial program 83.2%
Taylor expanded in a around inf
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
*-commutativeN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6430.9
Applied rewrites30.9%
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
*-commutativeN/A
sqrt-prodN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites30.9%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6429.1
Applied rewrites29.1%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6440.2
Applied rewrites40.2%
if 4.2e-95 < b Initial program 71.0%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
(FPCore (a b c) :precision binary64 (if (<= b -3e-180) (- (/ c b)) (if (<= b 2.25e-97) (sqrt (- (/ c a))) (+ (/ c b) (/ (- b) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-180) {
tmp = -(c / b);
} else if (b <= 2.25e-97) {
tmp = sqrt(-(c / a));
} else {
tmp = (c / b) + (-b / a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3d-180)) then
tmp = -(c / b)
else if (b <= 2.25d-97) then
tmp = sqrt(-(c / a))
else
tmp = (c / b) + (-b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3e-180) {
tmp = -(c / b);
} else if (b <= 2.25e-97) {
tmp = Math.sqrt(-(c / a));
} else {
tmp = (c / b) + (-b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-180: tmp = -(c / b) elif b <= 2.25e-97: tmp = math.sqrt(-(c / a)) else: tmp = (c / b) + (-b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-180) tmp = Float64(-Float64(c / b)); elseif (b <= 2.25e-97) tmp = sqrt(Float64(-Float64(c / a))); else tmp = Float64(Float64(c / b) + Float64(Float64(-b) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3e-180) tmp = -(c / b); elseif (b <= 2.25e-97) tmp = sqrt(-(c / a)); else tmp = (c / b) + (-b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-180], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 2.25e-97], N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision], N[(N[(c / b), $MachinePrecision] + N[((-b) / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-180}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-97}:\\
\;\;\;\;\sqrt{-\frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} + \frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.0000000000000001e-180Initial program 24.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6477.5
Applied rewrites77.5%
if -3.0000000000000001e-180 < b < 2.25000000000000005e-97Initial program 76.1%
lift-*.f64N/A
lift--.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6476.2
lift-*.f64N/A
count-2-revN/A
lower-+.f6476.2
Applied rewrites76.2%
Taylor expanded in a around -inf
count-2-revN/A
pow2N/A
+-commutativeN/A
associate-*r*N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
pow2N/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
*-commutativeN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6435.4
Applied rewrites35.4%
Taylor expanded in a around inf
*-commutativeN/A
sqrt-prodN/A
lower-sqrt.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6434.7
Applied rewrites34.7%
if 2.25000000000000005e-97 < b Initial program 71.1%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6485.3
Applied rewrites85.3%
(FPCore (a b c) :precision binary64 (if (<= b -3e-180) (- (/ c b)) (if (<= b 2.25e-97) (sqrt (- (/ c a))) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-180) {
tmp = -(c / b);
} else if (b <= 2.25e-97) {
tmp = sqrt(-(c / a));
} else {
tmp = -b / a;
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3d-180)) then
tmp = -(c / b)
else if (b <= 2.25d-97) then
tmp = sqrt(-(c / a))
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3e-180) {
tmp = -(c / b);
} else if (b <= 2.25e-97) {
tmp = Math.sqrt(-(c / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-180: tmp = -(c / b) elif b <= 2.25e-97: tmp = math.sqrt(-(c / a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-180) tmp = Float64(-Float64(c / b)); elseif (b <= 2.25e-97) tmp = sqrt(Float64(-Float64(c / a))); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3e-180) tmp = -(c / b); elseif (b <= 2.25e-97) tmp = sqrt(-(c / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-180], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 2.25e-97], N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-180}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-97}:\\
\;\;\;\;\sqrt{-\frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.0000000000000001e-180Initial program 24.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6477.5
Applied rewrites77.5%
if -3.0000000000000001e-180 < b < 2.25000000000000005e-97Initial program 76.1%
lift-*.f64N/A
lift--.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6476.2
lift-*.f64N/A
count-2-revN/A
lower-+.f6476.2
Applied rewrites76.2%
Taylor expanded in a around -inf
count-2-revN/A
pow2N/A
+-commutativeN/A
associate-*r*N/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
pow2N/A
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
*-commutativeN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6435.4
Applied rewrites35.4%
Taylor expanded in a around inf
*-commutativeN/A
sqrt-prodN/A
lower-sqrt.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6434.7
Applied rewrites34.7%
if 2.25000000000000005e-97 < b Initial program 71.1%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6485.0
Applied rewrites85.0%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (- (/ c b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -(c / b);
} else {
tmp = -b / a;
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1d-309)) then
tmp = -(c / b)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -(c / b);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -(c / b) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(-Float64(c / b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -(c / b); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], (-N[(c / b), $MachinePrecision]), N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 31.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6467.9
Applied rewrites67.9%
if -1.000000000000002e-309 < b Initial program 72.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6468.3
Applied rewrites68.3%
(FPCore (a b c) :precision binary64 (- (/ c b)))
double code(double a, double b, double c) {
return -(c / b);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -(c / b)
end function
public static double code(double a, double b, double c) {
return -(c / b);
}
def code(a, b, c): return -(c / b)
function code(a, b, c) return Float64(-Float64(c / b)) end
function tmp = code(a, b, c) tmp = -(c / b); end
code[a_, b_, c_] := (-N[(c / b), $MachinePrecision])
\begin{array}{l}
\\
-\frac{c}{b}
\end{array}
Initial program 52.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6434.9
Applied rewrites34.9%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 52.4%
Taylor expanded in c around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6435.7
Applied rewrites35.7%
Taylor expanded in a around inf
lift-/.f6410.6
Applied rewrites10.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
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(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2025116
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform c (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))