Jump to content

Wikipedia:Reference desk/Archives/Computing/2014 March 17

From Wikipedia, the free encyclopedia
Computing desk
< March 16 << Feb | March | Apr >> March 18 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


March 17

[edit]

Computational errors

[edit]

I have to compute these special functions. They have been a part of my life off and on for many years. I wrote a few C# routines for that. The trouble is I need fairly large indices. When I compute them my only control is graphic representation, observing them visually and making sure that they "behave decently." There is another way too, to use different path in recurrence formulas to compute the same function, thus arriving at the function from a different direction. Sometimes I use the double factorials which might be also error prone in some areas because you end up handling huge numbers. In many cases it is iterations over and over again, driving the indices up and up.

What are standard, mathematically correct ways to estimate computational errors in such situations. Where can I find them?

Thanks, --AboutFace 22 (talk) 16:16, 17 March 2014 (UTC)[reply]

You are right to be skeptical about the accuracy of a straightforward calculation with large indices. Repeated operations can multiply roundoff errors and subtraction kills precision. There is no substitute for a good math library whose behavior is properly characterized. But for off-the-beaten-track functions (other than those found in the Unix math libraries such as sin, cos, exp etc.) and matrix functions found in BLAS or LAPACK you might have to dig in the literature. Abramowitz and Stegun describes these functions but does not go into the detail you would need. List of numerical libraries might provide some ideas. EdJohnston (talk) 18:06, 17 March 2014 (UTC)[reply]
For large order n associated Legendre polynomials, asymptotic expansions in n may be useful; see for instance [1] (for Legendre polynomials) and [2] (for associated Legendre polynomials). --Mark viking (talk) 18:03, 17 March 2014 (UTC)[reply]

Thank you. Parts of it I have known for years, some of that is new. I can tell you that I had been complacent with my calculations more or less until I checked this. It is a Casio online calculator for Associated Legendre Polynomials. When you increase index n the functions take a totally bizarre shape. Mine behave much, much better. There is another website which I cannot immediately find which makes an error estimate for their code and it is discouraging. Thanks, ---AboutFace 22 (talk) 18:57, 17 March 2014 (UTC)[reply]

Could you use gsl_sf_legendre_sphPlm* from the GNU Scientific Library? It can return an error estimate and the documentation implies that it works at least for ℓ up to 150 (and probably higher, since the warning for ℓ > 150 applies to the unnormalized versions of these functions). -- BenRG (talk) 20:18, 17 March 2014 (UTC)[reply]

Thank you very much. There is a lot of stuff out there when one starts digging. --AboutFace 22 (talk) 21:52, 17 March 2014 (UTC)[reply]

How can I cut a little snippet from an MP3 file?

[edit]

I need to cut a passage from a song for class presentation. I have the song in MP3 format; what (free?) tool/program should I use to cut the passage and save it as an MP3? Thanks, Drmies (talk) 17:27, 17 March 2014 (UTC)[reply]

Googling free mp3 editor reveals many editors. First on my search was audacity. Here is a review : http://download.cnet.com/Audacity/3000-2170_4-10058117.html Star Lord - 星王 (talk) 17:34, 17 March 2014 (UTC)[reply]
Yes, I've used Audacity to extract sections of audio files. AndrewWTaylor (talk) 17:36, 17 March 2014 (UTC)[reply]
SoX - e.g.: sox in.mp3 out.mp3 trim 20 5 fade 1 will extract 5 seconds starting 20 seconds in, with a gentle fade at the beginning and end so there isn't a pop. -- Finlay McWalterTalk 17:38, 17 March 2014 (UTC)[reply]

C++ versus C

[edit]

I am an old C programmer. C is not perfect but I can make it do whatever I need done. I've been running into C++ for years. I have made a couple of attempts to understand it, but without much success, meaning I don't instantly see how to structure a new program in C++. There are a few little things that C++ introduced that I like, like the double slash comments and the ability to declare variables within blocks below the procedure level, but these don't really touch on C++'s raison d'etre. I have read some explanations of C++ and they list a bunch of things that C++ does, but I fail to see how any of these features translate into any kind of advantage. To me it looks like all C++ does is add an extra layer of obfuscation. I don't expect an explanation here, but if somebody could point me to one I would appreciate it.50.43.12.61 (talk) 20:35, 17 March 2014 (UTC)[reply]

Actually, C is pretty close to perfect, and C++ is an abomination (as the old joke goes: C++ is to C as breast cancer is to breast). That said, C++ supports object-oriented programming in a way that C does not. Of course everything you can do in C++ you can also do in C (they are both Turing-complete), but some things are much harder in C. I don't like operator-overloading, and I think inheritance is frequently abused. But it does offer real, tangible benefits for some problems. I really miss the ability to do generic programming in C (beyond using macros and thus ditching the advantages of the type system). Also, the C++ standard libraries are quite handy. You might want to take a look at Accelerated C++[3] for some ideas. --Stephan Schulz (talk) 20:59, 17 March 2014 (UTC)[reply]
You might find the C++ Frequently Asked Questions, archived by ParaShift, to be very helpful. It sincerely attempts to answer many C++ questions.
Alternately, you might enjoy reading the altogether insincere, but incredibly humorous and incredibly technically accurate C++ Frequently Questioned Answers web-page, maintained by Yossi Kreinin. It presents a brilliant deconstruction of the C++ programming language, as viewed by an expert C and C++ programmer who holds an admirably profound vendetta against many C++ paradigms. Nimur (talk) 21:06, 17 March 2014 (UTC)[reply]
Are you asking for a justification of features that are also found in many other languages, like OOP and generics/templates, or are you asking about C++-specific features, and if so which ones?
One of the most important things (in my opinion) that C++ offers over C is types that manage their own memory. You can declare std::string x = "Hello"; in a scope and use it very much as though it were int x = 123;. A C++ bignum library will likewise give you bignums that work like built-in integral types; you don't have to worry about refcounting or whatever just as you don't have to worry about that for ints. Generally, unless you're implementing one of these libraries, you rarely need to use dynamic allocation (malloc/free/new/delete) at all in C++, which is good since it's a huge source of bugs in C. -- BenRG (talk) 05:37, 18 March 2014 (UTC)[reply]
Actually, as far as I am aware, C also allows declaring variables inside blocks within functions. JIP | Talk 06:59, 18 March 2014 (UTC)[reply]
Yes, more recent dialects allow this. But, to underscore what Ben said, you don't get a destructor call if the variable goes out of scope. --Stephan Schulz (talk) 07:08, 18 March 2014 (UTC)[reply]
Thank you. Pergelator.50.43.12.61 (talk) 07:07, 18 March 2014 (UTC)[reply]
  • By far the most important thing that C++ adds is support for object-oriented programming. As Stephan said, that's possible with C, but requires using libraries to add a bunch or machinery. In C++ it is an intrinsic part of the language. The advantage of object-oriented programming doesn't really show up until programs become very large, though -- dozens of source code files and thousands of lines of code at minimum. Looie496 (talk) 15:13, 18 March 2014 (UTC)[reply]
  • I'll buck the trend and say OOP is not so important any more. The main improvements of C++ are a more serious type system (including generic programming using templates), and add-ons like the standard template library and Boost (C++ libraries) that use these features to implement things like smart pointers. I find C++ inventor Bjarne Stroustrup's writing about C++ to be clearer than that of some other authors who understand C++ less well, and am ok recommending The C++ Programming Language at least for experienced programmers (if you buy a copy make sure to get the 4th edition). He has another book, "Programming -- Principles and Practice Using C++"[4] intended for less experienced programmers, that sounds promising, but I haven't looked at it.

    As an alternative you might try an even bigger jump away from C, and look at Learn You a Haskell for Great Good, an online book about Haskell (programming language). Haskell is not for everyone, but using it for a while will get you some understanding of polymorphic type systems (like C++ generics but "done right") and other topics like functional programming, that you'll then be able to transfer to other languages. C++ improves on C but it's also a pretty bad mess because of its constraints of being a low-level language and supporting legacy C code. If your goal is to broaden your horizons rather than to specifically use C++, I'd start with Haskell, Scheme, Python, Go, etc. rather than C++. 70.36.142.114 (talk) 22:07, 18 March 2014 (UTC)[reply]

What is dogecoin?

[edit]

I just read this strange word. It is hard to follow all new developments in this crazy world. It is not he end of it. What is shibe? -- --AboutFace 22 (talk) 21:25, 17 March 2014 (UTC)[reply]

We have an article on the dogecoin, I think (note spelling, and note also that it has nothing to do with the Serenissima Repubblica di Venezia). --Trovatore (talk) 21:27, 17 March 2014 (UTC)[reply]
In addition to WP, there is the less reliable, but more entertaining Know You Meme entry on doge. --Mark viking (talk) 21:34, 17 March 2014 (UTC)[reply]