
(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 -5.2e+25)
(/ b (- a))
(if (<= b 9.2e-41)
(* (/ 0.5 a) (- (hypot (sqrt (* a (* c -4.0))) b) b))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e+25) {
tmp = b / -a;
} else if (b <= 9.2e-41) {
tmp = (0.5 / a) * (hypot(sqrt((a * (c * -4.0))), b) - b);
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e+25) {
tmp = b / -a;
} else if (b <= 9.2e-41) {
tmp = (0.5 / a) * (Math.hypot(Math.sqrt((a * (c * -4.0))), b) - b);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e+25: tmp = b / -a elif b <= 9.2e-41: tmp = (0.5 / a) * (math.hypot(math.sqrt((a * (c * -4.0))), b) - b) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e+25) tmp = Float64(b / Float64(-a)); elseif (b <= 9.2e-41) tmp = Float64(Float64(0.5 / a) * Float64(hypot(sqrt(Float64(a * Float64(c * -4.0))), b) - b)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e+25) tmp = b / -a; elseif (b <= 9.2e-41) tmp = (0.5 / a) * (hypot(sqrt((a * (c * -4.0))), b) - b); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e+25], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 9.2e-41], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{+25}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-41}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\mathsf{hypot}\left(\sqrt{a \cdot \left(c \cdot -4\right)}, b\right) - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.1999999999999997e25Initial program 56.3%
*-commutative56.3%
Simplified56.5%
Taylor expanded in b around -inf 93.1%
associate-*r/93.1%
mul-1-neg93.1%
Simplified93.1%
if -5.1999999999999997e25 < b < 9.20000000000000041e-41Initial program 71.4%
*-commutative71.4%
Simplified72.3%
div-sub72.3%
sub-neg72.3%
div-inv72.3%
pow272.3%
*-commutative72.3%
associate-/r*72.3%
metadata-eval72.3%
div-inv72.2%
*-commutative72.2%
associate-/r*72.2%
metadata-eval72.2%
Applied egg-rr72.2%
sub-neg72.2%
distribute-rgt-out--72.1%
Simplified72.1%
*-un-lft-identity72.1%
fma-undefine72.1%
add-sqr-sqrt70.2%
pow270.2%
hypot-define73.3%
Applied egg-rr73.3%
*-lft-identity73.3%
Simplified73.3%
if 9.20000000000000041e-41 < b Initial program 18.2%
*-commutative18.2%
Simplified18.2%
Taylor expanded in a around 0 91.0%
associate-*r/91.0%
mul-1-neg91.0%
Simplified91.0%
Final simplification84.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e+54)
(/ b (- a))
(if (<= b 3e-110)
(/ (- (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 <= -1.8e+54) {
tmp = b / -a;
} else if (b <= 3e-110) {
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 <= (-1.8d+54)) then
tmp = b / -a
else if (b <= 3d-110) 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 <= -1.8e+54) {
tmp = b / -a;
} else if (b <= 3e-110) {
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 <= -1.8e+54: tmp = b / -a elif b <= 3e-110: 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 <= -1.8e+54) tmp = Float64(b / Float64(-a)); elseif (b <= 3e-110) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.8e+54) tmp = b / -a; elseif (b <= 3e-110) 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, -1.8e+54], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 3e-110], 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 -1.8 \cdot 10^{+54}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 3 \cdot 10^{-110}:\\
\;\;\;\;\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 < -1.8000000000000001e54Initial program 51.3%
*-commutative51.3%
Simplified51.5%
Taylor expanded in b around -inf 95.2%
associate-*r/95.2%
mul-1-neg95.2%
Simplified95.2%
if -1.8000000000000001e54 < b < 2.99999999999999986e-110Initial program 76.7%
if 2.99999999999999986e-110 < b Initial program 22.1%
*-commutative22.1%
Simplified23.1%
Taylor expanded in a around 0 84.4%
associate-*r/84.4%
mul-1-neg84.4%
Simplified84.4%
Final simplification83.8%
(FPCore (a b c)
:precision binary64
(if (<= b -8.5e-20)
(* b (+ (/ c (pow b 2.0)) (/ -1.0 a)))
(if (<= b 3.6e-39)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-20) {
tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 3.6e-39) {
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 <= (-8.5d-20)) then
tmp = b * ((c / (b ** 2.0d0)) + ((-1.0d0) / a))
else if (b <= 3.6d-39) 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 <= -8.5e-20) {
tmp = b * ((c / Math.pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 3.6e-39) {
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 <= -8.5e-20: tmp = b * ((c / math.pow(b, 2.0)) + (-1.0 / a)) elif b <= 3.6e-39: 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 <= -8.5e-20) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a))); elseif (b <= 3.6e-39) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.5e-20) tmp = b * ((c / (b ^ 2.0)) + (-1.0 / a)); elseif (b <= 3.6e-39) 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, -8.5e-20], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.6e-39], 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 -8.5 \cdot 10^{-20}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-39}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.5000000000000005e-20Initial program 60.6%
*-commutative60.6%
Simplified60.8%
Taylor expanded in b around -inf 87.8%
mul-1-neg87.8%
distribute-rgt-neg-in87.8%
+-commutative87.8%
mul-1-neg87.8%
unsub-neg87.8%
Simplified87.8%
if -8.5000000000000005e-20 < b < 3.6000000000000001e-39Initial program 69.4%
*-commutative69.4%
Simplified70.4%
Taylor expanded in a around inf 61.0%
*-commutative61.0%
associate-*r*61.0%
Simplified61.0%
if 3.6000000000000001e-39 < b Initial program 18.2%
*-commutative18.2%
Simplified18.2%
Taylor expanded in a around 0 91.0%
associate-*r/91.0%
mul-1-neg91.0%
Simplified91.0%
Final simplification78.8%
(FPCore (a b c)
:precision binary64
(if (<= b -6e-78)
(* b (+ (/ c (pow b 2.0)) (/ -1.0 a)))
(if (<= b 6.8e-39)
(* (/ 0.5 a) (+ b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e-78) {
tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 6.8e-39) {
tmp = (0.5 / a) * (b + sqrt((a * (c * -4.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-78)) then
tmp = b * ((c / (b ** 2.0d0)) + ((-1.0d0) / a))
else if (b <= 6.8d-39) then
tmp = (0.5d0 / a) * (b + sqrt((a * (c * (-4.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-78) {
tmp = b * ((c / Math.pow(b, 2.0)) + (-1.0 / a));
} else if (b <= 6.8e-39) {
tmp = (0.5 / a) * (b + Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e-78: tmp = b * ((c / math.pow(b, 2.0)) + (-1.0 / a)) elif b <= 6.8e-39: tmp = (0.5 / a) * (b + math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e-78) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a))); elseif (b <= 6.8e-39) tmp = Float64(Float64(0.5 / a) * Float64(b + sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6e-78) tmp = b * ((c / (b ^ 2.0)) + (-1.0 / a)); elseif (b <= 6.8e-39) tmp = (0.5 / a) * (b + sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e-78], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.8e-39], N[(N[(0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{-78}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\mathbf{elif}\;b \leq 6.8 \cdot 10^{-39}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.99999999999999975e-78Initial program 65.2%
*-commutative65.2%
Simplified65.3%
Taylor expanded in b around -inf 82.2%
mul-1-neg82.2%
distribute-rgt-neg-in82.2%
+-commutative82.2%
mul-1-neg82.2%
unsub-neg82.2%
Simplified82.2%
if -5.99999999999999975e-78 < b < 6.7999999999999998e-39Initial program 65.8%
*-commutative65.8%
Simplified67.0%
Taylor expanded in a around inf 62.2%
*-commutative62.2%
associate-*r*62.2%
Simplified62.2%
div-inv62.1%
add-log-exp5.0%
add-log-exp62.1%
sqrt-prod42.4%
fmm-def42.4%
add-sqr-sqrt23.3%
sqrt-unprod42.2%
sqr-neg42.2%
sqrt-prod19.4%
add-sqr-sqrt41.6%
Applied egg-rr41.6%
*-commutative41.6%
fma-undefine41.6%
sqrt-prod60.5%
distribute-lft-in60.5%
metadata-eval60.5%
div-inv60.5%
clear-num60.5%
metadata-eval60.5%
div-inv60.5%
clear-num60.5%
Applied egg-rr60.5%
distribute-lft-out60.5%
+-commutative60.5%
Simplified60.5%
if 6.7999999999999998e-39 < b Initial program 18.2%
*-commutative18.2%
Simplified18.2%
Taylor expanded in a around 0 91.0%
associate-*r/91.0%
mul-1-neg91.0%
Simplified91.0%
Final simplification78.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-311) (/ b (- a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-311) {
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 <= (-5d-311)) 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 <= -5e-311) {
tmp = b / -a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-311: tmp = b / -a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-311) tmp = Float64(b / Float64(-a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-311) tmp = b / -a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-311], N[(b / (-a)), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.00000000000023e-311Initial program 68.2%
*-commutative68.2%
Simplified68.3%
Taylor expanded in b around -inf 62.9%
associate-*r/62.9%
mul-1-neg62.9%
Simplified62.9%
if -5.00000000000023e-311 < b Initial program 30.7%
*-commutative30.7%
Simplified31.5%
Taylor expanded in a around 0 69.0%
associate-*r/69.0%
mul-1-neg69.0%
Simplified69.0%
Final simplification65.8%
(FPCore (a b c) :precision binary64 (if (<= b 3.7e+24) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.7e+24) {
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 <= 3.7d+24) 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 <= 3.7e+24) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.7e+24: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.7e+24) 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 <= 3.7e+24) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.7e+24], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.7 \cdot 10^{+24}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 3.69999999999999999e24Initial program 61.8%
*-commutative61.8%
Simplified62.4%
Taylor expanded in b around -inf 45.3%
associate-*r/45.3%
mul-1-neg45.3%
Simplified45.3%
if 3.69999999999999999e24 < b Initial program 17.3%
*-commutative17.3%
Simplified17.3%
Taylor expanded in a around 0 79.1%
associate-*r/79.1%
frac-2neg79.1%
add-sqr-sqrt0.0%
sqrt-unprod31.6%
sqr-neg31.6%
sqrt-prod31.3%
add-sqr-sqrt31.3%
Applied egg-rr31.3%
distribute-lft-neg-in31.3%
metadata-eval31.3%
*-commutative31.3%
Simplified31.3%
Taylor expanded in c around 0 31.2%
Final simplification41.6%
(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 50.3%
*-commutative50.3%
Simplified50.8%
Taylor expanded in a around 0 28.0%
associate-*r/28.0%
frac-2neg28.0%
add-sqr-sqrt1.1%
sqrt-unprod9.4%
sqr-neg9.4%
sqrt-prod8.5%
add-sqr-sqrt10.4%
Applied egg-rr10.4%
distribute-lft-neg-in10.4%
metadata-eval10.4%
*-commutative10.4%
Simplified10.4%
Taylor expanded in c around 0 10.5%
(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 50.3%
*-commutative50.3%
Simplified50.8%
Taylor expanded in b around -inf 34.3%
associate-*r/34.3%
mul-1-neg34.3%
Simplified34.3%
div-inv34.2%
add-sqr-sqrt32.7%
sqrt-unprod22.7%
sqr-neg22.7%
sqrt-prod1.8%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
Simplified2.5%
(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 2024155
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))