
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1.1e+130)
(- (/ c b) (/ b a))
(if (<= b -1.52e-233)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(if (<= b 2.1e+21)
(/ (* c -2.0) (+ b (hypot (sqrt (* (* c a) -4.0)) b)))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e+130) {
tmp = (c / b) - (b / a);
} else if (b <= -1.52e-233) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 2.1e+21) {
tmp = (c * -2.0) / (b + hypot(sqrt(((c * a) * -4.0)), b));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e+130) {
tmp = (c / b) - (b / a);
} else if (b <= -1.52e-233) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 2.1e+21) {
tmp = (c * -2.0) / (b + Math.hypot(Math.sqrt(((c * a) * -4.0)), b));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e+130: tmp = (c / b) - (b / a) elif b <= -1.52e-233: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) elif b <= 2.1e+21: tmp = (c * -2.0) / (b + math.hypot(math.sqrt(((c * a) * -4.0)), b)) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e+130) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -1.52e-233) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); elseif (b <= 2.1e+21) tmp = Float64(Float64(c * -2.0) / Float64(b + hypot(sqrt(Float64(Float64(c * a) * -4.0)), b))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e+130) tmp = (c / b) - (b / a); elseif (b <= -1.52e-233) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); elseif (b <= 2.1e+21) tmp = (c * -2.0) / (b + hypot(sqrt(((c * a) * -4.0)), b)); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e+130], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.52e-233], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.1e+21], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{+130}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -1.52 \cdot 10^{-233}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.1 \cdot 10^{+21}:\\
\;\;\;\;\frac{c \cdot -2}{b + \mathsf{hypot}\left(\sqrt{\left(c \cdot a\right) \cdot -4}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.09999999999999997e130Initial program 49.4%
neg-sub049.4%
associate-+l-49.4%
sub0-neg49.4%
neg-mul-149.4%
*-commutative49.4%
associate-*r/49.3%
Simplified49.3%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
if -1.09999999999999997e130 < b < -1.51999999999999994e-233Initial program 90.4%
if -1.51999999999999994e-233 < b < 2.1e21Initial program 64.8%
neg-sub064.8%
associate-+l-64.8%
sub0-neg64.8%
neg-mul-164.8%
*-commutative64.8%
associate-*r/64.7%
Simplified64.7%
*-commutative64.7%
clear-num64.7%
flip--64.3%
frac-times51.2%
*-un-lft-identity51.2%
add-sqr-sqrt51.3%
fma-udef51.3%
add-sqr-sqrt51.1%
hypot-def51.1%
Applied egg-rr51.1%
*-commutative51.1%
associate-*r/51.1%
associate-/l*51.1%
*-commutative51.1%
*-commutative51.1%
associate-/r*64.3%
Simplified64.2%
Taylor expanded in b around 0 86.4%
*-commutative86.4%
Simplified86.4%
if 2.1e21 < b Initial program 11.6%
neg-sub011.6%
associate-+l-11.6%
sub0-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-*r/11.6%
Simplified11.7%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification91.1%
(FPCore (a b c)
:precision binary64
(if (<= b -8e+129)
(- (/ c b) (/ b a))
(if (<= b 4.3e-276)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(if (<= b 6e+20)
(* c (/ -2.0 (+ b (hypot (sqrt (* c (* a -4.0))) b))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e+129) {
tmp = (c / b) - (b / a);
} else if (b <= 4.3e-276) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 6e+20) {
tmp = c * (-2.0 / (b + hypot(sqrt((c * (a * -4.0))), b)));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8e+129) {
tmp = (c / b) - (b / a);
} else if (b <= 4.3e-276) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 6e+20) {
tmp = c * (-2.0 / (b + Math.hypot(Math.sqrt((c * (a * -4.0))), b)));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e+129: tmp = (c / b) - (b / a) elif b <= 4.3e-276: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) elif b <= 6e+20: tmp = c * (-2.0 / (b + math.hypot(math.sqrt((c * (a * -4.0))), b))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e+129) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.3e-276) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); elseif (b <= 6e+20) tmp = Float64(c * Float64(-2.0 / Float64(b + hypot(sqrt(Float64(c * Float64(a * -4.0))), b)))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8e+129) tmp = (c / b) - (b / a); elseif (b <= 4.3e-276) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); elseif (b <= 6e+20) tmp = c * (-2.0 / (b + hypot(sqrt((c * (a * -4.0))), b))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e+129], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.3e-276], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6e+20], N[(c * N[(-2.0 / N[(b + N[Sqrt[N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{+129}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.3 \cdot 10^{-276}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{+20}:\\
\;\;\;\;c \cdot \frac{-2}{b + \mathsf{hypot}\left(\sqrt{c \cdot \left(a \cdot -4\right)}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8e129Initial program 49.4%
neg-sub049.4%
associate-+l-49.4%
sub0-neg49.4%
neg-mul-149.4%
*-commutative49.4%
associate-*r/49.3%
Simplified49.3%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
if -8e129 < b < 4.2999999999999996e-276Initial program 89.4%
if 4.2999999999999996e-276 < b < 6e20Initial program 61.3%
neg-sub061.3%
associate-+l-61.3%
sub0-neg61.3%
neg-mul-161.3%
*-commutative61.3%
associate-*r/61.3%
Simplified61.3%
*-commutative61.3%
clear-num61.3%
flip--60.9%
frac-times48.6%
*-un-lft-identity48.6%
add-sqr-sqrt48.7%
fma-udef48.7%
add-sqr-sqrt48.4%
hypot-def48.5%
Applied egg-rr48.5%
*-commutative48.5%
associate-*r/48.5%
associate-/l*48.5%
*-commutative48.5%
*-commutative48.5%
associate-/r*60.8%
Simplified60.8%
Taylor expanded in b around 0 87.3%
*-commutative87.3%
Simplified87.3%
expm1-log1p-u66.6%
expm1-udef30.3%
*-commutative30.3%
*-un-lft-identity30.3%
times-frac30.3%
metadata-eval30.3%
Applied egg-rr30.3%
expm1-def66.6%
expm1-log1p87.3%
associate-*r/87.3%
*-commutative87.3%
associate-*r/87.1%
*-commutative87.1%
rem-square-sqrt0.0%
unpow20.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt87.1%
Simplified87.1%
if 6e20 < b Initial program 11.6%
neg-sub011.6%
associate-+l-11.6%
sub0-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-*r/11.6%
Simplified11.7%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(if (<= b -5.6e+129)
(- (/ c b) (/ b a))
(if (<= b 5.2e+20)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.6e+129) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e+20) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / 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.6d+129)) then
tmp = (c / b) - (b / a)
else if (b <= 5.2d+20) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (0.5d0 / 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.6e+129) {
tmp = (c / b) - (b / a);
} else if (b <= 5.2e+20) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.6e+129: tmp = (c / b) - (b / a) elif b <= 5.2e+20: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.6e+129) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.2e+20) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.6e+129) tmp = (c / b) - (b / a); elseif (b <= 5.2e+20) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.6e+129], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.2e+20], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.6 \cdot 10^{+129}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+20}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5.5999999999999995e129Initial program 49.4%
neg-sub049.4%
associate-+l-49.4%
sub0-neg49.4%
neg-mul-149.4%
*-commutative49.4%
associate-*r/49.3%
Simplified49.3%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
if -5.5999999999999995e129 < b < 5.2e20Initial program 78.7%
/-rgt-identity78.7%
metadata-eval78.7%
associate-/l*78.7%
associate-*r/78.5%
+-commutative78.5%
unsub-neg78.5%
fma-neg78.5%
*-commutative78.5%
distribute-rgt-neg-in78.5%
associate-*l*78.5%
metadata-eval78.5%
associate-/r*78.5%
metadata-eval78.5%
metadata-eval78.5%
Simplified78.5%
fma-udef78.5%
Applied egg-rr78.5%
if 5.2e20 < b Initial program 11.6%
neg-sub011.6%
associate-+l-11.6%
sub0-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-*r/11.6%
Simplified11.7%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification85.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1e+130)
(- (/ c b) (/ b a))
(if (<= b 2.05e+20)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+130) {
tmp = (c / b) - (b / a);
} else if (b <= 2.05e+20) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - 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 <= (-1d+130)) then
tmp = (c / b) - (b / a)
else if (b <= 2.05d+20) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - 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 <= -1e+130) {
tmp = (c / b) - (b / a);
} else if (b <= 2.05e+20) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+130: tmp = (c / b) - (b / a) elif b <= 2.05e+20: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+130) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.05e+20) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - 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 <= -1e+130) tmp = (c / b) - (b / a); elseif (b <= 2.05e+20) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+130], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.05e+20], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $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 \cdot 10^{+130}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{+20}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.0000000000000001e130Initial program 49.4%
neg-sub049.4%
associate-+l-49.4%
sub0-neg49.4%
neg-mul-149.4%
*-commutative49.4%
associate-*r/49.3%
Simplified49.3%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
if -1.0000000000000001e130 < b < 2.05e20Initial program 78.7%
if 2.05e20 < b Initial program 11.6%
neg-sub011.6%
associate-+l-11.6%
sub0-neg11.6%
neg-mul-111.6%
*-commutative11.6%
associate-*r/11.6%
Simplified11.7%
Taylor expanded in b around inf 93.2%
associate-*r/93.2%
neg-mul-193.2%
Simplified93.2%
Final simplification85.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e-93)
(- (/ c b) (/ b a))
(if (<= b 2.6e-80)
(* (- b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 2.6e-80) {
tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / 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.15d-93)) then
tmp = (c / b) - (b / a)
else if (b <= 2.6d-80) then
tmp = (b - sqrt((a * (c * (-4.0d0))))) * ((-0.5d0) / 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.15e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 2.6e-80) {
tmp = (b - Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.15e-93: tmp = (c / b) - (b / a) elif b <= 2.6e-80: tmp = (b - math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.15e-93) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.6e-80) tmp = Float64(Float64(b - sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.15e-93) tmp = (c / b) - (b / a); elseif (b <= 2.6e-80) tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.15e-93], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.6e-80], N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{-93}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-80}:\\
\;\;\;\;\left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.1499999999999999e-93Initial program 73.8%
neg-sub073.8%
associate-+l-73.8%
sub0-neg73.8%
neg-mul-173.8%
*-commutative73.8%
associate-*r/73.5%
Simplified73.5%
Taylor expanded in b around -inf 85.3%
mul-1-neg85.3%
unsub-neg85.3%
Simplified85.3%
if -1.1499999999999999e-93 < b < 2.6000000000000001e-80Initial program 75.2%
neg-sub075.2%
associate-+l-75.2%
sub0-neg75.2%
neg-mul-175.2%
*-commutative75.2%
associate-*r/75.1%
Simplified75.1%
Taylor expanded in a around inf 72.3%
associate-*r*72.3%
*-commutative72.3%
*-commutative72.3%
Simplified72.3%
if 2.6000000000000001e-80 < b Initial program 21.5%
neg-sub021.5%
associate-+l-21.5%
sub0-neg21.5%
neg-mul-121.5%
*-commutative21.5%
associate-*r/21.5%
Simplified21.5%
Taylor expanded in b around inf 82.6%
associate-*r/82.6%
neg-mul-182.6%
Simplified82.6%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 75.4%
neg-sub075.4%
associate-+l-75.4%
sub0-neg75.4%
neg-mul-175.4%
*-commutative75.4%
associate-*r/75.2%
Simplified75.2%
Taylor expanded in b around -inf 71.1%
mul-1-neg71.1%
unsub-neg71.1%
Simplified71.1%
if -4.999999999999985e-310 < b Initial program 35.6%
neg-sub035.6%
associate-+l-35.6%
sub0-neg35.6%
neg-mul-135.6%
*-commutative35.6%
associate-*r/35.6%
Simplified35.6%
Taylor expanded in b around inf 66.4%
associate-*r/66.4%
neg-mul-166.4%
Simplified66.4%
Final simplification68.8%
(FPCore (a b c) :precision binary64 (if (<= b 7e+101) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7e+101) {
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 <= 7d+101) 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 <= 7e+101) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7e+101: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7e+101) 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 <= 7e+101) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7e+101], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+101}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.00000000000000046e101Initial program 67.4%
neg-sub067.4%
associate-+l-67.4%
sub0-neg67.4%
neg-mul-167.4%
*-commutative67.4%
associate-*r/67.2%
Simplified67.2%
Taylor expanded in b around -inf 45.6%
associate-*r/45.6%
mul-1-neg45.6%
Simplified45.6%
if 7.00000000000000046e101 < b Initial program 6.7%
neg-sub06.7%
associate-+l-6.7%
sub0-neg6.7%
neg-mul-16.7%
*-commutative6.7%
associate-*r/6.7%
Simplified6.7%
Taylor expanded in b around -inf 2.6%
mul-1-neg2.6%
unsub-neg2.6%
Simplified2.6%
Taylor expanded in c around inf 31.7%
Final simplification43.0%
(FPCore (a b c) :precision binary64 (if (<= b 2.75e-301) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.75e-301) {
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.75d-301) 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.75e-301) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.75e-301: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.75e-301) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.75e-301) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.75e-301], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.75 \cdot 10^{-301}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 2.75000000000000003e-301Initial program 75.6%
neg-sub075.6%
associate-+l-75.6%
sub0-neg75.6%
neg-mul-175.6%
*-commutative75.6%
associate-*r/75.4%
Simplified75.4%
Taylor expanded in b around -inf 70.2%
associate-*r/70.2%
mul-1-neg70.2%
Simplified70.2%
if 2.75000000000000003e-301 < b Initial program 35.1%
neg-sub035.1%
associate-+l-35.1%
sub0-neg35.1%
neg-mul-135.1%
*-commutative35.1%
associate-*r/35.1%
Simplified35.1%
Taylor expanded in b around inf 66.9%
associate-*r/66.9%
neg-mul-166.9%
Simplified66.9%
Final simplification68.6%
(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 56.0%
/-rgt-identity56.0%
metadata-eval56.0%
associate-/l*56.0%
associate-*r/55.8%
+-commutative55.8%
unsub-neg55.8%
fma-neg55.8%
*-commutative55.8%
distribute-rgt-neg-in55.8%
associate-*l*55.8%
metadata-eval55.8%
associate-/r*55.8%
metadata-eval55.8%
metadata-eval55.8%
Simplified55.8%
add-sqr-sqrt55.6%
pow255.6%
sub-neg55.6%
fma-udef55.6%
add-sqr-sqrt43.7%
hypot-def51.2%
add-sqr-sqrt31.1%
sqrt-unprod42.5%
sqr-neg42.5%
sqrt-prod14.9%
add-sqr-sqrt26.8%
Applied egg-rr26.8%
Taylor expanded in b around inf 2.7%
Final simplification2.7%
(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 56.0%
neg-sub056.0%
associate-+l-56.0%
sub0-neg56.0%
neg-mul-156.0%
*-commutative56.0%
associate-*r/55.8%
Simplified55.8%
Taylor expanded in b around -inf 37.6%
mul-1-neg37.6%
unsub-neg37.6%
Simplified37.6%
Taylor expanded in c around inf 8.4%
Final simplification8.4%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023222
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(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)))