
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -9.8e+119)
(/ (+ (* -1.0 b) (* -1.0 b)) (* 2.0 a))
(if (<= b 2.65e-118)
(+
(* -1.0 (/ b (* 2.0 a)))
(/ (pow (fma (pow b 1.0) (pow b 1.0) (* -4.0 (* c a))) 0.5) (* 2.0 a)))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.8e+119) {
tmp = ((-1.0 * b) + (-1.0 * b)) / (2.0 * a);
} else if (b <= 2.65e-118) {
tmp = (-1.0 * (b / (2.0 * a))) + (pow(fma(pow(b, 1.0), pow(b, 1.0), (-4.0 * (c * a))), 0.5) / (2.0 * a));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9.8e+119) tmp = Float64(Float64(Float64(-1.0 * b) + Float64(-1.0 * b)) / Float64(2.0 * a)); elseif (b <= 2.65e-118) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64((fma((b ^ 1.0), (b ^ 1.0), Float64(-4.0 * Float64(c * a))) ^ 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, -9.8e+119], N[(N[(N[(-1.0 * b), $MachinePrecision] + N[(-1.0 * b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.65e-118], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[Power[b, 1.0], $MachinePrecision] * N[Power[b, 1.0], $MachinePrecision] + N[(-4.0 * N[(c * a), $MachinePrecision]), $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 -9.8 \cdot 10^{+119}:\\
\;\;\;\;\frac{-1 \cdot b + -1 \cdot b}{2 \cdot a}\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{-118}:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + \frac{{\left(\mathsf{fma}\left({b}^{1}, {b}^{1}, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -9.79999999999999992e119Initial program 51.9%
Taylor expanded in b around -inf
lower-*.f6497.1
Applied rewrites97.1%
if -9.79999999999999992e119 < b < 2.65000000000000019e-118Initial program 77.4%
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 rewrites77.4%
if 2.65000000000000019e-118 < b Initial program 14.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6488.1
Applied rewrites88.1%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e+120)
(* (* (fma (/ c (* b b)) -1.0 (pow a -1.0)) b) -1.0)
(if (<= b 2.65e-118)
(+
(* -1.0 (/ b (* 2.0 a)))
(/ (pow (fma (pow b 1.0) (pow b 1.0) (* -4.0 (* c a))) 0.5) (* 2.0 a)))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e+120) {
tmp = (fma((c / (b * b)), -1.0, pow(a, -1.0)) * b) * -1.0;
} else if (b <= 2.65e-118) {
tmp = (-1.0 * (b / (2.0 * a))) + (pow(fma(pow(b, 1.0), pow(b, 1.0), (-4.0 * (c * a))), 0.5) / (2.0 * a));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.2e+120) tmp = Float64(Float64(fma(Float64(c / Float64(b * b)), -1.0, (a ^ -1.0)) * b) * -1.0); elseif (b <= 2.65e-118) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64((fma((b ^ 1.0), (b ^ 1.0), Float64(-4.0 * Float64(c * a))) ^ 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.2e+120], N[(N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -1.0 + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, 2.65e-118], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[Power[b, 1.0], $MachinePrecision] * N[Power[b, 1.0], $MachinePrecision] + N[(-4.0 * N[(c * a), $MachinePrecision]), $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 -1.2 \cdot 10^{+120}:\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{c}{b \cdot b}, -1, {a}^{-1}\right) \cdot b\right) \cdot -1\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{-118}:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + \frac{{\left(\mathsf{fma}\left({b}^{1}, {b}^{1}, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.5}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -1.2e120Initial program 51.9%
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.f6496.9
Applied rewrites96.9%
if -1.2e120 < b < 2.65000000000000019e-118Initial program 77.4%
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 rewrites77.4%
if 2.65000000000000019e-118 < b Initial program 14.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6488.1
Applied rewrites88.1%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e+120)
(* (* (fma (/ c (* b b)) -1.0 (pow a -1.0)) b) -1.0)
(if (<= b 2.65e-118)
(+
(* -1.0 (/ b (* 2.0 a)))
(* 0.5 (* (pow a -1.0) (pow (fma -4.0 (* a c) (* b b)) 0.5))))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e+120) {
tmp = (fma((c / (b * b)), -1.0, pow(a, -1.0)) * b) * -1.0;
} else if (b <= 2.65e-118) {
tmp = (-1.0 * (b / (2.0 * a))) + (0.5 * (pow(a, -1.0) * pow(fma(-4.0, (a * c), (b * b)), 0.5)));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.2e+120) tmp = Float64(Float64(fma(Float64(c / Float64(b * b)), -1.0, (a ^ -1.0)) * b) * -1.0); elseif (b <= 2.65e-118) tmp = Float64(Float64(-1.0 * Float64(b / Float64(2.0 * a))) + Float64(0.5 * Float64((a ^ -1.0) * (fma(-4.0, Float64(a * c), Float64(b * b)) ^ 0.5)))); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.2e+120], N[(N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -1.0 + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, 2.65e-118], N[(N[(-1.0 * N[(b / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(N[Power[a, -1.0], $MachinePrecision] * N[Power[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{+120}:\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{c}{b \cdot b}, -1, {a}^{-1}\right) \cdot b\right) \cdot -1\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{-118}:\\
\;\;\;\;-1 \cdot \frac{b}{2 \cdot a} + 0.5 \cdot \left({a}^{-1} \cdot {\left(\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)\right)}^{0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -1.2e120Initial program 51.9%
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.f6496.9
Applied rewrites96.9%
if -1.2e120 < b < 2.65000000000000019e-118Initial program 77.4%
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 rewrites77.4%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
metadata-evalN/A
pow-negN/A
lower-/.f64N/A
lower-pow.f64N/A
Applied rewrites77.3%
Taylor expanded in b around 0
lower-*.f64N/A
lower-*.f64N/A
inv-powN/A
lift-pow.f64N/A
pow1/2N/A
lower-pow.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
sqr-abs-revN/A
lower-*.f6477.3
Applied rewrites77.3%
if 2.65000000000000019e-118 < b Initial program 14.1%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6488.1
Applied rewrites88.1%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e+117)
(* (* (fma (/ c (* b b)) -1.0 (pow a -1.0)) b) -1.0)
(if (<= b -6.8e-304)
(*
b
(-
(* 0.5 (* (pow (* a b) -1.0) (pow (fma -4.0 (* a c) (* b b)) 0.5)))
(* 0.5 (pow a -1.0))))
(* (/ c b) -1.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e+117) {
tmp = (fma((c / (b * b)), -1.0, pow(a, -1.0)) * b) * -1.0;
} else if (b <= -6.8e-304) {
tmp = b * ((0.5 * (pow((a * b), -1.0) * pow(fma(-4.0, (a * c), (b * b)), 0.5))) - (0.5 * pow(a, -1.0)));
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5.8e+117) tmp = Float64(Float64(fma(Float64(c / Float64(b * b)), -1.0, (a ^ -1.0)) * b) * -1.0); elseif (b <= -6.8e-304) tmp = Float64(b * Float64(Float64(0.5 * Float64((Float64(a * b) ^ -1.0) * (fma(-4.0, Float64(a * c), Float64(b * b)) ^ 0.5))) - Float64(0.5 * (a ^ -1.0)))); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5.8e+117], N[(N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -1.0 + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * -1.0), $MachinePrecision], If[LessEqual[b, -6.8e-304], N[(b * N[(N[(0.5 * N[(N[Power[N[(a * b), $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{+117}:\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{c}{b \cdot b}, -1, {a}^{-1}\right) \cdot b\right) \cdot -1\\
\mathbf{elif}\;b \leq -6.8 \cdot 10^{-304}:\\
\;\;\;\;b \cdot \left(0.5 \cdot \left({\left(a \cdot b\right)}^{-1} \cdot {\left(\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)\right)}^{0.5}\right) - 0.5 \cdot {a}^{-1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -5.80000000000000055e117Initial program 51.9%
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.f6496.9
Applied rewrites96.9%
if -5.80000000000000055e117 < b < -6.7999999999999997e-304Initial program 84.0%
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 rewrites84.0%
Applied rewrites24.9%
Taylor expanded in b around inf
lower-*.f64N/A
lower--.f64N/A
Applied rewrites62.8%
if -6.7999999999999997e-304 < b Initial program 21.8%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6475.9
Applied rewrites75.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (* (* (fma (/ c (* b b)) -1.0 (pow a -1.0)) b) -1.0) (* (/ c b) -1.0)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = (fma((c / (b * b)), -1.0, pow(a, -1.0)) * b) * -1.0;
} else {
tmp = (c / b) * -1.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(fma(Float64(c / Float64(b * b)), -1.0, (a ^ -1.0)) * b) * -1.0); else tmp = Float64(Float64(c / b) * -1.0); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[(N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -1.0 + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * -1.0), $MachinePrecision], N[(N[(c / b), $MachinePrecision] * -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\left(\mathsf{fma}\left(\frac{c}{b \cdot b}, -1, {a}^{-1}\right) \cdot b\right) \cdot -1\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} \cdot -1\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 68.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.f6471.9
Applied rewrites71.9%
if -3.999999999999988e-310 < b Initial program 21.9%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
lower-/.f6476.5
Applied rewrites76.5%
(FPCore (a b c) :precision binary64 (* (* (fma (/ c (* b b)) -1.0 (pow a -1.0)) b) -1.0))
double code(double a, double b, double c) {
return (fma((c / (b * b)), -1.0, pow(a, -1.0)) * b) * -1.0;
}
function code(a, b, c) return Float64(Float64(fma(Float64(c / Float64(b * b)), -1.0, (a ^ -1.0)) * b) * -1.0) end
code[a_, b_, c_] := N[(N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] * -1.0 + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision] * -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(\mathsf{fma}\left(\frac{c}{b \cdot b}, -1, {a}^{-1}\right) \cdot b\right) \cdot -1
\end{array}
Initial program 47.2%
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.f6440.1
Applied rewrites40.1%
herbie shell --seed 2025064
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform c (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ (- sqtD (/ b 2)) a) (/ (- c) (+ (/ b 2) sqtD)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))