
(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 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(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 -1e+154)
(/ b (- a))
(if (<= b 4.3e-75)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+154) {
tmp = b / -a;
} else if (b <= 4.3e-75) {
tmp = (sqrt(((b * b) - (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 <= (-1d+154)) then
tmp = b / -a
else if (b <= 4.3d-75) then
tmp = (sqrt(((b * b) - (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 <= -1e+154) {
tmp = b / -a;
} else if (b <= 4.3e-75) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+154: tmp = b / -a elif b <= 4.3e-75: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+154) tmp = Float64(b / Float64(-a)); elseif (b <= 4.3e-75) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+154) tmp = b / -a; elseif (b <= 4.3e-75) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+154], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 4.3e-75], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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^{+154}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 4.3 \cdot 10^{-75}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.00000000000000004e154Initial program 44.5%
*-commutative44.5%
Simplified44.5%
Taylor expanded in b around -inf 97.6%
associate-*r/97.6%
mul-1-neg97.6%
Simplified97.6%
if -1.00000000000000004e154 < b < 4.2999999999999999e-75Initial program 85.8%
if 4.2999999999999999e-75 < b Initial program 17.5%
*-commutative17.5%
Simplified17.5%
Taylor expanded in b around inf 83.4%
associate-*r/83.4%
neg-mul-183.4%
Simplified83.4%
Final simplification86.5%
(FPCore (a b c)
:precision binary64
(if (<= b -7e-142)
(* b (- (/ c (pow b 2.0)) (/ 1.0 a)))
(if (<= b 1.9e-75)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-142) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 1.9e-75) {
tmp = (sqrt((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 <= (-7d-142)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 1.9d-75) then
tmp = (sqrt((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 <= -7e-142) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 1.9e-75) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-142: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 1.9e-75: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-142) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 1.9e-75) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e-142) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 1.9e-75) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-142], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.9e-75], N[(N[(N[Sqrt[N[(c * N[(a * -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 \cdot 10^{-142}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-75}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -7.00000000000000029e-142Initial program 76.4%
*-commutative76.4%
Simplified76.4%
Taylor expanded in b around -inf 92.3%
mul-1-neg92.3%
distribute-rgt-neg-in92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
if -7.00000000000000029e-142 < b < 1.89999999999999997e-75Initial program 76.4%
*-commutative76.4%
Simplified76.4%
Taylor expanded in b around 0 74.9%
associate-*r*74.9%
*-commutative74.9%
*-commutative74.9%
Simplified74.9%
if 1.89999999999999997e-75 < b Initial program 17.5%
*-commutative17.5%
Simplified17.5%
Taylor expanded in b around inf 83.4%
associate-*r/83.4%
neg-mul-183.4%
Simplified83.4%
Final simplification84.5%
(FPCore (a b c) :precision binary64 (if (<= b -7e-142) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 5.4e-76) (/ (sqrt (* a (* c -4.0))) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e-142) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 5.4e-76) {
tmp = sqrt((a * (c * -4.0))) / (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 <= (-7d-142)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 5.4d-76) then
tmp = sqrt((a * (c * (-4.0d0)))) / (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 <= -7e-142) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 5.4e-76) {
tmp = Math.sqrt((a * (c * -4.0))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e-142: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 5.4e-76: tmp = math.sqrt((a * (c * -4.0))) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e-142) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 5.4e-76) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e-142) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 5.4e-76) tmp = sqrt((a * (c * -4.0))) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e-142], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.4e-76], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{-142}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{-76}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -7.00000000000000029e-142Initial program 76.4%
*-commutative76.4%
Simplified76.4%
Taylor expanded in b around -inf 92.3%
mul-1-neg92.3%
distribute-rgt-neg-in92.3%
+-commutative92.3%
mul-1-neg92.3%
unsub-neg92.3%
Simplified92.3%
if -7.00000000000000029e-142 < b < 5.4000000000000001e-76Initial program 76.4%
*-commutative76.4%
Simplified76.4%
add-cube-cbrt75.6%
pow375.6%
*-commutative75.6%
associate-*l*75.6%
Applied egg-rr75.6%
Taylor expanded in a around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt73.8%
distribute-lft-neg-in73.8%
metadata-eval73.8%
rem-cube-cbrt74.3%
Simplified74.3%
if 5.4000000000000001e-76 < b Initial program 17.5%
*-commutative17.5%
Simplified17.5%
Taylor expanded in b around inf 83.4%
associate-*r/83.4%
neg-mul-183.4%
Simplified83.4%
Final simplification84.3%
(FPCore (a b c) :precision binary64 (if (<= b -6e-169) (* b (- (/ c (pow b 2.0)) (/ 1.0 a))) (if (<= b 7.6e-170) (sqrt (/ c (- a))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e-169) {
tmp = b * ((c / pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7.6e-170) {
tmp = sqrt((c / -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 <= (-6d-169)) then
tmp = b * ((c / (b ** 2.0d0)) - (1.0d0 / a))
else if (b <= 7.6d-170) then
tmp = sqrt((c / -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 <= -6e-169) {
tmp = b * ((c / Math.pow(b, 2.0)) - (1.0 / a));
} else if (b <= 7.6e-170) {
tmp = Math.sqrt((c / -a));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e-169: tmp = b * ((c / math.pow(b, 2.0)) - (1.0 / a)) elif b <= 7.6e-170: tmp = math.sqrt((c / -a)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e-169) tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) - Float64(1.0 / a))); elseif (b <= 7.6e-170) tmp = sqrt(Float64(c / Float64(-a))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6e-169) tmp = b * ((c / (b ^ 2.0)) - (1.0 / a)); elseif (b <= 7.6e-170) tmp = sqrt((c / -a)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e-169], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.6e-170], N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{-169}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} - \frac{1}{a}\right)\\
\mathbf{elif}\;b \leq 7.6 \cdot 10^{-170}:\\
\;\;\;\;\sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.9999999999999998e-169Initial program 78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in b around -inf 87.2%
mul-1-neg87.2%
distribute-rgt-neg-in87.2%
+-commutative87.2%
mul-1-neg87.2%
unsub-neg87.2%
Simplified87.2%
if -5.9999999999999998e-169 < b < 7.5999999999999995e-170Initial program 78.5%
*-commutative78.5%
Simplified78.5%
add-cube-cbrt77.7%
pow377.7%
*-commutative77.7%
associate-*l*77.7%
Applied egg-rr77.7%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt39.3%
rem-cube-cbrt39.7%
associate-/l*39.6%
Simplified39.6%
add-sqr-sqrt39.4%
sqrt-unprod39.6%
*-commutative39.6%
*-commutative39.6%
swap-sqr39.6%
mul-1-neg39.6%
mul-1-neg39.6%
sqr-neg39.6%
add-sqr-sqrt39.6%
metadata-eval39.6%
Applied egg-rr39.6%
Taylor expanded in c around 0 39.7%
associate-*r/39.7%
neg-mul-139.7%
Simplified39.7%
if 7.5999999999999995e-170 < b Initial program 24.5%
*-commutative24.5%
Simplified24.5%
Taylor expanded in b around inf 77.0%
associate-*r/77.0%
neg-mul-177.0%
Simplified77.0%
Final simplification75.2%
(FPCore (a b c) :precision binary64 (if (<= b -1.35e-155) (/ b (- a)) (if (<= b 8e-170) (sqrt (/ c (- a))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-155) {
tmp = b / -a;
} else if (b <= 8e-170) {
tmp = sqrt((c / -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.35d-155)) then
tmp = b / -a
else if (b <= 8d-170) then
tmp = sqrt((c / -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.35e-155) {
tmp = b / -a;
} else if (b <= 8e-170) {
tmp = Math.sqrt((c / -a));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e-155: tmp = b / -a elif b <= 8e-170: tmp = math.sqrt((c / -a)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e-155) tmp = Float64(b / Float64(-a)); elseif (b <= 8e-170) tmp = sqrt(Float64(c / Float64(-a))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.35e-155) tmp = b / -a; elseif (b <= 8e-170) tmp = sqrt((c / -a)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e-155], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 8e-170], N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{-155}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-170}:\\
\;\;\;\;\sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.34999999999999991e-155Initial program 77.1%
*-commutative77.1%
Simplified77.1%
Taylor expanded in b around -inf 90.6%
associate-*r/90.6%
mul-1-neg90.6%
Simplified90.6%
if -1.34999999999999991e-155 < b < 7.99999999999999987e-170Initial program 80.4%
*-commutative80.4%
Simplified80.4%
add-cube-cbrt79.6%
pow379.6%
*-commutative79.6%
associate-*l*79.6%
Applied egg-rr79.6%
Taylor expanded in a around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt36.2%
rem-cube-cbrt36.5%
associate-/l*36.5%
Simplified36.5%
add-sqr-sqrt36.3%
sqrt-unprod36.5%
*-commutative36.5%
*-commutative36.5%
swap-sqr36.5%
mul-1-neg36.5%
mul-1-neg36.5%
sqr-neg36.5%
add-sqr-sqrt36.5%
metadata-eval36.5%
Applied egg-rr36.5%
Taylor expanded in c around 0 36.5%
associate-*r/36.5%
neg-mul-136.5%
Simplified36.5%
if 7.99999999999999987e-170 < b Initial program 24.5%
*-commutative24.5%
Simplified24.5%
Taylor expanded in b around inf 77.0%
associate-*r/77.0%
neg-mul-177.0%
Simplified77.0%
Final simplification75.1%
(FPCore (a b c) :precision binary64 (if (<= b 3.5e-280) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 3.5e-280) {
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 <= 3.5d-280) 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 <= 3.5e-280) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3.5e-280: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3.5e-280) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 3.5e-280) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3.5e-280], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-280}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 3.5000000000000001e-280Initial program 78.7%
*-commutative78.7%
Simplified78.7%
Taylor expanded in b around -inf 70.9%
associate-*r/70.9%
mul-1-neg70.9%
Simplified70.9%
if 3.5000000000000001e-280 < b Initial program 29.7%
*-commutative29.7%
Simplified29.7%
Taylor expanded in b around inf 70.3%
associate-*r/70.3%
neg-mul-170.3%
Simplified70.3%
Final simplification70.6%
(FPCore (a b c) :precision binary64 (if (<= b 2e-5) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2e-5) {
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-5) 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-5) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2e-5: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2e-5) 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 <= 2e-5) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2e-5], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{-5}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.00000000000000016e-5Initial program 71.8%
*-commutative71.8%
Simplified71.8%
Taylor expanded in b around -inf 51.7%
associate-*r/51.7%
mul-1-neg51.7%
Simplified51.7%
if 2.00000000000000016e-5 < b Initial program 14.3%
*-commutative14.3%
Simplified14.3%
Taylor expanded in b around inf 91.5%
associate-*r/91.5%
neg-mul-191.5%
Simplified91.5%
add-sqr-sqrt48.7%
sqrt-unprod50.6%
sqr-neg50.6%
sqrt-unprod10.5%
add-sqr-sqrt25.1%
*-un-lft-identity25.1%
Applied egg-rr25.1%
*-lft-identity25.1%
Simplified25.1%
Final simplification43.4%
(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 53.8%
*-commutative53.8%
Simplified53.8%
Taylor expanded in b around inf 36.9%
associate-*r/36.9%
neg-mul-136.9%
Simplified36.9%
add-sqr-sqrt19.2%
sqrt-unprod19.3%
sqr-neg19.3%
sqrt-unprod4.1%
add-sqr-sqrt9.7%
*-un-lft-identity9.7%
Applied egg-rr9.7%
*-lft-identity9.7%
Simplified9.7%
(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 53.8%
*-commutative53.8%
Simplified53.8%
Taylor expanded in b around -inf 36.3%
associate-*r/36.3%
mul-1-neg36.3%
Simplified36.3%
add-log-exp12.0%
Applied egg-rr12.0%
*-un-lft-identity12.0%
log-prod12.0%
metadata-eval12.0%
rem-log-exp36.3%
add-sqr-sqrt34.6%
sqrt-unprod28.6%
sqr-neg28.6%
sqrt-prod1.8%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
+-lft-identity2.6%
Simplified2.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t\_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t\_2}\\
\end{array}
\end{array}
herbie shell --seed 2024141
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ (- sqtD (/ b 2)) a) (/ (- c) (+ (/ b 2) sqtD)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))