
(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 -4e+117)
(- (/ c b) (/ b a))
(if (<= b 5e-95)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(if (or (<= b 2.35e-80) (not (<= b 0.135)))
(/ (- c) b)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+117) {
tmp = (c / b) - (b / a);
} else if (b <= 5e-95) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else if ((b <= 2.35e-80) || !(b <= 0.135)) {
tmp = -c / b;
} else {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e+117) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5e-95) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); elseif ((b <= 2.35e-80) || !(b <= 0.135)) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e+117], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e-95], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 2.35e-80], N[Not[LessEqual[b, 0.135]], $MachinePrecision]], N[((-c) / b), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+117}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-95}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.35 \cdot 10^{-80} \lor \neg \left(b \leq 0.135\right):\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.0000000000000002e117Initial program 47.7%
Taylor expanded in b around -inf 96.8%
+-commutative96.8%
mul-1-neg96.8%
unsub-neg96.8%
Simplified96.8%
if -4.0000000000000002e117 < b < 4.9999999999999998e-95Initial program 86.9%
remove-double-neg86.9%
distribute-frac-neg86.9%
distribute-neg-out86.9%
remove-double-neg86.9%
sub-neg86.9%
distribute-frac-neg86.9%
neg-mul-186.9%
Simplified86.9%
if 4.9999999999999998e-95 < b < 2.34999999999999986e-80 or 0.13500000000000001 < b Initial program 16.5%
Taylor expanded in b around inf 83.2%
associate-*r/83.2%
neg-mul-183.2%
Simplified83.2%
if 2.34999999999999986e-80 < b < 0.13500000000000001Initial program 57.6%
remove-double-neg57.6%
distribute-frac-neg57.6%
distribute-neg-out57.6%
remove-double-neg57.6%
sub-neg57.6%
distribute-frac-neg57.6%
neg-mul-157.6%
Simplified57.6%
*-commutative57.6%
associate-*r*57.6%
metadata-eval57.6%
distribute-lft-neg-in57.6%
fma-neg57.6%
Applied egg-rr57.6%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -6.5e+116)
(- (/ c b) (/ b a))
(if (or (<= b 7e-95) (and (not (<= b 4.2e-78)) (<= b 0.74)))
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e+116) {
tmp = (c / b) - (b / a);
} else if ((b <= 7e-95) || (!(b <= 4.2e-78) && (b <= 0.74))) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-6.5d+116)) then
tmp = (c / b) - (b / a)
else if ((b <= 7d-95) .or. (.not. (b <= 4.2d-78)) .and. (b <= 0.74d0)) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e+116) {
tmp = (c / b) - (b / a);
} else if ((b <= 7e-95) || (!(b <= 4.2e-78) && (b <= 0.74))) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.5e+116: tmp = (c / b) - (b / a) elif (b <= 7e-95) or (not (b <= 4.2e-78) and (b <= 0.74)): tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.5e+116) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif ((b <= 7e-95) || (!(b <= 4.2e-78) && (b <= 0.74))) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6.5e+116) tmp = (c / b) - (b / a); elseif ((b <= 7e-95) || (~((b <= 4.2e-78)) && (b <= 0.74))) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.5e+116], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 7e-95], And[N[Not[LessEqual[b, 4.2e-78]], $MachinePrecision], LessEqual[b, 0.74]]], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.5 \cdot 10^{+116}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7 \cdot 10^{-95} \lor \neg \left(b \leq 4.2 \cdot 10^{-78}\right) \land b \leq 0.74:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -6.4999999999999998e116Initial program 47.7%
Taylor expanded in b around -inf 96.8%
+-commutative96.8%
mul-1-neg96.8%
unsub-neg96.8%
Simplified96.8%
if -6.4999999999999998e116 < b < 6.9999999999999994e-95 or 4.2000000000000001e-78 < b < 0.73999999999999999Initial program 82.9%
remove-double-neg82.9%
distribute-frac-neg82.9%
distribute-neg-out82.9%
remove-double-neg82.9%
sub-neg82.9%
distribute-frac-neg82.9%
neg-mul-182.9%
Simplified83.0%
*-commutative83.0%
associate-*r*82.9%
metadata-eval82.9%
distribute-lft-neg-in82.9%
fma-neg82.9%
Applied egg-rr82.9%
if 6.9999999999999994e-95 < b < 4.2000000000000001e-78 or 0.73999999999999999 < b Initial program 16.5%
Taylor expanded in b around inf 83.2%
associate-*r/83.2%
neg-mul-183.2%
Simplified83.2%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.95e-69)
(- (/ c b) (/ b a))
(if (<= b 6.5e-95)
(* (- (sqrt (* c (* a -4.0))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-69) {
tmp = (c / b) - (b / a);
} else if (b <= 6.5e-95) {
tmp = (sqrt((c * (a * -4.0))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
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.95d-69)) then
tmp = (c / b) - (b / a)
else if (b <= 6.5d-95) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) * (0.5d0 / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-69) {
tmp = (c / b) - (b / a);
} else if (b <= 6.5e-95) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.95e-69: tmp = (c / b) - (b / a) elif b <= 6.5e-95: tmp = (math.sqrt((c * (a * -4.0))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.95e-69) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 6.5e-95) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.95e-69) tmp = (c / b) - (b / a); elseif (b <= 6.5e-95) tmp = (sqrt((c * (a * -4.0))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.95e-69], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.5e-95], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.95 \cdot 10^{-69}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6.5 \cdot 10^{-95}:\\
\;\;\;\;\left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.9499999999999999e-69Initial program 68.0%
Taylor expanded in b around -inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -1.9499999999999999e-69 < b < 6.49999999999999985e-95Initial program 80.2%
Taylor expanded in b around 0 71.7%
*-commutative71.7%
associate-*r*71.8%
Simplified71.8%
div-inv71.7%
neg-mul-171.7%
fma-def71.7%
*-commutative71.7%
inv-pow71.7%
*-commutative71.7%
unpow-prod-down71.7%
metadata-eval71.7%
inv-pow71.7%
Applied egg-rr71.7%
*-commutative71.7%
fma-udef71.7%
neg-mul-171.7%
+-commutative71.7%
associate-*r/71.7%
metadata-eval71.7%
unsub-neg71.7%
associate-*r*71.7%
*-commutative71.7%
associate-*l*71.7%
Simplified71.7%
if 6.49999999999999985e-95 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c)
:precision binary64
(if (<= b -9.8e-79)
(- (/ c b) (/ b a))
(if (<= b 6.2e-95)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.8e-79) {
tmp = (c / b) - (b / a);
} else if (b <= 6.2e-95) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
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.8d-79)) then
tmp = (c / b) - (b / a)
else if (b <= 6.2d-95) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9.8e-79) {
tmp = (c / b) - (b / a);
} else if (b <= 6.2e-95) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.8e-79: tmp = (c / b) - (b / a) elif b <= 6.2e-95: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.8e-79) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 6.2e-95) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.8e-79) tmp = (c / b) - (b / a); elseif (b <= 6.2e-95) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.8e-79], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.2e-95], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.8 \cdot 10^{-79}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-95}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.8000000000000001e-79Initial program 68.0%
Taylor expanded in b around -inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -9.8000000000000001e-79 < b < 6.19999999999999983e-95Initial program 80.2%
Taylor expanded in b around 0 71.7%
*-commutative71.7%
associate-*r*71.8%
Simplified71.8%
expm1-log1p-u68.8%
expm1-udef41.1%
neg-mul-141.1%
fma-def41.1%
Applied egg-rr41.1%
expm1-def68.8%
expm1-log1p71.8%
fma-udef71.8%
neg-mul-171.8%
+-commutative71.8%
unsub-neg71.8%
associate-*r*71.7%
*-commutative71.7%
associate-*l*71.8%
Simplified71.8%
if 6.19999999999999983e-95 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
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 <= (-2d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 72.7%
Taylor expanded in b around -inf 76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
Simplified76.4%
if -1.999999999999994e-310 < b Initial program 36.2%
Taylor expanded in b around inf 58.1%
associate-*r/58.1%
neg-mul-158.1%
Simplified58.1%
Final simplification67.2%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
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 <= (-2d-310)) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 72.7%
Taylor expanded in b around -inf 76.3%
associate-*r/76.3%
mul-1-neg76.3%
Simplified76.3%
if -1.999999999999994e-310 < b Initial program 36.2%
Taylor expanded in b around inf 58.1%
associate-*r/58.1%
neg-mul-158.1%
Simplified58.1%
Final simplification67.2%
(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 54.5%
Taylor expanded in b around -inf 39.6%
associate-*r/39.6%
mul-1-neg39.6%
Simplified39.6%
Final simplification39.6%
(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 54.5%
Applied egg-rr25.3%
Taylor expanded in a around 0 2.6%
Final simplification2.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-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(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $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{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023279
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))