
(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 -3.25e-170)
(/ (- c) b)
(if (<= b 8200000000.0)
(/ (- (- b) (sqrt (- (* b b) (* c (* 4.0 a))))) (* a 2.0))
(* -0.5 (/ (+ b (+ b (* -2.0 (/ a (/ b c))))) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 8200000000.0) {
tmp = (-b - sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / 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.25d-170)) then
tmp = -c / b
else if (b <= 8200000000.0d0) then
tmp = (-b - sqrt(((b * b) - (c * (4.0d0 * a))))) / (a * 2.0d0)
else
tmp = (-0.5d0) * ((b + (b + ((-2.0d0) * (a / (b / c))))) / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 8200000000.0) {
tmp = (-b - Math.sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.25e-170: tmp = -c / b elif b <= 8200000000.0: tmp = (-b - math.sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0) else: tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.25e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 8200000000.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a))))) / Float64(a * 2.0)); else tmp = Float64(-0.5 * Float64(Float64(b + Float64(b + Float64(-2.0 * Float64(a / Float64(b / c))))) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.25e-170) tmp = -c / b; elseif (b <= 8200000000.0) tmp = (-b - sqrt(((b * b) - (c * (4.0 * a))))) / (a * 2.0); else tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 8200000000.0], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(b + N[(b + N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 8200000000:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b + -2 \cdot \frac{a}{\frac{b}{c}}\right)}{a}\\
\end{array}
\end{array}
if b < -3.25000000000000018e-170Initial program 24.0%
Taylor expanded in b around -inf 77.6%
mul-1-neg77.6%
Simplified77.6%
if -3.25000000000000018e-170 < b < 8.2e9Initial program 85.5%
*-commutative85.5%
sqr-neg85.5%
*-commutative85.5%
sqr-neg85.5%
associate-*r*85.5%
*-commutative85.5%
Simplified85.5%
if 8.2e9 < b Initial program 58.7%
sub-neg58.7%
distribute-neg-out58.7%
neg-mul-158.7%
times-frac58.7%
metadata-eval58.7%
sub-neg58.7%
+-commutative58.7%
*-commutative58.7%
distribute-lft-neg-in58.7%
distribute-rgt-neg-out58.7%
associate-*l*58.7%
fma-def58.7%
distribute-lft-neg-in58.7%
distribute-rgt-neg-in58.7%
metadata-eval58.7%
Simplified58.7%
Taylor expanded in a around 0 88.7%
associate-/l*96.6%
Simplified96.6%
Final simplification84.6%
(FPCore (a b c)
:precision binary64
(if (<= b -3.25e-170)
(/ (- c) b)
(if (<= b 8200000000.0)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(* -0.5 (/ (+ b (+ b (* -2.0 (/ a (/ b c))))) a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 8200000000.0) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / 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.25d-170)) then
tmp = -c / b
else if (b <= 8200000000.0d0) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = (-0.5d0) * ((b + (b + ((-2.0d0) * (a / (b / c))))) / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 8200000000.0) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.25e-170: tmp = -c / b elif b <= 8200000000.0: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.25e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 8200000000.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(-0.5 * Float64(Float64(b + Float64(b + Float64(-2.0 * Float64(a / Float64(b / c))))) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.25e-170) tmp = -c / b; elseif (b <= 8200000000.0) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -0.5 * ((b + (b + (-2.0 * (a / (b / c))))) / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 8200000000.0], 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[(-0.5 * N[(N[(b + N[(b + N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 8200000000:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + \left(b + -2 \cdot \frac{a}{\frac{b}{c}}\right)}{a}\\
\end{array}
\end{array}
if b < -3.25000000000000018e-170Initial program 24.0%
Taylor expanded in b around -inf 77.6%
mul-1-neg77.6%
Simplified77.6%
if -3.25000000000000018e-170 < b < 8.2e9Initial program 85.5%
if 8.2e9 < b Initial program 58.7%
sub-neg58.7%
distribute-neg-out58.7%
neg-mul-158.7%
times-frac58.7%
metadata-eval58.7%
sub-neg58.7%
+-commutative58.7%
*-commutative58.7%
distribute-lft-neg-in58.7%
distribute-rgt-neg-out58.7%
associate-*l*58.7%
fma-def58.7%
distribute-lft-neg-in58.7%
distribute-rgt-neg-in58.7%
metadata-eval58.7%
Simplified58.7%
Taylor expanded in a around 0 88.7%
associate-/l*96.6%
Simplified96.6%
Final simplification84.6%
(FPCore (a b c)
:precision binary64
(if (<= b -3.25e-170)
(/ (- c) b)
(if (<= b 2.35e-138)
(* -0.5 (/ (+ b (sqrt (* c (* a -4.0)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 2.35e-138) {
tmp = -0.5 * ((b + 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 <= (-3.25d-170)) then
tmp = -c / b
else if (b <= 2.35d-138) then
tmp = (-0.5d0) * ((b + 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 <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 2.35e-138) {
tmp = -0.5 * ((b + Math.sqrt((c * (a * -4.0)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.25e-170: tmp = -c / b elif b <= 2.35e-138: tmp = -0.5 * ((b + 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 <= -3.25e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 2.35e-138) tmp = Float64(-0.5 * Float64(Float64(b + 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 <= -3.25e-170) tmp = -c / b; elseif (b <= 2.35e-138) tmp = -0.5 * ((b + sqrt((c * (a * -4.0)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.35e-138], N[(-0.5 * N[(N[(b + N[Sqrt[N[(c * N[(a * -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 -3.25 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.35 \cdot 10^{-138}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.25000000000000018e-170Initial program 24.0%
Taylor expanded in b around -inf 77.6%
mul-1-neg77.6%
Simplified77.6%
if -3.25000000000000018e-170 < b < 2.3500000000000001e-138Initial program 80.2%
sub-neg80.2%
distribute-neg-out80.2%
neg-mul-180.2%
times-frac80.2%
metadata-eval80.2%
sub-neg80.2%
+-commutative80.2%
*-commutative80.2%
distribute-lft-neg-in80.2%
distribute-rgt-neg-out80.2%
associate-*l*80.3%
fma-def80.3%
distribute-lft-neg-in80.3%
distribute-rgt-neg-in80.3%
metadata-eval80.3%
Simplified80.3%
Taylor expanded in a around inf 79.2%
associate-*r*79.3%
*-commutative79.3%
Simplified79.3%
if 2.3500000000000001e-138 < b Initial program 70.3%
Taylor expanded in b around inf 86.6%
+-commutative86.6%
mul-1-neg86.6%
unsub-neg86.6%
Simplified86.6%
Final simplification81.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.25e-170)
(/ (- c) b)
(if (<= b 2.42e-138)
(* (/ (sqrt (* a (* c -4.0))) a) (- 0.5))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = -c / b;
} else if (b <= 2.42e-138) {
tmp = (sqrt((a * (c * -4.0))) / a) * -0.5;
} 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.25d-170)) then
tmp = -c / b
else if (b <= 2.42d-138) then
tmp = (sqrt((a * (c * (-4.0d0)))) / a) * -0.5d0
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.25e-170) {
tmp = -c / b;
} else if (b <= 2.42e-138) {
tmp = (Math.sqrt((a * (c * -4.0))) / a) * -0.5;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.25e-170: tmp = -c / b elif b <= 2.42e-138: tmp = (math.sqrt((a * (c * -4.0))) / a) * -0.5 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.25e-170) tmp = Float64(Float64(-c) / b); elseif (b <= 2.42e-138) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) / a) * Float64(-0.5)); 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.25e-170) tmp = -c / b; elseif (b <= 2.42e-138) tmp = (sqrt((a * (c * -4.0))) / a) * -0.5; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-170], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.42e-138], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision] * (-0.5)), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.42 \cdot 10^{-138}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a} \cdot \left(-0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.25000000000000018e-170Initial program 24.0%
Taylor expanded in b around -inf 77.6%
mul-1-neg77.6%
Simplified77.6%
if -3.25000000000000018e-170 < b < 2.41999999999999993e-138Initial program 80.2%
clear-num80.2%
associate-/r/80.1%
associate-/r*80.1%
metadata-eval80.1%
add-sqr-sqrt80.0%
cancel-sign-sub-inv80.0%
add-sqr-sqrt38.1%
sqrt-unprod78.1%
sqr-neg78.1%
sqrt-prod39.8%
add-sqr-sqrt78.1%
Applied egg-rr78.3%
add-sqr-sqrt78.2%
pow278.2%
pow1/278.2%
sqrt-pow178.3%
metadata-eval78.3%
Applied egg-rr78.3%
Taylor expanded in a around inf 43.1%
Taylor expanded in b around 0 43.2%
Simplified78.3%
if 2.41999999999999993e-138 < b Initial program 70.3%
Taylor expanded in b around inf 86.6%
+-commutative86.6%
mul-1-neg86.6%
unsub-neg86.6%
Simplified86.6%
Final simplification80.8%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 34.6%
Taylor expanded in b around -inf 64.0%
mul-1-neg64.0%
Simplified64.0%
if -9.999999999999969e-311 < b Initial program 72.6%
Taylor expanded in b around inf 68.6%
+-commutative68.6%
mul-1-neg68.6%
unsub-neg68.6%
Simplified68.6%
Final simplification66.0%
(FPCore (a b c) :precision binary64 (if (<= b -3.2e-290) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-290) {
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.2d-290)) 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.2e-290) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-290: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-290) 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.2e-290) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-290], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-290}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3.19999999999999988e-290Initial program 33.8%
Taylor expanded in b around -inf 65.3%
mul-1-neg65.3%
Simplified65.3%
if -3.19999999999999988e-290 < b Initial program 72.5%
Taylor expanded in b around inf 66.1%
associate-*r/66.1%
mul-1-neg66.1%
Simplified66.1%
Final simplification65.7%
(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(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 51.8%
Taylor expanded in b around -inf 36.1%
mul-1-neg36.1%
Simplified36.1%
Final simplification36.1%
(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.8%
clear-num51.7%
associate-/r/51.7%
associate-/r*51.7%
metadata-eval51.7%
add-sqr-sqrt50.5%
cancel-sign-sub-inv50.5%
add-sqr-sqrt18.8%
sqrt-unprod30.4%
sqr-neg30.4%
sqrt-prod16.7%
add-sqr-sqrt33.6%
Applied egg-rr33.0%
Taylor expanded in b around -inf 3.0%
Final simplification3.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 / 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 51.8%
clear-num51.7%
associate-/r/51.7%
associate-/r*51.7%
metadata-eval51.7%
add-sqr-sqrt50.5%
cancel-sign-sub-inv50.5%
add-sqr-sqrt18.8%
sqrt-unprod30.4%
sqr-neg30.4%
sqrt-prod16.7%
add-sqr-sqrt33.6%
Applied egg-rr33.0%
Taylor expanded in a around 0 10.8%
Final simplification10.8%
(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 2024017
(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)))