
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1e+153)
(/ (- b) a)
(if (<= b 1.15e-93)
(- (/ (sqrt (fma (* -4.0 a) c (* b b))) (+ a a)) (/ b (+ a a)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = -b / a;
} else if (b <= 1.15e-93) {
tmp = (sqrt(fma((-4.0 * a), c, (b * b))) / (a + a)) - (b / (a + a));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1e+153) tmp = Float64(Float64(-b) / a); elseif (b <= 1.15e-93) tmp = Float64(Float64(sqrt(fma(Float64(-4.0 * a), c, Float64(b * b))) / Float64(a + a)) - Float64(b / Float64(a + a))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1e+153], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.15e-93], N[(N[(N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision] - N[(b / N[(a + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{a + a} - \frac{b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1e153Initial program 42.1%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6497.4
Applied rewrites97.4%
if -1e153 < b < 1.1499999999999999e-93Initial program 83.5%
Applied rewrites83.5%
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
negate-sub-reverseN/A
lower--.f64N/A
lower-sqrt.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6483.5
Applied rewrites83.5%
lift-+.f64N/A
lift-/.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
Applied rewrites83.5%
if 1.1499999999999999e-93 < b Initial program 19.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6483.9
Applied rewrites83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1e+153)
(/ (- b) a)
(if (<= b 1.15e-93)
(/ (- (sqrt (fma b b (* (* a -4.0) c))) b) (+ a a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = -b / a;
} else if (b <= 1.15e-93) {
tmp = (sqrt(fma(b, b, ((a * -4.0) * c))) - b) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1e+153) tmp = Float64(Float64(-b) / a); elseif (b <= 1.15e-93) tmp = Float64(Float64(sqrt(fma(b, b, Float64(Float64(a * -4.0) * c))) - b) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1e+153], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.15e-93], N[(N[(N[Sqrt[N[(b * b + N[(N[(a * -4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot -4\right) \cdot c\right)} - b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1e153Initial program 42.1%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6497.4
Applied rewrites97.4%
if -1e153 < b < 1.1499999999999999e-93Initial program 83.5%
Applied rewrites83.5%
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
negate-sub-reverseN/A
lower--.f64N/A
lower-sqrt.f64N/A
pow2N/A
+-commutativeN/A
pow2N/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6483.5
Applied rewrites83.5%
if 1.1499999999999999e-93 < b Initial program 19.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6483.9
Applied rewrites83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1e+153)
(/ (- b) a)
(if (<= b 1.15e-93)
(/ (+ (sqrt (fma (* -4.0 a) c (* b b))) (- b)) (+ a a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+153) {
tmp = -b / a;
} else if (b <= 1.15e-93) {
tmp = (sqrt(fma((-4.0 * a), c, (b * b))) + -b) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1e+153) tmp = Float64(Float64(-b) / a); elseif (b <= 1.15e-93) tmp = Float64(Float64(sqrt(fma(Float64(-4.0 * a), c, Float64(b * b))) + Float64(-b)) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1e+153], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.15e-93], N[(N[(N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + (-b)), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)} + \left(-b\right)}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1e153Initial program 42.1%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6497.4
Applied rewrites97.4%
if -1e153 < b < 1.1499999999999999e-93Initial program 83.5%
Applied rewrites83.5%
if 1.1499999999999999e-93 < b Initial program 19.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6483.9
Applied rewrites83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4.5e-37)
(* (- b) (+ (/ (- c) (* b b)) (/ 1.0 a)))
(if (<= b 1.15e-93)
(/ (fma -0.5 b (sqrt (* (* c a) -1.0))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-37) {
tmp = -b * ((-c / (b * b)) + (1.0 / a));
} else if (b <= 1.15e-93) {
tmp = fma(-0.5, b, sqrt(((c * a) * -1.0))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-37) tmp = Float64(Float64(-b) * Float64(Float64(Float64(-c) / Float64(b * b)) + Float64(1.0 / a))); elseif (b <= 1.15e-93) tmp = Float64(fma(-0.5, b, sqrt(Float64(Float64(c * a) * -1.0))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-37], N[((-b) * N[(N[((-c) / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-93], N[(N[(-0.5 * b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-37}:\\
\;\;\;\;\left(-b\right) \cdot \left(\frac{-c}{b \cdot b} + \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.5, b, \sqrt{\left(c \cdot a\right) \cdot -1}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.5000000000000004e-37Initial program 67.6%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-+.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f64N/A
pow2N/A
lift-*.f64N/A
lower-/.f6488.7
Applied rewrites88.7%
if -4.5000000000000004e-37 < b < 1.1499999999999999e-93Initial program 78.2%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6433.5
Applied rewrites33.5%
Taylor expanded in a around -inf
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6433.5
Applied rewrites33.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6468.5
Applied rewrites68.5%
if 1.1499999999999999e-93 < b Initial program 19.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6483.9
Applied rewrites83.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4.5e-37)
(/ (- b) a)
(if (<= b 1.15e-93)
(/ (fma -0.5 b (sqrt (* (* c a) -1.0))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-37) {
tmp = -b / a;
} else if (b <= 1.15e-93) {
tmp = fma(-0.5, b, sqrt(((c * a) * -1.0))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-37) tmp = Float64(Float64(-b) / a); elseif (b <= 1.15e-93) tmp = Float64(fma(-0.5, b, sqrt(Float64(Float64(c * a) * -1.0))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-37], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.15e-93], N[(N[(-0.5 * b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-37}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.5, b, \sqrt{\left(c \cdot a\right) \cdot -1}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.5000000000000004e-37Initial program 67.6%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6488.7
Applied rewrites88.7%
if -4.5000000000000004e-37 < b < 1.1499999999999999e-93Initial program 78.2%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6433.5
Applied rewrites33.5%
Taylor expanded in a around -inf
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6433.5
Applied rewrites33.5%
Taylor expanded in a around 0
lower-/.f64N/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6468.5
Applied rewrites68.5%
if 1.1499999999999999e-93 < b Initial program 19.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6483.9
Applied rewrites83.9%
(FPCore (a b c) :precision binary64 (if (<= b -8.5e-39) (/ (- b) a) (if (<= b 1.15e-93) (/ (sqrt (* (* a -4.0) c)) (+ a a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-39) {
tmp = -b / a;
} else if (b <= 1.15e-93) {
tmp = sqrt(((a * -4.0) * c)) / (a + a);
} else {
tmp = -c / b;
}
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 <= (-8.5d-39)) then
tmp = -b / a
else if (b <= 1.15d-93) then
tmp = sqrt(((a * (-4.0d0)) * c)) / (a + a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-39) {
tmp = -b / a;
} else if (b <= 1.15e-93) {
tmp = Math.sqrt(((a * -4.0) * c)) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e-39: tmp = -b / a elif b <= 1.15e-93: tmp = math.sqrt(((a * -4.0) * c)) / (a + a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e-39) tmp = Float64(Float64(-b) / a); elseif (b <= 1.15e-93) tmp = Float64(sqrt(Float64(Float64(a * -4.0) * c)) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.5e-39) tmp = -b / a; elseif (b <= 1.15e-93) tmp = sqrt(((a * -4.0) * c)) / (a + a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e-39], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.15e-93], N[(N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c), $MachinePrecision]], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.5 \cdot 10^{-39}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot -4\right) \cdot c}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.5000000000000005e-39Initial program 67.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6488.6
Applied rewrites88.6%
if -8.5000000000000005e-39 < b < 1.1499999999999999e-93Initial program 78.1%
Applied rewrites78.1%
Taylor expanded in a around inf
sqrt-unprodN/A
*-commutativeN/A
associate-*r*N/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6466.9
Applied rewrites66.9%
if 1.1499999999999999e-93 < b Initial program 19.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6483.9
Applied rewrites83.9%
(FPCore (a b c) :precision binary64 (if (<= b -4.5e-82) (/ (- b) a) (if (<= b 1.46e-128) (/ (sqrt (- c)) (sqrt a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-82) {
tmp = -b / a;
} else if (b <= 1.46e-128) {
tmp = sqrt(-c) / sqrt(a);
} else {
tmp = -c / b;
}
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 <= (-4.5d-82)) then
tmp = -b / a
else if (b <= 1.46d-128) then
tmp = sqrt(-c) / sqrt(a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-82) {
tmp = -b / a;
} else if (b <= 1.46e-128) {
tmp = Math.sqrt(-c) / Math.sqrt(a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-82: tmp = -b / a elif b <= 1.46e-128: tmp = math.sqrt(-c) / math.sqrt(a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-82) tmp = Float64(Float64(-b) / a); elseif (b <= 1.46e-128) tmp = Float64(sqrt(Float64(-c)) / sqrt(a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.5e-82) tmp = -b / a; elseif (b <= 1.46e-128) tmp = sqrt(-c) / sqrt(a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-82], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.46e-128], N[(N[Sqrt[(-c)], $MachinePrecision] / N[Sqrt[a], $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-82}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.46 \cdot 10^{-128}:\\
\;\;\;\;\frac{\sqrt{-c}}{\sqrt{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.4999999999999998e-82Initial program 69.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6484.7
Applied rewrites84.7%
if -4.4999999999999998e-82 < b < 1.46e-128Initial program 77.7%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6435.2
Applied rewrites35.2%
Taylor expanded in a around -inf
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6435.3
Applied rewrites35.3%
Taylor expanded in a around -inf
sqrt-prodN/A
*-commutativeN/A
lower-sqrt.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6434.4
Applied rewrites34.4%
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6443.8
Applied rewrites43.8%
if 1.46e-128 < b Initial program 21.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6481.6
Applied rewrites81.6%
(FPCore (a b c) :precision binary64 (if (<= b -1.75e-172) (/ (- b) a) (if (<= b 2.6e-144) (sqrt (/ (- c) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-172) {
tmp = -b / a;
} else if (b <= 2.6e-144) {
tmp = sqrt((-c / a));
} else {
tmp = -c / b;
}
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.75d-172)) then
tmp = -b / a
else if (b <= 2.6d-144) then
tmp = sqrt((-c / a))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.75e-172) {
tmp = -b / a;
} else if (b <= 2.6e-144) {
tmp = Math.sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.75e-172: tmp = -b / a elif b <= 2.6e-144: tmp = math.sqrt((-c / a)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.75e-172) tmp = Float64(Float64(-b) / a); elseif (b <= 2.6e-144) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.75e-172) tmp = -b / a; elseif (b <= 2.6e-144) tmp = sqrt((-c / a)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.75e-172], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.6e-144], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.75 \cdot 10^{-172}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-144}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.75000000000000014e-172Initial program 72.6%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6477.8
Applied rewrites77.8%
if -1.75000000000000014e-172 < b < 2.6000000000000001e-144Initial program 74.4%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6437.8
Applied rewrites37.8%
Taylor expanded in a around -inf
*-commutativeN/A
lower-fma.f64N/A
lift-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lift-/.f6437.8
Applied rewrites37.8%
Taylor expanded in a around -inf
sqrt-prodN/A
*-commutativeN/A
lower-sqrt.f64N/A
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6437.5
Applied rewrites37.5%
if 2.6000000000000001e-144 < b Initial program 22.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6480.2
Applied rewrites80.2%
(FPCore (a b c) :precision binary64 (if (<= b 2.5e-281) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.5e-281) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 <= 2.5d-281) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.5e-281) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.5e-281: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.5e-281) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.5e-281) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.5e-281], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.5 \cdot 10^{-281}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 2.4999999999999999e-281Initial program 72.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6465.2
Applied rewrites65.2%
if 2.4999999999999999e-281 < b Initial program 31.3%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6469.4
Applied rewrites69.4%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / 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 / a
end function
public static double code(double a, double b, double c) {
return -b / a;
}
def code(a, b, c): return -b / a
function code(a, b, c) return Float64(Float64(-b) / a) end
function tmp = code(a, b, c) tmp = -b / a; end
code[a_, b_, c_] := N[((-b) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b}{a}
\end{array}
Initial program 52.6%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lift-neg.f64N/A
lower-/.f6434.8
Applied rewrites34.8%
herbie shell --seed 2025110
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))