
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e+143)
(/ (- b) a)
(if (<= b 3.5e-53)
(/ (- (sqrt (fma (* -4.0 a) c (* b b))) b) (+ a a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e+143) {
tmp = -b / a;
} else if (b <= 3.5e-53) {
tmp = (sqrt(fma((-4.0 * a), c, (b * b))) - b) / (a + a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9.5e+143) tmp = Float64(Float64(-b) / a); elseif (b <= 3.5e-53) tmp = Float64(Float64(sqrt(fma(Float64(-4.0 * a), c, Float64(b * b))) - b) / Float64(a + a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9.5e+143], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.5e-53], N[(N[(N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{+143}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-53}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)} - b}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.50000000000000066e143Initial program 45.4%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6496.4
Applied rewrites96.4%
if -9.50000000000000066e143 < b < 3.49999999999999993e-53Initial program 82.0%
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
pow2N/A
associate-*r*N/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
lower-*.f64N/A
lower-neg.f6482.0
Applied rewrites82.0%
count-2-revN/A
lower-+.f6482.0
Applied rewrites82.0%
if 3.49999999999999993e-53 < b Initial program 11.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6490.7
Applied rewrites90.7%
Final simplification87.3%
(FPCore (a b c) :precision binary64 (if (<= b -8e-12) (/ (- b) a) (if (<= b 3.4e-53) (/ (fma b -0.5 (sqrt (* a (- c)))) a) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-12) {
tmp = -b / a;
} else if (b <= 3.4e-53) {
tmp = fma(b, -0.5, sqrt((a * -c))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -8e-12) tmp = Float64(Float64(-b) / a); elseif (b <= 3.4e-53) tmp = Float64(fma(b, -0.5, sqrt(Float64(a * Float64(-c)))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -8e-12], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.4e-53], N[(N[(b * -0.5 + N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-12}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-53}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, -0.5, \sqrt{a \cdot \left(-c\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.99999999999999984e-12Initial program 70.4%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6491.0
Applied rewrites91.0%
if -7.99999999999999984e-12 < b < 3.4e-53Initial program 74.3%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6439.7
Applied rewrites39.7%
Taylor expanded in a around -inf
lower-fma.f64N/A
lower-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6439.7
Applied rewrites39.7%
Taylor expanded in a around 0
lower-/.f64N/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6467.2
Applied rewrites67.2%
*-commutativeN/A
sqrt-prodN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f6467.2
Applied rewrites67.2%
if 3.4e-53 < b Initial program 11.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6490.7
Applied rewrites90.7%
Final simplification82.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (/ (- c) a))))
(if (<= b -2.5e-161)
(/ (- b) a)
(if (<= b 4.5e-270) (- t_0) (if (<= b 2.2e-93) t_0 (/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = sqrt((-c / a));
double tmp;
if (b <= -2.5e-161) {
tmp = -b / a;
} else if (b <= 4.5e-270) {
tmp = -t_0;
} else if (b <= 2.2e-93) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((-c / a))
if (b <= (-2.5d-161)) then
tmp = -b / a
else if (b <= 4.5d-270) then
tmp = -t_0
else if (b <= 2.2d-93) then
tmp = t_0
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt((-c / a));
double tmp;
if (b <= -2.5e-161) {
tmp = -b / a;
} else if (b <= 4.5e-270) {
tmp = -t_0;
} else if (b <= 2.2e-93) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt((-c / a)) tmp = 0 if b <= -2.5e-161: tmp = -b / a elif b <= 4.5e-270: tmp = -t_0 elif b <= 2.2e-93: tmp = t_0 else: tmp = -c / b return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(-c) / a)) tmp = 0.0 if (b <= -2.5e-161) tmp = Float64(Float64(-b) / a); elseif (b <= 4.5e-270) tmp = Float64(-t_0); elseif (b <= 2.2e-93) tmp = t_0; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt((-c / a)); tmp = 0.0; if (b <= -2.5e-161) tmp = -b / a; elseif (b <= 4.5e-270) tmp = -t_0; elseif (b <= 2.2e-93) tmp = t_0; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2.5e-161], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.5e-270], (-t$95$0), If[LessEqual[b, 2.2e-93], t$95$0, N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{-c}{a}}\\
\mathbf{if}\;b \leq -2.5 \cdot 10^{-161}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{-270}:\\
\;\;\;\;-t\_0\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-93}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.5e-161Initial program 74.4%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6482.6
Applied rewrites82.6%
if -2.5e-161 < b < 4.49999999999999998e-270Initial program 78.5%
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
pow2N/A
associate-*r*N/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
lower-*.f64N/A
lower-neg.f6478.5
Applied rewrites78.5%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6447.4
Applied rewrites47.4%
sqrt-prodN/A
lower-neg.f64N/A
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6447.4
Applied rewrites47.4%
if 4.49999999999999998e-270 < b < 2.19999999999999996e-93Initial program 62.0%
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
pow2N/A
associate-*r*N/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
lower-*.f64N/A
lower-neg.f6462.0
Applied rewrites62.0%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6431.7
Applied rewrites31.7%
Taylor expanded in c around -inf
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6452.1
Applied rewrites52.1%
if 2.19999999999999996e-93 < b Initial program 15.0%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6487.7
Applied rewrites87.7%
(FPCore (a b c) :precision binary64 (if (<= b -5.6e-145) (/ (- b) a) (if (<= b 3.4e-53) (/ (sqrt (* a (- c))) a) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.6e-145) {
tmp = -b / a;
} else if (b <= 3.4e-53) {
tmp = sqrt((a * -c)) / a;
} else {
tmp = -c / b;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5.6d-145)) then
tmp = -b / a
else if (b <= 3.4d-53) then
tmp = sqrt((a * -c)) / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.6e-145) {
tmp = -b / a;
} else if (b <= 3.4e-53) {
tmp = Math.sqrt((a * -c)) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.6e-145: tmp = -b / a elif b <= 3.4e-53: tmp = math.sqrt((a * -c)) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.6e-145) tmp = Float64(Float64(-b) / a); elseif (b <= 3.4e-53) tmp = Float64(sqrt(Float64(a * Float64(-c))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.6e-145) tmp = -b / a; elseif (b <= 3.4e-53) tmp = sqrt((a * -c)) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.6e-145], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.4e-53], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.6 \cdot 10^{-145}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-53}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.6000000000000002e-145Initial program 73.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6484.8
Applied rewrites84.8%
if -5.6000000000000002e-145 < b < 3.4e-53Initial program 70.3%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6440.2
Applied rewrites40.2%
Taylor expanded in a around -inf
lower-fma.f64N/A
lower-/.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6440.2
Applied rewrites40.2%
Taylor expanded in a around 0
lower-/.f64N/A
lower-fma.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6470.4
Applied rewrites70.4%
Taylor expanded in a around inf
sqrt-unprodN/A
*-commutativeN/A
mul-1-negN/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f6469.8
Applied rewrites69.8%
if 3.4e-53 < b Initial program 11.9%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6490.7
Applied rewrites90.7%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (if (<= b -1.72e-152) (/ (- b) a) (if (<= b 2.2e-93) (sqrt (/ (- c) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.72e-152) {
tmp = -b / a;
} else if (b <= 2.2e-93) {
tmp = sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.72d-152)) then
tmp = -b / a
else if (b <= 2.2d-93) then
tmp = sqrt((-c / a))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.72e-152) {
tmp = -b / a;
} else if (b <= 2.2e-93) {
tmp = Math.sqrt((-c / a));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.72e-152: tmp = -b / a elif b <= 2.2e-93: tmp = math.sqrt((-c / a)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.72e-152) tmp = Float64(Float64(-b) / a); elseif (b <= 2.2e-93) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.72e-152) tmp = -b / a; elseif (b <= 2.2e-93) tmp = sqrt((-c / a)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.72e-152], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.2e-93], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.72 \cdot 10^{-152}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-93}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.72e-152Initial program 73.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6484.1
Applied rewrites84.1%
if -1.72e-152 < b < 2.19999999999999996e-93Initial program 69.5%
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
pow2N/A
associate-*r*N/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
lower-*.f64N/A
lower-neg.f6469.5
Applied rewrites69.5%
Taylor expanded in a around -inf
mul-1-negN/A
lower-neg.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6437.0
Applied rewrites37.0%
Taylor expanded in c around -inf
sqrt-prodN/A
lower-sqrt.f64N/A
*-commutativeN/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6441.6
Applied rewrites41.6%
if 2.19999999999999996e-93 < b Initial program 15.0%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6487.7
Applied rewrites87.7%
(FPCore (a b c) :precision binary64 (if (<= b 1.4e-257) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.4e-257) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 1.4d-257) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.4e-257) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.4e-257: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.4e-257) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.4e-257) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.4e-257], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.4 \cdot 10^{-257}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.40000000000000001e-257Initial program 73.8%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6467.0
Applied rewrites67.0%
if 1.40000000000000001e-257 < b Initial program 30.1%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6466.3
Applied rewrites66.3%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / a;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -b / a
end function
public static double code(double a, double b, double c) {
return -b / a;
}
def code(a, b, c): return -b / a
function code(a, b, c) return Float64(Float64(-b) / a) end
function tmp = code(a, b, c) tmp = -b / a; end
code[a_, b_, c_] := N[((-b) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b}{a}
\end{array}
Initial program 53.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6437.3
Applied rewrites37.3%
herbie shell --seed 2025044
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))