
(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 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(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 -4.2e+108)
(- (/ c b) (/ b a))
(if (<= b 4.8e-51)
(/ (- (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 <= -4.2e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 4.8e-51) {
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 <= (-4.2d+108)) then
tmp = (c / b) - (b / a)
else if (b <= 4.8d-51) 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 <= -4.2e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 4.8e-51) {
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 <= -4.2e+108: tmp = (c / b) - (b / a) elif b <= 4.8e-51: 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 <= -4.2e+108) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.8e-51) 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 <= -4.2e+108) tmp = (c / b) - (b / a); elseif (b <= 4.8e-51) 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, -4.2e+108], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.8e-51], 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 -4.2 \cdot 10^{+108}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-51}:\\
\;\;\;\;\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 < -4.20000000000000019e108Initial program 53.5%
neg-sub053.5%
associate-+l-53.5%
sub0-neg53.5%
neg-mul-153.5%
*-commutative53.5%
associate-*r/53.5%
Simplified53.6%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
unsub-neg96.7%
Simplified96.7%
if -4.20000000000000019e108 < b < 4.8e-51Initial program 78.3%
if 4.8e-51 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
*-commutative11.0%
associate-*r/11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification85.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e+108)
(- (/ c b) (/ b a))
(if (<= b 4.7e-51)
(* (- (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 <= -1.65e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 4.7e-51) {
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 <= (-1.65d+108)) then
tmp = (c / b) - (b / a)
else if (b <= 4.7d-51) 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 <= -1.65e+108) {
tmp = (c / b) - (b / a);
} else if (b <= 4.7e-51) {
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 <= -1.65e+108: tmp = (c / b) - (b / a) elif b <= 4.7e-51: 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 <= -1.65e+108) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.7e-51) 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 <= -1.65e+108) tmp = (c / b) - (b / a); elseif (b <= 4.7e-51) 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, -1.65e+108], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.7e-51], 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 -1.65 \cdot 10^{+108}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.7 \cdot 10^{-51}:\\
\;\;\;\;\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 < -1.6500000000000001e108Initial program 53.5%
neg-sub053.5%
associate-+l-53.5%
sub0-neg53.5%
neg-mul-153.5%
*-commutative53.5%
associate-*r/53.5%
Simplified53.6%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
unsub-neg96.7%
Simplified96.7%
if -1.6500000000000001e108 < b < 4.6999999999999997e-51Initial program 78.3%
/-rgt-identity78.3%
metadata-eval78.3%
associate-/l*78.3%
associate-*r/78.1%
+-commutative78.1%
unsub-neg78.1%
fma-neg78.1%
*-commutative78.1%
distribute-rgt-neg-in78.1%
associate-*l*78.2%
metadata-eval78.2%
associate-/r*78.2%
metadata-eval78.2%
metadata-eval78.2%
Simplified78.2%
fma-udef78.2%
Applied egg-rr78.2%
if 4.6999999999999997e-51 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
*-commutative11.0%
associate-*r/11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification85.2%
(FPCore (a b c)
:precision binary64
(if (<= b -3.8e-154)
(- (/ c b) (/ b a))
(if (<= b 4.2e-48)
(* (- b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.8e-154) {
tmp = (c / b) - (b / a);
} else if (b <= 4.2e-48) {
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 <= (-3.8d-154)) then
tmp = (c / b) - (b / a)
else if (b <= 4.2d-48) 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 <= -3.8e-154) {
tmp = (c / b) - (b / a);
} else if (b <= 4.2e-48) {
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 <= -3.8e-154: tmp = (c / b) - (b / a) elif b <= 4.2e-48: 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 <= -3.8e-154) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.2e-48) 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 <= -3.8e-154) tmp = (c / b) - (b / a); elseif (b <= 4.2e-48) 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, -3.8e-154], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e-48], 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 -3.8 \cdot 10^{-154}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-48}:\\
\;\;\;\;\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 < -3.8000000000000001e-154Initial program 73.8%
neg-sub073.8%
associate-+l-73.8%
sub0-neg73.8%
neg-mul-173.8%
*-commutative73.8%
associate-*r/73.7%
Simplified73.7%
Taylor expanded in b around -inf 84.8%
mul-1-neg84.8%
unsub-neg84.8%
Simplified84.8%
if -3.8000000000000001e-154 < b < 4.19999999999999977e-48Initial program 62.3%
neg-sub062.3%
associate-+l-62.3%
sub0-neg62.3%
neg-mul-162.3%
*-commutative62.3%
associate-*r/62.3%
Simplified62.4%
Taylor expanded in a around inf 62.3%
associate-*r*62.3%
*-commutative62.3%
*-commutative62.3%
Simplified62.3%
if 4.19999999999999977e-48 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
*-commutative11.0%
associate-*r/11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification80.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3.7e-154)
(- (/ c b) (/ b a))
(if (<= b 2.2e-51)
(/ (* (- b (sqrt (* c (* a -4.0)))) -0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-154) {
tmp = (c / b) - (b / a);
} else if (b <= 2.2e-51) {
tmp = ((b - sqrt((c * (a * -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 <= (-3.7d-154)) then
tmp = (c / b) - (b / a)
else if (b <= 2.2d-51) then
tmp = ((b - sqrt((c * (a * (-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 <= -3.7e-154) {
tmp = (c / b) - (b / a);
} else if (b <= 2.2e-51) {
tmp = ((b - Math.sqrt((c * (a * -4.0)))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.7e-154: tmp = (c / b) - (b / a) elif b <= 2.2e-51: tmp = ((b - math.sqrt((c * (a * -4.0)))) * -0.5) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.7e-154) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.2e-51) tmp = Float64(Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) * -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 <= -3.7e-154) tmp = (c / b) - (b / a); elseif (b <= 2.2e-51) tmp = ((b - sqrt((c * (a * -4.0)))) * -0.5) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.7e-154], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2e-51], N[(N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.7 \cdot 10^{-154}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-51}:\\
\;\;\;\;\frac{\left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.69999999999999987e-154Initial program 73.8%
neg-sub073.8%
associate-+l-73.8%
sub0-neg73.8%
neg-mul-173.8%
*-commutative73.8%
associate-*r/73.7%
Simplified73.7%
Taylor expanded in b around -inf 84.8%
mul-1-neg84.8%
unsub-neg84.8%
Simplified84.8%
if -3.69999999999999987e-154 < b < 2.2e-51Initial program 62.3%
neg-sub062.3%
associate-+l-62.3%
sub0-neg62.3%
neg-mul-162.3%
*-commutative62.3%
associate-*r/62.3%
Simplified62.4%
add-cbrt-cube46.0%
pow345.9%
pow1/342.9%
sqrt-pow242.9%
metadata-eval42.9%
Applied egg-rr42.9%
unpow1/345.9%
fma-def45.9%
+-commutative45.9%
fma-def45.9%
Simplified45.9%
Taylor expanded in a around inf 22.0%
*-commutative22.0%
exp-prod22.1%
mul-1-neg22.1%
log-rec22.1%
remove-double-neg22.1%
*-commutative22.1%
log-prod43.5%
rem-exp-log45.9%
associate-*r*45.9%
*-commutative45.9%
rem-square-sqrt0.0%
unpow20.0%
associate-*r*0.0%
unpow20.0%
rem-square-sqrt45.9%
Simplified45.9%
associate-*r/45.9%
pow1/342.9%
pow-pow62.4%
metadata-eval62.4%
pow1/262.4%
Applied egg-rr62.4%
if 2.2e-51 < b Initial program 11.0%
neg-sub011.0%
associate-+l-11.0%
sub0-neg11.0%
neg-mul-111.0%
*-commutative11.0%
associate-*r/11.0%
Simplified11.0%
Taylor expanded in b around inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
Final simplification80.7%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 73.9%
neg-sub073.9%
associate-+l-73.9%
sub0-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-*r/73.8%
Simplified73.8%
Taylor expanded in b around -inf 73.4%
mul-1-neg73.4%
unsub-neg73.4%
Simplified73.4%
if -9.999999999999969e-311 < b Initial program 22.9%
neg-sub022.9%
associate-+l-22.9%
sub0-neg22.9%
neg-mul-122.9%
*-commutative22.9%
associate-*r/22.8%
Simplified22.9%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
neg-mul-169.9%
Simplified69.9%
Final simplification71.7%
(FPCore (a b c) :precision binary64 (if (<= b 1.02e+24) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.02e+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 <= 1.02d+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 <= 1.02e+24) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.02e+24: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.02e+24) 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 <= 1.02e+24) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.02e+24], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.02 \cdot 10^{+24}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.02000000000000004e24Initial program 65.5%
neg-sub065.5%
associate-+l-65.5%
sub0-neg65.5%
neg-mul-165.5%
*-commutative65.5%
associate-*r/65.4%
Simplified65.5%
Taylor expanded in b around -inf 54.2%
associate-*r/54.2%
mul-1-neg54.2%
Simplified54.2%
if 1.02000000000000004e24 < b Initial program 9.8%
neg-sub09.8%
associate-+l-9.8%
sub0-neg9.8%
neg-mul-19.8%
*-commutative9.8%
associate-*r/9.9%
Simplified9.9%
Taylor expanded in b around inf 71.6%
*-commutative71.6%
associate-/l*68.0%
Simplified68.0%
associate-*l/68.0%
frac-2neg68.0%
metadata-eval68.0%
frac-times74.3%
Applied egg-rr74.3%
associate-/r*68.1%
associate-*l*68.1%
metadata-eval68.1%
associate-*r/68.0%
associate-/r/68.0%
Simplified68.0%
expm1-log1p-u59.8%
expm1-udef35.8%
associate-/l*36.0%
*-un-lft-identity36.0%
times-frac39.3%
clear-num39.3%
/-rgt-identity39.3%
add-sqr-sqrt17.1%
sqrt-unprod22.4%
sqr-neg22.4%
sqrt-unprod17.2%
add-sqr-sqrt32.2%
Applied egg-rr32.2%
expm1-def31.5%
expm1-log1p31.6%
*-inverses31.6%
associate-/r*31.6%
/-rgt-identity31.6%
Simplified31.6%
Final simplification47.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
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-310)) 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-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) 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 <= -1e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 73.9%
neg-sub073.9%
associate-+l-73.9%
sub0-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-*r/73.8%
Simplified73.8%
Taylor expanded in b around -inf 73.3%
associate-*r/73.3%
mul-1-neg73.3%
Simplified73.3%
if -9.999999999999969e-311 < b Initial program 22.9%
neg-sub022.9%
associate-+l-22.9%
sub0-neg22.9%
neg-mul-122.9%
*-commutative22.9%
associate-*r/22.8%
Simplified22.9%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
neg-mul-169.9%
Simplified69.9%
Final simplification71.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 48.8%
neg-sub048.8%
associate-+l-48.8%
sub0-neg48.8%
neg-mul-148.8%
*-commutative48.8%
associate-*r/48.7%
Simplified48.8%
Taylor expanded in b around inf 27.2%
*-commutative27.2%
associate-/l*27.6%
Simplified27.6%
associate-*l/27.6%
frac-2neg27.6%
metadata-eval27.6%
frac-times30.6%
Applied egg-rr30.6%
associate-/r*27.6%
associate-*l*27.6%
metadata-eval27.6%
associate-*r/27.6%
associate-/r/27.6%
Simplified27.6%
expm1-log1p-u23.8%
expm1-udef12.9%
associate-/l*13.0%
*-un-lft-identity13.0%
times-frac14.0%
clear-num14.0%
/-rgt-identity14.0%
add-sqr-sqrt6.2%
sqrt-unprod9.3%
sqr-neg9.3%
sqrt-unprod6.2%
add-sqr-sqrt11.3%
Applied egg-rr11.3%
expm1-def11.2%
expm1-log1p11.8%
*-inverses11.8%
associate-/r*11.8%
/-rgt-identity11.8%
Simplified11.8%
Final simplification11.8%
(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 2023207
(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)))