
(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 (/ (/ (* c (* 4.0 a)) (- (- b) (sqrt (fma b b (* (* c a) -4.0))))) (* a 2.0)))
double code(double a, double b, double c) {
return ((c * (4.0 * a)) / (-b - sqrt(fma(b, b, ((c * a) * -4.0))))) / (a * 2.0);
}
function code(a, b, c) return Float64(Float64(Float64(c * Float64(4.0 * a)) / Float64(Float64(-b) - sqrt(fma(b, b, Float64(Float64(c * a) * -4.0))))) / Float64(a * 2.0)) end
code[a_, b_, c_] := N[(N[(N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision] / N[((-b) - N[Sqrt[N[(b * b + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{c \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)}}}{a \cdot 2}
\end{array}
Initial program 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip--52.4%
metadata-eval52.4%
pow252.4%
add-sqr-sqrt51.6%
sqrt-prod52.4%
sqr-neg52.4%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod52.4%
sqr-neg52.4%
sqrt-prod51.6%
add-sqr-sqrt52.4%
Applied egg-rr52.4%
neg-sub052.4%
Simplified52.4%
flip-+52.5%
pow252.5%
pow252.5%
distribute-frac-neg52.5%
pow252.5%
pow152.5%
pow-div52.5%
metadata-eval52.5%
pow152.5%
add-sqr-sqrt53.9%
pow253.9%
associate-*l*53.9%
Applied egg-rr53.9%
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%
associate-*r*99.3%
*-commutative99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* a 2.0)) -2.2)
(* (- (sqrt (fma b b (* a (* c -4.0)))) b) (/ 1.0 (* a 2.0)))
(/ (/ t_0 (* 2.0 (- (* a (/ c b)) b))) (* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -2.2) {
tmp = (sqrt(fma(b, b, (a * (c * -4.0)))) - b) * (1.0 / (a * 2.0));
} else {
tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 2.0)) <= -2.2) tmp = Float64(Float64(sqrt(fma(b, b, Float64(a * Float64(c * -4.0)))) - b) * Float64(1.0 / Float64(a * 2.0))); else tmp = Float64(Float64(t_0 / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -2.2], N[(N[(N[Sqrt[N[(b * b + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{a \cdot 2} \leq -2.2:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - 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)) < -2.2000000000000002Initial program 83.9%
*-commutative83.9%
Simplified83.9%
neg-sub083.9%
flip--84.1%
metadata-eval84.1%
pow284.1%
add-sqr-sqrt82.4%
sqrt-prod84.1%
sqr-neg84.1%
sqrt-unprod0.0%
add-sqr-sqrt1.5%
sub-neg1.5%
neg-sub01.5%
add-sqr-sqrt0.0%
sqrt-unprod84.1%
sqr-neg84.1%
sqrt-prod82.4%
add-sqr-sqrt84.1%
Applied egg-rr84.1%
neg-sub084.1%
Simplified84.1%
div-inv84.2%
pow284.2%
distribute-frac-neg84.2%
pow284.2%
pow184.2%
pow-div84.0%
metadata-eval84.0%
pow184.0%
pow284.0%
associate-*l*84.0%
Applied egg-rr84.0%
cancel-sign-sub-inv84.0%
unpow284.0%
metadata-eval84.0%
*-commutative84.0%
fma-undefine84.2%
associate-*l*84.2%
Applied egg-rr84.2%
if -2.2000000000000002 < (/.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 47.2%
*-commutative47.2%
Simplified47.2%
neg-sub047.2%
flip--47.2%
metadata-eval47.2%
pow247.2%
add-sqr-sqrt46.5%
sqrt-prod47.2%
sqr-neg47.2%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod47.2%
sqr-neg47.2%
sqrt-prod46.5%
add-sqr-sqrt47.2%
Applied egg-rr47.2%
neg-sub047.2%
Simplified47.2%
flip-+47.2%
pow247.2%
pow247.2%
distribute-frac-neg47.2%
pow247.2%
pow147.2%
pow-div47.2%
metadata-eval47.2%
pow147.2%
add-sqr-sqrt48.7%
pow248.7%
associate-*l*48.7%
Applied egg-rr48.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%
unpow299.4%
fmm-def99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in b around 0 99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in a around 0 88.0%
distribute-lft-out--88.0%
associate-/l*88.0%
Simplified88.0%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* a 2.0)) -2.2)
(/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
(/ (/ t_0 (* 2.0 (- (* a (/ c b)) b))) (* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -2.2) {
tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
} else {
tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 2.0)) <= -2.2) tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(t_0 / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -2.2], 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[(t$95$0 / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{a \cdot 2} \leq -2.2:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - 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)) < -2.2000000000000002Initial program 83.9%
*-commutative83.9%
Simplified84.2%
if -2.2000000000000002 < (/.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 47.2%
*-commutative47.2%
Simplified47.2%
neg-sub047.2%
flip--47.2%
metadata-eval47.2%
pow247.2%
add-sqr-sqrt46.5%
sqrt-prod47.2%
sqr-neg47.2%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod47.2%
sqr-neg47.2%
sqrt-prod46.5%
add-sqr-sqrt47.2%
Applied egg-rr47.2%
neg-sub047.2%
Simplified47.2%
flip-+47.2%
pow247.2%
pow247.2%
distribute-frac-neg47.2%
pow247.2%
pow147.2%
pow-div47.2%
metadata-eval47.2%
pow147.2%
add-sqr-sqrt48.7%
pow248.7%
associate-*l*48.7%
Applied egg-rr48.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%
unpow299.4%
fmm-def99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in b around 0 99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in a around 0 88.0%
distribute-lft-out--88.0%
associate-/l*88.0%
Simplified88.0%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))) (t_1 (sqrt (- (* b b) t_0))))
(if (<= (/ (- t_1 b) (* a 2.0)) -2.2)
(/ (- t_1 (/ (* b b) b)) (* a 2.0))
(/ (/ t_0 (* 2.0 (- (* a (/ c b)) b))) (* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double t_1 = sqrt(((b * b) - t_0));
double tmp;
if (((t_1 - b) / (a * 2.0)) <= -2.2) {
tmp = (t_1 - ((b * b) / b)) / (a * 2.0);
} else {
tmp = (t_0 / (2.0 * ((a * (c / 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) :: t_1
real(8) :: tmp
t_0 = c * (4.0d0 * a)
t_1 = sqrt(((b * b) - t_0))
if (((t_1 - b) / (a * 2.0d0)) <= (-2.2d0)) then
tmp = (t_1 - ((b * b) / b)) / (a * 2.0d0)
else
tmp = (t_0 / (2.0d0 * ((a * (c / b)) - b))) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double t_1 = Math.sqrt(((b * b) - t_0));
double tmp;
if (((t_1 - b) / (a * 2.0)) <= -2.2) {
tmp = (t_1 - ((b * b) / b)) / (a * 2.0);
} else {
tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): t_0 = c * (4.0 * a) t_1 = math.sqrt(((b * b) - t_0)) tmp = 0 if ((t_1 - b) / (a * 2.0)) <= -2.2: tmp = (t_1 - ((b * b) / b)) / (a * 2.0) else: tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0) return tmp
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) t_1 = sqrt(Float64(Float64(b * b) - t_0)) tmp = 0.0 if (Float64(Float64(t_1 - b) / Float64(a * 2.0)) <= -2.2) tmp = Float64(Float64(t_1 - Float64(Float64(b * b) / b)) / Float64(a * 2.0)); else tmp = Float64(Float64(t_0 / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (4.0 * a); t_1 = sqrt(((b * b) - t_0)); tmp = 0.0; if (((t_1 - b) / (a * 2.0)) <= -2.2) tmp = (t_1 - ((b * b) / b)) / (a * 2.0); else tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -2.2], N[(N[(t$95$1 - N[(N[(b * b), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
t_1 := \sqrt{b \cdot b - t\_0}\\
\mathbf{if}\;\frac{t\_1 - b}{a \cdot 2} \leq -2.2:\\
\;\;\;\;\frac{t\_1 - \frac{b \cdot b}{b}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - 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)) < -2.2000000000000002Initial program 83.9%
*-commutative83.9%
Simplified83.9%
neg-sub083.9%
flip--84.1%
metadata-eval84.1%
pow284.1%
add-sqr-sqrt82.4%
sqrt-prod84.1%
sqr-neg84.1%
sqrt-unprod0.0%
add-sqr-sqrt1.5%
sub-neg1.5%
neg-sub01.5%
add-sqr-sqrt0.0%
sqrt-unprod84.1%
sqr-neg84.1%
sqrt-prod82.4%
add-sqr-sqrt84.1%
Applied egg-rr84.1%
neg-sub084.1%
Simplified84.1%
pow284.1%
Applied egg-rr84.1%
if -2.2000000000000002 < (/.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 47.2%
*-commutative47.2%
Simplified47.2%
neg-sub047.2%
flip--47.2%
metadata-eval47.2%
pow247.2%
add-sqr-sqrt46.5%
sqrt-prod47.2%
sqr-neg47.2%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod47.2%
sqr-neg47.2%
sqrt-prod46.5%
add-sqr-sqrt47.2%
Applied egg-rr47.2%
neg-sub047.2%
Simplified47.2%
flip-+47.2%
pow247.2%
pow247.2%
distribute-frac-neg47.2%
pow247.2%
pow147.2%
pow-div47.2%
metadata-eval47.2%
pow147.2%
add-sqr-sqrt48.7%
pow248.7%
associate-*l*48.7%
Applied egg-rr48.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%
unpow299.4%
fmm-def99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in b around 0 99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in a around 0 88.0%
distribute-lft-out--88.0%
associate-/l*88.0%
Simplified88.0%
Final simplification87.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* 4.0 a))))
(if (<= (/ (- (sqrt (- (* b b) t_0)) b) (* a 2.0)) -2.2)
(* (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (/ 0.5 a))
(/ (/ t_0 (* 2.0 (- (* a (/ c b)) b))) (* a 2.0)))))
double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double tmp;
if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -2.2) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) * (0.5 / a);
} else {
tmp = (t_0 / (2.0 * ((a * (c / 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 = c * (4.0d0 * a)
if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0d0)) <= (-2.2d0)) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) * (0.5d0 / a)
else
tmp = (t_0 / (2.0d0 * ((a * (c / b)) - b))) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (4.0 * a);
double tmp;
if (((Math.sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -2.2) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) * (0.5 / a);
} else {
tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): t_0 = c * (4.0 * a) tmp = 0 if ((math.sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -2.2: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) * (0.5 / a) else: tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0) return tmp
function code(a, b, c) t_0 = Float64(c * Float64(4.0 * a)) tmp = 0.0 if (Float64(Float64(sqrt(Float64(Float64(b * b) - t_0)) - b) / Float64(a * 2.0)) <= -2.2) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(t_0 / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (4.0 * a); tmp = 0.0; if (((sqrt(((b * b) - t_0)) - b) / (a * 2.0)) <= -2.2) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) * (0.5 / a); else tmp = (t_0 / (2.0 * ((a * (c / b)) - b))) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], -2.2], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(4 \cdot a\right)\\
\mathbf{if}\;\frac{\sqrt{b \cdot b - t\_0} - b}{a \cdot 2} \leq -2.2:\\
\;\;\;\;\left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{2 \cdot \left(a \cdot \frac{c}{b} - 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)) < -2.2000000000000002Initial program 83.9%
*-commutative83.9%
Simplified83.9%
neg-sub083.9%
flip--84.1%
metadata-eval84.1%
pow284.1%
add-sqr-sqrt82.4%
sqrt-prod84.1%
sqr-neg84.1%
sqrt-unprod0.0%
add-sqr-sqrt1.5%
sub-neg1.5%
neg-sub01.5%
add-sqr-sqrt0.0%
sqrt-unprod84.1%
sqr-neg84.1%
sqrt-prod82.4%
add-sqr-sqrt84.1%
Applied egg-rr84.1%
neg-sub084.1%
Simplified84.1%
div-inv84.2%
pow284.2%
distribute-frac-neg84.2%
pow284.2%
pow184.2%
pow-div84.0%
metadata-eval84.0%
pow184.0%
pow284.0%
associate-*l*84.0%
Applied egg-rr84.0%
pow284.1%
Applied egg-rr84.0%
Taylor expanded in a around 0 84.0%
if -2.2000000000000002 < (/.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 47.2%
*-commutative47.2%
Simplified47.2%
neg-sub047.2%
flip--47.2%
metadata-eval47.2%
pow247.2%
add-sqr-sqrt46.5%
sqrt-prod47.2%
sqr-neg47.2%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod47.2%
sqr-neg47.2%
sqrt-prod46.5%
add-sqr-sqrt47.2%
Applied egg-rr47.2%
neg-sub047.2%
Simplified47.2%
flip-+47.2%
pow247.2%
pow247.2%
distribute-frac-neg47.2%
pow247.2%
pow147.2%
pow-div47.2%
metadata-eval47.2%
pow147.2%
add-sqr-sqrt48.7%
pow248.7%
associate-*l*48.7%
Applied egg-rr48.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%
unpow299.4%
fmm-def99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in b around 0 99.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in a around 0 88.0%
distribute-lft-out--88.0%
associate-/l*88.0%
Simplified88.0%
Final simplification87.4%
(FPCore (a b c) :precision binary64 (/ (/ (* c (* 4.0 a)) (* 2.0 (- (* a (/ c b)) b))) (* a 2.0)))
double code(double a, double b, double c) {
return ((c * (4.0 * a)) / (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 = ((c * (4.0d0 * a)) / (2.0d0 * ((a * (c / b)) - b))) / (a * 2.0d0)
end function
public static double code(double a, double b, double c) {
return ((c * (4.0 * a)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0);
}
def code(a, b, c): return ((c * (4.0 * a)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0)
function code(a, b, c) return Float64(Float64(Float64(c * Float64(4.0 * a)) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))) / Float64(a * 2.0)) end
function tmp = code(a, b, c) tmp = ((c * (4.0 * a)) / (2.0 * ((a * (c / b)) - b))) / (a * 2.0); end
code[a_, b_, c_] := N[(N[(N[(c * N[(4.0 * a), $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{c \cdot \left(4 \cdot a\right)}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}}{a \cdot 2}
\end{array}
Initial program 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip--52.4%
metadata-eval52.4%
pow252.4%
add-sqr-sqrt51.6%
sqrt-prod52.4%
sqr-neg52.4%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod52.4%
sqr-neg52.4%
sqrt-prod51.6%
add-sqr-sqrt52.4%
Applied egg-rr52.4%
neg-sub052.4%
Simplified52.4%
flip-+52.5%
pow252.5%
pow252.5%
distribute-frac-neg52.5%
pow252.5%
pow152.5%
pow-div52.5%
metadata-eval52.5%
pow152.5%
add-sqr-sqrt53.9%
pow253.9%
associate-*l*53.9%
Applied egg-rr53.9%
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%
associate-*r*99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in a around 0 83.5%
distribute-lft-out--83.5%
associate-/l*83.5%
Simplified83.5%
(FPCore (a b c) :precision binary64 (/ (- c) b))
double code(double a, double b, double c) {
return -c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -c / b
end function
public static double code(double a, double b, double c) {
return -c / b;
}
def code(a, b, c): return -c / b
function code(a, b, c) return Float64(Float64(-c) / b) end
function tmp = code(a, b, c) tmp = -c / b; end
code[a_, b_, c_] := N[((-c) / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{-c}{b}
\end{array}
Initial program 52.4%
*-commutative52.4%
Simplified52.5%
Taylor expanded in b around inf 67.0%
associate-*r/67.0%
mul-1-neg67.0%
Simplified67.0%
(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 52.4%
*-commutative52.4%
Simplified52.4%
neg-sub052.4%
flip--52.4%
metadata-eval52.4%
pow252.4%
add-sqr-sqrt51.6%
sqrt-prod52.4%
sqr-neg52.4%
sqrt-unprod0.0%
add-sqr-sqrt1.6%
sub-neg1.6%
neg-sub01.6%
add-sqr-sqrt0.0%
sqrt-unprod52.4%
sqr-neg52.4%
sqrt-prod51.6%
add-sqr-sqrt52.4%
Applied egg-rr52.4%
neg-sub052.4%
Simplified52.4%
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 2024177
(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)))