
(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 11 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 -9e-91)
(- (/ c b))
(if (<= b 1.5e+86)
(- (/ (- b) (+ a a)) (/ (sqrt (fma (* -4.0 a) c (* b b))) (* 2.0 a)))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-91) {
tmp = -(c / b);
} else if (b <= 1.5e+86) {
tmp = (-b / (a + a)) - (sqrt(fma((-4.0 * a), c, (b * b))) / (2.0 * a));
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9e-91) tmp = Float64(-Float64(c / b)); elseif (b <= 1.5e+86) tmp = Float64(Float64(Float64(-b) / Float64(a + a)) - Float64(sqrt(fma(Float64(-4.0 * a), c, Float64(b * b))) / Float64(2.0 * a))); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9e-91], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.5e+86], N[(N[((-b) / N[(a + a), $MachinePrecision]), $MachinePrecision] - N[(N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-91}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+86}:\\
\;\;\;\;\frac{-b}{a + a} - \frac{\sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.99999999999999952e-91Initial program 19.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
if -8.99999999999999952e-91 < b < 1.49999999999999988e86Initial program 80.2%
lift-*.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites80.2%
lift-*.f64N/A
count-2-revN/A
lower-+.f6480.2
Applied rewrites80.2%
if 1.49999999999999988e86 < b Initial program 55.2%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6495.5
Applied rewrites95.5%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-91)
(- (/ c b))
(if (<= b 1.5e+86)
(/ (- (- b) (sqrt (fma (* c a) -4.0 (* b b)))) (+ a a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-91) {
tmp = -(c / b);
} else if (b <= 1.5e+86) {
tmp = (-b - sqrt(fma((c * a), -4.0, (b * b)))) / (a + a);
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9e-91) tmp = Float64(-Float64(c / b)); elseif (b <= 1.5e+86) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(c * a), -4.0, Float64(b * b)))) / Float64(a + a)); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9e-91], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.5e+86], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0 + 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 -9 \cdot 10^{-91}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{+86}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -8.99999999999999952e-91Initial program 19.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
if -8.99999999999999952e-91 < b < 1.49999999999999988e86Initial program 80.2%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6480.2
Applied rewrites80.2%
lift-*.f64N/A
count-2-revN/A
lower-+.f6480.2
Applied rewrites80.2%
if 1.49999999999999988e86 < b Initial program 55.2%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6495.5
Applied rewrites95.5%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-91)
(- (/ c b))
(if (<= b 4.6e-41)
(/ (- (- b) (sqrt (* (* a c) -4.0))) (+ a a))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-91) {
tmp = -(c / b);
} else if (b <= 4.6e-41) {
tmp = (-b - sqrt(((a * c) * -4.0))) / (a + a);
} else {
tmp = (-b / a) + (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 <= (-9d-91)) then
tmp = -(c / b)
else if (b <= 4.6d-41) then
tmp = (-b - sqrt(((a * c) * (-4.0d0)))) / (a + a)
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-91) {
tmp = -(c / b);
} else if (b <= 4.6e-41) {
tmp = (-b - Math.sqrt(((a * c) * -4.0))) / (a + a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-91: tmp = -(c / b) elif b <= 4.6e-41: tmp = (-b - math.sqrt(((a * c) * -4.0))) / (a + a) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-91) tmp = Float64(-Float64(c / b)); elseif (b <= 4.6e-41) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(a * c) * -4.0))) / Float64(a + a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-91) tmp = -(c / b); elseif (b <= 4.6e-41) tmp = (-b - sqrt(((a * c) * -4.0))) / (a + a); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-91], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 4.6e-41], N[(N[((-b) - N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-91}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 4.6 \cdot 10^{-41}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\left(a \cdot c\right) \cdot -4}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -8.99999999999999952e-91Initial program 19.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
if -8.99999999999999952e-91 < b < 4.6000000000000002e-41Initial program 76.2%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6476.2
Applied rewrites76.2%
lift-*.f64N/A
count-2-revN/A
lower-+.f6476.2
Applied rewrites76.2%
Taylor expanded in a around inf
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6466.3
Applied rewrites66.3%
if 4.6000000000000002e-41 < b Initial program 67.0%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6488.3
Applied rewrites88.3%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6488.3
Applied rewrites88.3%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-91)
(- (/ c b))
(if (<= b 1e-63)
(/ (- (sqrt (* -4.0 (* c a)))) (+ a a))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-91) {
tmp = -(c / b);
} else if (b <= 1e-63) {
tmp = -sqrt((-4.0 * (c * a))) / (a + a);
} else {
tmp = (-b / a) + (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 <= (-9d-91)) then
tmp = -(c / b)
else if (b <= 1d-63) then
tmp = -sqrt(((-4.0d0) * (c * a))) / (a + a)
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-91) {
tmp = -(c / b);
} else if (b <= 1e-63) {
tmp = -Math.sqrt((-4.0 * (c * a))) / (a + a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-91: tmp = -(c / b) elif b <= 1e-63: tmp = -math.sqrt((-4.0 * (c * a))) / (a + a) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-91) tmp = Float64(-Float64(c / b)); elseif (b <= 1e-63) tmp = Float64(Float64(-sqrt(Float64(-4.0 * Float64(c * a)))) / Float64(a + a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-91) tmp = -(c / b); elseif (b <= 1e-63) tmp = -sqrt((-4.0 * (c * a))) / (a + a); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-91], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1e-63], N[((-N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-91}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 10^{-63}:\\
\;\;\;\;\frac{-\sqrt{-4 \cdot \left(c \cdot a\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -8.99999999999999952e-91Initial program 19.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
if -8.99999999999999952e-91 < b < 1.00000000000000007e-63Initial program 75.2%
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-*.f6466.4
Applied rewrites66.4%
lift-*.f64N/A
count-2-revN/A
lower-+.f6466.4
Applied rewrites66.4%
if 1.00000000000000007e-63 < b Initial program 68.3%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6486.3
Applied rewrites86.3%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6486.3
Applied rewrites86.3%
(FPCore (a b c) :precision binary64 (if (<= b -5.7e-101) (- (/ c b)) (if (<= b 6.5e-199) (- (/ (sqrt (- c)) (sqrt a))) (+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.7e-101) {
tmp = -(c / b);
} else if (b <= 6.5e-199) {
tmp = -(sqrt(-c) / sqrt(a));
} else {
tmp = (-b / a) + (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 <= (-5.7d-101)) then
tmp = -(c / b)
else if (b <= 6.5d-199) then
tmp = -(sqrt(-c) / sqrt(a))
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.7e-101) {
tmp = -(c / b);
} else if (b <= 6.5e-199) {
tmp = -(Math.sqrt(-c) / Math.sqrt(a));
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.7e-101: tmp = -(c / b) elif b <= 6.5e-199: tmp = -(math.sqrt(-c) / math.sqrt(a)) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.7e-101) tmp = Float64(-Float64(c / b)); elseif (b <= 6.5e-199) tmp = Float64(-Float64(sqrt(Float64(-c)) / sqrt(a))); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.7e-101) tmp = -(c / b); elseif (b <= 6.5e-199) tmp = -(sqrt(-c) / sqrt(a)); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.7e-101], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 6.5e-199], (-N[(N[Sqrt[(-c)], $MachinePrecision] / N[Sqrt[a], $MachinePrecision]), $MachinePrecision]), N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.7 \cdot 10^{-101}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-199}:\\
\;\;\;\;-\frac{\sqrt{-c}}{\sqrt{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -5.69999999999999983e-101Initial program 20.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6483.6
Applied rewrites83.6%
if -5.69999999999999983e-101 < b < 6.50000000000000017e-199Initial program 70.9%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6432.5
Applied rewrites32.5%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6435.7
Applied rewrites35.7%
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.f6445.1
Applied rewrites45.1%
if 6.50000000000000017e-199 < b Initial program 71.8%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6475.8
Applied rewrites75.8%
(FPCore (a b c) :precision binary64 (if (<= b -6.3e-145) (- (/ c b)) (if (<= b 1.5e-253) (- (sqrt (/ (- c) a))) (+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.3e-145) {
tmp = -(c / b);
} else if (b <= 1.5e-253) {
tmp = -sqrt((-c / a));
} else {
tmp = (-b / a) + (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 <= (-6.3d-145)) then
tmp = -(c / b)
else if (b <= 1.5d-253) then
tmp = -sqrt((-c / a))
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.3e-145) {
tmp = -(c / b);
} else if (b <= 1.5e-253) {
tmp = -Math.sqrt((-c / a));
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.3e-145: tmp = -(c / b) elif b <= 1.5e-253: tmp = -math.sqrt((-c / a)) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.3e-145) tmp = Float64(-Float64(c / b)); elseif (b <= 1.5e-253) tmp = Float64(-sqrt(Float64(Float64(-c) / a))); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.3e-145) tmp = -(c / b); elseif (b <= 1.5e-253) tmp = -sqrt((-c / a)); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.3e-145], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.5e-253], (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]), N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.3 \cdot 10^{-145}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-253}:\\
\;\;\;\;-\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -6.3000000000000001e-145Initial program 22.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
if -6.3000000000000001e-145 < b < 1.5000000000000001e-253Initial program 71.9%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6433.7
Applied rewrites33.7%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6437.1
Applied rewrites37.1%
if 1.5000000000000001e-253 < b Initial program 72.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6471.6
Applied rewrites71.6%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6471.6
Applied rewrites71.6%
(FPCore (a b c) :precision binary64 (if (<= b -6.3e-145) (- (/ c b)) (if (<= b 3.4e-211) (- (sqrt (/ (- c) a))) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.3e-145) {
tmp = -(c / b);
} else if (b <= 3.4e-211) {
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 <= (-6.3d-145)) then
tmp = -(c / b)
else if (b <= 3.4d-211) 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 <= -6.3e-145) {
tmp = -(c / b);
} else if (b <= 3.4e-211) {
tmp = -Math.sqrt((-c / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.3e-145: tmp = -(c / b) elif b <= 3.4e-211: tmp = -math.sqrt((-c / a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.3e-145) tmp = Float64(-Float64(c / b)); elseif (b <= 3.4e-211) tmp = Float64(-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 <= -6.3e-145) tmp = -(c / b); elseif (b <= 3.4e-211) tmp = -sqrt((-c / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.3e-145], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 3.4e-211], (-N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]), N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.3 \cdot 10^{-145}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-211}:\\
\;\;\;\;-\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.3000000000000001e-145Initial program 22.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6480.5
Applied rewrites80.5%
if -6.3000000000000001e-145 < b < 3.4000000000000001e-211Initial program 72.8%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6434.0
Applied rewrites34.0%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6437.3
Applied rewrites37.3%
if 3.4000000000000001e-211 < b Initial program 71.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6474.5
Applied rewrites74.5%
(FPCore (a b c) :precision binary64 (if (<= b -1.35e-143) (- (/ c b)) (if (<= b 2.5e-234) (sqrt (/ (- c) a)) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-143) {
tmp = -(c / b);
} else if (b <= 2.5e-234) {
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 <= (-1.35d-143)) then
tmp = -(c / b)
else if (b <= 2.5d-234) 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 <= -1.35e-143) {
tmp = -(c / b);
} else if (b <= 2.5e-234) {
tmp = Math.sqrt((-c / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e-143: tmp = -(c / b) elif b <= 2.5e-234: tmp = math.sqrt((-c / a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e-143) tmp = Float64(-Float64(c / b)); elseif (b <= 2.5e-234) 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 <= -1.35e-143) tmp = -(c / b); elseif (b <= 2.5e-234) tmp = sqrt((-c / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e-143], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 2.5e-234], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{-143}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-234}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.35000000000000005e-143Initial program 22.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6480.7
Applied rewrites80.7%
if -1.35000000000000005e-143 < b < 2.49999999999999989e-234Initial program 72.5%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6434.0
Applied rewrites34.0%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6434.0
Applied rewrites34.0%
if 2.49999999999999989e-234 < b Initial program 71.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6472.9
Applied rewrites72.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-309) (- (/ c b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-309) {
tmp = -(c / b);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-309: tmp = -(c / b) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-309) tmp = -(c / b); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-309], (-N[(c / b), $MachinePrecision]), N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-309}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.9999999999999977e-309Initial program 31.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6468.0
Applied rewrites68.0%
if -3.9999999999999977e-309 < b Initial program 72.4%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6467.3
Applied rewrites67.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 51.6%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6435.9
Applied rewrites35.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 51.6%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6434.2
Applied rewrites34.2%
Taylor expanded in a around inf
lift-/.f6411.4
Applied rewrites11.4%
(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 2025096
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (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)))