
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c) :precision binary64 (/ (/ (* 4.0 (* a (- c))) (+ b (sqrt (fma b b (* (* a c) -4.0))))) (* a 2.0)))
double code(double a, double b, double c) {
return ((4.0 * (a * -c)) / (b + sqrt(fma(b, b, ((a * c) * -4.0))))) / (a * 2.0);
}
function code(a, b, c) return Float64(Float64(Float64(4.0 * Float64(a * Float64(-c))) / Float64(b + sqrt(fma(b, b, Float64(Float64(a * c) * -4.0))))) / Float64(a * 2.0)) end
code[a_, b_, c_] := N[(N[(N[(4.0 * N[(a * (-c)), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{4 \cdot \left(a \cdot \left(-c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}}}{a \cdot 2}
\end{array}
Initial program 58.2%
*-commutative58.2%
Simplified58.2%
neg-sub058.2%
flip--58.0%
metadata-eval58.0%
pow258.0%
add-sqr-sqrt56.9%
sqrt-prod58.0%
sqr-neg58.0%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod58.0%
sqr-neg58.0%
sqrt-prod56.9%
add-sqr-sqrt58.0%
Applied egg-rr58.0%
neg-sub058.0%
Simplified58.0%
flip-+58.0%
pow258.0%
pow258.0%
distribute-frac-neg58.0%
pow258.0%
pow158.0%
pow-div58.1%
metadata-eval58.1%
pow158.1%
add-sqr-sqrt59.7%
pow259.7%
associate-*l*59.7%
Applied egg-rr59.7%
associate--r-99.3%
unpow299.3%
unpow299.3%
difference-of-squares99.3%
+-commutative99.3%
neg-mul-199.3%
distribute-rgt1-in99.3%
metadata-eval99.3%
mul0-lft99.3%
unpow299.3%
fmm-def99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in b around 0 99.3%
Final simplification99.3%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0)) -46.0)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/
(/
(+ (* 4.0 (* a c)) (* 0.0 (+ b b)))
(- (- (* c (* -2.0 (* a (- (/ -1.0 b) (/ (* a c) (pow b 3.0)))))) b) b))
(* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0)) <= -46.0) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (((4.0 * (a * c)) + (0.0 * (b + b))) / (((c * (-2.0 * (a * ((-1.0 / b) - ((a * c) / pow(b, 3.0)))))) - b) - b)) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) <= -46.0) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(Float64(Float64(4.0 * Float64(a * c)) + Float64(0.0 * Float64(b + b))) / Float64(Float64(Float64(c * Float64(-2.0 * Float64(a * Float64(Float64(-1.0 / b) - Float64(Float64(a * c) / (b ^ 3.0)))))) - b) - b)) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -46.0], 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], N[(N[(N[(N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] + N[(0.0 * N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(c * N[(-2.0 * N[(a * N[(N[(-1.0 / b), $MachinePrecision] - N[(N[(a * c), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -46:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right) + 0 \cdot \left(b + b\right)}{\left(c \cdot \left(-2 \cdot \left(a \cdot \left(\frac{-1}{b} - \frac{a \cdot c}{{b}^{3}}\right)\right)\right) - b\right) - b}}{a \cdot 2}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -46Initial program 89.2%
*-commutative89.2%
Simplified89.2%
if -46 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 54.9%
*-commutative54.9%
Simplified54.9%
neg-sub054.9%
flip--54.6%
metadata-eval54.6%
pow254.6%
add-sqr-sqrt53.5%
sqrt-prod54.6%
sqr-neg54.6%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod54.6%
sqr-neg54.6%
sqrt-prod53.5%
add-sqr-sqrt54.6%
Applied egg-rr54.6%
neg-sub054.6%
Simplified54.6%
flip-+54.6%
pow254.6%
pow254.6%
distribute-frac-neg54.6%
pow254.6%
pow154.6%
pow-div54.8%
metadata-eval54.8%
pow154.8%
add-sqr-sqrt56.3%
pow256.3%
associate-*l*56.3%
Applied egg-rr56.3%
associate--r-99.3%
unpow299.3%
unpow299.3%
difference-of-squares99.3%
+-commutative99.3%
neg-mul-199.3%
distribute-rgt1-in99.3%
metadata-eval99.3%
mul0-lft99.3%
unpow299.3%
fmm-def99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in c around 0 90.5%
distribute-lft-out90.5%
associate-/l*90.5%
Simplified90.5%
Taylor expanded in a around 0 90.5%
+-commutative90.5%
Simplified90.5%
Final simplification90.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))
(if (<= t_0 -46.0)
t_0
(/
(/
(+ (* 4.0 (* a c)) (* 0.0 (+ b b)))
(- (- (* c (* -2.0 (* a (- (/ -1.0 b) (/ (* a c) (pow b 3.0)))))) b) b))
(* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -46.0) {
tmp = t_0;
} else {
tmp = (((4.0 * (a * c)) + (0.0 * (b + b))) / (((c * (-2.0 * (a * ((-1.0 / b) - ((a * c) / pow(b, 3.0)))))) - b) - b)) / (a * 2.0);
}
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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-46.0d0)) then
tmp = t_0
else
tmp = (((4.0d0 * (a * c)) + (0.0d0 * (b + b))) / (((c * ((-2.0d0) * (a * (((-1.0d0) / b) - ((a * c) / (b ** 3.0d0)))))) - b) - b)) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -46.0) {
tmp = t_0;
} else {
tmp = (((4.0 * (a * c)) + (0.0 * (b + b))) / (((c * (-2.0 * (a * ((-1.0 / b) - ((a * c) / Math.pow(b, 3.0)))))) - b) - b)) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -46.0: tmp = t_0 else: tmp = (((4.0 * (a * c)) + (0.0 * (b + b))) / (((c * (-2.0 * (a * ((-1.0 / b) - ((a * c) / math.pow(b, 3.0)))))) - b) - b)) / (a * 2.0) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -46.0) tmp = t_0; else tmp = Float64(Float64(Float64(Float64(4.0 * Float64(a * c)) + Float64(0.0 * Float64(b + b))) / Float64(Float64(Float64(c * Float64(-2.0 * Float64(a * Float64(Float64(-1.0 / b) - Float64(Float64(a * c) / (b ^ 3.0)))))) - b) - b)) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -46.0) tmp = t_0; else tmp = (((4.0 * (a * c)) + (0.0 * (b + b))) / (((c * (-2.0 * (a * ((-1.0 / b) - ((a * c) / (b ^ 3.0)))))) - b) - b)) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -46.0], t$95$0, N[(N[(N[(N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] + N[(0.0 * N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(c * N[(-2.0 * N[(a * N[(N[(-1.0 / b), $MachinePrecision] - N[(N[(a * c), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -46:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right) + 0 \cdot \left(b + b\right)}{\left(c \cdot \left(-2 \cdot \left(a \cdot \left(\frac{-1}{b} - \frac{a \cdot c}{{b}^{3}}\right)\right)\right) - b\right) - b}}{a \cdot 2}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -46Initial program 89.2%
if -46 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 54.9%
*-commutative54.9%
Simplified54.9%
neg-sub054.9%
flip--54.6%
metadata-eval54.6%
pow254.6%
add-sqr-sqrt53.5%
sqrt-prod54.6%
sqr-neg54.6%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod54.6%
sqr-neg54.6%
sqrt-prod53.5%
add-sqr-sqrt54.6%
Applied egg-rr54.6%
neg-sub054.6%
Simplified54.6%
flip-+54.6%
pow254.6%
pow254.6%
distribute-frac-neg54.6%
pow254.6%
pow154.6%
pow-div54.8%
metadata-eval54.8%
pow154.8%
add-sqr-sqrt56.3%
pow256.3%
associate-*l*56.3%
Applied egg-rr56.3%
associate--r-99.3%
unpow299.3%
unpow299.3%
difference-of-squares99.3%
+-commutative99.3%
neg-mul-199.3%
distribute-rgt1-in99.3%
metadata-eval99.3%
mul0-lft99.3%
unpow299.3%
fmm-def99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in c around 0 90.5%
distribute-lft-out90.5%
associate-/l*90.5%
Simplified90.5%
Taylor expanded in a around 0 90.5%
+-commutative90.5%
Simplified90.5%
Final simplification90.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* a 2.0))))
(if (<= t_0 -0.094)
t_0
(/
(/ (* 4.0 (* a c)) (- (- b) (+ b (* -2.0 (/ (* a c) b)))))
(* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.094) {
tmp = t_0;
} else {
tmp = ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0);
}
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) - (c * (4.0d0 * a)))) - b) / (a * 2.0d0)
if (t_0 <= (-0.094d0)) then
tmp = t_0
else
tmp = ((4.0d0 * (a * c)) / (-b - (b + ((-2.0d0) * ((a * c) / b))))) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0);
double tmp;
if (t_0 <= -0.094) {
tmp = t_0;
} else {
tmp = ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0) tmp = 0 if t_0 <= -0.094: tmp = t_0 else: tmp = ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -0.094) tmp = t_0; else tmp = Float64(Float64(Float64(4.0 * Float64(a * c)) / Float64(Float64(-b) - Float64(b + Float64(-2.0 * Float64(Float64(a * c) / b))))) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (4.0 * a)))) - b) / (a * 2.0); tmp = 0.0; if (t_0 <= -0.094) tmp = t_0; else tmp = ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.094], t$95$0, N[(N[(N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[(b + N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -0.094:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \left(b + -2 \cdot \frac{a \cdot c}{b}\right)}}{a \cdot 2}\\
\end{array}
\end{array}
if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) < -0.094Initial program 81.5%
if -0.094 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 #s(literal 4 binary64) a) c)))) (*.f64 #s(literal 2 binary64) a)) Initial program 50.5%
*-commutative50.5%
Simplified50.5%
neg-sub050.5%
flip--50.2%
metadata-eval50.2%
pow250.2%
add-sqr-sqrt49.3%
sqrt-prod50.2%
sqr-neg50.2%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod50.2%
sqr-neg50.2%
sqrt-prod49.3%
add-sqr-sqrt50.2%
Applied egg-rr50.2%
neg-sub050.2%
Simplified50.2%
flip-+50.2%
pow250.2%
pow250.2%
distribute-frac-neg50.2%
pow250.2%
pow150.2%
pow-div50.3%
metadata-eval50.3%
pow150.3%
add-sqr-sqrt51.8%
pow251.8%
associate-*l*51.8%
Applied egg-rr51.9%
associate--r-99.4%
unpow299.4%
unpow299.4%
difference-of-squares99.4%
+-commutative99.4%
neg-mul-199.4%
distribute-rgt1-in99.4%
metadata-eval99.4%
mul0-lft99.4%
unpow299.4%
fmm-def99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in b around 0 99.3%
Taylor expanded in a around 0 87.1%
Final simplification85.7%
(FPCore (a b c) :precision binary64 (/ (/ (* 4.0 (* a c)) (- (- b) (+ b (* -2.0 (/ (* a c) b))))) (* a 2.0)))
double code(double a, double b, double c) {
return ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((4.0d0 * (a * c)) / (-b - (b + ((-2.0d0) * ((a * c) / b))))) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
return ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0);
}
def code(a, b, c): return ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0)
function code(a, b, c) return Float64(Float64(Float64(4.0 * Float64(a * c)) / Float64(Float64(-b) - Float64(b + Float64(-2.0 * Float64(Float64(a * c) / b))))) / Float64(a * 2.0)) end
function tmp = code(a, b, c) tmp = ((4.0 * (a * c)) / (-b - (b + (-2.0 * ((a * c) / b))))) / (a * 2.0); end
code[a_, b_, c_] := N[(N[(N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[(b + N[(-2.0 * N[(N[(a * c), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{4 \cdot \left(a \cdot c\right)}{\left(-b\right) - \left(b + -2 \cdot \frac{a \cdot c}{b}\right)}}{a \cdot 2}
\end{array}
Initial program 58.2%
*-commutative58.2%
Simplified58.2%
neg-sub058.2%
flip--58.0%
metadata-eval58.0%
pow258.0%
add-sqr-sqrt56.9%
sqrt-prod58.0%
sqr-neg58.0%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod58.0%
sqr-neg58.0%
sqrt-prod56.9%
add-sqr-sqrt58.0%
Applied egg-rr58.0%
neg-sub058.0%
Simplified58.0%
flip-+58.0%
pow258.0%
pow258.0%
distribute-frac-neg58.0%
pow258.0%
pow158.0%
pow-div58.1%
metadata-eval58.1%
pow158.1%
add-sqr-sqrt59.7%
pow259.7%
associate-*l*59.7%
Applied egg-rr59.7%
associate--r-99.3%
unpow299.3%
unpow299.3%
difference-of-squares99.3%
+-commutative99.3%
neg-mul-199.3%
distribute-rgt1-in99.3%
metadata-eval99.3%
mul0-lft99.3%
unpow299.3%
fmm-def99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in b around 0 99.3%
Taylor expanded in a around 0 81.1%
(FPCore (a b c) :precision binary64 (/ (/ (* 4.0 (* a c)) (* 2.0 (- (* a (/ c b)) b))) (* a 2.0)))
double code(double a, double b, double c) {
return ((4.0 * (a * c)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((4.0d0 * (a * c)) / (2.0d0 * ((a * (c / b)) - b))) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
return ((4.0 * (a * c)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
def code(a, b, c): return ((4.0 * (a * c)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0)
function code(a, b, c) return Float64(Float64(Float64(4.0 * Float64(a * c)) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) / Float64(a * 2.0)) end
function tmp = code(a, b, c) tmp = ((4.0 * (a * c)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0); end
code[a_, b_, c_] := N[(N[(N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{4 \cdot \left(a \cdot c\right)}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}}{a \cdot 2}
\end{array}
Initial program 58.2%
*-commutative58.2%
Simplified58.2%
neg-sub058.2%
flip--58.0%
metadata-eval58.0%
pow258.0%
add-sqr-sqrt56.9%
sqrt-prod58.0%
sqr-neg58.0%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod58.0%
sqr-neg58.0%
sqrt-prod56.9%
add-sqr-sqrt58.0%
Applied egg-rr58.0%
neg-sub058.0%
Simplified58.0%
flip-+58.0%
pow258.0%
pow258.0%
distribute-frac-neg58.0%
pow258.0%
pow158.0%
pow-div58.1%
metadata-eval58.1%
pow158.1%
add-sqr-sqrt59.7%
pow259.7%
associate-*l*59.7%
Applied egg-rr59.7%
associate--r-99.3%
unpow299.3%
unpow299.3%
difference-of-squares99.3%
+-commutative99.3%
neg-mul-199.3%
distribute-rgt1-in99.3%
metadata-eval99.3%
mul0-lft99.3%
unpow299.3%
fmm-def99.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in b around 0 99.3%
Taylor expanded in a around 0 81.0%
distribute-lft-out--81.0%
associate-/l*81.0%
Simplified81.0%
(FPCore (a b c) :precision binary64 (/ c (- b)))
double code(double a, double b, double c) {
return c / -b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / -b
end function
public static double code(double a, double b, double c) {
return c / -b;
}
def code(a, b, c): return c / -b
function code(a, b, c) return Float64(c / Float64(-b)) end
function tmp = code(a, b, c) tmp = c / -b; end
code[a_, b_, c_] := N[(c / (-b)), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{-b}
\end{array}
Initial program 58.2%
*-commutative58.2%
Simplified58.2%
Taylor expanded in b around inf 62.6%
associate-*r/62.6%
mul-1-neg62.6%
Simplified62.6%
Final simplification62.6%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 58.2%
*-commutative58.2%
Simplified58.2%
neg-sub058.2%
flip--58.0%
metadata-eval58.0%
pow258.0%
add-sqr-sqrt56.9%
sqrt-prod58.0%
sqr-neg58.0%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod58.0%
sqr-neg58.0%
sqrt-prod56.9%
add-sqr-sqrt58.0%
Applied egg-rr58.0%
neg-sub058.0%
Simplified58.0%
Taylor expanded in a around 0 3.2%
associate-*r/3.2%
distribute-rgt1-in3.2%
metadata-eval3.2%
mul0-lft3.2%
metadata-eval3.2%
Simplified3.2%
herbie shell --seed 2024186
(FPCore (a b c)
:name "Quadratic roots, narrow range"
:precision binary64
:pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))