
(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 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);
}
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.9e-102)
(/ (- c) b)
(if (<= b 1.45e+117)
(* -0.5 (/ (+ b (sqrt (fma b b (* a (* c -4.0))))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.9e-102) {
tmp = -c / b;
} else if (b <= 1.45e+117) {
tmp = -0.5 * ((b + sqrt(fma(b, b, (a * (c * -4.0))))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.9e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 1.45e+117) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(b, b, Float64(a * Float64(c * -4.0))))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.9e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.45e+117], N[(-0.5 * N[(N[(b + N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.45 \cdot 10^{+117}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.90000000000000013e-102Initial program 21.7%
Taylor expanded in b around -inf 81.1%
associate-*r/81.1%
neg-mul-181.1%
Simplified81.1%
if -1.90000000000000013e-102 < b < 1.45000000000000014e117Initial program 85.5%
/-rgt-identity85.5%
metadata-eval85.5%
associate-/l*85.5%
associate-/r/86.3%
*-commutative86.3%
metadata-eval86.3%
metadata-eval86.3%
associate-*l/86.3%
associate-/r/86.3%
times-frac85.5%
*-commutative85.5%
times-frac86.5%
metadata-eval86.5%
associate-/r/86.5%
*-commutative86.5%
div-sub86.5%
Simplified86.6%
if 1.45000000000000014e117 < b Initial program 52.6%
Taylor expanded in b around inf 97.0%
associate-*r/97.0%
mul-1-neg97.0%
Simplified97.0%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.85e-102)
(/ (- c) b)
(if (<= b 1e+124)
(/ (- (- 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 <= -2.85e-102) {
tmp = -c / b;
} else if (b <= 1e+124) {
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 <= (-2.85d-102)) then
tmp = -c / b
else if (b <= 1d+124) 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 <= -2.85e-102) {
tmp = -c / b;
} else if (b <= 1e+124) {
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 <= -2.85e-102: tmp = -c / b elif b <= 1e+124: 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 <= -2.85e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+124) 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 <= -2.85e-102) tmp = -c / b; elseif (b <= 1e+124) 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, -2.85e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+124], 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 -2.85 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+124}:\\
\;\;\;\;\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 < -2.85e-102Initial program 21.7%
Taylor expanded in b around -inf 81.1%
associate-*r/81.1%
neg-mul-181.1%
Simplified81.1%
if -2.85e-102 < b < 9.99999999999999948e123Initial program 85.5%
if 9.99999999999999948e123 < b Initial program 52.6%
Taylor expanded in b around inf 97.0%
associate-*r/97.0%
mul-1-neg97.0%
Simplified97.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -6.4e-103)
(/ (- c) b)
(if (<= b 5.6e+119)
(* -0.5 (/ (+ b (sqrt (- (* b b) (* c (* a 4.0))))) a))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.4e-103) {
tmp = -c / b;
} else if (b <= 5.6e+119) {
tmp = -0.5 * ((b + sqrt(((b * b) - (c * (a * 4.0))))) / a);
} 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 <= (-6.4d-103)) then
tmp = -c / b
else if (b <= 5.6d+119) then
tmp = (-0.5d0) * ((b + sqrt(((b * b) - (c * (a * 4.0d0))))) / a)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.4e-103) {
tmp = -c / b;
} else if (b <= 5.6e+119) {
tmp = -0.5 * ((b + Math.sqrt(((b * b) - (c * (a * 4.0))))) / a);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.4e-103: tmp = -c / b elif b <= 5.6e+119: tmp = -0.5 * ((b + math.sqrt(((b * b) - (c * (a * 4.0))))) / a) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.4e-103) tmp = Float64(Float64(-c) / b); elseif (b <= 5.6e+119) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0))))) / a)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.4e-103) tmp = -c / b; elseif (b <= 5.6e+119) tmp = -0.5 * ((b + sqrt(((b * b) - (c * (a * 4.0))))) / a); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.4e-103], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 5.6e+119], N[(-0.5 * N[(N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.4 \cdot 10^{-103}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{+119}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -6.39999999999999953e-103Initial program 21.7%
Taylor expanded in b around -inf 81.1%
associate-*r/81.1%
neg-mul-181.1%
Simplified81.1%
if -6.39999999999999953e-103 < b < 5.60000000000000026e119Initial program 85.5%
/-rgt-identity85.5%
metadata-eval85.5%
associate-/l*85.5%
associate-/r/86.3%
*-commutative86.3%
metadata-eval86.3%
metadata-eval86.3%
associate-*l/86.3%
associate-/r/86.3%
times-frac85.5%
*-commutative85.5%
times-frac86.5%
metadata-eval86.5%
associate-/r/86.5%
*-commutative86.5%
div-sub86.5%
Simplified86.6%
associate-*r*86.5%
metadata-eval86.5%
distribute-rgt-neg-in86.5%
*-commutative86.5%
fma-neg86.5%
*-commutative86.5%
*-commutative86.5%
associate-*l*85.5%
Applied egg-rr85.5%
if 5.60000000000000026e119 < b Initial program 52.6%
Taylor expanded in b around inf 97.0%
associate-*r/97.0%
mul-1-neg97.0%
Simplified97.0%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2.5e-102)
(/ (- c) b)
(if (<= b 2.35e-40)
(* -0.5 (/ (+ b (sqrt (* a (* c -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-102) {
tmp = -c / b;
} else if (b <= 2.35e-40) {
tmp = -0.5 * ((b + sqrt((a * (c * -4.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 <= (-2.5d-102)) then
tmp = -c / b
else if (b <= 2.35d-40) then
tmp = (-0.5d0) * ((b + sqrt((a * (c * (-4.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 <= -2.5e-102) {
tmp = -c / b;
} else if (b <= 2.35e-40) {
tmp = -0.5 * ((b + Math.sqrt((a * (c * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.5e-102: tmp = -c / b elif b <= 2.35e-40: tmp = -0.5 * ((b + math.sqrt((a * (c * -4.0)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.5e-102) tmp = Float64(Float64(-c) / b); elseif (b <= 2.35e-40) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.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 <= -2.5e-102) tmp = -c / b; elseif (b <= 2.35e-40) tmp = -0.5 * ((b + sqrt((a * (c * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.5e-102], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.35e-40], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.5 \cdot 10^{-102}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.35 \cdot 10^{-40}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.50000000000000013e-102Initial program 21.7%
Taylor expanded in b around -inf 81.1%
associate-*r/81.1%
neg-mul-181.1%
Simplified81.1%
if -2.50000000000000013e-102 < b < 2.35e-40Initial program 80.7%
/-rgt-identity80.7%
metadata-eval80.7%
associate-/l*80.7%
associate-/r/81.9%
*-commutative81.9%
metadata-eval81.9%
metadata-eval81.9%
associate-*l/81.9%
associate-/r/81.9%
times-frac80.7%
*-commutative80.7%
times-frac82.1%
metadata-eval82.1%
associate-/r/82.1%
*-commutative82.1%
div-sub82.1%
Simplified82.2%
Taylor expanded in b around 0 74.4%
*-commutative74.4%
associate-*l*73.0%
Simplified73.0%
Taylor expanded in c around 0 74.4%
*-commutative74.4%
*-commutative74.4%
associate-*l*74.5%
Simplified74.5%
if 2.35e-40 < b Initial program 67.0%
Taylor expanded in b around inf 90.8%
mul-1-neg90.8%
unsub-neg90.8%
Simplified90.8%
Final simplification82.7%
(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 33.8%
Taylor expanded in b around -inf 65.9%
associate-*r/65.9%
neg-mul-165.9%
Simplified65.9%
if -4.999999999999985e-310 < b Initial program 71.7%
Taylor expanded in b around inf 67.8%
mul-1-neg67.8%
unsub-neg67.8%
Simplified67.8%
Final simplification66.9%
(FPCore (a b c) :precision binary64 (if (<= b -0.00156) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.00156) {
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 <= (-0.00156d0)) 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 <= -0.00156) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.00156: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.00156) tmp = 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 <= -0.00156) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.00156], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.00156:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -0.00155999999999999997Initial program 18.1%
Taylor expanded in b around inf 2.0%
Taylor expanded in c around inf 21.7%
if -0.00155999999999999997 < b Initial program 67.3%
Taylor expanded in b around inf 49.3%
associate-*r/49.3%
mul-1-neg49.3%
Simplified49.3%
Final simplification41.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.8e-284) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-284) {
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.8d-284)) 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.8e-284) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e-284: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e-284) 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.8e-284) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e-284], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{-284}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.8000000000000003e-284Initial program 32.9%
Taylor expanded in b around -inf 67.4%
associate-*r/67.4%
neg-mul-167.4%
Simplified67.4%
if -2.8000000000000003e-284 < b Initial program 71.6%
Taylor expanded in b around inf 66.4%
associate-*r/66.4%
mul-1-neg66.4%
Simplified66.4%
Final simplification66.9%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
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(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 52.9%
Taylor expanded in b around inf 34.8%
Taylor expanded in c around inf 8.6%
Final simplification8.6%
(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 2023223
(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)))