
(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 9 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 -1e+155)
(/ (- b) a)
(if (<= b 1.12e-128)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+155) {
tmp = -b / a;
} else if (b <= 1.12e-128) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - 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+155)) then
tmp = -b / a
else if (b <= 1.12d-128) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - 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+155) {
tmp = -b / a;
} else if (b <= 1.12e-128) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+155: tmp = -b / a elif b <= 1.12e-128: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+155) tmp = Float64(Float64(-b) / a); elseif (b <= 1.12e-128) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - 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+155) tmp = -b / a; elseif (b <= 1.12e-128) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+155], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.12e-128], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $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^{+155}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.12 \cdot 10^{-128}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.00000000000000001e155Initial program 51.4%
*-commutative51.4%
Simplified51.4%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.00000000000000001e155 < b < 1.12e-128Initial program 85.4%
if 1.12e-128 < b Initial program 17.9%
*-commutative17.9%
Simplified17.9%
Taylor expanded in b around inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
Final simplification85.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2.25e-56)
(- (/ c b) (/ b a))
(if (<= b 7.2e-129)
(* (/ 0.5 a) (- (sqrt (* c (* a -4.0))) b))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.25e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 7.2e-129) {
tmp = (0.5 / a) * (sqrt((c * (a * -4.0))) - b);
} 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.25d-56)) then
tmp = (c / b) - (b / a)
else if (b <= 7.2d-129) then
tmp = (0.5d0 / a) * (sqrt((c * (a * (-4.0d0)))) - b)
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.25e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 7.2e-129) {
tmp = (0.5 / a) * (Math.sqrt((c * (a * -4.0))) - b);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.25e-56: tmp = (c / b) - (b / a) elif b <= 7.2e-129: tmp = (0.5 / a) * (math.sqrt((c * (a * -4.0))) - b) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.25e-56) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 7.2e-129) tmp = Float64(Float64(0.5 / a) * Float64(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 <= -2.25e-56) tmp = (c / b) - (b / a); elseif (b <= 7.2e-129) tmp = (0.5 / a) * (sqrt((c * (a * -4.0))) - b); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.25e-56], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.2e-129], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.25 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 7.2 \cdot 10^{-129}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{c \cdot \left(a \cdot -4\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.25e-56Initial program 72.3%
*-commutative72.3%
Simplified72.3%
Taylor expanded in b around -inf 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
if -2.25e-56 < b < 7.2e-129Initial program 81.8%
*-commutative81.8%
Simplified81.8%
prod-diff81.3%
*-commutative81.3%
fma-def81.3%
associate-+l+81.3%
pow281.3%
distribute-lft-neg-in81.3%
*-commutative81.3%
distribute-rgt-neg-in81.3%
metadata-eval81.3%
associate-*r*81.3%
*-commutative81.3%
*-commutative81.3%
fma-udef81.3%
Applied egg-rr81.3%
fma-def81.3%
fma-def81.4%
associate-*l*81.4%
Simplified81.4%
Taylor expanded in b around 0 74.6%
distribute-rgt-out75.0%
metadata-eval75.0%
associate-*r*75.0%
mul-1-neg75.0%
unsub-neg75.0%
*-commutative75.0%
Simplified75.0%
div-sub75.0%
sub-neg75.0%
sqrt-prod46.3%
*-commutative46.3%
*-commutative46.3%
div-inv46.3%
sqrt-unprod74.8%
*-commutative74.8%
associate-*r*74.8%
*-commutative74.8%
*-commutative74.8%
associate-/r*74.8%
metadata-eval74.8%
div-inv74.8%
*-commutative74.8%
associate-/r*74.8%
metadata-eval74.8%
Applied egg-rr74.8%
sub-neg74.8%
distribute-rgt-out--74.8%
associate-*r*74.8%
*-commutative74.8%
Simplified74.8%
if 7.2e-129 < b Initial program 17.9%
*-commutative17.9%
Simplified17.9%
Taylor expanded in b around inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
Final simplification81.4%
(FPCore (a b c)
:precision binary64
(if (<= b -7.8e-56)
(- (/ c b) (/ b a))
(if (<= b 4.8e-136)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.8e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 4.8e-136) {
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 <= (-7.8d-56)) then
tmp = (c / b) - (b / a)
else if (b <= 4.8d-136) 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 <= -7.8e-56) {
tmp = (c / b) - (b / a);
} else if (b <= 4.8e-136) {
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 <= -7.8e-56: tmp = (c / b) - (b / a) elif b <= 4.8e-136: 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 <= -7.8e-56) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 4.8e-136) 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 <= -7.8e-56) tmp = (c / b) - (b / a); elseif (b <= 4.8e-136) 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, -7.8e-56], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.8e-136], 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 -7.8 \cdot 10^{-56}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 4.8 \cdot 10^{-136}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.8e-56Initial program 72.3%
*-commutative72.3%
Simplified72.3%
Taylor expanded in b around -inf 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
if -7.8e-56 < b < 4.7999999999999997e-136Initial program 81.8%
*-commutative81.8%
Simplified81.8%
prod-diff81.3%
*-commutative81.3%
fma-def81.3%
associate-+l+81.3%
pow281.3%
distribute-lft-neg-in81.3%
*-commutative81.3%
distribute-rgt-neg-in81.3%
metadata-eval81.3%
associate-*r*81.3%
*-commutative81.3%
*-commutative81.3%
fma-udef81.3%
Applied egg-rr81.3%
fma-def81.3%
fma-def81.4%
associate-*l*81.4%
Simplified81.4%
Taylor expanded in b around 0 74.6%
distribute-rgt-out75.0%
metadata-eval75.0%
associate-*r*75.0%
mul-1-neg75.0%
unsub-neg75.0%
*-commutative75.0%
Simplified75.0%
if 4.7999999999999997e-136 < b Initial program 17.9%
*-commutative17.9%
Simplified17.9%
Taylor expanded in b around inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
Final simplification81.5%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-93) (- (/ c b) (/ b a)) (if (<= b 1.75e-129) (* 0.5 (/ (sqrt (* a (* c -4.0))) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.75e-129) {
tmp = 0.5 * (sqrt((a * (c * -4.0))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.4d-93)) then
tmp = (c / b) - (b / a)
else if (b <= 1.75d-129) then
tmp = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.75e-129) {
tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-93: tmp = (c / b) - (b / a) elif b <= 1.75e-129: tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-93) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.75e-129) tmp = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e-93) tmp = (c / b) - (b / a); elseif (b <= 1.75e-129) tmp = 0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-93], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.75e-129], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-93}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-129}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.4000000000000001e-93Initial program 73.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in b around -inf 85.2%
+-commutative85.2%
mul-1-neg85.2%
unsub-neg85.2%
Simplified85.2%
if -2.4000000000000001e-93 < b < 1.7499999999999999e-129Initial program 80.8%
*-commutative80.8%
Simplified80.8%
prod-diff80.3%
*-commutative80.3%
fma-def80.3%
associate-+l+80.3%
pow280.3%
distribute-lft-neg-in80.3%
*-commutative80.3%
distribute-rgt-neg-in80.3%
metadata-eval80.3%
associate-*r*80.3%
*-commutative80.3%
*-commutative80.3%
fma-udef80.3%
Applied egg-rr80.3%
fma-def80.3%
fma-def80.5%
associate-*l*80.5%
Simplified80.5%
Taylor expanded in b around 0 76.4%
associate-*l/76.6%
distribute-rgt-out77.0%
metadata-eval77.0%
associate-*r*77.0%
*-lft-identity77.0%
*-commutative77.0%
Simplified77.0%
if 1.7499999999999999e-129 < b Initial program 17.9%
*-commutative17.9%
Simplified17.9%
Taylor expanded in b around inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in b around -inf 65.3%
+-commutative65.3%
mul-1-neg65.3%
unsub-neg65.3%
Simplified65.3%
if -1.999999999999994e-310 < b Initial program 33.8%
*-commutative33.8%
Simplified33.8%
Taylor expanded in b around inf 63.0%
mul-1-neg63.0%
distribute-neg-frac63.0%
Simplified63.0%
Final simplification64.2%
(FPCore (a b c) :precision binary64 (if (<= b 3e+76) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3e+76) {
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 <= 3d+76) 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 <= 3e+76) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3e+76: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3e+76) 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 <= 3e+76) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3e+76], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{+76}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.9999999999999998e76Initial program 68.9%
*-commutative68.9%
Simplified68.9%
Taylor expanded in b around -inf 44.7%
associate-*r/44.7%
mul-1-neg44.7%
Simplified44.7%
if 2.9999999999999998e76 < b Initial program 9.0%
*-commutative9.0%
Simplified9.0%
Applied egg-rr3.7%
Taylor expanded in b around -inf 32.4%
Final simplification41.8%
(FPCore (a b c) :precision binary64 (if (<= b 2.05e-299) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.05e-299) {
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.05d-299) 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.05e-299) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.05e-299: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.05e-299) 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.05e-299) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.05e-299], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.05 \cdot 10^{-299}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 2.05e-299Initial program 74.8%
*-commutative74.8%
Simplified74.8%
Taylor expanded in b around -inf 64.6%
associate-*r/64.6%
mul-1-neg64.6%
Simplified64.6%
if 2.05e-299 < b Initial program 33.2%
*-commutative33.2%
Simplified33.2%
Taylor expanded in b around inf 63.5%
mul-1-neg63.5%
distribute-neg-frac63.5%
Simplified63.5%
Final simplification64.0%
(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 54.6%
*-commutative54.6%
Simplified54.6%
Applied egg-rr37.0%
Taylor expanded in a around 0 2.5%
Final simplification2.5%
(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 54.6%
*-commutative54.6%
Simplified54.6%
Applied egg-rr37.0%
Taylor expanded in b around -inf 10.0%
Final simplification10.0%
(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 2024018
(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)))