
(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 9 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 -7.2e-10)
(- (/ c b))
(if (<= b 3.45e+40)
(- (* (/ b a) -0.5) (/ (sqrt (fma (* c -4.0) a (* b b))) (* 2.0 a)))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.2e-10) {
tmp = -(c / b);
} else if (b <= 3.45e+40) {
tmp = ((b / a) * -0.5) - (sqrt(fma((c * -4.0), a, (b * b))) / (2.0 * a));
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -7.2e-10) tmp = Float64(-Float64(c / b)); elseif (b <= 3.45e+40) tmp = Float64(Float64(Float64(b / a) * -0.5) - Float64(sqrt(fma(Float64(c * -4.0), a, Float64(b * b))) / Float64(2.0 * a))); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-10], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 3.45e+40], N[(N[(N[(b / a), $MachinePrecision] * -0.5), $MachinePrecision] - N[(N[Sqrt[N[(N[(c * -4.0), $MachinePrecision] * a + 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 -7.2 \cdot 10^{-10}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.45 \cdot 10^{+40}:\\
\;\;\;\;\frac{b}{a} \cdot -0.5 - \frac{\sqrt{\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.2e-10Initial program 14.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
if -7.2e-10 < b < 3.4500000000000001e40Initial program 72.9%
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
associate-/r*N/A
lower-/.f64N/A
Applied rewrites73.0%
Applied rewrites73.0%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6473.0
Applied rewrites73.0%
if 3.4500000000000001e40 < b Initial program 60.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6493.4
Applied rewrites93.4%
(FPCore (a b c)
:precision binary64
(if (<= b -7.2e-10)
(- (/ c b))
(if (<= b 3.45e+40)
(/ (/ (- (- b) (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 <= -7.2e-10) {
tmp = -(c / b);
} else if (b <= 3.45e+40) {
tmp = ((-b - 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 <= -7.2e-10) tmp = Float64(-Float64(c / b)); elseif (b <= 3.45e+40) tmp = Float64(Float64(Float64(Float64(-b) - sqrt(fma(Float64(-4.0 * a), c, Float64(b * b)))) / 2.0) / a); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -7.2e-10], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 3.45e+40], N[(N[(N[((-b) - N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision] / a), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.2 \cdot 10^{-10}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 3.45 \cdot 10^{+40}:\\
\;\;\;\;\frac{\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)}}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -7.2e-10Initial program 14.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.3
Applied rewrites90.3%
if -7.2e-10 < b < 3.4500000000000001e40Initial program 72.9%
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
associate-/r*N/A
lower-/.f64N/A
Applied rewrites73.0%
if 3.4500000000000001e40 < b Initial program 60.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6493.4
Applied rewrites93.4%
(FPCore (a b c) :precision binary64 (if (<= b -3.8e-42) (- (/ c b)) (if (<= b 7e-54) (/ (* -0.5 (+ b (sqrt (* (* a -4.0) c)))) a) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-42) {
tmp = -(c / b);
} else if (b <= 7e-54) {
tmp = (-0.5 * (b + sqrt(((a * -4.0) * 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 <= (-3.8d-42)) then
tmp = -(c / b)
else if (b <= 7d-54) then
tmp = ((-0.5d0) * (b + sqrt(((a * (-4.0d0)) * 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 <= -3.8e-42) {
tmp = -(c / b);
} else if (b <= 7e-54) {
tmp = (-0.5 * (b + Math.sqrt(((a * -4.0) * c)))) / a;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-42: tmp = -(c / b) elif b <= 7e-54: tmp = (-0.5 * (b + math.sqrt(((a * -4.0) * c)))) / a else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-42) tmp = Float64(-Float64(c / b)); elseif (b <= 7e-54) tmp = Float64(Float64(-0.5 * Float64(b + sqrt(Float64(Float64(a * -4.0) * c)))) / a); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.8e-42) tmp = -(c / b); elseif (b <= 7e-54) tmp = (-0.5 * (b + sqrt(((a * -4.0) * c)))) / a; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-42], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 7e-54], N[(N[(-0.5 * N[(b + N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.8 \cdot 10^{-42}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-54}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b + \sqrt{\left(a \cdot -4\right) \cdot c}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.80000000000000017e-42Initial program 16.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.0
Applied rewrites88.0%
if -3.80000000000000017e-42 < b < 6.99999999999999964e-54Initial program 71.3%
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
associate-/r*N/A
lower-/.f64N/A
Applied rewrites71.3%
Taylor expanded in b around 0
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
sqrt-unprodN/A
*-commutativeN/A
lower-sqrt.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6464.4
Applied rewrites64.4%
if 6.99999999999999964e-54 < b Initial program 67.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6487.7
Applied rewrites87.7%
(FPCore (a b c) :precision binary64 (if (<= b -3.3e-42) (- (/ c b)) (if (<= b 7e-54) (/ (* (sqrt (* (* a -4.0) c)) -0.5) a) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.3e-42) {
tmp = -(c / b);
} else if (b <= 7e-54) {
tmp = (sqrt(((a * -4.0) * c)) * -0.5) / 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 <= (-3.3d-42)) then
tmp = -(c / b)
else if (b <= 7d-54) then
tmp = (sqrt(((a * (-4.0d0)) * c)) * (-0.5d0)) / 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 <= -3.3e-42) {
tmp = -(c / b);
} else if (b <= 7e-54) {
tmp = (Math.sqrt(((a * -4.0) * c)) * -0.5) / a;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.3e-42: tmp = -(c / b) elif b <= 7e-54: tmp = (math.sqrt(((a * -4.0) * c)) * -0.5) / a else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.3e-42) tmp = Float64(-Float64(c / b)); elseif (b <= 7e-54) tmp = Float64(Float64(sqrt(Float64(Float64(a * -4.0) * c)) * -0.5) / a); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.3e-42) tmp = -(c / b); elseif (b <= 7e-54) tmp = (sqrt(((a * -4.0) * c)) * -0.5) / a; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.3e-42], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 7e-54], N[(N[(N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c), $MachinePrecision]], $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.3 \cdot 10^{-42}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-54}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot -4\right) \cdot c} \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.3000000000000002e-42Initial program 16.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.0
Applied rewrites88.0%
if -3.3000000000000002e-42 < b < 6.99999999999999964e-54Initial program 71.3%
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
associate-/r*N/A
lower-/.f64N/A
Applied rewrites71.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
sqrt-unprodN/A
*-commutativeN/A
lower-sqrt.f64N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6463.2
Applied rewrites63.2%
if 6.99999999999999964e-54 < b Initial program 67.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6487.7
Applied rewrites87.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (/ c a)))))
(if (<= b -2.2e-50)
(- (/ c b))
(if (<= b -4.8e-234)
(fma (/ b a) -0.5 t_0)
(if (<= b 9.4e-91) (- t_0) (/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(-(c / a));
double tmp;
if (b <= -2.2e-50) {
tmp = -(c / b);
} else if (b <= -4.8e-234) {
tmp = fma((b / a), -0.5, t_0);
} else if (b <= 9.4e-91) {
tmp = -t_0;
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) t_0 = sqrt(Float64(-Float64(c / a))) tmp = 0.0 if (b <= -2.2e-50) tmp = Float64(-Float64(c / b)); elseif (b <= -4.8e-234) tmp = fma(Float64(b / a), -0.5, t_0); elseif (b <= 9.4e-91) tmp = Float64(-t_0); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision]}, If[LessEqual[b, -2.2e-50], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, -4.8e-234], N[(N[(b / a), $MachinePrecision] * -0.5 + t$95$0), $MachinePrecision], If[LessEqual[b, 9.4e-91], (-t$95$0), N[((-b) / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{-\frac{c}{a}}\\
\mathbf{if}\;b \leq -2.2 \cdot 10^{-50}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -4.8 \cdot 10^{-234}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{a}, -0.5, t\_0\right)\\
\mathbf{elif}\;b \leq 9.4 \cdot 10^{-91}:\\
\;\;\;\;-t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.1999999999999999e-50Initial program 16.6%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6487.5
Applied rewrites87.5%
if -2.1999999999999999e-50 < b < -4.7999999999999998e-234Initial program 60.6%
Taylor expanded in a around -inf
lower-fma.f64N/A
lower-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6426.7
Applied rewrites26.7%
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
sqrt-prodN/A
lower-fma.f64N/A
lift-/.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6426.7
Applied rewrites26.7%
if -4.7999999999999998e-234 < b < 9.40000000000000013e-91Initial program 77.1%
Taylor expanded in a around -inf
lower-fma.f64N/A
lower-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6434.3
Applied rewrites34.3%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6435.0
Applied rewrites35.0%
if 9.40000000000000013e-91 < b Initial program 69.0%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6484.6
Applied rewrites84.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (/ c a)))))
(if (<= b -2.2e-50)
(- (/ c b))
(if (<= b -4.8e-234) t_0 (if (<= b 9.4e-91) (- t_0) (/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(-(c / a));
double tmp;
if (b <= -2.2e-50) {
tmp = -(c / b);
} else if (b <= -4.8e-234) {
tmp = t_0;
} else if (b <= 9.4e-91) {
tmp = -t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = sqrt(-(c / a))
if (b <= (-2.2d-50)) then
tmp = -(c / b)
else if (b <= (-4.8d-234)) then
tmp = t_0
else if (b <= 9.4d-91) then
tmp = -t_0
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(-(c / a));
double tmp;
if (b <= -2.2e-50) {
tmp = -(c / b);
} else if (b <= -4.8e-234) {
tmp = t_0;
} else if (b <= 9.4e-91) {
tmp = -t_0;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(-(c / a)) tmp = 0 if b <= -2.2e-50: tmp = -(c / b) elif b <= -4.8e-234: tmp = t_0 elif b <= 9.4e-91: tmp = -t_0 else: tmp = -b / a return tmp
function code(a, b, c) t_0 = sqrt(Float64(-Float64(c / a))) tmp = 0.0 if (b <= -2.2e-50) tmp = Float64(-Float64(c / b)); elseif (b <= -4.8e-234) tmp = t_0; elseif (b <= 9.4e-91) tmp = Float64(-t_0); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(-(c / a)); tmp = 0.0; if (b <= -2.2e-50) tmp = -(c / b); elseif (b <= -4.8e-234) tmp = t_0; elseif (b <= 9.4e-91) tmp = -t_0; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision]}, If[LessEqual[b, -2.2e-50], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, -4.8e-234], t$95$0, If[LessEqual[b, 9.4e-91], (-t$95$0), N[((-b) / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{-\frac{c}{a}}\\
\mathbf{if}\;b \leq -2.2 \cdot 10^{-50}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq -4.8 \cdot 10^{-234}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 9.4 \cdot 10^{-91}:\\
\;\;\;\;-t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.1999999999999999e-50Initial program 16.6%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6487.5
Applied rewrites87.5%
if -2.1999999999999999e-50 < b < -4.7999999999999998e-234Initial program 60.6%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6426.8
Applied rewrites26.8%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6426.8
Applied rewrites26.8%
if -4.7999999999999998e-234 < b < 9.40000000000000013e-91Initial program 77.1%
Taylor expanded in a around -inf
lower-fma.f64N/A
lower-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6434.3
Applied rewrites34.3%
Taylor expanded in c around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6435.0
Applied rewrites35.0%
if 9.40000000000000013e-91 < b Initial program 69.0%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6484.6
Applied rewrites84.6%
(FPCore (a b c) :precision binary64 (if (<= b -2.2e-50) (- (/ c b)) (if (<= b 1.02e-176) (sqrt (- (/ c a))) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e-50) {
tmp = -(c / b);
} else if (b <= 1.02e-176) {
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 <= (-2.2d-50)) then
tmp = -(c / b)
else if (b <= 1.02d-176) 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 <= -2.2e-50) {
tmp = -(c / b);
} else if (b <= 1.02e-176) {
tmp = Math.sqrt(-(c / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e-50: tmp = -(c / b) elif b <= 1.02e-176: tmp = math.sqrt(-(c / a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e-50) tmp = Float64(-Float64(c / b)); elseif (b <= 1.02e-176) 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 <= -2.2e-50) tmp = -(c / b); elseif (b <= 1.02e-176) tmp = sqrt(-(c / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e-50], (-N[(c / b), $MachinePrecision]), If[LessEqual[b, 1.02e-176], N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.2 \cdot 10^{-50}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{elif}\;b \leq 1.02 \cdot 10^{-176}:\\
\;\;\;\;\sqrt{-\frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.1999999999999999e-50Initial program 16.6%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6487.5
Applied rewrites87.5%
if -2.1999999999999999e-50 < b < 1.02000000000000002e-176Initial program 67.1%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6431.7
Applied rewrites31.7%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6431.7
Applied rewrites31.7%
if 1.02000000000000002e-176 < b Initial program 71.2%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6477.0
Applied rewrites77.0%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (- (/ c b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -(c / b);
} else {
tmp = -b / a;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1d-309)) then
tmp = -(c / b)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -(c / b);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -(c / b) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(-Float64(c / b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -(c / b); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], (-N[(c / b), $MachinePrecision]), N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;-\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 31.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6467.0
Applied rewrites67.0%
if -1.000000000000002e-309 < b Initial program 71.6%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6466.8
Applied rewrites66.8%
(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.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6435.1
Applied rewrites35.1%
herbie shell --seed 2025101
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))