
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -9e-99)
(/ (- c) b)
(if (<= b 5.6e+67)
(/ (+ b (pow (fma (* -4.0 a) c (* b b)) 0.5)) (* 2.0 (- a)))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-99) {
tmp = -c / b;
} else if (b <= 5.6e+67) {
tmp = (b + pow(fma((-4.0 * a), c, (b * b)), 0.5)) / (2.0 * -a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9e-99) tmp = Float64(Float64(-c) / b); elseif (b <= 5.6e+67) tmp = Float64(Float64(b + (fma(Float64(-4.0 * a), c, Float64(b * b)) ^ 0.5)) / Float64(2.0 * Float64(-a))); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9e-99], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.6e+67], N[(N[(b + N[Power[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] / N[(2.0 * (-a)), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-99}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{+67}:\\
\;\;\;\;\frac{b + {\left(\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)\right)}^{0.5}}{2 \cdot \left(-a\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -9.0000000000000006e-99Initial program 15.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.4
Applied rewrites90.4%
if -9.0000000000000006e-99 < b < 5.5999999999999995e67Initial program 77.3%
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow1/2N/A
lower-pow.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6477.3
Applied rewrites77.3%
if 5.5999999999999995e67 < b Initial program 55.7%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6498.4
Applied rewrites98.4%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-99)
(/ (- c) b)
(if (<= b 5.6e+67)
(/ (- (- b) (sqrt (fma (* c a) -4.0 (* b b)))) (+ a a))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-99) {
tmp = -c / b;
} else if (b <= 5.6e+67) {
tmp = (-b - sqrt(fma((c * a), -4.0, (b * b)))) / (a + a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9e-99) tmp = Float64(Float64(-c) / b); elseif (b <= 5.6e+67) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(c * a), -4.0, Float64(b * b)))) / Float64(a + a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9e-99], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.6e+67], N[(N[((-b) - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-99}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{+67}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -9.0000000000000006e-99Initial program 15.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.4
Applied rewrites90.4%
if -9.0000000000000006e-99 < b < 5.5999999999999995e67Initial program 77.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6477.3
Applied rewrites77.3%
lift-*.f64N/A
count-2-revN/A
lift-+.f6477.3
Applied rewrites77.3%
if 5.5999999999999995e67 < b Initial program 55.7%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6498.4
Applied rewrites98.4%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-99)
(/ (- c) b)
(if (<= b 7.8e-97)
(/ (+ b (sqrt (* (* a c) -4.0))) (- (- a) a))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-99) {
tmp = -c / b;
} else if (b <= 7.8e-97) {
tmp = (b + sqrt(((a * c) * -4.0))) / (-a - a);
} else {
tmp = (-b / a) + (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 <= (-9d-99)) then
tmp = -c / b
else if (b <= 7.8d-97) then
tmp = (b + sqrt(((a * c) * (-4.0d0)))) / (-a - a)
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-99) {
tmp = -c / b;
} else if (b <= 7.8e-97) {
tmp = (b + Math.sqrt(((a * c) * -4.0))) / (-a - a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-99: tmp = -c / b elif b <= 7.8e-97: tmp = (b + math.sqrt(((a * c) * -4.0))) / (-a - a) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-99) tmp = Float64(Float64(-c) / b); elseif (b <= 7.8e-97) tmp = Float64(Float64(b + sqrt(Float64(Float64(a * c) * -4.0))) / Float64(Float64(-a) - a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-99) tmp = -c / b; elseif (b <= 7.8e-97) tmp = (b + sqrt(((a * c) * -4.0))) / (-a - a); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-99], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 7.8e-97], N[(N[(b + N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[((-a) - a), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-99}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{-97}:\\
\;\;\;\;\frac{b + \sqrt{\left(a \cdot c\right) \cdot -4}}{\left(-a\right) - a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -9.0000000000000006e-99Initial program 15.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.4
Applied rewrites90.4%
if -9.0000000000000006e-99 < b < 7.7999999999999997e-97Initial program 70.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6470.3
Applied rewrites70.3%
lift-*.f64N/A
count-2-revN/A
lift-+.f6470.3
Applied rewrites70.3%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6464.7
Applied rewrites64.7%
if 7.7999999999999997e-97 < b Initial program 68.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6488.5
Applied rewrites88.5%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6488.5
Applied rewrites88.5%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-99)
(/ (- c) b)
(if (<= b 7.8e-97)
(/ (- (sqrt (* -4.0 (* c a)))) (+ a a))
(+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-99) {
tmp = -c / b;
} else if (b <= 7.8e-97) {
tmp = -sqrt((-4.0 * (c * a))) / (a + a);
} else {
tmp = (-b / a) + (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 <= (-9d-99)) then
tmp = -c / b
else if (b <= 7.8d-97) then
tmp = -sqrt(((-4.0d0) * (c * a))) / (a + a)
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9e-99) {
tmp = -c / b;
} else if (b <= 7.8e-97) {
tmp = -Math.sqrt((-4.0 * (c * a))) / (a + a);
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-99: tmp = -c / b elif b <= 7.8e-97: tmp = -math.sqrt((-4.0 * (c * a))) / (a + a) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-99) tmp = Float64(Float64(-c) / b); elseif (b <= 7.8e-97) tmp = Float64(Float64(-sqrt(Float64(-4.0 * Float64(c * a)))) / Float64(a + a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-99) tmp = -c / b; elseif (b <= 7.8e-97) tmp = -sqrt((-4.0 * (c * a))) / (a + a); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-99], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 7.8e-97], N[((-N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-99}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{-97}:\\
\;\;\;\;\frac{-\sqrt{-4 \cdot \left(c \cdot a\right)}}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -9.0000000000000006e-99Initial program 15.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.4
Applied rewrites90.4%
if -9.0000000000000006e-99 < b < 7.7999999999999997e-97Initial program 70.3%
Taylor expanded in a around inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
*-commutativeN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6462.8
Applied rewrites62.8%
lift-*.f64N/A
count-2-revN/A
lower-+.f6462.8
Applied rewrites62.8%
if 7.7999999999999997e-97 < b Initial program 68.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6488.5
Applied rewrites88.5%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6488.5
Applied rewrites88.5%
Final simplification81.4%
(FPCore (a b c) :precision binary64 (if (<= b -4e-209) (/ (- c) b) (if (<= b 2.5e-213) (sqrt (/ (- c) a)) (+ (/ (- b) a) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-209) {
tmp = -c / b;
} else if (b <= 2.5e-213) {
tmp = sqrt((-c / a));
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4d-209)) then
tmp = -c / b
else if (b <= 2.5d-213) then
tmp = sqrt((-c / a))
else
tmp = (-b / a) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-209) {
tmp = -c / b;
} else if (b <= 2.5e-213) {
tmp = Math.sqrt((-c / a));
} else {
tmp = (-b / a) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-209: tmp = -c / b elif b <= 2.5e-213: tmp = math.sqrt((-c / a)) else: tmp = (-b / a) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-209) tmp = Float64(Float64(-c) / b); elseif (b <= 2.5e-213) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-209) tmp = -c / b; elseif (b <= 2.5e-213) tmp = sqrt((-c / a)); else tmp = (-b / a) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-209], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.5e-213], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-209}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-213}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -4.0000000000000002e-209Initial program 23.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6481.2
Applied rewrites81.2%
if -4.0000000000000002e-209 < b < 2.49999999999999989e-213Initial program 65.7%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6446.9
Applied rewrites46.9%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6446.9
Applied rewrites46.9%
if 2.49999999999999989e-213 < b Initial program 70.8%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6478.4
Applied rewrites78.4%
lift-/.f64N/A
lift-/.f64N/A
lift-fma.f64N/A
*-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f6478.4
Applied rewrites78.4%
Final simplification74.8%
(FPCore (a b c) :precision binary64 (if (<= b -4e-209) (/ (- c) b) (if (<= b 2.5e-213) (sqrt (/ (- c) a)) (/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-209) {
tmp = -c / b;
} else if (b <= 2.5e-213) {
tmp = sqrt((-c / a));
} else {
tmp = -b / a;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4d-209)) then
tmp = -c / b
else if (b <= 2.5d-213) then
tmp = sqrt((-c / a))
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-209) {
tmp = -c / b;
} else if (b <= 2.5e-213) {
tmp = Math.sqrt((-c / a));
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-209: tmp = -c / b elif b <= 2.5e-213: tmp = math.sqrt((-c / a)) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-209) tmp = Float64(Float64(-c) / b); elseif (b <= 2.5e-213) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-209) tmp = -c / b; elseif (b <= 2.5e-213) tmp = sqrt((-c / a)); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-209], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.5e-213], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-209}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-213}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.0000000000000002e-209Initial program 23.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6481.2
Applied rewrites81.2%
if -4.0000000000000002e-209 < b < 2.49999999999999989e-213Initial program 65.7%
Taylor expanded in a around -inf
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6446.9
Applied rewrites46.9%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f64N/A
lift-/.f6446.9
Applied rewrites46.9%
if 2.49999999999999989e-213 < b Initial program 70.8%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6477.5
Applied rewrites77.5%
Final simplification74.5%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-310)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 30.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6469.8
Applied rewrites69.8%
if -4.999999999999985e-310 < b Initial program 70.0%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-neg.f6466.5
Applied rewrites66.5%
Final simplification68.3%
(FPCore (a b c) :precision binary64 (/ (- c) b))
double code(double a, double b, double c) {
return -c / b;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -c / b
end function
public static double code(double a, double b, double c) {
return -c / b;
}
def code(a, b, c): return -c / b
function code(a, b, c) return Float64(Float64(-c) / b) end
function tmp = code(a, b, c) tmp = -c / b; end
code[a_, b_, c_] := N[((-c) / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{-c}{b}
\end{array}
Initial program 48.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6438.0
Applied rewrites38.0%
Final simplification38.0%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 48.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6433.1
Applied rewrites33.1%
Taylor expanded in a around inf
lift-/.f6410.0
Applied rewrites10.0%
herbie shell --seed 2025085
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))