
(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 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(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 -1.35e+69)
(+ (/ (- b) a) (/ c b))
(if (<= b 4.9e-67)
(/ (- (sqrt (fma (* -4.0 a) c (* b b))) b) (* 2.0 a))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e+69) {
tmp = (-b / a) + (c / b);
} else if (b <= 4.9e-67) {
tmp = (sqrt(fma((-4.0 * a), c, (b * b))) - b) / (2.0 * a);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.35e+69) tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); elseif (b <= 4.9e-67) tmp = Float64(Float64(sqrt(fma(Float64(-4.0 * a), c, Float64(b * b))) - b) / Float64(2.0 * a)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.35e+69], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.9e-67], N[(N[(N[Sqrt[N[(N[(-4.0 * a), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{+69}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\mathbf{elif}\;b \leq 4.9 \cdot 10^{-67}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4 \cdot a, c, b \cdot b\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.3499999999999999e69Initial program 62.4%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites62.5%
Taylor expanded in b around -inf
Applied rewrites96.9%
Taylor expanded in a around inf
Applied rewrites97.1%
Applied rewrites97.1%
if -1.3499999999999999e69 < b < 4.89999999999999993e-67Initial program 73.3%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites73.3%
if 4.89999999999999993e-67 < b Initial program 12.3%
Taylor expanded in a around 0
Applied rewrites92.1%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-81)
(+ (/ (- b) a) (/ c b))
(if (<= b 4.9e-67)
(/ (+ (- b) (sqrt (* -4.0 (* c a)))) (* 2.0 a))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-81) {
tmp = (-b / a) + (c / b);
} else if (b <= 4.9e-67) {
tmp = (-b + sqrt((-4.0 * (c * a)))) / (2.0 * 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 <= (-9.5d-81)) then
tmp = (-b / a) + (c / b)
else if (b <= 4.9d-67) then
tmp = (-b + sqrt(((-4.0d0) * (c * a)))) / (2.0d0 * 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 <= -9.5e-81) {
tmp = (-b / a) + (c / b);
} else if (b <= 4.9e-67) {
tmp = (-b + Math.sqrt((-4.0 * (c * a)))) / (2.0 * a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-81: tmp = (-b / a) + (c / b) elif b <= 4.9e-67: tmp = (-b + math.sqrt((-4.0 * (c * a)))) / (2.0 * a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-81) tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); elseif (b <= 4.9e-67) tmp = Float64(Float64(Float64(-b) + sqrt(Float64(-4.0 * Float64(c * a)))) / Float64(2.0 * a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-81) tmp = (-b / a) + (c / b); elseif (b <= 4.9e-67) tmp = (-b + sqrt((-4.0 * (c * a)))) / (2.0 * a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-81], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.9e-67], N[(N[((-b) + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-81}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\mathbf{elif}\;b \leq 4.9 \cdot 10^{-67}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{-4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -9.49999999999999917e-81Initial program 69.7%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites69.8%
Taylor expanded in b around -inf
Applied rewrites88.9%
Taylor expanded in a around inf
Applied rewrites89.1%
Applied rewrites89.1%
if -9.49999999999999917e-81 < b < 4.89999999999999993e-67Initial program 67.7%
Taylor expanded in a around inf
Applied rewrites61.6%
if 4.89999999999999993e-67 < b Initial program 12.3%
Taylor expanded in a around 0
Applied rewrites92.1%
Final simplification82.9%
(FPCore (a b c) :precision binary64 (if (<= b -9.5e-81) (+ (/ (- b) a) (/ c b)) (if (<= b 4.9e-67) (/ (sqrt (* -4.0 (* c a))) (* 2.0 a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-81) {
tmp = (-b / a) + (c / b);
} else if (b <= 4.9e-67) {
tmp = sqrt((-4.0 * (c * a))) / (2.0 * 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 <= (-9.5d-81)) then
tmp = (-b / a) + (c / b)
else if (b <= 4.9d-67) then
tmp = sqrt(((-4.0d0) * (c * a))) / (2.0d0 * 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 <= -9.5e-81) {
tmp = (-b / a) + (c / b);
} else if (b <= 4.9e-67) {
tmp = Math.sqrt((-4.0 * (c * a))) / (2.0 * a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-81: tmp = (-b / a) + (c / b) elif b <= 4.9e-67: tmp = math.sqrt((-4.0 * (c * a))) / (2.0 * a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-81) tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); elseif (b <= 4.9e-67) tmp = Float64(sqrt(Float64(-4.0 * Float64(c * a))) / Float64(2.0 * a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-81) tmp = (-b / a) + (c / b); elseif (b <= 4.9e-67) tmp = sqrt((-4.0 * (c * a))) / (2.0 * a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-81], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.9e-67], N[(N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-81}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\mathbf{elif}\;b \leq 4.9 \cdot 10^{-67}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -9.49999999999999917e-81Initial program 69.7%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites69.8%
Taylor expanded in b around -inf
Applied rewrites88.9%
Taylor expanded in a around inf
Applied rewrites89.1%
Applied rewrites89.1%
if -9.49999999999999917e-81 < b < 4.89999999999999993e-67Initial program 67.7%
Taylor expanded in a around inf
Applied rewrites60.4%
if 4.89999999999999993e-67 < b Initial program 12.3%
Taylor expanded in a around 0
Applied rewrites92.1%
Final simplification82.6%
(FPCore (a b c) :precision binary64 (if (<= b -1.95e-107) (+ (/ (- b) a) (/ c b)) (if (<= b 1.08e-165) (/ (sqrt (- c)) (sqrt a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-107) {
tmp = (-b / a) + (c / b);
} else if (b <= 1.08e-165) {
tmp = sqrt(-c) / sqrt(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.95d-107)) then
tmp = (-b / a) + (c / b)
else if (b <= 1.08d-165) then
tmp = sqrt(-c) / sqrt(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.95e-107) {
tmp = (-b / a) + (c / b);
} else if (b <= 1.08e-165) {
tmp = Math.sqrt(-c) / Math.sqrt(a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.95e-107: tmp = (-b / a) + (c / b) elif b <= 1.08e-165: tmp = math.sqrt(-c) / math.sqrt(a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-107) tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); elseif (b <= 1.08e-165) tmp = Float64(sqrt(Float64(-c)) / sqrt(a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.95e-107) tmp = (-b / a) + (c / b); elseif (b <= 1.08e-165) tmp = sqrt(-c) / sqrt(a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-107], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.08e-165], N[(N[Sqrt[(-c)], $MachinePrecision] / N[Sqrt[a], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-107}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{-165}:\\
\;\;\;\;\frac{\sqrt{-c}}{\sqrt{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.95e-107Initial program 71.9%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites72.0%
Taylor expanded in b around -inf
Applied rewrites83.6%
Taylor expanded in a around inf
Applied rewrites83.8%
Applied rewrites83.8%
if -1.95e-107 < b < 1.08000000000000003e-165Initial program 67.6%
Taylor expanded in a around -inf
Applied rewrites30.9%
Taylor expanded in c around -inf
Applied rewrites43.7%
Applied rewrites50.0%
if 1.08000000000000003e-165 < b Initial program 19.5%
Taylor expanded in a around 0
Applied rewrites83.3%
Final simplification78.5%
(FPCore (a b c) :precision binary64 (if (<= b -1.95e-107) (+ (/ (- b) a) (/ c b)) (if (<= b 9.1e-203) (sqrt (/ (- c) a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-107) {
tmp = (-b / a) + (c / b);
} else if (b <= 9.1e-203) {
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.95d-107)) then
tmp = (-b / a) + (c / b)
else if (b <= 9.1d-203) 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.95e-107) {
tmp = (-b / a) + (c / b);
} else if (b <= 9.1e-203) {
tmp = Math.sqrt((-c / a));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.95e-107: tmp = (-b / a) + (c / b) elif b <= 9.1e-203: tmp = math.sqrt((-c / a)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-107) tmp = Float64(Float64(Float64(-b) / a) + Float64(c / b)); elseif (b <= 9.1e-203) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.95e-107) tmp = (-b / a) + (c / b); elseif (b <= 9.1e-203) tmp = sqrt((-c / a)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-107], N[(N[((-b) / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9.1e-203], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-107}:\\
\;\;\;\;\frac{-b}{a} + \frac{c}{b}\\
\mathbf{elif}\;b \leq 9.1 \cdot 10^{-203}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.95e-107Initial program 71.9%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites72.0%
Taylor expanded in b around -inf
Applied rewrites83.6%
Taylor expanded in a around inf
Applied rewrites83.8%
Applied rewrites83.8%
if -1.95e-107 < b < 9.1000000000000006e-203Initial program 70.2%
Taylor expanded in a around -inf
Applied rewrites30.5%
Taylor expanded in c around -inf
Applied rewrites47.2%
if 9.1000000000000006e-203 < b Initial program 19.9%
Taylor expanded in a around 0
Applied rewrites81.7%
Final simplification77.8%
(FPCore (a b c) :precision binary64 (if (<= b -1.95e-107) (/ (- b) a) (if (<= b 9.1e-203) (sqrt (/ (- c) a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-107) {
tmp = -b / a;
} else if (b <= 9.1e-203) {
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.95d-107)) then
tmp = -b / a
else if (b <= 9.1d-203) 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.95e-107) {
tmp = -b / a;
} else if (b <= 9.1e-203) {
tmp = Math.sqrt((-c / a));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.95e-107: tmp = -b / a elif b <= 9.1e-203: tmp = math.sqrt((-c / a)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-107) tmp = Float64(Float64(-b) / a); elseif (b <= 9.1e-203) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.95e-107) tmp = -b / a; elseif (b <= 9.1e-203) tmp = sqrt((-c / a)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-107], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 9.1e-203], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-107}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 9.1 \cdot 10^{-203}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.95e-107Initial program 71.9%
Taylor expanded in b around -inf
Applied rewrites83.2%
if -1.95e-107 < b < 9.1000000000000006e-203Initial program 70.2%
Taylor expanded in a around -inf
Applied rewrites30.5%
Taylor expanded in c around -inf
Applied rewrites47.2%
if 9.1000000000000006e-203 < b Initial program 19.9%
Taylor expanded in a around 0
Applied rewrites81.7%
Final simplification77.6%
(FPCore (a b c) :precision binary64 (if (<= b 1e-272) (/ (- b) a) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1e-272) {
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 <= 1d-272) 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 <= 1e-272) {
tmp = -b / a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1e-272: tmp = -b / a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1e-272) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1e-272) tmp = -b / a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1e-272], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-272}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 9.9999999999999993e-273Initial program 72.3%
Taylor expanded in b around -inf
Applied rewrites69.7%
if 9.9999999999999993e-273 < b Initial program 23.2%
Taylor expanded in a around 0
Applied rewrites75.5%
Final simplification72.5%
(FPCore (a b c) :precision binary64 (if (<= b 8.5e-12) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 8.5e-12) {
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 <= 8.5d-12) 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 <= 8.5e-12) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 8.5e-12: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 8.5e-12) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 8.5e-12) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 8.5e-12], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.5 \cdot 10^{-12}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 8.4999999999999997e-12Initial program 65.7%
Taylor expanded in b around -inf
Applied rewrites53.6%
if 8.4999999999999997e-12 < b Initial program 12.2%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites12.2%
Taylor expanded in b around -inf
Applied rewrites2.2%
Taylor expanded in a around inf
Applied rewrites32.2%
(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.3%
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites48.4%
Taylor expanded in b around -inf
Applied rewrites36.3%
Taylor expanded in a around inf
Applied rewrites12.6%
herbie shell --seed 2025026
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))