
(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 -5e+154)
(* 0.5 (/ (fabs (* -2.0 (- (* a (/ c b)) b))) a))
(if (<= b 3.4e-49)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+154) {
tmp = 0.5 * (fabs((-2.0 * ((a * (c / b)) - b))) / a);
} else if (b <= 3.4e-49) {
tmp = (sqrt(((b * b) - (c * (a * 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 <= (-5d+154)) then
tmp = 0.5d0 * (abs(((-2.0d0) * ((a * (c / b)) - b))) / a)
else if (b <= 3.4d-49) then
tmp = (sqrt(((b * b) - (c * (a * 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 <= -5e+154) {
tmp = 0.5 * (Math.abs((-2.0 * ((a * (c / b)) - b))) / a);
} else if (b <= 3.4e-49) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e+154: tmp = 0.5 * (math.fabs((-2.0 * ((a * (c / b)) - b))) / a) elif b <= 3.4e-49: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e+154) tmp = Float64(0.5 * Float64(abs(Float64(-2.0 * Float64(Float64(a * Float64(c / b)) - b))) / a)); elseif (b <= 3.4e-49) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 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 <= -5e+154) tmp = 0.5 * (abs((-2.0 * ((a * (c / b)) - b))) / a); elseif (b <= 3.4e-49) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e+154], N[(0.5 * N[(N[Abs[N[(-2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.4e-49], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $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 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\left|-2 \cdot \left(a \cdot \frac{c}{b} - b\right)\right|}{a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-49}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.00000000000000004e154Initial program 53.4%
*-commutative53.4%
Simplified53.4%
Taylor expanded in a around 0 1.8%
add-sqr-sqrt1.7%
sqrt-unprod2.1%
pow22.1%
add-sqr-sqrt21.9%
sqrt-unprod53.1%
sqr-neg53.1%
sqrt-prod0.0%
add-sqr-sqrt53.5%
+-commutative53.5%
fma-define53.5%
associate-/l*53.5%
Applied egg-rr53.5%
unpow253.5%
rem-sqrt-square94.7%
Simplified94.7%
Taylor expanded in b around 0 83.5%
metadata-eval83.5%
cancel-sign-sub-inv83.5%
distribute-lft-out--83.5%
associate-*r/94.7%
Simplified94.7%
if -5.00000000000000004e154 < b < 3.40000000000000005e-49Initial program 81.6%
if 3.40000000000000005e-49 < b Initial program 18.3%
*-commutative18.3%
Simplified18.3%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
Final simplification85.6%
(FPCore (a b c)
:precision binary64
(if (<= b -4.1e-38)
(* 0.5 (/ (fabs (* -2.0 (- (* a (/ c b)) b))) a))
(if (<= b 3.4e-53)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e-38) {
tmp = 0.5 * (fabs((-2.0 * ((a * (c / b)) - b))) / a);
} else if (b <= 3.4e-53) {
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 <= (-4.1d-38)) then
tmp = 0.5d0 * (abs(((-2.0d0) * ((a * (c / b)) - b))) / a)
else if (b <= 3.4d-53) 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 <= -4.1e-38) {
tmp = 0.5 * (Math.abs((-2.0 * ((a * (c / b)) - b))) / a);
} else if (b <= 3.4e-53) {
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 <= -4.1e-38: tmp = 0.5 * (math.fabs((-2.0 * ((a * (c / b)) - b))) / a) elif b <= 3.4e-53: 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 <= -4.1e-38) tmp = Float64(0.5 * Float64(abs(Float64(-2.0 * Float64(Float64(a * Float64(c / b)) - b))) / a)); elseif (b <= 3.4e-53) 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 <= -4.1e-38) tmp = 0.5 * (abs((-2.0 * ((a * (c / b)) - b))) / a); elseif (b <= 3.4e-53) 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, -4.1e-38], N[(0.5 * N[(N[Abs[N[(-2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.4e-53], 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 -4.1 \cdot 10^{-38}:\\
\;\;\;\;0.5 \cdot \frac{\left|-2 \cdot \left(a \cdot \frac{c}{b} - b\right)\right|}{a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-53}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.0999999999999998e-38Initial program 70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in a around 0 1.9%
add-sqr-sqrt1.8%
sqrt-unprod2.5%
pow22.5%
add-sqr-sqrt14.0%
sqrt-unprod29.0%
sqr-neg29.0%
sqrt-prod0.0%
add-sqr-sqrt66.3%
+-commutative66.3%
fma-define66.3%
associate-/l*66.3%
Applied egg-rr66.3%
unpow266.3%
rem-sqrt-square87.7%
Simplified87.7%
Taylor expanded in b around 0 81.9%
metadata-eval81.9%
cancel-sign-sub-inv81.9%
distribute-lft-out--81.9%
associate-*r/87.7%
Simplified87.7%
if -4.0999999999999998e-38 < b < 3.4e-53Initial program 77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in b around 0 70.7%
*-commutative70.7%
associate-*r*70.8%
Simplified70.8%
if 3.4e-53 < b Initial program 18.3%
*-commutative18.3%
Simplified18.3%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
Final simplification81.9%
(FPCore (a b c)
:precision binary64
(if (<= b -2.5e-40)
(/ (- b) a)
(if (<= b 4.3e-52)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-40) {
tmp = -b / a;
} else if (b <= 4.3e-52) {
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 <= (-2.5d-40)) then
tmp = -b / a
else if (b <= 4.3d-52) 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 <= -2.5e-40) {
tmp = -b / a;
} else if (b <= 4.3e-52) {
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 <= -2.5e-40: tmp = -b / a elif b <= 4.3e-52: 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 <= -2.5e-40) tmp = Float64(Float64(-b) / a); elseif (b <= 4.3e-52) 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 <= -2.5e-40) tmp = -b / a; elseif (b <= 4.3e-52) 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, -2.5e-40], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.3e-52], 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 -2.5 \cdot 10^{-40}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.3 \cdot 10^{-52}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.49999999999999982e-40Initial program 70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
Simplified87.5%
if -2.49999999999999982e-40 < b < 4.3000000000000003e-52Initial program 77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in b around 0 70.7%
*-commutative70.7%
associate-*r*70.8%
Simplified70.8%
if 4.3000000000000003e-52 < b Initial program 18.3%
*-commutative18.3%
Simplified18.3%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
mul-1-neg86.8%
Simplified86.8%
Final simplification81.9%
(FPCore (a b c) :precision binary64 (if (<= b -3e-55) (/ (- b) a) (if (<= b 1.15e-63) (* -0.5 (- (sqrt (* c (/ -4.0 a))))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-55) {
tmp = -b / a;
} else if (b <= 1.15e-63) {
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 <= (-3d-55)) then
tmp = -b / a
else if (b <= 1.15d-63) 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 <= -3e-55) {
tmp = -b / a;
} else if (b <= 1.15e-63) {
tmp = -0.5 * -Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-55: tmp = -b / a elif b <= 1.15e-63: 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 <= -3e-55) tmp = Float64(Float64(-b) / a); elseif (b <= 1.15e-63) tmp = Float64(-0.5 * Float64(-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 <= -3e-55) tmp = -b / a; elseif (b <= 1.15e-63) tmp = -0.5 * -sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-55], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.15e-63], 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 -3 \cdot 10^{-55}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-63}:\\
\;\;\;\;-0.5 \cdot \left(-\sqrt{c \cdot \frac{-4}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -3.00000000000000016e-55Initial program 72.0%
*-commutative72.0%
Simplified72.0%
Taylor expanded in b around -inf 85.7%
mul-1-neg85.7%
Simplified85.7%
if -3.00000000000000016e-55 < b < 1.15e-63Initial program 77.4%
*-commutative77.4%
Simplified77.4%
*-un-lft-identity77.4%
add-cube-cbrt76.8%
prod-diff76.4%
Applied egg-rr76.4%
+-commutative76.4%
fma-undefine76.4%
associate-+l+76.4%
distribute-lft-neg-out76.4%
*-commutative76.4%
*-commutative76.4%
fma-define76.4%
associate-+r+76.4%
Simplified76.8%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt38.7%
rem-cube-cbrt39.0%
associate-/l*39.1%
Simplified39.1%
if 1.15e-63 < b Initial program 19.8%
*-commutative19.8%
Simplified19.8%
Taylor expanded in b around inf 85.3%
associate-*r/85.3%
mul-1-neg85.3%
Simplified85.3%
Final simplification71.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- b) a) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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 <= (-1d-309)) 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 <= -1e-309) {
tmp = -b / a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -b / a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(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 <= -1e-309) tmp = -b / a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in b around -inf 63.9%
mul-1-neg63.9%
Simplified63.9%
if -1.000000000000002e-309 < b Initial program 32.5%
*-commutative32.5%
Simplified32.5%
Taylor expanded in b around inf 66.0%
associate-*r/66.0%
mul-1-neg66.0%
Simplified66.0%
Final simplification65.0%
(FPCore (a b c) :precision binary64 (if (<= b 5.4e+48) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.4e+48) {
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 <= 5.4d+48) 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 <= 5.4e+48) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.4e+48: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.4e+48) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 5.4e+48) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.4e+48], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.4 \cdot 10^{+48}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 5.40000000000000007e48Initial program 67.9%
*-commutative67.9%
Simplified67.9%
Taylor expanded in b around -inf 42.4%
mul-1-neg42.4%
Simplified42.4%
if 5.40000000000000007e48 < b Initial program 13.9%
*-commutative13.9%
Simplified13.9%
Taylor expanded in a around 0 39.8%
frac-2neg39.8%
div-inv39.8%
add-sqr-sqrt0.0%
sqrt-unprod38.7%
sqr-neg38.7%
sqrt-prod38.7%
add-sqr-sqrt38.7%
Applied egg-rr38.7%
distribute-lft-neg-out38.7%
associate-*r/38.7%
*-rgt-identity38.7%
times-frac38.7%
associate-*r/38.9%
metadata-eval38.9%
*-commutative38.9%
*-lft-identity38.9%
associate-*r/38.7%
mul-1-neg38.7%
metadata-eval38.7%
times-frac38.7%
neg-mul-138.7%
distribute-rgt-neg-in38.7%
mul-1-neg38.7%
times-frac38.9%
/-rgt-identity38.9%
mul-1-neg38.9%
Simplified38.9%
Taylor expanded in b around 0 37.9%
Final simplification41.2%
(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 53.6%
*-commutative53.6%
Simplified53.6%
Taylor expanded in a around 0 12.7%
frac-2neg12.7%
div-inv12.7%
add-sqr-sqrt0.8%
sqrt-unprod11.5%
sqr-neg11.5%
sqrt-prod10.9%
add-sqr-sqrt12.5%
Applied egg-rr12.5%
distribute-lft-neg-out12.5%
associate-*r/12.5%
*-rgt-identity12.5%
times-frac12.5%
associate-*r/12.5%
metadata-eval12.5%
*-commutative12.5%
*-lft-identity12.5%
associate-*r/12.5%
mul-1-neg12.5%
metadata-eval12.5%
times-frac12.5%
neg-mul-112.5%
distribute-rgt-neg-in12.5%
mul-1-neg12.5%
times-frac12.5%
/-rgt-identity12.5%
mul-1-neg12.5%
Simplified12.5%
Taylor expanded in b around 0 12.3%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 53.6%
*-commutative53.6%
Simplified53.6%
*-un-lft-identity53.6%
*-un-lft-identity53.6%
prod-diff53.6%
*-commutative53.6%
*-un-lft-identity53.6%
fma-define53.6%
*-un-lft-identity53.6%
+-commutative53.6%
add-sqr-sqrt36.6%
sqrt-unprod50.1%
sqr-neg50.1%
sqrt-prod13.8%
add-sqr-sqrt36.4%
pow236.4%
add-sqr-sqrt22.8%
sqrt-unprod36.4%
sqr-neg36.4%
sqrt-prod13.8%
add-sqr-sqrt36.1%
*-commutative36.1%
*-un-lft-identity36.1%
Applied egg-rr36.1%
+-commutative36.1%
associate-+l+36.1%
fma-undefine36.1%
*-rgt-identity36.1%
Simplified36.1%
Taylor expanded in b around -inf 2.6%
herbie shell --seed 2024106
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))