Serving the Quantitative Finance Community

Cuchulainn
Posts: 18799
Joined: July 16th, 2004, 7:38 am
Location: Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch

### Functional programming

QuoteOriginally posted by: outrunQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: outrunand I'm sure there is need for complex<double, long> somewhereand Matrix<complex<double>, complex<long> >complex<Matrix<double>, Matrix<long> >could both be relenant for their different memory layouts.Indeed. The polar form for complex numbers is complex<double, Degree> and in 3d we have curvilinear coordinates Point<T1, T2, T3> e.g. Point<double, Degree, Degree> etc.AlsoPolynomial<Matrix> e.g. Cayley-Hamilton theoremMatrix<Polynomial> aka matrix polynomialsI wonder if anyone has developed efficient data structures for these in C++?Efficient could be defined be in the contect of algorithms that act on them, ... and that could be expressed as performance measures of the algorithms (speed, memory usage, parallel friendly)Time: how long does the algorithm take to complete.Space: how much working memory (typically RAM) is needed by the algorithm. This has two aspects: the amount of memory needed by the code, and the amount of memory needed for the data on which the code operates.
Leftist, Alt Right, Marxist, Nihilist, Neo Celtic Reconstructionists, and splitters, all opinions appreciated. (Obviously that doesn't include Liberal Democrats.)

Posts: 3300
Joined: September 20th, 2002, 8:30 pm

### Functional programming

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: outrunQuoteOriginally posted by: CuchulainnQuoteOriginally posted by: outrunand I'm sure there is need for complex<double, long> somewhereand Matrix<complex<double>, complex<long> >complex<Matrix<double>, Matrix<long> >could both be relenant for their different memory layouts.Indeed. The polar form for complex numbers is complex<double, Degree> and in 3d we have curvilinear coordinates Point<T1, T2, T3> e.g. Point<double, Degree, Degree> etc.AlsoPolynomial<Matrix> e.g. Cayley-Hamilton theoremMatrix<Polynomial> aka matrix polynomialsI wonder if anyone has developed efficient data structures for these in C++?Efficient could be defined be in the contect of algorithms that act on them, ... and that could be expressed as performance measures of the algorithms (speed, memory usage, parallel friendly)Time: how long does the algorithm take to complete.Space: how much working memory (typically RAM) is needed by the algorithm. This has two aspects: the amount of memory needed by the code, and the amount of memory needed for the data on which the code operates.What about bandwidth? The Time and Space performance dimensions of the algorithm are linked to the processing speed and memory capacity dimensions of the platform. But the platform also has an intrinsic bandwidth between memory and CPU and different algorithms may call for different levels of utilization of this bandwidth. To a first approximation, the bandwidth requirement of an algorithm is lower-bounded by the space requirement (the algorithm presumably read/writes each data location at least once) and the bandwidth requirement is upper-bounded by the time requirement (an algorithm may spend all of it's time in memory operations). Yet this interval might be quite large and different platforms might have different bandwidth levels (which is especially salient if we employ the algorithm on big data where memory access may be to secondary storage via IP channels).

exneratunrisk
Posts: 0
Joined: April 20th, 2004, 12:25 pm

### Functional programming

Performance: if it is designed that way, functional programming really matters - A Comparison of Programming Languages in Economics (a NBER paper). The big difference of 2 Mathematica programming styles.
Last edited by exneratunrisk on July 14th, 2014, 10:00 pm, edited 1 time in total.

ExSan
Posts: 456
Joined: April 12th, 2003, 10:40 am

### Functional programming

QuoteOriginally posted by: exneratunriskPerformance: if it is designed that way, functional programming really matters - A Comparison of Programming Languages in Economics (a NBER paper). The big difference of 2 Mathematica programming styles.pp10Quote°our result is that C++ and Fortran still maintain a considerable speed advantagewith respect to all other alternatives°around 10 times faster than Matlab, and around 48 times faster than the Pypy implementation of Python.°We find speed improvements of more than 100 percent between di§erent executables of thesame underlying code (and using equivalent optimization compilation flags)°Our fourth result is that Java imposes a speed penalty of 110 to 169 percent°Julia is also slightly faster than Java and close to 4 times faster than Matlab°Matlab runs between 9 to 11 times slower than the best C++ executable°Python has a mixed performance. In the Pypy implementation, our code runs around 44-45 times slower than in C++°e Numba,code runs only between 1.57 and 1.62 times slower than the best C++ executable°R's performance is poor overall, between 500 to 700 times slower than C++° Mathematica code takes up to 809 times longer than C++.
°°° About ExSan http://bit.ly/3U5bIdq #OpenToWork °°°

exneratunrisk
Posts: 0
Joined: April 20th, 2004, 12:25 pm

### Functional programming

QuoteOriginally posted by: ExSanQuoteOriginally posted by: exneratunriskPerformance: if it is designed that way, functional programming really matters - A Comparison of Programming Languages in Economics (a NBER paper). The big difference of 2 Mathematica programming styles.pp10Quote°our result is that C++ and Fortran still maintain a considerable speed advantagewith respect to all other alternatives°around 10 times faster than Matlab, and around 48 times faster than the Pypy implementation of Python.°We find speed improvements of more than 100 percent between di§erent executables of thesame underlying code (and using equivalent optimization compilation flags)°Our fourth result is that Java imposes a speed penalty of 110 to 169 percent°Julia is also slightly faster than Java and close to 4 times faster than Matlab°Matlab runs between 9 to 11 times slower than the best C++ executable°Python has a mixed performance. In the Pypy implementation, our code runs around 44-45 times slower than in C++°e Numba,code runs only between 1.57 and 1.62 times slower than the best C++ executable°R's performance is poor overall, between 500 to 700 times slower than C++° Mathematica code takes up to 809 times longer than C++.The art of programming: 809 times or 4 time (with functional ?...). That has to do with the implementation of a uniform functional expression layer that is used by the Mathematica Kernel (Wolfram Engine).
Last edited by exneratunrisk on July 16th, 2014, 10:00 pm, edited 1 time in total.

Cuchulainn
Posts: 18799
Joined: July 16th, 2004, 7:38 am
Location: Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch

### Re: Functional programming

VivienB: well, some do, some don't.In particular, compile-time generic programming (with the binding & dispatch performed statically but general enough so as to allow for compile-time laziness) is not as common.Let's take Template Haskell as an example: http://www.haskell.org/haskellwiki/Temp ... askellThis is closely associated with type classes,[/b] for which, again, while comparable features are widespread, things are rather more interesting as far as the compile-time variant is concerned.Also relevant in this context:- Multi-parameter type classes- (Indexed) Type familiesI'm wondering, how many other FP languages implement comparable features?// I think GP is far more than "generics" implemented by some programming languages. In particular, I find run-time attempts at the implementation particularly limited and generally uninteresting.From the PLT (programming language theory) point of view, Harper (2014) provides an interesting way to look at it (succinct if you're coming from an FP background):QuoteThe generic extension of a type operator is an example of the concept of a functor in category theory (MacLane, 1998). Generic programming is essentially functorial programming, exploiting the functorial action of polynomial type operators (Hinze and Jeuring, 2003).If you're curious / would like more information, take a look at Chapter 13 (Generic Programming), which is the source of the quote:Harper (2014) "Practical Foundations for Programming Languages" Second Editionhttp://www.cs.cmu.edu/~rwh/plbook/book.pdf
Yes, by George!
Haskell Type classes are the omphalos of C++20 Concepts.
Got it, QED

Why did you guys keep the rest of us in the dark for so long?

// HaskellThis is closely associated with type classes
Leftist, Alt Right, Marxist, Nihilist, Neo Celtic Reconstructionists, and splitters, all opinions appreciated. (Obviously that doesn't include Liberal Democrats.)

Cuchulainn
Posts: 18799
Joined: July 16th, 2004, 7:38 am
Location: Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch

### Re: Functional programming

how so?
Attachments
Test101Concepts.pdf