
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / 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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\frac{\left(-b\_2\right) + \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / 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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\frac{\left(-b\_2\right) + \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-139999999999999990570391402012014101040279878954120499602497551495632615299510876417962868570744422400)
(* -2 (/ b_2 a))
(if (<=
b_2
3215376232195769/169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536)
(- (/ (sqrt (- (* b_2 b_2) (* c a))) a) (/ b_2 a))
(* -1/2 (/ c b_2)))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.4e+101) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.9e-110) {
tmp = (sqrt(((b_2 * b_2) - (c * a))) / a) - (b_2 / a);
} else {
tmp = -0.5 * (c / b_2);
}
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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.4d+101)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 1.9d-110) then
tmp = (sqrt(((b_2 * b_2) - (c * a))) / a) - (b_2 / a)
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.4e+101) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.9e-110) {
tmp = (Math.sqrt(((b_2 * b_2) - (c * a))) / a) - (b_2 / a);
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.4e+101: tmp = -2.0 * (b_2 / a) elif b_2 <= 1.9e-110: tmp = (math.sqrt(((b_2 * b_2) - (c * a))) / a) - (b_2 / a) else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.4e+101) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 1.9e-110) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a))) / a) - Float64(b_2 / a)); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.4e+101) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 1.9e-110) tmp = (sqrt(((b_2 * b_2) - (c * a))) / a) - (b_2 / a); else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -139999999999999990570391402012014101040279878954120499602497551495632615299510876417962868570744422400], N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3215376232195769/169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -139999999999999990570391402012014101040279878954120499602497551495632615299510876417962868570744422400:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq \frac{3215376232195769}{169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536}:\\
\;\;\;\;\frac{\sqrt{b\_2 \cdot b\_2 - c \cdot a}}{a} - \frac{b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\end{array}
if b_2 < -1.3999999999999999e101Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -1.3999999999999999e101 < b_2 < 1.8999999999999999e-110Initial program 52.5%
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
sub-flip-reverseN/A
div-subN/A
lower--.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
remove-double-negN/A
remove-double-negN/A
lift-neg.f64N/A
remove-double-negN/A
lower-/.f64N/A
lift-neg.f64N/A
remove-double-neg52.2%
Applied rewrites52.2%
if 1.8999999999999999e-110 < b_2 Initial program 52.5%
Taylor expanded in b_2 around inf
lower-*.f64N/A
lower-/.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-139999999999999990570391402012014101040279878954120499602497551495632615299510876417962868570744422400)
(* -2 (/ b_2 a))
(if (<=
b_2
3215376232195769/169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536)
(/ (- (sqrt (- (* b_2 b_2) (* c a))) b_2) a)
(* -1/2 (/ c b_2)))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.4e+101) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.9e-110) {
tmp = (sqrt(((b_2 * b_2) - (c * a))) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.4d+101)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 1.9d-110) then
tmp = (sqrt(((b_2 * b_2) - (c * a))) - b_2) / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.4e+101) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.9e-110) {
tmp = (Math.sqrt(((b_2 * b_2) - (c * a))) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.4e+101: tmp = -2.0 * (b_2 / a) elif b_2 <= 1.9e-110: tmp = (math.sqrt(((b_2 * b_2) - (c * a))) - b_2) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.4e+101) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 1.9e-110) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a))) - b_2) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.4e+101) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 1.9e-110) tmp = (sqrt(((b_2 * b_2) - (c * a))) - b_2) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -139999999999999990570391402012014101040279878954120499602497551495632615299510876417962868570744422400], N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3215376232195769/169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -139999999999999990570391402012014101040279878954120499602497551495632615299510876417962868570744422400:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq \frac{3215376232195769}{169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536}:\\
\;\;\;\;\frac{\sqrt{b\_2 \cdot b\_2 - c \cdot a} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\end{array}
if b_2 < -1.3999999999999999e101Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -1.3999999999999999e101 < b_2 < 1.8999999999999999e-110Initial program 52.5%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-neg.f64N/A
remove-double-neg52.5%
Applied rewrites52.5%
if 1.8999999999999999e-110 < b_2 Initial program 52.5%
Taylor expanded in b_2 around inf
lower-*.f64N/A
lower-/.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -29000000000)
(* -2 (/ b_2 a))
(if (<=
b_2
3215376232195769/169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536)
(/ (- (sqrt (- (* a c))) b_2) a)
(* -1/2 (/ c b_2)))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -29000000000.0) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.9e-110) {
tmp = (sqrt(-(a * c)) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-29000000000.0d0)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 1.9d-110) then
tmp = (sqrt(-(a * c)) - b_2) / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -29000000000.0) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1.9e-110) {
tmp = (Math.sqrt(-(a * c)) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -29000000000.0: tmp = -2.0 * (b_2 / a) elif b_2 <= 1.9e-110: tmp = (math.sqrt(-(a * c)) - b_2) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -29000000000.0) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 1.9e-110) tmp = Float64(Float64(sqrt(Float64(-Float64(a * c))) - b_2) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -29000000000.0) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 1.9e-110) tmp = (sqrt(-(a * c)) - b_2) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -29000000000], N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3215376232195769/169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536], N[(N[(N[Sqrt[(-N[(a * c), $MachinePrecision])], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -29000000000:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq \frac{3215376232195769}{169230328010303641331690318856389386196071598838855992136870091590247882556495704531248437872567112920983350278405979725889536}:\\
\;\;\;\;\frac{\sqrt{-a \cdot c} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\end{array}
if b_2 < -2.9e10Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -2.9e10 < b_2 < 1.8999999999999999e-110Initial program 52.5%
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-neg.f64N/A
remove-double-neg52.5%
Applied rewrites52.5%
Taylor expanded in b_2 around 0
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f6434.1%
Applied rewrites34.1%
if 1.8999999999999999e-110 < b_2 Initial program 52.5%
Taylor expanded in b_2 around inf
lower-*.f64N/A
lower-/.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-7404544304199621/21778071482940061661655974875633165533184)
(* -2 (/ b_2 a))
(if (<=
b_2
5002207817901643/9619630419041620901435312524449124464130795720328478190417063819395928166869436184427311097384012607618805661696)
(/ (sqrt (- (* a c))) a)
(* -1/2 (/ c b_2)))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.4e-25) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 5.2e-97) {
tmp = sqrt(-(a * c)) / a;
} else {
tmp = -0.5 * (c / b_2);
}
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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-3.4d-25)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 5.2d-97) then
tmp = sqrt(-(a * c)) / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.4e-25) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 5.2e-97) {
tmp = Math.sqrt(-(a * c)) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -3.4e-25: tmp = -2.0 * (b_2 / a) elif b_2 <= 5.2e-97: tmp = math.sqrt(-(a * c)) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -3.4e-25) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 5.2e-97) tmp = Float64(sqrt(Float64(-Float64(a * c))) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -3.4e-25) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 5.2e-97) tmp = sqrt(-(a * c)) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7404544304199621/21778071482940061661655974875633165533184], N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5002207817901643/9619630419041620901435312524449124464130795720328478190417063819395928166869436184427311097384012607618805661696], N[(N[Sqrt[(-N[(a * c), $MachinePrecision])], $MachinePrecision] / a), $MachinePrecision], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-7404544304199621}{21778071482940061661655974875633165533184}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq \frac{5002207817901643}{9619630419041620901435312524449124464130795720328478190417063819395928166869436184427311097384012607618805661696}:\\
\;\;\;\;\frac{\sqrt{-a \cdot c}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\end{array}
if b_2 < -3.4e-25Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -3.4e-25 < b_2 < 5.2000000000000001e-97Initial program 52.5%
Taylor expanded in b_2 around 0
lower-/.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f6429.6%
Applied rewrites29.6%
if 5.2000000000000001e-97 < b_2 Initial program 52.5%
Taylor expanded in b_2 around inf
lower-*.f64N/A
lower-/.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
-8535058474086213/853505847408621347082221029212320998034529065256436244530720999905796766440656905154743321711558949215095028555959454777073766611727278730286509574698346245900180170177793863483274020596712195165307522065393485053656415748796987045268976304128)
(* -2 (/ b_2 a))
(if (<=
b_2
4290498537581631/429049853758163107186368799942587076079339706258956588087153966199096448962353503257659977541340909686081019461967553627320124249982290238285876768194691072)
(- (sqrt (/ c (- a))))
(* -1/2 (/ c b_2)))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1e-227) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1e-140) {
tmp = -sqrt((c / -a));
} else {
tmp = -0.5 * (c / b_2);
}
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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1d-227)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 1d-140) then
tmp = -sqrt((c / -a))
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1e-227) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 1e-140) {
tmp = -Math.sqrt((c / -a));
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1e-227: tmp = -2.0 * (b_2 / a) elif b_2 <= 1e-140: tmp = -math.sqrt((c / -a)) else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1e-227) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 1e-140) tmp = Float64(-sqrt(Float64(c / Float64(-a)))); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1e-227) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 1e-140) tmp = -sqrt((c / -a)); else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -8535058474086213/853505847408621347082221029212320998034529065256436244530720999905796766440656905154743321711558949215095028555959454777073766611727278730286509574698346245900180170177793863483274020596712195165307522065393485053656415748796987045268976304128], N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 4290498537581631/429049853758163107186368799942587076079339706258956588087153966199096448962353503257659977541340909686081019461967553627320124249982290238285876768194691072], (-N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision]), N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{-8535058474086213}{853505847408621347082221029212320998034529065256436244530720999905796766440656905154743321711558949215095028555959454777073766611727278730286509574698346245900180170177793863483274020596712195165307522065393485053656415748796987045268976304128}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq \frac{4290498537581631}{429049853758163107186368799942587076079339706258956588087153966199096448962353503257659977541340909686081019461967553627320124249982290238285876768194691072}:\\
\;\;\;\;-\sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\end{array}
if b_2 < -9.9999999999999994e-228Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if -9.9999999999999994e-228 < b_2 < 9.9999999999999998e-141Initial program 52.5%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6417.6%
Applied rewrites17.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6417.6%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-neg-fracN/A
lower-/.f64N/A
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-outN/A
metadata-evalN/A
*-rgt-identityN/A
lower-neg.f6417.6%
Applied rewrites17.6%
if 9.9999999999999998e-141 < b_2 Initial program 52.5%
Taylor expanded in b_2 around inf
lower-*.f64N/A
lower-/.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c)
:precision binary64
(if (<=
b_2
5033540777614485/359538626972463181545861038157804946723595395788461314546860162315465351611001926265416954644815072042240227759742786715317579537628833244985694861278948248755535786849730970552604439202492188238906165904170011537676301364684925762947826221081654474326701021369172596479894491876959432609670712659248448274432)
(* -2 (/ b_2 a))
(* -1/2 (/ c b_2))))double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 1.4e-293) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = -0.5 * (c / b_2);
}
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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= 1.4d-293) then
tmp = (-2.0d0) * (b_2 / a)
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 1.4e-293) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 1.4e-293: tmp = -2.0 * (b_2 / a) else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= 1.4e-293) tmp = Float64(-2.0 * Float64(b_2 / a)); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= 1.4e-293) tmp = -2.0 * (b_2 / a); else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 5033540777614485/359538626972463181545861038157804946723595395788461314546860162315465351611001926265416954644815072042240227759742786715317579537628833244985694861278948248755535786849730970552604439202492188238906165904170011537676301364684925762947826221081654474326701021369172596479894491876959432609670712659248448274432], N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(-1/2 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;b\_2 \leq \frac{5033540777614485}{359538626972463181545861038157804946723595395788461314546860162315465351611001926265416954644815072042240227759742786715317579537628833244985694861278948248755535786849730970552604439202492188238906165904170011537676301364684925762947826221081654474326701021369172596479894491876959432609670712659248448274432}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{c}{b\_2}\\
\end{array}
if b_2 < 1.4000000000000001e-293Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
if 1.4000000000000001e-293 < b_2 Initial program 52.5%
Taylor expanded in b_2 around inf
lower-*.f64N/A
lower-/.f6435.3%
Applied rewrites35.3%
(FPCore (a b_2 c) :precision binary64 (* -2 (/ b_2 a)))
double code(double a, double b_2, double c) {
return -2.0 * (b_2 / 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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-2.0d0) * (b_2 / a)
end function
public static double code(double a, double b_2, double c) {
return -2.0 * (b_2 / a);
}
def code(a, b_2, c): return -2.0 * (b_2 / a)
function code(a, b_2, c) return Float64(-2.0 * Float64(b_2 / a)) end
function tmp = code(a, b_2, c) tmp = -2.0 * (b_2 / a); end
code[a_, b$95$2_, c_] := N[(-2 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]
-2 \cdot \frac{b\_2}{a}
Initial program 52.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6435.1%
Applied rewrites35.1%
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
:herbie-expected 10
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))