
(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.6e-144)
(/ (- c) b)
(if (<= b 2e+108)
(/ (- (- 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 <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 2e+108) {
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 <= (-4.6d-144)) then
tmp = -c / b
else if (b <= 2d+108) 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 <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 2e+108) {
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 <= -4.6e-144: tmp = -c / b elif b <= 2e+108: 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 <= -4.6e-144) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+108) 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 <= -4.6e-144) tmp = -c / b; elseif (b <= 2e+108) 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, -4.6e-144], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+108], 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 -4.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+108}:\\
\;\;\;\;\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 < -4.6e-144Initial program 19.7%
*-commutative19.7%
sqr-neg19.7%
*-commutative19.7%
sqr-neg19.7%
associate-*r*19.7%
*-commutative19.7%
Simplified19.7%
Taylor expanded in b around -inf 79.9%
associate-*r/79.9%
neg-mul-179.9%
Simplified79.9%
if -4.6e-144 < b < 2.0000000000000001e108Initial program 87.7%
if 2.0000000000000001e108 < b Initial program 48.4%
*-commutative48.4%
sqr-neg48.4%
*-commutative48.4%
sqr-neg48.4%
associate-*r*48.4%
*-commutative48.4%
Simplified48.4%
Taylor expanded in b around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-144)
(/ (- c) b)
(if (<= b 0.026)
(* -0.5 (+ (/ b a) (/ 1.0 (/ a (sqrt (* c (* a -4.0)))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 0.026) {
tmp = -0.5 * ((b / a) + (1.0 / (a / sqrt((c * (a * -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 <= (-4.6d-144)) then
tmp = -c / b
else if (b <= 0.026d0) then
tmp = (-0.5d0) * ((b / a) + (1.0d0 / (a / sqrt((c * (a * (-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 <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 0.026) {
tmp = -0.5 * ((b / a) + (1.0 / (a / Math.sqrt((c * (a * -4.0))))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-144: tmp = -c / b elif b <= 0.026: tmp = -0.5 * ((b / a) + (1.0 / (a / math.sqrt((c * (a * -4.0)))))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-144) tmp = Float64(Float64(-c) / b); elseif (b <= 0.026) tmp = Float64(-0.5 * Float64(Float64(b / a) + Float64(1.0 / Float64(a / sqrt(Float64(c * Float64(a * -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 <= -4.6e-144) tmp = -c / b; elseif (b <= 0.026) tmp = -0.5 * ((b / a) + (1.0 / (a / sqrt((c * (a * -4.0)))))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-144], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 0.026], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(1.0 / N[(a / N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $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 -4.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 0.026:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{1}{\frac{a}{\sqrt{c \cdot \left(a \cdot -4\right)}}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.6e-144Initial program 19.7%
*-commutative19.7%
sqr-neg19.7%
*-commutative19.7%
sqr-neg19.7%
associate-*r*19.7%
*-commutative19.7%
Simplified19.7%
Taylor expanded in b around -inf 79.9%
associate-*r/79.9%
neg-mul-179.9%
Simplified79.9%
if -4.6e-144 < b < 0.0259999999999999988Initial program 86.2%
*-commutative86.2%
sqr-neg86.2%
*-commutative86.2%
sqr-neg86.2%
associate-*r*86.2%
*-commutative86.2%
Simplified86.2%
prod-diff85.8%
*-commutative85.8%
fma-def85.8%
associate-+l+85.8%
*-commutative85.8%
distribute-rgt-neg-in85.8%
fma-def85.9%
*-commutative85.9%
distribute-rgt-neg-in85.9%
metadata-eval85.9%
*-commutative85.9%
fma-udef85.8%
distribute-lft-neg-in85.8%
distribute-rgt-neg-in85.8%
fma-def85.9%
Applied egg-rr85.9%
Taylor expanded in b around 0 72.4%
distribute-lft-out72.4%
associate-*l/72.5%
distribute-rgt-out72.8%
metadata-eval72.8%
associate-*r*72.8%
*-lft-identity72.8%
Simplified72.8%
clear-num72.9%
inv-pow72.9%
Applied egg-rr72.9%
unpow-172.9%
Applied egg-rr72.9%
if 0.0259999999999999988 < b Initial program 60.4%
*-commutative60.4%
sqr-neg60.4%
*-commutative60.4%
sqr-neg60.4%
associate-*r*60.4%
*-commutative60.4%
Simplified60.4%
Taylor expanded in b around inf 94.2%
mul-1-neg94.2%
unsub-neg94.2%
Simplified94.2%
Final simplification82.8%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-144)
(/ (- c) b)
(if (<= b 0.0185)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 0.0185) {
tmp = (-b - sqrt((c * (a * -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 <= (-4.6d-144)) then
tmp = -c / b
else if (b <= 0.0185d0) then
tmp = (-b - sqrt((c * (a * (-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 <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 0.0185) {
tmp = (-b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-144: tmp = -c / b elif b <= 0.0185: tmp = (-b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-144) tmp = Float64(Float64(-c) / b); elseif (b <= 0.0185) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -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 <= -4.6e-144) tmp = -c / b; elseif (b <= 0.0185) tmp = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-144], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 0.0185], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $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.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 0.0185:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.6e-144Initial program 19.7%
*-commutative19.7%
sqr-neg19.7%
*-commutative19.7%
sqr-neg19.7%
associate-*r*19.7%
*-commutative19.7%
Simplified19.7%
Taylor expanded in b around -inf 79.9%
associate-*r/79.9%
neg-mul-179.9%
Simplified79.9%
if -4.6e-144 < b < 0.0184999999999999991Initial program 86.2%
*-commutative86.2%
sqr-neg86.2%
*-commutative86.2%
sqr-neg86.2%
associate-*r*86.2%
*-commutative86.2%
Simplified86.2%
Taylor expanded in b around 0 72.8%
*-commutative72.8%
*-commutative72.8%
*-commutative72.8%
associate-*r*72.8%
Simplified72.8%
if 0.0184999999999999991 < b Initial program 60.4%
*-commutative60.4%
sqr-neg60.4%
*-commutative60.4%
sqr-neg60.4%
associate-*r*60.4%
*-commutative60.4%
Simplified60.4%
Taylor expanded in b around inf 94.2%
mul-1-neg94.2%
unsub-neg94.2%
Simplified94.2%
Final simplification82.8%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e-144)
(/ (- c) b)
(if (<= b 3.3e-74)
(* -0.5 (/ (sqrt (* c (* a -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 3.3e-74) {
tmp = -0.5 * (sqrt((c * (a * -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 <= (-4.6d-144)) then
tmp = -c / b
else if (b <= 3.3d-74) then
tmp = (-0.5d0) * (sqrt((c * (a * (-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 <= -4.6e-144) {
tmp = -c / b;
} else if (b <= 3.3e-74) {
tmp = -0.5 * (Math.sqrt((c * (a * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e-144: tmp = -c / b elif b <= 3.3e-74: tmp = -0.5 * (math.sqrt((c * (a * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e-144) tmp = Float64(Float64(-c) / b); elseif (b <= 3.3e-74) tmp = Float64(-0.5 * Float64(sqrt(Float64(c * Float64(a * -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 <= -4.6e-144) tmp = -c / b; elseif (b <= 3.3e-74) tmp = -0.5 * (sqrt((c * (a * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e-144], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.3e-74], N[(-0.5 * N[(N[Sqrt[N[(c * N[(a * -4.0), $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 -4.6 \cdot 10^{-144}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-74}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.6e-144Initial program 19.7%
*-commutative19.7%
sqr-neg19.7%
*-commutative19.7%
sqr-neg19.7%
associate-*r*19.7%
*-commutative19.7%
Simplified19.7%
Taylor expanded in b around -inf 79.9%
associate-*r/79.9%
neg-mul-179.9%
Simplified79.9%
if -4.6e-144 < b < 3.29999999999999996e-74Initial program 84.9%
*-commutative84.9%
sqr-neg84.9%
*-commutative84.9%
sqr-neg84.9%
associate-*r*84.9%
*-commutative84.9%
Simplified84.9%
prod-diff84.5%
*-commutative84.5%
fma-def84.5%
associate-+l+84.5%
*-commutative84.5%
distribute-rgt-neg-in84.5%
fma-def84.5%
*-commutative84.5%
distribute-rgt-neg-in84.5%
metadata-eval84.5%
*-commutative84.5%
fma-udef84.5%
distribute-lft-neg-in84.5%
distribute-rgt-neg-in84.5%
fma-def84.5%
Applied egg-rr84.5%
Taylor expanded in b around 0 75.9%
associate-*l/76.0%
distribute-rgt-out76.4%
metadata-eval76.4%
associate-*r*76.4%
*-lft-identity76.4%
Simplified76.4%
if 3.29999999999999996e-74 < b Initial program 64.5%
*-commutative64.5%
sqr-neg64.5%
*-commutative64.5%
sqr-neg64.5%
associate-*r*64.5%
*-commutative64.5%
Simplified64.5%
Taylor expanded in b around inf 88.4%
mul-1-neg88.4%
unsub-neg88.4%
Simplified88.4%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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 <= (-1d-309)) 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 <= -1e-309) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) 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 <= -1e-309) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial 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 65.5%
associate-*r/65.5%
neg-mul-165.5%
Simplified65.5%
if -1.000000000000002e-309 < 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 71.4%
mul-1-neg71.4%
unsub-neg71.4%
Simplified71.4%
Final simplification68.6%
(FPCore (a b c) :precision binary64 (if (<= b -3.6e-304) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.6e-304) {
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 <= (-3.6d-304)) 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 <= -3.6e-304) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.6e-304: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.6e-304) 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 <= -3.6e-304) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.6e-304], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.6 \cdot 10^{-304}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.6000000000000001e-304Initial program 30.5%
*-commutative30.5%
sqr-neg30.5%
*-commutative30.5%
sqr-neg30.5%
associate-*r*30.5%
*-commutative30.5%
Simplified30.5%
Taylor expanded in b around -inf 67.0%
associate-*r/67.0%
neg-mul-167.0%
Simplified67.0%
if -3.6000000000000001e-304 < b Initial program 70.6%
*-commutative70.6%
sqr-neg70.6%
*-commutative70.6%
sqr-neg70.6%
associate-*r*70.6%
*-commutative70.6%
Simplified70.6%
Taylor expanded in b around inf 69.5%
associate-*r/69.5%
mul-1-neg69.5%
Simplified69.5%
Final simplification68.4%
(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 52.0%
*-commutative52.0%
sqr-neg52.0%
*-commutative52.0%
sqr-neg52.0%
associate-*r*52.0%
*-commutative52.0%
Simplified52.0%
Taylor expanded in b around inf 38.5%
associate-*r/38.5%
mul-1-neg38.5%
Simplified38.5%
Final simplification38.5%
(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 52.0%
*-commutative52.0%
sqr-neg52.0%
*-commutative52.0%
sqr-neg52.0%
associate-*r*52.0%
*-commutative52.0%
Simplified52.0%
clear-num51.9%
associate-/r/51.9%
*-commutative51.9%
associate-/r*51.9%
metadata-eval51.9%
add-sqr-sqrt14.5%
sqrt-unprod27.7%
sqr-neg27.7%
sqrt-prod20.8%
add-sqr-sqrt33.9%
sub-neg33.9%
add-sqr-sqrt30.7%
hypot-def25.9%
*-commutative25.9%
distribute-rgt-neg-in25.9%
*-commutative25.9%
distribute-rgt-neg-in25.9%
metadata-eval25.9%
Applied egg-rr25.9%
Taylor expanded in b around -inf 2.5%
Final simplification2.5%
(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 2023264
(FPCore (a b c)
:name "quadm (p42, negative)"
: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)))