
(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]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+98)
(/ (- b) a)
(if (<= b 1.32e-59)
(/ (- (sqrt (fma (* c a) -4.0 (* b b))) b) (+ a a))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+98) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = (sqrt(fma((c * a), -4.0, (b * b))) - b) / (a + a);
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.5e+98) tmp = Float64(Float64(-b) / a); elseif (b <= 1.32e-59) tmp = Float64(Float64(sqrt(fma(Float64(c * a), -4.0, Float64(b * b))) - b) / Float64(a + a)); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.5e+98], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.32e-59], N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{+98}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-59}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -1.5000000000000001e98Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -1.5000000000000001e98 < b < 1.3199999999999999e-59Initial program 52.2%
Applied rewrites52.2%
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6452.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6452.2%
Applied rewrites52.2%
if 1.3199999999999999e-59 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+98)
(/ (- b) a)
(if (<= b 1.32e-59)
(/ (- (sqrt (fma (* c -4.0) a (* b b))) b) (+ a a))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+98) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = (sqrt(fma((c * -4.0), a, (b * b))) - b) / (a + a);
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.5e+98) tmp = Float64(Float64(-b) / a); elseif (b <= 1.32e-59) tmp = Float64(Float64(sqrt(fma(Float64(c * -4.0), a, Float64(b * b))) - b) / Float64(a + a)); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.5e+98], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.32e-59], N[(N[(N[Sqrt[N[(N[(c * -4.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{+98}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-59}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)} - b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -1.5000000000000001e98Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -1.5000000000000001e98 < b < 1.3199999999999999e-59Initial program 52.2%
Applied rewrites52.2%
if 1.3199999999999999e-59 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e-81)
(/ (- b) a)
(if (<= b 1.32e-59)
(/ (+ (- b) (sqrt (* -4.0 (* a c)))) (* 2.0 a))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-81) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = (-b + sqrt((-4.0 * (a * c)))) / (2.0 * a);
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.2d-81)) then
tmp = -b / a
else if (b <= 1.32d-59) then
tmp = (-b + sqrt(((-4.0d0) * (a * c)))) / (2.0d0 * a)
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e-81) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = (-b + Math.sqrt((-4.0 * (a * c)))) / (2.0 * a);
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e-81: tmp = -b / a elif b <= 1.32e-59: tmp = (-b + math.sqrt((-4.0 * (a * c)))) / (2.0 * a) else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e-81) tmp = Float64(Float64(-b) / a); elseif (b <= 1.32e-59) tmp = Float64(Float64(Float64(-b) + sqrt(Float64(-4.0 * Float64(a * c)))) / Float64(2.0 * a)); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.2e-81) tmp = -b / a; elseif (b <= 1.32e-59) tmp = (-b + sqrt((-4.0 * (a * c)))) / (2.0 * a); else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e-81], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.32e-59], N[(N[((-b) + N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{-81}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-59}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{-4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -1.2e-81Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -1.2e-81 < b < 1.3199999999999999e-59Initial program 52.2%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6433.0%
Applied rewrites33.0%
if 1.3199999999999999e-59 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.35e-88)
(/ (- b) a)
(if (<= b 1.32e-59)
(* 0.5 (/ (sqrt (- (* 4.0 (* a c)))) a))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-88) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = 0.5 * (sqrt(-(4.0 * (a * c))) / a);
} else {
tmp = -1.0 * (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.35d-88)) then
tmp = -b / a
else if (b <= 1.32d-59) then
tmp = 0.5d0 * (sqrt(-(4.0d0 * (a * c))) / a)
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-88) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = 0.5 * (Math.sqrt(-(4.0 * (a * c))) / a);
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-88: tmp = -b / a elif b <= 1.32e-59: tmp = 0.5 * (math.sqrt(-(4.0 * (a * c))) / a) else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-88) tmp = Float64(Float64(-b) / a); elseif (b <= 1.32e-59) tmp = Float64(0.5 * Float64(sqrt(Float64(-Float64(4.0 * Float64(a * c)))) / a)); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.35e-88) tmp = -b / a; elseif (b <= 1.32e-59) tmp = 0.5 * (sqrt(-(4.0 * (a * c))) / a); else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-88], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.32e-59], N[(0.5 * N[(N[Sqrt[(-N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision])], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-88}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-59}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{-4 \cdot \left(a \cdot c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -2.35e-88Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -2.35e-88 < b < 1.3199999999999999e-59Initial program 52.2%
Taylor expanded in b around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-*.f6428.2%
Applied rewrites28.2%
if 1.3199999999999999e-59 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.35e-88)
(/ (- b) a)
(if (<= b 1.32e-59)
(* -0.5 (* c (sqrt (/ -4.0 (* a c)))))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-88) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = -0.5 * (c * sqrt((-4.0 / (a * c))));
} else {
tmp = -1.0 * (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.35d-88)) then
tmp = -b / a
else if (b <= 1.32d-59) then
tmp = (-0.5d0) * (c * sqrt(((-4.0d0) / (a * c))))
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-88) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = -0.5 * (c * Math.sqrt((-4.0 / (a * c))));
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-88: tmp = -b / a elif b <= 1.32e-59: tmp = -0.5 * (c * math.sqrt((-4.0 / (a * c)))) else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-88) tmp = Float64(Float64(-b) / a); elseif (b <= 1.32e-59) tmp = Float64(-0.5 * Float64(c * sqrt(Float64(-4.0 / Float64(a * c))))); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.35e-88) tmp = -b / a; elseif (b <= 1.32e-59) tmp = -0.5 * (c * sqrt((-4.0 / (a * c)))); else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-88], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.32e-59], N[(-0.5 * N[(c * N[Sqrt[N[(-4.0 / N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-88}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-59}:\\
\;\;\;\;-0.5 \cdot \left(c \cdot \sqrt{\frac{-4}{a \cdot c}}\right)\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -2.35e-88Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -2.35e-88 < b < 1.3199999999999999e-59Initial program 52.2%
Taylor expanded in a around -inf
lower-fma.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f6419.9%
Applied rewrites19.9%
Taylor expanded in c around inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6427.0%
Applied rewrites27.0%
if 1.3199999999999999e-59 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.35e-88)
(/ (- b) a)
(if (<= b 1.32e-59)
(/ (sqrt (* (* -4.0 c) a)) (+ a a))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-88) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = sqrt(((-4.0 * c) * a)) / (a + a);
} else {
tmp = -1.0 * (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.35d-88)) then
tmp = -b / a
else if (b <= 1.32d-59) then
tmp = sqrt((((-4.0d0) * c) * a)) / (a + a)
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-88) {
tmp = -b / a;
} else if (b <= 1.32e-59) {
tmp = Math.sqrt(((-4.0 * c) * a)) / (a + a);
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-88: tmp = -b / a elif b <= 1.32e-59: tmp = math.sqrt(((-4.0 * c) * a)) / (a + a) else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-88) tmp = Float64(Float64(-b) / a); elseif (b <= 1.32e-59) tmp = Float64(sqrt(Float64(Float64(-4.0 * c) * a)) / Float64(a + a)); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.35e-88) tmp = -b / a; elseif (b <= 1.32e-59) tmp = sqrt(((-4.0 * c) * a)) / (a + a); else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-88], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.32e-59], N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a), $MachinePrecision]], $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-88}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-59}:\\
\;\;\;\;\frac{\sqrt{\left(-4 \cdot c\right) \cdot a}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -2.35e-88Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -2.35e-88 < b < 1.3199999999999999e-59Initial program 52.2%
Taylor expanded in b around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-*.f6428.2%
Applied rewrites28.2%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
metadata-evalN/A
associate-/r*N/A
count-2-revN/A
lift-+.f64N/A
lower-*.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-+.f64N/A
Applied rewrites28.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f6428.1%
lift-/.f64N/A
metadata-evalN/A
associate-/r*N/A
count-2-revN/A
lift-+.f64N/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6428.1%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f6428.1%
Applied rewrites28.1%
if 1.3199999999999999e-59 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-113)
(/ (- b) a)
(if (<= b 5.65e-61)
(* -0.5 (* (sqrt c) (sqrt (/ -4.0 a))))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-113) {
tmp = -b / a;
} else if (b <= 5.65e-61) {
tmp = -0.5 * (sqrt(c) * sqrt((-4.0 / a)));
} else {
tmp = -1.0 * (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.1d-113)) then
tmp = -b / a
else if (b <= 5.65d-61) then
tmp = (-0.5d0) * (sqrt(c) * sqrt(((-4.0d0) / a)))
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-113) {
tmp = -b / a;
} else if (b <= 5.65e-61) {
tmp = -0.5 * (Math.sqrt(c) * Math.sqrt((-4.0 / a)));
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-113: tmp = -b / a elif b <= 5.65e-61: tmp = -0.5 * (math.sqrt(c) * math.sqrt((-4.0 / a))) else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-113) tmp = Float64(Float64(-b) / a); elseif (b <= 5.65e-61) tmp = Float64(-0.5 * Float64(sqrt(c) * sqrt(Float64(-4.0 / a)))); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.1e-113) tmp = -b / a; elseif (b <= 5.65e-61) tmp = -0.5 * (sqrt(c) * sqrt((-4.0 / a))); else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-113], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 5.65e-61], N[(-0.5 * N[(N[Sqrt[c], $MachinePrecision] * N[Sqrt[N[(-4.0 / a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-113}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 5.65 \cdot 10^{-61}:\\
\;\;\;\;-0.5 \cdot \left(\sqrt{c} \cdot \sqrt{\frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -2.1e-113Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -2.1e-113 < b < 5.6499999999999998e-61Initial program 52.2%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.3%
Applied rewrites17.3%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
sqrt-prodN/A
lower-unsound-sqrt.f64N/A
lower-unsound-*.f64N/A
lower-unsound-sqrt.f64N/A
lower-/.f6417.4%
Applied rewrites17.4%
if 5.6499999999999998e-61 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-113)
(/ (- b) a)
(if (<= b 1.35e-157)
(* -0.5 (sqrt (* -4.0 (/ c a))))
(* -1.0 (/ c b)))))double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-113) {
tmp = -b / a;
} else if (b <= 1.35e-157) {
tmp = -0.5 * sqrt((-4.0 * (c / a)));
} else {
tmp = -1.0 * (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.1d-113)) then
tmp = -b / a
else if (b <= 1.35d-157) then
tmp = (-0.5d0) * sqrt(((-4.0d0) * (c / a)))
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-113) {
tmp = -b / a;
} else if (b <= 1.35e-157) {
tmp = -0.5 * Math.sqrt((-4.0 * (c / a)));
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-113: tmp = -b / a elif b <= 1.35e-157: tmp = -0.5 * math.sqrt((-4.0 * (c / a))) else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-113) tmp = Float64(Float64(-b) / a); elseif (b <= 1.35e-157) tmp = Float64(-0.5 * sqrt(Float64(-4.0 * Float64(c / a)))); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.1e-113) tmp = -b / a; elseif (b <= 1.35e-157) tmp = -0.5 * sqrt((-4.0 * (c / a))); else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-113], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.35e-157], N[(-0.5 * N[Sqrt[N[(-4.0 * N[(c / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-113}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-157}:\\
\;\;\;\;-0.5 \cdot \sqrt{-4 \cdot \frac{c}{a}}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < -2.1e-113Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if -2.1e-113 < b < 1.35e-157Initial program 52.2%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.3%
Applied rewrites17.3%
if 1.35e-157 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c) :precision binary64 (if (<= b 2.9e-290) (/ (- b) a) (* -1.0 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.9e-290) {
tmp = -b / a;
} else {
tmp = -1.0 * (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-290) then
tmp = -b / a
else
tmp = (-1.0d0) * (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.9e-290) {
tmp = -b / a;
} else {
tmp = -1.0 * (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.9e-290: tmp = -b / a else: tmp = -1.0 * (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.9e-290) tmp = Float64(Float64(-b) / a); else tmp = Float64(-1.0 * Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.9e-290) tmp = -b / a; else tmp = -1.0 * (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.9e-290], N[((-b) / a), $MachinePrecision], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;b \leq 2.9 \cdot 10^{-290}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\end{array}
if b < 2.8999999999999999e-290Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
if 2.8999999999999999e-290 < b Initial program 52.2%
Taylor expanded in b around inf
lower-*.f64N/A
lower-/.f6434.3%
Applied rewrites34.3%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / a;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -b / a
end function
public static double code(double a, double b, double c) {
return -b / a;
}
def code(a, b, c): return -b / a
function code(a, b, c) return Float64(Float64(-b) / a) end
function tmp = code(a, b, c) tmp = -b / a; end
code[a_, b_, c_] := N[((-b) / a), $MachinePrecision]
\frac{-b}{a}
Initial program 52.2%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6436.5%
Applied rewrites36.5%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
*-rgt-identityN/A
metadata-evalN/A
distribute-rgt-neg-outN/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identity36.5%
Applied rewrites36.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
herbie shell --seed 2025252
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform c (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))