manybody/tools.hpp File Reference

Some mathematical and other tools. More...

#include <string>
#include <sstream>
#include <cmath>
#include <vector>

Include dependency graph for tools.hpp:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string format (double x, int prec=16)
 Simple function to format a double with a given precision. Useful if we don't want to mess with, e.g., cout's settings and produce predictable double-output.
void print_copyright (std::ostream &os)
 Print copyright notice.
std::string move_to (int N)
 Move to position (using ANSI escape seq.).
double lnfact (int n)
 Compute ln(n!).
double fact (int n)
 Compute n!.
double lnbinom (int n, int m)
 Compute log of factorial, ln(n!/m!/(n-m)!).
double binom (int n, int m)
 Compute "n ober m" = n!/(m!(n-m)!).
template<typename T>
std::string yesno (const T &x)
 Return string "yes" if true, "no" if false.
template<typename T>
int m1pow (const T &i)
 Compute pow(-1,i). Used a lot!
template<typename T>
sqr (const T &x)
 Compute square of number; used a lot!
template<class T>
size_t count_bits (const T &x)
 Count bits in a word. See http://graphics.stanford.edu/~seander/bithacks.html.
template<typename T>
std::string to_binary (const T &a, const size_t &n=0)
 Compute a binary string version of number.
template<class Vector>
bool general_inc (Vector &alpha, int min, int max, size_t digit=0)
 Simple recursive function to step through multi-indices.
bool more_general_inc (std::vector< int > &alpha, const std::vector< int > &min, const std::vector< int > &max, int digit=0)
 Simple recursive function to step through multi-indices. More general version of general_inc(). Here, the max and min values are different for each index in the multi-index.


Detailed Description

Some mathematical and other tools.

Author:
Simen Kvaal
Date:
6-13-08

Function Documentation

double binom ( int  n,
int  m 
) [inline]

Compute "n ober m" = n!/(m!(n-m)!).

Parameters:
n a number
m a number

Here is the call graph for this function:

double fact ( int  n  )  [inline]

Compute n!.

Parameters:
n number to take factorial of

Here is the call graph for this function:

std::string format ( double  x,
int  prec = 16 
) [inline]

Simple function to format a double with a given precision. Useful if we don't want to mess with, e.g., cout's settings and produce predictable double-output.

Parameters:
x number to write
prec precision

template<class Vector>
bool general_inc ( Vector &  alpha,
int  min,
int  max,
size_t  digit = 0 
) [inline]

Simple recursive function to step through multi-indices.

The template parameter Vector must implement Vector::size() and Vector::operator[]().

Parameters:
alpha Multi-index
min Minimum value of each index
max Maximum value + 1 of each index
digit Which digit to increase. User should not use this; used for recursion.
Returns:
true if alpha = (max-1,max-1,....,max-1) upon entry, such that it wraps around to (min,min,...min); false otherwise.

double lnbinom ( int  n,
int  m 
) [inline]

Compute log of factorial, ln(n!/m!/(n-m)!).

Parameters:
n a number
m a number

Here is the call graph for this function:

double lnfact ( int  n  )  [inline]

Compute ln(n!).

Parameters:
n number to take factorial of

bool more_general_inc ( std::vector< int > &  alpha,
const std::vector< int > &  min,
const std::vector< int > &  max,
int  digit = 0 
) [inline]

Simple recursive function to step through multi-indices. More general version of general_inc(). Here, the max and min values are different for each index in the multi-index.

The template parameter Vector must implement Vector::size() and Vector::operator[]().

Parameters:
alpha Multi-index
min Minimum value of each index
max Maximum value + 1 of each index
digit Which digit to increase. User should not use this; used for recursion.
Returns:
true if alpha = (max[0]-1,max[1]-1,....,max[n]-1) upon entry, such that it wraps around to (min[0],min[1]...,min[n]); false otherwise.

std::string move_to ( int  N  )  [inline]

Move to position (using ANSI escape seq.).

Parameters:
N position on line, should be >=0.

template<typename T>
std::string to_binary ( const T &  a,
const size_t &  n = 0 
)

Compute a binary string version of number.

Parameters:
a Number to convert
n Number of bits to use; n = 0 (default) means all bits.


Generated on Wed Jun 17 11:44:02 2009 for OpenFCI by  doxygen 1.4.7