
(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 -7.8e+141)
(- (/ c b) (/ b a))
(if (<= b 1.08e+77)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.8e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.08e+77) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
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 <= (-7.8d+141)) then
tmp = (c / b) - (b / a)
else if (b <= 1.08d+77) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.8e+141) {
tmp = (c / b) - (b / a);
} else if (b <= 1.08e+77) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.8e+141: tmp = (c / b) - (b / a) elif b <= 1.08e+77: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.8e+141) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.08e+77) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.8e+141) tmp = (c / b) - (b / a); elseif (b <= 1.08e+77) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.8e+141], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.08e+77], 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[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.8 \cdot 10^{+141}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{+77}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -7.79999999999999983e141Initial program 54.3%
Simplified54.4%
Taylor expanded in b around -inf 96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
Simplified96.3%
if -7.79999999999999983e141 < b < 1.07999999999999996e77Initial program 84.1%
if 1.07999999999999996e77 < b Initial program 27.0%
*-commutative27.0%
Simplified27.0%
add-cube-cbrt27.0%
pow327.0%
associate-*l*27.0%
Applied egg-rr27.0%
Taylor expanded in a around 0 95.3%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(if (<= b -8.5e-87)
(- (/ c b) (/ b a))
(if (<= b 1.26e-182)
(/ (+ b (sqrt (* c (* a -4.0)))) (* a 2.0))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = (b + sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
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-87)) then
tmp = (c / b) - (b / a)
else if (b <= 1.26d-182) then
tmp = (b + sqrt((c * (a * (-4.0d0))))) / (a * 2.0d0)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8.5e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.5e-87: tmp = (c / b) - (b / a) elif b <= 1.26e-182: tmp = (b + math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.5e-87) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.26e-182) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / Float64(a * 2.0)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8.5e-87) tmp = (c / b) - (b / a); elseif (b <= 1.26e-182) tmp = (b + sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.5e-87], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.26e-182], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.5 \cdot 10^{-87}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{-182}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -8.5000000000000001e-87Initial program 74.4%
Simplified74.5%
Taylor expanded in b around -inf 88.5%
+-commutative88.5%
mul-1-neg88.5%
unsub-neg88.5%
Simplified88.5%
if -8.5000000000000001e-87 < b < 1.26e-182Initial program 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in b around 0 72.9%
*-commutative72.9%
*-commutative72.9%
associate-*r*72.9%
Simplified72.9%
expm1-log1p-u51.5%
expm1-udef19.4%
add-sqr-sqrt14.0%
sqrt-unprod19.1%
sqr-neg19.1%
sqrt-prod5.3%
add-sqr-sqrt18.7%
Applied egg-rr18.7%
expm1-def50.8%
expm1-log1p70.7%
Simplified70.7%
if 1.26e-182 < b Initial program 48.8%
*-commutative48.8%
Simplified48.8%
add-cube-cbrt48.7%
pow348.7%
associate-*l*48.7%
Applied egg-rr48.7%
Taylor expanded in a around 0 80.3%
Final simplification81.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e-87)
(- (/ c b) (/ b a))
(if (<= b 1.26e-182)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ 0.0 (* a 2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.65e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
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-87)) then
tmp = (c / b) - (b / a)
else if (b <= 1.26d-182) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.65e-87) {
tmp = (c / b) - (b / a);
} else if (b <= 1.26e-182) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.65e-87: tmp = (c / b) - (b / a) elif b <= 1.26e-182: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.65e-87) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.26e-182) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.65e-87) tmp = (c / b) - (b / a); elseif (b <= 1.26e-182) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.65e-87], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.26e-182], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.65 \cdot 10^{-87}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.26 \cdot 10^{-182}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.65e-87Initial program 74.4%
Simplified74.5%
Taylor expanded in b around -inf 88.5%
+-commutative88.5%
mul-1-neg88.5%
unsub-neg88.5%
Simplified88.5%
if -1.65e-87 < b < 1.26e-182Initial program 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in b around 0 72.9%
*-commutative72.9%
*-commutative72.9%
associate-*r*72.9%
Simplified72.9%
if 1.26e-182 < b Initial program 48.8%
*-commutative48.8%
Simplified48.8%
add-cube-cbrt48.7%
pow348.7%
associate-*l*48.7%
Applied egg-rr48.7%
Taylor expanded in a around 0 80.3%
Final simplification82.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-296) (- (/ c b) (/ b a)) (/ 0.0 (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-296) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-296)) then
tmp = (c / b) - (b / a)
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-296) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-296: tmp = (c / b) - (b / a) else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-296) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-296) tmp = (c / b) - (b / a); else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-296], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-296}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2e-296Initial program 73.6%
Simplified73.7%
Taylor expanded in b around -inf 70.7%
+-commutative70.7%
mul-1-neg70.7%
unsub-neg70.7%
Simplified70.7%
if -2e-296 < b Initial program 54.3%
*-commutative54.3%
Simplified54.3%
add-cube-cbrt54.1%
pow354.1%
associate-*l*54.1%
Applied egg-rr54.1%
Taylor expanded in a around 0 68.3%
Final simplification69.6%
(FPCore (a b c) :precision binary64 (if (<= b -9.5e-301) (/ (- b) a) (/ 0.0 (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-301) {
tmp = -b / a;
} else {
tmp = 0.0 / (a * 2.0);
}
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 <= (-9.5d-301)) then
tmp = -b / a
else
tmp = 0.0d0 / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-301) {
tmp = -b / a;
} else {
tmp = 0.0 / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-301: tmp = -b / a else: tmp = 0.0 / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-301) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-301) tmp = -b / a; else tmp = 0.0 / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-301], N[((-b) / a), $MachinePrecision], N[(0.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-301}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a \cdot 2}\\
\end{array}
\end{array}
if b < -9.50000000000000032e-301Initial program 73.8%
Simplified73.9%
Taylor expanded in b around -inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
if -9.50000000000000032e-301 < b Initial program 54.0%
*-commutative54.0%
Simplified54.0%
add-cube-cbrt53.8%
pow353.8%
associate-*l*53.8%
Applied egg-rr53.8%
Taylor expanded in a around 0 68.8%
Final simplification69.2%
(FPCore (a b c) :precision binary64 (if (<= b 7.2e-46) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e-46) {
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 <= 7.2d-46) 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 <= 7.2e-46) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.2e-46: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.2e-46) 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 <= 7.2e-46) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.2e-46], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{-46}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.2e-46Initial program 73.9%
Simplified73.9%
Taylor expanded in b around -inf 55.5%
associate-*r/55.5%
mul-1-neg55.5%
Simplified55.5%
if 7.2e-46 < b Initial program 45.5%
Simplified45.5%
Taylor expanded in b around -inf 2.5%
+-commutative2.5%
mul-1-neg2.5%
unsub-neg2.5%
Simplified2.5%
Taylor expanded in c around inf 28.2%
Final simplification46.4%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 74.2%
Simplified74.3%
Taylor expanded in b around -inf 68.5%
associate-*r/68.5%
mul-1-neg68.5%
Simplified68.5%
if -1.999999999999994e-310 < b Initial program 53.2%
Simplified53.2%
Taylor expanded in a around 0 22.6%
mul-1-neg22.6%
distribute-neg-frac22.6%
Simplified22.6%
Final simplification47.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 64.4%
Simplified64.5%
Taylor expanded in b around -inf 38.1%
+-commutative38.1%
mul-1-neg38.1%
unsub-neg38.1%
Simplified38.1%
Taylor expanded in c around inf 11.4%
Final simplification11.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(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 2024023
(FPCore (a b c)
:name "The quadratic formula (r1)"
: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)))