1

The C++ standard library has type traits such as is_arithmetic is_integral and is_floating_point, but

  • complex numbers are arithmetic but you can't, say, compare them to each other,
  • no is_algebraic_number or has_transcendents
  • no is_well_ordered (ok, you could nitpick and say that all types in "real life" are nicely enumerable by a computer lexicographically by memory representation, so they are well-ordered in that sence, but you know what I mean)
  • etc.

Also, on the function front while there are functions like abs() and fabs() (no general template absolute value function though), it doesn't look like we don't really have distance functions, nor norm functions etc.

So, all in all, it seems the standard library does not equip us very well for algebraic (/ topological) reasoning in code.

My questions are:

  • While there certainly are domain-specific languages in which things are better (I guess Mathmetica's language? Maybe Matlab/Octave symbolics?), is this common among general-purpose programming languages?
  • Are there initiatives or efforts to change this situation, i.e. expand the formal math aspects of the standard library (as opposed to numerics, fast math etc.)?
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Why would you expect the standard library to have the same level of support for mathematical abstractions as purpose-built tools? – Kyle Apr 26 '16 at 18:33
  • @Kyle: Well, I guess because having such traits and functions does not in itself involve "committing" to any data types, or algorithms, etc. Still, if you're telling me that people have just been using/contributing to more special-purpose libraries, that's an answer I guess. – einpoklum Apr 26 '16 at 19:03
  • One obvious reason for the lack of special libraries is the lack of general need/interest for those. Also, with every library you load, you trade off some efficiency. – Matsmath Apr 26 '16 at 20:33
  • @Matsmath: Fair enough - although this is all compile-time stuff, so at run-time you won't lose any efficiency. – einpoklum Apr 26 '16 at 21:10
  • If the formal math aspects of standard libraries were expanded you would encounter the very same kind of limitations soon after. The limitation is not in the features that standard libraries provide but in the very concept of "library" because they are untweakable entities. The limitation is in the boundaries of black boxes because they try to behave as hardware, not as software. – Leandro Caniglia Apr 26 '16 at 23:50
  • 1
    I think this is an important question, especially for generic programming. I increasingly need such an algebraic traits library in C++ and whilst I haven't started yet, I might be able to give you a concrete answer pointing to my own work in the near future. – Jeremy W. Murphy May 01 '16 at 11:50

0 Answers0