
(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
(if (<= b -6e+153)
(/ b (- a))
(if (<= b 4.2e-57)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e+153) {
tmp = b / -a;
} else if (b <= 4.2e-57) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-6d+153)) then
tmp = b / -a
else if (b <= 4.2d-57) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6e+153) {
tmp = b / -a;
} else if (b <= 4.2e-57) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e+153: tmp = b / -a elif b <= 4.2e-57: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e+153) tmp = Float64(b / Float64(-a)); elseif (b <= 4.2e-57) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6e+153) tmp = b / -a; elseif (b <= 4.2e-57) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e+153], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 4.2e-57], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{+153}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-57}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -6.00000000000000037e153Initial program 46.6%
*-commutative46.6%
Simplified46.6%
*-commutative46.6%
add-sqr-sqrt23.5%
sqrt-unprod46.1%
*-commutative46.1%
*-commutative46.1%
swap-sqr46.1%
metadata-eval46.1%
metadata-eval46.1%
swap-sqr46.1%
sqrt-unprod22.8%
add-sqr-sqrt45.9%
add-cube-cbrt45.9%
pow345.9%
Applied egg-rr46.6%
Taylor expanded in b around -inf 91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
if -6.00000000000000037e153 < b < 4.1999999999999999e-57Initial program 86.3%
if 4.1999999999999999e-57 < b Initial program 8.6%
*-commutative8.6%
Simplified8.6%
*-commutative8.6%
add-sqr-sqrt5.8%
sqrt-unprod6.7%
*-commutative6.7%
*-commutative6.7%
swap-sqr6.7%
metadata-eval6.7%
metadata-eval6.7%
swap-sqr6.7%
sqrt-unprod1.2%
add-sqr-sqrt5.9%
add-cube-cbrt5.9%
pow35.9%
Applied egg-rr8.6%
Applied egg-rr8.6%
Taylor expanded in b around inf 93.9%
associate-*r/93.9%
mul-1-neg93.9%
Simplified93.9%
Final simplification89.8%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-127)
(- (/ c b) (/ b a))
(if (<= b 5.2e-47)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-127) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e-47) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5.8d-127)) then
tmp = (c / b) - (b / a)
else if (b <= 5.2d-47) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-127) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e-47) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-127: tmp = (c / b) - (b / a) elif b <= 5.2e-47: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-127) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.2e-47) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e-127) tmp = (c / b) - (b / a); elseif (b <= 5.2e-47) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-127], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.2e-47], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{-127}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.8000000000000001e-127Initial program 80.1%
*-commutative80.1%
Simplified80.1%
*-commutative80.1%
add-sqr-sqrt42.2%
sqrt-unprod68.9%
*-commutative68.9%
*-commutative68.9%
swap-sqr68.9%
metadata-eval68.9%
metadata-eval68.9%
swap-sqr68.9%
sqrt-unprod33.0%
add-sqr-sqrt64.9%
add-cube-cbrt64.9%
pow364.9%
Applied egg-rr79.9%
Applied egg-rr79.9%
Taylor expanded in b around -inf 81.4%
mul-1-neg81.4%
*-commutative81.4%
distribute-rgt-neg-in81.4%
+-commutative81.4%
mul-1-neg81.4%
unsub-neg81.4%
Simplified81.4%
Taylor expanded in a around 0 79.5%
+-commutative79.5%
*-commutative79.5%
associate-*r/81.6%
mul-1-neg81.6%
unsub-neg81.6%
div-sub81.6%
associate-/l*81.6%
associate-/l/77.4%
associate-/r*81.7%
*-inverses81.7%
associate-*r/81.7%
*-rgt-identity81.7%
Simplified81.7%
if -5.8000000000000001e-127 < b < 5.2e-47Initial program 75.6%
*-commutative75.6%
Simplified75.6%
*-commutative75.6%
add-sqr-sqrt37.4%
sqrt-unprod24.6%
*-commutative24.6%
*-commutative24.6%
swap-sqr24.6%
metadata-eval24.6%
metadata-eval24.6%
swap-sqr24.6%
sqrt-unprod0.6%
add-sqr-sqrt2.9%
add-cube-cbrt2.9%
pow32.9%
Applied egg-rr74.8%
Taylor expanded in c around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt71.0%
distribute-lft-neg-in71.0%
metadata-eval71.0%
rem-cube-cbrt71.6%
Simplified71.6%
if 5.2e-47 < b Initial program 8.6%
*-commutative8.6%
Simplified8.6%
*-commutative8.6%
add-sqr-sqrt5.8%
sqrt-unprod6.7%
*-commutative6.7%
*-commutative6.7%
swap-sqr6.7%
metadata-eval6.7%
metadata-eval6.7%
swap-sqr6.7%
sqrt-unprod1.2%
add-sqr-sqrt5.9%
add-cube-cbrt5.9%
pow35.9%
Applied egg-rr8.6%
Applied egg-rr8.6%
Taylor expanded in b around inf 93.9%
associate-*r/93.9%
mul-1-neg93.9%
Simplified93.9%
Final simplification83.7%
(FPCore (a b c) :precision binary64 (if (<= b -2.6e-208) (- (/ c b) (/ b a)) (if (<= b 4.5e-167) (* -0.5 (sqrt (* c (/ -4.0 a)))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-208) {
tmp = (c / b) - (b / a);
} else if (b <= 4.5e-167) {
tmp = -0.5 * sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.6d-208)) then
tmp = (c / b) - (b / a)
else if (b <= 4.5d-167) then
tmp = (-0.5d0) * sqrt((c * ((-4.0d0) / a)))
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.6e-208) {
tmp = (c / b) - (b / a);
} else if (b <= 4.5e-167) {
tmp = -0.5 * Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.6e-208: tmp = (c / b) - (b / a) elif b <= 4.5e-167: tmp = -0.5 * math.sqrt((c * (-4.0 / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.6e-208) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.5e-167) tmp = Float64(-0.5 * sqrt(Float64(c * Float64(-4.0 / a)))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.6e-208) tmp = (c / b) - (b / a); elseif (b <= 4.5e-167) tmp = -0.5 * sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.6e-208], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.5e-167], N[(-0.5 * N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.6 \cdot 10^{-208}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{-167}:\\
\;\;\;\;-0.5 \cdot \sqrt{c \cdot \frac{-4}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.60000000000000017e-208Initial program 79.7%
*-commutative79.7%
Simplified79.7%
*-commutative79.7%
add-sqr-sqrt43.6%
sqrt-unprod66.1%
*-commutative66.1%
*-commutative66.1%
swap-sqr66.1%
metadata-eval66.1%
metadata-eval66.1%
swap-sqr66.1%
sqrt-unprod29.7%
add-sqr-sqrt59.5%
add-cube-cbrt59.5%
pow359.5%
Applied egg-rr79.4%
Applied egg-rr79.6%
Taylor expanded in b around -inf 74.4%
mul-1-neg74.4%
*-commutative74.4%
distribute-rgt-neg-in74.4%
+-commutative74.4%
mul-1-neg74.4%
unsub-neg74.4%
Simplified74.4%
Taylor expanded in a around 0 74.5%
+-commutative74.5%
*-commutative74.5%
associate-*r/76.5%
mul-1-neg76.5%
unsub-neg76.5%
div-sub76.5%
associate-/l*76.5%
associate-/l/69.9%
associate-/r*76.5%
*-inverses76.5%
associate-*r/76.5%
*-rgt-identity76.5%
Simplified76.5%
if -2.60000000000000017e-208 < b < 4.5000000000000001e-167Initial program 74.4%
*-commutative74.4%
Simplified74.4%
*-commutative74.4%
add-sqr-sqrt14.2%
sqrt-unprod14.5%
*-commutative14.5%
*-commutative14.5%
swap-sqr14.5%
metadata-eval14.5%
metadata-eval14.5%
swap-sqr14.5%
sqrt-unprod0.3%
add-sqr-sqrt0.7%
add-cube-cbrt0.7%
pow30.7%
Applied egg-rr73.7%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt28.0%
associate-/l*28.0%
rem-cube-cbrt28.2%
Simplified28.2%
pow128.2%
*-commutative28.2%
add-sqr-sqrt0.7%
sqrt-unprod53.5%
mul-1-neg53.5%
mul-1-neg53.5%
sqr-neg53.5%
add-sqr-sqrt53.5%
associate-*r/53.3%
Applied egg-rr53.3%
unpow153.3%
*-commutative53.3%
associate-/l*53.5%
Simplified53.5%
if 4.5000000000000001e-167 < b Initial program 21.8%
*-commutative21.8%
Simplified21.8%
*-commutative21.8%
add-sqr-sqrt16.1%
sqrt-unprod11.2%
*-commutative11.2%
*-commutative11.2%
swap-sqr11.2%
metadata-eval11.2%
metadata-eval11.2%
swap-sqr11.2%
sqrt-unprod1.0%
add-sqr-sqrt4.9%
add-cube-cbrt4.9%
pow34.9%
Applied egg-rr21.6%
Applied egg-rr21.8%
Taylor expanded in b around inf 81.6%
associate-*r/81.6%
mul-1-neg81.6%
Simplified81.6%
Final simplification76.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.42e-188) (- (/ c b) (/ b a)) (if (<= b 4.8e-105) (sqrt (/ (- c) a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.42e-188) {
tmp = (c / b) - (b / a);
} else if (b <= 4.8e-105) {
tmp = sqrt((-c / a));
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.42d-188)) then
tmp = (c / b) - (b / a)
else if (b <= 4.8d-105) then
tmp = sqrt((-c / a))
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.42e-188) {
tmp = (c / b) - (b / a);
} else if (b <= 4.8e-105) {
tmp = Math.sqrt((-c / a));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.42e-188: tmp = (c / b) - (b / a) elif b <= 4.8e-105: tmp = math.sqrt((-c / a)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.42e-188) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.8e-105) tmp = sqrt(Float64(Float64(-c) / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.42e-188) tmp = (c / b) - (b / a); elseif (b <= 4.8e-105) tmp = sqrt((-c / a)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.42e-188], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.8e-105], N[Sqrt[N[((-c) / a), $MachinePrecision]], $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.42 \cdot 10^{-188}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-105}:\\
\;\;\;\;\sqrt{\frac{-c}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.4200000000000001e-188Initial program 79.6%
*-commutative79.6%
Simplified79.6%
*-commutative79.6%
add-sqr-sqrt43.1%
sqrt-unprod65.8%
*-commutative65.8%
*-commutative65.8%
swap-sqr65.8%
metadata-eval65.8%
metadata-eval65.8%
swap-sqr65.8%
sqrt-unprod30.0%
add-sqr-sqrt60.1%
add-cube-cbrt60.1%
pow360.1%
Applied egg-rr79.2%
Applied egg-rr79.4%
Taylor expanded in b around -inf 75.0%
mul-1-neg75.0%
*-commutative75.0%
distribute-rgt-neg-in75.0%
+-commutative75.0%
mul-1-neg75.0%
unsub-neg75.0%
Simplified75.0%
Taylor expanded in a around 0 75.2%
+-commutative75.2%
*-commutative75.2%
associate-*r/77.1%
mul-1-neg77.1%
unsub-neg77.1%
div-sub77.1%
associate-/l*77.1%
associate-/l/70.5%
associate-/r*77.2%
*-inverses77.2%
associate-*r/77.2%
*-rgt-identity77.2%
Simplified77.2%
if -1.4200000000000001e-188 < b < 4.8000000000000003e-105Initial program 78.4%
*-commutative78.4%
Simplified78.4%
*-commutative78.4%
add-sqr-sqrt33.8%
sqrt-unprod21.1%
*-commutative21.1%
*-commutative21.1%
swap-sqr21.1%
metadata-eval21.1%
metadata-eval21.1%
swap-sqr21.1%
sqrt-unprod0.2%
add-sqr-sqrt0.7%
add-cube-cbrt0.7%
pow30.7%
Applied egg-rr77.7%
Taylor expanded in c around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt30.8%
associate-/l*30.8%
rem-cube-cbrt31.0%
Simplified31.0%
add-sqr-sqrt31.0%
sqr-neg31.0%
mul-1-neg31.0%
mul-1-neg31.0%
sqrt-unprod0.8%
add-sqr-sqrt40.8%
mul-1-neg40.8%
sqrt-prod50.9%
distribute-rgt-neg-in50.9%
Applied egg-rr50.9%
distribute-rgt-neg-out50.9%
distribute-lft-neg-out50.9%
*-commutative50.9%
Simplified50.9%
add-sqr-sqrt0.0%
sqrt-unprod1.2%
*-commutative1.2%
*-commutative1.2%
swap-sqr1.2%
Applied egg-rr30.9%
associate-*l*30.9%
associate-*l/30.9%
metadata-eval30.9%
metadata-eval30.9%
associate-/r*30.9%
*-commutative30.9%
associate-/l*30.9%
times-frac30.9%
metadata-eval30.9%
associate-*l/30.9%
*-commutative30.9%
mul-1-neg30.9%
Simplified30.9%
if 4.8000000000000003e-105 < b Initial program 13.3%
*-commutative13.3%
Simplified13.3%
*-commutative13.3%
add-sqr-sqrt8.7%
sqrt-unprod8.7%
*-commutative8.7%
*-commutative8.7%
swap-sqr8.7%
metadata-eval8.7%
metadata-eval8.7%
swap-sqr8.7%
sqrt-unprod1.1%
add-sqr-sqrt5.5%
add-cube-cbrt5.5%
pow35.5%
Applied egg-rr13.2%
Applied egg-rr13.3%
Taylor expanded in b around inf 89.7%
associate-*r/89.7%
mul-1-neg89.7%
Simplified89.7%
Final simplification74.2%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-310)) then
tmp = (c / b) - (b / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = (c / b) - (b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 79.2%
*-commutative79.2%
Simplified79.2%
*-commutative79.2%
add-sqr-sqrt41.3%
sqrt-unprod61.7%
*-commutative61.7%
*-commutative61.7%
swap-sqr61.7%
metadata-eval61.7%
metadata-eval61.7%
swap-sqr61.7%
sqrt-unprod27.1%
add-sqr-sqrt54.1%
add-cube-cbrt54.1%
pow354.1%
Applied egg-rr78.8%
Applied egg-rr79.0%
Taylor expanded in b around -inf 67.7%
mul-1-neg67.7%
*-commutative67.7%
distribute-rgt-neg-in67.7%
+-commutative67.7%
mul-1-neg67.7%
unsub-neg67.7%
Simplified67.7%
Taylor expanded in a around 0 68.0%
+-commutative68.0%
*-commutative68.0%
associate-*r/69.7%
mul-1-neg69.7%
unsub-neg69.7%
div-sub69.7%
associate-/l*69.7%
associate-/l/63.7%
associate-/r*69.8%
*-inverses69.8%
associate-*r/69.8%
*-rgt-identity69.8%
Simplified69.8%
if -1.999999999999994e-310 < b Initial program 29.1%
*-commutative29.1%
Simplified29.1%
*-commutative29.1%
add-sqr-sqrt15.5%
sqrt-unprod11.3%
*-commutative11.3%
*-commutative11.3%
swap-sqr11.3%
metadata-eval11.3%
metadata-eval11.3%
swap-sqr11.3%
sqrt-unprod0.9%
add-sqr-sqrt4.3%
add-cube-cbrt4.3%
pow34.3%
Applied egg-rr28.8%
Applied egg-rr29.1%
Taylor expanded in b around inf 71.3%
associate-*r/71.3%
mul-1-neg71.3%
Simplified71.3%
Final simplification70.6%
(FPCore (a b c) :precision binary64 (if (<= b 1.85e-290) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.85e-290) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 1.85d-290) then
tmp = b / -a
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.85e-290) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.85e-290: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.85e-290) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.85e-290) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.85e-290], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.85 \cdot 10^{-290}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 1.84999999999999989e-290Initial program 79.9%
*-commutative79.9%
Simplified79.9%
*-commutative79.9%
add-sqr-sqrt40.8%
sqrt-unprod60.5%
*-commutative60.5%
*-commutative60.5%
swap-sqr60.5%
metadata-eval60.5%
metadata-eval60.5%
swap-sqr60.5%
sqrt-unprod26.2%
add-sqr-sqrt52.3%
add-cube-cbrt52.3%
pow352.3%
Applied egg-rr79.5%
Taylor expanded in b around -inf 67.3%
associate-*r/67.3%
mul-1-neg67.3%
Simplified67.3%
if 1.84999999999999989e-290 < b Initial program 27.0%
*-commutative27.0%
Simplified27.0%
*-commutative27.0%
add-sqr-sqrt15.2%
sqrt-unprod10.9%
*-commutative10.9%
*-commutative10.9%
swap-sqr10.9%
metadata-eval10.9%
metadata-eval10.9%
swap-sqr10.9%
sqrt-unprod0.9%
add-sqr-sqrt4.5%
add-cube-cbrt4.5%
pow34.5%
Applied egg-rr26.7%
Applied egg-rr27.0%
Taylor expanded in b around inf 73.4%
associate-*r/73.4%
mul-1-neg73.4%
Simplified73.4%
Final simplification70.5%
(FPCore (a b c) :precision binary64 (if (<= b 2.15e-29) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.15e-29) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 2.15d-29) then
tmp = b / -a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.15e-29) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.15e-29: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.15e-29) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.15e-29) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.15e-29], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.15 \cdot 10^{-29}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.1499999999999999e-29Initial program 77.7%
*-commutative77.7%
Simplified77.7%
*-commutative77.7%
add-sqr-sqrt39.9%
sqrt-unprod50.6%
*-commutative50.6%
*-commutative50.6%
swap-sqr50.6%
metadata-eval50.6%
metadata-eval50.6%
swap-sqr50.6%
sqrt-unprod19.8%
add-sqr-sqrt39.7%
add-cube-cbrt39.7%
pow339.7%
Applied egg-rr77.3%
Taylor expanded in b around -inf 51.6%
associate-*r/51.6%
mul-1-neg51.6%
Simplified51.6%
if 2.1499999999999999e-29 < b Initial program 8.2%
*-commutative8.2%
Simplified8.2%
*-commutative8.2%
add-sqr-sqrt5.8%
sqrt-unprod6.8%
*-commutative6.8%
*-commutative6.8%
swap-sqr6.8%
metadata-eval6.8%
metadata-eval6.8%
swap-sqr6.8%
sqrt-unprod1.2%
add-sqr-sqrt5.9%
add-cube-cbrt5.9%
pow35.9%
Applied egg-rr8.1%
Applied egg-rr8.2%
Taylor expanded in b around -inf 2.2%
mul-1-neg2.2%
*-commutative2.2%
distribute-rgt-neg-in2.2%
+-commutative2.2%
mul-1-neg2.2%
unsub-neg2.2%
Simplified2.2%
Taylor expanded in a around inf 27.6%
Final simplification42.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 52.2%
*-commutative52.2%
Simplified52.2%
*-commutative52.2%
add-sqr-sqrt27.4%
sqrt-unprod34.5%
*-commutative34.5%
*-commutative34.5%
swap-sqr34.5%
metadata-eval34.5%
metadata-eval34.5%
swap-sqr34.5%
sqrt-unprod12.9%
add-sqr-sqrt27.3%
add-cube-cbrt27.3%
pow327.3%
Applied egg-rr51.9%
Applied egg-rr52.1%
Taylor expanded in b around -inf 32.3%
mul-1-neg32.3%
*-commutative32.3%
distribute-rgt-neg-in32.3%
+-commutative32.3%
mul-1-neg32.3%
unsub-neg32.3%
Simplified32.3%
Taylor expanded in a around inf 12.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2024111
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))