• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[section:main_faq Boost.Math Frequently Asked Questions (FAQs)]
2
3# ['I'm a FORTRAN/NAG/SPSS/SAS/Cephes/MathCad/R user
4and I don't see where the functions like dnorm(mean, sd) are in Boost.Math?]
5
6  Nearly all are provided, and many more like mean, skewness, quantiles, complements ...
7but Boost.Math makes full use of C++, and it looks a bit different.
8But do not panic! See section on construction and the many examples.
9Briefly, the distribution is constructed with the parameters (like location and scale)
10(things after the | in representation like P(X=k|n, p) or ; in a common representation of pdf f(x; [mu][sigma][super 2]).
11Functions like pdf, cdf are called with the name of that distribution and the random variate often called x or k.
12For example, `normal my_norm(0, 1);  pdf(my_norm, 2.0);`
13
14# I'm a user of [@http://support.sas.com/rnd/app/da/new/probabilityfunctions.html New SAS Functions for Computing Probabilities].
15
16  You will find the interface more familiar, but to be able to select a distribution (perhaps using a string)
17see the Extras/Future Directions section,
18and /boost/libs/math/dot_net_example/boost_math.cpp for an example that is used to create a C# (C sharp) utility
19(that you might also find useful):
20see [@http://sourceforge.net/projects/distexplorer/ Statistical Distribution Explorer].
21
22# ['I'm allergic to reading manuals and prefer to learn from examples.]
23
24  Fear not - you are not alone! Many examples are available for functions and distributions.
25Some are referenced directly from the text.  Others can be found at `\boost_latest_release\libs\math\example`,
26for example
27If you are a Visual Studio user, you should be able to create projects from each of these,
28making sure that the Boost library is in the include directories list (there are usually NO libraries that must be built).
29
30# ['How do I make sure that the Boost library is in the Visual Studio include directories list?]
31
32  You can add an include path, for example,  your Boost place /boost-latest_release,
33for example `X:/boost_1_70_0/` if you have a separate partition X for Boost releases.
34Or you can use an environment variable BOOST_ROOT set to your Boost place, and include that.
35Visual Studio before 2010 provided Tools, Options, VC++ Directories to control directories:
36Visual Studio 2010 instead provides property sheets to assist.
37You may find it convenient to create a new one adding \boost-latest_release;
38to the existing include items in $(IncludePath).
39
40# ['I'm a FORTRAN/NAG/SPSS/SAS/Cephes/MathCad/R user and
41I don't see where the properties like mean, median, mode, variance, skewness of distributions are in Boost.Math?]
42
43  They are all available (if defined for the parameters with which you constructed the distribution) via __usual_accessors.
44
45# ['I am a C programmer.  Can I user Boost.Math with C?]
46
47  Yes you can, including all the special functions, and TR1 functions like isnan.
48They appear as C functions, by being declared as "extern C".
49
50# ['I am a C# (Basic? F# FORTRAN?  Other CLI?) programmer.  Can I use Boost.Math with C#? (or ...)?]
51
52  Yes you can, including all the special functions, and TR1 functions like isnan.
53But you [*must build the Boost.Math as a dynamic library (.dll) and compile with the /CLI option].
54See the boost/math/dot_net_example folder which contains an example that
55builds a simple statistical distribution app with a GUI.
56See [@http://sourceforge.net/projects/distexplorer/ Statistical Distribution Explorer]
57
58# ['What these "policies" things for?]
59
60  Policies are a powerful (if necessarily complex) fine-grain mechanism that
61allow you to customise the behaviour of the Boost.Math library according to your precise needs.
62See __policy_section.  But if, very probably, the default behaviour suits you, you don't need to know more.
63
64# ['I am a C user and expect to see global C-style`::errno` set for overflow/errors etc?]
65
66  You can achieve what you want - see __error_policy and __user_error_handling and many examples.
67
68# ['I am a C user and expect to silently return a max value for overflow?]
69
70  You (and C++ users too) can return whatever you want on overflow
71- see  __overflow_error and __error_policy and several examples.
72
73# ['I don't want any error message for overflow etc?]
74
75  You can control exactly what happens for all the abnormal conditions, including the values returned.
76See __domain_error, __overflow_error __error_policy __user_error_handling etc and examples.
77
78# ['My environment doesn't allow and/or I don't want exceptions.  Can I still user Boost.Math?]
79
80  Yes but you must customise the error handling: see __user_error_handling and __changing_policy_defaults .
81
82# ['The docs are several hundreds of pages long! Can I read the docs off-line or on paper?]
83
84  Yes - you can download the Boost current release of most documentation
85as a zip of pdfs (including Boost.Math) from Sourceforge, for example
86[@https://sourceforge.net/projects/boost/files/boost-docs/1.45.0/boost_pdf_1_45_0.tar.gz/download].
87And you can print any pages you need (or even print all pages - but be warned that there are several hundred!).
88Both html and pdf versions are highly hyperlinked.
89The entire Boost.Math pdf can be searched with Adobe Reader, Edit, Find ...
90This can often find what you seek, a partial substitute for a full index.
91
92# ['I want a compact version for an embedded application. Can I use float precision?]
93
94  Yes - by selecting  RealType template parameter as float:
95for example normal_distribution<float> your_normal(mean, sd);
96(But double may still be used internally, so space saving may be less that you hope for).
97You can also change the promotion policy, but accuracy might be much reduced.
98
99# ['I seem to get somewhat different results compared to other programs.  Why?]
100
101  We hope Boost.Math to be more accurate: our priority is accuracy (over speed).
102See the section on accuracy. But for evaluations that require iterations
103there are parameters which can change the required accuracy (see __policy_section).
104You might be able to squeeze a little more (or less) accuracy at the cost of runtime.
105
106# ['Will my program run more slowly compared to other math functions and statistical libraries?]
107
108  Probably, thought not always, and not by too much:  our priority is accuracy.
109For most functions, making sure you have the latest compiler version with all optimisations switched on is the key to speed.
110For evaluations that require iteration, you may be able to gain a little more speed at the expense of accuracy.
111See detailed suggestions and results on __performance.
112
113# ['How do I handle infinity and NaNs portably?]
114
115  See __fp_facets for Facets for Floating-Point Infinities and NaNs.
116
117# ['Where are the pre-built libraries?]
118
119  Good news - you probably don't need any! - just `#include <boost/`['math/distribution_you_want>].
120But in the unlikely event that you do, see __building.
121
122# ['I don't see the function or distribution that I want.]
123
124  You could try an email to ask the authors - but no promises!
125
126# ['I need more decimal digits for values/computations.]
127
128  You can use Boost.Math with __multiprecision: typically
129__cpp_dec_float is a useful user-defined type to provide a fixed number of decimal digits, usually 50 or 100.
130
131# Why can't I write something really simple like `cpp_int one(1); cpp_dec_float_50 two(2); one * two;`
132
133  Because `cpp_int` might be bigger than `cpp_dec_float can hold`, so you must make an [*explicit] conversion.
134See [@http://svn.boost.org/svn/boost/trunk/libs/multiprecision/doc/html/boost_multiprecision/intro.html mixed multiprecision arithmetic]
135and [@http://svn.boost.org/svn/boost/trunk/libs/multiprecision/doc/html/boost_multiprecision/tut/conversions.html conversion].
136
137# ['How do I choose between Boost.Multiprecision cpp_bin_50 and cpp_dec_50?]
138
139  Unless you have a specific reason to choose `cpp_dec_`, then the default choice should be `cpp_bin_`, for example using the convenience `typedefs` like
140`boost::multiprecision::cpp_bin_50` or `boost::multiprecision::cpp_bin_100`.
141
142  In general, both work well and give the same results and at roughly the same speed with `cpp_dec_50` sometimes faster.
143
144  cpp_dec_ was developed first paving the way for cpp_bin_. cpp_dec_ has several guard digits and is not rounded at all, using 'brute force' to get the promised number of decimal digits correct,
145but making it difficult to reason about precision and computational uncertainty, for example
146see [*https://svn.boost.org/trac10/ticket/12133].
147It also has a fast but imprecise division operator giving surprising results sometimes,
148see [*https://svn.boost.org/trac10/ticket/11178].
149
150  cpp_bin_ is correctly/exactly rounded making it possible to reason about both the precision and rounding of the results.
151
152#['How do I see or report bugs and features, and request new functions?]
153
154  Currently open bug reports can be viewed
155  [@https://github.com/boostorg/math/issues here] on GITHUB.
156
157  All old bug reports including closed ones can be viewed on Trac (now read-only)
158  [@https://svn.boost.org/trac/boost/query?status=assigned&status=closed&status=new&status=reopened&component=math&col=id&col=summary&col=status&col=type&col=milestone&col=component&order=priority here]
159  and more recent issues on GIThub [@https://github.com/boostorg/math/issues?utf8=%E2%9C%93&q=is%3Aissue here].
160
161#[' How can I tell if my compiler will work with Boost.Math?]
162
163You should start by assuming that your compiler/platform *will* compile, even if it only supports a C++03 standard.
164
165Boost in general does *not* 'support' a particular C++ standard or compiler or platform.
166Each library has its own requirements, and for Boost.Math, each individual function or distribution
167or tool may have different requirements and may or may not work on any particular compiler.
168
169So the short answer is to try it and see what works for you.
170
171Some recent functions are written to require more recent standards, even perhaps not-yet-standardized features.
172Some clues about requirements can be gleaned from tests and examples (see jamfiles) and notes on requirements in documentation.
173You can refer to the [@https://www.boost.org/development/tests/develop/developer/math.html Boost Test Matrix] to see the
174current results for Boost.Math tests of many compilers on many platforms.
175But bear in mind that the testing or demonstration code may use C++11 or higher features like
176`std::numeric_limits<>max_digits10`, `auto`, `lambdas ...` for convenience;
177these may not be needed for your application.
178
179[endsect] [/section:faq Frequently Asked Questions]
180
181[/
182  Copyright 2010, 2012 John Maddock and Paul A. Bristow.
183  Distributed under the Boost Software License, Version 1.0.
184  (See accompanying file LICENSE_1_0.txt or copy at
185  http://www.boost.org/LICENSE_1_0.txt).
186]
187
188