
(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 -1.9e+23)
(fma (/ b a) -1.0 (/ c b))
(if (<= b 1.02e-153)
(+ (/ (- b) (+ a a)) (/ (sqrt (fma (* a -4.0) c (* b b))) (* 2.0 a)))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e+23) {
tmp = fma((b / a), -1.0, (c / b));
} else if (b <= 1.02e-153) {
tmp = (-b / (a + a)) + (sqrt(fma((a * -4.0), c, (b * b))) / (2.0 * a));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.9e+23) tmp = fma(Float64(b / a), -1.0, Float64(c / b)); elseif (b <= 1.02e-153) tmp = Float64(Float64(Float64(-b) / Float64(a + a)) + Float64(sqrt(fma(Float64(a * -4.0), c, Float64(b * b))) / Float64(2.0 * a))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.9e+23], N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.02e-153], N[(N[((-b) / N[(a + a), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{+23}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-153}:\\
\;\;\;\;\frac{-b}{a + a} + \frac{\sqrt{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.89999999999999987e23Initial program 64.5%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6492.2
Applied rewrites92.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6492.5
Applied rewrites92.5%
if -1.89999999999999987e23 < b < 1.02e-153Initial program 80.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
associate-*r*N/A
fp-cancel-sub-sign-invN/A
pow2N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6480.4
Applied rewrites80.4%
lift-*.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-addN/A
lower-+.f64N/A
lower-/.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites80.5%
lift-*.f64N/A
count-2-revN/A
lift-+.f6480.5
Applied rewrites80.5%
if 1.02e-153 < b Initial program 22.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6478.8
Applied rewrites78.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.9e+23)
(fma (/ b a) -1.0 (/ c b))
(if (<= b 1.02e-153)
(/ (+ (- b) (sqrt (fma b b (* -4.0 (* c a))))) (+ a a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e+23) {
tmp = fma((b / a), -1.0, (c / b));
} else if (b <= 1.02e-153) {
tmp = (-b + sqrt(fma(b, b, (-4.0 * (c * a))))) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.9e+23) tmp = fma(Float64(b / a), -1.0, Float64(c / b)); elseif (b <= 1.02e-153) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(-4.0 * Float64(c * a))))) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.9e+23], N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.02e-153], N[(N[((-b) + N[Sqrt[N[(b * b + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{+23}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-153}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.89999999999999987e23Initial program 64.5%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6492.2
Applied rewrites92.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6492.5
Applied rewrites92.5%
if -1.89999999999999987e23 < b < 1.02e-153Initial program 80.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
associate-*r*N/A
fp-cancel-sub-sign-invN/A
pow2N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6480.4
Applied rewrites80.4%
lift-*.f64N/A
count-2-revN/A
lower-+.f6480.4
Applied rewrites80.4%
if 1.02e-153 < b Initial program 22.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6478.8
Applied rewrites78.8%
(FPCore (a b c) :precision binary64 (if (<= b -75.0) (fma (/ b a) -1.0 (/ c b)) (if (<= b 1.02e-153) (/ (sqrt (* (* a c) -4.0)) (+ a a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -75.0) {
tmp = fma((b / a), -1.0, (c / b));
} else if (b <= 1.02e-153) {
tmp = sqrt(((a * c) * -4.0)) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -75.0) tmp = fma(Float64(b / a), -1.0, Float64(c / b)); elseif (b <= 1.02e-153) tmp = Float64(sqrt(Float64(Float64(a * c) * -4.0)) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -75.0], N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.02e-153], N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -75:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-153}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot c\right) \cdot -4}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -75Initial program 65.9%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6491.3
Applied rewrites91.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6491.6
Applied rewrites91.6%
if -75 < b < 1.02e-153Initial program 79.8%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
associate-*r*N/A
fp-cancel-sub-sign-invN/A
pow2N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6479.8
Applied rewrites79.8%
lift-*.f64N/A
count-2-revN/A
lower-+.f6479.8
Applied rewrites79.8%
Taylor expanded in a around inf
sqrt-unprodN/A
*-commutativeN/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6462.5
Applied rewrites62.5%
if 1.02e-153 < b Initial program 22.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6478.8
Applied rewrites78.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.9e-10)
(fma (/ b a) -1.0 (/ c b))
(if (<= b -1.4e-169)
(/ (sqrt (- c)) (sqrt a))
(if (<= b 3.8e-188) (- (sqrt (/ (- c) a))) (/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-10) {
tmp = fma((b / a), -1.0, (c / b));
} else if (b <= -1.4e-169) {
tmp = sqrt(-c) / sqrt(a);
} else if (b <= 3.8e-188) {
tmp = -sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.9e-10) tmp = fma(Float64(b / a), -1.0, Float64(c / b)); elseif (b <= -1.4e-169) tmp = Float64(sqrt(Float64(-c)) / sqrt(a)); elseif (b <= 3.8e-188) tmp = Float64(-sqrt(Float64(Float64(-c) / a))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.9e-10], N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.4e-169], N[(N[Sqrt[(-c)], $MachinePrecision] / N[Sqrt[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e-188], (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]), N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq -1.4 \cdot 10^{-169}:\\
\;\;\;\;\frac{\sqrt{-c}}{\sqrt{a}}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-188}:\\
\;\;\;\;-\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.8999999999999999e-10Initial program 66.4%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6490.5
Applied rewrites90.5%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6490.9
Applied rewrites90.9%
if -1.8999999999999999e-10 < b < -1.39999999999999994e-169Initial program 88.4%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6422.7
Applied rewrites22.7%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6422.7
Applied rewrites22.7%
Taylor expanded in c around -inf
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-sqrt.f6421.2
Applied rewrites21.2%
lift-sqrt.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
sqrt-divN/A
lower-/.f64N/A
lower-sqrt.f64N/A
lift-neg.f64N/A
lower-sqrt.f6428.3
Applied rewrites28.3%
if -1.39999999999999994e-169 < b < 3.8e-188Initial program 75.2%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6438.3
Applied rewrites38.3%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6438.3
Applied rewrites38.3%
if 3.8e-188 < b Initial program 24.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6476.2
Applied rewrites76.2%
(FPCore (a b c) :precision binary64 (if (<= b -3.9e-83) (fma (/ b a) -1.0 (/ c b)) (if (<= b 3.8e-188) (- (sqrt (/ (- c) a))) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.9e-83) {
tmp = fma((b / a), -1.0, (c / b));
} else if (b <= 3.8e-188) {
tmp = -sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -3.9e-83) tmp = fma(Float64(b / a), -1.0, Float64(c / b)); elseif (b <= 3.8e-188) tmp = Float64(-sqrt(Float64(Float64(-c) / a))); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -3.9e-83], N[(N[(b / a), $MachinePrecision] * -1.0 + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e-188], (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]), N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.9 \cdot 10^{-83}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -1, \frac{c}{b}\right)\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-188}:\\
\;\;\;\;-\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.9e-83Initial program 69.7%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6485.3
Applied rewrites85.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6485.6
Applied rewrites85.6%
if -3.9e-83 < b < 3.8e-188Initial program 78.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6434.5
Applied rewrites34.5%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6434.5
Applied rewrites34.5%
if 3.8e-188 < b Initial program 24.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6476.2
Applied rewrites76.2%
(FPCore (a b c) :precision binary64 (if (<= b -3.9e-83) (/ (- b) a) (if (<= b 3.8e-188) (- (sqrt (/ (- c) a))) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.9e-83) {
tmp = -b / a;
} else if (b <= 3.8e-188) {
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 <= (-3.9d-83)) then
tmp = -b / a
else if (b <= 3.8d-188) 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 <= -3.9e-83) {
tmp = -b / a;
} else if (b <= 3.8e-188) {
tmp = -Math.sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.9e-83: tmp = -b / a elif b <= 3.8e-188: tmp = -math.sqrt((-c / a)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.9e-83) tmp = Float64(Float64(-b) / a); elseif (b <= 3.8e-188) tmp = Float64(-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 <= -3.9e-83) tmp = -b / a; elseif (b <= 3.8e-188) tmp = -sqrt((-c / a)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.9e-83], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.8e-188], (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]), N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.9 \cdot 10^{-83}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-188}:\\
\;\;\;\;-\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.9e-83Initial program 69.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6485.3
Applied rewrites85.3%
if -3.9e-83 < b < 3.8e-188Initial program 78.8%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6434.5
Applied rewrites34.5%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6434.5
Applied rewrites34.5%
if 3.8e-188 < b Initial program 24.7%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6476.2
Applied rewrites76.2%
(FPCore (a b c) :precision binary64 (if (<= b -3.6e-120) (/ (- b) a) (if (<= b 2.7e-207) (sqrt (/ (- c) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-120) {
tmp = -b / a;
} else if (b <= 2.7e-207) {
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 <= (-3.6d-120)) then
tmp = -b / a
else if (b <= 2.7d-207) 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 <= -3.6e-120) {
tmp = -b / a;
} else if (b <= 2.7e-207) {
tmp = Math.sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-120: tmp = -b / a elif b <= 2.7e-207: tmp = math.sqrt((-c / a)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-120) tmp = Float64(Float64(-b) / a); elseif (b <= 2.7e-207) 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 <= -3.6e-120) tmp = -b / a; elseif (b <= 2.7e-207) tmp = sqrt((-c / a)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-120], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.7e-207], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{-120}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.7 \cdot 10^{-207}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.6000000000000003e-120Initial program 71.1%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6481.9
Applied rewrites81.9%
if -3.6000000000000003e-120 < b < 2.7e-207Initial program 77.3%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6436.4
Applied rewrites36.4%
Taylor expanded in c around -inf
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6437.0
Applied rewrites37.0%
if 2.7e-207 < b Initial program 25.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6474.7
Applied rewrites74.7%
(FPCore (a b c) :precision binary64 (if (<= b 1.3e-280) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.3e-280) {
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 <= 1.3d-280) 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 <= 1.3e-280) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.3e-280: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.3e-280) 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 <= 1.3e-280) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.3e-280], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.3 \cdot 10^{-280}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.3e-280Initial program 72.6%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6466.1
Applied rewrites66.1%
if 1.3e-280 < b Initial program 30.2%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6469.0
Applied rewrites69.0%
(FPCore (a b c) :precision binary64 (if (<= b 3500000.0) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3500000.0) {
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 <= 3500000.0d0) 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 <= 3500000.0) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3500000.0: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3500000.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3500000.0) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3500000.0], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3500000:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.5e6Initial program 68.5%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6449.4
Applied rewrites49.4%
if 3.5e6 < b Initial program 13.1%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f642.5
Applied rewrites2.5%
Taylor expanded in a around inf
lower-/.f6428.1
Applied rewrites28.1%
(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.2%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lift-neg.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6434.8
Applied rewrites34.8%
Taylor expanded in a around inf
lower-/.f6410.4
Applied rewrites10.4%
herbie shell --seed 2025103
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))