http://qs1969.pair.com?node_id=1189615


in reply to Re: solve cubic equations
in thread solve cubic equations

my \C = ( ( Δ1 + sqrt( Δ1² - 4 × Δ0³ + 0i) ) / 2 ).roots(3)[0];

Mathematically, your code is equivalent. (The arctan and cos are hidden inside roots.) Numerically, yours is potentially unstable. The first + in the line above might lose accuracy due to subtracting nearly-equal numbers. See Numerical Recipes, chapter 5.6. Unfortunately, sometimes we have to choose between code that looks nice and code that works.

The trouble with Perl 6 is that it's full of people who think it's a good idea to have a class called "Cool" which contains a hodgepodge of numerical and string-manipulation methods.

Replies are listed 'Best First'.
Re^3: solve cubic equations
by bduggan (Pilgrim) on May 11, 2017 at 00:08 UTC
    1. Yes, it's totally possible to optimize for accuracy, and yes, some situations call for that.
    2. Allomorphic typing is cool.
      1. Lots of things are cool, but you can't name them all "Cool" in your language.
      2. This post is the 9th hit on google for the phrase "allomorphic typing." Of the ones above it, 7 are about linguistics, and the other one says that term was briefly in use in computer science 26 years ago. You don't frighten me with your silly language behavior.