Serving the Quantitative Finance Community

 
User avatar
Polter
Posts: 1
Joined: April 29th, 2008, 4:55 pm

Functional programming

June 24th, 2014, 8:56 pm

Indeed, it's a good idea to use consistent terminology; thankfully, GP is an unambiguous, well-defined term (significantly predating the appearance of "C#" -- it's not clear what its importance or relevance is here):QuoteThe term generic programming was originally coined by David Musser and Alexander Stepanov[2] in a more specific sense than the above, to describe a programming paradigm whereby fundamental requirements on types are abstracted from across concrete examples of algorithms and data structures and formalised as concepts, with generic functions implemented in terms of these concepts, typically using language genericity mechanisms as described above.// from the posted link: http://en.wikipedia.org/wiki/Generic_programming// referring to Musser, D. R.; Stepanov, A. A. (1989). "Generic programming".It seems that there's some possible misunderstanding / conflation between the necessary conditions and sufficient conditions going on here.GP is a programming style, parametric polymorphism is a tool that may be used in this context; consider: Quotegeneric functions and generic datatypes respectively [...] form the basis of generic programming.Fortunately, it's not a mater of a personal "opinion" about what the best(?) term is, both are well-defined, well-known, and have their own specific uses.It seems that Eiffel only supported generic datatypes ("generic classes"):http://en.wikipedia.org/wiki/Eiffel_%28 ... n_Eiffel// On a side note, if one wanted to point out some kind of historical precedence, even just in the context of support for parametric polymorphism, ML (1973) would've been more appropriate than Eiffel (1986). Credit where credit's due, and all that.// Similarly, Cardelli & Wegner (1985) is indeed a good read, although it's worth noting that "parametric polymorphism" was already introduced by Strachey (1967), in "Fundamental Concepts in Programming Languages".Now, to the necessary vs. sufficient conditions; take an example:QuoteGenerics are a facility of generic programmingNote that a "facility of X" is not equal to X.In other words, "generics" are not equal "generic programming" -- just as languages that happen support "functions" (sometimes even "procedures" or "subroutines") aren't all equally supporting "functional programming".A necessary condition is not a sufficient condition: It would be a bit silly to argue that C is a functional programming language, wouldn't it?These are all well-defined and well-known terms in the PLT community -- and it's a good idea to stick to the established terminology, especially when communicating with other people (assuming being understood is considered a desirable feature).If some conflate support for "generics" with support for "generic programming" -- or support for "functions" with support for "functional programming" -- then, indeed, seems they may suffer from the "changing the meaning of words" problem. No reason to blame CS "abandon", really :-)
Last edited by Polter on June 23rd, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Functional programming

June 25th, 2014, 6:05 am

QuoteIndeed, it's a good idea to use consistent terminology; thankfully, GP is an unambiguous, well-defined term (significantly predating the appearance of "C#" -- it's not clear what its importance or relevance is here):It was meant as a concrete example of a language that supports generics. Eiffel is another example. C# is important IMO. FP is for functions and is generics-agnostic? Maybe you are thinking about polymorphism?
Last edited by Cuchulainn on June 24th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
VivienB
Posts: 25
Joined: August 6th, 2012, 3:32 pm

Functional programming

June 25th, 2014, 7:30 am

QuoteOriginally posted by: CuchulainnQuoteFor the PDE, there is also all the low level part that deals with matrix operations, and that must IMO use imperative programmingSure. Are the underlying types generic. i.e. Matrix<T>?I don't think we need generics here, only float matrix operations are usefull (and algorithms needed only work on floats).
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Functional programming

June 25th, 2014, 8:12 am

QuoteOriginally posted by: VivienBQuoteOriginally posted by: CuchulainnQuoteFor the PDE, there is also all the low level part that deals with matrix operations, and that must IMO use imperative programmingSure. Are the underlying types generic. i.e. Matrix<T>?I don't think we need generics here, only float matrix operations are usefull (and algorithms needed only work on floats).Not necessarily; it depends.In some applications you could have 3 versions of a matrix1. int and very fast2. float and fast3. double and less fast.In CAD (fast collision detection) and computer graphics screen coordinates are short; and not to mention polar coordinate systems and matrix<Complex> (!!)And for the Keller box scheme we need block tridiagonal matrices. (nested matrices). Not to mention matrices over polynomial domains. etc.
Last edited by Cuchulainn on June 24th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
VivienB
Posts: 25
Joined: August 6th, 2012, 3:32 pm

Functional programming

June 25th, 2014, 8:37 am

QuoteOriginally posted by: Cuchulainn1. int and very fastThe needed operations are not defined on int (eg matrix inversion).QuoteOriginally posted by: Cuchulainn2. float and fast3. double and less fast.How big would be the time difference between float matrix operations (matrix/vector multiplication, linear system solving) and double matrix operations?
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Functional programming

June 25th, 2014, 8:57 am

(double)
Last edited by Cuchulainn on June 24th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Functional programming

June 25th, 2014, 9:41 am

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: VivienBQuoteOriginally posted by: Cuchulainn1. int and very fastThe needed operations are not defined on int (eg matrix inversion).QuoteOriginally posted by: Cuchulainn2. float and fast3. double and less fast.How big would be the time difference between float matrix operations (matrix/vector multiplication, linear system solving) and double matrix operations?No one does matrix inversion in this sense these days, just + and *. We probably need to be careful with /. But maybeThis is a mathematical issue, not a s/w issue.It would be easy to benchmark float v double. And AFAIR GPUs only had float at one stage.Even if certain use cases proved inconclusive would not be a reason not to use generic matrices.
 
User avatar
katastrofa
Posts: 7440
Joined: August 16th, 2007, 5:36 am
Location: Alpha Centauri

Functional programming

June 25th, 2014, 10:41 am

Matrix<double> vs Matrix<complex<double>>
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Functional programming

June 25th, 2014, 1:20 pm

QuoteOriginally posted by: katastrofaMatrix<double> vs Matrix<complex<double>>That's a nice example. Both double and complex<double> are fields with *, +, -, /So LU<T> will work with both types, and more. Gaussian integers are std::complex<long>.
Last edited by Cuchulainn on June 24th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Traden4Alpha
Posts: 3300
Joined: September 20th, 2002, 8:30 pm

Functional programming

June 25th, 2014, 10:50 pm

From a Generics stand-point, the elements of Matrix<T> can be anything that admits the usual arithemetic operations. Thus, one could have a Matrix of matrices.There's also various Matrix variants such as symmetric, triangular, sparse that could be generic across a wide range of applications and implementations.
 
User avatar
Cuchulainn
Posts: 20255
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Functional programming

June 26th, 2014, 8:51 am

QuoteOriginally 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++?
Last edited by Cuchulainn on June 25th, 2014, 10:00 pm, edited 1 time in total.