
(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}
Herbie found 8 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
(fma
a
(/
(*
(fma (/ (fma -5.0 (/ (* (* a a) c) (* b b)) (* -2.0 a)) (* b b)) c -1.0)
(* c c))
(* (* b b) b))
(/ (- c) b)))
double code(double a, double b, double c) {
return fma(a, ((fma((fma(-5.0, (((a * a) * c) / (b * b)), (-2.0 * a)) / (b * b)), c, -1.0) * (c * c)) / ((b * b) * b)), (-c / b));
}
function code(a, b, c) return fma(a, Float64(Float64(fma(Float64(fma(-5.0, Float64(Float64(Float64(a * a) * c) / Float64(b * b)), Float64(-2.0 * a)) / Float64(b * b)), c, -1.0) * Float64(c * c)) / Float64(Float64(b * b) * b)), Float64(Float64(-c) / b)) end
code[a_, b_, c_] := N[(a * N[(N[(N[(N[(N[(-5.0 * N[(N[(N[(a * a), $MachinePrecision] * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * a), $MachinePrecision]), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] * c + -1.0), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision] + N[((-c) / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, \frac{\mathsf{fma}\left(\frac{\mathsf{fma}\left(-5, \frac{\left(a \cdot a\right) \cdot c}{b \cdot b}, -2 \cdot a\right)}{b \cdot b}, c, -1\right) \cdot \left(c \cdot c\right)}{\left(b \cdot b\right) \cdot b}, \frac{-c}{b}\right)
\end{array}
Initial program 55.3%
Taylor expanded in a around 0
Applied rewrites90.9%
Taylor expanded in b around inf
Applied rewrites90.9%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites90.9%
Taylor expanded in b around inf
lower-/.f64N/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lift-*.f64N/A
lower-*.f64N/A
pow2N/A
lift-*.f6490.9
Applied rewrites90.9%
(FPCore (a b c)
:precision binary64
(if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) -4.0)
(/ (+ (sqrt (fma -4.0 (* c a) (* b b))) (- b)) (+ a a))
(fma
a
(/ (* (fma (* a (/ c (* b b))) -2.0 -1.0) (* c c)) (* (* b b) b))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -4.0) {
tmp = (sqrt(fma(-4.0, (c * a), (b * b))) + -b) / (a + a);
} else {
tmp = fma(a, ((fma((a * (c / (b * b))), -2.0, -1.0) * (c * c)) / ((b * b) * b)), (-c / b));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) <= -4.0) tmp = Float64(Float64(sqrt(fma(-4.0, Float64(c * a), Float64(b * b))) + Float64(-b)) / Float64(a + a)); else tmp = fma(a, Float64(Float64(fma(Float64(a * Float64(c / Float64(b * b))), -2.0, -1.0) * Float64(c * c)) / Float64(Float64(b * b) * b)), Float64(Float64(-c) / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -4.0], N[(N[(N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + (-b)), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], N[(a * N[(N[(N[(N[(a * N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -2.0 + -1.0), $MachinePrecision] * N[(c * c), $MachinePrecision]), $MachinePrecision] / N[(N[(b * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision] + N[((-c) / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \leq -4:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)} + \left(-b\right)}{a + a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{\mathsf{fma}\left(a \cdot \frac{c}{b \cdot b}, -2, -1\right) \cdot \left(c \cdot c\right)}{\left(b \cdot b\right) \cdot b}, \frac{-c}{b}\right)\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -4Initial program 83.6%
lift-*.f64N/A
pow2N/A
metadata-evalN/A
pow-negN/A
lower-/.f64N/A
lower-pow.f6483.4
Applied rewrites83.4%
Applied rewrites83.6%
if -4 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 51.5%
Taylor expanded in a around 0
Applied rewrites93.1%
Taylor expanded in b around inf
Applied rewrites93.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
negate-subN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
lift-*.f6490.5
Applied rewrites90.5%
(FPCore (a b c) :precision binary64 (if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) -3e-5) (/ (+ (- b) (sqrt (fma b b (* -4.0 (* c a))))) (* 2.0 a)) (- (/ (fma a (/ (* c c) (* b b)) c) b))))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -3e-5) {
tmp = (-b + sqrt(fma(b, b, (-4.0 * (c * a))))) / (2.0 * a);
} else {
tmp = -(fma(a, ((c * c) / (b * b)), c) / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) <= -3e-5) tmp = Float64(Float64(Float64(-b) + sqrt(fma(b, b, Float64(-4.0 * Float64(c * a))))) / Float64(2.0 * a)); else tmp = Float64(-Float64(fma(a, Float64(Float64(c * c) / Float64(b * b)), c) / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -3e-5], N[(N[((-b) + N[Sqrt[N[(b * b + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], (-N[(N[(a * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / b), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \leq -3 \cdot 10^{-5}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\mathsf{fma}\left(a, \frac{c \cdot c}{b \cdot b}, c\right)}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -3.00000000000000008e-5Initial program 73.9%
lift-*.f64N/A
lift--.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
fp-cancel-sub-sign-invN/A
pow2N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6474.0
Applied rewrites74.0%
if -3.00000000000000008e-5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 38.4%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6492.7
Applied rewrites92.7%
Applied rewrites92.7%
(FPCore (a b c) :precision binary64 (if (<= (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) -3e-5) (/ (+ (sqrt (fma -4.0 (* c a) (* b b))) (- b)) (+ a a)) (- (/ (fma a (/ (* c c) (* b b)) c) b))))
double code(double a, double b, double c) {
double tmp;
if (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)) <= -3e-5) {
tmp = (sqrt(fma(-4.0, (c * a), (b * b))) + -b) / (a + a);
} else {
tmp = -(fma(a, ((c * c) / (b * b)), c) / b);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) <= -3e-5) tmp = Float64(Float64(sqrt(fma(-4.0, Float64(c * a), Float64(b * b))) + Float64(-b)) / Float64(a + a)); else tmp = Float64(-Float64(fma(a, Float64(Float64(c * c) / Float64(b * b)), c) / b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[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], -3e-5], N[(N[(N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + (-b)), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], (-N[(N[(a * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / b), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \leq -3 \cdot 10^{-5}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)} + \left(-b\right)}{a + a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\mathsf{fma}\left(a, \frac{c \cdot c}{b \cdot b}, c\right)}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -3.00000000000000008e-5Initial program 73.9%
lift-*.f64N/A
pow2N/A
metadata-evalN/A
pow-negN/A
lower-/.f64N/A
lower-pow.f6473.6
Applied rewrites73.6%
Applied rewrites73.9%
if -3.00000000000000008e-5 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 38.4%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6492.7
Applied rewrites92.7%
Applied rewrites92.7%
(FPCore (a b c) :precision binary64 (- (/ (- (* (* c c) a)) (* (* b b) b)) (/ c b)))
double code(double a, double b, double c) {
return (-((c * c) * a) / ((b * b) * b)) - (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 * c) * a) / ((b * b) * b)) - (c / b)
end function
public static double code(double a, double b, double c) {
return (-((c * c) * a) / ((b * b) * b)) - (c / b);
}
def code(a, b, c): return (-((c * c) * a) / ((b * b) * b)) - (c / b)
function code(a, b, c) return Float64(Float64(Float64(-Float64(Float64(c * c) * a)) / Float64(Float64(b * b) * b)) - Float64(c / b)) end
function tmp = code(a, b, c) tmp = (-((c * c) * a) / ((b * b) * b)) - (c / b); end
code[a_, b_, c_] := N[(N[((-N[(N[(c * c), $MachinePrecision] * a), $MachinePrecision]) / N[(N[(b * b), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\left(c \cdot c\right) \cdot a}{\left(b \cdot b\right) \cdot b} - \frac{c}{b}
\end{array}
Initial program 55.3%
Taylor expanded in a around 0
Applied rewrites90.9%
Taylor expanded in b around inf
Applied rewrites90.9%
Taylor expanded in a around 0
+-commutativeN/A
mul-1-negN/A
negate-subN/A
lower--.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
pow3N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f6481.7
Applied rewrites81.7%
(FPCore (a b c) :precision binary64 (/ (+ (- c) (- (/ (* (* c c) a) (* b b)))) b))
double code(double a, double b, double c) {
return (-c + -(((c * c) * a) / (b * b))) / 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 + -(((c * c) * a) / (b * b))) / b
end function
public static double code(double a, double b, double c) {
return (-c + -(((c * c) * a) / (b * b))) / b;
}
def code(a, b, c): return (-c + -(((c * c) * a) / (b * b))) / b
function code(a, b, c) return Float64(Float64(Float64(-c) + Float64(-Float64(Float64(Float64(c * c) * a) / Float64(b * b)))) / b) end
function tmp = code(a, b, c) tmp = (-c + -(((c * c) * a) / (b * b))) / b; end
code[a_, b_, c_] := N[(N[((-c) + (-N[(N[(N[(c * c), $MachinePrecision] * a), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision])), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-c\right) + \left(-\frac{\left(c \cdot c\right) \cdot a}{b \cdot b}\right)}{b}
\end{array}
Initial program 55.3%
Taylor expanded in b around inf
lower-/.f64N/A
mul-1-negN/A
lower-+.f64N/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f6481.7
Applied rewrites81.7%
(FPCore (a b c) :precision binary64 (- (/ (fma a (/ (* c c) (* b b)) c) b)))
double code(double a, double b, double c) {
return -(fma(a, ((c * c) / (b * b)), c) / b);
}
function code(a, b, c) return Float64(-Float64(fma(a, Float64(Float64(c * c) / Float64(b * b)), c) / b)) end
code[a_, b_, c_] := (-N[(N[(a * N[(N[(c * c), $MachinePrecision] / N[(b * b), $MachinePrecision]), $MachinePrecision] + c), $MachinePrecision] / b), $MachinePrecision])
\begin{array}{l}
\\
-\frac{\mathsf{fma}\left(a, \frac{c \cdot c}{b \cdot b}, c\right)}{b}
\end{array}
Initial program 55.3%
Taylor expanded in a around 0
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow3N/A
pow2N/A
lower-*.f64N/A
pow2N/A
lift-*.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6481.7
Applied rewrites81.7%
Applied rewrites81.7%
(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 55.3%
Taylor expanded in a around 0
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6464.5
Applied rewrites64.5%
herbie shell --seed 2025116
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))