
(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 -1e+121)
(/ (- (* a (/ c b)) b) a)
(if (<= b 2.65e-47)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+121) {
tmp = ((a * (c / b)) - b) / a;
} else if (b <= 2.65e-47) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -(c / b);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1d+121)) then
tmp = ((a * (c / b)) - b) / a
else if (b <= 2.65d-47) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -(c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e+121) {
tmp = ((a * (c / b)) - b) / a;
} else if (b <= 2.65e-47) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+121: tmp = ((a * (c / b)) - b) / a elif b <= 2.65e-47: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+121) tmp = Float64(Float64(Float64(a * Float64(c / b)) - b) / a); elseif (b <= 2.65e-47) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(-Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+121) tmp = ((a * (c / b)) - b) / a; elseif (b <= 2.65e-47) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+121], N[(N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.65e-47], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+121}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\mathbf{elif}\;b \leq 2.65 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -1.00000000000000004e121Initial program 44.7%
*-commutative44.7%
Simplified44.7%
Taylor expanded in b around -inf 94.5%
mul-1-neg94.5%
distribute-rgt-neg-in94.5%
+-commutative94.5%
mul-1-neg94.5%
unsub-neg94.5%
Simplified94.5%
Taylor expanded in a around 0 86.9%
mul-1-neg86.9%
+-commutative86.9%
unsub-neg86.9%
associate-/l*95.1%
Simplified95.1%
if -1.00000000000000004e121 < b < 2.64999999999999999e-47Initial program 83.3%
if 2.64999999999999999e-47 < b Initial program 11.1%
*-commutative11.1%
Simplified11.1%
Taylor expanded in b around inf 88.5%
associate-*r/88.5%
mul-1-neg88.5%
Simplified88.5%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-23)
(- (/ c b) (/ b a))
(if (<= b 1.22e-47)
(/ (- (sqrt (* -4.0 (* a c))) b) (* a 2.0))
(- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-23) {
tmp = (c / b) - (b / a);
} else if (b <= 1.22e-47) {
tmp = (sqrt((-4.0 * (a * 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 <= (-2.1d-23)) then
tmp = (c / b) - (b / a)
else if (b <= 1.22d-47) then
tmp = (sqrt(((-4.0d0) * (a * 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 <= -2.1e-23) {
tmp = (c / b) - (b / a);
} else if (b <= 1.22e-47) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0);
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-23: tmp = (c / b) - (b / a) elif b <= 1.22e-47: tmp = (math.sqrt((-4.0 * (a * c))) - b) / (a * 2.0) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-23) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.22e-47) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * 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 <= -2.1e-23) tmp = (c / b) - (b / a); elseif (b <= 1.22e-47) tmp = (sqrt((-4.0 * (a * c))) - b) / (a * 2.0); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-23], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.22e-47], N[(N[(N[Sqrt[N[(-4.0 * N[(a * 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 -2.1 \cdot 10^{-23}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -2.1000000000000001e-23Initial program 62.1%
*-commutative62.1%
Simplified62.1%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-rgt-neg-in87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
Simplified87.5%
Taylor expanded in a around inf 87.9%
+-commutative87.9%
mul-1-neg87.9%
unsub-neg87.9%
Simplified87.9%
if -2.1000000000000001e-23 < b < 1.2199999999999999e-47Initial program 81.0%
*-commutative81.0%
Simplified81.0%
Applied egg-rr80.7%
sub-neg80.7%
distribute-rgt-out--80.7%
Simplified80.7%
pow1/280.7%
pow-to-exp75.2%
Applied egg-rr75.2%
Taylor expanded in a around -inf 42.6%
mul-1-neg42.6%
unsub-neg42.6%
*-commutative42.6%
Simplified42.6%
*-commutative42.6%
clear-num42.6%
un-div-inv42.6%
exp-prod37.2%
unpow1/237.2%
diff-log66.9%
add-exp-log71.8%
*-commutative71.8%
div-inv71.8%
times-frac71.8%
metadata-eval71.8%
div-inv71.8%
metadata-eval71.8%
Applied egg-rr71.8%
associate-/r/71.8%
/-rgt-identity71.8%
Simplified71.8%
if 1.2199999999999999e-47 < b Initial program 11.1%
*-commutative11.1%
Simplified11.1%
Taylor expanded in b around inf 88.5%
associate-*r/88.5%
mul-1-neg88.5%
Simplified88.5%
Final simplification83.1%
(FPCore (a b c)
:precision binary64
(if (<= b -2.3e-21)
(- (/ c b) (/ b a))
(if (<= b 3.7e-47)
(* (/ 0.5 a) (- (sqrt (* a (* c -4.0))) b))
(- (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e-21) {
tmp = (c / b) - (b / a);
} else if (b <= 3.7e-47) {
tmp = (0.5 / a) * (sqrt((a * (c * -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.3d-21)) then
tmp = (c / b) - (b / a)
else if (b <= 3.7d-47) then
tmp = (0.5d0 / a) * (sqrt((a * (c * (-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.3e-21) {
tmp = (c / b) - (b / a);
} else if (b <= 3.7e-47) {
tmp = (0.5 / a) * (Math.sqrt((a * (c * -4.0))) - b);
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.3e-21: tmp = (c / b) - (b / a) elif b <= 3.7e-47: tmp = (0.5 / a) * (math.sqrt((a * (c * -4.0))) - b) else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.3e-21) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.7e-47) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(Float64(a * Float64(c * -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.3e-21) tmp = (c / b) - (b / a); elseif (b <= 3.7e-47) tmp = (0.5 / a) * (sqrt((a * (c * -4.0))) - b); else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.3e-21], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.7e-47], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], (-N[(c / b), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{-21}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.7 \cdot 10^{-47}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{a \cdot \left(c \cdot -4\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -2.29999999999999999e-21Initial program 62.1%
*-commutative62.1%
Simplified62.1%
Taylor expanded in b around -inf 87.5%
mul-1-neg87.5%
distribute-rgt-neg-in87.5%
+-commutative87.5%
mul-1-neg87.5%
unsub-neg87.5%
Simplified87.5%
Taylor expanded in a around inf 87.9%
+-commutative87.9%
mul-1-neg87.9%
unsub-neg87.9%
Simplified87.9%
if -2.29999999999999999e-21 < b < 3.7e-47Initial program 81.0%
*-commutative81.0%
Simplified81.0%
Applied egg-rr80.7%
sub-neg80.7%
distribute-rgt-out--80.7%
Simplified80.7%
Taylor expanded in a around inf 71.5%
*-commutative71.5%
associate-*r*71.5%
Simplified71.5%
if 3.7e-47 < b Initial program 11.1%
*-commutative11.1%
Simplified11.1%
Taylor expanded in b around inf 88.5%
associate-*r/88.5%
mul-1-neg88.5%
Simplified88.5%
Final simplification83.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 69.5%
*-commutative69.5%
Simplified69.5%
Taylor expanded in b around -inf 65.0%
mul-1-neg65.0%
distribute-rgt-neg-in65.0%
+-commutative65.0%
mul-1-neg65.0%
unsub-neg65.0%
Simplified65.0%
Taylor expanded in a around inf 66.2%
+-commutative66.2%
mul-1-neg66.2%
unsub-neg66.2%
Simplified66.2%
if -4.999999999999985e-310 < b Initial program 30.3%
*-commutative30.3%
Simplified30.3%
Taylor expanded in b around inf 65.5%
associate-*r/65.5%
mul-1-neg65.5%
Simplified65.5%
Final simplification65.9%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ b (- a)) (- (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = b / -a;
} else {
tmp = -(c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = b / -a else: tmp = -(c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(b / Float64(-a)); else tmp = Float64(-Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = b / -a; else tmp = -(c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(b / (-a)), $MachinePrecision], (-N[(c / b), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;-\frac{c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 69.5%
*-commutative69.5%
Simplified69.5%
Taylor expanded in b around -inf 65.8%
mul-1-neg65.8%
distribute-neg-frac265.8%
Simplified65.8%
if -4.999999999999985e-310 < b Initial program 30.3%
*-commutative30.3%
Simplified30.3%
Taylor expanded in b around inf 65.5%
associate-*r/65.5%
mul-1-neg65.5%
Simplified65.5%
Final simplification65.6%
(FPCore (a b c) :precision binary64 (if (<= b 2.22e-41) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.22e-41) {
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.22d-41) 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.22e-41) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.22e-41: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.22e-41) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.22e-41) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.22e-41], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.22 \cdot 10^{-41}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.2200000000000001e-41Initial program 70.8%
*-commutative70.8%
Simplified70.8%
Taylor expanded in b around -inf 51.5%
mul-1-neg51.5%
distribute-neg-frac251.5%
Simplified51.5%
if 2.2200000000000001e-41 < b Initial program 11.2%
*-commutative11.2%
Simplified11.2%
Taylor expanded in b around -inf 2.3%
mul-1-neg2.3%
distribute-rgt-neg-in2.3%
+-commutative2.3%
mul-1-neg2.3%
unsub-neg2.3%
Simplified2.3%
Taylor expanded in b around 0 25.0%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 50.1%
*-commutative50.1%
Simplified50.1%
Taylor expanded in b around -inf 33.8%
mul-1-neg33.8%
distribute-rgt-neg-in33.8%
+-commutative33.8%
mul-1-neg33.8%
unsub-neg33.8%
Simplified33.8%
Taylor expanded in b around 0 10.9%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 50.1%
*-commutative50.1%
Simplified50.1%
*-un-lft-identity50.1%
*-un-lft-identity50.1%
prod-diff50.1%
*-commutative50.1%
*-un-lft-identity50.1%
fma-define50.1%
*-un-lft-identity50.1%
+-commutative50.1%
add-sqr-sqrt35.0%
sqrt-unprod48.2%
sqr-neg48.2%
sqrt-prod13.3%
add-sqr-sqrt32.6%
pow232.6%
add-sqr-sqrt19.5%
sqrt-unprod32.6%
sqr-neg32.6%
sqrt-prod13.3%
add-sqr-sqrt32.3%
*-commutative32.3%
*-un-lft-identity32.3%
Applied egg-rr32.3%
+-commutative32.3%
associate-+l+31.9%
fma-undefine31.9%
*-rgt-identity31.9%
Simplified31.9%
Taylor expanded in b around -inf 2.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- b) t_0) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b < 0.0d0) then
tmp = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-b - t_0) / (2.0d0 * a)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b < 0.0) {
tmp = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b < 0.0: tmp = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b < 0.0) tmp = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-b - t_0) / (2.0 * a))); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t\_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2024093
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(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)))