
(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);
}
real(8) function code(a, b, c)
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 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);
}
real(8) function code(a, b, c)
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 -1.45e-85)
(/ (- c) b)
(if (<= b 4.5e+69)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-85) {
tmp = -c / b;
} else if (b <= 4.5e+69) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.45d-85)) then
tmp = -c / b
else if (b <= 4.5d+69) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.45e-85) {
tmp = -c / b;
} else if (b <= 4.5e+69) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.45e-85: tmp = -c / b elif b <= 4.5e+69: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.45e-85) tmp = Float64(Float64(-c) / b); elseif (b <= 4.5e+69) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.45e-85) tmp = -c / b; elseif (b <= 4.5e+69) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.45e-85], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.5e+69], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.45 \cdot 10^{-85}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{+69}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -1.4500000000000001e-85Initial program 22.9%
*-commutative22.9%
Simplified22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -1.4500000000000001e-85 < b < 4.4999999999999999e69Initial program 82.0%
if 4.4999999999999999e69 < b Initial program 57.8%
*-commutative57.8%
Simplified57.8%
Taylor expanded in b around inf 97.2%
associate-*r/97.2%
mul-1-neg97.2%
Simplified97.2%
Final simplification88.0%
(FPCore (a b c)
:precision binary64
(if (<= b -7.6e-88)
(/ (- c) b)
(if (<= b 6e+69)
(* (/ -0.5 a) (+ b (sqrt (+ (* b b) (* a (* c -4.0))))))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-88) {
tmp = -c / b;
} else if (b <= 6e+69) {
tmp = (-0.5 / a) * (b + sqrt(((b * b) + (a * (c * -4.0)))));
} else {
tmp = -(b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-7.6d-88)) then
tmp = -c / b
else if (b <= 6d+69) then
tmp = ((-0.5d0) / a) * (b + sqrt(((b * b) + (a * (c * (-4.0d0))))))
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-88) {
tmp = -c / b;
} else if (b <= 6e+69) {
tmp = (-0.5 / a) * (b + Math.sqrt(((b * b) + (a * (c * -4.0)))));
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.6e-88: tmp = -c / b elif b <= 6e+69: tmp = (-0.5 / a) * (b + math.sqrt(((b * b) + (a * (c * -4.0))))) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.6e-88) tmp = Float64(Float64(-c) / b); elseif (b <= 6e+69) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))))); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.6e-88) tmp = -c / b; elseif (b <= 6e+69) tmp = (-0.5 / a) * (b + sqrt(((b * b) + (a * (c * -4.0))))); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.6e-88], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 6e+69], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.6 \cdot 10^{-88}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{+69}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -7.60000000000000022e-88Initial program 22.9%
*-commutative22.9%
Simplified22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -7.60000000000000022e-88 < b < 5.99999999999999967e69Initial program 82.0%
*-commutative82.0%
Simplified82.0%
frac-2neg82.0%
div-inv81.8%
*-commutative81.8%
*-commutative81.8%
distribute-lft-neg-in81.8%
associate-/r*81.8%
metadata-eval81.8%
metadata-eval81.8%
sub-neg81.8%
distribute-neg-out81.8%
remove-double-neg81.8%
fma-neg81.8%
*-commutative81.8%
distribute-rgt-neg-in81.8%
associate-*l*81.8%
metadata-eval81.8%
Applied egg-rr81.8%
fma-udef81.8%
Applied egg-rr81.8%
if 5.99999999999999967e69 < b Initial program 57.8%
*-commutative57.8%
Simplified57.8%
Taylor expanded in b around inf 97.2%
associate-*r/97.2%
mul-1-neg97.2%
Simplified97.2%
Final simplification87.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e-86)
(/ (- c) b)
(if (<= b 2.8e-120)
(* (/ -0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-86) {
tmp = -c / b;
} else if (b <= 2.8e-120) {
tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.8d-86)) then
tmp = -c / b
else if (b <= 2.8d-120) then
tmp = ((-0.5d0) / a) * (b + sqrt((a * (c * (-4.0d0)))))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-86) {
tmp = -c / b;
} else if (b <= 2.8e-120) {
tmp = (-0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e-86: tmp = -c / b elif b <= 2.8e-120: tmp = (-0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-86) tmp = Float64(Float64(-c) / b); elseif (b <= 2.8e-120) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.8e-86) tmp = -c / b; elseif (b <= 2.8e-120) tmp = (-0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-86], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.8e-120], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-86}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-120}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.79999999999999983e-86Initial program 22.9%
*-commutative22.9%
Simplified22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -1.79999999999999983e-86 < b < 2.79999999999999994e-120Initial program 79.4%
*-commutative79.4%
Simplified79.4%
frac-2neg79.4%
div-inv79.3%
*-commutative79.3%
*-commutative79.3%
distribute-lft-neg-in79.3%
associate-/r*79.3%
metadata-eval79.3%
metadata-eval79.3%
sub-neg79.3%
distribute-neg-out79.3%
remove-double-neg79.3%
fma-neg79.3%
*-commutative79.3%
distribute-rgt-neg-in79.3%
associate-*l*79.3%
metadata-eval79.3%
Applied egg-rr79.3%
Taylor expanded in b around 0 74.5%
*-commutative74.5%
associate-*r*74.5%
Simplified74.5%
if 2.79999999999999994e-120 < b Initial program 67.2%
*-commutative67.2%
Simplified67.2%
Taylor expanded in b around inf 88.3%
+-commutative88.3%
mul-1-neg88.3%
unsub-neg88.3%
Simplified88.3%
Final simplification85.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-87)
(/ (- c) b)
(if (<= b 2.6e-121)
(/ (/ (+ b (sqrt (* a (* c -4.0)))) -2.0) a)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-87) {
tmp = -c / b;
} else if (b <= 2.6e-121) {
tmp = ((b + sqrt((a * (c * -4.0)))) / -2.0) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-3.8d-87)) then
tmp = -c / b
else if (b <= 2.6d-121) then
tmp = ((b + sqrt((a * (c * (-4.0d0))))) / (-2.0d0)) / a
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-87) {
tmp = -c / b;
} else if (b <= 2.6e-121) {
tmp = ((b + Math.sqrt((a * (c * -4.0)))) / -2.0) / a;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-87: tmp = -c / b elif b <= 2.6e-121: tmp = ((b + math.sqrt((a * (c * -4.0)))) / -2.0) / a else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-87) tmp = Float64(Float64(-c) / b); elseif (b <= 2.6e-121) tmp = Float64(Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / -2.0) / a); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.8e-87) tmp = -c / b; elseif (b <= 2.6e-121) tmp = ((b + sqrt((a * (c * -4.0)))) / -2.0) / a; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-87], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.6e-121], N[(N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / -2.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.8 \cdot 10^{-87}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-121}:\\
\;\;\;\;\frac{\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{-2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.8e-87Initial program 22.9%
*-commutative22.9%
Simplified22.9%
Taylor expanded in b around -inf 86.9%
associate-*r/86.9%
neg-mul-186.9%
Simplified86.9%
if -3.8e-87 < b < 2.59999999999999986e-121Initial program 79.4%
*-commutative79.4%
Simplified79.4%
Taylor expanded in b around 0 74.6%
*-commutative74.6%
associate-*r*74.6%
Simplified74.6%
Applied egg-rr74.5%
associate-*l/74.6%
*-lft-identity74.6%
Simplified74.6%
if 2.59999999999999986e-121 < b Initial program 67.2%
*-commutative67.2%
Simplified67.2%
Taylor expanded in b around inf 88.3%
+-commutative88.3%
mul-1-neg88.3%
unsub-neg88.3%
Simplified88.3%
Final simplification85.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 35.8%
*-commutative35.8%
Simplified35.8%
Taylor expanded in b around -inf 69.3%
associate-*r/69.3%
neg-mul-169.3%
Simplified69.3%
if -4.999999999999985e-310 < b Initial program 70.0%
*-commutative70.0%
Simplified70.0%
Taylor expanded in b around inf 78.3%
+-commutative78.3%
mul-1-neg78.3%
unsub-neg78.3%
Simplified78.3%
Final simplification73.4%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-301) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-301) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.6d-301)) then
tmp = -c / b
else
tmp = -(b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-301) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-301: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.6e-301) tmp = Float64(Float64(-c) / b); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.6e-301) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-301], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-301}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -2.5999999999999998e-301Initial program 35.3%
*-commutative35.3%
Simplified35.3%
Taylor expanded in b around -inf 69.8%
associate-*r/69.8%
neg-mul-169.8%
Simplified69.8%
if -2.5999999999999998e-301 < b Initial program 70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in b around inf 76.8%
associate-*r/76.8%
mul-1-neg76.8%
Simplified76.8%
Final simplification73.0%
(FPCore (a b c) :precision binary64 (- (/ b a)))
double code(double a, double b, double c) {
return -(b / a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -(b / a)
end function
public static double code(double a, double b, double c) {
return -(b / a);
}
def code(a, b, c): return -(b / a)
function code(a, b, c) return Float64(-Float64(b / a)) end
function tmp = code(a, b, c) tmp = -(b / a); end
code[a_, b_, c_] := (-N[(b / a), $MachinePrecision])
\begin{array}{l}
\\
-\frac{b}{a}
\end{array}
Initial program 51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in b around inf 36.9%
associate-*r/36.9%
mul-1-neg36.9%
Simplified36.9%
Final simplification36.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2023297
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))