
(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 8 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.4e+160)
(- (/ c b) (/ b a))
(if (<= b 1.15e-61)
(/ (+ (- b) (sqrt (fma b b (* (* c a) -4.0)))) (+ a a))
(- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.4e+160) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-61) {
tmp = (-b + sqrt(fma(b, b, ((c * a) * -4.0)))) / (a + a);
} else {
tmp = -(c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.4e+160) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-61) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(Float64(c * a) * -4.0)))) / Float64(a + a)); else tmp = Float64(-Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.4e+160], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-61], N[(N[((-b) + N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.4 \cdot 10^{+160}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-61}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -1.4e160Initial program 42.0%
Taylor expanded in b around -inf
Applied rewrites97.3%
Taylor expanded in a around inf
Applied rewrites97.8%
Taylor expanded in c around 0
Applied rewrites97.8%
if -1.4e160 < b < 1.14999999999999996e-61Initial program 81.7%
Taylor expanded in a around 0
Applied rewrites81.7%
Applied rewrites81.7%
if 1.14999999999999996e-61 < b Initial program 17.6%
Taylor expanded in a around 0
Applied rewrites86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -3.3e-59)
(- (/ c b) (/ b a))
(if (<= b 1.15e-61)
(/ (+ (- b) (sqrt (* (* c a) -4.0))) (+ a a))
(- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.3e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-61) {
tmp = (-b + sqrt(((c * a) * -4.0))) / (a + a);
} else {
tmp = -(c / b);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3.3d-59)) then
tmp = (c / b) - (b / a)
else if (b <= 1.15d-61) then
tmp = (-b + sqrt(((c * a) * (-4.0d0)))) / (a + a)
else
tmp = -(c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.3e-59) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-61) {
tmp = (-b + Math.sqrt(((c * a) * -4.0))) / (a + a);
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.3e-59: tmp = (c / b) - (b / a) elif b <= 1.15e-61: tmp = (-b + math.sqrt(((c * a) * -4.0))) / (a + a) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.3e-59) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-61) tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(c * a) * -4.0))) / Float64(a + a)); else tmp = Float64(-Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.3e-59) tmp = (c / b) - (b / a); elseif (b <= 1.15e-61) tmp = (-b + sqrt(((c * a) * -4.0))) / (a + a); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.3e-59], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-61], N[(N[((-b) + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.3 \cdot 10^{-59}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-61}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\left(c \cdot a\right) \cdot -4}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -3.29999999999999982e-59Initial program 69.0%
Taylor expanded in b around -inf
Applied rewrites87.6%
Taylor expanded in a around inf
Applied rewrites88.0%
Taylor expanded in c around 0
Applied rewrites88.0%
if -3.29999999999999982e-59 < b < 1.14999999999999996e-61Initial program 75.9%
Taylor expanded in a around inf
Applied rewrites68.4%
Applied rewrites68.4%
if 1.14999999999999996e-61 < b Initial program 17.6%
Taylor expanded in a around 0
Applied rewrites86.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-60) (- (/ c b) (/ b a)) (if (<= b 6.8e-46) (/ (sqrt (* (* c a) -4.0)) (+ a a)) (- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-60) {
tmp = (c / b) - (b / a);
} else if (b <= 6.8e-46) {
tmp = sqrt(((c * a) * -4.0)) / (a + a);
} else {
tmp = -(c / b);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-60)) then
tmp = (c / b) - (b / a)
else if (b <= 6.8d-46) then
tmp = sqrt(((c * a) * (-4.0d0))) / (a + a)
else
tmp = -(c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-60) {
tmp = (c / b) - (b / a);
} else if (b <= 6.8e-46) {
tmp = Math.sqrt(((c * a) * -4.0)) / (a + a);
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-60: tmp = (c / b) - (b / a) elif b <= 6.8e-46: tmp = math.sqrt(((c * a) * -4.0)) / (a + a) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-60) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 6.8e-46) tmp = Float64(sqrt(Float64(Float64(c * a) * -4.0)) / Float64(a + a)); else tmp = Float64(-Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-60) tmp = (c / b) - (b / a); elseif (b <= 6.8e-46) tmp = sqrt(((c * a) * -4.0)) / (a + a); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-60], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.8e-46], N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-60}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6.8 \cdot 10^{-46}:\\
\;\;\;\;\frac{\sqrt{\left(c \cdot a\right) \cdot -4}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -5.0000000000000001e-60Initial program 69.0%
Taylor expanded in b around -inf
Applied rewrites87.6%
Taylor expanded in a around inf
Applied rewrites87.9%
Taylor expanded in c around 0
Applied rewrites87.9%
if -5.0000000000000001e-60 < b < 6.79999999999999992e-46Initial program 74.9%
Taylor expanded in a around inf
Applied rewrites66.5%
Applied rewrites66.5%
if 6.79999999999999992e-46 < b Initial program 16.4%
Taylor expanded in a around 0
Applied rewrites87.7%
(FPCore (a b c) :precision binary64 (if (<= b -2.9e-105) (- (/ c b) (/ b a)) (if (<= b 1.05e-121) (sqrt (- (/ c a))) (- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-105) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-121) {
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 <= (-2.9d-105)) then
tmp = (c / b) - (b / a)
else if (b <= 1.05d-121) 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 <= -2.9e-105) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-121) {
tmp = Math.sqrt(-(c / a));
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-105: tmp = (c / b) - (b / a) elif b <= 1.05e-121: tmp = math.sqrt(-(c / a)) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-105) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.05e-121) 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 <= -2.9e-105) tmp = (c / b) - (b / a); elseif (b <= 1.05e-121) tmp = sqrt(-(c / a)); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-105], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e-121], N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-105}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{-121}:\\
\;\;\;\;\sqrt{-\frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -2.90000000000000003e-105Initial program 70.8%
Taylor expanded in b around -inf
Applied rewrites84.1%
Taylor expanded in a around inf
Applied rewrites84.4%
Taylor expanded in c around 0
Applied rewrites84.4%
if -2.90000000000000003e-105 < b < 1.0499999999999999e-121Initial program 76.7%
Taylor expanded in a around -inf
Applied rewrites34.1%
Taylor expanded in c around -inf
Applied rewrites34.2%
if 1.0499999999999999e-121 < b Initial program 21.4%
Taylor expanded in a around 0
Applied rewrites81.9%
(FPCore (a b c) :precision binary64 (if (<= b -2.9e-105) (- (/ b a)) (if (<= b 1.05e-121) (sqrt (- (/ c a))) (- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-105) {
tmp = -(b / a);
} else if (b <= 1.05e-121) {
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 <= (-2.9d-105)) then
tmp = -(b / a)
else if (b <= 1.05d-121) 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 <= -2.9e-105) {
tmp = -(b / a);
} else if (b <= 1.05e-121) {
tmp = Math.sqrt(-(c / a));
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-105: tmp = -(b / a) elif b <= 1.05e-121: tmp = math.sqrt(-(c / a)) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-105) tmp = Float64(-Float64(b / a)); elseif (b <= 1.05e-121) 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 <= -2.9e-105) tmp = -(b / a); elseif (b <= 1.05e-121) tmp = sqrt(-(c / a)); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-105], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 1.05e-121], N[Sqrt[(-N[(c / a), $MachinePrecision])], $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-105}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{-121}:\\
\;\;\;\;\sqrt{-\frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -2.90000000000000003e-105Initial program 70.8%
Taylor expanded in b around -inf
Applied rewrites84.0%
if -2.90000000000000003e-105 < b < 1.0499999999999999e-121Initial program 76.7%
Taylor expanded in a around -inf
Applied rewrites34.1%
Taylor expanded in c around -inf
Applied rewrites34.2%
if 1.0499999999999999e-121 < b Initial program 21.4%
Taylor expanded in a around 0
Applied rewrites81.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (- (/ b a)) (- (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
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 <= (-4d-310)) 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 <= -4e-310) {
tmp = -(b / a);
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -(b / a) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) 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 <= -4e-310) tmp = -(b / a); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], (-N[(b / a), $MachinePrecision]), (-N[(c / b), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 72.8%
Taylor expanded in b around -inf
Applied rewrites68.2%
if -3.999999999999988e-310 < b Initial program 32.6%
Taylor expanded in a around 0
Applied rewrites67.7%
(FPCore (a b c) :precision binary64 (if (<= b 560.0) (- (/ b a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 560.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 <= 560.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 <= 560.0) {
tmp = -(b / a);
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 560.0: tmp = -(b / a) else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 560.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 <= 560.0) tmp = -(b / a); else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 560.0], (-N[(b / a), $MachinePrecision]), N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 560:\\
\;\;\;\;-\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 560Initial program 69.8%
Taylor expanded in b around -inf
Applied rewrites50.0%
if 560 < b Initial program 14.1%
Taylor expanded in b around -inf
Applied rewrites2.4%
Taylor expanded in a around inf
Applied rewrites27.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(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.6%
Taylor expanded in b around -inf
Applied rewrites34.5%
Taylor expanded in a around inf
Applied rewrites10.7%
herbie shell --seed 2025134
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))