
(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 9 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.4e-103)
(/ c (- b))
(if (<= b 1.05e+100)
(/ (- (- 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.4e-103) {
tmp = c / -b;
} else if (b <= 1.05e+100) {
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.4e-103) tmp = Float64(c / Float64(-b)); elseif (b <= 1.05e+100) 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.4e-103], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.05e+100], 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.4 \cdot 10^{-103}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{+100}:\\
\;\;\;\;\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.3999999999999999e-103Initial program 23.2%
div-sub22.8%
sub-neg22.8%
neg-mul-122.8%
*-commutative22.8%
associate-/l*22.7%
distribute-neg-frac22.7%
neg-mul-122.7%
*-commutative22.7%
associate-/l*22.7%
distribute-rgt-out23.1%
associate-/r*23.1%
metadata-eval23.1%
sub-neg23.1%
+-commutative23.1%
Simplified23.1%
Taylor expanded in b around -inf 77.7%
mul-1-neg77.7%
distribute-neg-frac277.7%
Simplified77.7%
if -4.3999999999999999e-103 < b < 1.0499999999999999e100Initial program 86.5%
fma-neg86.5%
*-commutative86.5%
associate-*r*86.5%
distribute-lft-neg-in86.5%
*-commutative86.5%
distribute-rgt-neg-in86.5%
associate-*r*86.5%
metadata-eval86.5%
*-commutative86.5%
Simplified86.5%
if 1.0499999999999999e100 < b Initial program 59.0%
div-sub59.0%
sub-neg59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*59.0%
distribute-neg-frac59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*58.9%
distribute-rgt-out58.9%
associate-/r*58.9%
metadata-eval58.9%
sub-neg58.9%
+-commutative58.9%
Simplified59.0%
Taylor expanded in c around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e-100)
(/ c (- b))
(if (<= b 2.25e+97)
(/ (- (- 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 <= -1.2e-100) {
tmp = c / -b;
} else if (b <= 2.25e+97) {
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 <= (-1.2d-100)) then
tmp = c / -b
else if (b <= 2.25d+97) 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 <= -1.2e-100) {
tmp = c / -b;
} else if (b <= 2.25e+97) {
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 <= -1.2e-100: tmp = c / -b elif b <= 2.25e+97: 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 <= -1.2e-100) tmp = Float64(c / Float64(-b)); elseif (b <= 2.25e+97) 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 <= -1.2e-100) tmp = c / -b; elseif (b <= 2.25e+97) 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, -1.2e-100], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 2.25e+97], 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 -1.2 \cdot 10^{-100}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{+97}:\\
\;\;\;\;\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 < -1.2000000000000001e-100Initial program 23.2%
div-sub22.8%
sub-neg22.8%
neg-mul-122.8%
*-commutative22.8%
associate-/l*22.7%
distribute-neg-frac22.7%
neg-mul-122.7%
*-commutative22.7%
associate-/l*22.7%
distribute-rgt-out23.1%
associate-/r*23.1%
metadata-eval23.1%
sub-neg23.1%
+-commutative23.1%
Simplified23.1%
Taylor expanded in b around -inf 77.7%
mul-1-neg77.7%
distribute-neg-frac277.7%
Simplified77.7%
if -1.2000000000000001e-100 < b < 2.24999999999999988e97Initial program 86.5%
if 2.24999999999999988e97 < b Initial program 59.0%
div-sub59.0%
sub-neg59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*59.0%
distribute-neg-frac59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*58.9%
distribute-rgt-out58.9%
associate-/r*58.9%
metadata-eval58.9%
sub-neg58.9%
+-commutative58.9%
Simplified59.0%
Taylor expanded in c around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e-103)
(/ c (- b))
(if (<= b 1.25e+100)
(/ (- (- b) (sqrt (- (* b b) (* a (* c 4.0))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-103) {
tmp = c / -b;
} else if (b <= 1.25e+100) {
tmp = (-b - sqrt(((b * b) - (a * (c * 4.0))))) / (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 <= (-1.85d-103)) then
tmp = c / -b
else if (b <= 1.25d+100) then
tmp = (-b - sqrt(((b * b) - (a * (c * 4.0d0))))) / (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 <= -1.85e-103) {
tmp = c / -b;
} else if (b <= 1.25e+100) {
tmp = (-b - Math.sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e-103: tmp = c / -b elif b <= 1.25e+100: tmp = (-b - math.sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e-103) tmp = Float64(c / Float64(-b)); elseif (b <= 1.25e+100) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) / 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 <= -1.85e-103) tmp = c / -b; elseif (b <= 1.25e+100) tmp = (-b - sqrt(((b * b) - (a * (c * 4.0))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-103], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 1.25e+100], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $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 -1.85 \cdot 10^{-103}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{+100}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.85e-103Initial program 23.2%
div-sub22.8%
sub-neg22.8%
neg-mul-122.8%
*-commutative22.8%
associate-/l*22.7%
distribute-neg-frac22.7%
neg-mul-122.7%
*-commutative22.7%
associate-/l*22.7%
distribute-rgt-out23.1%
associate-/r*23.1%
metadata-eval23.1%
sub-neg23.1%
+-commutative23.1%
Simplified23.1%
Taylor expanded in b around -inf 77.7%
mul-1-neg77.7%
distribute-neg-frac277.7%
Simplified77.7%
if -1.85e-103 < b < 1.25e100Initial program 86.5%
*-commutative86.5%
*-commutative86.5%
sqr-neg86.5%
*-commutative86.5%
sqr-neg86.5%
*-commutative86.5%
associate-*r*86.5%
Simplified86.5%
if 1.25e100 < b Initial program 59.0%
div-sub59.0%
sub-neg59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*59.0%
distribute-neg-frac59.0%
neg-mul-159.0%
*-commutative59.0%
associate-/l*58.9%
distribute-rgt-out58.9%
associate-/r*58.9%
metadata-eval58.9%
sub-neg58.9%
+-commutative58.9%
Simplified59.0%
Taylor expanded in c around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e-105)
(/ c (- b))
(if (<= b 8.4e-103)
(* (/ -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 <= -3.5e-105) {
tmp = c / -b;
} else if (b <= 8.4e-103) {
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 <= (-3.5d-105)) then
tmp = c / -b
else if (b <= 8.4d-103) 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 <= -3.5e-105) {
tmp = c / -b;
} else if (b <= 8.4e-103) {
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 <= -3.5e-105: tmp = c / -b elif b <= 8.4e-103: 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 <= -3.5e-105) tmp = Float64(c / Float64(-b)); elseif (b <= 8.4e-103) 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 <= -3.5e-105) tmp = c / -b; elseif (b <= 8.4e-103) 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, -3.5e-105], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 8.4e-103], 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 -3.5 \cdot 10^{-105}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 8.4 \cdot 10^{-103}:\\
\;\;\;\;\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 < -3.5e-105Initial program 23.2%
div-sub22.8%
sub-neg22.8%
neg-mul-122.8%
*-commutative22.8%
associate-/l*22.7%
distribute-neg-frac22.7%
neg-mul-122.7%
*-commutative22.7%
associate-/l*22.7%
distribute-rgt-out23.1%
associate-/r*23.1%
metadata-eval23.1%
sub-neg23.1%
+-commutative23.1%
Simplified23.1%
Taylor expanded in b around -inf 77.7%
mul-1-neg77.7%
distribute-neg-frac277.7%
Simplified77.7%
if -3.5e-105 < b < 8.40000000000000019e-103Initial program 83.3%
div-sub83.3%
sub-neg83.3%
neg-mul-183.3%
*-commutative83.3%
associate-/l*83.3%
distribute-neg-frac83.3%
neg-mul-183.3%
*-commutative83.3%
associate-/l*83.0%
distribute-rgt-out83.0%
associate-/r*83.0%
metadata-eval83.0%
sub-neg83.0%
+-commutative83.0%
Simplified83.1%
Taylor expanded in a around inf 75.6%
*-commutative75.6%
associate-*r*75.7%
Simplified75.7%
if 8.40000000000000019e-103 < b Initial program 70.1%
div-sub70.1%
sub-neg70.1%
neg-mul-170.1%
*-commutative70.1%
associate-/l*70.0%
distribute-neg-frac70.0%
neg-mul-170.0%
*-commutative70.0%
associate-/l*70.0%
distribute-rgt-out70.0%
associate-/r*70.0%
metadata-eval70.0%
sub-neg70.0%
+-commutative70.0%
Simplified70.0%
Taylor expanded in c around 0 92.2%
+-commutative92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
Final simplification82.4%
(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(c / Float64(-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.7%
div-sub35.5%
sub-neg35.5%
neg-mul-135.5%
*-commutative35.5%
associate-/l*35.4%
distribute-neg-frac35.4%
neg-mul-135.4%
*-commutative35.4%
associate-/l*35.3%
distribute-rgt-out35.6%
associate-/r*35.6%
metadata-eval35.6%
sub-neg35.6%
+-commutative35.6%
Simplified35.6%
Taylor expanded in b around -inf 65.4%
mul-1-neg65.4%
distribute-neg-frac265.4%
Simplified65.4%
if -4.999999999999985e-310 < b Initial program 73.2%
div-sub73.2%
sub-neg73.2%
neg-mul-173.2%
*-commutative73.2%
associate-/l*73.1%
distribute-neg-frac73.1%
neg-mul-173.1%
*-commutative73.1%
associate-/l*73.0%
distribute-rgt-out73.0%
associate-/r*73.0%
metadata-eval73.0%
sub-neg73.0%
+-commutative73.0%
Simplified73.0%
Taylor expanded in c around 0 70.7%
+-commutative70.7%
mul-1-neg70.7%
unsub-neg70.7%
Simplified70.7%
Final simplification68.2%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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 <= (-1d-309)) 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 <= -1e-309) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 35.7%
div-sub35.5%
sub-neg35.5%
neg-mul-135.5%
*-commutative35.5%
associate-/l*35.4%
distribute-neg-frac35.4%
neg-mul-135.4%
*-commutative35.4%
associate-/l*35.3%
distribute-rgt-out35.6%
associate-/r*35.6%
metadata-eval35.6%
sub-neg35.6%
+-commutative35.6%
Simplified35.6%
Taylor expanded in b around -inf 65.4%
mul-1-neg65.4%
distribute-neg-frac265.4%
Simplified65.4%
if -1.000000000000002e-309 < b Initial program 73.2%
div-sub73.2%
sub-neg73.2%
neg-mul-173.2%
*-commutative73.2%
associate-/l*73.1%
distribute-neg-frac73.1%
neg-mul-173.1%
*-commutative73.1%
associate-/l*73.0%
distribute-rgt-out73.0%
associate-/r*73.0%
metadata-eval73.0%
sub-neg73.0%
+-commutative73.0%
Simplified73.0%
Taylor expanded in a around 0 70.3%
associate-*r/70.3%
mul-1-neg70.3%
Simplified70.3%
Final simplification68.0%
(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 / Float64(-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 55.5%
div-sub55.4%
sub-neg55.4%
neg-mul-155.4%
*-commutative55.4%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.2%
distribute-rgt-out55.3%
associate-/r*55.3%
metadata-eval55.3%
sub-neg55.3%
+-commutative55.3%
Simplified55.4%
Taylor expanded in b around -inf 31.9%
mul-1-neg31.9%
distribute-neg-frac231.9%
Simplified31.9%
Final simplification31.9%
(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 55.5%
*-commutative55.5%
*-commutative55.5%
sqr-neg55.5%
*-commutative55.5%
sqr-neg55.5%
*-commutative55.5%
associate-*r*55.5%
Simplified55.5%
Applied egg-rr57.7%
Taylor expanded in b around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
distribute-rgt-neg-in0.0%
associate-*r/0.0%
neg-mul-10.0%
associate-*r/0.0%
metadata-eval0.0%
unpow20.0%
rem-square-sqrt30.9%
Simplified30.9%
Taylor expanded in a around inf 2.4%
Final simplification2.4%
(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 55.5%
div-sub55.4%
sub-neg55.4%
neg-mul-155.4%
*-commutative55.4%
associate-/l*55.3%
distribute-neg-frac55.3%
neg-mul-155.3%
*-commutative55.3%
associate-/l*55.2%
distribute-rgt-out55.3%
associate-/r*55.3%
metadata-eval55.3%
sub-neg55.3%
+-commutative55.3%
Simplified55.4%
Taylor expanded in a around 0 37.3%
Taylor expanded in a around inf 10.7%
Final simplification10.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 2024060
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(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)))