
(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 -4.5e+77)
(* (/ b a) -1.0)
(if (<= b 125000000000.0)
(+
(* -1.0 (/ b (* 2.0 a)))
(/ (pow (fma (* c -4.0) a (* b b)) 0.5) (* 2.0 a)))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e+77) {
tmp = (b / a) * -1.0;
} else if (b <= 125000000000.0) {
tmp = (-1.0 * (b / (2.0 * a))) + (pow(fma((c * -4.0), a, (b * b)), 0.5) / (2.0 * a));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4.5e+77) tmp = Float64(Float64(b / a) * -1.0); elseif (b <= 125000000000.0) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64((fma(Float64(c * -4.0), a, Float64(b * b)) ^ 0.5) / Float64(2.0 * a))); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4.5e+77], N[(N[(b / a), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, 125000000000.0], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[(c * -4.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{+77}:\\
\;\;\;\;\frac{b}{a} \cdot -1\\
\mathbf{elif}\;b \leq 125000000000:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + \frac{{\left(\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)\right)}^{0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -4.50000000000000024e77Initial program 66.1%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6497.0
Applied rewrites97.0%
if -4.50000000000000024e77 < b < 1.25e11Initial program 72.9%
lift-*.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-addN/A
lower-+.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites73.0%
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
pow-prod-upN/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6473.0
Applied rewrites73.0%
if 1.25e11 < b Initial program 13.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6487.6
Applied rewrites87.6%
Final simplification82.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4e+77)
(* (/ b a) -1.0)
(if (<= b 1.7e-48)
(+
(* -1.0 (/ b (* 2.0 a)))
(/ (exp (* (log (fma (* c -4.0) a (* b b))) 0.5)) (* 2.0 a)))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+77) {
tmp = (b / a) * -1.0;
} else if (b <= 1.7e-48) {
tmp = (-1.0 * (b / (2.0 * a))) + (exp((log(fma((c * -4.0), a, (b * b))) * 0.5)) / (2.0 * a));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e+77) tmp = Float64(Float64(b / a) * -1.0); elseif (b <= 1.7e-48) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64(exp(Float64(log(fma(Float64(c * -4.0), a, Float64(b * b))) * 0.5)) / Float64(2.0 * a))); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e+77], N[(N[(b / a), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, 1.7e-48], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(N[Log[N[(N[(c * -4.0), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+77}:\\
\;\;\;\;\frac{b}{a} \cdot -1\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-48}:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + \frac{e^{\log \left(\mathsf{fma}\left(c \cdot -4, a, b \cdot b\right)\right) \cdot 0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -3.99999999999999993e77Initial program 66.1%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6497.0
Applied rewrites97.0%
if -3.99999999999999993e77 < b < 1.70000000000000014e-48Initial program 75.1%
lift-*.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-addN/A
lower-+.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites75.2%
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
pow-prod-upN/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6475.2
Applied rewrites75.2%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f6471.0
Applied rewrites71.0%
if 1.70000000000000014e-48 < b Initial program 20.2%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6480.9
Applied rewrites80.9%
Final simplification80.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4e+77)
(* (/ b a) -1.0)
(if (<= b 1.7e-48)
(+
(* -1.0 (/ b (* 2.0 a)))
(/ (exp (* (log (fma b b (* (* -4.0 a) c))) 0.5)) (* 2.0 a)))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+77) {
tmp = (b / a) * -1.0;
} else if (b <= 1.7e-48) {
tmp = (-1.0 * (b / (2.0 * a))) + (exp((log(fma(b, b, ((-4.0 * a) * c))) * 0.5)) / (2.0 * a));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e+77) tmp = Float64(Float64(b / a) * -1.0); elseif (b <= 1.7e-48) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64(exp(Float64(log(fma(b, b, Float64(Float64(-4.0 * a) * c))) * 0.5)) / Float64(2.0 * a))); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e+77], N[(N[(b / a), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, 1.7e-48], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(N[Log[N[(b * b + N[(N[(-4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+77}:\\
\;\;\;\;\frac{b}{a} \cdot -1\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-48}:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + \frac{e^{\log \left(\mathsf{fma}\left(b, b, \left(-4 \cdot a\right) \cdot c\right)\right) \cdot 0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -3.99999999999999993e77Initial program 66.1%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f6497.0
Applied rewrites97.0%
if -3.99999999999999993e77 < b < 1.70000000000000014e-48Initial program 75.1%
lift-*.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-addN/A
lower-+.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites75.2%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
Applied rewrites71.0%
if 1.70000000000000014e-48 < b Initial program 20.2%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6480.9
Applied rewrites80.9%
Final simplification80.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.04e-110)
(* (fma (/ c b) -1.0 (/ b a)) -1.0)
(if (<= b 6e-64)
(+
(* -1.0 (/ b (* 2.0 a)))
(/
(exp (* (+ (+ (log 4.0) (log a)) (log (pow (/ -1.0 c) -1.0))) 0.5))
(* 2.0 a)))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.04e-110) {
tmp = fma((c / b), -1.0, (b / a)) * -1.0;
} else if (b <= 6e-64) {
tmp = (-1.0 * (b / (2.0 * a))) + (exp((((log(4.0) + log(a)) + log(pow((-1.0 / c), -1.0))) * 0.5)) / (2.0 * a));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.04e-110) tmp = Float64(fma(Float64(c / b), -1.0, Float64(b / a)) * -1.0); elseif (b <= 6e-64) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64(exp(Float64(Float64(Float64(log(4.0) + log(a)) + log((Float64(-1.0 / c) ^ -1.0))) * 0.5)) / Float64(2.0 * a))); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.04e-110], N[(N[(N[(c / b), $MachinePrecision] * -1.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, 6e-64], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(N[(N[(N[Log[4.0], $MachinePrecision] + N[Log[a], $MachinePrecision]), $MachinePrecision] + N[Log[N[Power[N[(-1.0 / c), $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.04 \cdot 10^{-110}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b}, -1, \frac{b}{a}\right) \cdot -1\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-64}:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + \frac{e^{\left(\left(\log 4 + \log a\right) + \log \left({\left(\frac{-1}{c}\right)}^{-1}\right)\right) \cdot 0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -1.03999999999999993e-110Initial program 77.4%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6485.6
Applied rewrites85.6%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-/.f6485.9
Applied rewrites85.9%
if -1.03999999999999993e-110 < b < 6.0000000000000001e-64Initial program 65.3%
lift-*.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-addN/A
lower-+.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-*.f64N/A
lift-*.f64N/A
lower-/.f64N/A
Applied rewrites65.3%
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
pow-prod-upN/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6465.3
Applied rewrites65.3%
lift-pow.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f6461.4
Applied rewrites61.4%
Taylor expanded in c around -inf
lower-+.f64N/A
log-prodN/A
lower-+.f64N/A
lower-log.f64N/A
lower-log.f64N/A
log-pow-revN/A
lower-log.f64N/A
lower-pow.f64N/A
lower-/.f6446.2
Applied rewrites46.2%
if 6.0000000000000001e-64 < b Initial program 23.8%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6477.8
Applied rewrites77.8%
Final simplification71.1%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (* (fma (/ c b) -1.0 (/ b a)) -1.0) (* (/ c b) -1.0)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = fma((c / b), -1.0, (b / a)) * -1.0;
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(fma(Float64(c / b), -1.0, Float64(b / a)) * -1.0); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(N[(c / b), $MachinePrecision] * -1.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * -1.0), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b}, -1, \frac{b}{a}\right) \cdot -1\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.4%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6466.4
Applied rewrites66.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-/.f6468.2
Applied rewrites68.2%
if -4.999999999999985e-310 < b Initial program 39.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6456.0
Applied rewrites56.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (* (fma (/ c b) -1.0 (/ b a)) -1.0) (* (/ 1.0 (* -1.0 b)) c)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = fma((c / b), -1.0, (b / a)) * -1.0;
} else {
tmp = (1.0 / (-1.0 * b)) * c;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(fma(Float64(c / b), -1.0, Float64(b / a)) * -1.0); else tmp = Float64(Float64(1.0 / Float64(-1.0 * b)) * c); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(N[(c / b), $MachinePrecision] * -1.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * -1.0), $MachinePrecision], N[(N[(1.0 / N[(-1.0 * b), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b}, -1, \frac{b}{a}\right) \cdot -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 \cdot b} \cdot c\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.4%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6466.4
Applied rewrites66.4%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-/.f6468.2
Applied rewrites68.2%
if -4.999999999999985e-310 < b Initial program 39.1%
Taylor expanded in c around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites41.8%
Taylor expanded in a around 0
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
lower-neg.f6455.9
Applied rewrites55.9%
Final simplification62.5%
(FPCore (a b c) :precision binary64 (* (fma (/ c b) -1.0 (/ b a)) -1.0))
double code(double a, double b, double c) {
return fma((c / b), -1.0, (b / a)) * -1.0;
}
function code(a, b, c) return Float64(fma(Float64(c / b), -1.0, Float64(b / a)) * -1.0) end
code[a_, b_, c_] := N[(N[(N[(c / b), $MachinePrecision] * -1.0 + N[(b / a), $MachinePrecision]), $MachinePrecision] * -1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{c}{b}, -1, \frac{b}{a}\right) \cdot -1
\end{array}
Initial program 58.1%
Taylor expanded in b around -inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
inv-powN/A
lower-pow.f6436.6
Applied rewrites36.6%
Taylor expanded in a around inf
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lift-/.f6437.6
Applied rewrites37.6%
herbie shell --seed 2025065
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))