
(FPCore (a b_2 c) :precision binary64 (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / 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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 - Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 - math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) - N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b_2 c) :precision binary64 (/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / 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_2, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a
end function
public static double code(double a, double b_2, double c) {
return (-b_2 - Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 - math.sqrt(((b_2 * b_2) - (a * c)))) / a
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function tmp = code(a, b_2, c) tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) - N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
\end{array}
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.26e-123)
(* -0.5 (/ c b_2))
(if (<= b_2 7e+139)
(-
(* -1.0 (/ b_2 a))
(/ (pow (fma (pow b_2 1.0) (pow b_2 1.0) (* -1.0 (* c a))) 0.5) a))
(* -1.0 (/ (+ b_2 b_2) a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.26e-123) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 7e+139) {
tmp = (-1.0 * (b_2 / a)) - (pow(fma(pow(b_2, 1.0), pow(b_2, 1.0), (-1.0 * (c * a))), 0.5) / a);
} else {
tmp = -1.0 * ((b_2 + b_2) / a);
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.26e-123) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 7e+139) tmp = Float64(Float64(-1.0 * Float64(b_2 / a)) - Float64((fma((b_2 ^ 1.0), (b_2 ^ 1.0), Float64(-1.0 * Float64(c * a))) ^ 0.5) / a)); else tmp = Float64(-1.0 * Float64(Float64(b_2 + b_2) / a)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.26e-123], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 7e+139], N[(N[(-1.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[(N[Power[b$95$2, 1.0], $MachinePrecision] * N[Power[b$95$2, 1.0], $MachinePrecision] + N[(-1.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(N[(b$95$2 + b$95$2), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.26 \cdot 10^{-123}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 7 \cdot 10^{+139}:\\
\;\;\;\;-1 \cdot \frac{b\_2}{a} - \frac{{\left(\mathsf{fma}\left({b\_2}^{1}, {b\_2}^{1}, -1 \cdot \left(c \cdot a\right)\right)\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b\_2 + b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.26000000000000005e-123Initial program 15.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.26000000000000005e-123 < b_2 < 6.99999999999999957e139Initial program 83.8%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites83.8%
if 6.99999999999999957e139 < b_2 Initial program 44.4%
Taylor expanded in a around 0
Applied rewrites98.1%
Final simplification86.8%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.26e-123)
(* -0.5 (/ c b_2))
(if (<= b_2 7e+139)
(-
(* -1.0 (/ b_2 a))
(/ (pow (fma (pow b_2 1.0) (pow b_2 1.0) (* -1.0 (* c a))) 0.5) a))
(fma (/ c b_2) 0.5 (* (/ b_2 a) -2.0)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.26e-123) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 7e+139) {
tmp = (-1.0 * (b_2 / a)) - (pow(fma(pow(b_2, 1.0), pow(b_2, 1.0), (-1.0 * (c * a))), 0.5) / a);
} else {
tmp = fma((c / b_2), 0.5, ((b_2 / a) * -2.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.26e-123) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 7e+139) tmp = Float64(Float64(-1.0 * Float64(b_2 / a)) - Float64((fma((b_2 ^ 1.0), (b_2 ^ 1.0), Float64(-1.0 * Float64(c * a))) ^ 0.5) / a)); else tmp = fma(Float64(c / b_2), 0.5, Float64(Float64(b_2 / a) * -2.0)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.26e-123], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 7e+139], N[(N[(-1.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[(N[Power[b$95$2, 1.0], $MachinePrecision] * N[Power[b$95$2, 1.0], $MachinePrecision] + N[(-1.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * 0.5 + N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.26 \cdot 10^{-123}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 7 \cdot 10^{+139}:\\
\;\;\;\;-1 \cdot \frac{b\_2}{a} - \frac{{\left(\mathsf{fma}\left({b\_2}^{1}, {b\_2}^{1}, -1 \cdot \left(c \cdot a\right)\right)\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2}, 0.5, \frac{b\_2}{a} \cdot -2\right)\\
\end{array}
\end{array}
if b_2 < -1.26000000000000005e-123Initial program 15.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.26000000000000005e-123 < b_2 < 6.99999999999999957e139Initial program 83.8%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites83.8%
if 6.99999999999999957e139 < b_2 Initial program 44.4%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.26e-123)
(* -0.5 (/ c b_2))
(if (<= b_2 6.5e+139)
(-
(* -1.0 (/ b_2 a))
(* (pow a -1.0) (pow (fma -1.0 (* a c) (* b_2 b_2)) 0.5)))
(fma (/ c b_2) 0.5 (* (/ b_2 a) -2.0)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.26e-123) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 6.5e+139) {
tmp = (-1.0 * (b_2 / a)) - (pow(a, -1.0) * pow(fma(-1.0, (a * c), (b_2 * b_2)), 0.5));
} else {
tmp = fma((c / b_2), 0.5, ((b_2 / a) * -2.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.26e-123) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 6.5e+139) tmp = Float64(Float64(-1.0 * Float64(b_2 / a)) - Float64((a ^ -1.0) * (fma(-1.0, Float64(a * c), Float64(b_2 * b_2)) ^ 0.5))); else tmp = fma(Float64(c / b_2), 0.5, Float64(Float64(b_2 / a) * -2.0)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.26e-123], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 6.5e+139], N[(N[(-1.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] - N[(N[Power[a, -1.0], $MachinePrecision] * N[Power[N[(-1.0 * N[(a * c), $MachinePrecision] + N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * 0.5 + N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.26 \cdot 10^{-123}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 6.5 \cdot 10^{+139}:\\
\;\;\;\;-1 \cdot \frac{b\_2}{a} - {a}^{-1} \cdot {\left(\mathsf{fma}\left(-1, a \cdot c, b\_2 \cdot b\_2\right)\right)}^{0.5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2}, 0.5, \frac{b\_2}{a} \cdot -2\right)\\
\end{array}
\end{array}
if b_2 < -1.26000000000000005e-123Initial program 15.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.26000000000000005e-123 < b_2 < 6.5000000000000003e139Initial program 83.8%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites83.8%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites83.6%
Taylor expanded in b_2 around 0
lower-*.f64N/A
inv-powN/A
lift-pow.f64N/A
pow1/2N/A
pow2N/A
sqr-abs-revN/A
lower-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f6483.7
Applied rewrites83.7%
if 6.5000000000000003e139 < b_2 Initial program 44.4%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.26e-123)
(* -0.5 (/ c b_2))
(if (<= b_2 6e+136)
(*
(* -1.0 b_2)
(fma
(pow (* a b_2) -1.0)
(pow (fma -1.0 (* a c) (* b_2 b_2)) 0.5)
(pow a -1.0)))
(fma (/ c b_2) 0.5 (* (/ b_2 a) -2.0)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.26e-123) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 6e+136) {
tmp = (-1.0 * b_2) * fma(pow((a * b_2), -1.0), pow(fma(-1.0, (a * c), (b_2 * b_2)), 0.5), pow(a, -1.0));
} else {
tmp = fma((c / b_2), 0.5, ((b_2 / a) * -2.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.26e-123) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 6e+136) tmp = Float64(Float64(-1.0 * b_2) * fma((Float64(a * b_2) ^ -1.0), (fma(-1.0, Float64(a * c), Float64(b_2 * b_2)) ^ 0.5), (a ^ -1.0))); else tmp = fma(Float64(c / b_2), 0.5, Float64(Float64(b_2 / a) * -2.0)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.26e-123], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 6e+136], N[(N[(-1.0 * b$95$2), $MachinePrecision] * N[(N[Power[N[(a * b$95$2), $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(-1.0 * N[(a * c), $MachinePrecision] + N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * 0.5 + N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.26 \cdot 10^{-123}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 6 \cdot 10^{+136}:\\
\;\;\;\;\left(-1 \cdot b\_2\right) \cdot \mathsf{fma}\left({\left(a \cdot b\_2\right)}^{-1}, {\left(\mathsf{fma}\left(-1, a \cdot c, b\_2 \cdot b\_2\right)\right)}^{0.5}, {a}^{-1}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2}, 0.5, \frac{b\_2}{a} \cdot -2\right)\\
\end{array}
\end{array}
if b_2 < -1.26000000000000005e-123Initial program 15.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.26000000000000005e-123 < b_2 < 5.99999999999999958e136Initial program 83.8%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites83.8%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites83.6%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites63.8%
if 5.99999999999999958e136 < b_2 Initial program 44.4%
Taylor expanded in c around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
Final simplification78.3%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.26e-123)
(* -0.5 (/ c b_2))
(if (<= b_2 6e+136)
(*
(* -1.0 b_2)
(fma
(pow (* a b_2) -1.0)
(pow (fma -1.0 (* a c) (* b_2 b_2)) 0.5)
(pow a -1.0)))
(* (fma (/ c (* b_2 b_2)) 0.5 (* -2.0 (pow a -1.0))) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.26e-123) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 6e+136) {
tmp = (-1.0 * b_2) * fma(pow((a * b_2), -1.0), pow(fma(-1.0, (a * c), (b_2 * b_2)), 0.5), pow(a, -1.0));
} else {
tmp = fma((c / (b_2 * b_2)), 0.5, (-2.0 * pow(a, -1.0))) * b_2;
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.26e-123) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 6e+136) tmp = Float64(Float64(-1.0 * b_2) * fma((Float64(a * b_2) ^ -1.0), (fma(-1.0, Float64(a * c), Float64(b_2 * b_2)) ^ 0.5), (a ^ -1.0))); else tmp = Float64(fma(Float64(c / Float64(b_2 * b_2)), 0.5, Float64(-2.0 * (a ^ -1.0))) * b_2); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.26e-123], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 6e+136], N[(N[(-1.0 * b$95$2), $MachinePrecision] * N[(N[Power[N[(a * b$95$2), $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(-1.0 * N[(a * c), $MachinePrecision] + N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(c / N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision] * 0.5 + N[(-2.0 * N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.26 \cdot 10^{-123}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 6 \cdot 10^{+136}:\\
\;\;\;\;\left(-1 \cdot b\_2\right) \cdot \mathsf{fma}\left({\left(a \cdot b\_2\right)}^{-1}, {\left(\mathsf{fma}\left(-1, a \cdot c, b\_2 \cdot b\_2\right)\right)}^{0.5}, {a}^{-1}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{b\_2 \cdot b\_2}, 0.5, -2 \cdot {a}^{-1}\right) \cdot b\_2\\
\end{array}
\end{array}
if b_2 < -1.26000000000000005e-123Initial program 15.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.26000000000000005e-123 < b_2 < 5.99999999999999958e136Initial program 83.8%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites83.8%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites83.6%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites63.8%
if 5.99999999999999958e136 < b_2 Initial program 44.4%
Taylor expanded in b_2 around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sub-sign-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
metadata-evalN/A
lower-*.f64N/A
inv-powN/A
lower-pow.f6497.8
Applied rewrites97.8%
Final simplification78.3%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.26e-123)
(* -0.5 (/ c b_2))
(*
(* -1.0 b_2)
(fma
(pow (* a b_2) -1.0)
(pow (fma -1.0 (* a c) (* b_2 b_2)) 0.5)
(pow a -1.0)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.26e-123) {
tmp = -0.5 * (c / b_2);
} else {
tmp = (-1.0 * b_2) * fma(pow((a * b_2), -1.0), pow(fma(-1.0, (a * c), (b_2 * b_2)), 0.5), pow(a, -1.0));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.26e-123) tmp = Float64(-0.5 * Float64(c / b_2)); else tmp = Float64(Float64(-1.0 * b_2) * fma((Float64(a * b_2) ^ -1.0), (fma(-1.0, Float64(a * c), Float64(b_2 * b_2)) ^ 0.5), (a ^ -1.0))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.26e-123], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * b$95$2), $MachinePrecision] * N[(N[Power[N[(a * b$95$2), $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(-1.0 * N[(a * c), $MachinePrecision] + N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.26 \cdot 10^{-123}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot b\_2\right) \cdot \mathsf{fma}\left({\left(a \cdot b\_2\right)}^{-1}, {\left(\mathsf{fma}\left(-1, a \cdot c, b\_2 \cdot b\_2\right)\right)}^{0.5}, {a}^{-1}\right)\\
\end{array}
\end{array}
if b_2 < -1.26000000000000005e-123Initial program 15.5%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-/.f6484.9
Applied rewrites84.9%
if -1.26000000000000005e-123 < b_2 Initial program 72.2%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites72.3%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites72.1%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites57.8%
Final simplification68.7%
(FPCore (a b_2 c) :precision binary64 (* (* -1.0 b_2) (fma (pow (* a b_2) -1.0) (pow (fma -1.0 (* a c) (* b_2 b_2)) 0.5) (pow a -1.0))))
double code(double a, double b_2, double c) {
return (-1.0 * b_2) * fma(pow((a * b_2), -1.0), pow(fma(-1.0, (a * c), (b_2 * b_2)), 0.5), pow(a, -1.0));
}
function code(a, b_2, c) return Float64(Float64(-1.0 * b_2) * fma((Float64(a * b_2) ^ -1.0), (fma(-1.0, Float64(a * c), Float64(b_2 * b_2)) ^ 0.5), (a ^ -1.0))) end
code[a_, b$95$2_, c_] := N[(N[(-1.0 * b$95$2), $MachinePrecision] * N[(N[Power[N[(a * b$95$2), $MachinePrecision], -1.0], $MachinePrecision] * N[Power[N[(-1.0 * N[(a * c), $MachinePrecision] + N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-1 \cdot b\_2\right) \cdot \mathsf{fma}\left({\left(a \cdot b\_2\right)}^{-1}, {\left(\mathsf{fma}\left(-1, a \cdot c, b\_2 \cdot b\_2\right)\right)}^{0.5}, {a}^{-1}\right)
\end{array}
Initial program 49.4%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites48.7%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites48.0%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites39.2%
Final simplification39.2%
(FPCore (a b_2 c)
:precision binary64
(*
(* -1.0 b_2)
(fma
(pow (* a b_2) -1.0)
(*
b_2
(-
-1.0
(fma
-0.5
(/ (* a c) (* b_2 b_2))
(fma
-0.125
(/ (pow (* a c) 2.0) (pow b_2 4.0))
(* -0.0625 (/ (pow (* a c) 3.0) (pow b_2 6.0)))))))
(pow a -1.0))))
double code(double a, double b_2, double c) {
return (-1.0 * b_2) * fma(pow((a * b_2), -1.0), (b_2 * (-1.0 - fma(-0.5, ((a * c) / (b_2 * b_2)), fma(-0.125, (pow((a * c), 2.0) / pow(b_2, 4.0)), (-0.0625 * (pow((a * c), 3.0) / pow(b_2, 6.0))))))), pow(a, -1.0));
}
function code(a, b_2, c) return Float64(Float64(-1.0 * b_2) * fma((Float64(a * b_2) ^ -1.0), Float64(b_2 * Float64(-1.0 - fma(-0.5, Float64(Float64(a * c) / Float64(b_2 * b_2)), fma(-0.125, Float64((Float64(a * c) ^ 2.0) / (b_2 ^ 4.0)), Float64(-0.0625 * Float64((Float64(a * c) ^ 3.0) / (b_2 ^ 6.0))))))), (a ^ -1.0))) end
code[a_, b$95$2_, c_] := N[(N[(-1.0 * b$95$2), $MachinePrecision] * N[(N[Power[N[(a * b$95$2), $MachinePrecision], -1.0], $MachinePrecision] * N[(b$95$2 * N[(-1.0 - N[(-0.5 * N[(N[(a * c), $MachinePrecision] / N[(b$95$2 * b$95$2), $MachinePrecision]), $MachinePrecision] + N[(-0.125 * N[(N[Power[N[(a * c), $MachinePrecision], 2.0], $MachinePrecision] / N[Power[b$95$2, 4.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0625 * N[(N[Power[N[(a * c), $MachinePrecision], 3.0], $MachinePrecision] / N[Power[b$95$2, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[a, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-1 \cdot b\_2\right) \cdot \mathsf{fma}\left({\left(a \cdot b\_2\right)}^{-1}, b\_2 \cdot \left(-1 - \mathsf{fma}\left(-0.5, \frac{a \cdot c}{b\_2 \cdot b\_2}, \mathsf{fma}\left(-0.125, \frac{{\left(a \cdot c\right)}^{2}}{{b\_2}^{4}}, -0.0625 \cdot \frac{{\left(a \cdot c\right)}^{3}}{{b\_2}^{6}}\right)\right)\right), {a}^{-1}\right)
\end{array}
Initial program 49.4%
lift-/.f64N/A
lift-neg.f64N/A
lift--.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
div-subN/A
mul-1-negN/A
associate-*r/N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites48.7%
lift-pow.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites48.0%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-fma.f64N/A
Applied rewrites39.2%
Taylor expanded in b_2 around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-fma.f64N/A
Applied rewrites7.0%
Final simplification7.0%
herbie shell --seed 2025064
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
: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_2 0) (/ c (- sqtD b_2)) (/ (+ b_2 sqtD) (- a)))))
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))