
(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 -4.9e-54)
(/ (- c) b)
(if (<= b 1.75e+89)
(/ (- (- b) (sqrt (fma b b (* c (* -4.0 a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.9e-54) {
tmp = -c / b;
} else if (b <= 1.75e+89) {
tmp = (-b - sqrt(fma(b, b, (c * (-4.0 * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4.9e-54) tmp = Float64(Float64(-c) / b); elseif (b <= 1.75e+89) tmp = Float64(Float64(Float64(-b) - sqrt(fma(b, b, Float64(c * Float64(-4.0 * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4.9e-54], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.75e+89], N[(N[((-b) - N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.9 \cdot 10^{-54}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.90000000000000021e-54Initial program 16.1%
*-commutative16.1%
sqr-neg16.1%
*-commutative16.1%
sqr-neg16.1%
associate-*r*16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac87.5%
Simplified87.5%
if -4.90000000000000021e-54 < b < 1.75e89Initial program 80.5%
*-commutative80.5%
fma-neg80.6%
associate-*r*80.6%
distribute-lft-neg-in80.6%
*-commutative80.6%
distribute-rgt-neg-in80.6%
associate-*r*80.6%
metadata-eval80.6%
*-commutative80.6%
Simplified80.6%
if 1.75e89 < b Initial program 52.9%
*-commutative52.9%
sqr-neg52.9%
*-commutative52.9%
sqr-neg52.9%
associate-*r*52.9%
*-commutative52.9%
Simplified52.9%
Taylor expanded in b around inf 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -7e-65)
(/ (- c) b)
(if (<= b 1.95e+89)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-65) {
tmp = -c / b;
} else if (b <= 1.95e+89) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.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 <= (-7d-65)) then
tmp = -c / b
else if (b <= 1.95d+89) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.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 <= -7e-65) {
tmp = -c / b;
} else if (b <= 1.95e+89) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-65: tmp = -c / b elif b <= 1.95e+89: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-65) tmp = Float64(Float64(-c) / b); elseif (b <= 1.95e+89) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.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 <= -7e-65) tmp = -c / b; elseif (b <= 1.95e+89) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-65], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.95e+89], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-65}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.00000000000000009e-65Initial program 16.1%
*-commutative16.1%
sqr-neg16.1%
*-commutative16.1%
sqr-neg16.1%
associate-*r*16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac87.5%
Simplified87.5%
if -7.00000000000000009e-65 < b < 1.95000000000000005e89Initial program 80.5%
if 1.95000000000000005e89 < b Initial program 52.9%
*-commutative52.9%
sqr-neg52.9%
*-commutative52.9%
sqr-neg52.9%
associate-*r*52.9%
*-commutative52.9%
Simplified52.9%
Taylor expanded in b around inf 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -9.5e-62)
(/ (- c) b)
(if (<= b 4.2e-92)
(* -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 <= -9.5e-62) {
tmp = -c / b;
} else if (b <= 4.2e-92) {
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 <= (-9.5d-62)) then
tmp = -c / b
else if (b <= 4.2d-92) 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 <= -9.5e-62) {
tmp = -c / b;
} else if (b <= 4.2e-92) {
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 <= -9.5e-62: tmp = -c / b elif b <= 4.2e-92: 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 <= -9.5e-62) tmp = Float64(Float64(-c) / b); elseif (b <= 4.2e-92) 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 <= -9.5e-62) tmp = -c / b; elseif (b <= 4.2e-92) 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, -9.5e-62], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.2e-92], 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 -9.5 \cdot 10^{-62}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-92}:\\
\;\;\;\;-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 < -9.49999999999999951e-62Initial program 16.1%
*-commutative16.1%
sqr-neg16.1%
*-commutative16.1%
sqr-neg16.1%
associate-*r*16.1%
*-commutative16.1%
Simplified16.1%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-neg-frac87.5%
Simplified87.5%
if -9.49999999999999951e-62 < b < 4.2e-92Initial program 77.8%
sub-neg77.8%
distribute-neg-out77.8%
neg-mul-177.8%
times-frac77.8%
metadata-eval77.8%
sub-neg77.8%
+-commutative77.8%
*-commutative77.8%
distribute-lft-neg-in77.8%
distribute-rgt-neg-out77.8%
associate-*l*77.8%
fma-def77.8%
distribute-lft-neg-in77.8%
distribute-rgt-neg-in77.8%
metadata-eval77.8%
Simplified77.8%
Taylor expanded in a around inf 74.1%
*-commutative74.1%
associate-*r*74.1%
Simplified74.1%
if 4.2e-92 < b Initial program 65.0%
*-commutative65.0%
sqr-neg65.0%
*-commutative65.0%
sqr-neg65.0%
associate-*r*65.0%
*-commutative65.0%
Simplified65.0%
Taylor expanded in b around inf 85.4%
+-commutative85.4%
mul-1-neg85.4%
unsub-neg85.4%
Simplified85.4%
Final simplification83.0%
(FPCore (a b c) :precision binary64 (if (<= b 5.8e-306) (/ 0.5 (+ (* -0.5 (/ b c)) (/ 0.5 (/ b a)))) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.8e-306) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 / (b / 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 <= 5.8d-306) then
tmp = 0.5d0 / (((-0.5d0) * (b / c)) + (0.5d0 / (b / 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 <= 5.8e-306) {
tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 / (b / a)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.8e-306: tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 / (b / a))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.8e-306) tmp = Float64(0.5 / Float64(Float64(-0.5 * Float64(b / c)) + Float64(0.5 / Float64(b / 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 <= 5.8e-306) tmp = 0.5 / ((-0.5 * (b / c)) + (0.5 / (b / a))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.8e-306], N[(0.5 / N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(0.5 / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.8 \cdot 10^{-306}:\\
\;\;\;\;\frac{0.5}{-0.5 \cdot \frac{b}{c} + \frac{0.5}{\frac{b}{a}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < 5.7999999999999998e-306Initial program 32.7%
sub-neg32.7%
distribute-neg-out32.7%
neg-mul-132.7%
times-frac32.7%
metadata-eval32.7%
sub-neg32.7%
+-commutative32.7%
*-commutative32.7%
distribute-lft-neg-in32.7%
distribute-rgt-neg-out32.7%
associate-*l*32.7%
fma-def32.8%
distribute-lft-neg-in32.8%
distribute-rgt-neg-in32.8%
metadata-eval32.8%
Simplified32.8%
clear-num32.7%
inv-pow32.7%
pow232.7%
Applied egg-rr32.7%
unpow-132.7%
Simplified32.7%
Taylor expanded in b around -inf 69.0%
un-div-inv69.0%
frac-2neg69.0%
metadata-eval69.0%
+-commutative69.0%
fma-def69.0%
clear-num69.0%
un-div-inv69.0%
Applied egg-rr69.0%
fma-udef69.0%
distribute-neg-in69.0%
distribute-lft-neg-in69.0%
metadata-eval69.0%
distribute-neg-frac69.0%
metadata-eval69.0%
Simplified69.0%
if 5.7999999999999998e-306 < b Initial program 69.8%
*-commutative69.8%
sqr-neg69.8%
*-commutative69.8%
sqr-neg69.8%
associate-*r*69.8%
*-commutative69.8%
Simplified69.8%
Taylor expanded in b around inf 66.4%
+-commutative66.4%
mul-1-neg66.4%
unsub-neg66.4%
Simplified66.4%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 32.2%
*-commutative32.2%
sqr-neg32.2%
*-commutative32.2%
sqr-neg32.2%
associate-*r*32.2%
*-commutative32.2%
Simplified32.2%
Taylor expanded in b around -inf 69.0%
mul-1-neg69.0%
distribute-neg-frac69.0%
Simplified69.0%
if -3.999999999999988e-310 < b Initial program 70.0%
*-commutative70.0%
sqr-neg70.0%
*-commutative70.0%
sqr-neg70.0%
associate-*r*70.0%
*-commutative70.0%
Simplified70.0%
Taylor expanded in b around inf 65.9%
+-commutative65.9%
mul-1-neg65.9%
unsub-neg65.9%
Simplified65.9%
Final simplification67.4%
(FPCore (a b c) :precision binary64 (if (<= b -3e-307) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-307) {
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 <= (-3d-307)) 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 <= -3e-307) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-307: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-307) 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 <= -3e-307) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-307], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-307}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -2.9999999999999999e-307Initial program 31.7%
*-commutative31.7%
sqr-neg31.7%
*-commutative31.7%
sqr-neg31.7%
associate-*r*31.7%
*-commutative31.7%
Simplified31.7%
Taylor expanded in b around -inf 69.5%
mul-1-neg69.5%
distribute-neg-frac69.5%
Simplified69.5%
if -2.9999999999999999e-307 < b Initial program 70.2%
*-commutative70.2%
sqr-neg70.2%
*-commutative70.2%
sqr-neg70.2%
associate-*r*70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in b around inf 65.2%
associate-*r/65.2%
mul-1-neg65.2%
Simplified65.2%
Final simplification67.3%
(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.5%
*-commutative51.5%
sqr-neg51.5%
*-commutative51.5%
sqr-neg51.5%
associate-*r*51.5%
*-commutative51.5%
Simplified51.5%
Taylor expanded in b around inf 34.8%
associate-*r/34.8%
mul-1-neg34.8%
Simplified34.8%
Final simplification34.8%
(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(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.5%
sub-neg51.5%
distribute-neg-out51.5%
neg-mul-151.5%
times-frac51.5%
metadata-eval51.5%
sub-neg51.5%
+-commutative51.5%
*-commutative51.5%
distribute-lft-neg-in51.5%
distribute-rgt-neg-out51.5%
associate-*l*51.5%
fma-def51.6%
distribute-lft-neg-in51.6%
distribute-rgt-neg-in51.6%
metadata-eval51.6%
Simplified51.6%
clear-num51.5%
inv-pow51.5%
pow251.5%
Applied egg-rr51.5%
unpow-151.5%
Simplified51.5%
Taylor expanded in b around -inf 35.5%
Taylor expanded in a around inf 2.7%
Final simplification2.7%
(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 2024011
(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)))