
(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 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(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 (/ (* 2.0 c) (- (- b) (sqrt (fma -4.0 (* c a) (pow b 2.0))))))
double code(double a, double b, double c) {
return (2.0 * c) / (-b - sqrt(fma(-4.0, (c * a), pow(b, 2.0))));
}
function code(a, b, c) return Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(fma(-4.0, Float64(c * a), (b ^ 2.0))))) end
code[a_, b_, c_] := N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2 \cdot c}{\left(-b\right) - \sqrt{\mathsf{fma}\left(-4, c \cdot a, {b}^{2}\right)}}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
flip-+55.4%
Applied egg-rr57.8%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
div-inv99.2%
+-commutative99.2%
mul0-lft99.2%
div099.2%
fma-define99.2%
div099.2%
Applied egg-rr99.2%
*-commutative99.2%
times-frac99.3%
*-lft-identity99.3%
associate-/r*99.6%
*-lft-identity99.6%
*-commutative99.6%
times-frac99.6%
metadata-eval99.6%
fma-undefine99.6%
+-rgt-identity99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in c around 0 99.6%
(FPCore (a b c)
:precision binary64
(if (<= (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)) -2.6)
(/ (- (sqrt (fma b b (* c (* -4.0 a)))) b) (* 2.0 a))
(/
(/
1.0
(/
(+
(* -0.5 (/ b c))
(* a (+ (* 0.5 (/ (* c a) (pow b 3.0))) (* 0.5 (/ 1.0 b)))))
a))
(* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (((sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a)) <= -2.6) {
tmp = (sqrt(fma(b, b, (c * (-4.0 * a)))) - b) / (2.0 * a);
} else {
tmp = (1.0 / (((-0.5 * (b / c)) + (a * ((0.5 * ((c * a) / pow(b, 3.0))) + (0.5 * (1.0 / b))))) / a)) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)) <= -2.6) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(-4.0 * a)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(1.0 / Float64(Float64(Float64(-0.5 * Float64(b / c)) + Float64(a * Float64(Float64(0.5 * Float64(Float64(c * a) / (b ^ 3.0))) + Float64(0.5 * Float64(1.0 / b))))) / a)) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], -2.6], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(0.5 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a} \leq -2.6:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{-0.5 \cdot \frac{b}{c} + a \cdot \left(0.5 \cdot \frac{c \cdot a}{{b}^{3}} + 0.5 \cdot \frac{1}{b}\right)}{a}}}{2 \cdot a}\\
\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)) < -2.60000000000000009Initial program 86.3%
*-commutative86.3%
+-commutative86.3%
sqr-neg86.3%
unsub-neg86.3%
sqr-neg86.3%
fma-neg86.5%
distribute-lft-neg-in86.5%
*-commutative86.5%
*-commutative86.5%
distribute-rgt-neg-in86.5%
metadata-eval86.5%
Simplified86.5%
if -2.60000000000000009 < (/.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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip3--51.7%
metadata-eval51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
sub0-neg51.7%
+-lft-identity51.7%
mul0-lft51.7%
+-rgt-identity51.7%
Simplified51.7%
flip-+52.0%
Applied egg-rr54.3%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
clear-num99.3%
inv-pow99.3%
+-commutative99.3%
mul0-lft99.3%
div099.3%
fma-define99.3%
div099.3%
Applied egg-rr99.3%
unpow-199.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
+-commutative99.3%
fma-define99.3%
*-commutative99.3%
fma-undefine99.3%
+-rgt-identity99.3%
associate-*r*99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in a around 0 91.5%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))
(if (<= t_0 -2.6)
t_0
(/
(/
1.0
(/
(+
(* -0.5 (/ b c))
(* a (+ (* 0.5 (/ (* c a) (pow b 3.0))) (* 0.5 (/ 1.0 b)))))
a))
(* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
double tmp;
if (t_0 <= -2.6) {
tmp = t_0;
} else {
tmp = (1.0 / (((-0.5 * (b / c)) + (a * ((0.5 * ((c * a) / pow(b, 3.0))) + (0.5 * (1.0 / b))))) / a)) / (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) - (c * (a * 4.0d0)))) - b) / (2.0d0 * a)
if (t_0 <= (-2.6d0)) then
tmp = t_0
else
tmp = (1.0d0 / ((((-0.5d0) * (b / c)) + (a * ((0.5d0 * ((c * a) / (b ** 3.0d0))) + (0.5d0 * (1.0d0 / b))))) / a)) / (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) - (c * (a * 4.0)))) - b) / (2.0 * a);
double tmp;
if (t_0 <= -2.6) {
tmp = t_0;
} else {
tmp = (1.0 / (((-0.5 * (b / c)) + (a * ((0.5 * ((c * a) / Math.pow(b, 3.0))) + (0.5 * (1.0 / b))))) / a)) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a) tmp = 0 if t_0 <= -2.6: tmp = t_0 else: tmp = (1.0 / (((-0.5 * (b / c)) + (a * ((0.5 * ((c * a) / math.pow(b, 3.0))) + (0.5 * (1.0 / b))))) / a)) / (2.0 * a) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)) tmp = 0.0 if (t_0 <= -2.6) tmp = t_0; else tmp = Float64(Float64(1.0 / Float64(Float64(Float64(-0.5 * Float64(b / c)) + Float64(a * Float64(Float64(0.5 * Float64(Float64(c * a) / (b ^ 3.0))) + Float64(0.5 * Float64(1.0 / b))))) / a)) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a); tmp = 0.0; if (t_0 <= -2.6) tmp = t_0; else tmp = (1.0 / (((-0.5 * (b / c)) + (a * ((0.5 * ((c * a) / (b ^ 3.0))) + (0.5 * (1.0 / b))))) / a)) / (2.0 * a); 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[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2.6], t$95$0, N[(N[(1.0 / N[(N[(N[(-0.5 * N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(a * N[(N[(0.5 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\mathbf{if}\;t\_0 \leq -2.6:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{-0.5 \cdot \frac{b}{c} + a \cdot \left(0.5 \cdot \frac{c \cdot a}{{b}^{3}} + 0.5 \cdot \frac{1}{b}\right)}{a}}}{2 \cdot a}\\
\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)) < -2.60000000000000009Initial program 86.3%
if -2.60000000000000009 < (/.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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip3--51.7%
metadata-eval51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
sub0-neg51.7%
+-lft-identity51.7%
mul0-lft51.7%
+-rgt-identity51.7%
Simplified51.7%
flip-+52.0%
Applied egg-rr54.3%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
clear-num99.3%
inv-pow99.3%
+-commutative99.3%
mul0-lft99.3%
div099.3%
fma-define99.3%
div099.3%
Applied egg-rr99.3%
unpow-199.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
+-commutative99.3%
fma-define99.3%
*-commutative99.3%
fma-undefine99.3%
+-rgt-identity99.3%
associate-*r*99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in a around 0 91.5%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))
(if (<= t_0 -2.6)
t_0
(/
(/
1.0
(/
(+
(* -0.5 (/ b a))
(* c (+ (* 0.5 (/ (* c a) (pow b 3.0))) (* 0.5 (/ 1.0 b)))))
c))
(* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
double tmp;
if (t_0 <= -2.6) {
tmp = t_0;
} else {
tmp = (1.0 / (((-0.5 * (b / a)) + (c * ((0.5 * ((c * a) / pow(b, 3.0))) + (0.5 * (1.0 / b))))) / c)) / (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) - (c * (a * 4.0d0)))) - b) / (2.0d0 * a)
if (t_0 <= (-2.6d0)) then
tmp = t_0
else
tmp = (1.0d0 / ((((-0.5d0) * (b / a)) + (c * ((0.5d0 * ((c * a) / (b ** 3.0d0))) + (0.5d0 * (1.0d0 / b))))) / c)) / (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) - (c * (a * 4.0)))) - b) / (2.0 * a);
double tmp;
if (t_0 <= -2.6) {
tmp = t_0;
} else {
tmp = (1.0 / (((-0.5 * (b / a)) + (c * ((0.5 * ((c * a) / Math.pow(b, 3.0))) + (0.5 * (1.0 / b))))) / c)) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a) tmp = 0 if t_0 <= -2.6: tmp = t_0 else: tmp = (1.0 / (((-0.5 * (b / a)) + (c * ((0.5 * ((c * a) / math.pow(b, 3.0))) + (0.5 * (1.0 / b))))) / c)) / (2.0 * a) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)) tmp = 0.0 if (t_0 <= -2.6) tmp = t_0; else tmp = Float64(Float64(1.0 / Float64(Float64(Float64(-0.5 * Float64(b / a)) + Float64(c * Float64(Float64(0.5 * Float64(Float64(c * a) / (b ^ 3.0))) + Float64(0.5 * Float64(1.0 / b))))) / c)) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a); tmp = 0.0; if (t_0 <= -2.6) tmp = t_0; else tmp = (1.0 / (((-0.5 * (b / a)) + (c * ((0.5 * ((c * a) / (b ^ 3.0))) + (0.5 * (1.0 / b))))) / c)) / (2.0 * a); 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[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2.6], t$95$0, N[(N[(1.0 / N[(N[(N[(-0.5 * N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(c * N[(N[(0.5 * N[(N[(c * a), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\mathbf{if}\;t\_0 \leq -2.6:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{-0.5 \cdot \frac{b}{a} + c \cdot \left(0.5 \cdot \frac{c \cdot a}{{b}^{3}} + 0.5 \cdot \frac{1}{b}\right)}{c}}}{2 \cdot a}\\
\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)) < -2.60000000000000009Initial program 86.3%
if -2.60000000000000009 < (/.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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip3--51.7%
metadata-eval51.7%
metadata-eval51.7%
pow251.7%
Applied egg-rr51.7%
sub0-neg51.7%
+-lft-identity51.7%
mul0-lft51.7%
+-rgt-identity51.7%
Simplified51.7%
flip-+52.0%
Applied egg-rr54.3%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
clear-num99.3%
inv-pow99.3%
+-commutative99.3%
mul0-lft99.3%
div099.3%
fma-define99.3%
div099.3%
Applied egg-rr99.3%
unpow-199.3%
associate-*r*99.3%
*-commutative99.3%
*-commutative99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
+-commutative99.3%
fma-define99.3%
*-commutative99.3%
fma-undefine99.3%
+-rgt-identity99.3%
associate-*r*99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in c around 0 91.5%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))
(if (<= t_0 -0.1)
t_0
(/ (* 0.5 (/ (* (* c a) 4.0) a)) (- (* 2.0 (/ (* c a) b)) (* 2.0 b))))))
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
double tmp;
if (t_0 <= -0.1) {
tmp = t_0;
} else {
tmp = (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * 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) :: t_0
real(8) :: tmp
t_0 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (2.0d0 * a)
if (t_0 <= (-0.1d0)) then
tmp = t_0
else
tmp = (0.5d0 * (((c * a) * 4.0d0) / a)) / ((2.0d0 * ((c * a) / b)) - (2.0d0 * b))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
double tmp;
if (t_0 <= -0.1) {
tmp = t_0;
} else {
tmp = (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b));
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a) tmp = 0 if t_0 <= -0.1: tmp = t_0 else: tmp = (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b)) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)) tmp = 0.0 if (t_0 <= -0.1) tmp = t_0; else tmp = Float64(Float64(0.5 * Float64(Float64(Float64(c * a) * 4.0) / a)) / Float64(Float64(2.0 * Float64(Float64(c * a) / b)) - Float64(2.0 * b))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a); tmp = 0.0; if (t_0 <= -0.1) tmp = t_0; else tmp = (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b)); 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[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.1], t$95$0, N[(N[(0.5 * N[(N[(N[(c * a), $MachinePrecision] * 4.0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[(N[(2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(2.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\mathbf{if}\;t\_0 \leq -0.1:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \frac{\left(c \cdot a\right) \cdot 4}{a}}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}\\
\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.10000000000000001Initial program 82.6%
if -0.10000000000000001 < (/.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.7%
*-commutative50.7%
Simplified50.7%
neg-sub050.7%
flip3--50.1%
metadata-eval50.1%
metadata-eval50.1%
pow250.1%
Applied egg-rr50.1%
sub0-neg50.1%
+-lft-identity50.1%
mul0-lft50.1%
+-rgt-identity50.1%
Simplified50.1%
flip-+50.3%
Applied egg-rr52.7%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
div-inv99.2%
+-commutative99.2%
mul0-lft99.2%
div099.2%
fma-define99.2%
div099.2%
Applied egg-rr99.2%
*-commutative99.2%
times-frac99.3%
*-lft-identity99.3%
associate-/r*99.6%
*-lft-identity99.6%
*-commutative99.6%
times-frac99.6%
metadata-eval99.6%
fma-undefine99.6%
+-rgt-identity99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in c around 0 86.8%
Final simplification86.2%
(FPCore (a b c) :precision binary64 (/ (* 0.5 (/ (* 4.0 (* c (- a))) a)) (+ b (sqrt (+ (pow b 2.0) (* -4.0 (* c a)))))))
double code(double a, double b, double c) {
return (0.5 * ((4.0 * (c * -a)) / a)) / (b + sqrt((pow(b, 2.0) + (-4.0 * (c * 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.5d0 * ((4.0d0 * (c * -a)) / a)) / (b + sqrt(((b ** 2.0d0) + ((-4.0d0) * (c * a)))))
end function
public static double code(double a, double b, double c) {
return (0.5 * ((4.0 * (c * -a)) / a)) / (b + Math.sqrt((Math.pow(b, 2.0) + (-4.0 * (c * a)))));
}
def code(a, b, c): return (0.5 * ((4.0 * (c * -a)) / a)) / (b + math.sqrt((math.pow(b, 2.0) + (-4.0 * (c * a)))))
function code(a, b, c) return Float64(Float64(0.5 * Float64(Float64(4.0 * Float64(c * Float64(-a))) / a)) / Float64(b + sqrt(Float64((b ^ 2.0) + Float64(-4.0 * Float64(c * a)))))) end
function tmp = code(a, b, c) tmp = (0.5 * ((4.0 * (c * -a)) / a)) / (b + sqrt(((b ^ 2.0) + (-4.0 * (c * a))))); end
code[a_, b_, c_] := N[(N[(0.5 * N[(N[(4.0 * N[(c * (-a)), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(N[Power[b, 2.0], $MachinePrecision] + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{4 \cdot \left(c \cdot \left(-a\right)\right)}{a}}{b + \sqrt{{b}^{2} + -4 \cdot \left(c \cdot a\right)}}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
flip-+55.4%
Applied egg-rr57.8%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
div-inv99.2%
+-commutative99.2%
mul0-lft99.2%
div099.2%
fma-define99.2%
div099.2%
Applied egg-rr99.2%
*-commutative99.2%
times-frac99.3%
*-lft-identity99.3%
associate-/r*99.6%
*-lft-identity99.6%
*-commutative99.6%
times-frac99.6%
metadata-eval99.6%
fma-undefine99.6%
+-rgt-identity99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
Simplified99.6%
fma-undefine99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b c) :precision binary64 (/ (* 0.5 (/ (* (* c a) 4.0) a)) (- (* 2.0 (/ (* c a) b)) (* 2.0 b))))
double code(double a, double b, double c) {
return (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b));
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (0.5d0 * (((c * a) * 4.0d0) / a)) / ((2.0d0 * ((c * a) / b)) - (2.0d0 * b))
end function
public static double code(double a, double b, double c) {
return (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b));
}
def code(a, b, c): return (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b))
function code(a, b, c) return Float64(Float64(0.5 * Float64(Float64(Float64(c * a) * 4.0) / a)) / Float64(Float64(2.0 * Float64(Float64(c * a) / b)) - Float64(2.0 * b))) end
function tmp = code(a, b, c) tmp = (0.5 * (((c * a) * 4.0) / a)) / ((2.0 * ((c * a) / b)) - (2.0 * b)); end
code[a_, b_, c_] := N[(N[(0.5 * N[(N[(N[(c * a), $MachinePrecision] * 4.0), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / N[(N[(2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] - N[(2.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \frac{\left(c \cdot a\right) \cdot 4}{a}}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
flip-+55.4%
Applied egg-rr57.8%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
div-inv99.2%
+-commutative99.2%
mul0-lft99.2%
div099.2%
fma-define99.2%
div099.2%
Applied egg-rr99.2%
*-commutative99.2%
times-frac99.3%
*-lft-identity99.3%
associate-/r*99.6%
*-lft-identity99.6%
*-commutative99.6%
times-frac99.6%
metadata-eval99.6%
fma-undefine99.6%
+-rgt-identity99.6%
associate-*r*99.6%
*-commutative99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in c around 0 82.5%
Final simplification82.5%
(FPCore (a b c) :precision binary64 (/ (/ (* (* c a) 4.0) (* 2.0 (- (/ (* c a) b) b))) (* 2.0 a)))
double code(double a, double b, double c) {
return (((c * a) * 4.0) / (2.0 * (((c * a) / b) - b))) / (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 = (((c * a) * 4.0d0) / (2.0d0 * (((c * a) / b) - b))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (((c * a) * 4.0) / (2.0 * (((c * a) / b) - b))) / (2.0 * a);
}
def code(a, b, c): return (((c * a) * 4.0) / (2.0 * (((c * a) / b) - b))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(Float64(c * a) * 4.0) / Float64(2.0 * Float64(Float64(Float64(c * a) / b) - b))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (((c * a) * 4.0) / (2.0 * (((c * a) / b) - b))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[(N[(N[(c * a), $MachinePrecision] * 4.0), $MachinePrecision] / N[(2.0 * N[(N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\left(c \cdot a\right) \cdot 4}{2 \cdot \left(\frac{c \cdot a}{b} - b\right)}}{2 \cdot a}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
flip-+55.4%
Applied egg-rr57.8%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in c around 0 82.4%
distribute-lft-out--82.4%
*-commutative82.4%
Simplified82.4%
Taylor expanded in b around 0 82.4%
*-commutative82.4%
Simplified82.4%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (/ (/ 1.0 (/ (+ (* -0.5 (/ b a)) (* 0.5 (/ c b))) c)) (* 2.0 a)))
double code(double a, double b, double c) {
return (1.0 / (((-0.5 * (b / a)) + (0.5 * (c / b))) / 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 = (1.0d0 / ((((-0.5d0) * (b / a)) + (0.5d0 * (c / b))) / c)) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (1.0 / (((-0.5 * (b / a)) + (0.5 * (c / b))) / c)) / (2.0 * a);
}
def code(a, b, c): return (1.0 / (((-0.5 * (b / a)) + (0.5 * (c / b))) / c)) / (2.0 * a)
function code(a, b, c) return Float64(Float64(1.0 / Float64(Float64(Float64(-0.5 * Float64(b / a)) + Float64(0.5 * Float64(c / b))) / c)) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (1.0 / (((-0.5 * (b / a)) + (0.5 * (c / b))) / c)) / (2.0 * a); end
code[a_, b_, c_] := N[(N[(1.0 / N[(N[(N[(-0.5 * N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\frac{-0.5 \cdot \frac{b}{a} + 0.5 \cdot \frac{c}{b}}{c}}}{2 \cdot a}
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
flip-+55.4%
Applied egg-rr57.8%
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%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
clear-num99.2%
inv-pow99.2%
+-commutative99.2%
mul0-lft99.2%
div099.2%
fma-define99.2%
div099.2%
Applied egg-rr99.2%
unpow-199.2%
associate-*r*99.2%
*-commutative99.2%
*-commutative99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
+-commutative99.2%
fma-define99.2%
*-commutative99.2%
fma-undefine99.2%
+-rgt-identity99.2%
associate-*r*99.2%
*-commutative99.2%
Simplified99.2%
Taylor expanded in c around 0 82.3%
Final simplification82.3%
(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 55.8%
*-commutative55.8%
Simplified55.8%
Taylor expanded in b around inf 64.4%
associate-*r/64.4%
mul-1-neg64.4%
Simplified64.4%
Final simplification64.4%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
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
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 55.8%
*-commutative55.8%
Simplified55.8%
neg-sub055.8%
flip3--55.1%
metadata-eval55.1%
metadata-eval55.1%
pow255.1%
Applied egg-rr55.1%
sub0-neg55.1%
+-lft-identity55.1%
mul0-lft55.1%
+-rgt-identity55.1%
Simplified55.1%
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%
Taylor expanded in a around 0 3.2%
herbie shell --seed 2024123
(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)))