
(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 11 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 -1.66e-195)
(/ (- c) b)
(if (<= b 4e+101)
(* -0.5 (/ (+ b (sqrt (fma a (* c -4.0) (* b b)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 4e+101) {
tmp = -0.5 * ((b + sqrt(fma(a, (c * -4.0), (b * b)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.66e-195) tmp = Float64(Float64(-c) / b); elseif (b <= 4e+101) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.66e-195], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4e+101], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $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 -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+101}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.66e-195Initial program 20.6%
Simplified20.7%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -1.66e-195 < b < 3.9999999999999999e101Initial program 80.8%
Simplified80.8%
if 3.9999999999999999e101 < b Initial program 58.8%
Simplified58.8%
Taylor expanded in b around inf 95.3%
mul-1-neg95.3%
unsub-neg95.3%
Simplified95.3%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(/ (- c) b)
(if (<= b 8.5e+100)
(/ (- (- 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.66e-195) {
tmp = -c / b;
} else if (b <= 8.5e+100) {
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.66d-195)) then
tmp = -c / b
else if (b <= 8.5d+100) 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.66e-195) {
tmp = -c / b;
} else if (b <= 8.5e+100) {
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.66e-195: tmp = -c / b elif b <= 8.5e+100: 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.66e-195) tmp = Float64(Float64(-c) / b); elseif (b <= 8.5e+100) 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.66e-195) tmp = -c / b; elseif (b <= 8.5e+100) 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.66e-195], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 8.5e+100], 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.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+100}:\\
\;\;\;\;\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.66e-195Initial program 20.6%
Simplified20.7%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -1.66e-195 < b < 8.50000000000000043e100Initial program 80.8%
if 8.50000000000000043e100 < b Initial program 58.8%
Simplified58.8%
Taylor expanded in b around inf 95.3%
mul-1-neg95.3%
unsub-neg95.3%
Simplified95.3%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(/ (- c) b)
(if (<= b 1.35e+102)
(* (/ -0.5 a) (+ b (sqrt (+ (* b b) (* c (* a -4.0))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 1.35e+102) {
tmp = (-0.5 / a) * (b + sqrt(((b * b) + (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 <= (-1.66d-195)) then
tmp = -c / b
else if (b <= 1.35d+102) then
tmp = ((-0.5d0) / a) * (b + sqrt(((b * b) + (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 <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 1.35e+102) {
tmp = (-0.5 / a) * (b + Math.sqrt(((b * b) + (c * (a * -4.0)))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.66e-195: tmp = -c / b elif b <= 1.35e+102: tmp = (-0.5 / a) * (b + math.sqrt(((b * b) + (c * (a * -4.0))))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.66e-195) tmp = Float64(Float64(-c) / b); elseif (b <= 1.35e+102) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(b * b) + 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 <= -1.66e-195) tmp = -c / b; elseif (b <= 1.35e+102) tmp = (-0.5 / a) * (b + sqrt(((b * b) + (c * (a * -4.0))))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.66e-195], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.35e+102], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $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 -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{+102}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.66e-195Initial program 20.6%
Simplified20.7%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -1.66e-195 < b < 1.3500000000000001e102Initial program 80.8%
Simplified80.8%
expm1-log1p-u52.0%
expm1-udef27.4%
*-commutative27.4%
Applied egg-rr27.4%
expm1-def52.0%
expm1-log1p80.8%
associate-*l/80.8%
*-commutative80.8%
associate-/l*80.6%
associate-/r/80.7%
fma-udef80.7%
+-commutative80.7%
associate-*r*80.7%
metadata-eval80.7%
distribute-rgt-neg-in80.7%
associate-*r*80.7%
*-rgt-identity80.7%
fma-udef80.7%
*-rgt-identity80.7%
*-commutative80.7%
associate-*r*80.7%
distribute-rgt-neg-in80.7%
*-commutative80.7%
distribute-rgt-neg-in80.7%
metadata-eval80.7%
Simplified80.7%
fma-udef80.7%
Applied egg-rr80.7%
if 1.3500000000000001e102 < b Initial program 58.8%
Simplified58.8%
Taylor expanded in b around inf 95.3%
mul-1-neg95.3%
unsub-neg95.3%
Simplified95.3%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(/ (- c) b)
(if (<= b 1.55e-77)
(/ (- (- 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 <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 1.55e-77) {
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 <= (-1.66d-195)) then
tmp = -c / b
else if (b <= 1.55d-77) 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 <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 1.55e-77) {
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 <= -1.66e-195: tmp = -c / b elif b <= 1.55e-77: 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 <= -1.66e-195) tmp = Float64(Float64(-c) / b); elseif (b <= 1.55e-77) 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 <= -1.66e-195) tmp = -c / b; elseif (b <= 1.55e-77) 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, -1.66e-195], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.55e-77], 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 -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-77}:\\
\;\;\;\;\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 < -1.66e-195Initial program 20.6%
Simplified20.7%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -1.66e-195 < b < 1.55000000000000004e-77Initial program 77.0%
Taylor expanded in b around 0 70.3%
*-commutative70.3%
associate-*l*70.4%
Simplified70.4%
if 1.55000000000000004e-77 < b Initial program 67.0%
Simplified67.1%
Taylor expanded in b around inf 87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
Final simplification82.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(/ (- c) b)
(if (<= b 2.2e-77)
(* (/ -0.5 a) (+ b (sqrt (* c (* a -4.0)))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 2.2e-77) {
tmp = (-0.5 / a) * (b + 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 <= (-1.66d-195)) then
tmp = -c / b
else if (b <= 2.2d-77) then
tmp = ((-0.5d0) / a) * (b + 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 <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 2.2e-77) {
tmp = (-0.5 / a) * (b + Math.sqrt((c * (a * -4.0))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.66e-195: tmp = -c / b elif b <= 2.2e-77: tmp = (-0.5 / a) * (b + math.sqrt((c * (a * -4.0)))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.66e-195) tmp = Float64(Float64(-c) / b); elseif (b <= 2.2e-77) tmp = Float64(Float64(-0.5 / a) * Float64(b + 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 <= -1.66e-195) tmp = -c / b; elseif (b <= 2.2e-77) tmp = (-0.5 / a) * (b + sqrt((c * (a * -4.0)))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.66e-195], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.2e-77], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(c * N[(a * -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 -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-77}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.66e-195Initial program 20.6%
Simplified20.7%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -1.66e-195 < b < 2.20000000000000007e-77Initial program 77.0%
Simplified77.0%
expm1-log1p-u51.1%
expm1-udef25.7%
*-commutative25.7%
Applied egg-rr25.7%
expm1-def51.1%
expm1-log1p77.0%
associate-*l/77.0%
*-commutative77.0%
associate-/l*76.9%
associate-/r/77.0%
fma-udef77.0%
+-commutative77.0%
associate-*r*76.9%
metadata-eval76.9%
distribute-rgt-neg-in76.9%
associate-*r*77.0%
*-rgt-identity77.0%
fma-udef77.0%
*-rgt-identity77.0%
*-commutative77.0%
associate-*r*77.0%
distribute-rgt-neg-in77.0%
*-commutative77.0%
distribute-rgt-neg-in77.0%
metadata-eval77.0%
Simplified77.0%
Taylor expanded in b around 0 70.2%
*-commutative70.2%
associate-*r*70.3%
Simplified70.3%
if 2.20000000000000007e-77 < b Initial program 67.0%
Simplified67.1%
Taylor expanded in b around inf 87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
Final simplification82.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.66e-195)
(/ (- c) b)
(if (<= b 3.5e-77)
(* -0.5 (/ (sqrt (* a (/ c -0.25))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 3.5e-77) {
tmp = -0.5 * (sqrt((a * (c / -0.25))) / 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 <= (-1.66d-195)) then
tmp = -c / b
else if (b <= 3.5d-77) then
tmp = (-0.5d0) * (sqrt((a * (c / (-0.25d0)))) / 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 <= -1.66e-195) {
tmp = -c / b;
} else if (b <= 3.5e-77) {
tmp = -0.5 * (Math.sqrt((a * (c / -0.25))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.66e-195: tmp = -c / b elif b <= 3.5e-77: tmp = -0.5 * (math.sqrt((a * (c / -0.25))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.66e-195) tmp = Float64(Float64(-c) / b); elseif (b <= 3.5e-77) tmp = Float64(-0.5 * Float64(sqrt(Float64(a * Float64(c / -0.25))) / 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 <= -1.66e-195) tmp = -c / b; elseif (b <= 3.5e-77) tmp = -0.5 * (sqrt((a * (c / -0.25))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.66e-195], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.5e-77], N[(-0.5 * N[(N[Sqrt[N[(a * N[(c / -0.25), $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 -1.66 \cdot 10^{-195}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-77}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{a \cdot \frac{c}{-0.25}}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.66e-195Initial program 20.6%
Simplified20.7%
Taylor expanded in b around -inf 84.8%
associate-*r/84.8%
neg-mul-184.8%
Simplified84.8%
if -1.66e-195 < b < 3.50000000000000013e-77Initial program 77.0%
Simplified77.0%
pow1/277.0%
pow-to-exp72.4%
Applied egg-rr72.4%
Taylor expanded in a around -inf 42.3%
mul-1-neg42.3%
unsub-neg42.3%
*-commutative42.3%
Simplified42.3%
Taylor expanded in b around 0 42.0%
*-commutative42.0%
log-prod42.1%
+-commutative42.1%
log-prod42.0%
log-div64.8%
exp-to-pow68.9%
unpow1/268.9%
associate-/r/68.9%
*-commutative68.9%
associate-/l*68.9%
metadata-eval68.9%
Simplified68.9%
if 3.50000000000000013e-77 < b Initial program 67.0%
Simplified67.1%
Taylor expanded in b around inf 87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
Final simplification82.3%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 30.0%
Simplified30.0%
Taylor expanded in b around -inf 70.6%
associate-*r/70.6%
neg-mul-170.6%
Simplified70.6%
if -3.999999999999988e-310 < b Initial program 70.4%
Simplified70.5%
Taylor expanded in b around inf 71.9%
mul-1-neg71.9%
unsub-neg71.9%
Simplified71.9%
Final simplification71.2%
(FPCore (a b c) :precision binary64 (if (<= b -6.3e-27) (/ c b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.3e-27) {
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 <= (-6.3d-27)) 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 <= -6.3e-27) {
tmp = c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.3e-27: tmp = c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.3e-27) tmp = 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 <= -6.3e-27) tmp = c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.3e-27], N[(c / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.3 \cdot 10^{-27}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -6.3000000000000001e-27Initial program 13.8%
Simplified13.8%
Taylor expanded in b around inf 2.7%
mul-1-neg2.7%
unsub-neg2.7%
Simplified2.7%
Taylor expanded in c around inf 22.3%
if -6.3000000000000001e-27 < b Initial program 65.6%
Simplified65.7%
Taylor expanded in b around inf 48.1%
associate-*r/48.1%
mul-1-neg48.1%
Simplified48.1%
Final simplification39.0%
(FPCore (a b c) :precision binary64 (if (<= b -3.8e-298) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-298) {
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.8d-298)) 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.8e-298) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.8e-298: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.8e-298) 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.8e-298) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.8e-298], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.8 \cdot 10^{-298}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -3.8e-298Initial program 28.5%
Simplified28.6%
Taylor expanded in b around -inf 72.0%
associate-*r/72.0%
neg-mul-172.0%
Simplified72.0%
if -3.8e-298 < b Initial program 71.2%
Simplified71.3%
Taylor expanded in b around inf 69.8%
associate-*r/69.8%
mul-1-neg69.8%
Simplified69.8%
Final simplification71.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 47.2%
Simplified47.3%
clear-num47.2%
un-div-inv47.2%
Applied egg-rr47.2%
Taylor expanded in b around -inf 41.0%
Taylor expanded in b around 0 2.8%
Final simplification2.8%
(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 47.2%
Simplified47.3%
Taylor expanded in b around inf 31.9%
mul-1-neg31.9%
unsub-neg31.9%
Simplified31.9%
Taylor expanded in c around inf 9.7%
Final simplification9.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 2023213
(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)))