| Alternative 1 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 7624 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e+75)
(/ b (/ a -0.6666666666666666))
(if (<= b 9e-72)
(/ (- (sqrt (- (* b b) (* (* a 3.0) c))) b) (* a 3.0))
(/ (* c -0.5) b))))double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e+75) {
tmp = b / (a / -0.6666666666666666);
} else if (b <= 9e-72) {
tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / 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
code = (-b + sqrt(((b * b) - ((3.0d0 * a) * c)))) / (3.0d0 * a)
end function
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+75)) then
tmp = b / (a / (-0.6666666666666666d0))
else if (b <= 9d-72) then
tmp = (sqrt(((b * b) - ((a * 3.0d0) * c))) - b) / (a * 3.0d0)
else
tmp = (c * (-0.5d0)) / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e+75) {
tmp = b / (a / -0.6666666666666666);
} else if (b <= 9e-72) {
tmp = (Math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0);
} else {
tmp = (c * -0.5) / b;
}
return tmp;
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a)
def code(a, b, c): tmp = 0 if b <= -3.5e+75: tmp = b / (a / -0.6666666666666666) elif b <= 9e-72: tmp = (math.sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0) else: tmp = (c * -0.5) / b return tmp
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -3.5e+75) tmp = Float64(b / Float64(a / -0.6666666666666666)); elseif (b <= 9e-72) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 3.0) * c))) - b) / Float64(a * 3.0)); else tmp = Float64(Float64(c * -0.5) / b); end return tmp end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a); end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.5e+75) tmp = b / (a / -0.6666666666666666); elseif (b <= 9e-72) tmp = (sqrt(((b * b) - ((a * 3.0) * c))) - b) / (a * 3.0); else tmp = (c * -0.5) / b; end tmp_2 = tmp; end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -3.5e+75], N[(b / N[(a / -0.6666666666666666), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 9e-72], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 3.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{b}{\frac{a}{-0.6666666666666666}}\\
\mathbf{elif}\;b \leq 9 \cdot 10^{-72}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 3\right) \cdot c} - b}{a \cdot 3}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b}\\
\end{array}
Results
if b < -3.4999999999999998e75Initial program 35.6%
Simplified35.5%
[Start]35.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]35.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\frac{3 \cdot a}{1}}}
\] |
metadata-eval [<=]35.6 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\frac{3 \cdot a}{\color{blue}{--1}}}
\] |
associate-/l* [<=]35.6 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \left(--1\right)}{3 \cdot a}}
\] |
associate-*r/ [<=]35.5 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{--1}{3 \cdot a}}
\] |
*-commutative [=>]35.5 | \[ \color{blue}{\frac{--1}{3 \cdot a} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}
\] |
associate-*l/ [=>]35.6 | \[ \color{blue}{\frac{\left(--1\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}}
\] |
associate-*r/ [<=]35.6 | \[ \color{blue}{\left(--1\right) \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [=>]35.6 | \[ \color{blue}{1} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
metadata-eval [<=]35.6 | \[ \color{blue}{\frac{-1}{-1}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
times-frac [<=]35.6 | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{-1 \cdot \left(3 \cdot a\right)}}
\] |
neg-mul-1 [<=]35.6 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{-3 \cdot a}}
\] |
distribute-rgt-neg-in [=>]35.6 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{3 \cdot \left(-a\right)}}
\] |
times-frac [=>]35.5 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
metadata-eval [=>]35.5 | \[ \color{blue}{-0.3333333333333333} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}
\] |
neg-mul-1 [=>]35.5 | \[ -0.3333333333333333 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{-1 \cdot a}}
\] |
Applied egg-rr45.2%
[Start]35.5 | \[ -0.3333333333333333 \cdot \frac{b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}}{a}
\] |
|---|---|
associate-*r/ [=>]35.5 | \[ \color{blue}{\frac{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}\right)}{a}}
\] |
clear-num [=>]35.5 | \[ \color{blue}{\frac{1}{\frac{a}{-0.3333333333333333 \cdot \left(b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}\right)}}}
\] |
*-commutative [=>]35.5 | \[ \frac{1}{\frac{a}{\color{blue}{\left(b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}\right) \cdot -0.3333333333333333}}}
\] |
fma-udef [=>]35.5 | \[ \frac{1}{\frac{a}{\left(b - \sqrt{\color{blue}{b \cdot b + a \cdot \left(c \cdot -3\right)}}\right) \cdot -0.3333333333333333}}
\] |
add-sqr-sqrt [=>]19.1 | \[ \frac{1}{\frac{a}{\left(b - \sqrt{b \cdot b + \color{blue}{\sqrt{a \cdot \left(c \cdot -3\right)} \cdot \sqrt{a \cdot \left(c \cdot -3\right)}}}\right) \cdot -0.3333333333333333}}
\] |
hypot-def [=>]45.2 | \[ \frac{1}{\frac{a}{\left(b - \color{blue}{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -3\right)}\right)}\right) \cdot -0.3333333333333333}}
\] |
Taylor expanded in b around -inf 92.5%
Simplified92.5%
[Start]92.5 | \[ -0.6666666666666666 \cdot \frac{b}{a}
\] |
|---|---|
associate-*r/ [=>]92.5 | \[ \color{blue}{\frac{-0.6666666666666666 \cdot b}{a}}
\] |
*-commutative [=>]92.5 | \[ \frac{\color{blue}{b \cdot -0.6666666666666666}}{a}
\] |
associate-/l* [=>]92.5 | \[ \color{blue}{\frac{b}{\frac{a}{-0.6666666666666666}}}
\] |
if -3.4999999999999998e75 < b < 9e-72Initial program 78.6%
if 9e-72 < b Initial program 17.1%
Simplified17.2%
[Start]17.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]17.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{\frac{3 \cdot a}{1}}}
\] |
metadata-eval [<=]17.1 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\frac{3 \cdot a}{\color{blue}{--1}}}
\] |
associate-/l* [<=]17.1 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \left(--1\right)}{3 \cdot a}}
\] |
associate-*r/ [<=]17.1 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \frac{--1}{3 \cdot a}}
\] |
*-commutative [=>]17.1 | \[ \color{blue}{\frac{--1}{3 \cdot a} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}
\] |
associate-*l/ [=>]17.1 | \[ \color{blue}{\frac{\left(--1\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{3 \cdot a}}
\] |
associate-*r/ [<=]17.1 | \[ \color{blue}{\left(--1\right) \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}}
\] |
metadata-eval [=>]17.1 | \[ \color{blue}{1} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
metadata-eval [<=]17.1 | \[ \color{blue}{\frac{-1}{-1}} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\] |
times-frac [<=]17.1 | \[ \color{blue}{\frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{-1 \cdot \left(3 \cdot a\right)}}
\] |
neg-mul-1 [<=]17.1 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{-3 \cdot a}}
\] |
distribute-rgt-neg-in [=>]17.1 | \[ \frac{-1 \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}{\color{blue}{3 \cdot \left(-a\right)}}
\] |
times-frac [=>]17.1 | \[ \color{blue}{\frac{-1}{3} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}}
\] |
metadata-eval [=>]17.1 | \[ \color{blue}{-0.3333333333333333} \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-a}
\] |
neg-mul-1 [=>]17.1 | \[ -0.3333333333333333 \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{\color{blue}{-1 \cdot a}}
\] |
Taylor expanded in b around inf 85.7%
Simplified85.7%
[Start]85.7 | \[ -0.5 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]85.7 | \[ \color{blue}{\frac{-0.5 \cdot c}{b}}
\] |
Final simplification83.9%
| Alternative 1 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.8% |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Accuracy | 78.6% |
| Cost | 7368 |
| Alternative 6 | |
|---|---|
| Accuracy | 16.6% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 38.4% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 38.4% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 38.4% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Accuracy | 64.7% |
| Cost | 452 |
| Alternative 11 | |
|---|---|
| Accuracy | 64.7% |
| Cost | 452 |
| Alternative 12 | |
|---|---|
| Accuracy | 7.5% |
| Cost | 320 |
herbie shell --seed 2023147
(FPCore (a b c)
:name "Cubic critical"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))