
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.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) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+154)
(fma 0.5 (/ c b) (* (/ b a) -0.6666666666666666))
(if (<= b 2.8e-97)
(/ (+ (- b) (sqrt (fma b b (* (* -3.0 a) c)))) (* 3.0 a))
(/ (* -0.5 c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+154) {
tmp = fma(0.5, (c / b), ((b / a) * -0.6666666666666666));
} else if (b <= 2.8e-97) {
tmp = (-b + sqrt(fma(b, b, ((-3.0 * a) * c)))) / (3.0 * a);
} else {
tmp = (-0.5 * c) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.5e+154) tmp = fma(0.5, Float64(c / b), Float64(Float64(b / a) * -0.6666666666666666)); elseif (b <= 2.8e-97) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(Float64(-3.0 * a) * c)))) / Float64(3.0 * a)); else tmp = Float64(Float64(-0.5 * c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.5e+154], N[(0.5 * N[(c / b), $MachinePrecision] + N[(N[(b / a), $MachinePrecision] * -0.6666666666666666), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.8e-97], N[(N[((-b) + N[Sqrt[N[(b * b + N[(N[(-3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-97}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, \left(-3 \cdot a\right) \cdot c\right)}}{3 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\
\end{array}
\end{array}
if b < -1.50000000000000013e154Initial program 28.6%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
Taylor expanded in a around inf
Applied rewrites99.8%
if -1.50000000000000013e154 < b < 2.8000000000000002e-97Initial program 88.2%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval88.2
Applied rewrites88.2%
if 2.8000000000000002e-97 < b Initial program 21.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites21.9%
Applied rewrites21.9%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+154)
(fma 0.5 (/ c b) (* (/ b a) -0.6666666666666666))
(if (<= b 2.8e-97)
(* 0.3333333333333333 (/ (- (sqrt (fma (* c -3.0) a (* b b))) b) a))
(/ (* -0.5 c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+154) {
tmp = fma(0.5, (c / b), ((b / a) * -0.6666666666666666));
} else if (b <= 2.8e-97) {
tmp = 0.3333333333333333 * ((sqrt(fma((c * -3.0), a, (b * b))) - b) / a);
} else {
tmp = (-0.5 * c) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.5e+154) tmp = fma(0.5, Float64(c / b), Float64(Float64(b / a) * -0.6666666666666666)); elseif (b <= 2.8e-97) tmp = Float64(0.3333333333333333 * Float64(Float64(sqrt(fma(Float64(c * -3.0), a, Float64(b * b))) - b) / a)); else tmp = Float64(Float64(-0.5 * c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.5e+154], N[(0.5 * N[(c / b), $MachinePrecision] + N[(N[(b / a), $MachinePrecision] * -0.6666666666666666), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.8e-97], N[(0.3333333333333333 * N[(N[(N[Sqrt[N[(N[(c * -3.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-97}:\\
\;\;\;\;0.3333333333333333 \cdot \frac{\sqrt{\mathsf{fma}\left(c \cdot -3, a, b \cdot b\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\
\end{array}
\end{array}
if b < -1.50000000000000013e154Initial program 28.6%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
Taylor expanded in a around inf
Applied rewrites99.8%
if -1.50000000000000013e154 < b < 2.8000000000000002e-97Initial program 88.2%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval88.2
Applied rewrites88.2%
Applied rewrites88.1%
if 2.8000000000000002e-97 < b Initial program 21.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites21.9%
Applied rewrites21.9%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
Final simplification90.6%
(FPCore (a b c)
:precision binary64
(if (<= b -3.25e-83)
(fma 0.5 (/ c b) (* (/ b a) -0.6666666666666666))
(if (<= b 2.8e-97)
(/ (+ (- b) (sqrt (* (* c a) -3.0))) (* 3.0 a))
(/ (* -0.5 c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-83) {
tmp = fma(0.5, (c / b), ((b / a) * -0.6666666666666666));
} else if (b <= 2.8e-97) {
tmp = (-b + sqrt(((c * a) * -3.0))) / (3.0 * a);
} else {
tmp = (-0.5 * c) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -3.25e-83) tmp = fma(0.5, Float64(c / b), Float64(Float64(b / a) * -0.6666666666666666)); elseif (b <= 2.8e-97) tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(c * a) * -3.0))) / Float64(3.0 * a)); else tmp = Float64(Float64(-0.5 * c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-83], N[(0.5 * N[(c / b), $MachinePrecision] + N[(N[(b / a), $MachinePrecision] * -0.6666666666666666), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.8e-97], N[(N[((-b) + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -3.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.25 \cdot 10^{-83}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-97}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\left(c \cdot a\right) \cdot -3}}{3 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\
\end{array}
\end{array}
if b < -3.25e-83Initial program 65.3%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6485.6
Applied rewrites85.6%
Taylor expanded in a around inf
Applied rewrites85.6%
if -3.25e-83 < b < 2.8000000000000002e-97Initial program 84.8%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6483.4
Applied rewrites83.4%
if 2.8000000000000002e-97 < b Initial program 21.8%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites21.9%
Applied rewrites21.9%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f6489.8
Applied rewrites89.8%
Applied rewrites89.8%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (fma 0.5 (/ c b) (* (/ b a) -0.6666666666666666)) (/ (* -0.5 c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = fma(0.5, (c / b), ((b / a) * -0.6666666666666666));
} else {
tmp = (-0.5 * c) / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = fma(0.5, Float64(c / b), Float64(Float64(b / a) * -0.6666666666666666)); else tmp = Float64(Float64(-0.5 * c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(0.5 * N[(c / b), $MachinePrecision] + N[(N[(b / a), $MachinePrecision] * -0.6666666666666666), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{c}{b}, \frac{b}{a} \cdot -0.6666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 71.9%
Taylor expanded in b around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6464.0
Applied rewrites64.0%
Taylor expanded in a around inf
Applied rewrites64.1%
if -1.999999999999994e-310 < b Initial program 33.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites33.5%
Applied rewrites33.4%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f6476.0
Applied rewrites76.0%
Applied rewrites76.0%
(FPCore (a b c) :precision binary64 (if (<= b 2.85e-282) (* -0.6666666666666666 (/ b a)) (/ (* -0.5 c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e-282) {
tmp = -0.6666666666666666 * (b / a);
} else {
tmp = (-0.5 * 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.85d-282) then
tmp = (-0.6666666666666666d0) * (b / a)
else
tmp = ((-0.5d0) * c) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e-282) {
tmp = -0.6666666666666666 * (b / a);
} else {
tmp = (-0.5 * c) / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.85e-282: tmp = -0.6666666666666666 * (b / a) else: tmp = (-0.5 * c) / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.85e-282) tmp = Float64(-0.6666666666666666 * Float64(b / a)); else tmp = Float64(Float64(-0.5 * c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.85e-282) tmp = -0.6666666666666666 * (b / a); else tmp = (-0.5 * c) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.85e-282], N[(-0.6666666666666666 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * c), $MachinePrecision] / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.85 \cdot 10^{-282}:\\
\;\;\;\;-0.6666666666666666 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b}\\
\end{array}
\end{array}
if b < 2.8500000000000001e-282Initial program 72.3%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6462.5
Applied rewrites62.5%
if 2.8500000000000001e-282 < b Initial program 32.3%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites32.4%
Applied rewrites32.4%
Taylor expanded in a around 0
lower-*.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
Applied rewrites77.2%
(FPCore (a b c) :precision binary64 (if (<= b 2.85e-282) (* -0.6666666666666666 (/ b a)) (* (/ c b) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e-282) {
tmp = -0.6666666666666666 * (b / a);
} else {
tmp = (c / b) * -0.5;
}
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.85d-282) then
tmp = (-0.6666666666666666d0) * (b / a)
else
tmp = (c / b) * (-0.5d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e-282) {
tmp = -0.6666666666666666 * (b / a);
} else {
tmp = (c / b) * -0.5;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.85e-282: tmp = -0.6666666666666666 * (b / a) else: tmp = (c / b) * -0.5 return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.85e-282) tmp = Float64(-0.6666666666666666 * Float64(b / a)); else tmp = Float64(Float64(c / b) * -0.5); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.85e-282) tmp = -0.6666666666666666 * (b / a); else tmp = (c / b) * -0.5; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.85e-282], N[(-0.6666666666666666 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.85 \cdot 10^{-282}:\\
\;\;\;\;-0.6666666666666666 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -0.5\\
\end{array}
\end{array}
if b < 2.8500000000000001e-282Initial program 72.3%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6462.5
Applied rewrites62.5%
if 2.8500000000000001e-282 < b Initial program 32.3%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
(FPCore (a b c) :precision binary64 (if (<= b 3.8e-284) (* -0.6666666666666666 (/ b a)) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.8e-284) {
tmp = -0.6666666666666666 * (b / a);
} else {
tmp = 0.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) :: tmp
if (b <= 3.8d-284) then
tmp = (-0.6666666666666666d0) * (b / a)
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 3.8e-284) {
tmp = -0.6666666666666666 * (b / a);
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.8e-284: tmp = -0.6666666666666666 * (b / a) else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.8e-284) tmp = Float64(-0.6666666666666666 * Float64(b / a)); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3.8e-284) tmp = -0.6666666666666666 * (b / a); else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.8e-284], N[(-0.6666666666666666 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.8 \cdot 10^{-284}:\\
\;\;\;\;-0.6666666666666666 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < 3.7999999999999999e-284Initial program 72.1%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6462.9
Applied rewrites62.9%
if 3.7999999999999999e-284 < b Initial program 32.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites32.9%
Applied rewrites25.9%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
+-inversesN/A
metadata-eval21.7
Applied rewrites21.7%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 52.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites53.0%
Applied rewrites49.5%
Taylor expanded in a around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
+-inversesN/A
metadata-eval12.1
Applied rewrites12.1%
herbie shell --seed 2024357
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))