diff --git a/eo/contrib/boost/config.hpp b/eo/contrib/boost/config.hpp new file mode 100644 index 000000000..055a27855 --- /dev/null +++ b/eo/contrib/boost/config.hpp @@ -0,0 +1,70 @@ +// Boost config.hpp configuration header file ------------------------------// + +// (C) Copyright John Maddock 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/config for most recent version. + +// Boost config.hpp policy and rationale documentation has been moved to +// http://www.boost.org/libs/config +// +// CAUTION: This file is intended to be completely stable - +// DO NOT MODIFY THIS FILE! +// + +#ifndef BOOST_CONFIG_HPP +#define BOOST_CONFIG_HPP + +// if we don't have a user config, then use the default location: +#if !defined(BOOST_USER_CONFIG) && !defined(BOOST_NO_USER_CONFIG) +# define BOOST_USER_CONFIG +#endif +// include it first: +#ifdef BOOST_USER_CONFIG +# include BOOST_USER_CONFIG +#endif + +// if we don't have a compiler config set, try and find one: +#if !defined(BOOST_COMPILER_CONFIG) && !defined(BOOST_NO_COMPILER_CONFIG) && !defined(BOOST_NO_CONFIG) +# include +#endif +// if we have a compiler config, include it now: +#ifdef BOOST_COMPILER_CONFIG +# include BOOST_COMPILER_CONFIG +#endif + +// if we don't have a std library config set, try and find one: +#if !defined(BOOST_STDLIB_CONFIG) && !defined(BOOST_NO_STDLIB_CONFIG) && !defined(BOOST_NO_CONFIG) +# include +#endif +// if we have a std library config, include it now: +#ifdef BOOST_STDLIB_CONFIG +# include BOOST_STDLIB_CONFIG +#endif + +// if we don't have a platform config set, try and find one: +#if !defined(BOOST_PLATFORM_CONFIG) && !defined(BOOST_NO_PLATFORM_CONFIG) && !defined(BOOST_NO_CONFIG) +# include +#endif +// if we have a platform config, include it now: +#ifdef BOOST_PLATFORM_CONFIG +# include BOOST_PLATFORM_CONFIG +#endif + +// get config suffix code: +#include + +#endif // BOOST_CONFIG_HPP + + + + + + + + + + + diff --git a/eo/contrib/boost/config/abi_prefix.hpp b/eo/contrib/boost/config/abi_prefix.hpp new file mode 100644 index 000000000..1733dc036 --- /dev/null +++ b/eo/contrib/boost/config/abi_prefix.hpp @@ -0,0 +1,20 @@ +// abi_prefix header -------------------------------------------------------// + +// © Copyright John Maddock 2003 + +// Use, modification and distribution are subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt). + +#ifndef BOOST_CONFIG_ABI_PREFIX_HPP +# define BOOST_CONFIG_ABI_PREFIX_HPP +#else +# error double inclusion of header boost/config/abi_prefix.hpp is an error +#endif + +#include + +// this must occur after all other includes and before any code appears: +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif diff --git a/eo/contrib/boost/config/abi_suffix.hpp b/eo/contrib/boost/config/abi_suffix.hpp new file mode 100644 index 000000000..6339da631 --- /dev/null +++ b/eo/contrib/boost/config/abi_suffix.hpp @@ -0,0 +1,23 @@ +// abi_sufffix header -------------------------------------------------------// + +// © Copyright John Maddock 2003 + +// Use, modification and distribution are subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt). + +// This header should be #included AFTER code that was preceded by a #include +// . + +#ifndef BOOST_CONFIG_ABI_PREFIX_HPP +# error Header boost/config/abi_prefix.hpp must only be used after boost/config/abi_prefix.hpp +#else +# undef BOOST_CONFIG_ABI_PREFIX_HPP +#endif + +// the suffix header occurs after all of our code: +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + + diff --git a/eo/contrib/boost/config/auto_link.hpp b/eo/contrib/boost/config/auto_link.hpp new file mode 100644 index 000000000..0c36f7b0f --- /dev/null +++ b/eo/contrib/boost/config/auto_link.hpp @@ -0,0 +1,354 @@ +// (C) Copyright John Maddock 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + /* + * LOCATION: see http://www.boost.org for most recent version. + * FILE auto_link.hpp + * VERSION see + * DESCRIPTION: Automatic library inclusion for Borland/Microsoft compilers. + */ + +/************************************************************************* + +USAGE: +~~~~~~ + +Before including this header you must define one or more of define the following macros: + +BOOST_LIB_NAME: Required: A string containing the basename of the library, + for example boost_regex. +BOOST_LIB_TOOLSET: Optional: the base name of the toolset. +BOOST_DYN_LINK: Optional: when set link to dll rather than static library. +BOOST_LIB_DIAGNOSTIC: Optional: when set the header will print out the name + of the library selected (useful for debugging). +BOOST_AUTO_LINK_NOMANGLE: Specifies that we should link to BOOST_LIB_NAME.lib, + rather than a mangled-name version. + +These macros will be undef'ed at the end of the header, further this header +has no include guards - so be sure to include it only once from your library! + +Algorithm: +~~~~~~~~~~ + +Libraries for Borland and Microsoft compilers are automatically +selected here, the name of the lib is selected according to the following +formula: + +BOOST_LIB_PREFIX + + BOOST_LIB_NAME + + "_" + + BOOST_LIB_TOOLSET + + BOOST_LIB_THREAD_OPT + + BOOST_LIB_RT_OPT + "-" + + BOOST_LIB_VERSION + +These are defined as: + +BOOST_LIB_PREFIX: "lib" for static libraries otherwise "". + +BOOST_LIB_NAME: The base name of the lib ( for example boost_regex). + +BOOST_LIB_TOOLSET: The compiler toolset name (vc6, vc7, bcb5 etc). + +BOOST_LIB_THREAD_OPT: "-mt" for multithread builds, otherwise nothing. + +BOOST_LIB_RT_OPT: A suffix that indicates the runtime library used, + contains one or more of the following letters after + a hiphen: + + s static runtime (dynamic if not present). + d debug build (release if not present). + g debug/diagnostic runtime (release if not present). + p STLPort Build. + +BOOST_LIB_VERSION: The Boost version, in the form x_y, for Boost version x.y. + + +***************************************************************************/ + +#ifdef __cplusplus +# ifndef BOOST_CONFIG_HPP +# include +# endif +#elif defined(_MSC_VER) && !defined(__MWERKS__) && !defined(__EDG_VERSION__) +// +// C language compatability (no, honestly) +// +# define BOOST_MSVC _MSC_VER +# define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X) +# define BOOST_DO_STRINGIZE(X) #X +#endif +// +// Only include what follows for known and supported compilers: +// +#if defined(BOOST_MSVC) \ + || defined(__BORLANDC__) \ + || (defined(__MWERKS__) && defined(_WIN32) && (__MWERKS__ >= 0x3000)) \ + || (defined(__ICL) && defined(_MSC_EXTENSIONS) && (_MSC_VER >= 1200)) + +#ifndef BOOST_VERSION_HPP +# include +#endif + +#ifndef BOOST_LIB_NAME +# error "Macro BOOST_LIB_NAME not set (internal error)" +#endif + +// +// error check: +// +#if defined(__MSVC_RUNTIME_CHECKS) && !defined(_DEBUG) +# pragma message("Using the /RTC option without specifying a debug runtime will lead to linker errors") +# pragma message("Hint: go to the code generation options and switch to one of the debugging runtimes") +# error "Incompatible build options" +#endif +// +// select toolset if not defined already: +// +#ifndef BOOST_LIB_TOOLSET +#if defined(BOOST_MSVC) && (BOOST_MSVC == 1200) + + // vc6: +# define BOOST_LIB_TOOLSET "vc6" + +#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300) + + // vc7: +# define BOOST_LIB_TOOLSET "vc7" + +#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1310) + + // vc71: +# define BOOST_LIB_TOOLSET "vc71" + +#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1400) + + // vc80: +# define BOOST_LIB_TOOLSET "vc80" + +#elif defined(__BORLANDC__) + + // CBuilder 6: +# define BOOST_LIB_TOOLSET "bcb" + +#elif defined(__ICL) + + // Intel C++, no version number: +# define BOOST_LIB_TOOLSET "iw" + +#elif defined(__MWERKS__) && (__MWERKS__ <= 0x31FF ) + + // Metrowerks CodeWarrior 8.x +# define BOOST_LIB_TOOLSET "cw8" + +#elif defined(__MWERKS__) && (__MWERKS__ <= 0x32FF ) + + // Metrowerks CodeWarrior 9.x +# define BOOST_LIB_TOOLSET "cw9" + +#endif +#endif // BOOST_LIB_TOOLSET + +// +// select thread opt: +// +#if defined(_MT) || defined(__MT__) +# define BOOST_LIB_THREAD_OPT "-mt" +#else +# define BOOST_LIB_THREAD_OPT +#endif + +#if defined(_MSC_VER) || defined(__MWERKS__) + +# ifdef _DLL + +# if (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) && (defined(_STLP_OWN_IOSTREAMS) || defined(__STL_OWN_IOSTREAMS)) + +# if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG)) +# define BOOST_LIB_RT_OPT "-gdp" +# elif defined(_DEBUG) +# define BOOST_LIB_RT_OPT "-gdp" +# pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1") +# error "Build options aren't compatible with pre-built libraries" +# else +# define BOOST_LIB_RT_OPT "-p" +# endif + +# elif defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) + +# if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG)) +# define BOOST_LIB_RT_OPT "-gdpn" +# elif defined(_DEBUG) +# define BOOST_LIB_RT_OPT "-gdpn" +# pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1") +# error "Build options aren't compatible with pre-built libraries" +# else +# define BOOST_LIB_RT_OPT "-pn" +# endif + +# else + +# if defined(_DEBUG) +# define BOOST_LIB_RT_OPT "-gd" +# else +# define BOOST_LIB_RT_OPT +# endif + +# endif + +# else + +# if (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) && (defined(_STLP_OWN_IOSTREAMS) || defined(__STL_OWN_IOSTREAMS)) + +# if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG)) +# define BOOST_LIB_RT_OPT "-sgdp" +# elif defined(_DEBUG) +# define BOOST_LIB_RT_OPT "-sgdp" +# pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1") +# error "Build options aren't compatible with pre-built libraries" +# else +# define BOOST_LIB_RT_OPT "-sp" +# endif + +# elif defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) + +# if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG)) +# define BOOST_LIB_RT_OPT "-sgdpn" +# elif defined(_DEBUG) +# define BOOST_LIB_RT_OPT "-sgdpn" +# pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1") +# error "Build options aren't compatible with pre-built libraries" +# else +# define BOOST_LIB_RT_OPT "-spn" +# endif + +# else + +# if defined(_DEBUG) +# define BOOST_LIB_RT_OPT "-sgd" +# else +# define BOOST_LIB_RT_OPT "-s" +# endif + +# endif + +# endif + +#elif defined(__BORLANDC__) + +// +// figure out whether we want the debug builds or not: +// +#if __BORLANDC__ > 0x561 +#pragma defineonoption BOOST_BORLAND_DEBUG -v +#endif +// +// sanity check: +// +#if defined(__STL_DEBUG) || defined(_STLP_DEBUG) +#error "Pre-built versions of the Boost libraries are not provided in STLPort-debug form" +#endif + +# ifdef _RTLDLL + +# ifdef BOOST_BORLAND_DEBUG +# define BOOST_LIB_RT_OPT "-d" +# else +# define BOOST_LIB_RT_OPT +# endif + +# else + +# ifdef BOOST_BORLAND_DEBUG +# define BOOST_LIB_RT_OPT "-sd" +# else +# define BOOST_LIB_RT_OPT "-s" +# endif + +# endif + +#endif + +// +// select linkage opt: +// +#if (defined(_DLL) || defined(_RTLDLL)) && defined(BOOST_DYN_LINK) +# define BOOST_LIB_PREFIX +#elif defined(BOOST_DYN_LINK) +# error "Mixing a dll boost library with a static runtime is a really bad idea..." +#else +# define BOOST_LIB_PREFIX "lib" +#endif + +// +// now include the lib: +// +#if defined(BOOST_LIB_NAME) \ + && defined(BOOST_LIB_PREFIX) \ + && defined(BOOST_LIB_TOOLSET) \ + && defined(BOOST_LIB_THREAD_OPT) \ + && defined(BOOST_LIB_RT_OPT) \ + && defined(BOOST_LIB_VERSION) + +#ifndef BOOST_AUTO_LINK_NOMANGLE +# pragma comment(lib, BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT "-" BOOST_LIB_VERSION ".lib") +# ifdef BOOST_LIB_DIAGNOSTIC +# pragma message ("Linking to lib file: " BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT "-" BOOST_LIB_VERSION ".lib") +# endif +#else +# pragma comment(lib, BOOST_STRINGIZE(BOOST_LIB_NAME) ".lib") +# ifdef BOOST_LIB_DIAGNOSTIC +# pragma message ("Linking to lib file: " BOOST_STRINGIZE(BOOST_LIB_NAME) ".lib") +# endif +#endif + +#else +# error "some required macros where not defined (internal logic error)." +#endif + + +#endif // _MSC_VER || __BORLANDC__ + +// +// finally undef any macros we may have set: +// +#ifdef BOOST_LIB_PREFIX +# undef BOOST_LIB_PREFIX +#endif +#if defined(BOOST_LIB_NAME) +# undef BOOST_LIB_NAME +#endif +#if defined(BOOST_LIB_TOOLSET) +# undef BOOST_LIB_TOOLSET +#endif +#if defined(BOOST_LIB_THREAD_OPT) +# undef BOOST_LIB_THREAD_OPT +#endif +#if defined(BOOST_LIB_RT_OPT) +# undef BOOST_LIB_RT_OPT +#endif +#if defined(BOOST_LIB_LINK_OPT) +# undef BOOST_LIB_LINK_OPT +#endif +#if defined(BOOST_LIB_DEBUG_OPT) +# undef BOOST_LIB_DEBUG_OPT +#endif +#if defined(BOOST_DYN_LINK) +# undef BOOST_DYN_LINK +#endif +#if defined(BOOST_AUTO_LINK_NOMANGLE) +# undef BOOST_AUTO_LINK_NOMANGLE +#endif + + + + + + + + + + diff --git a/eo/contrib/boost/config/compiler/borland.hpp b/eo/contrib/boost/config/compiler/borland.hpp new file mode 100644 index 000000000..66769bec5 --- /dev/null +++ b/eo/contrib/boost/config/compiler/borland.hpp @@ -0,0 +1,175 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright David Abrahams 2002 - 2003. +// (C) Copyright Aleksey Gurtovoy 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Borland C++ compiler setup: + +// Version 5.0 and below: +# if __BORLANDC__ <= 0x0550 +// Borland C++Builder 4 and 5: +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +# if __BORLANDC__ == 0x0550 +// Borland C++Builder 5, command-line compiler 5.5: +# define BOOST_NO_OPERATORS_IN_NAMESPACE +# endif +# endif + +// Version 5.51 and below: +#if (__BORLANDC__ <= 0x551) +# define BOOST_NO_CV_SPECIALIZATIONS +# define BOOST_NO_CV_VOID_SPECIALIZATIONS +# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# define BOOST_NO_DEDUCED_TYPENAME +// workaround for missing WCHAR_MAX/WCHAR_MIN: +#include +#include +#ifndef WCHAR_MAX +# define WCHAR_MAX 0xffff +#endif +#ifndef WCHAR_MIN +# define WCHAR_MIN 0 +#endif +#endif + +// Version 7.0 (Kylix) and below: +#if (__BORLANDC__ <= 0x570) +# define BOOST_NO_SFINAE +# define BOOST_NO_INTEGRAL_INT64_T +# define BOOST_NO_DEPENDENT_NESTED_DERIVATIONS +# define BOOST_NO_PRIVATE_IN_AGGREGATE +# define BOOST_NO_USING_TEMPLATE +# define BOOST_BCB_PARTIAL_SPECIALIZATION_BUG +# define BOOST_NO_TEMPLATE_TEMPLATES +# define BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS + // we shouldn't really need this - but too many things choke + // without it, this needs more investigation: +# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# define BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL +# define BOOST_NO_IS_ABSTRACT +# ifdef NDEBUG + // fix broken so that Boost.test works: +# include +# undef strcmp +# endif + +// +// new bug in 5.61: +#if (__BORLANDC__ >= 0x561) && (__BORLANDC__ <= 0x570) + // this seems to be needed by the command line compiler, but not the IDE: +# define BOOST_NO_MEMBER_FUNCTION_SPECIALIZATIONS +#endif + +# ifdef _WIN32 +# define BOOST_NO_SWPRINTF +# elif defined(linux) || defined(__linux__) || defined(__linux) + // we should really be able to do without this + // but the wcs* functions aren't imported into std:: +# define BOOST_NO_STDC_NAMESPACE + // _CPPUNWIND doesn't get automatically set for some reason: +# pragma defineonoption BOOST_CPPUNWIND -x +# endif +#endif + +// +// Post 0x561 we have long long and stdint.h: +#if __BORLANDC__ >= 0x561 +# ifndef __NO_LONG_LONG +# define BOOST_HAS_LONG_LONG +# endif + // On non-Win32 platforms let the platform config figure this out: +# ifdef _WIN32 +# define BOOST_HAS_STDINT_H +# endif +#endif + +// Borland C++Builder 6 defaults to using STLPort. If _USE_OLD_RW_STL is +// defined, then we have 0x560 or greater with the Rogue Wave implementation +// which presumably has the std::DBL_MAX bug. +#if ((__BORLANDC__ >= 0x550) && (__BORLANDC__ < 0x560)) || defined(_USE_OLD_RW_STL) +// is partly broken, some macros define symbols that are really in +// namespace std, so you end up having to use illegal constructs like +// std::DBL_MAX, as a fix we'll just include float.h and have done with: +#include +#endif +// +// __int64: +// +#if (__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__) +# define BOOST_HAS_MS_INT64 +#endif +// +// check for exception handling support: +// +#if !defined(_CPPUNWIND) && !defined(BOOST_CPPUNWIND) && !defined(__EXCEPTIONS) +# define BOOST_NO_EXCEPTIONS +#endif +// +// all versions have a : +// +#ifndef __STRICT_ANSI__ +# define BOOST_HAS_DIRENT_H +#endif +// +// all versions support __declspec: +// +#ifndef __STRICT_ANSI__ +# define BOOST_HAS_DECLSPEC +#endif +// +// ABI fixing headers: +// +#if __BORLANDC__ < 0x600 // not implemented for version 6 compiler yet +#ifndef BOOST_ABI_PREFIX +# define BOOST_ABI_PREFIX "boost/config/abi/borland_prefix.hpp" +#endif +#ifndef BOOST_ABI_SUFFIX +# define BOOST_ABI_SUFFIX "boost/config/abi/borland_suffix.hpp" +#endif +#endif +// +// Disable Win32 support in ANSI mode: +// +#if __BORLANDC__ < 0x600 +# pragma defineonoption BOOST_DISABLE_WIN32 -A +#elif defined(__STRICT_ANSI__) +# define BOOST_DISABLE_WIN32 +#endif +// +// MSVC compatibility mode does some nasty things: +// +#if defined(_MSC_VER) && (_MSC_VER <= 1200) +# define BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP +# define BOOST_NO_VOID_RETURNS +#endif + +#define BOOST_COMPILER "Borland C++ version " BOOST_STRINGIZE(__BORLANDC__) + +// +// versions check: +// we don't support Borland prior to version 5.4: +#if __BORLANDC__ < 0x540 +# error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 1536 (Builder X preview): +#if (__BORLANDC__ > 1536) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# else +# pragma message( "Unknown compiler version - please run the configure tests and report the results") +# endif +#endif + + + + + + + + diff --git a/eo/contrib/boost/config/compiler/comeau.hpp b/eo/contrib/boost/config/compiler/comeau.hpp new file mode 100644 index 000000000..1b71008e0 --- /dev/null +++ b/eo/contrib/boost/config/compiler/comeau.hpp @@ -0,0 +1,59 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright Douglas Gregor 2001. +// (C) Copyright Peter Dimov 2001. +// (C) Copyright Aleksey Gurtovoy 2003. +// (C) Copyright Beman Dawes 2003. +// (C) Copyright Jens Maurer 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Comeau C++ compiler setup: + +#include "boost/config/compiler/common_edg.hpp" + +#if (__COMO_VERSION__ <= 4245) + +# if defined(_MSC_VER) && _MSC_VER <= 1300 +# if _MSC_VER > 100 + // only set this in non-strict mode: +# define BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP +# endif +# endif + +// Void returns don't work when emulating VC 6 (Peter Dimov) + +# if defined(_MSC_VER) && (_MSC_VER == 1200) +# define BOOST_NO_VOID_RETURNS +# endif + +#endif // version 4245 + +// +// enable __int64 support in VC emulation mode +// +# if defined(_MSC_VER) && (_MSC_VER >= 1200) +# define BOOST_HAS_MS_INT64 +# endif + +#define BOOST_COMPILER "Comeau compiler version " BOOST_STRINGIZE(__COMO_VERSION__) + +// +// versions check: +// we don't know Comeau prior to version 4245: +#if __COMO_VERSION__ < 4245 +# error "Compiler not configured - please reconfigure" +#endif +// +// last known and checked version is 4245: +#if (__COMO_VERSION__ > 4245) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + + + diff --git a/eo/contrib/boost/config/compiler/common_edg.hpp b/eo/contrib/boost/config/compiler/common_edg.hpp new file mode 100644 index 000000000..0443be1ae --- /dev/null +++ b/eo/contrib/boost/config/compiler/common_edg.hpp @@ -0,0 +1,62 @@ +// (C) Copyright John Maddock 2001 - 2002. +// (C) Copyright Jens Maurer 2001. +// (C) Copyright David Abrahams 2002. +// (C) Copyright Aleksey Gurtovoy 2002. +// (C) Copyright Markus Schoepflin 2005. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// +// Options common to all edg based compilers. +// +// This is included from within the individual compiler mini-configs. + +#ifndef __EDG_VERSION__ +# error This file requires that __EDG_VERSION__ be defined. +#endif + +#if (__EDG_VERSION__ <= 238) +# define BOOST_NO_INTEGRAL_INT64_T +# define BOOST_NO_SFINAE +#endif + +#if (__EDG_VERSION__ <= 240) +# define BOOST_NO_VOID_RETURNS +#endif + +#if (__EDG_VERSION__ <= 241) && !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) +# define BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP +#endif + +#if (__EDG_VERSION__ <= 244) && !defined(BOOST_NO_TEMPLATE_TEMPLATES) +# define BOOST_NO_TEMPLATE_TEMPLATES +#endif + +#if (__EDG_VERSION__ < 300) && !defined(BOOST_NO_IS_ABSTRACT) +# define BOOST_NO_IS_ABSTRACT +#endif + +#if (__EDG_VERSION__ <= 303) && !defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) +# define BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL +#endif + +// See also kai.hpp which checks a Kai-specific symbol for EH +# if !defined(__KCC) && !defined(__EXCEPTIONS) +# define BOOST_NO_EXCEPTIONS +# endif + +# if !defined(__NO_LONG_LONG) +# define BOOST_HAS_LONG_LONG +# endif + +#ifdef c_plusplus +// EDG has "long long" in non-strict mode +// However, some libraries have insufficient "long long" support +// #define BOOST_HAS_LONG_LONG +#endif + + + diff --git a/eo/contrib/boost/config/compiler/compaq_cxx.hpp b/eo/contrib/boost/config/compiler/compaq_cxx.hpp new file mode 100644 index 000000000..a52e66a29 --- /dev/null +++ b/eo/contrib/boost/config/compiler/compaq_cxx.hpp @@ -0,0 +1,19 @@ +// (C) Copyright John Maddock 2001 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Dec Alpha True64 C++ compiler setup: + +#define BOOST_COMPILER "Dec Alpha True64 " BOOST_STRINGIZE(__DECCXX_VER) + +#include "boost/config/compiler/common_edg.hpp" + +// +// versions check: +// Nothing to do here? + + + diff --git a/eo/contrib/boost/config/compiler/digitalmars.hpp b/eo/contrib/boost/config/compiler/digitalmars.hpp new file mode 100644 index 000000000..32fc71faf --- /dev/null +++ b/eo/contrib/boost/config/compiler/digitalmars.hpp @@ -0,0 +1,49 @@ +// Copyright (C) Christof Meerwald 2003 +// Copyright (C) Dan Watkins 2003 +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// Digital Mars C++ compiler setup: +#define BOOST_COMPILER __DMC_VERSION_STRING__ + +#define BOOST_HAS_LONG_LONG +#define BOOST_HAS_PRAGMA_ONCE + +#if (__DMC__ <= 0x833) +#define BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL +#define BOOST_NO_TEMPLATE_TEMPLATES +#define BOOST_NEEDS_TOKEN_PASTING_OP_FOR_TOKENS_JUXTAPOSING +#define BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS +#define BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS +#endif +#if (__DMC__ <= 0x840) || !defined(BOOST_STRICT_CONFIG) +#define BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS +#define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +#define BOOST_NO_OPERATORS_IN_NAMESPACE +#define BOOST_NO_UNREACHABLE_RETURN_DETECTION +#define BOOST_NO_SFINAE +#define BOOST_NO_USING_TEMPLATE +#define BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL +#endif + +// +// has macros: +#if (__DMC__ >= 0x840) +#define BOOST_HAS_DIRENT_H +#define BOOST_HAS_STDINT_H +#define BOOST_HAS_WINTHREADS +#endif + + +// check for exception handling support: +#ifndef _CPPUNWIND +# define BOOST_NO_EXCEPTIONS +#endif + +#if (__DMC__ < 0x840) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif diff --git a/eo/contrib/boost/config/compiler/gcc.hpp b/eo/contrib/boost/config/compiler/gcc.hpp new file mode 100644 index 000000000..d94b16b76 --- /dev/null +++ b/eo/contrib/boost/config/compiler/gcc.hpp @@ -0,0 +1,105 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Darin Adler 2001 - 2002. +// (C) Copyright Jens Maurer 2001 - 2002. +// (C) Copyright Beman Dawes 2001 - 2003. +// (C) Copyright Douglas Gregor 2002. +// (C) Copyright David Abrahams 2002 - 2003. +// (C) Copyright Synge Todo 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// GNU C++ compiler setup: + +#if __GNUC__ < 3 +# if __GNUC_MINOR__ == 91 + // egcs 1.1 won't parse shared_ptr.hpp without this: +# define BOOST_NO_AUTO_PTR +# endif +# if __GNUC_MINOR__ < 95 + // + // Prior to gcc 2.95 member templates only partly + // work - define BOOST_MSVC6_MEMBER_TEMPLATES + // instead since inline member templates mostly work. + // +# define BOOST_NO_MEMBER_TEMPLATES +# if __GNUC_MINOR__ >= 9 +# define BOOST_MSVC6_MEMBER_TEMPLATES +# endif +# endif + +# if __GNUC_MINOR__ < 96 +# define BOOST_NO_SFINAE +# endif + +# if __GNUC_MINOR__ <= 97 +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +# define BOOST_NO_OPERATORS_IN_NAMESPACE +# endif + +# define BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE +# define BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL +# define BOOST_NO_IS_ABSTRACT +#elif __GNUC__ == 3 + // + // gcc-3.x problems: + // + // Bug specific to gcc 3.1 and 3.2: + // +# if ((__GNUC_MINOR__ == 1) || (__GNUC_MINOR__ == 2)) +# define BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS +# endif +# if __GNUC_MINOR__ < 4 +# define BOOST_NO_IS_ABSTRACT +# endif +#endif + +#ifndef __EXCEPTIONS +# define BOOST_NO_EXCEPTIONS +#endif + + +// +// Threading support: Turn this on unconditionally here (except for +// those platforms where we can know for sure). It will get turned off again +// later if no threading API is detected. +// +#if !defined(__MINGW32__) && !defined(linux) && !defined(__linux) && !defined(__linux__) +# define BOOST_HAS_THREADS +#endif + +// +// gcc has "long long" +// +#define BOOST_HAS_LONG_LONG + +// +// gcc implements the named return value optimization since version 3.1 +// +#if __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) +#define BOOST_HAS_NRVO +#endif + +#define BOOST_COMPILER "GNU C++ version " __VERSION__ + +// +// versions check: +// we don't know gcc prior to version 2.90: +#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 90) +# error "Compiler not configured - please reconfigure" +#endif +// +// last known and checked version is 4.0 (Pre-release): +#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0)) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# else +// we don't emit warnings here anymore since there are no defect macros defined for +// gcc post 3.4, so any failures are gcc regressions... +//# warning "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + diff --git a/eo/contrib/boost/config/compiler/greenhills.hpp b/eo/contrib/boost/config/compiler/greenhills.hpp new file mode 100644 index 000000000..038b6b2b5 --- /dev/null +++ b/eo/contrib/boost/config/compiler/greenhills.hpp @@ -0,0 +1,28 @@ +// (C) Copyright John Maddock 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Greenhills C++ compiler setup: + +#define BOOST_COMPILER "Greenhills C++ version " BOOST_STRINGIZE(__ghs) + +#include "boost/config/compiler/common_edg.hpp" + +// +// versions check: +// we don't support Greenhills prior to version 0: +#if __ghs < 0 +# error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 0: +#if (__ghs > 0) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + diff --git a/eo/contrib/boost/config/compiler/hp_acc.hpp b/eo/contrib/boost/config/compiler/hp_acc.hpp new file mode 100644 index 000000000..3d05ba563 --- /dev/null +++ b/eo/contrib/boost/config/compiler/hp_acc.hpp @@ -0,0 +1,70 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2001 - 2003. +// (C) Copyright Aleksey Gurtovoy 2002. +// (C) Copyright David Abrahams 2002 - 2003. +// (C) Copyright Toon Knapen 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// HP aCC C++ compiler setup: + +#if (__HP_aCC <= 33100) +# define BOOST_NO_INTEGRAL_INT64_T +# define BOOST_NO_OPERATORS_IN_NAMESPACE +# if !defined(_NAMESPACE_STD) +# define BOOST_NO_STD_LOCALE +# define BOOST_NO_STRINGSTREAM +# endif +#endif + +#if (__HP_aCC <= 33300) +// member templates are sufficiently broken that we disable them for now +# define BOOST_NO_MEMBER_TEMPLATES +# define BOOST_NO_DEPENDENT_NESTED_DERIVATIONS +# define BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE +#endif + +#if (__HP_aCC <= 33900) || !defined(BOOST_STRICT_CONFIG) +# define BOOST_NO_UNREACHABLE_RETURN_DETECTION +# define BOOST_NO_TEMPLATE_TEMPLATES +# define BOOST_NO_SWPRINTF +# define BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS +# define BOOST_NO_IS_ABSTRACT +// std lib config should set this one already: +//# define BOOST_NO_STD_ALLOCATOR +#endif + +// optional features rather than defects: +#if (__HP_aCC >= 33900) +# define BOOST_HAS_LONG_LONG +# define BOOST_HAS_PARTIAL_STD_ALLOCATOR +#endif + +#if (__HP_aCC >= 50000 ) && (__HP_aCC <= 53800 ) || (__HP_aCC < 31300 ) +# define BOOST_NO_MEMBER_TEMPLATE_KEYWORD +#endif + +#define BOOST_NO_MEMBER_TEMPLATE_FRIENDS + +#define BOOST_COMPILER "HP aCC version " BOOST_STRINGIZE(__HP_aCC) + +// +// versions check: +// we don't support HP aCC prior to version 0: +#if __HP_aCC < 33000 +# error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 0: +#if (__HP_aCC > 53800) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + + + diff --git a/eo/contrib/boost/config/compiler/intel.hpp b/eo/contrib/boost/config/compiler/intel.hpp new file mode 100644 index 000000000..652557766 --- /dev/null +++ b/eo/contrib/boost/config/compiler/intel.hpp @@ -0,0 +1,146 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright Peter Dimov 2001. +// (C) Copyright Jens Maurer 2001. +// (C) Copyright David Abrahams 2002 - 2003. +// (C) Copyright Aleksey Gurtovoy 2002 - 2003. +// (C) Copyright Guillaume Melquiond 2002 - 2003. +// (C) Copyright Beman Dawes 2003. +// (C) Copyright Martin Wille 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Intel compiler setup: + +#include "boost/config/compiler/common_edg.hpp" + +#if defined(__INTEL_COMPILER) +# define BOOST_INTEL_CXX_VERSION __INTEL_COMPILER +#elif defined(__ICL) +# define BOOST_INTEL_CXX_VERSION __ICL +#elif defined(__ICC) +# define BOOST_INTEL_CXX_VERSION __ICC +#elif defined(__ECC) +# define BOOST_INTEL_CXX_VERSION __ECC +#endif + +#define BOOST_COMPILER "Intel C++ version " BOOST_STRINGIZE(BOOST_INTEL_CXX_VERSION) +#define BOOST_INTEL BOOST_INTEL_CXX_VERSION + +#if defined(_WIN32) || defined(_WIN64) +# define BOOST_INTEL_WIN BOOST_INTEL +#else +# define BOOST_INTEL_LINUX BOOST_INTEL +#endif + +#if (BOOST_INTEL_CXX_VERSION <= 500) && defined(_MSC_VER) +# define BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS +# define BOOST_NO_TEMPLATE_TEMPLATES +#endif + +#if (BOOST_INTEL_CXX_VERSION <= 600) + +# if defined(_MSC_VER) && (_MSC_VER <= 1300) // added check for <= VC 7 (Peter Dimov) + +// Boost libraries assume strong standard conformance unless otherwise +// indicated by a config macro. As configured by Intel, the EDG front-end +// requires certain compiler options be set to achieve that strong conformance. +// Particularly /Qoption,c,--arg_dep_lookup (reported by Kirk Klobe & Thomas Witt) +// and /Zc:wchar_t,forScope. See boost-root/tools/build/intel-win32-tools.jam for +// details as they apply to particular versions of the compiler. When the +// compiler does not predefine a macro indicating if an option has been set, +// this config file simply assumes the option has been set. +// Thus BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP will not be defined, even if +// the compiler option is not enabled. + +# define BOOST_NO_SWPRINTF +# endif + +// Void returns, 64 bit integrals don't work when emulating VC 6 (Peter Dimov) + +# if defined(_MSC_VER) && (_MSC_VER <= 1200) +# define BOOST_NO_VOID_RETURNS +# define BOOST_NO_INTEGRAL_INT64_T +# endif + +#endif + +#if (BOOST_INTEL_CXX_VERSION <= 710) && defined(_WIN32) +# define BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS +#endif + +// See http://aspn.activestate.com/ASPN/Mail/Message/boost/1614864 +#if BOOST_INTEL_CXX_VERSION < 600 +# define BOOST_NO_INTRINSIC_WCHAR_T +#else +// We should test the macro _WCHAR_T_DEFINED to check if the compiler +// supports wchar_t natively. *BUT* there is a problem here: the standard +// headers define this macro if they typedef wchar_t. Anyway, we're lucky +// because they define it without a value, while Intel C++ defines it +// to 1. So we can check its value to see if the macro was defined natively +// or not. +// Under UNIX, the situation is exactly the same, but the macro _WCHAR_T +// is used instead. +# if ((_WCHAR_T_DEFINED + 0) == 0) && ((_WCHAR_T + 0) == 0) +# define BOOST_NO_INTRINSIC_WCHAR_T +# endif +#endif + +// +// Verify that we have actually got BOOST_NO_INTRINSIC_WCHAR_T +// set correctly, if we don't do this now, we will get errors later +// in type_traits code among other things, getting this correct +// for the Intel compiler is actually remarkably fragile and tricky: +// +#if defined(BOOST_NO_INTRINSIC_WCHAR_T) +#include +template< typename T > struct assert_no_intrinsic_wchar_t; +template<> struct assert_no_intrinsic_wchar_t { typedef void type; }; +// if you see an error here then you need to unset BOOST_NO_INTRINSIC_WCHAR_T +// where it is defined above: +typedef assert_no_intrinsic_wchar_t::type assert_no_intrinsic_wchar_t_; +#else +template< typename T > struct assert_intrinsic_wchar_t; +template<> struct assert_intrinsic_wchar_t {}; +// if you see an error here then define BOOST_NO_INTRINSIC_WCHAR_T on the command line: +template<> struct assert_intrinsic_wchar_t {}; +#endif + +#if _MSC_VER+0 >= 1000 +# if _MSC_VER >= 1200 +# define BOOST_HAS_MS_INT64 +# endif +# define BOOST_NO_SWPRINTF +#elif defined(_WIN32) +# define BOOST_DISABLE_WIN32 +#endif + +// I checked version 6.0 build 020312Z, it implements the NRVO. +// Correct this as you find out which version of the compiler +// implemented the NRVO first. (Daniel Frey) +#if (BOOST_INTEL_CXX_VERSION >= 600) +# define BOOST_HAS_NRVO +#endif + +// +// versions check: +// we don't support Intel prior to version 5.0: +#if BOOST_INTEL_CXX_VERSION < 500 +# error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version: +#if (BOOST_INTEL_CXX_VERSION > 900) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# elif defined(_MSC_VER) +# pragma message("Unknown compiler version - please run the configure tests and report the results") +# endif +#endif + + + + + diff --git a/eo/contrib/boost/config/compiler/kai.hpp b/eo/contrib/boost/config/compiler/kai.hpp new file mode 100644 index 000000000..de16f1a67 --- /dev/null +++ b/eo/contrib/boost/config/compiler/kai.hpp @@ -0,0 +1,35 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright David Abrahams 2002. +// (C) Copyright Aleksey Gurtovoy 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Kai C++ compiler setup: + +#include "boost/config/compiler/common_edg.hpp" + +# if (__KCC_VERSION <= 4001) || !defined(BOOST_STRICT_CONFIG) + // at least on Sun, the contents of is not in namespace std +# define BOOST_NO_STDC_NAMESPACE +# endif + +// see also common_edg.hpp which needs a special check for __KCC +# if !defined(_EXCEPTIONS) +# define BOOST_NO_EXCEPTIONS +# endif + +#define BOOST_COMPILER "Kai C++ version " BOOST_STRINGIZE(__KCC_VERSION) + +// +// last known and checked version is 4001: +#if (__KCC_VERSION > 4001) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + + diff --git a/eo/contrib/boost/config/compiler/metrowerks.hpp b/eo/contrib/boost/config/compiler/metrowerks.hpp new file mode 100644 index 000000000..f173295eb --- /dev/null +++ b/eo/contrib/boost/config/compiler/metrowerks.hpp @@ -0,0 +1,104 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright Darin Adler 2001. +// (C) Copyright Peter Dimov 2001. +// (C) Copyright David Abrahams 2001 - 2002. +// (C) Copyright Beman Dawes 2001 - 2003. +// (C) Copyright Stefan Slapeta 2004. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Metrowerks C++ compiler setup: + +// locale support is disabled when linking with the dynamic runtime +# ifdef _MSL_NO_LOCALE +# define BOOST_NO_STD_LOCALE +# endif + +# if __MWERKS__ <= 0x2301 // 5.3 +# define BOOST_NO_FUNCTION_TEMPLATE_ORDERING +# define BOOST_NO_POINTER_TO_MEMBER_CONST +# define BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS +# define BOOST_NO_MEMBER_TEMPLATE_KEYWORD +# endif + +# if __MWERKS__ <= 0x2401 // 6.2 +//# define BOOST_NO_FUNCTION_TEMPLATE_ORDERING +# endif + +# if(__MWERKS__ <= 0x2407) // 7.x +# define BOOST_NO_MEMBER_FUNCTION_SPECIALIZATIONS +# define BOOST_NO_UNREACHABLE_RETURN_DETECTION +# endif + +# if(__MWERKS__ <= 0x3003) // 8.x +# define BOOST_NO_SFINAE +# endif + +// the "|| !defined(BOOST_STRICT_CONFIG)" part should apply to the last +// tested version *only*: +# if(__MWERKS__ <= 0x3206) || !defined(BOOST_STRICT_CONFIG) // 9.5 +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +# define BOOST_NO_IS_ABSTRACT +# endif + +#if !__option(wchar_type) +# define BOOST_NO_INTRINSIC_WCHAR_T +#endif + +#if !__option(exceptions) +# define BOOST_NO_EXCEPTIONS +#endif + +#if (__INTEL__ && _WIN32) || (__POWERPC__ && macintosh) +# if __MWERKS__ == 0x3000 +# define BOOST_COMPILER_VERSION 8.0 +# elif __MWERKS__ == 0x3001 +# define BOOST_COMPILER_VERSION 8.1 +# elif __MWERKS__ == 0x3002 +# define BOOST_COMPILER_VERSION 8.2 +# elif __MWERKS__ == 0x3003 +# define BOOST_COMPILER_VERSION 8.3 +# elif __MWERKS__ == 0x3200 +# define BOOST_COMPILER_VERSION 9.0 +# elif __MWERKS__ == 0x3201 +# define BOOST_COMPILER_VERSION 9.1 +# elif __MWERKS__ == 0x3202 +# define BOOST_COMPILER_VERSION 9.2 +# elif __MWERKS__ == 0x3204 +# define BOOST_COMPILER_VERSION 9.3 +# elif __MWERKS__ == 0x3205 +# define BOOST_COMPILER_VERSION 9.4 +# elif __MWERKS__ == 0x3206 +# define BOOST_COMPILER_VERSION 9.5 +# else +# define BOOST_COMPILER_VERSION __MWERKS__ +# endif +#else +# define BOOST_COMPILER_VERSION __MWERKS__ +#endif + +#define BOOST_COMPILER "Metrowerks CodeWarrior C++ version " BOOST_STRINGIZE(BOOST_COMPILER_VERSION) + +// +// versions check: +// we don't support Metrowerks prior to version 5.3: +#if __MWERKS__ < 0x2301 +# error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version: +#if (__MWERKS__ > 0x3205) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + + + + + + diff --git a/eo/contrib/boost/config/compiler/mpw.hpp b/eo/contrib/boost/config/compiler/mpw.hpp new file mode 100644 index 000000000..8ab2aacb6 --- /dev/null +++ b/eo/contrib/boost/config/compiler/mpw.hpp @@ -0,0 +1,51 @@ +// (C) Copyright John Maddock 2001 - 2002. +// (C) Copyright Aleksey Gurtovoy 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// MPW C++ compilers setup: + +# if defined(__SC__) +# define BOOST_COMPILER "MPW SCpp version " BOOST_STRINGIZE(__SC__) +# elif defined(__MRC__) +# define BOOST_COMPILER "MPW MrCpp version " BOOST_STRINGIZE(__MRC__) +# else +# error "Using MPW compiler configuration by mistake. Please update." +# endif + +// +// MPW 8.90: +// +#if (MPW_CPLUS <= 0x890) || !defined(BOOST_STRICT_CONFIG) +# define BOOST_NO_CV_SPECIALIZATIONS +# define BOOST_NO_DEPENDENT_NESTED_DERIVATIONS +# define BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS +# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION +# define BOOST_NO_INTRINSIC_WCHAR_T +# define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# define BOOST_NO_USING_TEMPLATE + +# define BOOST_NO_CWCHAR +# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + +# define BOOST_NO_STD_ALLOCATOR /* actually a bug with const reference overloading */ +#endif + +// +// versions check: +// we don't support MPW prior to version 8.9: +#if MPW_CPLUS < 0x890 +# error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 0x890: +#if (MPW_CPLUS > 0x890) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + diff --git a/eo/contrib/boost/config/compiler/sgi_mipspro.hpp b/eo/contrib/boost/config/compiler/sgi_mipspro.hpp new file mode 100644 index 000000000..689b67eeb --- /dev/null +++ b/eo/contrib/boost/config/compiler/sgi_mipspro.hpp @@ -0,0 +1,24 @@ +// (C) Copyright John Maddock 2001 - 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// SGI C++ compiler setup: + +#define BOOST_COMPILER "SGI Irix compiler version " BOOST_STRINGIZE(_COMPILER_VERSION) + +#include "boost/config/compiler/common_edg.hpp" + +// +// Threading support: +// Turn this on unconditionally here, it will get turned off again later +// if no threading API is detected. +// +#define BOOST_HAS_THREADS +// +// version check: +// probably nothing to do here? + + diff --git a/eo/contrib/boost/config/compiler/sunpro_cc.hpp b/eo/contrib/boost/config/compiler/sunpro_cc.hpp new file mode 100644 index 000000000..eca19feb0 --- /dev/null +++ b/eo/contrib/boost/config/compiler/sunpro_cc.hpp @@ -0,0 +1,90 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright Jens Maurer 2001 - 2003. +// (C) Copyright Peter Dimov 2002. +// (C) Copyright Aleksey Gurtovoy 2002 - 2003. +// (C) Copyright David Abrahams 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Sun C++ compiler setup: + +# if __SUNPRO_CC <= 0x500 +# define BOOST_NO_MEMBER_TEMPLATES +# define BOOST_NO_FUNCTION_TEMPLATE_ORDERING +# endif + +# if (__SUNPRO_CC <= 0x520) + // + // Sunpro 5.2 and earler: + // + // although sunpro 5.2 supports the syntax for + // inline initialization it often gets the value + // wrong, especially where the value is computed + // from other constants (J Maddock 6th May 2001) +# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION + + // Although sunpro 5.2 supports the syntax for + // partial specialization, it often seems to + // bind to the wrong specialization. Better + // to disable it until suppport becomes more stable + // (J Maddock 6th May 2001). +# define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# endif + +# if (__SUNPRO_CC <= 0x530) + // Requesting debug info (-g) with Boost.Python results + // in an internal compiler error for "static const" + // initialized in-class. + // >> Assertion: (../links/dbg_cstabs.cc, line 611) + // while processing ../test.cpp at line 0. + // (Jens Maurer according to Gottfried Ganßauge 04 Mar 2002) +# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION + + // SunPro 5.3 has better support for partial specialization, + // but breaks when compiling std::less > + // (Jens Maurer 4 Nov 2001). + + // std::less specialization fixed as reported by George + // Heintzelman; partial specialization re-enabled + // (Peter Dimov 17 Jan 2002) + +//# define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // integral constant expressions with 64 bit numbers fail +# define BOOST_NO_INTEGRAL_INT64_T +# endif + +# if (__SUNPRO_CC < 0x570) +# define BOOST_NO_TEMPLATE_TEMPLATES + // see http://lists.boost.org/MailArchives/boost/msg47184.php + // and http://lists.boost.org/MailArchives/boost/msg47220.php +# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION +# define BOOST_NO_SFINAE +# define BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS +# define BOOST_NO_IS_ABSTRACT +# endif + +#define BOOST_COMPILER "Sun compiler version " BOOST_STRINGIZE(__SUNPRO_CC) + +// +// versions check: +// we don't support sunpro prior to version 4: +#if __SUNPRO_CC < 0x400 +#error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 0x570: +#if (__SUNPRO_CC > 0x570) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + + + + + diff --git a/eo/contrib/boost/config/compiler/vacpp.hpp b/eo/contrib/boost/config/compiler/vacpp.hpp new file mode 100644 index 000000000..4cf0de7c1 --- /dev/null +++ b/eo/contrib/boost/config/compiler/vacpp.hpp @@ -0,0 +1,58 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Toon Knapen 2001 - 2003. +// (C) Copyright Lie-Quan Lee 2001. +// (C) Copyright Markus Schöpflin 2002 - 2003. +// (C) Copyright Beman Dawes 2002 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Visual Age (IBM) C++ compiler setup: + +#if __IBMCPP__ <= 501 +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +# define BOOST_NO_MEMBER_FUNCTION_SPECIALIZATIONS +#endif + +#if (__IBMCPP__ <= 502) +// Actually the compiler supports inclass member initialization but it +// requires a definition for the class member and it doesn't recognize +// it as an integral constant expression when used as a template argument. +# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION +# define BOOST_NO_INTEGRAL_INT64_T +# define BOOST_NO_MEMBER_TEMPLATE_KEYWORD +#endif + +#if (__IBMCPP__ <= 600) || !defined(BOOST_STRICT_CONFIG) +# define BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS +# define BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES 1 +#endif + +// +// On AIX thread support seems to be indicated by _THREAD_SAFE: +// +#ifdef _THREAD_SAFE +# define BOOST_HAS_THREADS +#endif + +#define BOOST_COMPILER "IBM Visual Age version " BOOST_STRINGIZE(__IBMCPP__) + +// +// versions check: +// we don't support Visual age prior to version 5: +#if __IBMCPP__ < 500 +#error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 600: +#if (__IBMCPP__ > 600) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# endif +#endif + + + + diff --git a/eo/contrib/boost/config/compiler/visualc.hpp b/eo/contrib/boost/config/compiler/visualc.hpp new file mode 100644 index 000000000..1ce600ccf --- /dev/null +++ b/eo/contrib/boost/config/compiler/visualc.hpp @@ -0,0 +1,147 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Darin Adler 2001 - 2002. +// (C) Copyright Peter Dimov 2001. +// (C) Copyright Aleksey Gurtovoy 2002. +// (C) Copyright David Abrahams 2002 - 2003. +// (C) Copyright Beman Dawes 2002 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Microsoft Visual C++ compiler setup: + +#define BOOST_MSVC _MSC_VER + +// turn off the warnings before we #include anything +#pragma warning( disable : 4503 ) // warning: decorated name length exceeded + +#if _MSC_VER < 1300 // 1200 == VC++ 6.0, 1201 == EVC4.2 +#pragma warning( disable : 4786 ) // ident trunc to '255' chars in debug info +# define BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS +# define BOOST_NO_VOID_RETURNS +# define BOOST_NO_EXCEPTION_STD_NAMESPACE + // disable min/max macro defines on vc6: + // +#endif + +#if (_MSC_VER <= 1300) // 1300 == VC++ 7.0 + +#if !defined(_MSC_EXTENSIONS) && !defined(BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS) // VC7 bug with /Za +# define BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS +#endif + +# define BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS +# define BOOST_NO_INCLASS_MEMBER_INITIALIZATION +# define BOOST_NO_PRIVATE_IN_AGGREGATE +# define BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP +# define BOOST_NO_INTEGRAL_INT64_T +# define BOOST_NO_DEDUCED_TYPENAME +# define BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE + +// VC++ 6/7 has member templates but they have numerous problems including +// cases of silent failure, so for safety we define: +# define BOOST_NO_MEMBER_TEMPLATES +// For VC++ experts wishing to attempt workarounds, we define: +# define BOOST_MSVC6_MEMBER_TEMPLATES + +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +# define BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# define BOOST_NO_CV_VOID_SPECIALIZATIONS +# define BOOST_NO_FUNCTION_TEMPLATE_ORDERING +# define BOOST_NO_USING_TEMPLATE +# define BOOST_NO_SWPRINTF +# define BOOST_NO_TEMPLATE_TEMPLATES +# define BOOST_NO_SFINAE +# define BOOST_NO_POINTER_TO_MEMBER_TEMPLATE_PARAMETERS +# define BOOST_NO_IS_ABSTRACT +# if (_MSC_VER > 1200) +# define BOOST_NO_MEMBER_FUNCTION_SPECIALIZATIONS +# endif + +#endif + +#if _MSC_VER < 1310 // 1310 == VC++ 7.1 +# define BOOST_NO_SWPRINTF +#endif + +#if _MSC_VER <= 1400 // 1400 == VC++ 8.0 +# define BOOST_NO_MEMBER_TEMPLATE_FRIENDS +#endif + +#ifndef _NATIVE_WCHAR_T_DEFINED +# define BOOST_NO_INTRINSIC_WCHAR_T +#endif + +#ifdef _WIN32_WCE +# define BOOST_NO_THREADEX +# define BOOST_NO_GETSYSTEMTIMEASFILETIME +#endif + +// +// check for exception handling support: +#ifndef _CPPUNWIND +# define BOOST_NO_EXCEPTIONS +#endif + +// +// __int64 support: +// +#if (_MSC_VER >= 1200) +# define BOOST_HAS_MS_INT64 +#endif +#if (_MSC_VER >= 1310) && defined(_MSC_EXTENSIONS) +# define BOOST_HAS_LONG_LONG +#endif +// +// disable Win32 API's if compiler extentions are +// turned off: +// +#ifndef _MSC_EXTENSIONS +# define BOOST_DISABLE_WIN32 +#endif + +// +// all versions support __declspec: +// +#define BOOST_HAS_DECLSPEC +// +// prefix and suffix headers: +// +#ifndef BOOST_ABI_PREFIX +# define BOOST_ABI_PREFIX "boost/config/abi/msvc_prefix.hpp" +#endif +#ifndef BOOST_ABI_SUFFIX +# define BOOST_ABI_SUFFIX "boost/config/abi/msvc_suffix.hpp" +#endif + +# if _MSC_VER == 1200 +# define BOOST_COMPILER_VERSION 6.0 +# elif _MSC_VER == 1300 +# define BOOST_COMPILER_VERSION 7.0 +# elif _MSC_VER == 1310 +# define BOOST_COMPILER_VERSION 7.1 +# elif _MSC_VER == 1400 +# define BOOST_COMPILER_VERSION 8.0 +# else +# define BOOST_COMPILER_VERSION _MSC_VER +# endif + +#define BOOST_COMPILER "Microsoft Visual C++ version " BOOST_STRINGIZE(BOOST_COMPILER_VERSION) + +// +// versions check: +// we don't support Visual C++ prior to version 6: +#if _MSC_VER < 1200 +#error "Compiler not supported or configured - please reconfigure" +#endif +// +// last known and checked version is 1310: +#if (_MSC_VER > 1400) +# if defined(BOOST_ASSERT_CONFIG) +# error "Unknown compiler version - please run the configure tests and report the results" +# else +# pragma message("Unknown compiler version - please run the configure tests and report the results") +# endif +#endif diff --git a/eo/contrib/boost/config/platform/aix.hpp b/eo/contrib/boost/config/platform/aix.hpp new file mode 100644 index 000000000..894ef42ce --- /dev/null +++ b/eo/contrib/boost/config/platform/aix.hpp @@ -0,0 +1,33 @@ +// (C) Copyright John Maddock 2001 - 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// IBM/Aix specific config options: + +#define BOOST_PLATFORM "IBM Aix" + +#define BOOST_HAS_UNISTD_H +#define BOOST_HAS_NL_TYPES_H +#define BOOST_HAS_NANOSLEEP +#define BOOST_HAS_CLOCK_GETTIME + +// This needs support in "boost/cstdint.hpp" exactly like FreeBSD. +// This platform has header named which includes all +// the things needed. +#define BOOST_HAS_STDINT_H + +// Threading API's: +#define BOOST_HAS_PTHREADS +#define BOOST_HAS_PTHREAD_DELAY_NP +#define BOOST_HAS_SCHED_YIELD +//#define BOOST_HAS_PTHREAD_YIELD + +// boilerplate code: +#include + + + + diff --git a/eo/contrib/boost/config/platform/amigaos.hpp b/eo/contrib/boost/config/platform/amigaos.hpp new file mode 100644 index 000000000..34bcf4128 --- /dev/null +++ b/eo/contrib/boost/config/platform/amigaos.hpp @@ -0,0 +1,15 @@ +// (C) Copyright John Maddock 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +#define BOOST_PLATFORM "AmigaOS" + +#define BOOST_DISABLE_THREADS +#define BOOST_NO_CWCHAR +#define BOOST_NO_STD_WSTRING +#define BOOST_NO_INTRINSIC_WCHAR_T + + diff --git a/eo/contrib/boost/config/platform/beos.hpp b/eo/contrib/boost/config/platform/beos.hpp new file mode 100644 index 000000000..48c3d8dc5 --- /dev/null +++ b/eo/contrib/boost/config/platform/beos.hpp @@ -0,0 +1,26 @@ +// (C) Copyright John Maddock 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// BeOS specific config options: + +#define BOOST_PLATFORM "BeOS" + +#define BOOST_NO_CWCHAR +#define BOOST_NO_CWCTYPE +#define BOOST_HAS_UNISTD_H + +#define BOOST_HAS_BETHREADS + +#ifndef BOOST_DISABLE_THREADS +# define BOOST_HAS_THREADS +#endif + +// boilerplate code: +#include + + + diff --git a/eo/contrib/boost/config/platform/bsd.hpp b/eo/contrib/boost/config/platform/bsd.hpp new file mode 100644 index 000000000..09988e0ca --- /dev/null +++ b/eo/contrib/boost/config/platform/bsd.hpp @@ -0,0 +1,71 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Darin Adler 2001. +// (C) Copyright Douglas Gregor 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// generic BSD config options: + +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) +#error "This platform is not BSD" +#endif + +#ifdef __FreeBSD__ +#define BOOST_PLATFORM "FreeBSD " BOOST_STRINGIZE(__FreeBSD__) +#elif defined(__NetBSD__) +#define BOOST_PLATFORM "NetBSD " BOOST_STRINGIZE(__NetBSD__) +#elif defined(__OpenBSD__) +#define BOOST_PLATFORM "OpenBSD " BOOST_STRINGIZE(__OpenBSD__) +#endif + +// +// is this the correct version check? +// FreeBSD has but does not +// advertise the fact in : +// +#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) +# define BOOST_HAS_NL_TYPES_H +#endif + +// +// FreeBSD 3.x has pthreads support, but defines _POSIX_THREADS in +// and not in +// +#if defined(__FreeBSD__) && (__FreeBSD__ <= 3) +# define BOOST_HAS_PTHREADS +#endif + +// +// No wide character support in the BSD header files: +// +#if !(defined(__FreeBSD__) && (__FreeBSD__ >= 5)) +# define BOOST_NO_CWCHAR +#endif +// +// The BSD has macros only, no functions: +// +#if !defined(__OpenBSD__) +# define BOOST_NO_CTYPE_FUNCTIONS +#endif + +// +// thread API's not auto detected: +// +#define BOOST_HAS_SCHED_YIELD +#define BOOST_HAS_NANOSLEEP +#define BOOST_HAS_GETTIMEOFDAY +#define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +#define BOOST_HAS_SIGACTION + +// boilerplate code: +#define BOOST_HAS_UNISTD_H +#include + + + + + + diff --git a/eo/contrib/boost/config/platform/cygwin.hpp b/eo/contrib/boost/config/platform/cygwin.hpp new file mode 100644 index 000000000..0fd2ebe2d --- /dev/null +++ b/eo/contrib/boost/config/platform/cygwin.hpp @@ -0,0 +1,48 @@ +// (C) Copyright John Maddock 2001 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// cygwin specific config options: + +#define BOOST_PLATFORM "Cygwin" +#define BOOST_NO_CWCTYPE +#define BOOST_NO_CWCHAR +#define BOOST_NO_SWPRINTF +#define BOOST_HAS_DIRENT_H + +// +// Threading API: +// See if we have POSIX threads, if we do use them, otherwise +// revert to native Win threads. +#define BOOST_HAS_UNISTD_H +#include +#if defined(_POSIX_THREADS) && (_POSIX_THREADS+0 >= 0) && !defined(BOOST_HAS_WINTHREADS) +# define BOOST_HAS_PTHREADS +# define BOOST_HAS_SCHED_YIELD +# define BOOST_HAS_GETTIMEOFDAY +# define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +# define BOOST_HAS_SIGACTION +#else +# if !defined(BOOST_HAS_WINTHREADS) +# define BOOST_HAS_WINTHREADS +# endif +# define BOOST_HAS_FTIME +#endif + +// +// find out if we have a stdint.h, there should be a better way to do this: +// +#include +#ifdef _STDINT_H +#define BOOST_HAS_STDINT_H +#endif + +// boilerplate code: +#include + + + + diff --git a/eo/contrib/boost/config/platform/hpux.hpp b/eo/contrib/boost/config/platform/hpux.hpp new file mode 100644 index 000000000..fa773aa79 --- /dev/null +++ b/eo/contrib/boost/config/platform/hpux.hpp @@ -0,0 +1,68 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2001 - 2003. +// (C) Copyright David Abrahams 2002. +// (C) Copyright Toon Knapen 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// hpux specific config options: + +#define BOOST_PLATFORM "HP-UX" + +// In principle, HP-UX has a nice under the name +// However, it has the following problem: +// Use of UINT32_C(0) results in "0u l" for the preprocessed source +// (verifyable with gcc 2.95.3, assumed for HP aCC) +// #define BOOST_HAS_STDINT_H + +#define BOOST_NO_SWPRINTF +#define BOOST_NO_CWCTYPE + +#if defined(__GNUC__) +# if (__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 3)) + // GNU C on HP-UX does not support threads (checked up to gcc 3.3) +# define BOOST_DISABLE_THREADS +# elif !defined(BOOST_DISABLE_THREADS) + // threads supported from gcc-3.3 onwards: +# define BOOST_HAS_THREADS +# define BOOST_HAS_PTHREADS +# endif +#endif + +// boilerplate code: +#define BOOST_HAS_UNISTD_H +#include + +// the following are always available: +#ifndef BOOST_HAS_GETTIMEOFDAY +# define BOOST_HAS_GETTIMEOFDAY +#endif +#ifndef BOOST_HAS_SCHED_YIELD +# define BOOST_HAS_SCHED_YIELD +#endif +#ifndef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +# define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +#endif +#ifndef BOOST_HAS_NL_TYPES_H +# define BOOST_HAS_NL_TYPES_H +#endif +#ifndef BOOST_HAS_NANOSLEEP +# define BOOST_HAS_NANOSLEEP +#endif +#ifndef BOOST_HAS_GETTIMEOFDAY +# define BOOST_HAS_GETTIMEOFDAY +#endif +#ifndef BOOST_HAS_DIRENT_H +# define BOOST_HAS_DIRENT_H +#endif +#ifndef BOOST_HAS_CLOCK_GETTIME +# define BOOST_HAS_CLOCK_GETTIME +#endif +#ifndef BOOST_HAS_SIGACTION +# define BOOST_HAS_SIGACTION +#endif + + diff --git a/eo/contrib/boost/config/platform/irix.hpp b/eo/contrib/boost/config/platform/irix.hpp new file mode 100644 index 000000000..aeae49c8b --- /dev/null +++ b/eo/contrib/boost/config/platform/irix.hpp @@ -0,0 +1,31 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org for most recent version. + +// SGI Irix specific config options: + +#define BOOST_PLATFORM "SGI Irix" + +#define BOOST_NO_SWPRINTF +// +// these are not auto detected by POSIX feature tests: +// +#define BOOST_HAS_GETTIMEOFDAY +#define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE + +#ifdef __GNUC__ + // GNU C on IRIX does not support threads (checked up to gcc 3.3) +# define BOOST_DISABLE_THREADS +#endif + +// boilerplate code: +#define BOOST_HAS_UNISTD_H +#include + + + diff --git a/eo/contrib/boost/config/platform/linux.hpp b/eo/contrib/boost/config/platform/linux.hpp new file mode 100644 index 000000000..51ae13347 --- /dev/null +++ b/eo/contrib/boost/config/platform/linux.hpp @@ -0,0 +1,98 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2001 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// linux specific config options: + +#define BOOST_PLATFORM "linux" + +// make sure we have __GLIBC_PREREQ if available at all +#include + +// +// added to glibc 2.1.1 +// We can only test for 2.1 though: +// +#if defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))) + // defines int64_t unconditionally, but defines + // int64_t only if __GNUC__. Thus, assume a fully usable + // only when using GCC. +# if defined __GNUC__ +# define BOOST_HAS_STDINT_H +# endif +#endif + +#if defined(__LIBCOMO__) + // + // como on linux doesn't have std:: c functions: + // NOTE: versions of libcomo prior to beta28 have octal version numbering, + // e.g. version 25 is 21 (dec) + // +# if __LIBCOMO_VERSION__ <= 20 +# define BOOST_NO_STDC_NAMESPACE +# endif + +# if __LIBCOMO_VERSION__ <= 21 +# define BOOST_NO_SWPRINTF +# endif + +#endif + +// +// If glibc is past version 2 then we definitely have +// gettimeofday, earlier versions may or may not have it: +// +#if defined(__GLIBC__) && (__GLIBC__ >= 2) +# define BOOST_HAS_GETTIMEOFDAY +#endif + +#ifdef __USE_POSIX199309 +# define BOOST_HAS_NANOSLEEP +#endif + +#if defined(__GLIBC__) && defined(__GLIBC_PREREQ) +// __GLIBC_PREREQ is available since 2.1.2 + + // swprintf is available since glibc 2.2.0 +# if !__GLIBC_PREREQ(2,2) || (!defined(__USE_ISOC99) && !defined(__USE_UNIX98)) +# define BOOST_NO_SWPRINTF +# endif +#else +# define BOOST_NO_SWPRINTF +#endif + +// boilerplate code: +#define BOOST_HAS_UNISTD_H +#include + +#ifndef __GNUC__ +// +// if the compiler is not gcc we still need to be able to parse +// the GNU system headers, some of which (mainly ) +// use GNU specific extensions: +// +# ifndef __extension__ +# define __extension__ +# endif +# ifndef __const__ +# define __const__ const +# endif +# ifndef __volatile__ +# define __volatile__ volatile +# endif +# ifndef __signed__ +# define __signed__ signed +# endif +# ifndef __typeof__ +# define __typeof__ typeof +# endif +# ifndef __inline__ +# define __inline__ inline +# endif +#endif + + diff --git a/eo/contrib/boost/config/platform/macos.hpp b/eo/contrib/boost/config/platform/macos.hpp new file mode 100644 index 000000000..d6877d311 --- /dev/null +++ b/eo/contrib/boost/config/platform/macos.hpp @@ -0,0 +1,78 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Darin Adler 2001 - 2002. +// (C) Copyright Bill Kempf 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Mac OS specific config options: + +#define BOOST_PLATFORM "Mac OS" + +#if __MACH__ && !defined(_MSL_USING_MSL_C) + +// Using the Mac OS X system BSD-style C library. + +# ifndef BOOST_HAS_UNISTD_H +# define BOOST_HAS_UNISTD_H +# endif +// +// Begin by including our boilerplate code for POSIX +// feature detection, this is safe even when using +// the MSL as Metrowerks supply their own +// to replace the platform-native BSD one. G++ users +// should also always be able to do this on MaxOS X. +// +# include +# ifndef BOOST_HAS_STDINT_H +# define BOOST_HAS_STDINT_H +# endif + +// +// BSD runtime has pthreads, sigaction, sched_yield and gettimeofday, +// of these only pthreads are advertised in , so set the +// other options explicitly: +// +# define BOOST_HAS_SCHED_YIELD +# define BOOST_HAS_GETTIMEOFDAY +# define BOOST_HAS_SIGACTION + +# if (__GNUC__ < 3) && !defined( __APPLE_CC__) + +// GCC strange "ignore std" mode works better if you pretend everything +// is in the std namespace, for the most part. + +# define BOOST_NO_STDC_NAMESPACE +# endif + +#else + +// Using the MSL C library. + +// We will eventually support threads in non-Carbon builds, but we do +// not support this yet. +# if ( defined(TARGET_API_MAC_CARBON) && TARGET_API_MAC_CARBON ) || ( defined(TARGET_CARBON) && TARGET_CARBON ) + +# if !defined(BOOST_HAS_PTHREADS) +# define BOOST_HAS_MPTASKS +# elif ( __dest_os == __mac_os_x ) +// We are doing a Carbon/Mach-O/MSL build which has pthreads, but only the +// gettimeofday and no posix. +# define BOOST_HAS_GETTIMEOFDAY +# endif + +// The MP task implementation of Boost Threads aims to replace MP-unsafe +// parts of the MSL, so we turn on threads unconditionally. +# define BOOST_HAS_THREADS + +// The remote call manager depends on this. +# define BOOST_BIND_ENABLE_PASCAL + +# endif + +#endif + + + diff --git a/eo/contrib/boost/config/platform/solaris.hpp b/eo/contrib/boost/config/platform/solaris.hpp new file mode 100644 index 000000000..700dc3ce6 --- /dev/null +++ b/eo/contrib/boost/config/platform/solaris.hpp @@ -0,0 +1,21 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// sun specific config options: + +#define BOOST_PLATFORM "Sun Solaris" + +#define BOOST_HAS_GETTIMEOFDAY + +// boilerplate code: +#define BOOST_HAS_UNISTD_H +#include + + + + diff --git a/eo/contrib/boost/config/platform/win32.hpp b/eo/contrib/boost/config/platform/win32.hpp new file mode 100644 index 000000000..548bff280 --- /dev/null +++ b/eo/contrib/boost/config/platform/win32.hpp @@ -0,0 +1,50 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Bill Kempf 2001. +// (C) Copyright Aleksey Gurtovoy 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Win32 specific config options: + +#define BOOST_PLATFORM "Win32" + +#if defined(__GNUC__) && !defined(BOOST_NO_SWPRINTF) +# define BOOST_NO_SWPRINTF +#endif + +#if !defined(__GNUC__) && !defined(BOOST_HAS_DECLSPEC) +# define BOOST_HAS_DECLSPEC +#endif + +#if defined(__MINGW32__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2))) +# define BOOST_HAS_STDINT_H +# define __STDC_LIMIT_MACROS +#endif + +// +// Win32 will normally be using native Win32 threads, +// but there is a pthread library avaliable as an option, +// we used to disable this when BOOST_DISABLE_WIN32 was +// defined but no longer - this should allow some +// files to be compiled in strict mode - while maintaining +// a consistent setting of BOOST_HAS_THREADS across +// all translation units (needed for shared_ptr etc). +// + +#ifdef _WIN32_WCE +# define BOOST_NO_ANSI_APIS +#endif + +#ifndef BOOST_HAS_PTHREADS +# define BOOST_HAS_WINTHREADS +#endif + +#ifndef BOOST_DISABLE_WIN32 +// WEK: Added +#define BOOST_HAS_FTIME +#define BOOST_WINDOWS 1 + +#endif diff --git a/eo/contrib/boost/config/posix_features.hpp b/eo/contrib/boost/config/posix_features.hpp new file mode 100644 index 000000000..4afb476b7 --- /dev/null +++ b/eo/contrib/boost/config/posix_features.hpp @@ -0,0 +1,87 @@ +// (C) Copyright John Maddock 2001 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org for most recent version. + +// All POSIX feature tests go in this file, +// Note that we test _POSIX_C_SOURCE and _XOPEN_SOURCE as well +// _POSIX_VERSION and _XOPEN_VERSION: on some systems POSIX API's +// may be present but none-functional unless _POSIX_C_SOURCE and +// _XOPEN_SOURCE have been defined to the right value (it's up +// to the user to do this *before* including any header, although +// in most cases the compiler will do this for you). + +# if defined(BOOST_HAS_UNISTD_H) +# include + + // XOpen has , but is this the correct version check? +# if defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 3) +# define BOOST_HAS_NL_TYPES_H +# endif + + // POSIX version 6 requires +# if defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200100) +# define BOOST_HAS_STDINT_H +# endif + + // POSIX version 2 requires +# if defined(_POSIX_VERSION) && (_POSIX_VERSION >= 199009L) +# define BOOST_HAS_DIRENT_H +# endif + + // POSIX version 3 requires to have sigaction: +# if defined(_POSIX_VERSION) && (_POSIX_VERSION >= 199506L) +# define BOOST_HAS_SIGACTION +# endif + // POSIX defines _POSIX_THREADS > 0 for pthread support, + // however some platforms define _POSIX_THREADS without + // a value, hence the (_POSIX_THREADS+0 >= 0) check. + // Strictly speaking this may catch platforms with a + // non-functioning stub , but such occurrences should + // occur very rarely if at all. +# if defined(_POSIX_THREADS) && (_POSIX_THREADS+0 >= 0) && !defined(BOOST_HAS_WINTHREADS) && !defined(BOOST_HAS_MPTASKS) +# define BOOST_HAS_PTHREADS +# endif + + // BOOST_HAS_NANOSLEEP: + // This is predicated on _POSIX_TIMERS or _XOPEN_REALTIME: +# if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS+0 >= 0)) \ + || (defined(_XOPEN_REALTIME) && (_XOPEN_REALTIME+0 >= 0)) +# define BOOST_HAS_NANOSLEEP +# endif + + // BOOST_HAS_CLOCK_GETTIME: + // This is predicated on _POSIX_TIMERS (also on _XOPEN_REALTIME + // but at least one platform - linux - defines that flag without + // defining clock_gettime): +# if (defined(_POSIX_TIMERS) && (_POSIX_TIMERS+0 >= 0)) +# define BOOST_HAS_CLOCK_GETTIME +# endif + + // BOOST_HAS_SCHED_YIELD: + // This is predicated on _POSIX_PRIORITY_SCHEDULING or + // on _POSIX_THREAD_PRIORITY_SCHEDULING or on _XOPEN_REALTIME. +# if defined(_POSIX_PRIORITY_SCHEDULING) && (_POSIX_PRIORITY_SCHEDULING+0 > 0)\ + || (defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING+0 > 0))\ + || (defined(_XOPEN_REALTIME) && (_XOPEN_REALTIME+0 >= 0)) +# define BOOST_HAS_SCHED_YIELD +# endif + + // BOOST_HAS_GETTIMEOFDAY: + // BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE: + // These are predicated on _XOPEN_VERSION, and appears to be first released + // in issue 4, version 2 (_XOPEN_VERSION > 500). +# if defined(_XOPEN_VERSION) && (_XOPEN_VERSION+0 >= 500) +# define BOOST_HAS_GETTIMEOFDAY +# if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE+0 >= 500) +# define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +# endif +# endif + +# endif + + + diff --git a/eo/contrib/boost/config/requires_threads.hpp b/eo/contrib/boost/config/requires_threads.hpp new file mode 100644 index 000000000..cfaff2302 --- /dev/null +++ b/eo/contrib/boost/config/requires_threads.hpp @@ -0,0 +1,92 @@ +// (C) Copyright John Maddock 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +#ifndef BOOST_CONFIG_REQUIRES_THREADS_HPP +#define BOOST_CONFIG_REQUIRES_THREADS_HPP + +#ifndef BOOST_CONFIG_HPP +# include +#endif + +#if defined(BOOST_DISABLE_THREADS) + +// +// special case to handle versions of gcc which don't currently support threads: +// +#if defined(__GNUC__) && ((__GNUC__ < 3) || (__GNUC_MINOR__ <= 3) || !defined(BOOST_STRICT_CONFIG)) +// +// this is checked up to gcc 3.3: +// +#if defined(__sgi) || defined(__hpux) +# error "Multi-threaded programs are not supported by gcc on HPUX or Irix (last checked with gcc 3.3)" +#endif + +#endif + +# error "Threading support unavaliable: it has been explicitly disabled with BOOST_DISABLE_THREADS" + +#elif !defined(BOOST_HAS_THREADS) + +# if defined __COMO__ +// Comeau C++ +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -D_MT (Windows) or -D_REENTRANT (Unix)" + +#elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) +// Intel +#ifdef _WIN32 +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: either /MT /MTd /MD or /MDd" +#else +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -openmp" +#endif + +# elif defined __GNUC__ +// GNU C++: +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)" + +#elif defined __sgi +// SGI MIPSpro C++ +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -D_SGI_MP_SOURCE" + +#elif defined __DECCXX +// Compaq Tru64 Unix cxx +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -pthread" + +#elif defined __BORLANDC__ +// Borland +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -tWM" + +#elif defined __MWERKS__ +// Metrowerks CodeWarrior +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: either -runtime sm, -runtime smd, -runtime dm, or -runtime dmd" + +#elif defined __SUNPRO_CC +// Sun Workshop Compiler C++ +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -mt" + +#elif defined __HP_aCC +// HP aCC +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -mt" + +#elif defined(__IBMCPP__) +// IBM Visual Age +# error "Compiler threading support is not turned on. Please compile the code with the xlC_r compiler" + +#elif defined _MSC_VER +// Microsoft Visual C++ +// +// Must remain the last #elif since some other vendors (Metrowerks, for +// example) also #define _MSC_VER +# error "Compiler threading support is not turned on. Please set the correct command line options for threading: either /MT /MTd /MD or /MDd" + +#else + +# error "Compiler threading support is not turned on. Please consult your compiler's documentation for the appropriate options to use" + +#endif // compilers + +#endif // BOOST_HAS_THREADS + +#endif // BOOST_CONFIG_REQUIRES_THREADS_HPP diff --git a/eo/contrib/boost/config/select_compiler_config.hpp b/eo/contrib/boost/config/select_compiler_config.hpp new file mode 100644 index 000000000..3453f1a35 --- /dev/null +++ b/eo/contrib/boost/config/select_compiler_config.hpp @@ -0,0 +1,83 @@ +// Boost compiler configuration selection header file + +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Martin Wille 2003. +// (C) Copyright Guillaume Melquiond 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// locate which compiler we are using and define +// BOOST_COMPILER_CONFIG as needed: + +# if defined __COMO__ +// Comeau C++ +# define BOOST_COMPILER_CONFIG "boost/config/compiler/comeau.hpp" + +#elif defined __DMC__ +// Digital Mars C++ +# define BOOST_COMPILER_CONFIG "boost/config/compiler/digitalmars.hpp" + +#elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) +// Intel +# define BOOST_COMPILER_CONFIG "boost/config/compiler/intel.hpp" + +# elif defined __GNUC__ +// GNU C++: +# define BOOST_COMPILER_CONFIG "boost/config/compiler/gcc.hpp" + +#elif defined __KCC +// Kai C++ +# define BOOST_COMPILER_CONFIG "boost/config/compiler/kai.hpp" + +#elif defined __sgi +// SGI MIPSpro C++ +# define BOOST_COMPILER_CONFIG "boost/config/compiler/sgi_mipspro.hpp" + +#elif defined __DECCXX +// Compaq Tru64 Unix cxx +# define BOOST_COMPILER_CONFIG "boost/config/compiler/compaq_cxx.hpp" + +#elif defined __ghs +// Greenhills C++ +# define BOOST_COMPILER_CONFIG "boost/config/compiler/greenhills.hpp" + +#elif defined __BORLANDC__ +// Borland +# define BOOST_COMPILER_CONFIG "boost/config/compiler/borland.hpp" + +#elif defined __MWERKS__ +// Metrowerks CodeWarrior +# define BOOST_COMPILER_CONFIG "boost/config/compiler/metrowerks.hpp" + +#elif defined __SUNPRO_CC +// Sun Workshop Compiler C++ +# define BOOST_COMPILER_CONFIG "boost/config/compiler/sunpro_cc.hpp" + +#elif defined __HP_aCC +// HP aCC +# define BOOST_COMPILER_CONFIG "boost/config/compiler/hp_acc.hpp" + +#elif defined(__MRC__) || defined(__SC__) +// MPW MrCpp or SCpp +# define BOOST_COMPILER_CONFIG "boost/config/compiler/mpw.hpp" + +#elif defined(__IBMCPP__) +// IBM Visual Age +# define BOOST_COMPILER_CONFIG "boost/config/compiler/vacpp.hpp" + +#elif defined _MSC_VER +// Microsoft Visual C++ +// +// Must remain the last #elif since some other vendors (Metrowerks, for +// example) also #define _MSC_VER +# define BOOST_COMPILER_CONFIG "boost/config/compiler/visualc.hpp" + +#elif defined (BOOST_ASSERT_CONFIG) +// this must come last - generate an error if we don't +// recognise the compiler: +# error "Unknown compiler - please configure (http://www.boost.org/libs/config/config.htm#configuring) and report the results to the main boost mailing list (http://www.boost.org/more/mailing_lists.htm#main)" + +#endif diff --git a/eo/contrib/boost/config/select_platform_config.hpp b/eo/contrib/boost/config/select_platform_config.hpp new file mode 100644 index 000000000..60bfa5095 --- /dev/null +++ b/eo/contrib/boost/config/select_platform_config.hpp @@ -0,0 +1,86 @@ +// Boost compiler configuration selection header file + +// (C) Copyright John Maddock 2001 - 2002. +// (C) Copyright Jens Maurer 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// locate which platform we are on and define BOOST_PLATFORM_CONFIG as needed. +// Note that we define the headers to include using "header_name" not +// in order to prevent macro expansion within the header +// name (for example "linux" is a macro on linux systems). + +#if defined(linux) || defined(__linux) || defined(__linux__) +// linux: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/linux.hpp" + +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +// BSD: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/bsd.hpp" + +#elif defined(sun) || defined(__sun) +// solaris: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/solaris.hpp" + +#elif defined(__sgi) +// SGI Irix: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/irix.hpp" + +#elif defined(__hpux) +// hp unix: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/hpux.hpp" + +#elif defined(__CYGWIN__) +// cygwin is not win32: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/cygwin.hpp" + +#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) +// win32: +# define BOOST_PLATFORM_CONFIG "boost/config/platform/win32.hpp" + +#elif defined(__BEOS__) +// BeOS +# define BOOST_PLATFORM_CONFIG "boost/config/platform/beos.hpp" + +#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) +// MacOS +# define BOOST_PLATFORM_CONFIG "boost/config/platform/macos.hpp" + +#elif defined(__IBMCPP__) || defined(_AIX) +// IBM +# define BOOST_PLATFORM_CONFIG "boost/config/platform/aix.hpp" + +#elif defined(__amigaos__) +// AmigaOS +# define BOOST_PLATFORM_CONFIG "boost/config/platform/amigaos.hpp" + +#else + +# if defined(unix) \ + || defined(__unix) \ + || defined(_XOPEN_SOURCE) \ + || defined(_POSIX_SOURCE) + + // generic unix platform: + +# ifndef BOOST_HAS_UNISTD_H +# define BOOST_HAS_UNISTD_H +# endif + +# include + +# endif + +# if defined (BOOST_ASSERT_CONFIG) + // this must come last - generate an error if we don't + // recognise the platform: +# error "Unknown platform - please configure and report the results to boost.org" +# endif + +#endif + + + diff --git a/eo/contrib/boost/config/select_stdlib_config.hpp b/eo/contrib/boost/config/select_stdlib_config.hpp new file mode 100644 index 000000000..b7bf59143 --- /dev/null +++ b/eo/contrib/boost/config/select_stdlib_config.hpp @@ -0,0 +1,68 @@ +// Boost compiler configuration selection header file + +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2001 - 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + +// See http://www.boost.org for most recent version. + +// locate which std lib we are using and define BOOST_STDLIB_CONFIG as needed: + +// we need to include a std lib header here in order to detect which +// library is in use, use as it's about the smallest +// of the std lib headers - do not rely on this header being included - +// users can short-circuit this header if they know whose std lib +// they are using. + +#include + +#if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) +// STLPort library; this _must_ come first, otherwise since +// STLport typically sits on top of some other library, we +// can end up detecting that first rather than STLport: +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/stlport.hpp" + +#elif defined(__LIBCOMO__) +// Comeau STL: +#define BOOST_STDLIB_CONFIG "boost/config/stdlib/libcomo.hpp" + +#elif defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER) +// Rogue Wave library: +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/roguewave.hpp" + +#elif defined(__GLIBCPP__) || defined(__GLIBCXX__) +// GNU libstdc++ 3 +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/libstdcpp3.hpp" + +#elif defined(__STL_CONFIG_H) +// generic SGI STL +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/sgi.hpp" + +#elif defined(__MSL_CPP__) +// MSL standard lib: +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/msl.hpp" + +#elif defined(__IBMCPP__) +// take the default VACPP std lib +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/vacpp.hpp" + +#elif defined(MSIPL_COMPILE_H) +// Modena C++ standard library +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/modena.hpp" + +#elif (defined(_YVALS) && !defined(__IBMCPP__)) || defined(_CPPLIB_VER) +// Dinkumware Library (this has to appear after any possible replacement libraries): +# define BOOST_STDLIB_CONFIG "boost/config/stdlib/dinkumware.hpp" + +#elif defined (BOOST_ASSERT_CONFIG) +// this must come last - generate an error if we don't +// recognise the library: +# error "Unknown standard library - please configure and report the results to boost.org" + +#endif + + + diff --git a/eo/contrib/boost/config/stdlib/dinkumware.hpp b/eo/contrib/boost/config/stdlib/dinkumware.hpp new file mode 100644 index 000000000..aa214fc1b --- /dev/null +++ b/eo/contrib/boost/config/stdlib/dinkumware.hpp @@ -0,0 +1,106 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2001. +// (C) Copyright Peter Dimov 2001. +// (C) Copyright David Abrahams 2002. +// (C) Copyright Guillaume Melquiond 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Dinkumware standard library config: + +#if !defined(_YVALS) && !defined(_CPPLIB_VER) +#include +#if !defined(_YVALS) && !defined(_CPPLIB_VER) +#error This is not the Dinkumware lib! +#endif +#endif + + +#if defined(_CPPLIB_VER) && (_CPPLIB_VER >= 306) + // full dinkumware 3.06 and above + // fully conforming provided the compiler supports it: +# if !(defined(_GLOBAL_USING) && (_GLOBAL_USING+0 > 0)) && !defined(__BORLANDC__) && !defined(_STD) && !(defined(__ICC) && (__ICC >= 700)) // can be defined in yvals.h +# define BOOST_NO_STDC_NAMESPACE +# endif +# if !(defined(_HAS_MEMBER_TEMPLATES_REBIND) && (_HAS_MEMBER_TEMPLATES_REBIND+0 > 0)) && !(defined(_MSC_VER) && (_MSC_VER > 1300)) && defined(BOOST_MSVC) +# define BOOST_NO_STD_ALLOCATOR +# endif +# define BOOST_HAS_PARTIAL_STD_ALLOCATOR +# if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) + // if this lib version is set up for vc6 then there is no std::use_facet: +# define BOOST_NO_STD_USE_FACET +# define BOOST_HAS_TWO_ARG_USE_FACET + // C lib functions aren't in namespace std either: +# define BOOST_NO_STDC_NAMESPACE + // and nor is +# define BOOST_NO_EXCEPTION_STD_NAMESPACE +# endif +// There's no numeric_limits support unless _LONGLONG is defined: +# if !defined(_LONGLONG) && (_CPPLIB_VER <= 310) +# define BOOST_NO_MS_INT64_NUMERIC_LIMITS +# endif +// 3.06 appears to have (non-sgi versions of) & , +// and no at all +#else +# define BOOST_MSVC_STD_ITERATOR 1 +# define BOOST_NO_STD_ITERATOR +# define BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS +# define BOOST_NO_STD_ALLOCATOR +# define BOOST_NO_STDC_NAMESPACE +# define BOOST_NO_STD_USE_FACET +# define BOOST_NO_STD_OUTPUT_ITERATOR_ASSIGN +# define BOOST_HAS_MACRO_USE_FACET +# ifndef _CPPLIB_VER + // Updated Dinkum library defines this, and provides + // its own min and max definitions. +# define BOOST_NO_STD_MIN_MAX +# define BOOST_NO_MS_INT64_NUMERIC_LIMITS +# endif +#endif + +// +// std extension namespace is stdext for vc7.1 and later, +// the same applies to other compilers that sit on top +// of vc7.1 (Intel and Comeau): +// +#if defined(_MSC_VER) && (_MSC_VER >= 1310) && !defined(__BORLANDC__) +# define BOOST_STD_EXTENSION_NAMESPACE stdext +#endif + + +#if (defined(_MSC_VER) && (_MSC_VER <= 1300) && !defined(__BORLANDC__)) || !defined(_CPPLIB_VER) || (_CPPLIB_VER < 306) + // if we're using a dinkum lib that's + // been configured for VC6/7 then there is + // no iterator traits (true even for icl) +# define BOOST_NO_STD_ITERATOR_TRAITS +#endif + +#if defined(__ICL) && (__ICL < 800) && defined(_CPPLIB_VER) && (_CPPLIB_VER <= 310) +// Intel C++ chokes over any non-trivial use of +// this may be an overly restrictive define, but regex fails without it: +# define BOOST_NO_STD_LOCALE +#endif + +#ifdef _CPPLIB_VER +# define BOOST_DINKUMWARE_STDLIB _CPPLIB_VER +#else +# define BOOST_DINKUMWARE_STDLIB 1 +#endif + +#ifdef _CPPLIB_VER +# define BOOST_STDLIB "Dinkumware standard library version " BOOST_STRINGIZE(_CPPLIB_VER) +#else +# define BOOST_STDLIB "Dinkumware standard library version 1.x" +#endif + + + + + + + + + diff --git a/eo/contrib/boost/config/stdlib/libcomo.hpp b/eo/contrib/boost/config/stdlib/libcomo.hpp new file mode 100644 index 000000000..b2c8e4400 --- /dev/null +++ b/eo/contrib/boost/config/stdlib/libcomo.hpp @@ -0,0 +1,46 @@ +// (C) Copyright John Maddock 2002 - 2003. +// (C) Copyright Jens Maurer 2002 - 2003. +// (C) Copyright Beman Dawes 2002 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Comeau STL: + +#if !defined(__LIBCOMO__) +# include +# if !defined(__LIBCOMO__) +# error "This is not the Comeau STL!" +# endif +#endif + +// +// std::streambuf is non-standard +// NOTE: versions of libcomo prior to beta28 have octal version numbering, +// e.g. version 25 is 21 (dec) +#if __LIBCOMO_VERSION__ <= 22 +# define BOOST_NO_STD_WSTREAMBUF +#endif + +#if (__LIBCOMO_VERSION__ <= 31) && defined(_WIN32) +#define BOOST_NO_SWPRINTF +#endif + +#if __LIBCOMO_VERSION__ >= 31 +# define BOOST_HAS_HASH +# define BOOST_HAS_SLIST +#endif + +// +// Intrinsic type_traits support. +// The SGI STL has it's own __type_traits class, which +// has intrinsic compiler support with SGI's compilers. +// Whatever map SGI style type traits to boost equivalents: +// +#define BOOST_HAS_SGI_TYPE_TRAITS + +#define BOOST_STDLIB "Comeau standard library " BOOST_STRINGIZE(__LIBCOMO_VERSION__) + + diff --git a/eo/contrib/boost/config/stdlib/libstdcpp3.hpp b/eo/contrib/boost/config/stdlib/libstdcpp3.hpp new file mode 100644 index 000000000..f367fa0f1 --- /dev/null +++ b/eo/contrib/boost/config/stdlib/libstdcpp3.hpp @@ -0,0 +1,61 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright Jens Maurer 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// config for libstdc++ v3 +// not much to go in here: + +#ifdef __GLIBCXX__ +#define BOOST_STDLIB "GNU libstdc++ version " BOOST_STRINGIZE(__GLIBCXX__) +#else +#define BOOST_STDLIB "GNU libstdc++ version " BOOST_STRINGIZE(__GLIBCPP__) +#endif + +#if !defined(_GLIBCPP_USE_WCHAR_T) && !defined(_GLIBCXX_USE_WCHAR_T) +# define BOOST_NO_CWCHAR +# define BOOST_NO_CWCTYPE +# define BOOST_NO_STD_WSTRING +# define BOOST_NO_STD_WSTREAMBUF +#endif + +#if defined(__osf__) && !defined(_REENTRANT) \ + && ( defined(_GLIBCXX_HAVE_GTHR_DEFAULT) || defined(_GLIBCPP_HAVE_GTHR_DEFAULT) ) +// GCC 3 on Tru64 forces the definition of _REENTRANT when any std lib header +// file is included, therefore for consistency we define it here as well. +# define _REENTRANT +#endif + +#ifdef __GLIBCXX__ // gcc 3.4 and greater: +# ifdef _GLIBCXX_HAVE_GTHR_DEFAULT + // + // If the std lib has thread support turned on, then turn it on in Boost + // as well. We do this because some gcc-3.4 std lib headers define _REENTANT + // while others do not... + // +# define BOOST_HAS_THREADS +# else +# define BOOST_DISABLE_THREADS +# endif +#elif defined(__GLIBCPP__) && !defined(_GLIBCPP_HAVE_GTHR_DEFAULT) + // disable thread support if the std lib was built single threaded: +# define BOOST_DISABLE_THREADS +#endif + +#if (defined(linux) || defined(__linux) || defined(__linux__)) && defined(__arm__) && defined(_GLIBCPP_HAVE_GTHR_DEFAULT) +// linux on arm apparently doesn't define _REENTRANT +// so just turn on threading support whenever the std lib is thread safe: +# define BOOST_HAS_THREADS +#endif + + +#if !defined(_GLIBCPP_USE_LONG_LONG) \ + && !defined(_GLIBCXX_USE_LONG_LONG)\ + && defined(BOOST_HAS_LONG_LONG) +// May have been set by compiler/*.hpp, but "long long" without library +// support is useless. +# undef BOOST_HAS_LONG_LONG +#endif diff --git a/eo/contrib/boost/config/stdlib/modena.hpp b/eo/contrib/boost/config/stdlib/modena.hpp new file mode 100644 index 000000000..61e31b7d1 --- /dev/null +++ b/eo/contrib/boost/config/stdlib/modena.hpp @@ -0,0 +1,30 @@ +// (C) Copyright Jens Maurer 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Modena C++ standard library (comes with KAI C++) + +#if !defined(MSIPL_COMPILE_H) +# include +# if !defined(__MSIPL_COMPILE_H) +# error "This is not the Modena C++ library!" +# endif +#endif + +#ifndef MSIPL_NL_TYPES +#define BOOST_NO_STD_MESSAGES +#endif + +#ifndef MSIPL_WCHART +#define BOOST_NO_STD_WSTRING +#endif + +#define BOOST_STDLIB "Modena C++ standard library" + + + + + diff --git a/eo/contrib/boost/config/stdlib/msl.hpp b/eo/contrib/boost/config/stdlib/msl.hpp new file mode 100644 index 000000000..0df8e0e3b --- /dev/null +++ b/eo/contrib/boost/config/stdlib/msl.hpp @@ -0,0 +1,59 @@ +// (C) Copyright John Maddock 2001. +// (C) Copyright Darin Adler 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Metrowerks standard library: + +#ifndef __MSL_CPP__ +# include +# ifndef __MSL_CPP__ +# error This is not the MSL standard library! +# endif +#endif + +#if __MSL_CPP__ >= 0x6000 // Pro 6 +# define BOOST_HAS_HASH +# define BOOST_STD_EXTENSION_NAMESPACE Metrowerks +#endif +#define BOOST_HAS_SLIST + +#if __MSL_CPP__ < 0x6209 +# define BOOST_NO_STD_MESSAGES +#endif + +// check C lib version for +#include + +#if defined(__MSL__) && (__MSL__ >= 0x5000) +# define BOOST_HAS_STDINT_H +# if !defined(__PALMOS_TRAPS__) +# define BOOST_HAS_UNISTD_H +# endif + // boilerplate code: +# include +#endif + +#if defined(_MWMT) || _MSL_THREADSAFE +# define BOOST_HAS_THREADS +#endif + +#ifdef _MSL_NO_EXPLICIT_FUNC_TEMPLATE_ARG +# define BOOST_NO_STD_USE_FACET +# define BOOST_HAS_TWO_ARG_USE_FACET +#endif + + +#define BOOST_STDLIB "Metrowerks Standard Library version " BOOST_STRINGIZE(__MSL_CPP__) + + + + + + + + + diff --git a/eo/contrib/boost/config/stdlib/roguewave.hpp b/eo/contrib/boost/config/stdlib/roguewave.hpp new file mode 100644 index 000000000..b331f6538 --- /dev/null +++ b/eo/contrib/boost/config/stdlib/roguewave.hpp @@ -0,0 +1,127 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Jens Maurer 2001. +// (C) Copyright David Abrahams 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Rogue Wave std lib: + +#if !defined(__STD_RWCOMPILER_H__) && !defined(_RWSTD_VER) +# include +# if !defined(__STD_RWCOMPILER_H__) && !defined(_RWSTD_VER) +# error This is not the Rogue Wave standard library +# endif +#endif +// +// figure out a consistent version number: +// +#ifndef _RWSTD_VER +# define BOOST_RWSTD_VER 0x010000 +#elif _RWSTD_VER < 0x010000 +# define BOOST_RWSTD_VER (_RWSTD_VER << 8) +#else +# define BOOST_RWSTD_VER _RWSTD_VER +#endif + +#ifndef _RWSTD_VER +# define BOOST_STDLIB "Rogue Wave standard library version (Unknown version)" +#else +# define BOOST_STDLIB "Rogue Wave standard library version " BOOST_STRINGIZE(_RWSTD_VER) +#endif + +// +// Prior to version 2.2.0 the primary template for std::numeric_limits +// does not have compile time constants, even though specializations of that +// template do: +// +#if BOOST_RWSTD_VER < 0x020200 +# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +#endif + +// Sun CC 5.5 patch 113817-07 adds long long specialization, but does not change the +// library version number (http://sunsolve6.sun.com/search/document.do?assetkey=1-21-113817): +#if BOOST_RWSTD_VER <= 0x020101 && (!defined(__SUNPRO_CC) || (__SUNPRO_CC < 0x550)) +# define BOOST_NO_LONG_LONG_NUMERIC_LIMITS +# endif + +// +// Borland version of numeric_limits lacks __int64 specialisation: +// +#ifdef __BORLANDC__ +# define BOOST_NO_MS_INT64_NUMERIC_LIMITS +#endif + +// +// No std::iterator if it can't figure out default template args: +// +#if defined(_RWSTD_NO_SIMPLE_DEFAULT_TEMPLATES) || defined(RWSTD_NO_SIMPLE_DEFAULT_TEMPLATES) || (BOOST_RWSTD_VER < 0x020000) +# define BOOST_NO_STD_ITERATOR +#endif + +// +// No iterator traits without partial specialization: +// +#if defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) || defined(RWSTD_NO_CLASS_PARTIAL_SPEC) +# define BOOST_NO_STD_ITERATOR_TRAITS +#endif + +// +// Prior to version 2.0, std::auto_ptr was buggy, and there were no +// new-style iostreams, and no conformant std::allocator: +// +#if (BOOST_RWSTD_VER < 0x020000) +# define BOOST_NO_AUTO_PTR +# define BOOST_NO_STRINGSTREAM +# define BOOST_NO_STD_ALLOCATOR +# define BOOST_NO_STD_LOCALE +#endif + +// +// No template iterator constructors without member template support: +// +#if defined(RWSTD_NO_MEMBER_TEMPLATES) || defined(_RWSTD_NO_MEMBER_TEMPLATES) +# define BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS +#endif + +// +// RW defines _RWSTD_ALLOCATOR if the allocator is conformant and in use +// (the or _HPACC_ part is a hack - the library seems to define _RWSTD_ALLOCATOR +// on HP aCC systems even though the allocator is in fact broken): +// +#if !defined(_RWSTD_ALLOCATOR) || (defined(__HP_aCC) && __HP_aCC <= 33100) +# define BOOST_NO_STD_ALLOCATOR +#endif + +// +// If we have a std::locale, we still may not have std::use_facet: +// +#if defined(_RWSTD_NO_TEMPLATE_ON_RETURN_TYPE) && !defined(BOOST_NO_STD_LOCALE) +# define BOOST_NO_STD_USE_FACET +# define BOOST_HAS_TWO_ARG_USE_FACET +#endif + +// +// There's no std::distance prior to version 2, or without +// partial specialization support: +// +#if (BOOST_RWSTD_VER < 0x020000) || defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) + #define BOOST_NO_STD_DISTANCE +#endif + +// +// Some versions of the rogue wave library don't have assignable +// OutputIterators: +// +#if BOOST_RWSTD_VER < 0x020100 +# define BOOST_NO_STD_OUTPUT_ITERATOR_ASSIGN +#endif + +// +// Disable BOOST_HAS_LONG_LONG when the library has no support for it. +// +#if !defined(_RWSTD_LONG_LONG) && defined(BOOST_HAS_LONG_LONG) +# undef BOOST_HAS_LONG_LONG +#endif diff --git a/eo/contrib/boost/config/stdlib/sgi.hpp b/eo/contrib/boost/config/stdlib/sgi.hpp new file mode 100644 index 000000000..67f7a0a4b --- /dev/null +++ b/eo/contrib/boost/config/stdlib/sgi.hpp @@ -0,0 +1,111 @@ +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Darin Adler 2001. +// (C) Copyright Jens Maurer 2001 - 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// generic SGI STL: + +#if !defined(__STL_CONFIG_H) +# include +# if !defined(__STL_CONFIG_H) +# error "This is not the SGI STL!" +# endif +#endif + +// +// No std::iterator traits without partial specialisation: +// +#if !defined(__STL_CLASS_PARTIAL_SPECIALIZATION) +# define BOOST_NO_STD_ITERATOR_TRAITS +#endif + +// +// No std::stringstream with gcc < 3 +// +#if defined(__GNUC__) && (__GNUC__ < 3) && \ + ((__GNUC_MINOR__ < 95) || (__GNUC_MINOR__ == 96)) && \ + !defined(__STL_USE_NEW_IOSTREAMS) || \ + defined(__APPLE_CC__) + // Note that we only set this for GNU C++ prior to 2.95 since the + // latest patches for that release do contain a minimal + // If you are running a 2.95 release prior to 2.95.3 then this will need + // setting, but there is no way to detect that automatically (other + // than by running the configure script). + // Also, the unofficial GNU C++ 2.96 included in RedHat 7.1 doesn't + // have . +# define BOOST_NO_STRINGSTREAM +#endif + +// +// Assume no std::locale without own iostreams (this may be an +// incorrect assumption in some cases): +// +#if !defined(__SGI_STL_OWN_IOSTREAMS) && !defined(__STL_USE_NEW_IOSTREAMS) +# define BOOST_NO_STD_LOCALE +#endif + +// +// Original native SGI streams have non-standard std::messages facet: +// +#if defined(__sgi) && (_COMPILER_VERSION <= 650) && !defined(__SGI_STL_OWN_IOSTREAMS) +# define BOOST_NO_STD_LOCALE +#endif + +// +// SGI's new iostreams have missing "const" in messages<>::open +// +#if defined(__sgi) && (_COMPILER_VERSION <= 740) && defined(__STL_USE_NEW_IOSTREAMS) +# define BOOST_NO_STD_MESSAGES +#endif + +// +// No template iterator constructors, or std::allocator +// without member templates: +// +#if !defined(__STL_MEMBER_TEMPLATES) +# define BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS +# define BOOST_NO_STD_ALLOCATOR +#endif + +// +// We always have SGI style hash_set, hash_map, and slist: +// +#define BOOST_HAS_HASH +#define BOOST_HAS_SLIST + +// +// If this is GNU libstdc++2, then no and no std::wstring: +// +#if (defined(__GNUC__) && (__GNUC__ < 3)) +# include +# if defined(__BASTRING__) +# define BOOST_NO_LIMITS +// Note: will provide compile-time constants +# undef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# define BOOST_NO_STD_WSTRING +# endif +#endif + +// +// There is no standard iterator unless we have namespace support: +// +#if !defined(__STL_USE_NAMESPACES) +# define BOOST_NO_STD_ITERATOR +#endif + +// +// Intrinsic type_traits support. +// The SGI STL has it's own __type_traits class, which +// has intrinsic compiler support with SGI's compilers. +// Whatever map SGI style type traits to boost equivalents: +// +#define BOOST_HAS_SGI_TYPE_TRAITS + +#define BOOST_STDLIB "SGI standard library" + + + diff --git a/eo/contrib/boost/config/stdlib/stlport.hpp b/eo/contrib/boost/config/stdlib/stlport.hpp new file mode 100644 index 000000000..4843ea59b --- /dev/null +++ b/eo/contrib/boost/config/stdlib/stlport.hpp @@ -0,0 +1,201 @@ +// (C) Copyright John Maddock 2001 - 2002. +// (C) Copyright Darin Adler 2001. +// (C) Copyright Jens Maurer 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// STLPort standard library config: + +#if !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) +# include +# if !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION) +# error "This is not STLPort!" +# endif +#endif + +// +// __STL_STATIC_CONST_INIT_BUG implies BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +// for versions prior to 4.1(beta) +// +#if (defined(__STL_STATIC_CONST_INIT_BUG) || defined(_STLP_STATIC_CONST_INIT_BUG)) && (__SGI_STL_PORT <= 0x400) +# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +#endif + +// +// If STLport thinks that there is no partial specialisation, then there is no +// std::iterator traits: +// +#if !(defined(_STLP_CLASS_PARTIAL_SPECIALIZATION) || defined(__STL_CLASS_PARTIAL_SPECIALIZATION)) +# define BOOST_NO_STD_ITERATOR_TRAITS +#endif + +// +// No new style iostreams on GCC without STLport's iostreams enabled: +// +#if (defined(__GNUC__) && (__GNUC__ < 3)) && !(defined(__SGI_STL_OWN_IOSTREAMS) || defined(_STLP_OWN_IOSTREAMS)) +# define BOOST_NO_STRINGSTREAM +#endif + +// +// No new iostreams implies no std::locale, and no std::stringstream: +// +#if defined(__STL_NO_IOSTREAMS) || defined(__STL_NO_NEW_IOSTREAMS) || defined(_STLP_NO_IOSTREAMS) || defined(_STLP_NO_NEW_IOSTREAMS) +# define BOOST_NO_STD_LOCALE +# define BOOST_NO_STRINGSTREAM +#endif + +// +// If the streams are not native, and we have a "using ::x" compiler bug +// then the io stream facets are not available in namespace std:: +// +#ifdef _STLPORT_VERSION +# if !defined(_STLP_OWN_IOSTREAMS) && defined(_STLP_USE_NAMESPACES) && defined(BOOST_NO_USING_TEMPLATE) && !defined(__BORLANDC__) +# define BOOST_NO_STD_LOCALE +# endif +#else +# if !defined(__SGI_STL_OWN_IOSTREAMS) && defined(__STL_USE_NAMESPACES) && defined(BOOST_NO_USING_TEMPLATE) && !defined(__BORLANDC__) +# define BOOST_NO_STD_LOCALE +# endif +#endif + +// +// Without member template support enabled, their are no template +// iterate constructors, and no std::allocator: +// +#if !(defined(__STL_MEMBER_TEMPLATES) || defined(_STLP_MEMBER_TEMPLATES)) +# define BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS +# define BOOST_NO_STD_ALLOCATOR +#endif +// +// however we always have at least a partial allocator: +// +#define BOOST_HAS_PARTIAL_STD_ALLOCATOR + +#if !defined(_STLP_MEMBER_TEMPLATE_CLASSES) +# define BOOST_NO_STD_ALLOCATOR +#endif + +#if defined(_STLP_NO_MEMBER_TEMPLATE_KEYWORD) && defined(BOOST_MSVC) && (BOOST_MSVC <= 1300) +# define BOOST_NO_STD_ALLOCATOR +#endif + +// +// If STLport thinks there is no wchar_t at all, then we have to disable +// the support for the relevant specilazations of std:: templates. +// +#if !defined(_STLP_HAS_WCHAR_T) && !defined(_STLP_WCHAR_T_IS_USHORT) +# ifndef BOOST_NO_STD_WSTRING +# define BOOST_NO_STD_WSTRING +# endif +# ifndef BOOST_NO_STD_WSTREAMBUF +# define BOOST_NO_STD_WSTREAMBUF +# endif +#endif + +// +// We always have SGI style hash_set, hash_map, and slist: +// +#define BOOST_HAS_HASH +#define BOOST_HAS_SLIST + +// +// STLport does a good job of importing names into namespace std::, +// but doesn't always get them all, define BOOST_NO_STDC_NAMESPACE, since our +// workaround does not conflict with STLports: +// +// +// Harold Howe says: +// Borland switched to STLport in BCB6. Defining BOOST_NO_STDC_NAMESPACE with +// BCB6 does cause problems. If we detect C++ Builder, then don't define +// BOOST_NO_STDC_NAMESPACE +// +#if !defined(__BORLANDC__) && !defined(__DMC__) +// +// If STLport is using it's own namespace, and the real names are in +// the global namespace, then we duplicate STLport's using declarations +// (by defining BOOST_NO_STDC_NAMESPACE), we do this because STLport doesn't +// necessarily import all the names we need into namespace std:: +// +# if (defined(__STL_IMPORT_VENDOR_CSTD) \ + || defined(__STL_USE_OWN_NAMESPACE) \ + || defined(_STLP_IMPORT_VENDOR_CSTD) \ + || defined(_STLP_USE_OWN_NAMESPACE)) \ + && (defined(__STL_VENDOR_GLOBAL_CSTD) || defined (_STLP_VENDOR_GLOBAL_CSTD)) +# define BOOST_NO_STDC_NAMESPACE +# define BOOST_NO_EXCEPTION_STD_NAMESPACE +# endif +#elif defined(__BORLANDC__) && __BORLANDC__ < 0x560 +// STLport doesn't import std::abs correctly: +#include +namespace std { using ::abs; } +// and strcmp/strcpy don't get imported either ('cos they are macros) +#include +#ifdef strcpy +# undef strcpy +#endif +#ifdef strcmp +# undef strcmp +#endif +#ifdef _STLP_VENDOR_CSTD +namespace std{ using _STLP_VENDOR_CSTD::strcmp; using _STLP_VENDOR_CSTD::strcpy; } +#endif +#endif + +// +// std::use_facet may be non-standard, uses a class instead: +// +#if defined(__STL_NO_EXPLICIT_FUNCTION_TMPL_ARGS) || defined(_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) +# define BOOST_NO_STD_USE_FACET +# define BOOST_HAS_STLP_USE_FACET +#endif + +// +// If STLport thinks there are no wide functions, etc. is not working; but +// only if BOOST_NO_STDC_NAMESPACE is not defined (if it is then we do the import +// into std:: ourselves). +// +#if defined(_STLP_NO_NATIVE_WIDE_FUNCTIONS) && !defined(BOOST_NO_STDC_NAMESPACE) +# define BOOST_NO_CWCHAR +# define BOOST_NO_CWCTYPE +#endif + +// +// If STLport for some reason was configured so that it thinks that wchar_t +// is not an intrinsic type, then we have to disable the support for it as +// well (we would be missing required specializations otherwise). +// +#if !defined( _STLP_HAS_WCHAR_T) || defined(_STLP_WCHAR_T_IS_USHORT) +# undef BOOST_NO_INTRINSIC_WCHAR_T +# define BOOST_NO_INTRINSIC_WCHAR_T +#endif + +// +// Borland ships a version of STLport with C++ Builder 6 that lacks +// hashtables and the like: +// +#if defined(__BORLANDC__) && (__BORLANDC__ == 0x560) +# undef BOOST_HAS_HASH +#endif + +// +// gcc-2.95.3/STLPort does not like the using declarations we use to get ADL with std::min/max +// +#if defined(__GNUC__) && (__GNUC__ < 3) +# include // for std::min and std::max +# define BOOST_USING_STD_MIN() ((void)0) +# define BOOST_USING_STD_MAX() ((void)0) +namespace boost { using std::min; using std::max; } +#endif + +#define BOOST_STDLIB "STLPort standard library version " BOOST_STRINGIZE(__SGI_STL_PORT) + + + + + + + + diff --git a/eo/contrib/boost/config/stdlib/vacpp.hpp b/eo/contrib/boost/config/stdlib/vacpp.hpp new file mode 100644 index 000000000..8321ee0cc --- /dev/null +++ b/eo/contrib/boost/config/stdlib/vacpp.hpp @@ -0,0 +1,18 @@ +// (C) Copyright John Maddock 2001 - 2002. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +#if __IBMCPP__ <= 501 +# define BOOST_NO_STD_ALLOCATOR +#endif + +#define BOOST_HAS_MACRO_USE_FACET +#define BOOST_NO_STD_MESSAGES + +#define BOOST_STDLIB "Visual Age default standard library" + + + diff --git a/eo/contrib/boost/config/suffix.hpp b/eo/contrib/boost/config/suffix.hpp new file mode 100644 index 000000000..d4d9502d4 --- /dev/null +++ b/eo/contrib/boost/config/suffix.hpp @@ -0,0 +1,547 @@ +// Boost config.hpp configuration header file ------------------------------// + +// (C) Copyright John Maddock 2001 - 2003. +// (C) Copyright Darin Adler 2001. +// (C) Copyright Peter Dimov 2001. +// (C) Copyright Bill Kempf 2002. +// (C) Copyright Jens Maurer 2002. +// (C) Copyright David Abrahams 2002 - 2003. +// (C) Copyright Gennaro Prota 2003. +// (C) Copyright Eric Friedman 2003. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org for most recent version. + +// Boost config.hpp policy and rationale documentation has been moved to +// http://www.boost.org/libs/config +// +// This file is intended to be stable, and relatively unchanging. +// It should contain boilerplate code only - no compiler specific +// code unless it is unavoidable - no changes unless unavoidable. + +#ifndef BOOST_CONFIG_SUFFIX_HPP +#define BOOST_CONFIG_SUFFIX_HPP + +// +// look for long long by looking for the appropriate macros in . +// Note that we use limits.h rather than climits for maximal portability, +// remember that since these just declare a bunch of macros, there should be +// no namespace issues from this. +// +#include +# if !defined(BOOST_HAS_LONG_LONG) \ + && !defined(BOOST_MSVC) && !defined(__BORLANDC__) \ + && (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX)) +# define BOOST_HAS_LONG_LONG +#endif + +// TODO: Remove the following lines after the 1.33 release because the presence +// of an integral 64 bit type has nothing to do with support for long long. + +#if !defined(BOOST_HAS_LONG_LONG) && !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(__DECCXX_VER) +# define BOOST_NO_INTEGRAL_INT64_T +#endif + +// GCC 3.x will clean up all of those nasty macro definitions that +// BOOST_NO_CTYPE_FUNCTIONS is intended to help work around, so undefine +// it under GCC 3.x. +#if defined(__GNUC__) && (__GNUC__ >= 3) && defined(BOOST_NO_CTYPE_FUNCTIONS) +# undef BOOST_NO_CTYPE_FUNCTIONS +#endif + + +// +// Assume any extensions are in namespace std:: unless stated otherwise: +// +# ifndef BOOST_STD_EXTENSION_NAMESPACE +# define BOOST_STD_EXTENSION_NAMESPACE std +# endif + +// +// If cv-qualified specializations are not allowed, then neither are cv-void ones: +// +# if defined(BOOST_NO_CV_SPECIALIZATIONS) \ + && !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS) +# define BOOST_NO_CV_VOID_SPECIALIZATIONS +# endif + +// +// If there is no numeric_limits template, then it can't have any compile time +// constants either! +// +# if defined(BOOST_NO_LIMITS) \ + && !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) +# define BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# define BOOST_NO_MS_INT64_NUMERIC_LIMITS +# define BOOST_NO_LONG_LONG_NUMERIC_LIMITS +# endif + +// +// if there is no long long then there is no specialisation +// for numeric_limits either: +// +#if !defined(BOOST_HAS_LONG_LONG) && !defined(BOOST_NO_LONG_LONG_NUMERIC_LIMITS) +# define BOOST_NO_LONG_LONG_NUMERIC_LIMITS +#endif + +// +// if there is no __int64 then there is no specialisation +// for numeric_limits<__int64> either: +// +#if !defined(BOOST_HAS_MS_INT64) && !defined(BOOST_NO_MS_INT64_NUMERIC_LIMITS) +# define BOOST_NO_MS_INT64_NUMERIC_LIMITS +#endif + +// +// if member templates are supported then so is the +// VC6 subset of member templates: +// +# if !defined(BOOST_NO_MEMBER_TEMPLATES) \ + && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) +# define BOOST_MSVC6_MEMBER_TEMPLATES +# endif + +// +// Without partial specialization, can't test for partial specialisation bugs: +// +# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ + && !defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) +# define BOOST_BCB_PARTIAL_SPECIALIZATION_BUG +# endif + +// +// Without partial specialization, we can't have array-type partial specialisations: +// +# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ + && !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS) +# define BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS +# endif + +// +// Without partial specialization, std::iterator_traits can't work: +// +# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ + && !defined(BOOST_NO_STD_ITERATOR_TRAITS) +# define BOOST_NO_STD_ITERATOR_TRAITS +# endif + +// +// Without member template support, we can't have template constructors +// in the standard library either: +// +# if defined(BOOST_NO_MEMBER_TEMPLATES) \ + && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) \ + && !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) +# define BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS +# endif + +// +// Without member template support, we can't have a conforming +// std::allocator template either: +// +# if defined(BOOST_NO_MEMBER_TEMPLATES) \ + && !defined(BOOST_MSVC6_MEMBER_TEMPLATES) \ + && !defined(BOOST_NO_STD_ALLOCATOR) +# define BOOST_NO_STD_ALLOCATOR +# endif + +// +// without ADL support then using declarations will break ADL as well: +// +#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) && !defined(BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL) +# define BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL +#endif + +// +// If we have a standard allocator, then we have a partial one as well: +// +#if !defined(BOOST_NO_STD_ALLOCATOR) +# define BOOST_HAS_PARTIAL_STD_ALLOCATOR +#endif + +// +// We can't have a working std::use_facet if there is no std::locale: +// +# if defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_STD_USE_FACET) +# define BOOST_NO_STD_USE_FACET +# endif + +// +// We can't have a std::messages facet if there is no std::locale: +// +# if defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_STD_MESSAGES) +# define BOOST_NO_STD_MESSAGES +# endif + +// +// We can't have a working std::wstreambuf if there is no std::locale: +// +# if defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_STD_WSTREAMBUF) +# define BOOST_NO_STD_WSTREAMBUF +# endif + +// +// We can't have a if there is no : +// +# if defined(BOOST_NO_CWCHAR) && !defined(BOOST_NO_CWCTYPE) +# define BOOST_NO_CWCTYPE +# endif + +// +// We can't have a swprintf if there is no : +// +# if defined(BOOST_NO_CWCHAR) && !defined(BOOST_NO_SWPRINTF) +# define BOOST_NO_SWPRINTF +# endif + +// +// If Win32 support is turned off, then we must turn off +// threading support also, unless there is some other +// thread API enabled: +// +#if defined(BOOST_DISABLE_WIN32) && defined(_WIN32) \ + && !defined(BOOST_DISABLE_THREADS) && !defined(BOOST_HAS_PTHREADS) +# define BOOST_DISABLE_THREADS +#endif + +// +// Turn on threading support if the compiler thinks that it's in +// multithreaded mode. We put this here because there are only a +// limited number of macros that identify this (if there's any missing +// from here then add to the appropriate compiler section): +// +#if (defined(__MT__) || defined(_MT) || defined(_REENTRANT) \ + || defined(_PTHREADS)) && !defined(BOOST_HAS_THREADS) +# define BOOST_HAS_THREADS +#endif + +// +// Turn threading support off if BOOST_DISABLE_THREADS is defined: +// +#if defined(BOOST_DISABLE_THREADS) && defined(BOOST_HAS_THREADS) +# undef BOOST_HAS_THREADS +#endif + +// +// Turn threading support off if we don't recognise the threading API: +// +#if defined(BOOST_HAS_THREADS) && !defined(BOOST_HAS_PTHREADS)\ + && !defined(BOOST_HAS_WINTHREADS) && !defined(BOOST_HAS_BETHREADS)\ + && !defined(BOOST_HAS_MPTASKS) +# undef BOOST_HAS_THREADS +#endif + +// +// Turn threading detail macros off if we don't (want to) use threading +// +#ifndef BOOST_HAS_THREADS +# undef BOOST_HAS_PTHREADS +# undef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE +# undef BOOST_HAS_WINTHREADS +# undef BOOST_HAS_BETHREADS +# undef BOOST_HAS_MPTASKS +#endif + +// +// If the compiler claims to be C99 conformant, then it had better +// have a : +// +# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) +# define BOOST_HAS_STDINT_H +# endif + +// +// Define BOOST_NO_SLIST and BOOST_NO_HASH if required. +// Note that this is for backwards compatibility only. +// +# ifndef BOOST_HAS_SLIST +# define BOOST_NO_SLIST +# endif + +# ifndef BOOST_HAS_HASH +# define BOOST_NO_HASH +# endif + +// BOOST_HAS_ABI_HEADERS +// This macro gets set if we have headers that fix the ABI, +// and prevent ODR violations when linking to external libraries: +#if defined(BOOST_ABI_PREFIX) && defined(BOOST_ABI_SUFFIX) && !defined(BOOST_HAS_ABI_HEADERS) +# define BOOST_HAS_ABI_HEADERS +#endif + +#if defined(BOOST_HAS_ABI_HEADERS) && defined(BOOST_DISABLE_ABI_HEADERS) +# undef BOOST_HAS_ABI_HEADERS +#endif + +// BOOST_NO_STDC_NAMESPACE workaround --------------------------------------// +// Because std::size_t usage is so common, even in boost headers which do not +// otherwise use the C library, the workaround is included here so +// that ugly workaround code need not appear in many other boost headers. +// NOTE WELL: This is a workaround for non-conforming compilers; +// must still be #included in the usual places so that inclusion +// works as expected with standard conforming compilers. The resulting +// double inclusion of is harmless. + +# ifdef BOOST_NO_STDC_NAMESPACE +# include + namespace std { using ::ptrdiff_t; using ::size_t; } +# endif + +// Workaround for the unfortunate min/max macros defined by some platform headers + +#define BOOST_PREVENT_MACRO_SUBSTITUTION + +#ifndef BOOST_USING_STD_MIN +# define BOOST_USING_STD_MIN() using std::min +#endif + +#ifndef BOOST_USING_STD_MAX +# define BOOST_USING_STD_MAX() using std::max +#endif + +// BOOST_NO_STD_MIN_MAX workaround -----------------------------------------// + +# ifdef BOOST_NO_STD_MIN_MAX + +namespace std { + template + inline const _Tp& min BOOST_PREVENT_MACRO_SUBSTITUTION (const _Tp& __a, const _Tp& __b) { + return __b < __a ? __b : __a; + } + template + inline const _Tp& max BOOST_PREVENT_MACRO_SUBSTITUTION (const _Tp& __a, const _Tp& __b) { + return __a < __b ? __b : __a; + } +} + +# endif + +// BOOST_STATIC_CONSTANT workaround --------------------------------------- // +// On compilers which don't allow in-class initialization of static integral +// constant members, we must use enums as a workaround if we want the constants +// to be available at compile-time. This macro gives us a convenient way to +// declare such constants. + +# ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION +# define BOOST_STATIC_CONSTANT(type, assignment) enum { assignment } +# else +# define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment +# endif + +// BOOST_USE_FACET / HAS_FACET workaround ----------------------------------// +// When the standard library does not have a conforming std::use_facet there +// are various workarounds available, but they differ from library to library. +// The same problem occurs with has_facet. +// These macros provide a consistent way to access a locale's facets. +// Usage: +// replace +// std::use_facet(loc); +// with +// BOOST_USE_FACET(Type, loc); +// Note do not add a std:: prefix to the front of BOOST_USE_FACET! +// Use for BOOST_HAS_FACET is analagous. + +#if defined(BOOST_NO_STD_USE_FACET) +# ifdef BOOST_HAS_TWO_ARG_USE_FACET +# define BOOST_USE_FACET(Type, loc) std::use_facet(loc, static_cast(0)) +# define BOOST_HAS_FACET(Type, loc) std::has_facet(loc, static_cast(0)) +# elif defined(BOOST_HAS_MACRO_USE_FACET) +# define BOOST_USE_FACET(Type, loc) std::_USE(loc, Type) +# define BOOST_HAS_FACET(Type, loc) std::_HAS(loc, Type) +# elif defined(BOOST_HAS_STLP_USE_FACET) +# define BOOST_USE_FACET(Type, loc) (*std::_Use_facet(loc)) +# define BOOST_HAS_FACET(Type, loc) std::has_facet< Type >(loc) +# endif +#else +# define BOOST_USE_FACET(Type, loc) std::use_facet< Type >(loc) +# define BOOST_HAS_FACET(Type, loc) std::has_facet< Type >(loc) +#endif + +// BOOST_NESTED_TEMPLATE workaround ------------------------------------------// +// Member templates are supported by some compilers even though they can't use +// the A::template member syntax, as a workaround replace: +// +// typedef typename A::template rebind binder; +// +// with: +// +// typedef typename A::BOOST_NESTED_TEMPLATE rebind binder; + +#ifndef BOOST_NO_MEMBER_TEMPLATE_KEYWORD +# define BOOST_NESTED_TEMPLATE template +#else +# define BOOST_NESTED_TEMPLATE +#endif + +// BOOST_UNREACHABLE_RETURN(x) workaround -------------------------------------// +// Normally evaluates to nothing, unless BOOST_NO_UNREACHABLE_RETURN_DETECTION +// is defined, in which case it evaluates to return x; Use when you have a return +// statement that can never be reached. + +#ifdef BOOST_NO_UNREACHABLE_RETURN_DETECTION +# define BOOST_UNREACHABLE_RETURN(x) return x; +#else +# define BOOST_UNREACHABLE_RETURN(x) +#endif + +// BOOST_DEDUCED_TYPENAME workaround ------------------------------------------// +// +// Some compilers don't support the use of `typename' for dependent +// types in deduced contexts, e.g. +// +// template void f(T, typename T::type); +// ^^^^^^^^ +// Replace these declarations with: +// +// template void f(T, BOOST_DEDUCED_TYPENAME T::type); + +#ifndef BOOST_NO_DEDUCED_TYPENAME +# define BOOST_DEDUCED_TYPENAME typename +#else +# define BOOST_DEDUCED_TYPENAME +#endif + +// long long workaround ------------------------------------------// +// On gcc (and maybe other compilers?) long long is alway supported +// but it's use may generate either warnings (with -ansi), or errors +// (with -pedantic -ansi) unless it's use is prefixed by __extension__ +// +#if defined(BOOST_HAS_LONG_LONG) +namespace boost{ +# ifdef __GNUC__ + __extension__ typedef long long long_long_type; + __extension__ typedef unsigned long long ulong_long_type; +# else + typedef long long long_long_type; + typedef unsigned long long ulong_long_type; +# endif +} +#endif + +// BOOST_[APPEND_]EXPLICIT_TEMPLATE_[NON_]TYPE macros --------------------------// +// +// Some compilers have problems with function templates whose +// template parameters don't appear in the function parameter +// list (basically they just link one instantiation of the +// template in the final executable). These macros provide a +// uniform way to cope with the problem with no effects on the +// calling syntax. + +// Example: +// +// #include +// #include +// #include +// +// template +// void f() { std::cout << n << ' '; } +// +// template +// void g() { std::cout << typeid(T).name() << ' '; } +// +// int main() { +// f<1>(); +// f<2>(); +// +// g(); +// g(); +// } +// +// With VC++ 6.0 the output is: +// +// 2 2 double double +// +// To fix it, write +// +// template +// void f(BOOST_EXPLICIT_TEMPLATE_NON_TYPE(int, n)) { ... } +// +// template +// void g(BOOST_EXPLICIT_TEMPLATE_TYPE(T)) { ... } +// + + +#if defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS + +# include "boost/type.hpp" +# include "boost/non_type.hpp" + +# define BOOST_EXPLICIT_TEMPLATE_TYPE(t) boost::type* = 0 +# define BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type* +# define BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type* = 0 +# define BOOST_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type* + +# define BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \ + , BOOST_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \ + , BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \ + , BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \ + , BOOST_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + +#else + +// no workaround needed: expand to nothing + +# define BOOST_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + +# define BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + + +#endif // defined BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS + + +// ---------------------------------------------------------------------------// + +// +// Helper macro BOOST_STRINGIZE: +// Converts the parameter X to a string after macro replacement +// on X has been performed. +// +#define BOOST_STRINGIZE(X) BOOST_DO_STRINGIZE(X) +#define BOOST_DO_STRINGIZE(X) #X + +// +// Helper macro BOOST_JOIN: +// The following piece of macro magic joins the two +// arguments together, even when one of the arguments is +// itself a macro (see 16.3.1 in C++ standard). The key +// is that macro expansion of macro arguments does not +// occur in BOOST_DO_JOIN2 but does in BOOST_DO_JOIN. +// +#define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y ) +#define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y) +#define BOOST_DO_JOIN2( X, Y ) X##Y + +// +// Set some default values for compiler/library/platform names. +// These are for debugging config setup only: +// +# ifndef BOOST_COMPILER +# define BOOST_COMPILER "Unknown ISO C++ Compiler" +# endif +# ifndef BOOST_STDLIB +# define BOOST_STDLIB "Unknown ISO standard library" +# endif +# ifndef BOOST_PLATFORM +# if defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) \ + || defined(_POSIX_SOURCE) +# define BOOST_PLATFORM "Generic Unix" +# else +# define BOOST_PLATFORM "Unknown" +# endif +# endif + +#endif + + + diff --git a/eo/contrib/boost/config/user.hpp b/eo/contrib/boost/config/user.hpp new file mode 100644 index 000000000..5a4a9d477 --- /dev/null +++ b/eo/contrib/boost/config/user.hpp @@ -0,0 +1,124 @@ +// boost/config/user.hpp ---------------------------------------------------// + +// (C) Copyright John Maddock 2001. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// Do not check in modified versions of this file, +// This file may be customized by the end user, but not by boost. + +// +// Use this file to define a site and compiler specific +// configuration policy: +// + +// define this to locate a compiler config file: +// #define BOOST_COMPILER_CONFIG + +// define this to locate a stdlib config file: +// #define BOOST_STDLIB_CONFIG + +// define this to locate a platform config file: +// #define BOOST_PLATFORM_CONFIG + +// define this to disable compiler config, +// use if your compiler config has nothing to set: +// #define BOOST_NO_COMPILER_CONFIG + +// define this to disable stdlib config, +// use if your stdlib config has nothing to set: +// #define BOOST_NO_STDLIB_CONFIG + +// define this to disable platform config, +// use if your platform config has nothing to set: +// #define BOOST_NO_PLATFORM_CONFIG + +// define this to disable all config options, +// excluding the user config. Use if your +// setup is fully ISO compliant, and has no +// useful extensions, or for autoconf generated +// setups: +// #define BOOST_NO_CONFIG + +// define this to make the config "optimistic" +// about unknown compiler versions. Normally +// unknown compiler versions are assumed to have +// all the defects of the last known version, however +// setting this flag, causes the config to assume +// that unknown compiler versions are fully conformant +// with the standard: +// #define BOOST_STRICT_CONFIG + +// define this to cause the config to halt compilation +// with an #error if it encounters anything unknown -- +// either an unknown compiler version or an unknown +// compiler/platform/library: +// #define BOOST_ASSERT_CONFIG + + +// define if you want to disable threading support, even +// when available: +// #define BOOST_DISABLE_THREADS + +// define when you want to disable Win32 specific features +// even when available: +// #define BOOST_DISABLE_WIN32 + +// BOOST_DISABLE_ABI_HEADERS: Stops boost headers from including any +// prefix/suffix headers that normally control things like struct +// packing and alignment. +// #define BOOST_DISABLE_ABI_HEADERS + +// BOOST_ABI_PREFIX: A prefix header to include in place of whatever +// boost.config would normally select, any replacement should set up +// struct packing and alignment options as required. +// #define BOOST_ABI_PREFIX my-header-name + +// BOOST_ABI_SUFFIX: A suffix header to include in place of whatever +// boost.config would normally select, any replacement should undo +// the effects of the prefix header. +// #define BOOST_ABI_SUFFIX my-header-name + +// BOOST_ALL_DYN_LINK: Forces all libraries that have separate source, +// to be linked as dll's rather than static libraries on Microsoft Windows +// (this macro is used to turn on __declspec(dllimport) modifiers, so that +// the compiler knows which symbols to look for in a dll rather than in a +// static library). Note that there may be some libraries that can only +// be statically linked (Boost.Test for example) and others which may only +// be dynamically linked (Boost.Threads for example), in these cases this +// macro has no effect. +// #define BOOST_ALL_DYN_LINK + +// BOOST_WHATEVER_DYN_LINK: Forces library "whatever" to be linked as a dll +// rather than a static library on Microsoft Windows: replace the WHATEVER +// part of the macro name with the name of the library that you want to +// dynamically link to, for example use BOOST_DATE_TIME_DYN_LINK or +// BOOST_REGEX_DYN_LINK etc (this macro is used to turn on __declspec(dllimport) +// modifiers, so that the compiler knows which symbols to look for in a dll +// rather than in a static library). +// Note that there may be some libraries that can only be statically linked +// (Boost.Test for example) and others which may only be dynamically linked +// (Boost.Threads for example), in these cases this macro is unsupported. +// #define BOOST_WHATEVER_DYN_LINK + +// BOOST_ALL_NO_LIB: Tells the config system not to automatically select +// which libraries to link against. +// Normally if a compiler supports #pragma lib, then the correct library +// build variant will be automatically selected and linked against, +// simply by the act of including one of that library's headers. +// This macro turns that feature off. +// #define BOOST_ALL_NO_LIB + +// BOOST_WHATEVER_NO_LIB: Tells the config system not to automatically +// select which library to link against for library "whatever", +// replace WHATEVER in the macro name with the name of the library; +// for example BOOST_DATE_TIME_NO_LIB or BOOST_REGEX_NO_LIB. +// Normally if a compiler supports #pragma lib, then the correct library +// build variant will be automatically selected and linked against, simply +// by the act of including one of that library's headers. This macro turns +// that feature off. +// #define BOOST_WHATEVER_NO_LIB + + + diff --git a/eo/contrib/boost/limits.hpp b/eo/contrib/boost/limits.hpp new file mode 100644 index 000000000..f468dbce7 --- /dev/null +++ b/eo/contrib/boost/limits.hpp @@ -0,0 +1,143 @@ + +// (C) Copyright John maddock 1999. +// (C) David Abrahams 2002. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// use this header as a workaround for missing + +// See http://www.boost.org/libs/utility/limits.html for documentation. + +#ifndef BOOST_LIMITS +#define BOOST_LIMITS + +#include + +#ifdef BOOST_NO_LIMITS +# include +#else +# include +#endif + +#if (defined(BOOST_HAS_LONG_LONG) && defined(BOOST_NO_LONG_LONG_NUMERIC_LIMITS)) \ + || (defined(BOOST_HAS_MS_INT64) && defined(BOOST_NO_MS_INT64_NUMERIC_LIMITS)) +// Add missing specializations for numeric_limits: +#ifdef BOOST_HAS_MS_INT64 +# define BOOST_LLT __int64 +# define BOOST_ULLT unsigned __int64 +#else +# define BOOST_LLT ::boost::long_long_type +# define BOOST_ULLT ::boost::ulong_long_type +#endif + +namespace std +{ + template<> + class numeric_limits + { + public: + + BOOST_STATIC_CONSTANT(bool, is_specialized = true); +#ifdef BOOST_HAS_MS_INT64 + static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0x8000000000000000i64; } + static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0x7FFFFFFFFFFFFFFFi64; } +#elif defined(LLONG_MAX) + static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LLONG_MIN; } + static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LLONG_MAX; } +#elif defined(LONGLONG_MAX) + static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LONGLONG_MIN; } + static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return LONGLONG_MAX; } +#else + static BOOST_LLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 1LL << (sizeof(BOOST_LLT) * CHAR_BIT - 1); } + static BOOST_LLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ~(min)(); } +#endif + BOOST_STATIC_CONSTANT(int, digits = sizeof(BOOST_LLT) * CHAR_BIT -1); + BOOST_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BOOST_LLT) - 1) * 301L / 1000); + BOOST_STATIC_CONSTANT(bool, is_signed = true); + BOOST_STATIC_CONSTANT(bool, is_integer = true); + BOOST_STATIC_CONSTANT(bool, is_exact = true); + BOOST_STATIC_CONSTANT(int, radix = 2); + static BOOST_LLT epsilon() throw() { return 0; }; + static BOOST_LLT round_error() throw() { return 0; }; + + BOOST_STATIC_CONSTANT(int, min_exponent = 0); + BOOST_STATIC_CONSTANT(int, min_exponent10 = 0); + BOOST_STATIC_CONSTANT(int, max_exponent = 0); + BOOST_STATIC_CONSTANT(int, max_exponent10 = 0); + + BOOST_STATIC_CONSTANT(bool, has_infinity = false); + BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = false); + BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = false); + BOOST_STATIC_CONSTANT(bool, has_denorm = false); + BOOST_STATIC_CONSTANT(bool, has_denorm_loss = false); + static BOOST_LLT infinity() throw() { return 0; }; + static BOOST_LLT quiet_NaN() throw() { return 0; }; + static BOOST_LLT signaling_NaN() throw() { return 0; }; + static BOOST_LLT denorm_min() throw() { return 0; }; + + BOOST_STATIC_CONSTANT(bool, is_iec559 = false); + BOOST_STATIC_CONSTANT(bool, is_bounded = false); + BOOST_STATIC_CONSTANT(bool, is_modulo = false); + + BOOST_STATIC_CONSTANT(bool, traps = false); + BOOST_STATIC_CONSTANT(bool, tinyness_before = false); + BOOST_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero); + + }; + + template<> + class numeric_limits + { + public: + + BOOST_STATIC_CONSTANT(bool, is_specialized = true); +#ifdef BOOST_HAS_MS_INT64 + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0ui64; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0xFFFFFFFFFFFFFFFFui64; } +#elif defined(ULLONG_MAX) && defined(ULLONG_MIN) + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MIN; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULLONG_MAX; } +#elif defined(ULONGLONG_MAX) && defined(ULONGLONG_MIN) + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MIN; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ULONGLONG_MAX; } +#else + static BOOST_ULLT min BOOST_PREVENT_MACRO_SUBSTITUTION (){ return 0uLL; } + static BOOST_ULLT max BOOST_PREVENT_MACRO_SUBSTITUTION (){ return ~0uLL; } +#endif + BOOST_STATIC_CONSTANT(int, digits = sizeof(BOOST_LLT) * CHAR_BIT); + BOOST_STATIC_CONSTANT(int, digits10 = (CHAR_BIT * sizeof (BOOST_LLT)) * 301L / 1000); + BOOST_STATIC_CONSTANT(bool, is_signed = false); + BOOST_STATIC_CONSTANT(bool, is_integer = true); + BOOST_STATIC_CONSTANT(bool, is_exact = true); + BOOST_STATIC_CONSTANT(int, radix = 2); + static BOOST_ULLT epsilon() throw() { return 0; }; + static BOOST_ULLT round_error() throw() { return 0; }; + + BOOST_STATIC_CONSTANT(int, min_exponent = 0); + BOOST_STATIC_CONSTANT(int, min_exponent10 = 0); + BOOST_STATIC_CONSTANT(int, max_exponent = 0); + BOOST_STATIC_CONSTANT(int, max_exponent10 = 0); + + BOOST_STATIC_CONSTANT(bool, has_infinity = false); + BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = false); + BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = false); + BOOST_STATIC_CONSTANT(bool, has_denorm = false); + BOOST_STATIC_CONSTANT(bool, has_denorm_loss = false); + static BOOST_ULLT infinity() throw() { return 0; }; + static BOOST_ULLT quiet_NaN() throw() { return 0; }; + static BOOST_ULLT signaling_NaN() throw() { return 0; }; + static BOOST_ULLT denorm_min() throw() { return 0; }; + + BOOST_STATIC_CONSTANT(bool, is_iec559 = false); + BOOST_STATIC_CONSTANT(bool, is_bounded = false); + BOOST_STATIC_CONSTANT(bool, is_modulo = false); + + BOOST_STATIC_CONSTANT(bool, traps = false); + BOOST_STATIC_CONSTANT(bool, tinyness_before = false); + BOOST_STATIC_CONSTANT(float_round_style, round_style = round_toward_zero); + + }; +} +#endif + +#endif diff --git a/eo/contrib/boost/numeric/interval.hpp b/eo/contrib/boost/numeric/interval.hpp new file mode 100644 index 000000000..e6f976df0 --- /dev/null +++ b/eo/contrib/boost/numeric/interval.hpp @@ -0,0 +1,32 @@ +/* Boost interval.hpp header file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_HPP +#define BOOST_NUMERIC_INTERVAL_HPP + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#endif // BOOST_NUMERIC_INTERVAL_HPP diff --git a/eo/contrib/boost/numeric/interval/arith.hpp b/eo/contrib/boost/numeric/interval/arith.hpp new file mode 100644 index 000000000..64a8e97ee --- /dev/null +++ b/eo/contrib/boost/numeric/interval/arith.hpp @@ -0,0 +1,305 @@ +/* Boost interval/arith.hpp template implementation file + * + * Copyright 2000 Jens Maurer + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_ARITH_HPP +#define BOOST_NUMERIC_INTERVAL_ARITH_HPP + +#include +#include +#include +#include +#include +#include + +namespace boost { +namespace numeric { + +/* + * Basic arithmetic operators + */ + +template inline +const interval& operator+(const interval& x) +{ + return x; +} + +template inline +interval operator-(const interval& x) +{ + if (interval_lib::detail::test_input(x)) + return interval::empty(); + return interval(-x.upper(), -x.lower(), true); +} + +template inline +interval& interval::operator+=(const interval& r) +{ + if (interval_lib::detail::test_input(*this, r)) + set_empty(); + else { + typename Policies::rounding rnd; + set(rnd.add_down(low, r.low), rnd.add_up(up, r.up)); + } + return *this; +} + +template inline +interval& interval::operator+=(const T& r) +{ + if (interval_lib::detail::test_input(*this, r)) + set_empty(); + else { + typename Policies::rounding rnd; + set(rnd.add_down(low, r), rnd.add_up(up, r)); + } + return *this; +} + +template inline +interval& interval::operator-=(const interval& r) +{ + if (interval_lib::detail::test_input(*this, r)) + set_empty(); + else { + typename Policies::rounding rnd; + set(rnd.sub_down(low, r.up), rnd.sub_up(up, r.low)); + } + return *this; +} + +template inline +interval& interval::operator-=(const T& r) +{ + if (interval_lib::detail::test_input(*this, r)) + set_empty(); + else { + typename Policies::rounding rnd; + set(rnd.sub_down(low, r), rnd.sub_up(up, r)); + } + return *this; +} + +template inline +interval& interval::operator*=(const interval& r) +{ + return *this = *this * r; +} + +template inline +interval& interval::operator*=(const T& r) +{ + return *this = r * *this; +} + +template inline +interval& interval::operator/=(const interval& r) +{ + return *this = *this / r; +} + +template inline +interval& interval::operator/=(const T& r) +{ + return *this = *this / r; +} + +template inline +interval operator+(const interval& x, + const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + return interval(rnd.add_down(x.lower(), y.lower()), + rnd.add_up (x.upper(), y.upper()), true); +} + +template inline +interval operator+(const T& x, const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + return interval(rnd.add_down(x, y.lower()), + rnd.add_up (x, y.upper()), true); +} + +template inline +interval operator+(const interval& x, const T& y) +{ return y + x; } + +template inline +interval operator-(const interval& x, + const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + return interval(rnd.sub_down(x.lower(), y.upper()), + rnd.sub_up (x.upper(), y.lower()), true); +} + +template inline +interval operator-(const T& x, const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + return interval(rnd.sub_down(x, y.upper()), + rnd.sub_up (x, y.lower()), true); +} + +template inline +interval operator-(const interval& x, const T& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + return interval(rnd.sub_down(x.lower(), y), + rnd.sub_up (x.upper(), y), true); +} + +template inline +interval operator*(const interval& x, + const interval& y) +{ + BOOST_USING_STD_MIN(); + BOOST_USING_STD_MAX(); + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + typename Policies::rounding rnd; + const T& xl = x.lower(); + const T& xu = x.upper(); + const T& yl = y.lower(); + const T& yu = y.upper(); + + if (interval_lib::user::is_neg(xl)) + if (interval_lib::user::is_pos(xu)) + if (interval_lib::user::is_neg(yl)) + if (interval_lib::user::is_pos(yu)) // M * M + return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_down(xl, yu), rnd.mul_down(xu, yl)), + max BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.mul_up (xl, yl), rnd.mul_up (xu, yu)), true); + else // M * N + return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yl), true); + else + if (interval_lib::user::is_pos(yu)) // M * P + return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yu), true); + else // M * Z + return I(static_cast(0), static_cast(0), true); + else + if (interval_lib::user::is_neg(yl)) + if (interval_lib::user::is_pos(yu)) // N * M + return I(rnd.mul_down(xl, yu), rnd.mul_up(xl, yl), true); + else // N * N + return I(rnd.mul_down(xu, yu), rnd.mul_up(xl, yl), true); + else + if (interval_lib::user::is_pos(yu)) // N * P + return I(rnd.mul_down(xl, yu), rnd.mul_up(xu, yl), true); + else // N * Z + return I(static_cast(0), static_cast(0), true); + else + if (interval_lib::user::is_pos(xu)) + if (interval_lib::user::is_neg(yl)) + if (interval_lib::user::is_pos(yu)) // P * M + return I(rnd.mul_down(xu, yl), rnd.mul_up(xu, yu), true); + else // P * N + return I(rnd.mul_down(xu, yl), rnd.mul_up(xl, yu), true); + else + if (interval_lib::user::is_pos(yu)) // P * P + return I(rnd.mul_down(xl, yl), rnd.mul_up(xu, yu), true); + else // P * Z + return I(static_cast(0), static_cast(0), true); + else // Z * ? + return I(static_cast(0), static_cast(0), true); +} + +template inline +interval operator*(const T& x, const interval& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + typename Policies::rounding rnd; + const T& yl = y.lower(); + const T& yu = y.upper(); + // x is supposed not to be infinite + if (interval_lib::user::is_neg(x)) + return I(rnd.mul_down(x, yu), rnd.mul_up(x, yl), true); + else if (interval_lib::user::is_zero(x)) + return I(static_cast(0), static_cast(0), true); + else + return I(rnd.mul_down(x, yl), rnd.mul_up(x, yu), true); +} + +template inline +interval operator*(const interval& x, const T& y) +{ return y * x; } + +template inline +interval operator/(const interval& x, + const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + if (in_zero(y)) + if (!interval_lib::user::is_zero(y.lower())) + if (!interval_lib::user::is_zero(y.upper())) + return interval_lib::detail::div_zero(x); + else + return interval_lib::detail::div_negative(x, y.lower()); + else + if (!interval_lib::user::is_zero(y.upper())) + return interval_lib::detail::div_positive(x, y.upper()); + else + return interval::empty(); + else + return interval_lib::detail::div_non_zero(x, y); +} + +template inline +interval operator/(const T& x, const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + if (in_zero(y)) + if (!interval_lib::user::is_zero(y.lower())) + if (!interval_lib::user::is_zero(y.upper())) + return interval_lib::detail::div_zero(x); + else + return interval_lib::detail::div_negative(x, y.lower()); + else + if (!interval_lib::user::is_zero(y.upper())) + return interval_lib::detail::div_positive(x, y.upper()); + else + return interval::empty(); + else + return interval_lib::detail::div_non_zero(x, y); +} + +template inline +interval operator/(const interval& x, const T& y) +{ + if (interval_lib::detail::test_input(x, y) || interval_lib::user::is_zero(y)) + return interval::empty(); + typename Policies::rounding rnd; + const T& xl = x.lower(); + const T& xu = x.upper(); + if (interval_lib::user::is_neg(y)) + return interval(rnd.div_down(xu, y), rnd.div_up(xl, y), true); + else + return interval(rnd.div_down(xl, y), rnd.div_up(xu, y), true); +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_ARITH_HPP diff --git a/eo/contrib/boost/numeric/interval/arith2.hpp b/eo/contrib/boost/numeric/interval/arith2.hpp new file mode 100644 index 000000000..274a68119 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/arith2.hpp @@ -0,0 +1,212 @@ +/* Boost interval/arith2.hpp template implementation file + * + * This header provides some auxiliary arithmetic + * functions: fmod, sqrt, square, pov, inverse and + * a multi-interval division. + * + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_ARITH2_HPP +#define BOOST_NUMERIC_INTERVAL_ARITH2_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { +namespace numeric { + +template inline +interval fmod(const interval& x, + const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + typedef typename interval_lib::unprotect >::type I; + T const &yb = interval_lib::user::is_neg(x.lower()) ? y.lower() : y.upper(); + T n = rnd.int_down(rnd.div_down(x.lower(), yb)); + return (const I&)x - n * (const I&)y; +} + +template inline +interval fmod(const interval& x, const T& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + typedef typename interval_lib::unprotect >::type I; + T n = rnd.int_down(rnd.div_down(x.lower(), y)); + return (const I&)x - n * I(y); +} + +template inline +interval fmod(const T& x, const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + typename Policies::rounding rnd; + typedef typename interval_lib::unprotect >::type I; + T const &yb = interval_lib::user::is_neg(x) ? y.lower() : y.upper(); + T n = rnd.int_down(rnd.div_down(x, yb)); + return x - n * (const I&)y; +} + +namespace interval_lib { + +template inline +interval division_part1(const interval& x, + const interval& y, bool& b) +{ + typedef interval I; + b = false; + if (detail::test_input(x, y)) + return I::empty(); + if (in_zero(y)) + if (!user::is_zero(y.lower())) + if (!user::is_zero(y.upper())) + return detail::div_zero_part1(x, y, b); + else + return detail::div_negative(x, y.lower()); + else + if (!user::is_zero(y.upper())) + return detail::div_positive(x, y.upper()); + else + return I::empty(); + else + return detail::div_non_zero(x, y); +} + +template inline +interval division_part2(const interval& x, + const interval& y, bool b = true) +{ + if (!b) return interval::empty(); + return detail::div_zero_part2(x, y); +} + +template inline +interval multiplicative_inverse(const interval& x) +{ + typedef interval I; + if (detail::test_input(x)) + return I::empty(); + T one = static_cast(1); + typename Policies::rounding rnd; + if (in_zero(x)) { + typedef typename Policies::checking checking; + if (!user::is_zero(x.lower())) + if (!user::is_zero(x.upper())) + return I::whole(); + else + return I(checking::neg_inf(), rnd.div_up(one, x.lower()), true); + else + if (!user::is_zero(x.upper())) + return I(rnd.div_down(one, x.upper()), checking::pos_inf(), true); + else + return I::empty(); + } else + return I(rnd.div_down(one, x.upper()), rnd.div_up(one, x.lower()), true); +} + +namespace detail { + +template inline +T pow_aux(const T& x_, int pwr, Rounding& rnd) // x and pwr are positive +{ + T x = x_; + T y = (pwr & 1) ? x_ : static_cast(1); + pwr >>= 1; + while (pwr > 0) { + x = rnd.mul_up(x, x); + if (pwr & 1) y = rnd.mul_up(x, y); + pwr >>= 1; + } + return y; +} + +} // namespace detail +} // namespace interval_lib + +template inline +interval pow(const interval& x, int pwr) +{ + BOOST_USING_STD_MAX(); + using interval_lib::detail::pow_aux; + typedef interval I; + + if (interval_lib::detail::test_input(x)) + return I::empty(); + + if (pwr == 0) + if (interval_lib::user::is_zero(x.lower()) + && interval_lib::user::is_zero(x.upper())) + return I::empty(); + else + return I(static_cast(1)); + else if (pwr < 0) + return interval_lib::multiplicative_inverse(pow(x, -pwr)); + + typename Policies::rounding rnd; + + if (interval_lib::user::is_neg(x.upper())) { // [-2,-1] + T yl = pow_aux(-x.upper(), pwr, rnd); + T yu = pow_aux(-x.lower(), pwr, rnd); + if (pwr & 1) // [-2,-1]^1 + return I(-yu, -yl, true); + else // [-2,-1]^2 + return I(yl, yu, true); + } else if (interval_lib::user::is_neg(x.lower())) { // [-1,1] + if (pwr & 1) { // [-1,1]^1 + return I(-pow_aux(-x.lower(), pwr, rnd), pow_aux(x.upper(), pwr, rnd), true); + } else { // [-1,1]^2 + return I(static_cast(0), pow_aux(max BOOST_PREVENT_MACRO_SUBSTITUTION(-x.lower(), x.upper()), pwr, rnd), true); + } + } else { // [1,2] + return I(pow_aux(x.lower(), pwr, rnd), pow_aux(x.upper(), pwr, rnd), true); + } +} + +template inline +interval sqrt(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x) || interval_lib::user::is_neg(x.upper())) + return I::empty(); + typename Policies::rounding rnd; + T l = !interval_lib::user::is_pos(x.lower()) ? static_cast(0) : rnd.sqrt_down(x.lower()); + return I(l, rnd.sqrt_up(x.upper()), true); +} + +template inline +interval square(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + const T& xl = x.lower(); + const T& xu = x.upper(); + if (interval_lib::user::is_neg(xu)) + return I(rnd.mul_down(xu, xu), rnd.mul_up(xl, xl), true); + else if (interval_lib::user::is_pos(x.lower())) + return I(rnd.mul_down(xl, xl), rnd.mul_up(xu, xu), true); + else + return I(static_cast(0), (-xl > xu ? rnd.mul_up(xl, xl) : rnd.mul_up(xu, xu)), true); +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_ARITH2_HPP diff --git a/eo/contrib/boost/numeric/interval/arith3.hpp b/eo/contrib/boost/numeric/interval/arith3.hpp new file mode 100644 index 000000000..518e6182f --- /dev/null +++ b/eo/contrib/boost/numeric/interval/arith3.hpp @@ -0,0 +1,69 @@ +/* Boost interval/arith3.hpp template implementation file + * + * This headers provides arithmetical functions + * which compute an interval given some base + * numbers. The resulting interval encloses the + * real result of the arithmetic operation. + * + * Copyright 2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_ARITH3_HPP +#define BOOST_NUMERIC_INTERVAL_ARITH3_HPP + +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { + +template inline +I add(const typename I::base_type& x, const typename I::base_type& y) +{ + typedef typename I::traits_type Policies; + if (detail::test_input(x, y)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.add_down(x, y), rnd.add_up(x, y), true); +} + +template inline +I sub(const typename I::base_type& x, const typename I::base_type& y) +{ + typedef typename I::traits_type Policies; + if (detail::test_input(x, y)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.sub_down(x, y), rnd.sub_up(x, y), true); +} + +template inline +I mul(const typename I::base_type& x, const typename I::base_type& y) +{ + typedef typename I::traits_type Policies; + if (detail::test_input(x, y)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.mul_down(x, y), rnd.mul_up(x, y), true); +} + +template inline +I div(const typename I::base_type& x, const typename I::base_type& y) +{ + typedef typename I::traits_type Policies; + if (detail::test_input(x, y) || user::is_zero(y)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.div_down(x, y), rnd.div_up(x, y), true); +} + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_ARITH3_HPP diff --git a/eo/contrib/boost/numeric/interval/checking.hpp b/eo/contrib/boost/numeric/interval/checking.hpp new file mode 100644 index 000000000..2db486a0b --- /dev/null +++ b/eo/contrib/boost/numeric/interval/checking.hpp @@ -0,0 +1,130 @@ +/* Boost interval/checking.hpp template implementation file + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_CHECKING_HPP +#define BOOST_NUMERIC_INTERVAL_CHECKING_HPP + +#include +#include +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { + +struct exception_create_empty +{ + void operator()() + { + throw std::runtime_error("boost::interval: empty interval created"); + } +}; + +struct exception_invalid_number +{ + void operator()() + { + throw std::invalid_argument("boost::interval: invalid number"); + } +}; + +template +struct checking_base +{ + static T pos_inf() + { + assert(std::numeric_limits::has_infinity); + return std::numeric_limits::infinity(); + } + static T neg_inf() + { + assert(std::numeric_limits::has_infinity); + return -std::numeric_limits::infinity(); + } + static T nan() + { + assert(std::numeric_limits::has_quiet_NaN); + return std::numeric_limits::quiet_NaN(); + } + static bool is_nan(const T& x) + { + return std::numeric_limits::has_quiet_NaN && (x != x); + } + static T empty_lower() + { + return (std::numeric_limits::has_quiet_NaN ? + std::numeric_limits::quiet_NaN() : static_cast(1)); + } + static T empty_upper() + { + return (std::numeric_limits::has_quiet_NaN ? + std::numeric_limits::quiet_NaN() : static_cast(0)); + } + static bool is_empty(const T& l, const T& u) + { + return !(l <= u); // safety for partial orders + } +}; + +template, + class Exception = exception_create_empty> +struct checking_no_empty: Checking +{ + static T nan() + { + assert(false); + return Checking::nan(); + } + static T empty_lower() + { + Exception()(); + return Checking::empty_lower(); + } + static T empty_upper() + { + Exception()(); + return Checking::empty_upper(); + } + static bool is_empty(const T&, const T&) + { + return false; + } +}; + +template > +struct checking_no_nan: Checking +{ + static bool is_nan(const T&) + { + return false; + } +}; + +template, + class Exception = exception_invalid_number> +struct checking_catch_nan: Checking +{ + static bool is_nan(const T& x) + { + if (Checking::is_nan(x)) Exception()(); + return false; + } +}; + +template +struct checking_strict: + checking_no_nan > +{}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_CHECKING_HPP diff --git a/eo/contrib/boost/numeric/interval/compare.hpp b/eo/contrib/boost/numeric/interval/compare.hpp new file mode 100644 index 000000000..f21753e71 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare.hpp @@ -0,0 +1,19 @@ +/* Boost interval/compare.hpp template implementation file + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_HPP + +#include +#include +#include +#include +#include + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_HPP diff --git a/eo/contrib/boost/numeric/interval/compare/certain.hpp b/eo/contrib/boost/numeric/interval/compare/certain.hpp new file mode 100644 index 000000000..9232d5cd8 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare/certain.hpp @@ -0,0 +1,113 @@ +/* Boost interval/compare/certain.hpp template implementation file + * + * Copyright 2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_CERTAIN_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_CERTAIN_HPP + +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace compare { +namespace certain { + +template inline +bool operator<(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() < y.lower(); +} + +template inline +bool operator<(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() < y; +} + +template inline +bool operator<=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() <= y.lower(); +} + +template inline +bool operator<=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() <= y; +} + +template inline +bool operator>(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() > y.upper(); +} + +template inline +bool operator>(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() > y; +} + +template inline +bool operator>=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() >= y.upper(); +} + +template inline +bool operator>=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() >= y; +} + +template inline +bool operator==(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() == y.lower() && x.lower() == y.upper(); +} + +template inline +bool operator==(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() == y && x.lower() == y; +} + +template inline +bool operator!=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() < y.lower() || x.lower() > y.upper(); +} + +template inline +bool operator!=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() < y || x.lower() > y; +} + +} // namespace certain +} // namespace compare +} // namespace interval_lib +} // namespace numeric +} // namespace boost + + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_CERTAIN_HPP diff --git a/eo/contrib/boost/numeric/interval/compare/explicit.hpp b/eo/contrib/boost/numeric/interval/compare/explicit.hpp new file mode 100644 index 000000000..8c68be891 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare/explicit.hpp @@ -0,0 +1,248 @@ +/* Boost interval/compare/explicit.hpp template implementation file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP + +#include + +namespace boost { +namespace numeric { +namespace interval_lib { + +/* + * Certainly... operations + */ + +template inline +bool cerlt(const interval& x, const interval& y) +{ + return x.upper() < y.lower(); +} + +template inline +bool cerlt(const interval& x, const T& y) +{ + return x.upper() < y; +} + +template inline +bool cerlt(const T& x, const interval& y) +{ + return x < y.lower(); +} + +template inline +bool cerle(const interval& x, const interval& y) +{ + return x.upper() <= y.lower(); +} + +template inline +bool cerle(const interval& x, const T& y) +{ + return x.upper() <= y; +} + +template inline +bool cerle(const T& x, const interval& y) +{ + return x <= y.lower(); +} + +template inline +bool cergt(const interval& x, const interval& y) +{ + return x.lower() > y.upper(); +} + +template inline +bool cergt(const interval& x, const T& y) +{ + return x.lower() > y; +} + +template inline +bool cergt(const T& x, const interval& y) +{ + return x > y.upper(); +} + +template inline +bool cerge(const interval& x, const interval& y) +{ + return x.lower() >= y.upper(); +} + +template inline +bool cerge(const interval& x, const T& y) +{ + return x.lower() >= y; +} + +template inline +bool cerge(const T& x, const interval& y) +{ + return x >= y.upper(); +} + +template inline +bool cereq(const interval& x, const interval& y) +{ + return x.lower() == y.upper() && y.lower() == x.upper(); +} + +template inline +bool cereq(const interval& x, const T& y) +{ + return x.lower() == y && x.upper() == y; +} + +template inline +bool cereq(const T& x, const interval& y) +{ + return x == y.lower() && x == y.upper(); +} + +template inline +bool cerne(const interval& x, const interval& y) +{ + return x.upper() < y.lower() || y.upper() < x.lower(); +} + +template inline +bool cerne(const interval& x, const T& y) +{ + return x.upper() < y || y < x.lower(); +} + +template inline +bool cerne(const T& x, const interval& y) +{ + return x < y.lower() || y.upper() < x; +} + +/* + * Possibly... comparisons + */ + +template inline +bool poslt(const interval& x, const interval& y) +{ + return x.lower() < y.upper(); +} + +template inline +bool poslt(const interval& x, const T& y) +{ + return x.lower() < y; +} + +template inline +bool poslt(const T& x, const interval& y) +{ + return x < y.upper(); +} + +template inline +bool posle(const interval& x, const interval& y) +{ + return x.lower() <= y.upper(); +} + +template inline +bool posle(const interval& x, const T& y) +{ + return x.lower() <= y; +} + +template inline +bool posle(const T& x, const interval& y) +{ + return x <= y.upper(); +} + +template inline +bool posgt(const interval& x, const interval& y) +{ + return x.upper() > y.lower(); +} + +template inline +bool posgt(const interval& x, const T& y) +{ + return x.upper() > y; +} + +template inline +bool posgt(const T& x, const interval & y) +{ + return x > y.lower(); +} + +template inline +bool posge(const interval& x, const interval& y) +{ + return x.upper() >= y.lower(); +} + +template inline +bool posge(const interval& x, const T& y) +{ + return x.upper() >= y; +} + +template inline +bool posge(const T& x, const interval& y) +{ + return x >= y.lower(); +} + +template inline +bool poseq(const interval& x, const interval& y) +{ + return x.upper() >= y.lower() && y.upper() >= x.lower(); +} + +template inline +bool poseq(const interval& x, const T& y) +{ + return x.upper() >= y && y >= x.lower(); +} + +template inline +bool poseq(const T& x, const interval& y) +{ + return x >= y.lower() && y.upper() >= x; +} + +template inline +bool posne(const interval& x, const interval& y) +{ + return x.upper() != y.lower() || y.upper() != x.lower(); +} + +template inline +bool posne(const interval& x, const T& y) +{ + return x.upper() != y || y != x.lower(); +} + +template inline +bool posne(const T& x, const interval& y) +{ + return x != y.lower() || y.upper() != x; +} + +} // namespace interval_lib +} // namespace numeric +} //namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_EXPLICIT_HPP diff --git a/eo/contrib/boost/numeric/interval/compare/lexicographic.hpp b/eo/contrib/boost/numeric/interval/compare/lexicographic.hpp new file mode 100644 index 000000000..03f6036d2 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare/lexicographic.hpp @@ -0,0 +1,122 @@ +/* Boost interval/compare/lexicographic.hpp template implementation file + * + * Copyright 2002-2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP + +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace compare { +namespace lexicographic { + +template inline +bool operator<(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + const T& xl = x.lower(); + const T& yl = y.lower(); + return xl < yl || (xl == yl && x.upper() < y.upper()); +} + +template inline +bool operator<(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() < y; +} + +template inline +bool operator<=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + const T& xl = x.lower(); + const T& yl = y.lower(); + return xl < yl || (xl == yl && x.upper() <= y.upper()); +} + +template inline +bool operator<=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + const T& xl = x.lower(); + return xl < y || (xl == y && x.upper() <= y); +} + +template inline +bool operator>(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + const T& xl = x.lower(); + const T& yl = y.lower(); + return xl > yl || (xl == yl && x.upper() > y.upper()); +} + +template inline +bool operator>(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + const T& xl = x.lower(); + return xl > y || (xl == y && x.upper() > y); +} + +template inline +bool operator>=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + const T& xl = x.lower(); + const T& yl = y.lower(); + return xl > yl || (xl == yl && x.upper() >= y.upper()); +} + +template inline +bool operator>=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() >= y; +} + +template inline +bool operator==(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() == y.lower() && x.upper() == y.upper(); +} + +template inline +bool operator==(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() == y && x.upper() == y; +} + +template inline +bool operator!=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() != y.lower() || x.upper() != y.upper(); +} + +template inline +bool operator!=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() != y || x.upper() != y; +} + +} // namespace lexicographic +} // namespace compare +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_LEXICOGRAPHIC_HPP diff --git a/eo/contrib/boost/numeric/interval/compare/possible.hpp b/eo/contrib/boost/numeric/interval/compare/possible.hpp new file mode 100644 index 000000000..59bec31b9 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare/possible.hpp @@ -0,0 +1,113 @@ +/* Boost interval/compare/possible.hpp template implementation file + * + * Copyright 2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_POSSIBLE_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_POSSIBLE_HPP + +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace compare { +namespace possible { + +template inline +bool operator<(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() < y.upper(); +} + +template inline +bool operator<(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() < y; +} + +template inline +bool operator<=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() <= y.upper(); +} + +template inline +bool operator<=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() <= y; +} + +template inline +bool operator>(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() > y.lower(); +} + +template inline +bool operator>(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() > y; +} + +template inline +bool operator>=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() >= y.lower(); +} + +template inline +bool operator>=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.upper() >= y; +} + +template inline +bool operator==(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() <= y.upper() && x.upper() >= y.lower(); +} + +template inline +bool operator==(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() <= y && x.upper() >= y; +} + +template inline +bool operator!=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() != y.upper() || x.upper() != y.lower(); +} + +template inline +bool operator!=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + return x.lower() != y || x.upper() != y; +} + +} // namespace possible +} // namespace compare +} // namespace interval_lib +} // namespace numeric +} // namespace boost + + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_POSSIBLE_HPP diff --git a/eo/contrib/boost/numeric/interval/compare/set.hpp b/eo/contrib/boost/numeric/interval/compare/set.hpp new file mode 100644 index 000000000..aa4f1716b --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare/set.hpp @@ -0,0 +1,101 @@ +/* Boost interval/compare/set.hpp template implementation file + * + * Copyright 2002-2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP + +#include +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace compare { +namespace set { + +template inline +bool operator<(const interval& x, const interval& y) +{ + return proper_subset(x, y); +} + +template inline +bool operator<(const interval& x, const T& y) +{ + throw comparison_error(); +} + +template inline +bool operator<=(const interval& x, const interval& y) +{ + return subset(x, y); +} + +template inline +bool operator<=(const interval& x, const T& y) +{ + throw comparison_error(); +} + +template inline +bool operator>(const interval& x, const interval& y) +{ + return proper_subset(y, x); +} + +template inline +bool operator>(const interval& x, const T& y) +{ + throw comparison_error(); +} + +template inline +bool operator>=(const interval& x, const interval& y) +{ + return subset(y, x); +} + +template inline +bool operator>=(const interval& x, const T& y) +{ + throw comparison_error(); +} + +template inline +bool operator==(const interval& x, const interval& y) +{ + return equal(y, x); +} + +template inline +bool operator==(const interval& x, const T& y) +{ + throw comparison_error(); +} + +template inline +bool operator!=(const interval& x, const interval& y) +{ + return !equal(y, x); +} + +template inline +bool operator!=(const interval& x, const T& y) +{ + throw comparison_error(); +} + +} // namespace set +} // namespace compare +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_SET_HPP diff --git a/eo/contrib/boost/numeric/interval/compare/tribool.hpp b/eo/contrib/boost/numeric/interval/compare/tribool.hpp new file mode 100644 index 000000000..6e4a83e27 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/compare/tribool.hpp @@ -0,0 +1,138 @@ +/* Boost interval/compare/tribool.hpp template implementation file + * + * Copyright 2002-2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP +#define BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP + +#include +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace compare { +namespace tribool { + +template inline +logic::tribool operator<(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() < y.lower()) return true; + if (x.lower() >= y.upper()) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator<(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() < y) return true; + if (x.lower() >= y) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator<=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() <= y.lower()) return true; + if (x.lower() > y.upper()) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator<=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() <= y) return true; + if (x.lower() > y) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator>(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.lower() > y.upper()) return true; + if (x.upper() <= y.lower()) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator>(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.lower() > y) return true; + if (x.upper() <= y) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator>=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.lower() >= y.upper()) return true; + if (x.upper() < y.lower()) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator>=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.lower() >= y) return true; + if (x.upper() < y) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator==(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() == y.lower() && x.lower() == y.upper()) return true; + if (x.upper() < y.lower() || x.lower() > y.upper()) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator==(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() == y && x.lower() == y) return true; + if (x.upper() < y || x.lower() > y) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator!=(const interval& x, const interval& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() < y.lower() || x.lower() > y.upper()) return true; + if (x.upper() == y.lower() && x.lower() == y.upper()) return false; + return logic::indeterminate; +} + +template inline +logic::tribool operator!=(const interval& x, const T& y) +{ + if (detail::test_input(x, y)) throw comparison_error(); + if (x.upper() < y || x.lower() > y) return true; + if (x.upper() == y && x.lower() == y) return false; + return logic::indeterminate; +} + +} // namespace tribool +} // namespace compare +} // namespace interval_lib +} // namespace numeric +} // namespace boost + + +#endif // BOOST_NUMERIC_INTERVAL_COMPARE_TRIBOOL_HPP diff --git a/eo/contrib/boost/numeric/interval/constants.hpp b/eo/contrib/boost/numeric/interval/constants.hpp new file mode 100644 index 000000000..a3a42efec --- /dev/null +++ b/eo/contrib/boost/numeric/interval/constants.hpp @@ -0,0 +1,85 @@ +/* Boost interval/constants.hpp template implementation file + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP +#define BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace constants { + +// These constants should be exactly computed. +// Decimal representations wouldn't do it since the standard doesn't +// specify the rounding (even nearest) that should be used. + +static const float pi_f_l = 13176794.0f/(1<<22); +static const float pi_f_u = 13176795.0f/(1<<22); +static const double pi_d_l = (3373259426.0 + 273688.0 / (1<<21)) / (1<<30); +static const double pi_d_u = (3373259426.0 + 273689.0 / (1<<21)) / (1<<30); + +template inline T pi_lower() { return 3; } +template inline T pi_upper() { return 4; } +template inline T pi_half_lower() { return 1; } +template inline T pi_half_upper() { return 2; } +template inline T pi_twice_lower() { return 6; } +template inline T pi_twice_upper() { return 7; } + +template<> inline float pi_lower() { return pi_f_l; } +template<> inline float pi_upper() { return pi_f_u; } +template<> inline float pi_half_lower() { return pi_f_l / 2; } +template<> inline float pi_half_upper() { return pi_f_u / 2; } +template<> inline float pi_twice_lower() { return pi_f_l * 2; } +template<> inline float pi_twice_upper() { return pi_f_u * 2; } + +template<> inline double pi_lower() { return pi_d_l; } +template<> inline double pi_upper() { return pi_d_u; } +template<> inline double pi_half_lower() { return pi_d_l / 2; } +template<> inline double pi_half_upper() { return pi_d_u / 2; } +template<> inline double pi_twice_lower() { return pi_d_l * 2; } +template<> inline double pi_twice_upper() { return pi_d_u * 2; } + +template<> inline long double pi_lower() { return pi_d_l; } +template<> inline long double pi_upper() { return pi_d_u; } +template<> inline long double pi_half_lower() { return pi_d_l / 2; } +template<> inline long double pi_half_upper() { return pi_d_u / 2; } +template<> inline long double pi_twice_lower() { return pi_d_l * 2; } +template<> inline long double pi_twice_upper() { return pi_d_u * 2; } + +} // namespace constants + +template inline +I pi() +{ + typedef typename I::base_type T; + return I(constants::pi_lower(), + constants::pi_upper(), true); +} + +template inline +I pi_half() +{ + typedef typename I::base_type T; + return I(constants::pi_half_lower(), + constants::pi_half_upper(), true); +} + +template inline +I pi_twice() +{ + typedef typename I::base_type T; + return I(constants::pi_twice_lower(), + constants::pi_twice_upper(), true); +} + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_CONSTANTS_HPP diff --git a/eo/contrib/boost/numeric/interval/detail/bcc_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/bcc_rounding_control.hpp new file mode 100644 index 000000000..e3aaf046c --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/bcc_rounding_control.hpp @@ -0,0 +1,57 @@ +/* Boost interval/detail/bcc_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP + +#ifndef __BORLANDC__ +# error This header is only intended for Borland C++. +#endif + +#ifndef _M_IX86 +# error This header only works on x86 CPUs. +#endif + +#include // Borland C++ rounding control + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +#ifndef BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC +extern "C" { unsigned int _RTLENTRY _fm_init(void); } + +struct borland_workaround { + borland_workaround() { _fm_init(); } +}; + +static borland_workaround borland_workaround_exec; +#endif // BOOST_NUMERIC_INTERVAL_KEEP_EXCEPTIONS_FOR_BCC + +__inline double rint(double) +{ __emit__(0xD9); __emit__(0xFC); /* asm FRNDINT */ } + +struct x86_rounding +{ + typedef unsigned int rounding_mode; + static void get_rounding_mode(rounding_mode& mode) + { mode = _control87(0, 0); } + static void set_rounding_mode(const rounding_mode mode) + { _control87(mode, 0xffff); } + static double to_int(const double& x) { return rint(x); } +}; + +} // namespace detail +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_BCC_ROUNDING_CONTROL_HPP */ diff --git a/eo/contrib/boost/numeric/interval/detail/bugs.hpp b/eo/contrib/boost/numeric/interval/detail/bugs.hpp new file mode 100644 index 000000000..2058b9aee --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/bugs.hpp @@ -0,0 +1,79 @@ +/* Boost interval/detail/bugs.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_BUGS +#define BOOST_NUMERIC_INTERVAL_DETAIL_BUGS + +#include + +#if defined(__GLIBC__) && (defined(__USE_MISC) || defined(__USE_XOPEN_EXTENDED) || defined(__USE_ISOC99)) && !defined(__ICC) +# define BOOST_HAS_INV_HYPERBOLIC +#endif + +#ifdef BOOST_NO_STDC_NAMESPACE +# define BOOST_NUMERIC_INTERVAL_using_math(a) using ::a +# ifdef BOOST_HAS_INV_HYPERBOLIC +# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a +# endif +#else +# define BOOST_NUMERIC_INTERVAL_using_math(a) using std::a +# if defined(BOOST_HAS_INV_HYPERBOLIC) +# if defined(__GLIBCPP__) || defined(__GLIBCXX__) +# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using ::a +# else +# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) using std::a +# endif +# endif +#endif + +#if defined(__COMO__) || defined(BOOST_INTEL) +# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a +#elif defined(BOOST_NO_STDC_NAMESPACE) +# define BOOST_NUMERIC_INTERVAL_using_max(a) using ::a +#else +# define BOOST_NUMERIC_INTERVAL_using_max(a) using std::a +#endif + +#ifndef BOOST_NUMERIC_INTERVAL_using_ahyp +# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) +#endif + +#if defined(__GNUC__) && (__GNUC__ <= 2) +// cf PR c++/1981 for a description of the bug +#include +#include +namespace boost { +namespace numeric { + using std::min; + using std::max; + using std::sqrt; + using std::exp; + using std::log; + using std::cos; + using std::tan; + using std::asin; + using std::acos; + using std::atan; + using std::ceil; + using std::floor; + using std::sinh; + using std::cosh; + using std::tanh; +# undef BOOST_NUMERIC_INTERVAL_using_max +# undef BOOST_NUMERIC_INTERVAL_using_math +# define BOOST_NUMERIC_INTERVAL_using_max(a) +# define BOOST_NUMERIC_INTERVAL_using_math(a) +# undef BOOST_NUMERIC_INTERVAL_using_ahyp +# define BOOST_NUMERIC_INTERVAL_using_ahyp(a) +} // namespace numeric +} // namespace boost +#endif + +#endif // BOOST_NUMERIC_INTERVAL_DETAIL_BUGS diff --git a/eo/contrib/boost/numeric/interval/detail/c99_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/c99_rounding_control.hpp new file mode 100644 index 000000000..181d28666 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/c99_rounding_control.hpp @@ -0,0 +1,47 @@ +/* Boost interval/detail/c99_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP + +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +struct c99_rounding_control: c99_rounding +{ + template + static T force_rounding(const T& r) { volatile T r_ = r; return r_; } +}; + +} // namespace detail + +template<> +struct rounding_control: + detail::c99_rounding_control { }; + +template<> +struct rounding_control: + detail::c99_rounding_control { }; + +template<> +struct rounding_control: + detail::c99_rounding_control { }; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE + +#endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99_ROUNDING_CONTROL_HPP diff --git a/eo/contrib/boost/numeric/interval/detail/c99sub_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/c99sub_rounding_control.hpp new file mode 100644 index 000000000..571c51fcc --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/c99sub_rounding_control.hpp @@ -0,0 +1,43 @@ +/* Boost interval/detail/c99sub_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUNDING_CONTROL_HPP + +#include // ISO C 99 rounding mode control + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +extern "C" { double rint(double); } + +struct c99_rounding +{ + typedef int rounding_mode; + + static void set_rounding_mode(const rounding_mode mode) { fesetround(mode); } + static void get_rounding_mode(rounding_mode &mode) { mode = fegetround(); } + static void downward() { set_rounding_mode(FE_DOWNWARD); } + static void upward() { set_rounding_mode(FE_UPWARD); } + static void to_nearest() { set_rounding_mode(FE_TONEAREST); } + static void toward_zero() { set_rounding_mode(FE_TOWARDZERO); } + + template + static T to_int(const T& r) { return rint(r); } +}; + +} // namespace detail +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_DETAIL_C99SUB_ROUBDING_CONTROL_HPP diff --git a/eo/contrib/boost/numeric/interval/detail/division.hpp b/eo/contrib/boost/numeric/interval/detail/division.hpp new file mode 100644 index 000000000..24fb025ad --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/division.hpp @@ -0,0 +1,194 @@ +/* Boost interval/detail/division.hpp file + * + * Copyright 2003 Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP + +#include +#include +#include +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +template inline +interval div_non_zero(const interval& x, + const interval& y) +{ + // assert(!in_zero(y)); + typename Policies::rounding rnd; + typedef interval I; + const T& xl = x.lower(); + const T& xu = x.upper(); + const T& yl = y.lower(); + const T& yu = y.upper(); + if (::boost::numeric::interval_lib::user::is_neg(xu)) + if (::boost::numeric::interval_lib::user::is_neg(yu)) + return I(rnd.div_down(xu, yl), rnd.div_up(xl, yu), true); + else + return I(rnd.div_down(xl, yl), rnd.div_up(xu, yu), true); + else if (::boost::numeric::interval_lib::user::is_neg(xl)) + if (::boost::numeric::interval_lib::user::is_neg(yu)) + return I(rnd.div_down(xu, yu), rnd.div_up(xl, yu), true); + else + return I(rnd.div_down(xl, yl), rnd.div_up(xu, yl), true); + else + if (::boost::numeric::interval_lib::user::is_neg(yu)) + return I(rnd.div_down(xu, yu), rnd.div_up(xl, yl), true); + else + return I(rnd.div_down(xl, yu), rnd.div_up(xu, yl), true); +} + +template inline +interval div_non_zero(const T& x, const interval& y) +{ + // assert(!in_zero(y)); + typename Policies::rounding rnd; + typedef interval I; + const T& yl = y.lower(); + const T& yu = y.upper(); + if (::boost::numeric::interval_lib::user::is_neg(x)) + return I(rnd.div_down(x, yl), rnd.div_up(x, yu), true); + else + return I(rnd.div_down(x, yu), rnd.div_up(x, yl), true); +} + +template inline +interval div_positive(const interval& x, const T& yu) +{ + // assert(::boost::numeric::interval_lib::user::is_pos(yu)); + if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && + ::boost::numeric::interval_lib::user::is_zero(x.upper())) + return x; + typename Policies::rounding rnd; + typedef interval I; + const T& xl = x.lower(); + const T& xu = x.upper(); + typedef typename Policies::checking checking; + if (::boost::numeric::interval_lib::user::is_neg(xu)) + return I(checking::neg_inf(), rnd.div_up(xu, yu), true); + else if (::boost::numeric::interval_lib::user::is_neg(xl)) + return I(checking::neg_inf(), checking::pos_inf(), true); + else + return I(rnd.div_down(xl, yu), checking::pos_inf(), true); +} + +template inline +interval div_positive(const T& x, const T& yu) +{ + // assert(::boost::numeric::interval_lib::user::is_pos(yu)); + typedef interval I; + if (::boost::numeric::interval_lib::user::is_zero(x)) + return I(static_cast(0), static_cast(0), true); + typename Policies::rounding rnd; + typedef typename Policies::checking checking; + if (::boost::numeric::interval_lib::user::is_neg(x)) + return I(checking::neg_inf(), rnd.div_up(x, yu), true); + else + return I(rnd.div_down(x, yu), checking::pos_inf(), true); +} + +template inline +interval div_negative(const interval& x, const T& yl) +{ + // assert(::boost::numeric::interval_lib::user::is_neg(yl)); + if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && + ::boost::numeric::interval_lib::user::is_zero(x.upper())) + return x; + typename Policies::rounding rnd; + typedef interval I; + const T& xl = x.lower(); + const T& xu = x.upper(); + typedef typename Policies::checking checking; + if (::boost::numeric::interval_lib::user::is_neg(xu)) + return I(rnd.div_down(xu, yl), checking::pos_inf(), true); + else if (::boost::numeric::interval_lib::user::is_neg(xl)) + return I(checking::neg_inf(), checking::pos_inf(), true); + else + return I(checking::neg_inf(), rnd.div_up(xl, yl), true); +} + +template inline +interval div_negative(const T& x, const T& yl) +{ + // assert(::boost::numeric::interval_lib::user::is_neg(yl)); + typedef interval I; + if (::boost::numeric::interval_lib::user::is_zero(x)) + return I(static_cast(0), static_cast(0), true); + typename Policies::rounding rnd; + typedef typename Policies::checking checking; + if (::boost::numeric::interval_lib::user::is_neg(x)) + return I(rnd.div_down(x, yl), checking::pos_inf(), true); + else + return I(checking::neg_inf(), rnd.div_up(x, yl), true); +} + +template inline +interval div_zero(const interval& x) +{ + if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && + ::boost::numeric::interval_lib::user::is_zero(x.upper())) + return x; + else return interval::whole(); +} + +template inline +interval div_zero(const T& x) +{ + if (::boost::numeric::interval_lib::user::is_zero(x)) + return interval(static_cast(0), static_cast(0), true); + else return interval::whole(); +} + +template inline +interval div_zero_part1(const interval& x, + const interval& y, bool& b) +{ + // assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper())); + if (::boost::numeric::interval_lib::user::is_zero(x.lower()) && ::boost::numeric::interval_lib::user::is_zero(x.upper())) + { b = false; return x; } + typename Policies::rounding rnd; + typedef interval I; + const T& xl = x.lower(); + const T& xu = x.upper(); + const T& yl = y.lower(); + const T& yu = y.upper(); + typedef typename Policies::checking checking; + if (::boost::numeric::interval_lib::user::is_neg(xu)) + { b = true; return I(checking::neg_inf(), rnd.div_up(xu, yu), true); } + else if (::boost::numeric::interval_lib::user::is_neg(xl)) + { b = false; return I(checking::neg_inf(), checking::pos_inf(), true); } + else + { b = true; return I(checking::neg_inf(), rnd.div_up(xl, yl), true); } +} + +template inline +interval div_zero_part2(const interval& x, + const interval& y) +{ + // assert(::boost::numeric::interval_lib::user::is_neg(y.lower()) && ::boost::numeric::interval_lib::user::is_pos(y.upper()) && (div_zero_part1(x, y, b), b)); + typename Policies::rounding rnd; + typedef interval I; + typedef typename Policies::checking checking; + if (::boost::numeric::interval_lib::user::is_neg(x.upper())) + return I(rnd.div_down(x.upper(), y.lower()), checking::pos_inf(), true); + else + return I(rnd.div_down(x.lower(), y.upper()), checking::pos_inf(), true); +} + +} // namespace detail +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_DETAIL_DIVISION_HPP diff --git a/eo/contrib/boost/numeric/interval/detail/interval_prototype.hpp b/eo/contrib/boost/numeric/interval/detail/interval_prototype.hpp new file mode 100644 index 000000000..ac9029b70 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/interval_prototype.hpp @@ -0,0 +1,41 @@ +/* Boost interval/detail/interval_prototype.hpp file + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP + +namespace boost { +namespace numeric { + +namespace interval_lib { + +template struct rounded_math; +template struct checking_strict; +class comparison_error; +template struct policies; + +/* + * default policies class + */ + +template +struct default_policies +{ + typedef policies, checking_strict > type; +}; + +} // namespace interval_lib + +template::type > +class interval; + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_DETAIL_INTERVAL_PROTOTYPE_HPP diff --git a/eo/contrib/boost/numeric/interval/detail/msvc_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/msvc_rounding_control.hpp new file mode 100644 index 000000000..2068c934c --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/msvc_rounding_control.hpp @@ -0,0 +1,88 @@ +/* Boost interval/detail/msvc_rounding_control.hpp file + * + * Copyright 2000 Maarten Keijzer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP + +#ifndef _MSC_VER +# error This header is only intended for MSVC, but might work for Borland as well +#endif + +#include // MSVC rounding control + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +extern "C" { double rint(double); } + +struct x86_rounding +{ + static unsigned int hard2msvc(unsigned short m) { + unsigned int n = 0; + if (m & 0x01) n |= _EM_INVALID; + if (m & 0x02) n |= _EM_DENORMAL; + if (m & 0x04) n |= _EM_ZERODIVIDE; + if (m & 0x08) n |= _EM_OVERFLOW; + if (m & 0x10) n |= _EM_UNDERFLOW; + if (m & 0x20) n |= _EM_INEXACT; + switch (m & 0x300) { + case 0x000: n |= _PC_24; break; + case 0x200: n |= _PC_53; break; + case 0x300: n |= _PC_64; break; + } + switch (m & 0xC00) { + case 0x000: n |= _RC_NEAR; break; + case 0x400: n |= _RC_DOWN; break; + case 0x800: n |= _RC_UP; break; + case 0xC00: n |= _RC_CHOP; break; + } + if (m & 0x1000) n |= _IC_AFFINE; // only useful on 287 + return n; + } + + static unsigned short msvc2hard(unsigned int n) { + unsigned short m = 0; + if (n & _EM_INVALID) m |= 0x01; + if (n & _EM_DENORMAL) m |= 0x02; + if (n & _EM_ZERODIVIDE) m |= 0x04; + if (n & _EM_OVERFLOW) m |= 0x08; + if (n & _EM_UNDERFLOW) m |= 0x10; + if (n & _EM_INEXACT) m |= 0x20; + switch (n & _MCW_RC) { + case _RC_NEAR: m |= 0x000; break; + case _RC_DOWN: m |= 0x400; break; + case _RC_UP: m |= 0x800; break; + case _RC_CHOP: m |= 0xC00; break; + } + switch (n & _MCW_PC) { + case _PC_24: m |= 0x000; break; + case _PC_53: m |= 0x200; break; + case _PC_64: m |= 0x300; break; + } + if ((n & _MCW_IC) == _IC_AFFINE) m |= 0x1000; + return m; + } + + typedef unsigned short rounding_mode; + static void get_rounding_mode(rounding_mode& mode) + { mode = msvc2hard(_control87(0, 0)); } + static void set_rounding_mode(const rounding_mode mode) + { _control87(hard2msvc(mode), _MCW_EM | _MCW_RC | _MCW_PC | _MCW_IC); } + static double to_int(const double& x) { return rint(x); } +}; + +} // namespace detail +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_MSVC_ROUNDING_CONTROL_HPP */ diff --git a/eo/contrib/boost/numeric/interval/detail/ppc_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/ppc_rounding_control.hpp new file mode 100644 index 000000000..400522a75 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/ppc_rounding_control.hpp @@ -0,0 +1,95 @@ +/* Boost interval/detail/ppc_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * Copyright 2005 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP + +#if !defined(powerpc) && !defined(__powerpc__) && !defined(__ppc__) +#error This header only works on PPC CPUs. +#endif + +#if defined(__GNUC__ ) || (__IBMCPP__ >= 700) + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +typedef union { + ::boost::long_long_type imode; + double dmode; +} rounding_mode_struct; + +static const rounding_mode_struct mode_upward = { 0xFFF8000000000002LL }; +static const rounding_mode_struct mode_downward = { 0xFFF8000000000003LL }; +static const rounding_mode_struct mode_to_nearest = { 0xFFF8000000000001LL }; +static const rounding_mode_struct mode_toward_zero = { 0xFFF8000000000000LL }; + +struct ppc_rounding_control +{ + typedef double rounding_mode; + + static void set_rounding_mode(const rounding_mode mode) + { __asm__ __volatile__ ("mtfsf 255,%0" : : "f"(mode)); } + + static void get_rounding_mode(rounding_mode& mode) + { __asm__ __volatile__ ("mffs %0" : "=f"(mode)); } + + static void downward() { set_rounding_mode(mode_downward.dmode); } + static void upward() { set_rounding_mode(mode_upward.dmode); } + static void to_nearest() { set_rounding_mode(mode_to_nearest.dmode); } + static void toward_zero() { set_rounding_mode(mode_toward_zero.dmode); } +}; + +} // namespace detail + +extern "C" { + float rintf(float); + double rint(double); +} + +template<> +struct rounding_control: + detail::ppc_rounding_control +{ + static float force_rounding(const float r) + { + float tmp; + __asm__ __volatile__ ("frsp %0, %1" : "=f" (tmp) : "f" (r)); + return tmp; + } + static float to_int(const float& x) { return rintf(x); } +}; + +template<> +struct rounding_control: + detail::ppc_rounding_control +{ + static const double & force_rounding(const double& r) { return r; } + static double to_int(const double& r) { return rint(r); } +}; + +template<> +struct rounding_control: + detail::ppc_rounding_control +{ + static const long double & force_rounding(const long double& r) { return r; } + static long double to_int(const long double& r) { return rint(r); } +}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE +#endif + +#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_PPC_ROUNDING_CONTROL_HPP */ diff --git a/eo/contrib/boost/numeric/interval/detail/sparc_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/sparc_rounding_control.hpp new file mode 100644 index 000000000..6ba5baf03 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/sparc_rounding_control.hpp @@ -0,0 +1,112 @@ +/* Boost interval/detail/sparc_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + * + * The basic code in this file was kindly provided by Jeremy Siek. + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP + +#if !defined(sparc) && !defined(__sparc__) +# error This header is only intended for SPARC CPUs. +#endif + +#ifdef __SUNPRO_CC +# include +#endif + + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +struct sparc_rounding_control +{ + typedef unsigned int rounding_mode; + + static void set_rounding_mode(const rounding_mode& mode) + { +# if defined(__GNUC__) + __asm__ __volatile__("ld %0, %%fsr" : : "m"(mode)); +# elif defined (__SUNPRO_CC) + fpsetround(fp_rnd(mode)); +# elif defined(__KCC) + asm("sethi %hi(mode), %o1"); + asm("ld [%o1+%lo(mode)], %fsr"); +# else +# error Unsupported compiler for Sparc rounding control. +# endif + } + + static void get_rounding_mode(rounding_mode& mode) + { +# if defined(__GNUC__) + __asm__ __volatile__("st %%fsr, %0" : "=m"(mode)); +# elif defined (__SUNPRO_CC) + mode = fpgetround(); +# elif defined(__KCC) +# error KCC on Sun SPARC get_round_mode: please fix me + asm("st %fsr, [mode]"); +# else +# error Unsupported compiler for Sparc rounding control. +# endif + } + +#if defined(__SUNPRO_CC) + static void downward() { set_rounding_mode(FP_RM); } + static void upward() { set_rounding_mode(FP_RP); } + static void to_nearest() { set_rounding_mode(FP_RN); } + static void toward_zero() { set_rounding_mode(FP_RZ); } +#else + static void downward() { set_rounding_mode(0xc0000000); } + static void upward() { set_rounding_mode(0x80000000); } + static void to_nearest() { set_rounding_mode(0x00000000); } + static void toward_zero() { set_rounding_mode(0x40000000); } +#endif +}; + +} // namespace detail + +extern "C" { + float rintf(float); + double rint(double); +} + +template<> +struct rounding_control: + detail::sparc_rounding_control +{ + static const float& force_rounding(const float& x) { return x; } + static float to_int(const float& x) { return rintf(x); } +}; + +template<> +struct rounding_control: + detail::sparc_rounding_control +{ + static const double& force_rounding(const double& x) { return x; } + static double to_int(const double& x) { return rint(x); } +}; + +template<> +struct rounding_control: + detail::sparc_rounding_control +{ + static const long double& force_rounding(const long double& x) { return x; } + static long double to_int(const long double& x) { return rint(x); } +}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE + +#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_SPARC_ROUNDING_CONTROL_HPP */ diff --git a/eo/contrib/boost/numeric/interval/detail/test_input.hpp b/eo/contrib/boost/numeric/interval/detail/test_input.hpp new file mode 100644 index 000000000..58695fec3 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/test_input.hpp @@ -0,0 +1,76 @@ +/* Boost interval/detail/test_input.hpp file + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP + +#include + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace user { + +template inline +bool is_zero(T const &v) { return v == static_cast(0); } + +template inline +bool is_neg (T const &v) { return v < static_cast(0); } + +template inline +bool is_pos (T const &v) { return v > static_cast(0); } + +} // namespace user + +namespace detail { + +template inline +bool test_input(const interval& x) { + typedef typename Policies::checking checking; + return checking::is_empty(x.lower(), x.upper()); +} + +template inline +bool test_input(const interval& x, const interval& y) { + typedef typename Policies1::checking checking1; + typedef typename Policies2::checking checking2; + return checking1::is_empty(x.lower(), x.upper()) || + checking2::is_empty(y.lower(), y.upper()); +} + +template inline +bool test_input(const T& x, const interval& y) { + typedef typename Policies::checking checking; + return checking::is_nan(x) || checking::is_empty(y.lower(), y.upper()); +} + +template inline +bool test_input(const interval& x, const T& y) { + typedef typename Policies::checking checking; + return checking::is_empty(x.lower(), x.upper()) || checking::is_nan(y); +} + +template inline +bool test_input(const T& x) { + typedef typename Policies::checking checking; + return checking::is_nan(x); +} + +template inline +bool test_input(const T& x, const T& y) { + typedef typename Policies::checking checking; + return checking::is_nan(x) || checking::is_nan(y); +} + +} // namespace detail +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_DETAIL_TEST_INPUT_HPP diff --git a/eo/contrib/boost/numeric/interval/detail/x86_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/x86_rounding_control.hpp new file mode 100644 index 000000000..3eebdbac5 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/x86_rounding_control.hpp @@ -0,0 +1,108 @@ +/* Boost interval/detail/x86_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP + +#ifdef __GNUC__ +# include +#elif defined(__BORLANDC__) +# include +#elif defined(_MSC_VER) +# include +#elif defined(__MWERKS__) || defined(__ICC) +# define BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM +# include +#else +# error Unsupported C++ compiler. +#endif + +namespace boost { +namespace numeric { +namespace interval_lib { + +namespace detail { + +#ifdef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM +typedef c99_rounding x86_rounding_control; +#undef BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM +#else +struct fpu_rounding_modes +{ + unsigned short to_nearest; + unsigned short downward; + unsigned short upward; + unsigned short toward_zero; +}; + +// exceptions masked, extended precision +// hardware default is 0x037f (0x1000 only has a meaning on 287) +static const fpu_rounding_modes rnd_mode = { 0x137f, 0x177f, 0x1b7f, 0x1f7f }; + +struct x86_rounding_control: x86_rounding +{ + static void to_nearest() { set_rounding_mode(rnd_mode.to_nearest); } + static void downward() { set_rounding_mode(rnd_mode.downward); } + static void upward() { set_rounding_mode(rnd_mode.upward); } + static void toward_zero() { set_rounding_mode(rnd_mode.toward_zero); } +}; +#endif // BOOST_NUMERIC_INTERVAL_USE_C99_SUBSYSTEM + +} // namespace detail + +template<> +struct rounding_control: detail::x86_rounding_control +{ + static float force_rounding(const float& r) + { volatile float r_ = r; return r_; } +}; + +template<> +struct rounding_control: detail::x86_rounding_control +{ + /*static double force_rounding(double r) + { asm volatile ("" : "+m"(r) : ); return r; }*/ + static double force_rounding(const double& r) + { volatile double r_ = r; return r_; } +}; + +namespace detail { + +template +struct x86_rounding_control_long_double; + +template<> +struct x86_rounding_control_long_double: x86_rounding_control +{ + static long double force_rounding(long double const &r) + { volatile long double r_ = r; return r_; } +}; + +template<> +struct x86_rounding_control_long_double: x86_rounding_control +{ + static long double const &force_rounding(long double const &r) + { return r; } +}; + +} // namespace detail + +template<> +struct rounding_control: + detail::x86_rounding_control_long_double< (sizeof(long double) >= 10) > +{}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE + +#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86_ROUNDING_CONTROL_HPP */ diff --git a/eo/contrib/boost/numeric/interval/detail/x86gcc_rounding_control.hpp b/eo/contrib/boost/numeric/interval/detail/x86gcc_rounding_control.hpp new file mode 100644 index 000000000..079d681df --- /dev/null +++ b/eo/contrib/boost/numeric/interval/detail/x86gcc_rounding_control.hpp @@ -0,0 +1,51 @@ +/* Boost interval/detail/x86gcc_rounding_control.hpp file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP + +#ifndef __GNUC__ +# error This header only works with GNU CC. +#endif + +#ifndef __i386__ +# error This header only works on x86 CPUs. +#endif + +namespace boost { +namespace numeric { +namespace interval_lib { +namespace detail { + +struct x86_rounding +{ + typedef unsigned short rounding_mode; + + static void set_rounding_mode(const rounding_mode& mode) + { __asm__ __volatile__ ("fldcw %0" : : "m"(mode)); } + + static void get_rounding_mode(rounding_mode& mode) + { __asm__ __volatile__ ("fnstcw %0" : "=m"(mode)); } + + template + static T to_int(T r) + { + T r_; + __asm__ ("frndint" : "=&t"(r_) : "0"(r)); + return r_; + } +}; + +} // namespace detail +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif /* BOOST_NUMERIC_INTERVAL_DETAIL_X86GCC_ROUNDING_CONTROL_HPP */ diff --git a/eo/contrib/boost/numeric/interval/ext/integer.hpp b/eo/contrib/boost/numeric/interval/ext/integer.hpp new file mode 100644 index 000000000..628a343ac --- /dev/null +++ b/eo/contrib/boost/numeric/interval/ext/integer.hpp @@ -0,0 +1,70 @@ +/* Boost interval/ext/integer.hpp template implementation file + * + * Copyright 2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_EXT_INTEGER_HPP +#define BOOST_NUMERIC_INTERVAL_EXT_INTEGER_HPP + +#include +#include + +namespace boost { +namespace numeric { + +template inline +interval operator+ (const interval& x, int y) +{ + return x + static_cast(y); +} + +template inline +interval operator+ (int x, const interval& y) +{ + return static_cast(x) + y; +} + +template inline +interval operator- (const interval& x, int y) +{ + return x - static_cast(y); +} + +template inline +interval operator- (int x, const interval& y) +{ + return static_cast(x) - y; +} + +template inline +interval operator* (const interval& x, int y) +{ + return x * static_cast(y); +} + +template inline +interval operator* (int x, const interval& y) +{ + return static_cast(x) * y; +} + +template inline +interval operator/ (const interval& x, int y) +{ + return x / static_cast(y); +} + +template inline +interval operator/ (int x, const interval& y) +{ + return static_cast(x) / y; +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_EXT_INTEGER_HPP diff --git a/eo/contrib/boost/numeric/interval/ext/x86_fast_rounding_control.hpp b/eo/contrib/boost/numeric/interval/ext/x86_fast_rounding_control.hpp new file mode 100644 index 000000000..7f89a4e54 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/ext/x86_fast_rounding_control.hpp @@ -0,0 +1,70 @@ +/* Boost interval/detail/x86gcc_rounding_control.hpp file + * + * This header provides a rounding control policy + * that avoids flushing results to memory. In + * order for this optimization to be reliable, it + * should be used only when no underflow or + * overflow would happen without it. Indeed, only + * values in range are correctly rounded. + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP +#define BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP + +namespace boost { +namespace numeric { +namespace interval_lib { + +namespace detail { + +// exceptions masked, expected precision (the mask is 0x0300) +static const fpu_rounding_modes rnd_mode_f = { 0x107f, 0x147f, 0x187f, 0x1c7f }; +static const fpu_rounding_modes rnd_mode_d = { 0x127f, 0x167f, 0x1a7f, 0x1e7f }; +static const fpu_rounding_modes rnd_mode_l = { 0x137f, 0x177f, 0x1b7f, 0x1f7f }; + +} // namespace detail + +template +struct x86_fast_rounding_control; + +template<> +struct x86_fast_rounding_control: detail::x86_rounding +{ + static void to_nearest() { set_rounding_mode(detail::rnd_mode_f.to_nearest); } + static void downward() { set_rounding_mode(detail::rnd_mode_f.downward); } + static void upward() { set_rounding_mode(detail::rnd_mode_f.upward); } + static void toward_zero() { set_rounding_mode(detail::rnd_mode_f.toward_zero); } + static const float& force_rounding(const float& r) { return r; } +}; + +template<> +struct x86_fast_rounding_control: detail::x86_rounding +{ + static void to_nearest() { set_rounding_mode(detail::rnd_mode_d.to_nearest); } + static void downward() { set_rounding_mode(detail::rnd_mode_d.downward); } + static void upward() { set_rounding_mode(detail::rnd_mode_d.upward); } + static void toward_zero() { set_rounding_mode(detail::rnd_mode_d.toward_zero); } + static const double& force_rounding(const double& r) { return r; } +}; + +template<> +struct x86_fast_rounding_control: detail::x86_rounding +{ + static void to_nearest() { set_rounding_mode(detail::rnd_mode_l.to_nearest); } + static void downward() { set_rounding_mode(detail::rnd_mode_l.downward); } + static void upward() { set_rounding_mode(detail::rnd_mode_l.upward); } + static void toward_zero() { set_rounding_mode(detail::rnd_mode_l.toward_zero); } + static const long double& force_rounding(const long double& r) { return r; } +}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_EXT_X86_FAST_ROUNDING_CONTROL_HPP diff --git a/eo/contrib/boost/numeric/interval/hw_rounding.hpp b/eo/contrib/boost/numeric/interval/hw_rounding.hpp new file mode 100644 index 000000000..ed225d405 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/hw_rounding.hpp @@ -0,0 +1,64 @@ +/* Boost interval/hw_rounding.hpp template implementation file + * + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * Copyright 2005 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP +#define BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP + +#include +#include + +#define BOOST_NUMERIC_INTERVAL_NO_HARDWARE + +// define appropriate specialization of rounding_control for built-in types +#if defined(__i386__) || defined(_M_IX86) || defined(__BORLANDC__) +# include +#elif defined(powerpc) || defined(__powerpc__) || defined(__ppc__) +# include +#elif defined(sparc) || defined(__sparc__) +# include +#endif + +#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE) && (defined(__USE_ISOC99) || defined(__MSL__)) +# include +#endif + +#if defined(BOOST_NUMERIC_INTERVAL_NO_HARDWARE) +# undef BOOST_NUMERIC_INTERVAL_NO_HARDWARE +# error Boost.Numeric.Interval: Please specify rounding control mechanism. +#endif + +namespace boost { +namespace numeric { +namespace interval_lib { + +/* + * Three specializations of rounded_math + */ + +template<> +struct rounded_math + : save_state > +{}; + +template<> +struct rounded_math + : save_state > +{}; + +template<> +struct rounded_math + : save_state > +{}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_HW_ROUNDING_HPP diff --git a/eo/contrib/boost/numeric/interval/interval.hpp b/eo/contrib/boost/numeric/interval/interval.hpp new file mode 100644 index 000000000..0b2d0eec6 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/interval.hpp @@ -0,0 +1,450 @@ +/* Boost interval/interval.hpp header file + * + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_INTERVAL_HPP +#define BOOST_NUMERIC_INTERVAL_INTERVAL_HPP + +#include +#include +#include + +namespace boost { +namespace numeric { + +namespace interval_lib { + +class comparison_error + : public std::runtime_error +{ +public: + comparison_error() + : std::runtime_error("boost::interval: uncertain comparison") + { } +}; + +} // namespace interval_lib + +/* + * interval class + */ + +template +class interval +{ +private: + struct interval_holder; + struct number_holder; +public: + typedef T base_type; + typedef Policies traits_type; + + T const &lower() const; + T const &upper() const; + + interval(); + interval(T const &v); + template interval(T1 const &v); + interval(T const &l, T const &u); + template interval(T1 const &l, T2 const &u); + interval(interval const &r); + template interval(interval const &r); + template interval(interval const &r); + + interval &operator=(T const &v); + template interval &operator=(T1 const &v); + interval &operator=(interval const &r); + template interval &operator=(interval const &r); + template interval &operator=(interval const &r); + + void assign(const T& l, const T& u); + + static interval empty(); + static interval whole(); + static interval hull(const T& x, const T& y); + + interval& operator+= (const T& r); + interval& operator+= (const interval& r); + interval& operator-= (const T& r); + interval& operator-= (const interval& r); + interval& operator*= (const T& r); + interval& operator*= (const interval& r); + interval& operator/= (const T& r); + interval& operator/= (const interval& r); + + bool operator< (const interval_holder& r) const; + bool operator> (const interval_holder& r) const; + bool operator<= (const interval_holder& r) const; + bool operator>= (const interval_holder& r) const; + bool operator== (const interval_holder& r) const; + bool operator!= (const interval_holder& r) const; + + bool operator< (const number_holder& r) const; + bool operator> (const number_holder& r) const; + bool operator<= (const number_holder& r) const; + bool operator>= (const number_holder& r) const; + bool operator== (const number_holder& r) const; + bool operator!= (const number_holder& r) const; + + // the following is for internal use only, it is not a published interface + // nevertheless, it's public because friends don't always work correctly. + interval(const T& l, const T& u, bool): low(l), up(u) {} + void set_empty(); + void set_whole(); + void set(const T& l, const T& u); + +private: + struct interval_holder { + template + interval_holder(const interval& r) + : low(r.lower()), up(r.upper()) + { + typedef typename Policies2::checking checking2; + if (checking2::is_empty(low, up)) + throw interval_lib::comparison_error(); + } + + const T& low; + const T& up; + }; + + struct number_holder { + number_holder(const T& r) : val(r) + { + typedef typename Policies::checking checking; + if (checking::is_nan(r)) + throw interval_lib::comparison_error(); + } + + const T& val; + }; + + typedef typename Policies::checking checking; + typedef typename Policies::rounding rounding; + + T low; + T up; +}; + +template inline +interval::interval(): + low(static_cast(0)), up(static_cast(0)) +{} + +template inline +interval::interval(T const &v): low(v), up(v) +{ + if (checking::is_nan(v)) set_empty(); +} + +template template inline +interval::interval(T1 const &v) +{ + if (checking::is_nan(v)) set_empty(); + else { + rounding rnd; + low = rnd.conv_down(v); + up = rnd.conv_up (v); + } +} + +template template inline +interval::interval(T1 const &l, T2 const &u) +{ + if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u)) set_empty(); + else { + rounding rnd; + low = rnd.conv_down(l); + up = rnd.conv_up (u); + } +} + +template inline +interval::interval(T const &l, T const &u): low(l), up(u) +{ + if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u)) + set_empty(); +} + + +template inline +interval::interval(interval const &r): low(r.lower()), up(r.upper()) +{} + +template template inline +interval::interval(interval const &r): low(r.lower()), up(r.upper()) +{ + typedef typename Policies1::checking checking1; + if (checking1::is_empty(r.lower(), r.upper())) set_empty(); +} + +template template inline +interval::interval(interval const &r) +{ + typedef typename Policies1::checking checking1; + if (checking1::is_empty(r.lower(), r.upper())) set_empty(); + else { + rounding rnd; + low = rnd.conv_down(r.lower()); + up = rnd.conv_up (r.upper()); + } +} + +template inline +interval &interval::operator=(T const &v) +{ + if (checking::is_nan(v)) set_empty(); + else low = up = v; + return *this; +} + +template template inline +interval &interval::operator=(T1 const &v) +{ + if (checking::is_nan(v)) set_empty(); + else { + rounding rnd; + low = rnd.conv_down(v); + up = rnd.conv_up (v); + } + return *this; +} + +template inline +interval &interval::operator=(interval const &r) +{ + low = r.lower(); + up = r.upper(); + return *this; +} + +template template inline +interval &interval::operator=(interval const &r) +{ + typedef typename Policies1::checking checking1; + if (checking1::is_empty(r.lower(), r.upper())) set_empty(); + else { + low = r.lower(); + up = r.upper(); + } + return *this; +} + +template template inline +interval &interval::operator=(interval const &r) +{ + typedef typename Policies1::checking checking1; + if (checking1::is_empty(r.lower(), r.upper())) set_empty(); + else { + rounding rnd; + low = rnd.conv_down(r.lower()); + up = rnd.conv_up (r.upper()); + } + return *this; +} + +template inline +void interval::assign(const T& l, const T& u) +{ + if (checking::is_nan(l) || checking::is_nan(u) || !(l <= u)) + set_empty(); + else set(l, u); +} + +template inline +void interval::set(const T& l, const T& u) +{ + low = l; + up = u; +} + +template inline +void interval::set_empty() +{ + low = checking::empty_lower(); + up = checking::empty_upper(); +} + +template inline +void interval::set_whole() +{ + low = checking::neg_inf(); + up = checking::pos_inf(); +} + +template inline +interval interval::hull(const T& x, const T& y) +{ + bool bad_x = checking::is_nan(x); + bool bad_y = checking::is_nan(y); + if (bad_x) + if (bad_y) return interval::empty(); + else return interval(y, y, true); + else + if (bad_y) return interval(x, x, true); + if (x <= y) return interval(x, y, true); + else return interval(y, x, true); +} + +template inline +interval interval::empty() +{ + return interval(checking::empty_lower(), + checking::empty_upper(), true); +} + +template inline +interval interval::whole() +{ + return interval(checking::neg_inf(), checking::pos_inf(), true); +} + +template inline +const T& interval::lower() const +{ + return low; +} + +template inline +const T& interval::upper() const +{ + return up; +} + +/* + * interval/interval comparisons + */ + +template inline +bool interval::operator< (const interval_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up < r.low) return true; + else if (low >= r.up) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator> (const interval_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (low > r.up) return true; + else if (up <= r.low) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator<= (const interval_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up <= r.low) return true; + else if (low > r.up) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator>= (const interval_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (low >= r.up) return true; + else if (up < r.low) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator== (const interval_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up == r.low && low == r.up) return true; + else if (up < r.low || low > r.up) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator!= (const interval_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up < r.low || low > r.up) return true; + else if (up == r.low && low == r.up) return false; + } + throw interval_lib::comparison_error(); +} + +/* + * interval/number comparisons + */ + +template inline +bool interval::operator< (const number_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up < r.val) return true; + else if (low >= r.val) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator> (const number_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (low > r.val) return true; + else if (up <= r.val) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator<= (const number_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up <= r.val) return true; + else if (low > r.val) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator>= (const number_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (low >= r.val) return true; + else if (up < r.val) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator== (const number_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up == r.val && low == r.val) return true; + else if (up < r.val || low > r.val) return false; + } + throw interval_lib::comparison_error(); +} + +template inline +bool interval::operator!= (const number_holder& r) const +{ + if (!checking::is_empty(low, up)) { + if (up < r.val || low > r.val) return true; + else if (up == r.val && low == r.val) return false; + } + throw interval_lib::comparison_error(); +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_INTERVAL_HPP diff --git a/eo/contrib/boost/numeric/interval/io.hpp b/eo/contrib/boost/numeric/interval/io.hpp new file mode 100644 index 000000000..dc4179e52 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/io.hpp @@ -0,0 +1,41 @@ +/* Boost interval/io.hpp header file + * + * This file is only meant to provide a quick + * implementation of the output operator. It is + * provided for test programs that aren't even + * interested in the precision of the results. + * A real progam should define its own operators + * and never include this header. + * + * Copyright 2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_IO_HPP +#define BOOST_NUMERIC_INTERVAL_IO_HPP + +#include +#include +#include + +namespace boost { +namespace numeric { + +template +std::basic_ostream &operator<< + (std::basic_ostream &stream, + interval const &value) +{ + if (empty(value)) + return stream << "[]"; + else + return stream << '[' << lower(value) << ',' << upper(value) << ']'; +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_IO_HPP diff --git a/eo/contrib/boost/numeric/interval/limits.hpp b/eo/contrib/boost/numeric/interval/limits.hpp new file mode 100644 index 000000000..d691ccee2 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/limits.hpp @@ -0,0 +1,51 @@ +/* Boost interval/limits.hpp template implementation file + * + * Copyright 2000 Jens Maurer + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_LIMITS_HPP +#define BOOST_NUMERIC_INTERVAL_LIMITS_HPP + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + +#include +#include +#include + +namespace std { + +template +class numeric_limits > + : public numeric_limits +{ +private: + typedef boost::numeric::interval I; + typedef numeric_limits bl; +public: + static I min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return I((bl::min)(), (bl::min)()); } + static I max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return I((bl::max)(), (bl::max)()); } + static I epsilon() throw() { return I(bl::epsilon(), bl::epsilon()); } + + BOOST_STATIC_CONSTANT(float_round_style, round_style = round_indeterminate); + BOOST_STATIC_CONSTANT(bool, is_iec559 = false); + + static I infinity () throw() { return I::whole(); } + static I quiet_NaN() throw() { return I::empty(); } + static I signaling_NaN() throw() + { return I(bl::signaling_NaN(), bl::signaling_Nan()); } + static I denorm_min() throw() + { return I(bl::denorm_min(), bl::denorm_min()); } +private: + static I round_error(); // hide this on purpose, not yet implemented +}; + +} // namespace std + +#endif + +#endif // BOOST_NUMERIC_INTERVAL_LIMITS_HPP diff --git a/eo/contrib/boost/numeric/interval/policies.hpp b/eo/contrib/boost/numeric/interval/policies.hpp new file mode 100644 index 000000000..70ad220d9 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/policies.hpp @@ -0,0 +1,75 @@ +/* Boost interval/policies.hpp template implementation file + * + * Copyright 2003 Guillaume Melquiond + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_POLICIES_HPP +#define BOOST_NUMERIC_INTERVAL_POLICIES_HPP + +#include + +namespace boost { +namespace numeric { +namespace interval_lib { + +/* + * policies class + */ + +template +struct policies +{ + typedef Rounding rounding; + typedef Checking checking; +}; + +/* + * policies switching classes + */ + +template +class change_rounding +{ + typedef typename OldInterval::base_type T; + typedef typename OldInterval::traits_type p; + typedef typename p::checking checking; +public: + typedef interval > type; +}; + +template +class change_checking +{ + typedef typename OldInterval::base_type T; + typedef typename OldInterval::traits_type p; + typedef typename p::rounding rounding; +public: + typedef interval > type; +}; + +/* + * Protect / unprotect: control whether the rounding mode is set/reset + * at each operation, rather than once and for all. + */ + +template +class unprotect +{ + typedef typename OldInterval::base_type T; + typedef typename OldInterval::traits_type p; + typedef typename p::rounding r; + typedef typename r::unprotected_rounding newRounding; +public: + typedef typename change_rounding::type type; +}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + + +#endif // BOOST_NUMERIC_INTERVAL_POLICIES_HPP diff --git a/eo/contrib/boost/numeric/interval/rounded_arith.hpp b/eo/contrib/boost/numeric/interval/rounded_arith.hpp new file mode 100644 index 000000000..6ce5c7f7e --- /dev/null +++ b/eo/contrib/boost/numeric/interval/rounded_arith.hpp @@ -0,0 +1,120 @@ +/* Boost interval/rounded_arith.hpp template implementation file + * + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP +#define BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP + +#include +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { + +/* + * Three classes of rounding: exact, std, opp + * See documentation for details. + */ + +template +struct rounded_arith_exact: Rounding { + void init() { } + template T conv_down(U const &v) { return v; } + template T conv_up (U const &v) { return v; } + T add_down (const T& x, const T& y) { return x + y; } + T add_up (const T& x, const T& y) { return x + y; } + T sub_down (const T& x, const T& y) { return x - y; } + T sub_up (const T& x, const T& y) { return x - y; } + T mul_down (const T& x, const T& y) { return x * y; } + T mul_up (const T& x, const T& y) { return x * y; } + T div_down (const T& x, const T& y) { return x / y; } + T div_up (const T& x, const T& y) { return x / y; } + T median (const T& x, const T& y) { return (x + y) / 2; } + T sqrt_down(const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(sqrt); return sqrt(x); } + T sqrt_up (const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(sqrt); return sqrt(x); } + T int_down (const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(floor); return floor(x); } + T int_up (const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(ceil); return ceil(x); } +}; + +template +struct rounded_arith_std: Rounding { +# define BOOST_DN(EXPR) this->downward(); return this->force_rounding(EXPR) +# define BOOST_NR(EXPR) this->to_nearest(); return this->force_rounding(EXPR) +# define BOOST_UP(EXPR) this->upward(); return this->force_rounding(EXPR) + void init() { } + template T conv_down(U const &v) { BOOST_DN(v); } + template T conv_up (U const &v) { BOOST_UP(v); } + T add_down(const T& x, const T& y) { BOOST_DN(x + y); } + T sub_down(const T& x, const T& y) { BOOST_DN(x - y); } + T mul_down(const T& x, const T& y) { BOOST_DN(x * y); } + T div_down(const T& x, const T& y) { BOOST_DN(x / y); } + T add_up (const T& x, const T& y) { BOOST_UP(x + y); } + T sub_up (const T& x, const T& y) { BOOST_UP(x - y); } + T mul_up (const T& x, const T& y) { BOOST_UP(x * y); } + T div_up (const T& x, const T& y) { BOOST_UP(x / y); } + T median(const T& x, const T& y) { BOOST_NR((x + y) / 2); } + T sqrt_down(const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_DN(sqrt(x)); } + T sqrt_up (const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_UP(sqrt(x)); } + T int_down(const T& x) { this->downward(); return to_int(x); } + T int_up (const T& x) { this->upward(); return to_int(x); } +# undef BOOST_DN +# undef BOOST_NR +# undef BOOST_UP +}; + +template +struct rounded_arith_opp: Rounding { + void init() { this->upward(); } +# define BOOST_DN(EXPR) \ + this->downward(); \ + T r = this->force_rounding(EXPR); \ + this->upward(); \ + return r +# define BOOST_NR(EXPR) \ + this->to_nearest(); \ + T r = this->force_rounding(EXPR); \ + this->upward(); \ + return r +# define BOOST_UP(EXPR) return this->force_rounding(EXPR) +# define BOOST_UP_NEG(EXPR) return -this->force_rounding(EXPR) + template T conv_down(U const &v) { BOOST_UP_NEG(-v); } + template T conv_up (U const &v) { BOOST_UP(v); } + T add_down(const T& x, const T& y) { BOOST_UP_NEG((-x) - y); } + T sub_down(const T& x, const T& y) { BOOST_UP_NEG(y - x); } + T mul_down(const T& x, const T& y) { BOOST_UP_NEG(x * (-y)); } + T div_down(const T& x, const T& y) { BOOST_UP_NEG(x / (-y)); } + T add_up (const T& x, const T& y) { BOOST_UP(x + y); } + T sub_up (const T& x, const T& y) { BOOST_UP(x - y); } + T mul_up (const T& x, const T& y) { BOOST_UP(x * y); } + T div_up (const T& x, const T& y) { BOOST_UP(x / y); } + T median (const T& x, const T& y) { BOOST_NR((x + y) / 2); } + T sqrt_down(const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_DN(sqrt(x)); } + T sqrt_up (const T& x) + { BOOST_NUMERIC_INTERVAL_using_math(sqrt); BOOST_UP(sqrt(x)); } + T int_down(const T& x) { return -to_int(-x); } + T int_up (const T& x) { return to_int(x); } +# undef BOOST_DN +# undef BOOST_NR +# undef BOOST_UP +# undef BOOST_UP_NEG +}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_ROUNDED_ARITH_HPP diff --git a/eo/contrib/boost/numeric/interval/rounded_transc.hpp b/eo/contrib/boost/numeric/interval/rounded_transc.hpp new file mode 100644 index 000000000..e1704f5f2 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/rounded_transc.hpp @@ -0,0 +1,140 @@ +/* Boost interval/rounded_transc.hpp template implementation file + * + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP +#define BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP + +#include +#include +#include + +namespace boost { +namespace numeric { +namespace interval_lib { + +template +struct rounded_transc_exact: Rounding +{ +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); } \ + T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_math(f); return f(x); } + BOOST_NUMERIC_INTERVAL_new_func(exp) + BOOST_NUMERIC_INTERVAL_new_func(log) + BOOST_NUMERIC_INTERVAL_new_func(sin) + BOOST_NUMERIC_INTERVAL_new_func(cos) + BOOST_NUMERIC_INTERVAL_new_func(tan) + BOOST_NUMERIC_INTERVAL_new_func(asin) + BOOST_NUMERIC_INTERVAL_new_func(acos) + BOOST_NUMERIC_INTERVAL_new_func(atan) + BOOST_NUMERIC_INTERVAL_new_func(sinh) + BOOST_NUMERIC_INTERVAL_new_func(cosh) + BOOST_NUMERIC_INTERVAL_new_func(tanh) +# undef BOOST_NUMERIC_INTERVAL_new_func +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); } \ + T f##_up (const T& x) { BOOST_NUMERIC_INTERVAL_using_ahyp(f); return f(x); } + BOOST_NUMERIC_INTERVAL_new_func(asinh) + BOOST_NUMERIC_INTERVAL_new_func(acosh) + BOOST_NUMERIC_INTERVAL_new_func(atanh) +# undef BOOST_NUMERIC_INTERVAL_new_func +}; + +template +struct rounded_transc_std: Rounding +{ +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_math(f); \ + this->downward(); return this->force_rounding(f(x)); } \ + T f##_up (const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_math(f); \ + this->upward(); return this->force_rounding(f(x)); } + BOOST_NUMERIC_INTERVAL_new_func(exp) + BOOST_NUMERIC_INTERVAL_new_func(log) + BOOST_NUMERIC_INTERVAL_new_func(sin) + BOOST_NUMERIC_INTERVAL_new_func(cos) + BOOST_NUMERIC_INTERVAL_new_func(tan) + BOOST_NUMERIC_INTERVAL_new_func(asin) + BOOST_NUMERIC_INTERVAL_new_func(acos) + BOOST_NUMERIC_INTERVAL_new_func(atan) + BOOST_NUMERIC_INTERVAL_new_func(sinh) + BOOST_NUMERIC_INTERVAL_new_func(cosh) + BOOST_NUMERIC_INTERVAL_new_func(tanh) +# undef BOOST_NUMERIC_INTERVAL_new_func +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \ + this->downward(); return this->force_rounding(f(x)); } \ + T f##_up (const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \ + this->upward(); return this->force_rounding(f(x)); } + BOOST_NUMERIC_INTERVAL_new_func(asinh) + BOOST_NUMERIC_INTERVAL_new_func(acosh) + BOOST_NUMERIC_INTERVAL_new_func(atanh) +# undef BOOST_NUMERIC_INTERVAL_new_func +}; + +template +struct rounded_transc_opp: Rounding +{ +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_math(f); \ + this->downward(); T y = this->force_rounding(f(x)); \ + this->upward(); return y; } \ + T f##_up (const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_math(f); \ + return this->force_rounding(f(x)); } + BOOST_NUMERIC_INTERVAL_new_func(exp) + BOOST_NUMERIC_INTERVAL_new_func(log) + BOOST_NUMERIC_INTERVAL_new_func(cos) + BOOST_NUMERIC_INTERVAL_new_func(acos) + BOOST_NUMERIC_INTERVAL_new_func(cosh) +# undef BOOST_NUMERIC_INTERVAL_new_func +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_math(f); \ + return -this->force_rounding(-f(x)); } \ + T f##_up (const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_math(f); \ + return this->force_rounding(f(x)); } + BOOST_NUMERIC_INTERVAL_new_func(sin) + BOOST_NUMERIC_INTERVAL_new_func(tan) + BOOST_NUMERIC_INTERVAL_new_func(asin) + BOOST_NUMERIC_INTERVAL_new_func(atan) + BOOST_NUMERIC_INTERVAL_new_func(sinh) + BOOST_NUMERIC_INTERVAL_new_func(tanh) +# undef BOOST_NUMERIC_INTERVAL_new_func +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \ + this->downward(); T y = this->force_rounding(f(x)); \ + this->upward(); return y; } \ + T f##_up (const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \ + return this->force_rounding(f(x)); } + BOOST_NUMERIC_INTERVAL_new_func(asinh) + BOOST_NUMERIC_INTERVAL_new_func(atanh) +# undef BOOST_NUMERIC_INTERVAL_new_func +# define BOOST_NUMERIC_INTERVAL_new_func(f) \ + T f##_down(const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \ + return -this->force_rounding(-f(x)); } \ + T f##_up (const T& x) \ + { BOOST_NUMERIC_INTERVAL_using_ahyp(f); \ + return this->force_rounding(f(x)); } + BOOST_NUMERIC_INTERVAL_new_func(acosh) +# undef BOOST_NUMERIC_INTERVAL_new_func +}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_ROUNDED_TRANSC_HPP diff --git a/eo/contrib/boost/numeric/interval/rounding.hpp b/eo/contrib/boost/numeric/interval/rounding.hpp new file mode 100644 index 000000000..f69e2e4b5 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/rounding.hpp @@ -0,0 +1,101 @@ +/* Boost interval/rounding.hpp template implementation file + * + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_ROUNDING_HPP +#define BOOST_NUMERIC_INTERVAL_ROUNDING_HPP + +namespace boost { +namespace numeric { +namespace interval_lib { + +/* + * Default rounding_control class (does nothing) + */ + +template +struct rounding_control +{ + typedef int rounding_mode; + static void get_rounding_mode(rounding_mode&) {} + static void set_rounding_mode(rounding_mode) {} + static void upward() {} + static void downward() {} + static void to_nearest() {} + static const T& to_int(const T& x) { return x; } + static const T& force_rounding(const T& x) { return x; } +}; + +/* + * A few rounding control classes (exact/std/opp: see documentation) + * rounded_arith_* control the rounding of the arithmetic operators + * rounded_transc_* control the rounding of the transcendental functions + */ + +template > +struct rounded_arith_exact; + +template > +struct rounded_arith_std; + +template > +struct rounded_arith_opp; + +template +struct rounded_transc_dummy; + +template > +struct rounded_transc_exact; + +template > +struct rounded_transc_std; + +template > +struct rounded_transc_opp; + +/* + * State-saving classes: allow to set and reset rounding control + */ + +namespace detail { + +template +struct save_state_unprotected: Rounding +{ + typedef save_state_unprotected unprotected_rounding; +}; + +} // namespace detail + +template +struct save_state: Rounding +{ + typename Rounding::rounding_mode mode; + save_state() { + this->get_rounding_mode(mode); + this->init(); + } + ~save_state() { this->set_rounding_mode(mode); } + typedef detail::save_state_unprotected unprotected_rounding; +}; + +template +struct save_state_nothing: Rounding +{ + typedef save_state_nothing unprotected_rounding; +}; + +template +struct rounded_math: save_state_nothing > +{}; + +} // namespace interval_lib +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_ROUNDING_HPP diff --git a/eo/contrib/boost/numeric/interval/transc.hpp b/eo/contrib/boost/numeric/interval/transc.hpp new file mode 100644 index 000000000..88aebd6b3 --- /dev/null +++ b/eo/contrib/boost/numeric/interval/transc.hpp @@ -0,0 +1,232 @@ +/* Boost interval/transc.hpp template implementation file + * + * Copyright 2000 Jens Maurer + * Copyright 2002 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_TRANSC_HPP +#define BOOST_NUMERIC_INTERVAL_TRANSC_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { +namespace numeric { + +template inline +interval exp(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.exp_down(x.lower()), rnd.exp_up(x.upper()), true); +} + +template inline +interval log(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x) || + !interval_lib::user::is_pos(x.upper())) + return I::empty(); + typename Policies::rounding rnd; + typedef typename Policies::checking checking; + T l = !interval_lib::user::is_pos(x.lower()) + ? checking::neg_inf() : rnd.log_down(x.lower()); + return I(l, rnd.log_up(x.upper()), true); +} + +template inline +interval cos(const interval& x) +{ + if (interval_lib::detail::test_input(x)) + return interval::empty(); + typename Policies::rounding rnd; + typedef interval I; + typedef typename interval_lib::unprotect::type R; + + // get lower bound within [0, pi] + const R pi2 = interval_lib::pi_twice(); + R tmp = fmod((const R&)x, pi2); + if (width(tmp) >= pi2.lower()) + return I(static_cast(-1), static_cast(1), true); // we are covering a full period + if (tmp.lower() >= interval_lib::constants::pi_upper()) + return -cos(tmp - interval_lib::pi()); + T l = tmp.lower(); + T u = tmp.upper(); + + BOOST_USING_STD_MIN(); + // separate into monotone subintervals + if (u <= interval_lib::constants::pi_lower()) + return I(rnd.cos_down(u), rnd.cos_up(l), true); + else if (u <= pi2.lower()) + return I(static_cast(-1), rnd.cos_up(min BOOST_PREVENT_MACRO_SUBSTITUTION(rnd.sub_down(pi2.lower(), u), l)), true); + else + return I(static_cast(-1), static_cast(1), true); +} + +template inline +interval sin(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + typedef typename interval_lib::unprotect::type R; + I r = cos((const R&)x - interval_lib::pi_half()); + (void)&rnd; + return r; +} + +template inline +interval tan(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + typedef typename interval_lib::unprotect::type R; + + // get lower bound within [-pi/2, pi/2] + const R pi = interval_lib::pi(); + R tmp = fmod((const R&)x, pi); + const T pi_half_d = interval_lib::constants::pi_half_lower(); + if (tmp.lower() >= pi_half_d) + tmp -= pi; + if (tmp.lower() <= -pi_half_d || tmp.upper() >= pi_half_d) + return I::whole(); + return I(rnd.tan_down(tmp.lower()), rnd.tan_up(tmp.upper()), true); +} + +template inline +interval asin(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x) + || x.upper() < static_cast(-1) || x.lower() > static_cast(1)) + return I::empty(); + typename Policies::rounding rnd; + T l = (x.lower() <= static_cast(-1)) + ? -interval_lib::constants::pi_half_upper() + : rnd.asin_down(x.lower()); + T u = (x.upper() >= static_cast(1) ) + ? interval_lib::constants::pi_half_upper() + : rnd.asin_up (x.upper()); + return I(l, u, true); +} + +template inline +interval acos(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x) + || x.upper() < static_cast(-1) || x.lower() > static_cast(1)) + return I::empty(); + typename Policies::rounding rnd; + T l = (x.upper() >= static_cast(1) ) + ? static_cast(0) + : rnd.acos_down(x.upper()); + T u = (x.lower() <= static_cast(-1)) + ? interval_lib::constants::pi_upper() + : rnd.acos_up (x.lower()); + return I(l, u, true); +} + +template inline +interval atan(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.atan_down(x.lower()), rnd.atan_up(x.upper()), true); +} + +template inline +interval sinh(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.sinh_down(x.lower()), rnd.sinh_up(x.upper()), true); +} + +template inline +interval cosh(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + if (interval_lib::user::is_neg(x.upper())) + return I(rnd.cosh_down(x.upper()), rnd.cosh_up(x.lower()), true); + else if (!interval_lib::user::is_neg(x.lower())) + return I(rnd.cosh_down(x.lower()), rnd.cosh_up(x.upper()), true); + else + return I(static_cast(0), rnd.cosh_up(-x.lower() > x.upper() ? x.lower() : x.upper()), true); +} + +template inline +interval tanh(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.tanh_down(x.lower()), rnd.tanh_up(x.upper()), true); +} + +template inline +interval asinh(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + typename Policies::rounding rnd; + return I(rnd.asinh_down(x.lower()), rnd.asinh_up(x.upper()), true); +} + +template inline +interval acosh(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x) || x.upper() < static_cast(1)) + return I::empty(); + typename Policies::rounding rnd; + T l = x.lower() <= static_cast(1) ? static_cast(0) : rnd.acosh_down(x.lower()); + return I(l, rnd.acosh_up(x.upper()), true); +} + +template inline +interval atanh(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x) + || x.upper() < static_cast(-1) || x.lower() > static_cast(1)) + return I::empty(); + typename Policies::rounding rnd; + typedef typename Policies::checking checking; + T l = (x.lower() <= static_cast(-1)) + ? checking::neg_inf() : rnd.atanh_down(x.lower()); + T u = (x.upper() >= static_cast(1) ) + ? checking::pos_inf() : rnd.atanh_up (x.upper()); + return I(l, u, true); +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_TRANSC_HPP diff --git a/eo/contrib/boost/numeric/interval/utility.hpp b/eo/contrib/boost/numeric/interval/utility.hpp new file mode 100644 index 000000000..d24d84d7a --- /dev/null +++ b/eo/contrib/boost/numeric/interval/utility.hpp @@ -0,0 +1,331 @@ +/* Boost interval/utility.hpp template implementation file + * + * Copyright 2000 Jens Maurer + * Copyright 2002-2003 Hervé Brönnimann, Guillaume Melquiond, Sylvain Pion + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or + * copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_NUMERIC_INTERVAL_UTILITY_HPP +#define BOOST_NUMERIC_INTERVAL_UTILITY_HPP + +#include +#include +#include +#include +#include +#include + +/* + * Implementation of simple functions + */ + +namespace boost { +namespace numeric { + +/* + * Utility Functions + */ + +template inline +const T& lower(const interval& x) +{ + return x.lower(); +} + +template inline +const T& upper(const interval& x) +{ + return x.upper(); +} + +template inline +T checked_lower(const interval& x) +{ + if (empty(x)) { + typedef typename Policies::checking checking; + return checking::nan(); + } + return x.lower(); +} + +template inline +T checked_upper(const interval& x) +{ + if (empty(x)) { + typedef typename Policies::checking checking; + return checking::nan(); + } + return x.upper(); +} + +template inline +T width(const interval& x) +{ + if (interval_lib::detail::test_input(x)) return static_cast(0); + typename Policies::rounding rnd; + return rnd.sub_up(x.upper(), x.lower()); +} + +template inline +T median(const interval& x) +{ + if (interval_lib::detail::test_input(x)) { + typedef typename Policies::checking checking; + return checking::nan(); + } + typename Policies::rounding rnd; + return rnd.median(x.lower(), x.upper()); +} + +template inline +interval widen(const interval& x, const T& v) +{ + if (interval_lib::detail::test_input(x)) + return interval::empty(); + typename Policies::rounding rnd; + return interval(rnd.sub_down(x.lower(), v), + rnd.add_up (x.upper(), v), true); +} + +/* + * Set-like operations + */ + +template inline +bool empty(const interval& x) +{ + return interval_lib::detail::test_input(x); +} + +template inline +bool in_zero(const interval& x) +{ + if (interval_lib::detail::test_input(x)) return false; + return (!interval_lib::user::is_pos(x.lower())) && + (!interval_lib::user::is_neg(x.upper())); +} + +template inline +bool in(const T& x, const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) return false; + return y.lower() <= x && x <= y.upper(); +} + +template inline +bool subset(const interval& x, + const interval& y) +{ + if (empty(x)) return true; + return !empty(y) && y.lower() <= x.lower() && x.upper() <= y.upper(); +} + +template inline +bool proper_subset(const interval& x, + const interval& y) +{ + if (empty(y)) return false; + if (empty(x)) return true; + return y.lower() <= x.lower() && x.upper() <= y.upper() && + (y.lower() != x.lower() || x.upper() != y.upper()); +} + +template inline +bool overlap(const interval& x, + const interval& y) +{ + if (interval_lib::detail::test_input(x, y)) return false; + return x.lower() <= y.lower() && y.lower() <= x.upper() || + y.lower() <= x.lower() && x.lower() <= y.upper(); +} + +template inline +bool singleton(const interval& x) +{ + return !empty(x) && x.lower() == x.upper(); +} + +template inline +bool equal(const interval& x, const interval& y) +{ + if (empty(x)) return empty(y); + return !empty(y) && x.lower() == y.lower() && x.upper() == y.upper(); +} + +template inline +interval intersect(const interval& x, + const interval& y) +{ + BOOST_USING_STD_MIN(); + BOOST_USING_STD_MAX(); + if (interval_lib::detail::test_input(x, y)) + return interval::empty(); + const T& l = max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()); + const T& u = min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()); + if (l <= u) return interval(l, u, true); + else return interval::empty(); +} + +template inline +interval hull(const interval& x, + const interval& y) +{ + BOOST_USING_STD_MIN(); + BOOST_USING_STD_MAX(); + bool bad_x = interval_lib::detail::test_input(x); + bool bad_y = interval_lib::detail::test_input(y); + if (bad_x) + if (bad_y) return interval::empty(); + else return y; + else + if (bad_y) return x; + return interval(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), + max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true); +} + +template inline +interval hull(const interval& x, const T& y) +{ + BOOST_USING_STD_MIN(); + BOOST_USING_STD_MAX(); + bool bad_x = interval_lib::detail::test_input(x); + bool bad_y = interval_lib::detail::test_input(y); + if (bad_y) + if (bad_x) return interval::empty(); + else return x; + else + if (bad_x) return interval(y, y, true); + return interval(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), + max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true); +} + +template inline +interval hull(const T& x, const interval& y) +{ + BOOST_USING_STD_MIN(); + BOOST_USING_STD_MAX(); + bool bad_x = interval_lib::detail::test_input(x); + bool bad_y = interval_lib::detail::test_input(y); + if (bad_x) + if (bad_y) return interval::empty(); + else return y; + else + if (bad_y) return interval(x, x, true); + return interval(min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), + max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true); +} + +template inline +interval hull(const T& x, const T& y) +{ + return interval::hull(x, y); +} + +template inline +std::pair, interval > +bisect(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return std::pair(I::empty(), I::empty()); + const T m = median(x); + return std::pair(I(x.lower(), m, true), I(m, x.upper(), true)); +} + +/* + * Elementary functions + */ + +template inline +T norm(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) { + typedef typename Policies::checking checking; + return checking::nan(); + } + BOOST_USING_STD_MAX(); + return max BOOST_PREVENT_MACRO_SUBSTITUTION(-x.lower(), x.upper()); +} + +template inline +interval abs(const interval& x) +{ + typedef interval I; + if (interval_lib::detail::test_input(x)) + return I::empty(); + if (!interval_lib::user::is_neg(x.lower())) return x; + if (!interval_lib::user::is_pos(x.upper())) return -x; + BOOST_USING_STD_MAX(); + return I(static_cast(0), max BOOST_PREVENT_MACRO_SUBSTITUTION(-x.lower(), x.upper()), true); +} + +template inline +interval max BOOST_PREVENT_MACRO_SUBSTITUTION (const interval& x, + const interval& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + BOOST_USING_STD_MAX(); + return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true); +} + +template inline +interval max BOOST_PREVENT_MACRO_SUBSTITUTION (const interval& x, const T& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + BOOST_USING_STD_MAX(); + return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), max BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true); +} + +template inline +interval max BOOST_PREVENT_MACRO_SUBSTITUTION (const T& x, const interval& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + BOOST_USING_STD_MAX(); + return I(max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), max BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true); +} + +template inline +interval min BOOST_PREVENT_MACRO_SUBSTITUTION (const interval& x, + const interval& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + BOOST_USING_STD_MIN(); + return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y.upper()), true); +} + +template inline +interval min BOOST_PREVENT_MACRO_SUBSTITUTION (const interval& x, const T& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + BOOST_USING_STD_MIN(); + return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x.lower(), y), min BOOST_PREVENT_MACRO_SUBSTITUTION(x.upper(), y), true); +} + +template inline +interval min BOOST_PREVENT_MACRO_SUBSTITUTION (const T& x, const interval& y) +{ + typedef interval I; + if (interval_lib::detail::test_input(x, y)) + return I::empty(); + BOOST_USING_STD_MIN(); + return I(min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.lower()), min BOOST_PREVENT_MACRO_SUBSTITUTION(x, y.upper()), true); +} + +} // namespace numeric +} // namespace boost + +#endif // BOOST_NUMERIC_INTERVAL_UTILITY_HPP diff --git a/eo/contrib/mathsym/COPYING b/eo/contrib/mathsym/COPYING new file mode 100644 index 000000000..d60c31a97 --- /dev/null +++ b/eo/contrib/mathsym/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/eo/contrib/mathsym/GNUmakefile b/eo/contrib/mathsym/GNUmakefile new file mode 100644 index 000000000..bb3ff94ee --- /dev/null +++ b/eo/contrib/mathsym/GNUmakefile @@ -0,0 +1,87 @@ +COMPILEFLAGS=-Wno-deprecated -g -Wall -Wshadow #-DINTERVAL_DEBUG +OPTFLAGS= -O2 -DNDEBUG + +PROFILE_FLAGS=#-pg + +INCLUDES=-I. -Isym -Ifun -Igen -Ieval -Iregression -I../../src -Ieo_interface -I.. + +CPPFLAGS=$(COMPILEFLAGS) $(OPTFLAGS) $(INCLUDES) $(PROFILE_FLAGS) -D__I386__ -DSIZEOF_UNSIGNED_LONG=4 +EXTLIBS=tcc/libtcc.a tcc/libtcc1.a ../../src/libeo.a ../../src/utils/libeoutils.a + +LIBS=${EXTLIBS} -ldl + +SYMLIB=libsym.a + +VPATH=sym fun gen eval regression eo_interface + +CXXSOURCES=FunDef.cpp Sym.cpp SymImpl.cpp SymOps.cpp sym_compile.cpp TreeBuilder.cpp LanguageTable.cpp\ + Dataset.cpp ErrorMeasure.cpp Scaling.cpp TargetInfo.cpp BoundsCheck.cpp util.cpp NodeSelector.cpp\ + eoSymCrossover.cpp + +PROGRAMS=test/test test/test_compile test/testeo + +OBJS= $(CXXSOURCES:.cpp=.o) c_compile.o + +all: tcc/ symreg + +include $(CXXSOURCES:.cpp=.d) symreg.d + +clean: + rm *.o *.d $(PROGRAMS) $(SYMLIB) symreg || true + +distclean: clean + rm -rf tcc + +symreg: libsym.a symreg.o $(EXTLIBS) + $(CXX) -o symreg symreg.o libsym.a $(LIBS) $(PROFILE_FLAGS) + +libsym.a: $(OBJS) + rm libsym.a; ar cq $(SYMLIB) $(OBJS) + +check: $(PROGRAMS) + test/test && test/test_compile && test/testeo && echo "all tests succeeded" + +test/test: test/test.o ${SYMLIB} + $(CXX) -o test/test test/test.o ${SYMLIB} ${LIBS} + +test/test_compile: test/test_compile.o ${SYMLIB} + $(CXX) -o test/test_compile test/test_compile.o $(SYMLIB) ${LIBS} + +test/testeo: test/testeo.o ${SYMLIB} + $(CXX) -o test/testeo test/testeo.o $(SYMLIB) ${LIBS} + +# eo +../../src/libeo.a: + make -C ../../src + +../../src/utils/libeoutils.a: + make -C ../../src/utils + +# tiny cc +tcc/: tcc.tar.gz + tar xvfz tcc.tar.gz && cd tcc && ./configure && make + +tcc/Makefile: tcc/ + cd tcc && ./configure + +tcc/libtcc.a: tcc/Makefile + make -Ctcc + +tcc/libtcc1.a: tcc/Makefile + make -Ctcc + +#rules +c_compile.o: eval/c_compile.c + gcc -c eval/c_compile.c -I./tcc $(COMPILEFLAGS) $(OPTFLAGS) + +%.o:%.cpp + $(CXX) -o $@ -c $< $(CPPFLAGS) $(INCLUDE) + +%.d: %.cpp + $(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< | sed "s/$*.o/& $@/g" > $@ ' + + +%.d: %.c + $(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< | sed "s/$*.o/& $@/g" > $@ ' + + diff --git a/eo/contrib/mathsym/README b/eo/contrib/mathsym/README new file mode 100644 index 000000000..a0d79b61a --- /dev/null +++ b/eo/contrib/mathsym/README @@ -0,0 +1,172 @@ + +This is not yet another gp system (nyagp). For one, it is not general. +It does one thing, find mathematical functions, and tries to do that well. + +So, if you're trying to steer ants on various New Mexico trails, or build your +own tiny block world, you're in the wrong place. However, if you're interested +in finding mathematical functions either through direct application on data or +running it through a simulator, you might find what you're looking for here. + +=== Representation (sym/ + gen/) ======== + +Mathsym has a few interesting characteristics. First and foremost is the +basic representation. It uses trees, but these trees are stored in a +reference counted hashtable. This means that every subtree that is alive +is stored once and only once. The reference counting mechanism takes care +of memory management. + +The idea of using a hashtable (for offline analysis) comes from Walter Tackett, in his +1994 dissertation. The current system is just a real-time implementation of this +idea, adding the reference counting for ease of use. + +The hashtable brings overhead. It's still pretty fast, but a string based representation +would run rounds around it. However, by virtue of it storing every subtree only once, it +is fairly tight on memory. This helps tremendously when confronted with growing populations, bloat. +The hashtable implementation can not stop bloat, but does make it more manageable. In a typical +GP run, the number of distinct subtrees is only 10-20% of the total number of subtrees. + +Other advantages of the hashtable are in the ability to examine the run more thoroughly. It is easy +to check how many subtrees are present in the system, and for each subtree you can check the reference +count. + +The basic tree is called a Sym. A Sym is simply a tree, and has children, accessible through args(). +A Sym simply contains an iterator (== decorated pointer) to an entry in the hashtable. +Every time you create a Sym, it is either looked up in the hashtable or added to the hashtable. +A Sym has several members: size, depth, args, etc. One interesting member is the refcount(). +This returns the reference count of the Sym in the hashtable, and thus returns the number +of distinct contexts in which the Sym is used. + +Another nice thing of these hashtable Syms is that a check for equality reduces to a pointer comparison. + +The Sym nodes are identified by a simple token, of type token_t (usually an unsigned int). It +is completely generic and could conceivably be adapted to steer ants. The rest of the library +is however targeted at mathematical functions purely. + +sym/Sym.h is the file to look into for the functionality provided by Sym. The sym/ directory +is where the source files are stored that are relevant for the generic Sym functionality. The +'gen/' directory contains some generic functionality to build and traverse trees, independent of +the function and terminal set. + +The file sym/README.cpp documents the use of the sym library for general GP use. + +=== Function Set (fun/) === + +The standard GP function set of binary functions: addition, multiplication, subtraction and +division is NOT supported. + +What is however supported are the functions of: + +summation: arbitrary arity, arity zero meaning 0.0. Arity 2 is standard addition +product: arbitrary arity, arity zero meaning 1.0. Arity 2 is standard multiplication +inversion: 1.0 / x. Only arity 1 +unary minus: -x. Only arity 1 + +Plus a whole bunch of other functions (see "fun/FunDef.h") + +The reason for this is the observation (actually from a friend of mine, thanks Luuk), +that this set of functions is complete and slightly more orthogonal than a binary set. + +The directory 'fun' contains the functionality for the function and terminal set, together +with ERC's etc. fun/FunDef.cpp contains the definition of the functionality. Stuff can be +added here, but best to contact me if you miss particular functions. + +=== Evaluation (eval/) === + +The second important thing is evaluation. Although Syms can be evaluated through an interpreter, +this is not the fastest way to go about with it. The standard way of evaluating a Sym is to +first *compile* it to a function, and then run it in your favourite environment. Compilation +is done through the use of the excellent tinycc compiler, which is blazingly fast and produces +pretty good functions. + +Compilation comes in several flavours: compile a single function and retrieve a pointer to a function +of signature: + +double func(const double* x); + +where x is the input array. Another option is to compile a bunch of functions in one go, and retrieve an array +of such function pointers. The Syms are simply printed and compiled. An example: + +double func(const double* x) { return x*x + x * 1./x; } + +The batch version proceeds significantly more quickly than calling compile every time. The function pointers +can be given to a simulation for extremely quick evaluation. + +A third option is to compile a complete population in one go, and return a single pointer of signature + +void func(const double* x, double* y); + +Where 'y' is the (preallocated) output array. This allows to evaluate a complete population in one function +call, storing the results in 'y'. It uses the hashtable to store every calculation only once. An example +for the two function x*x + x*1./x and x + sin(x*x) is: + +void func(const double* x, double* y) { + double a0 = x; + double a1 = a0 * a0; + double a2 = 1.0; + double a3 = a2 / a0; + double a4 = a2 * a3; + y[0] = a4; + double a5 = sin(a1); + double a6 = a0 + a5; + y[1] = a6; +} + +This is the fastest way to evaluate even humongous populations quickly. You might be surprised at +the amount of code re-use in a GP population. + +The three compilation functions can be found in eval/sym_compile.h + +A limiting factor in tinycc is that the struct TCCState that is used to hold the compilation context, +is not really self-contained. This unfortunately means that with every call to 'compile' ALL previous +pointers that have been produced are invalidated. I'm still looking at ways to circumvent this. + +To work with mathsym, a few small changes in tccelf.c were necessary, check README.TCC for details. + +=== Interval Arithmetic (eval/) === + +GP is pretty good at finding mathematical expressions that are numerically unsound. Take for instance +the function '1 / x'. This is well defined only when x is strictly positive, but will lead to problems +when x equals 0. The standard answer is to define some pseudo-arithmetical function called 'protected +division' that will return some value (usually 1) when a division by zero occurs. This leads to a number +of protected functions (sqrt, log, tan, etc.) which all need to be protected. Interpreting results from +GP using such functions is in general hard. + +Interval arithmetic (through another excellent library boost/numeric/interval) is used to calculate +if particular functions can conceivably produce problems. This completely annihilates the use for Koza-style +protected operators and is a more safe and sound method. For interval arithmetic to function, the bounds +on the input variables need to be known. As for every function we can calculate a guarenteed, +though not necessarily tight, output interval given the input intervals, we can check arbitrary functions +for possible problems. If, for example for division, the input interval contains 0, we know that a division +by zero is theoretically possible. It's then best to throw away the entire function. + +Interval Arithmetic is accessible through the class IntervalBoundsCheck (eval/BoundsCheck.h) + +=== More generic support (gen/) === + +The gen subdirectory contains some general utility classes for defining function sets and for +creating trees. The idea is that these functions are generic and only append on the sym/ part +of the library. Unfortunately, the language table currently needs an ERC function, a default +implementation is hidden inside fun/FunDef.cpp. Will fix at some point. + +gen/LanguageTable.cpp -> defines the functions/terminals that can be used +gen/TreeBuilder.cpp -> can create trees based on a LanguageTable + +=== Data and Errors (regression/) === + +The above classes are generic and apply for any type of problem where a mathematical function can be +used to steer some process, run a simulation, whatever. First check the intervals, then compile the +Sym(s) to a (set of) function pointer(s), and use the pointers in some way to evaluate for fitness. +One particular type of problem for which support is built in is 'symbolic regression'. This type of +problem involves finding an mathematical input/output relationship based on some data. + +To enable this, regression/ introduces the class Dataset to contain the data and ErrorMeasure to calculate +error. Currently supported: mean squared error, mean absolute error and mean squared error scaled (proportional +to correlation squared). They use some helper classes such as Scaling and TargetInfo. + +=== EO interface (eo_interface/) === + +Contains the classes to make it all work with EO. Check the root application 'symreg' for ways to use this + + + + diff --git a/eo/contrib/mathsym/README.TCC b/eo/contrib/mathsym/README.TCC new file mode 100644 index 000000000..8441c232f --- /dev/null +++ b/eo/contrib/mathsym/README.TCC @@ -0,0 +1,5 @@ + +To refrain tcc from searching for libtcc1.a in the path, uncomment +out the lines looking for that in 'tccelf.c'. Search for libtcc1 and uncomment +these two lines. All should be well. + diff --git a/eo/contrib/mathsym/eo_interface/eoSym.h b/eo/contrib/mathsym/eo_interface/eoSym.h new file mode 100644 index 000000000..11443af4e --- /dev/null +++ b/eo/contrib/mathsym/eo_interface/eoSym.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EOSYM_H_ +#define EOSYM_H_ + +#include +#include +#include + + +template +class EoSym : public EO, public Sym { + + public: + + void set(const Sym& sym) { + invalidate(); + static_cast(this)->operator=(sym); + } + + virtual void printOn(ostream& os) const; + virtual void readFrom(istream& is); +}; + + +template +void EoSym::printOn(ostream& os) const { + EO::printOn(os); + os << ' '; + write_raw(os, *this); +} + +template +void EoSym::readFrom(istream& is) { + EO::readFrom(is); + read_raw(is, *this); +} + +template +inline std::ostream& operator<<(std::ostream& os, const EoSym& f) { f.printOn(os); return os; } +template +inline istream& operator>>(std::istream& is, EoSym& f) { f.readFrom(is); return os; } + + +#endif + + diff --git a/eo/contrib/mathsym/eo_interface/eoSymCrossover.cpp b/eo/contrib/mathsym/eo_interface/eoSymCrossover.cpp new file mode 100644 index 000000000..63d46c208 --- /dev/null +++ b/eo/contrib/mathsym/eo_interface/eoSymCrossover.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#include + +#include +#include + +bool subtree_quad(Sym& a, Sym& b, NodeSelector& select) { + unsigned i = select.select_node(a); + unsigned j = select.select_node(b); + + Sym aprime = insert_subtree(a, i, get_subtree(b, j)); + Sym bprime = insert_subtree(b, j, get_subtree(a, i)); + + a = aprime; + b = bprime; + return true; +} + +bool subtree_bin(Sym& a, const Sym& b, NodeSelector& select) { + unsigned i = select.select_node(a); + unsigned j = select.select_node(b); + + a = insert_subtree(a, i, get_subtree(b,j)); + + return true; +} + +Sym homologous_binimpl(Sym a, Sym b) { + + bool use_a = rng.random(2); + + token_t head = (use_a? a : b).token(); + SymVec args = use_a?a.args() : b.args(); + + const SymVec& a_args = a.args(); + const SymVec& b_args = b.args(); + unsigned mn = std::min(a_args.size(), b_args.size()); + + bool changed = !use_a; + + for (unsigned i = 0; i < mn; ++i) { + args[i] = homologous_binimpl(a_args[i], b_args[i]); + if (args[i] != a_args[i]) { + changed = true; + } + } + + return changed? Sym(head, args) : a; +} + +bool homologous_bin(Sym& a, const Sym& b) { + if (a==b) return false; + Sym org = a; + a = homologous_binimpl(a,b); + return org != a; +} + + diff --git a/eo/contrib/mathsym/eo_interface/eoSymCrossover.h b/eo/contrib/mathsym/eo_interface/eoSymCrossover.h new file mode 100644 index 000000000..faa9acfaf --- /dev/null +++ b/eo/contrib/mathsym/eo_interface/eoSymCrossover.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EOSYMCROSSOVER_H +#define EOSYMCROSSOVER_H + +class NodeSelector; +class Sym; + +#include + +extern bool subtree_quad(Sym& a, Sym& b, NodeSelector& select); +template +class eoQuadSubtreeCrossover : public eoQuadOp { + NodeSelector& node_selector; + + public: + eoQuadSubtreeCrossover(NodeSelector& _node_selector) : node_selector(_node_selector) {} + + bool operator()(EoType& a, EoType& b) { return subtree_quad(a,b, node_selector); } +}; + + +extern bool subtree_bin(Sym& a, const Sym& b, NodeSelector& select); +template +class eoBinSubtreeCrossover : public eoBinOp { + NodeSelector& node_selector; + + public : + + eoBinSubtreeCrossover(NodeSelector& _node_selector) : node_selector(_node_selector) {} + + bool operator()(EoType& a, const EoType& b) { return subtree_bin(a, b, node_selector); } +}; + +/** Yet another homologous crossover, afaik not particularly + * defined in the literature + */ +extern bool homologous_bin(Sym& a, const Sym& b); +template +class eoBinHomologousCrossover : public eoBinOp { + public: + bool operator()(EoType& a, const EoType& b) { + return homologous_bin(a,b); + } +}; + + +#endif + diff --git a/eo/contrib/mathsym/eo_interface/eoSymEval.h b/eo/contrib/mathsym/eo_interface/eoSymEval.h new file mode 100644 index 000000000..bbc8392af --- /dev/null +++ b/eo/contrib/mathsym/eo_interface/eoSymEval.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SYMEVAL_H +#define SYMEVAL_H + +#include +#include +#include + +#include + +template +class eoSymPopEval : public eoPopEvalFunc { + + BoundsCheck& check; + ErrorMeasure& measure; + + public: + + eoSymPopEval(BoundsCheck& _check, ErrorMeasure& _measure) : + check(_check), measure(_measure) {} + + /** apparently this thing works on two populations, why? + * + * In any case, currently only implemented the population wide + * evaluation version, as that one is much faster. This because the + * compile going on behind the scenes is much faster when done in one + * go (and using subtree similarity) then when done on a case by case + * basis. + */ + void operator()(eoPop& p1, eoPop& p2) { + + std::vector unevaluated; + std::vector tmppop; + + for (unsigned i = 0; i < p1.size(); ++i) { + if (p1[i].invalid()) { + + if (check.in_bounds(p1[i])) { + unevaluated.push_back(i); + tmppop.push_back( static_cast(p1[i]) ); + } else { + p1[i].fitness( measure.worst_performance() ); + } + } + } + + for (unsigned i = 0; i < p2.size(); ++i) { + if (p2[i].invalid()) { + + if (check.in_bounds(p2[i])) { + + unevaluated.push_back(p1.size() + i); + tmppop.push_back( static_cast(p2[i]) ); + + } else { + p2[i].fitness( measure.worst_performance() ); // pretty bad error + } + } + } + + std::vector result = measure.calc_error(tmppop); + + for (unsigned i = 0; i < result.size(); ++i) { + unsigned idx = unevaluated[i]; + + if (idx < p1.size()) { + p1[idx].fitness(result[i].error); + } else { + idx -= p1.size(); + p2[idx].fitness(result[i].error); + } + } + } + +}; + + +#endif diff --git a/eo/contrib/mathsym/eo_interface/eoSymInit.h b/eo/contrib/mathsym/eo_interface/eoSymInit.h new file mode 100644 index 000000000..591b0050a --- /dev/null +++ b/eo/contrib/mathsym/eo_interface/eoSymInit.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EOSYMINIT_H +#define EOSYMINIT_H + +#include +#include + +/** Default initializer, Koza style */ +template +class eoSymInit : public eoInit { + + TreeBuilder& builder; + + double own_grow_prob; + unsigned own_max_depth; + + + double& grow_prob; + unsigned& max_depth; + + public: + + /** By default build ramped half and half with max depth 6 */ + eoSymInit(TreeBuilder& _builder) + : builder(_builder), + own_grow_prob(0.5), + own_max_depth(6), + grow_prob(own_grow_prob), + max_depth(own_max_depth) + {} + + /** Control the grow_prob and max_depth externally */ + eoSymInit(TreeBuilder& _builder, double& _grow_prob, unsigned& _max_depth) + : builder(_builder), + grow_prob(_grow_prob), + max_depth(_max_depth) + {} + + /** build the tree */ + void operator()(EoType& tree) { + int depth_to_use = rng.random(max_depth-2) + 2; // two levels minimum + builder.build_tree(tree, depth_to_use, rng.flip(grow_prob)); + } + +}; + +#endif + diff --git a/eo/contrib/mathsym/eo_interface/eoSymMutate.h b/eo/contrib/mathsym/eo_interface/eoSymMutate.h new file mode 100644 index 000000000..03a95d1d2 --- /dev/null +++ b/eo/contrib/mathsym/eo_interface/eoSymMutate.h @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SYMMUTATE_H +#define SYMMUTATE_H + +#include +#include + +#include +#include + +template +class eoSymSubtreeMutate : public eoMonOp { + + TreeBuilder& subtree_builder; + NodeSelector& node_selector; + + public : + + eoSymSubtreeMutate(TreeBuilder& _subtree_builder, NodeSelector& _node_selector) + : subtree_builder(_subtree_builder), node_selector(_node_selector) {} + + + bool operator()(EoType& tomutate) { + unsigned xover_point = node_selector.select_node(tomutate); + // create subtree + Sym newtree = subtree_builder.build_tree(6, true); // TODO, parameterize + static_cast(tomutate) = insert_subtree(tomutate, xover_point, newtree); + return true; + } + +}; + +/** Class for doing node mutation + * Two parameters: + * + * mutation_rate (the rate at which to do mutation) + * is_rate_absolute : don't rescale the rate to the size of the tree + */ + +template +class eoSymNodeMutate : public eoMonOp { + + LanguageTable& table; + double own_mutation_rate; + bool own_is_rate_absolute; + + // these two can (should?) move to an impl file + bool mutate(Sym& sym, double p) { + std::pair r = do_mutate(sym, p); + sym = r.first; + return r.second; + } + + std::pair do_mutate(Sym sym, double p) { + + bool changed = false; + SymVec args = sym.args(); + if (rng.flip(p)) { + token_t new_token = table.get_random_function( args.size()); + if (new_token != sym.token()) changed = true; + sym = Sym(new_token, args); + } + + for (unsigned i = 0; i < args.size(); ++i) { + std::pair r = do_mutate(args[i], p); + changed |= r.second; + if (r.second) + args[i] = r.first; + } + + if (changed) + return std::make_pair(Sym(sym.token(), args), true); + // else + return std::make_pair(sym, false); + } + + public: + + double& mutation_rate; + bool& is_rate_absolute; + + eoSymNodeMutate(LanguageTable& _table) + : table(_table), + own_mutation_rate(1.0), + own_is_rate_absolute(false), // this means a probability of node mutation of 1/sym.size() + mutation_rate(own_mutation_rate), + is_rate_absolute(own_is_rate_absolute) + {} + + eoSymNodeMutate(LanguageTable& _table, double& _mutation_rate, bool& _is_rate_absolute) + : table(_table), + mutation_rate(_mutation_rate), + is_rate_absolute(_is_rate_absolute) + {} + + + bool operator()(EoType& _eo) { + double p = mutation_rate; + if (!is_rate_absolute) p /= _eo.size(); + + return mutate(_eo, p); + } + +}; + +#endif diff --git a/eo/contrib/mathsym/eval/BoundsCheck.cpp b/eo/contrib/mathsym/eval/BoundsCheck.cpp new file mode 100644 index 000000000..715ebf524 --- /dev/null +++ b/eo/contrib/mathsym/eval/BoundsCheck.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "BoundsCheck.h" +#include +#include +#include + +using namespace std; + +class IntervalBoundsCheckImpl { + public : + vector bounds; +}; + +IntervalBoundsCheck::IntervalBoundsCheck(const vector& mins, const vector& maxes) { + pimpl = new IntervalBoundsCheckImpl; + vector& b = pimpl->bounds; + + b.resize( mins.size()); + + for (unsigned i = 0; i < b.size(); ++i) { + b[i] = Interval(mins[i], maxes[i]); + } + +} + +IntervalBoundsCheck::~IntervalBoundsCheck() { delete pimpl; } +IntervalBoundsCheck::IntervalBoundsCheck(const IntervalBoundsCheck& that) { pimpl = new IntervalBoundsCheckImpl(*that.pimpl); } +IntervalBoundsCheck& IntervalBoundsCheck::operator=(const IntervalBoundsCheck& that) { *pimpl = *that.pimpl; return *this; } + +bool IntervalBoundsCheck::in_bounds(const Sym& sym) const { + Interval bounds; + + try { + bounds = eval(sym, pimpl->bounds); + if (!valid(bounds)) return false; + } catch (interval_error) { + return false; + } + return true; +} + +std::string IntervalBoundsCheck::get_bounds(const Sym& sym) const { + + try { + Interval bounds = eval(sym, pimpl->bounds); + if (!valid(bounds)) return "err"; + ostringstream os; + os << bounds; + return os.str(); + } catch (interval_error) { + return "err"; + } +} + + +std::pair IntervalBoundsCheck::calc_bounds(const Sym& sym) const { + + Interval bounds = eval(sym, pimpl->bounds); + return make_pair(bounds.lower(), bounds.upper()); +} + + diff --git a/eo/contrib/mathsym/eval/BoundsCheck.h b/eo/contrib/mathsym/eval/BoundsCheck.h new file mode 100644 index 000000000..d484d0293 --- /dev/null +++ b/eo/contrib/mathsym/eval/BoundsCheck.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef BOUNDS_CHECK_H_ +#define BOUNDS_CHECK_H_ + +#include + +class IntervalBoundsCheckImpl; +class Sym; + +class BoundsCheck { + public : + virtual ~BoundsCheck() {}; + virtual bool in_bounds(const Sym&) const = 0; + virtual std::string get_bounds(const Sym&) const = 0; +}; + +// checks if a formula keeps within bounds using interval arithmetic +class IntervalBoundsCheck : public BoundsCheck { + + IntervalBoundsCheckImpl* pimpl; + + public: + + IntervalBoundsCheck(const std::vector& minima, const std::vector& maxima); + ~IntervalBoundsCheck(); + IntervalBoundsCheck(const IntervalBoundsCheck&); + IntervalBoundsCheck& operator=(const IntervalBoundsCheck&); + + bool in_bounds(const Sym&) const; + std::string get_bounds(const Sym&) const; + + std::pair calc_bounds(const Sym&) const; +}; + +class NoBoundsCheck : public BoundsCheck { + bool in_bounds(const Sym&) const { return false; } + std::string get_bounds(const Sym&) const { return ""; } +}; + +#endif + + diff --git a/eo/contrib/mathsym/eval/Interval.h b/eo/contrib/mathsym/eval/Interval.h new file mode 100644 index 000000000..1849af4cd --- /dev/null +++ b/eo/contrib/mathsym/eval/Interval.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef INTERVAL__H__ +#define INTERVAL__H__ + +#include +#include +#include + + +typedef boost::numeric::interval_lib::rounded_transc_exact RoundingTransc; +typedef boost::numeric::interval_lib::save_state Rounding; +typedef boost::numeric::interval_lib::checking_base Checking; +typedef boost::numeric::interval_lib::policies Policy; +typedef boost::numeric::interval Interval; + +struct interval_error{}; + +inline bool valid(const Interval& val) { + if (!finite(val.lower()) || !finite(val.upper())) return false; + + return val.lower() > -1e10 && val.upper() < 1e10; +} + +inline Interval sqrt(const Interval& val) { + if (val.lower() < 0.0) { + return Interval::whole(); + } + + return boost::numeric::sqrt(val); +} + +inline Interval sqr(const Interval& val) { + return square(val); +} + +inline Interval acos(const Interval& val) { + if (val.lower() < 1.0 || val.upper() > 1.0) { + return Interval::whole(); + } + + return boost::numeric::acos(val); +} + +inline Interval asin(const Interval& val) { + if (val.lower() < 1.0 || val.upper() > 1.0) { + return Interval::whole(); + } + + return boost::numeric::asin(val); +} + +inline Interval acosh(const Interval& val) { + if (val.lower() < 1.0) return Interval::whole(); + return boost::numeric::acosh(val); +} + +inline +std::ostream& operator<<(std::ostream& os, const Interval& val) { + os << '[' << val.lower() << ", " << val.upper() << ']'; + return os; +} + +#ifdef TEST_INTERVAL +using namespace std; +using namespace boost::numeric; + +int main() { + Interval a(0, 10); + Interval b(-1.5, 2); + cout << "a = " << a << endl; + cout << "b = " << b << endl; + cout << "a + b = " << a + b << endl; + cout << "a - b = " << a - b << endl; + cout << "b - a = " << b - a << endl; + cout << "-a = " << -a << endl; + cout << "a * b = " << a * b << endl; + cout << "b/(a+1) = " << b / (a + 1.0) << endl; + cout << "b * a = " << b * a << endl; + + cout << "b / a = " << b/a << endl; + + cout << "cos(a) = " << cos(a) << endl; + cout << "cos(b) = " << cos(b) << endl; + + cout << "log(b) = " << log(b) << endl; + + cout << "sqrt(b) = " << sqrt(b) << endl; + cout << "sqrt(a) = " << sqrt(a) << endl; + cout << "sqr(b) = " << sqr(b) << endl; + + cout << "exp(b*a)= " << exp(b*a) << endl; + + cout << "atan(a) = " << atan(a) << endl; + cout << "cosh(b) = " << cosh(b) << endl; + +} +#endif + +#endif diff --git a/eo/contrib/mathsym/eval/c_compile.c b/eo/contrib/mathsym/eval/c_compile.c new file mode 100644 index 000000000..2dcdc0537 --- /dev/null +++ b/eo/contrib/mathsym/eval/c_compile.c @@ -0,0 +1,40 @@ +#include +#include +#include + +static TCCState* s = 0; + +extern void symc_init() { + if (s != 0) { + tcc_delete(s); + } + s = tcc_new(); + + if (s == 0) { + fprintf(stderr, "Tiny cc doesn't function properly"); + exit(1); + } +} + +extern void symc_compile(const char* func_str) { + //printf("Compiling %s\n", func_str); + tcc_compile_string(s, func_str); +} + +extern void symc_link() { + tcc_relocate(s); +} + +extern void* symc_get_fun(const char* func_name) { + unsigned long val; + tcc_get_symbol(s, &val, func_name); + return (void*) val; +} + +extern void* symc_make(const char* func_str, const char* func_name) { + symc_init(); + symc_compile(func_str); + symc_link(); + return symc_get_fun(func_name); +} + diff --git a/eo/contrib/mathsym/eval/sym_compile.cpp b/eo/contrib/mathsym/eval/sym_compile.cpp new file mode 100644 index 000000000..81254e5fc --- /dev/null +++ b/eo/contrib/mathsym/eval/sym_compile.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#if __GNUC__ == 3 +#include +#else +#include +using std::hash_map; +#endif + +#include "Sym.h" +#include "FunDef.h" +#include "sym_compile.h" + +#include + +using namespace std; + +extern "C" { + void symc_init(); + void symc_compile(const char* func_str); + void symc_link(); + void* symc_get_fun(const char* func_name); + void* symc_make(const char* func_str, const char* func_name); +} + +string make_prototypes() { + string prot = get_prototypes(); + prot += "double sqr(double x) { return x*x; }"; + return prot; +} + +// contains variable names, like 'a0', 'a1', etc. +typedef hash_map HashMap; + +HashMap::iterator find_entry(Sym sym, ostream& os, HashMap& map) { + HashMap::iterator result = map.find(sym); + + if (result == map.end()) { // new entry + const SymVec& args = sym.args(); + vector argstr(args.size()); + for (unsigned i = 0; i < args.size(); ++i) { + argstr[i] = find_entry(args[i], os, map)->second; + } + + unsigned current_entry = map.size(); // current number of variables defined + + // write out the code + const FunDef& fun = get_element(sym.token()); + string code = fun.c_print(argstr, vector()); + os << "double a" << current_entry << "=" << code << ";\n"; + + // insert variable ref in map + ostringstream str; + str << 'a' << current_entry; + + result = map.insert( make_pair(sym, str.str()) ).first; // only want iterator + } + + return result; +} + +void write_entry(Sym sym, ostream& os, HashMap& map, unsigned out) { + HashMap::iterator it = find_entry(sym, os, map); + os << "y[" << out << "]=" << it->second << ";\n"; +} + +multi_function compile(const std::vector& syms) { + + ostringstream os; + + os << make_prototypes(); + + os << "double func(const double* x, double* y) { \n "; + + HashMap map; + + for (unsigned i = 0; i < syms.size(); ++i) { + write_entry(syms[i], os, map, i); + } + + os << ";}"; + string func_str = os.str(); + + //cout << "compiling " << func_str << endl; + + return (multi_function) symc_make(func_str.c_str(), "func"); +} + +single_function compile(Sym sym) { + + ostringstream os; + + os << make_prototypes(); + os << "double func(const double* x) { return "; + + string code = c_print(sym); + os << code; + os << ";}"; + string func_str = os.str(); + + //cout << "compiling " << func_str << endl; + + return (single_function) symc_make(func_str.c_str(), "func"); +} + +/* finds and inserts the full code in a hashmap */ +HashMap::iterator find_code(Sym sym, HashMap& map) { + HashMap::iterator result = map.find(sym); + + if (result == map.end()) { // new entry + const SymVec& args = sym.args(); + vector argstr(args.size()); + for (unsigned i = 0; i < args.size(); ++i) { + argstr[i] = find_code(args[i], map)->second; + } + + // write out the code + const FunDef& fun = get_element(sym.token()); + string code = fun.c_print(argstr, vector()); + result = map.insert( make_pair(sym, code) ).first; // only want iterator + } + + return result; +} + +string print_code(Sym sym, HashMap& map) { + HashMap::iterator it = find_code(sym, map); + return it->second; +} + +void compile(const std::vector& syms, std::vector& functions) { + symc_init(); + + ostringstream os; + os << make_prototypes(); + HashMap map; + for (unsigned i = 0; i < syms.size(); ++i) { + + os << "double func" << i << "(const double* x) { return "; + os << print_code(syms[i], map); //c_print(syms[i]); + os << ";}\n"; + + //symc_compile(os.str().c_str()); + //cout << "compiling " << os.str() << endl; + } + +#ifdef INTERVAL_DEBUG + //cout << "Compiling " << os.str() << endl; +#endif + + symc_compile(os.str().c_str()); + symc_link(); + + functions.resize(syms.size()); + for (unsigned i = 0; i < syms.size(); ++i) { + ostringstream os2; + os2 << "func" << i; + + functions[i] = (single_function) symc_get_fun(os2.str().c_str()); + } + +} + + + diff --git a/eo/contrib/mathsym/eval/sym_compile.h b/eo/contrib/mathsym/eval/sym_compile.h new file mode 100644 index 000000000..2a8b7f95f --- /dev/null +++ b/eo/contrib/mathsym/eval/sym_compile.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SYMCOMPILE_H_ +#define SYMCOMPILE_H_ + +#include + + +typedef double (*single_function)(const double *); +typedef void (*multi_function)(const double*, double*); // last argument is output + +/* + * Important, after every call of the functions below, the function pointers of the previous + * call are invalidated. Sorry, but that's the way the cookie crumbles (in tcc) + * */ + +single_function compile(Sym sym); +multi_function compile(const std::vector& sym); +void compile(const std::vector& sym, std::vector& functions); + +#endif diff --git a/eo/contrib/mathsym/fun/FunDef.cpp b/eo/contrib/mathsym/fun/FunDef.cpp new file mode 100644 index 000000000..60891af22 --- /dev/null +++ b/eo/contrib/mathsym/fun/FunDef.cpp @@ -0,0 +1,569 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#if __GNUC__ == 3 +#include +#else +#include +using std::hash_map; +#endif + +#include "Sym.h" +#include "FunDef.h" +#include + +using namespace std; +using namespace boost::numeric; + +vector language; + +token_t add_function(FunDef* function) { + language.push_back(function); + return token_t(language.size()-1); +} + +const FunDef& get_element(token_t token) { return *language[token]; } + +/* Printing */ + +string c_print(const Sym& sym) { + return c_print(sym, vector()); +} + +string c_print(const Sym& sym, const vector& vars) { + const SymVec& args = sym.args(); + vector names(args.size()); + for (unsigned i = 0; i < args.size(); ++i) { + names[i] = c_print(args[i], vars); + } + return language[sym.token()]->c_print(names, vars); +} + +/* Evaluation */ + + +double eval(const Sym& sym, const std::vector& inputs) { + return language[sym.token()]->eval(sym.args(), inputs); +} + + +/* Interval Logic */ +Interval eval(const Sym& sym, const vector& inputs) { + const SymVec& args = sym.args(); + vector interv(args.size()); + for (unsigned i = 0; i < args.size(); ++i) { + interv[i] = eval(args[i], inputs); + + if (!valid(interv[i])) throw interval_error(); + } + + return language[sym.token()]->eval(interv, inputs); +} + +/* */ +void add_function_to_table(LanguageTable& table, token_t token) { + const FunDef& fundef = *language[token]; + + if (fundef.has_varargs() == false) { + table.add_function(token, fundef.min_arity()); + } else { // sum or prod (or min or max) + table.add_function(token, 2); + } +} + + +// by default it is eager +double FunDef::eval(const SymVec& args, const vector& inputs) const { + vector values(args.size()); + for (unsigned i = 0; i < args.size(); ++i) { + values[i] = ::eval(args[i], inputs); + } + + return eval(values, inputs); +} + +/* Variable Handling */ +FunDef* make_var(int idx); // defined in FunDefs.h +static vector var_token; + +Sym SymVar(unsigned idx) { + if (var_token.size() <= idx) { + // it is new + var_token.resize(idx+1, token_t(-1)); + var_token[idx] = add_function( make_var(idx) ); + } else if (var_token[idx] == token_t(-1)) { + var_token[idx] = add_function( make_var(idx) ); + } + + return Sym(var_token[idx]); +} + + +/* Constant Handling */ + +struct HashDouble{ + size_t operator()(double val) const { + unsigned long h = 0; + char* s = (char*)&val; + for (unsigned i=0 ; i DoubleSet; + +static DoubleSet doubleSet; // for quick checking if a constant already exists +static vector is_constant; +static vector token_value; + +static std::vector free_list; + +void delete_val(token_t token) { // clean up the information about this constant + if (is_constant[token]) { + double value = token_value[token]; + + delete language[token]; + language[token] = 0; + + doubleSet.erase(value); + free_list.push_back(token); + } +} +FunDef* make_const(double value); + +Sym SymConst(double value) { + + Sym::set_extra_dtor(delete_val); + + DoubleSet::iterator it = doubleSet.find(value); + + if (it != doubleSet.end()) { + return Sym(it->second); + } + + + if (free_list.empty()) { // make space for tokens; + unsigned sz = language.size(); + language.resize(sz + sz+1); // double + is_constant.resize(language.size(), false); + token_value.resize(language.size(), 0.0); + + for (unsigned i = sz; i < language.size(); ++i) { + free_list.push_back(i); + } + } + + token_t token = free_list.back(); + free_list.pop_back(); + + assert(language[token] == 0); + + language[token] = make_const(value); + doubleSet[value] = token; + is_constant[token] = true; + token_value[token] = value; + + return Sym(token); +} + +/* LanguageTable depends on this one, XXX move somewhere safe.*/ +#include +extern Sym default_const() { return SymConst(rng.normal()); } + +/* The functions */ + +class Var : public FunDef { + public : + int idx; + string default_str; + + Var(int _idx) : idx(_idx) { + ostringstream os; + os << "x[" << idx << ']'; // CompiledCode expects this form + default_str = os.str(); + } + + double eval(const vector& _, const vector& inputs) const { return inputs[idx]; } + double eval(const SymVec& _, const vector& inputs) const { return inputs[idx]; } + string c_print(const vector& _, const vector& names) const { + if (names.empty()) { + return default_str; + } + return names[idx]; + } + + Interval eval(const vector& _, const vector& inputs) const { + return inputs[idx]; + } + + unsigned min_arity() const { return 0; } + + string name() const { return "var"; } + +}; + +class Const : public FunDef { + private: + double value; + string value_str; + public: + Const(double _value) : value(_value) { + ostringstream os; + os.precision(17); + os.setf(ios::showpoint); + os << '(' << value << ')'; + value_str = os.str(); + } + + + double eval(const vector& _, const vector& inputs) const { return value; } + double eval(const SymVec& _, const vector& inputs) const { return value; } + string c_print(const vector& _, const vector& names) const { + return value_str; + } + + Interval eval(const vector& _, const vector& inputs) const { + // Profil/Bias seems to have a problem with 0 * inf when the Interval is exact zero (fpe) + //if (value == 0.0) return Interval(-BiasEpsilon,BiasEpsilon); + return Interval(value); + } + + unsigned min_arity() const { return 0; } + + string name() const { return "parameter"; } +}; + + +// Get functions out, excluding Const and Var +vector get_defined_functions() { + vector res; + for (unsigned i = 0; i < language.size(); ++i) { + res.push_back(language[i]); + + if (dynamic_cast(language[i]) != 0 || (dynamic_cast(language[i]) != 0) ) { + res.back() = 0; // erase + } + } + + return res; +} + +class Sum : public FunDef { + + public : + + double eval(const vector& vals, const vector& _) const { + double res = 0; + for (unsigned i = 0; i < vals.size(); ++i) res += vals[i]; + return res; + } + + string c_print(const vector& args, const vector& _) const { + if (args.empty()) { return "0.0"; } + + ostringstream os; + os << "(" << args[0]; + for (unsigned i = 1; i < args.size(); ++i) { + os << "+" << args[i]; + } + os << ")"; + return os.str(); + } + + Interval eval(const vector& args, const vector& inputs) const { + Interval interv(0.0); //(0.0-BiasEpsilon, 0.0+BiasEpsilon); // Profil/Bias seems to have a problem with 0 * inf when the Interval is exact zero (fpe) + for (unsigned i = 0; i < args.size(); ++i) { + Interval a = args[i]; // Profil doesn't know much about const correctness + interv += a; + } + return interv; + } + + unsigned min_arity() const { return 0; } + bool has_varargs() const { return true; } + + string name() const { return "sum"; } +}; + + +class Prod : public FunDef { + + public : + + double eval(const vector& vals, const vector& _) const { + double res = 1; + for (unsigned i = 0; i < vals.size(); ++i) res *= vals[i]; + return res; + } + + string c_print(const vector& args, const vector& _) const { + if (args.empty()) { return "1.0"; } + + ostringstream os; + os << "(" << args[0]; + for (unsigned i = 1; i < args.size(); ++i) { + os << "*" << args[i]; + } + os << ")"; + + return os.str(); + } + + Interval eval(const vector& args, const vector& inputs) const { + Interval interv(1.0); + for (unsigned i = 0; i < args.size(); ++i) { + Interval a = args[i]; // Profil doesn't know much about const correctness + interv *= a; + } + return interv; + } + + unsigned min_arity() const { return 0; } + bool has_varargs() const { return true; } + + string name() const { return "prod"; } +}; + + +class Power : public FunDef { + public : + double eval(const vector& vals, const vector& _) const { + return pow(vals[0], vals[1]); + } + + string c_print(const vector& args, const vector& _) const { + return "pow(" + args[0] + ',' + args[1] + ')'; + } + + Interval eval(const vector& args, const vector& _) const { + Interval first = args[0]; + Interval second = args[1]; + Interval lg = log(first); + if (!valid(lg)) throw interval_error(); + return exp(second * lg); + } + + unsigned min_arity() const { return 2; } + + string name() const { return "pow"; } +}; + +class IsNeg : public FunDef { + + public: + double eval(const vector& vals, const vector& _) const { + if (vals[0] < 0.0) return vals[1]; + return vals[2]; + } + + double eval(const Sym& sym, const vector& inputs) const { + const SymVec& args = sym.args(); + double arg0 = ::eval(args[0], inputs); + if (arg0 < 0.0) { + return ::eval(args[1], inputs); + } + return ::eval(args[2], inputs); + } + + string c_print(const vector& args, const vector& _) const { + return "((" + args[0] + "<0.0)?" + args[1] + ":" + args[2]+")"; + } + + Interval eval(const vector& args, const vector& _) const { + Interval a0 = args[0]; + if (a0.upper() < 0.0) return args[1]; + if (a0.lower() >= 0.0) return args[2]; + + return Interval( std::min(args[1].lower(), args[2].lower()), std::max(args[1].upper(), args[2].upper())); + } + + unsigned min_arity() const { return 3; } + + string name() const { return "ifltz"; } +}; + +template +class Unary : public FunDef { + + Func un; + + double eval(const vector& vals, const vector& _) const { + return un(vals[0]); + } + + string c_print(const vector& args, const vector& _) const { + return un(args[0]); + } + + Interval eval(const vector& args, const vector& _) const { + return un(args[0]); + } + + unsigned min_arity() const { return 1; } + + string name() const { return un.name(); } + +}; + +struct Inv { + double operator()(double val) const { return 1.0 / val; } + string operator()(string v) const { return "(1./" + v + ")"; } + Interval operator()(Interval v) const { return 1.0 / v; } + + string name() const { return "inv"; } +}; + +struct Min { + double operator()(double val) const { return -val; } + string operator()(string v) const { return "(-" + v + ")"; } + Interval operator()(Interval v) const { return -v; } + + string name() const { return "min"; } +}; + +string prototypes = "double pow(double, double);"; +string get_prototypes() { return prototypes; } +unsigned add_prototype(string str) { prototypes += string("double ") + str + "(double);"; return prototypes.size(); } + + +#define FUNCDEF(funcname) struct funcname##_struct { \ + double operator()(double val) const { return funcname(val); }\ + string operator()(string val) const { return string(#funcname) + '(' + val + ')'; }\ + Interval operator()(Interval val) const { return funcname(val); }\ + string name() const { return string(#funcname); }\ +};\ +const token_t funcname##_token = add_function( new Unary);\ +unsigned funcname##_size = add_prototype(#funcname); + + + +FunDef* make_var(int idx) { return new Var(idx); } +FunDef* make_const(double value) { return new Const(value); } + +const token_t sum_token = add_function( new Sum ); +const token_t prod_token = add_function( new Prod); +const token_t inv_token = add_function( new Unary); +const token_t min_token = add_function( new Unary); +const token_t pow_token = add_function( new Power); +const token_t ifltz_token = add_function( new IsNeg); + +FUNCDEF(sin); +FUNCDEF(cos); +FUNCDEF(tan); +FUNCDEF(asin); +FUNCDEF(acos); +FUNCDEF(atan); + +FUNCDEF(sinh); +FUNCDEF(cosh); +FUNCDEF(tanh); +FUNCDEF(asinh); +FUNCDEF(acosh); +FUNCDEF(atanh); + +FUNCDEF(exp); +FUNCDEF(log); + +double sqr(double x) { return x*x; } + +FUNCDEF(sqr); +FUNCDEF(sqrt); + +/* Serialization */ +void write_raw(ostream& os, const Sym& sym) { + token_t token = sym.token(); + const SymVec& args = sym.args(); + + if (is_constant.size() > token && is_constant[token]) { + os << "c" << language[token]->c_print(vector(), vector()); + } else { + + const Var* var = dynamic_cast( language[token] ); + + if (var != 0) { + os << "v" << var->idx; + } else { + os << "f" << token << ' ' << args.size(); + } + } + + for (unsigned i = 0; i < args.size(); ++i) { + write_raw(os, args[i]); + } +} + +string write_raw(const Sym& sym) { + + ostringstream os; + write_raw(os, sym); + + return os.str(); +} + +Sym read_raw(istream& is) { + char id = is.get(); + + switch (id) { + case 'c' : + { + double val; + is.get(); // skip '(' + is >> val; + is.get(); // skip ')' + return SymConst(val); + } + case 'v' : + { + unsigned idx; + is >> idx; + return SymVar(idx); + } + case 'f' : + { + token_t token; + unsigned arity; + is >> token; + is >> arity; + SymVec args(arity); + for (unsigned i = 0; i < arity; ++i) { + args[i] = read_raw(is); + } + + return Sym(token, args); + } + default : { + cerr << "Character = " << id << " Could not read formula from stream" << endl; + exit(1); + } + + } + + return Sym(); +} + +Sym read_raw(string str) { + istringstream is(str); + return read_raw(is); +} + +void read_raw(istream& is, Sym& sym) { + sym = read_raw(is); +} + diff --git a/eo/contrib/mathsym/fun/FunDef.h b/eo/contrib/mathsym/fun/FunDef.h new file mode 100644 index 000000000..d250c3dda --- /dev/null +++ b/eo/contrib/mathsym/fun/FunDef.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef FUNCTION_DEF_H_ +#define FUNCTION_DEF_H_ + +#include +#include +#include + +#include "Sym.h" +#include "Interval.h" + +class FunDef { + public: + + virtual ~FunDef() {} + + // (possibly) lazy evaluation function, default implementation calls 'eager' eval + virtual double eval(const SymVec& args, const std::vector& inputs) const; + + // eager evaluation function + virtual double eval(const std::vector& args, const std::vector& inputs) const = 0; + + // interval evaluation + virtual Interval eval(const std::vector& args, const std::vector& inputs) const = 0; + + // prints 'c' like code + virtual std::string c_print(const std::vector& names, const std::vector& names) const = 0; + + virtual unsigned min_arity() const = 0; + virtual bool has_varargs() const { return false; } // sum, prod, min, max are variable arity + + virtual std::string name() const = 0; + + protected: + +}; + +extern std::vector get_defined_functions(); +extern const FunDef& get_element(token_t token); + +/* Single case evaluation */ +extern double eval(const Sym& sym, const std::vector& inputs); + +/* Static analysis through interval arithmetic */ +extern Interval eval(const Sym& sym, const std::vector& inputs); + +/* Pretty printers, second version allows setting of variable names */ +extern std::string c_print(const Sym& sym); +extern std::string c_print(const Sym& sym, const std::vector& var_names); + +/* Pretty printer streamer */ +inline std::ostream& operator<<(std::ostream& os, Sym sym) { return os << c_print(sym); } + +/* Create constant */ +extern Sym SymConst(double value); + +/* Create variable */ +extern Sym SymVar(unsigned idx); + +/* Add function to the language table (and take a guess at the arity) */ +class LanguageTable; +extern void add_function_to_table(LanguageTable& table, token_t token); + +// token names +extern const token_t sum_token; +extern const token_t prod_token; +extern const token_t inv_token; +extern const token_t min_token; +extern const token_t pow_token; +extern const token_t ifltz_token; + +#define HEADERFUNC(name) extern const token_t name##_token;\ + inline Sym name(Sym arg) { return Sym(name##_token, arg); } + +/* This defines the tokens: sin_token, cos_token, etc. */ +HEADERFUNC(sin); +HEADERFUNC(cos); +HEADERFUNC(tan); +HEADERFUNC(asin); +HEADERFUNC(acos); +HEADERFUNC(atan); + +HEADERFUNC(sinh); +HEADERFUNC(cosh); +HEADERFUNC(tanh); +HEADERFUNC(asinh); +HEADERFUNC(acosh); +HEADERFUNC(atanh); + +HEADERFUNC(exp); +HEADERFUNC(log); + +HEADERFUNC(sqr); +HEADERFUNC(sqrt); + +extern std::string get_prototypes(); + +// reading and writing in internal format +extern std::string write_raw(const Sym& sym); +extern void write_raw(ostream& os, const Sym& sym); +extern Sym read_raw(std::string str); +extern Sym read_raw(std::istream& is); +extern void read_raw(std::istream& is, Sym& sym); + +#include "SymOps.h" + +#endif + diff --git a/eo/contrib/mathsym/fun/SymOps.cpp b/eo/contrib/mathsym/fun/SymOps.cpp new file mode 100644 index 000000000..2d66b0d05 --- /dev/null +++ b/eo/contrib/mathsym/fun/SymOps.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "FunDef.h" +#include "SymOps.h" +#include "Sym.h" + +using namespace std; + +void collect(token_t t, Sym a, SymVec& args) { + + if (a.token() == t) { + const SymVec& a_args = a.args(); + for (unsigned i = 0; i < a_args.size(); ++i) { + collect(t, a_args[i], args); + } + return; + } + + args.push_back(a); +} + +Sym operator+(Sym a, Sym b) { + + SymVec args; + + collect(sum_token, a, args); + collect(sum_token, b, args); + + return Sym(sum_token, args); +} + +Sym operator*(Sym a, Sym b) { + + SymVec args; + + collect(prod_token, a, args); + collect(prod_token, b, args); + + return Sym(prod_token, args); +} + +Sym operator/(Sym a, Sym b) { + + SymVec args; + + collect(prod_token, a, args); + + SymVec args2; + collect(prod_token, b, args2); + + SymVec inv; + inv.push_back(Sym(prod_token, args2)); + + args.push_back( Sym(inv_token, inv) ); + + return Sym(prod_token, args); +} + +Sym operator-(Sym a, Sym b) { + + SymVec args; + + collect(sum_token, a, args); + + SymVec args2; + collect(sum_token, b, args2); + + SymVec min; + min.push_back(Sym(sum_token, args2)); + + args.push_back( Sym(min_token, min) ); + + return Sym(sum_token, args); +} + +Sym operator-(Sym a) { + return Sym(min_token, a); +} + +Sym pow(Sym a, Sym b) { + SymVec args; + args.push_back(a); + args.push_back(b); + return Sym(pow_token, args); +} + +Sym ifltz(Sym a, Sym b, Sym c) { + SymVec args; + args.push_back(a); + args.push_back(b); + args.push_back(c); + return Sym(ifltz_token, args); +} + diff --git a/eo/contrib/mathsym/fun/SymOps.h b/eo/contrib/mathsym/fun/SymOps.h new file mode 100644 index 000000000..16eb35fe3 --- /dev/null +++ b/eo/contrib/mathsym/fun/SymOps.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SYMOPS_H +#define SYMOPS_H + +#include "Sym.h" + +extern Sym operator+(Sym a, Sym b); +extern Sym operator*(Sym a, Sym b); +extern Sym operator/(Sym a, Sym b); +extern Sym operator-(Sym a, Sym b); +extern Sym pow(Sym a, Sym b); +extern Sym ifltz(Sym a, Sym b, Sym c); +extern Sym operator-(Sym a); + +#endif diff --git a/eo/contrib/mathsym/fun/util.cpp b/eo/contrib/mathsym/fun/util.cpp new file mode 100644 index 000000000..83e751dec --- /dev/null +++ b/eo/contrib/mathsym/fun/util.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +using namespace std; + +double error(string errstr) { + cerr << "ERROR: " << errstr << endl; + exit(1); +} + diff --git a/eo/contrib/mathsym/gen/LanguageTable.cpp b/eo/contrib/mathsym/gen/LanguageTable.cpp new file mode 100644 index 000000000..c5906afba --- /dev/null +++ b/eo/contrib/mathsym/gen/LanguageTable.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "LanguageTable.h" +#include "Sym.h" + +#include + +using namespace std; + +eoRng rng(time(0)); + +extern Sym default_const(); + +class LanguageImpl { + public : + std::vector vars; + LanguageTable::erc_func erc; + + std::vector functions; + std::vector< std::vector > functions_per_arity; + + LanguageImpl() : erc(default_const) {} +}; + +LanguageTable::LanguageTable() { + pimpl = new LanguageImpl; +} + +LanguageTable::~LanguageTable() { + delete pimpl; +} + +LanguageTable::LanguageTable(const LanguageTable& that) { + pimpl = new LanguageImpl(*that.pimpl); +} + +LanguageTable& LanguageTable::operator=(const LanguageTable& that) { + *pimpl = *that.pimpl; + return *this; +} + +void LanguageTable::add_function(token_t token, unsigned arity) { + functor_t f = {token, arity}; + add_function( f ); +} + +void LanguageTable::add_function(functor_t f) { + + if (f.arity > 0) { + pimpl->functions.push_back(f); + + } else { + pimpl->vars.push_back(Sym(f.token)); + } + + if (pimpl->functions_per_arity.size() <= f.arity) pimpl->functions_per_arity.resize(f.arity+1); + pimpl->functions_per_arity[f.arity].push_back(f.token); + +} + +void LanguageTable::set_erc( erc_func func) { pimpl->erc = func; } + +/* Getting info out */ + +extern Sym SymConst(double val); + +Sym LanguageTable::get_random_var() const { return rng.choice(pimpl->vars); } +Sym LanguageTable::get_random_const() const { return pimpl->erc(); } + +functor_t LanguageTable::get_random_function() const +{ + return rng.choice(pimpl->functions); +} + +token_t LanguageTable::get_random_function(unsigned arity) const +{ + return rng.choice(pimpl->functions_per_arity[arity]); +} + + + diff --git a/eo/contrib/mathsym/gen/LanguageTable.h b/eo/contrib/mathsym/gen/LanguageTable.h new file mode 100644 index 000000000..a19bc8890 --- /dev/null +++ b/eo/contrib/mathsym/gen/LanguageTable.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef LANGUAGE_TABLE_H +#define LANGUAGE_TABLE_H + +#include "token.h" + +class LanguageImpl; +class Sym; + +class LanguageTable { + + LanguageImpl* pimpl; + + public: + + LanguageTable(); + ~LanguageTable(); + + LanguageTable(const LanguageTable& org); + + LanguageTable& operator=(const LanguageTable& org); + + /* setting it up */ + typedef Sym (*erc_func)(); + + void add_function(token_t token, unsigned arity); + void add_function(functor_t functor); + void set_erc(erc_func func); + + /* Getting info out */ + + Sym get_random_var() const; + Sym get_random_const() const; + + functor_t get_random_function() const; + token_t get_random_function(unsigned arity) const; +}; + +#endif + diff --git a/eo/contrib/mathsym/gen/NodeSelector.cpp b/eo/contrib/mathsym/gen/NodeSelector.cpp new file mode 100644 index 000000000..db41448fe --- /dev/null +++ b/eo/contrib/mathsym/gen/NodeSelector.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "NodeSelector.h" +#include "Sym.h" + +#include + +unsigned RandomNodeSelector::select_node(Sym sym) const { + return rng.random(sym.size()); +} + +unsigned BiasedNodeSelector::select_node(Sym sym) const { + + unsigned p = rng.random(sym.size()); + for (unsigned i = 0; i < nRounds; ++i) { + Sym res = get_subtree(sym, p); + + if (res.args().size() > 0) break; + + p = rng.random(sym.size()); + } + + return p; +} + diff --git a/eo/contrib/mathsym/gen/NodeSelector.h b/eo/contrib/mathsym/gen/NodeSelector.h new file mode 100644 index 000000000..0a2863d9d --- /dev/null +++ b/eo/contrib/mathsym/gen/NodeSelector.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef NODESELECTOR_H +#define NODESELECTOR_H + +class Sym; + +/** Base class for selecting nodes */ +class NodeSelector { + public: + virtual unsigned select_node(Sym sym) const = 0; +}; + + +/** Select nodes uniformly */ +class RandomNodeSelector : public NodeSelector { + public: + unsigned select_node(Sym sym) const; +}; + +/** A node selector that does a specified number of rounds ignoring terminals */ +class BiasedNodeSelector : public NodeSelector { + public: + unsigned nRounds; + + BiasedNodeSelector() : nRounds(3) {} // 3: for binary trees 87.5% chance of selecting an internal node + BiasedNodeSelector(unsigned n) : nRounds(n) {} + + unsigned select_node(Sym sym) const; +}; + +#endif diff --git a/eo/contrib/mathsym/gen/TreeBuilder.cpp b/eo/contrib/mathsym/gen/TreeBuilder.cpp new file mode 100644 index 000000000..70b7ef53e --- /dev/null +++ b/eo/contrib/mathsym/gen/TreeBuilder.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "TreeBuilder.h" + +Sym TreeBuilder::make_terminal() const { + if (rng.flip(vcprob)) { + return table.get_random_var(); + } + + return table.get_random_const(); +} + +Sym TreeBuilder::build_tree(unsigned max_depth, bool grow) const { + if (max_depth == 0 || grow && rng.random(2) == 0) { + return make_terminal(); + } + + // pick a random function, no matter what arity + + functor_t func = table.get_random_function(); + + SymVec args(func.arity); + + for (unsigned i = 0; i < args.size(); ++i) { + args[i] = build_tree(max_depth-1, grow); + } + + return Sym(func.token, args); +} + diff --git a/eo/contrib/mathsym/gen/TreeBuilder.h b/eo/contrib/mathsym/gen/TreeBuilder.h new file mode 100644 index 000000000..1969a52be --- /dev/null +++ b/eo/contrib/mathsym/gen/TreeBuilder.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TREEBUILDER_H_ +#define TREEBUILDER_H_ + +#include "Sym.h" +#include "LanguageTable.h" + +class TreeBuilder { + const LanguageTable& table; + + // probability of selecting a var versus a const when the choice boils down to selecting a terminal + double vcprob; + + Sym make_terminal() const; + public: + + TreeBuilder(const LanguageTable& t) : table(t), vcprob(0.9) {}; + TreeBuilder(const LanguageTable& t, double vc) : table(t), vcprob(vc) {}; + + void set_var_vs_const_probability(double p) { vcprob = p; } + + Sym build_tree(unsigned max_depth, bool grow) const; + + void build_tree(Sym& tree, unsigned max_depth, bool grow) const { tree = build_tree(max_depth, grow); } + +}; + +#endif + diff --git a/eo/contrib/mathsym/header b/eo/contrib/mathsym/header new file mode 100644 index 000000000..a4ea44583 --- /dev/null +++ b/eo/contrib/mathsym/header @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + diff --git a/eo/contrib/mathsym/regression/Dataset.cpp b/eo/contrib/mathsym/regression/Dataset.cpp new file mode 100644 index 000000000..bdb314551 --- /dev/null +++ b/eo/contrib/mathsym/regression/Dataset.cpp @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Dataset.h" +#include +#include + +#include + +using namespace std; + +class DataSetImpl { + public: + vector< vector > inputs; + vector targets; + + void read_data(vector strings) { + // find the number of inputs + + istringstream cnt(strings[0]); + unsigned n = 0; + for (;;) { + string s; + cnt >> s; + if (!cnt) break; + ++n; + } + + inputs.resize(strings.size(), vector(n-1)); + targets.resize(strings.size()); + + for (unsigned i = 0; i < strings.size(); ++i) { + istringstream is(strings[i]); + for (unsigned j = 0; j < n; ++j) { + + if (!is) { + cerr << "Too few targets in record " << i << endl; + exit(1); + } + + if (j < n-1) { + is >> inputs[i][j]; + } else { + is >> targets[i]; + } + + } + } + + } + +}; + +Dataset::Dataset() { pimpl = new DataSetImpl; } +Dataset::~Dataset() { delete pimpl; } +Dataset::Dataset(const Dataset& that) { pimpl = new DataSetImpl(*that.pimpl); } +Dataset& Dataset::operator=(const Dataset& that) { *pimpl = *that.pimpl; return *this; } + +unsigned Dataset::n_records() const { return pimpl->targets.size(); } +unsigned Dataset::n_fields() const { return pimpl->inputs[0].size(); } +const std::vector& Dataset::get_inputs(unsigned record) const { return pimpl->inputs[record]; } +double Dataset::get_target(unsigned record) const { return pimpl->targets[record]; } + +double error(string errstr); + +void Dataset::load_data(std::string filename) { + vector strings; // first load it in strings + + ifstream is(filename.c_str()); + + for(;;) { + string s; + getline(is, s); + if (!is) break; + + if (s[0] == '#') continue; // comment, skip + + strings.push_back(s); + } + + is.close(); + + if (strings.size() == 0) { + error("No data could be loaded"); + } + + pimpl->read_data(strings); + +} + +std::vector Dataset::input_minima() const { + vector >& in = pimpl->inputs; + + vector mn(in[0].size(), 1e+50); + for (unsigned i = 0; i < in.size(); ++i) { + for (unsigned j = 0; j < in[i].size(); ++j) { + mn[j] = std::min(mn[j], in[i][j]); + } + } + + return mn; +} + +vector Dataset::input_maxima() const { + vector >& in = pimpl->inputs; + + vector mx(in[0].size(), -1e+50); + for (unsigned i = 0; i < in.size(); ++i) { + for (unsigned j = 0; j < in[i].size(); ++j) { + mx[j] = std::max(mx[j], in[i][j]); + } + } + + return mx; +} + + + + diff --git a/eo/contrib/mathsym/regression/Dataset.h b/eo/contrib/mathsym/regression/Dataset.h new file mode 100644 index 000000000..395036db5 --- /dev/null +++ b/eo/contrib/mathsym/regression/Dataset.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef DATASET_H_ +#define DATASET_H_ + +#include +#include + +class DataSetImpl; + +class Dataset { + + DataSetImpl* pimpl; + + Dataset& operator=(const Dataset&); // cannot assign + public: + + Dataset(); + ~Dataset(); + Dataset(const Dataset&); + + void load_data(std::string filename); + + unsigned n_records() const; + unsigned n_fields() const; + + const std::vector& get_inputs(unsigned record) const; + double get_target(unsigned record) const; + + std::vector input_minima() const; + std::vector input_maxima() const; + +}; + +#endif + diff --git a/eo/contrib/mathsym/regression/ErrorMeasure.cpp b/eo/contrib/mathsym/regression/ErrorMeasure.cpp new file mode 100644 index 000000000..b6a5795f4 --- /dev/null +++ b/eo/contrib/mathsym/regression/ErrorMeasure.cpp @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#include + +#include "ErrorMeasure.h" +#include "Dataset.h" +#include "Sym.h" +#include "sym_compile.h" +#include "TargetInfo.h" + +using namespace std; + +#ifdef INTERVAL_DEBUG + +#include +#include + +vector none; +IntervalBoundsCheck bounds(none, none); + +#endif + + + +static double not_a_number = atof("nan"); + +class ErrorMeasureImpl { + public: + const Dataset& data; + TargetInfo train_info; + + ErrorMeasure::measure measure; + + Scaling no_scaling; + + ErrorMeasureImpl(const Dataset& d, double t_p, ErrorMeasure::measure m) : data(d), measure(m) { + +#ifdef INTERVAL_DEBUG + bounds = IntervalBoundsCheck(d.input_minima(), d.input_maxima()); +#endif + + unsigned nrecords = d.n_records(); + unsigned cases = unsigned(t_p * nrecords); + + valarray t(cases); + + for (unsigned i = 0; i < cases; ++i) { + t[i] = data.get_target(i); + } + + train_info = TargetInfo(t); + no_scaling = Scaling(new NoScaling); + } + + ErrorMeasure::result eval(const valarray& y) { + + ErrorMeasure::result result; + result.scaling = no_scaling; + + + switch(measure) { + case ErrorMeasure::mean_squared: + result.error = pow(train_info.targets() - y, 2.0).sum() / y.size(); + return result; + case ErrorMeasure::absolute: + result.error = abs(train_info.targets() - y).sum() / y.size(); + return result; + case ErrorMeasure::mean_squared_scaled: + result.scaling = ols(y, train_info); + result.error = pow(train_info.targets() - result.scaling->transform(y), 2.0).sum() / y.size(); + return result; + default: + cerr << "Unknown measure encountered: " << measure << " " << __FILE__ << " " << __LINE__ << endl; + } + + return result; + } + + unsigned train_cases() const { + return train_info.targets().size(); + } + + vector multi_function_eval(const vector& pop) { + + multi_function all = compile(pop); + std::vector y(pop.size()); + std::vector err(pop.size()); + + const std::valarray& t = train_info.targets(); + + for (unsigned i = 0; i < train_cases(); ++i) { + // evaluate + all(&data.get_inputs(i)[0], &y[0]); + + for (unsigned j = 0; j < y.size(); ++j) { + double diff = y[j] - t[i]; + if (measure == ErrorMeasure::mean_squared) { // branch prediction will probably solve this inefficiency + err[j] += diff * diff; + } else { + err[j] += fabs(diff); + } + + } + + } + + std::vector result(pop.size()); + + double n = train_cases(); + Scaling no = Scaling(new NoScaling); + for (unsigned i = 0; i < pop.size(); ++i) { + result[i].error = err[i] / n; + result[i].scaling = no; + } + + return result; + + } + + vector single_function_eval(const vector & pop) { + + vector funcs(pop.size()); + compile(pop, funcs); // get one function pointer for each individual + + valarray y(train_cases()); + vector result(pop.size()); + for (unsigned i = 0; i < funcs.size(); ++i) { + for (unsigned j = 0; j < train_cases(); ++j) { + y[j] = funcs[i](&data.get_inputs(j)[0]); + } + +#ifdef INTERVAL_DEBUG + //cout << "eval func " << i << " " << pop[i] << endl; + pair b = bounds.calc_bounds(pop[i]); + + // check if y is in bounds + for (unsigned j = 0; j < y.size(); ++j) { + if (y[j] < b.first -1e-4 || y[j] > b.second + 1e-4 || !finite(y[j])) { + cout << "Error " << y[j] << " not in " << b.first << ' ' << b.second << endl; + cout << "Function " << pop[i] << endl; + exit(1); + } + } +#endif + + result[i] = eval(y); + } + + return result; + } + + vector calc_error(const vector& pop) { + + // currently we can only accumulate simple measures such as absolute and mean_squared + switch(measure) { + case ErrorMeasure::mean_squared: + case ErrorMeasure::absolute: + return multi_function_eval(pop); + case ErrorMeasure::mean_squared_scaled: + return single_function_eval(pop); + } + + return vector(); + } + +}; + +ErrorMeasure::result::result() { + error = 0.0; + scaling = Scaling(0); +} + +bool ErrorMeasure::result::valid() const { + return isfinite(error); +} + +ErrorMeasure::ErrorMeasure(const Dataset& data, double train_perc, measure meas) { + pimpl = new ErrorMeasureImpl(data, train_perc, meas); +} + +ErrorMeasure::~ErrorMeasure() { delete pimpl; } +ErrorMeasure::ErrorMeasure(const ErrorMeasure& that) { pimpl = new ErrorMeasureImpl(*that.pimpl); } + + +ErrorMeasure::result ErrorMeasure::calc_error(Sym sym) { + + single_function f = compile(sym); + + valarray y(pimpl->train_cases()); + + for (unsigned i = 0; i < y.size(); ++i) { + + y[i] = f(&pimpl->data.get_inputs(i)[0]); + + if (!finite(y[i])) { + result res; + res.scaling = Scaling(new NoScaling); + res.error = not_a_number; + return res; + } + + } + + return pimpl->eval(y); +} + +vector ErrorMeasure::calc_error(const vector& syms) { + return pimpl->calc_error(syms); + +} + +double ErrorMeasure::worst_performance() const { + + if (pimpl->measure == mean_squared_scaled) { + return pimpl->train_info.tvar(); + } + + return 1e+20; // TODO: make this general +} + diff --git a/eo/contrib/mathsym/regression/ErrorMeasure.h b/eo/contrib/mathsym/regression/ErrorMeasure.h new file mode 100644 index 000000000..17619fe97 --- /dev/null +++ b/eo/contrib/mathsym/regression/ErrorMeasure.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ERROR_MEASURE_H +#define ERROR_MEASURE_H + +#include "Scaling.h" + +class ErrorMeasureImpl; +class Sym; +class Dataset; + +class ErrorMeasure { + + ErrorMeasureImpl* pimpl; + + public : + + enum measure { + absolute, + mean_squared, + mean_squared_scaled, + }; + + struct result { + double error; + Scaling scaling; + + result(); + bool valid() const; + }; + + ErrorMeasure(const Dataset& data, double train_perc, measure meas = mean_squared); + + ~ErrorMeasure(); + ErrorMeasure(const ErrorMeasure& that); + ErrorMeasure& operator=(const ErrorMeasure& that); + + result calc_error(Sym sym); + + std::vector calc_error(const std::vector& sym); + + double worst_performance() const; +}; + +#endif + diff --git a/eo/contrib/mathsym/regression/Scaling.cpp b/eo/contrib/mathsym/regression/Scaling.cpp new file mode 100644 index 000000000..dd6b0d0fc --- /dev/null +++ b/eo/contrib/mathsym/regression/Scaling.cpp @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Scaling.h" +#include "TargetInfo.h" + +using namespace std; + +Scaling slope(const std::valarray& x, const TargetInfo& targets) { + + double xx = 0.0; + double xy = 0.0; + + const valarray& y = targets.targets(); + + for (unsigned i = 0; i < x.size(); ++i) { + xx += x[i] * x[i]; + xy += x[i] * y[i]; + } + + if (xx < 1e-7) return Scaling(new LinearScaling(0.0,0.0)); + + double b = xy / xx; + + return Scaling(new LinearScaling(0.0, b)); + +} + +// Still needs proper testing with non-trivial lambda +Scaling regularized_least_squares(const std::valarray& inputs, const TargetInfo& targets, double lambda) { + + double n = inputs.size(); + + valarray x = inputs; + + double a,b,d; + a=b=d=0; + + for (unsigned i = 0; i < n; ++i) { + a += 1 + lambda; + b += x[i]; + d += x[i] * x[i] + lambda; + } + + //invert + + double ad_bc = a*d - b * b; + // if ad_bc equals zero there's a problem + + if (ad_bc < 1e-17) return Scaling(new LinearScaling); + + double ai = d/ad_bc; + double bi = -b/ad_bc; + double di = a/ad_bc; + double ci = bi; + + // Now multiply this inverted covariance matrix (C^-1) with x' * t + + std::valarray ones = x; + + // calculate C^-1 * x' ) + for (unsigned i = 0; i < n; ++i) + { + ones[i] = (ai + bi * x[i]); + x[i] = (ci + di * x[i]); + } + + // results are in [ones, x], now multiply with y + + a = 0.0; // intercept + b = 0.0; // slope + + const valarray& t = targets.targets(); + + for (unsigned i = 0; i < n; ++i) + { + a += ones[i] * t[i]; + b += x[i] * t[i]; + } + + return Scaling(new LinearScaling(a,b)); +} + +Scaling ols(const std::valarray& y, const std::valarray& t) { + double n = y.size(); + + double y_mean = y.sum() / n; + double t_mean = t.sum() / n; + + std::valarray y_var = (y - y_mean); + std::valarray t_var = (t - t_mean); + std::valarray cov = t_var * y_var; + + y_var *= y_var; + t_var *= t_var; + + double sumvar = y_var.sum(); + + if (sumvar == 0. || sumvar/n < 1e-7 || sumvar/n > 1e+7) // breakout when numerical problems are likely + return Scaling(new LinearScaling(t_mean,0.)); + + + double b = cov.sum() / sumvar; + double a = t_mean - b * y_mean; + + Scaling s = Scaling(new LinearScaling(a,b)); + + return s; +} + +Scaling ols(const std::valarray& y, const TargetInfo& targets) { + double n = y.size(); + + double y_mean = y.sum() / n; + + std::valarray y_var = (y - y_mean); + std::valarray cov = targets.tcov_part() * y_var; + + y_var *= y_var; + + double sumvar = y_var.sum(); + + if (sumvar == 0. || sumvar/n < 1e-7 || sumvar/n > 1e+7) // breakout when numerical problems are likely + return Scaling(new LinearScaling(targets.tmean(),0.)); + + + double b = cov.sum() / sumvar; + double a = targets.tmean() - b * y_mean; + + if (!finite(b)) { + + cout << a << ' ' << b << endl; + cout << sumvar << endl; + cout << y_mean << endl; + cout << cov.sum() << endl; + exit(1); + } + + Scaling s = Scaling(new LinearScaling(a,b)); + + return s; +} + + +Scaling wls(const std::valarray& inputs, const TargetInfo& targets) { + + std::valarray x = inputs; + const std::valarray& w = targets.weights(); + + unsigned n = x.size(); + // First calculate x'*W (as W is a diagonal matrix it's simply elementwise multiplication + std::valarray wx = targets.weights() * x; + + // Now x'*W is contained in [w,wx], calculate x' * W * x (the covariance) + double a,b,d; + a=b=d=0.0; + + for (unsigned i = 0; i < n; ++i) + { + a += w[i]; + b += wx[i]; + d += x[i] * wx[i]; + } + + //invert + + double ad_bc = a*d - b * b; + // if ad_bc equals zero there's a problem + + if (ad_bc < 1e-17) return Scaling(new LinearScaling); + + double ai = d/ad_bc; + double bi = -b/ad_bc; + double di = a/ad_bc; + double ci = bi; + + // Now multiply this inverted covariance matrix (C^-1) with x' * W * y + + // create alias to reuse the wx we do not need anymore + std::valarray& ones = wx; + + // calculate C^-1 * x' * W (using the fact that W is diagonal) + for (unsigned i = 0; i < n; ++i) + { + ones[i] = w[i]*(ai + bi * x[i]); + x[i] = w[i]*(ci + di * x[i]); + } + + // results are in [ones, x], now multiply with y + + a = 0.0; // intercept + b = 0.0; // slope + + const valarray& t = targets.targets(); + + for (unsigned i = 0; i < n; ++i) + { + a += ones[i] * t[i]; + b += x[i] * t[i]; + } + + return Scaling(new LinearScaling(a,b)); +} + + +//Scaling med(const std::valarray& inputs, const TargetInfo& targets); + +double mse(const std::valarray& y, const TargetInfo& t) { + + valarray residuals = t.targets()-y; + residuals *= residuals; + double sz = residuals.size(); + if (t.has_weights()) { + residuals *= t.weights(); + sz = 1.0; + } + + return residuals.sum() / sz; +} + +double rms(const std::valarray& y, const TargetInfo& t) { + return sqrt(mse(y,t)); +} + +double mae(const std::valarray& y, const TargetInfo& t) { + valarray residuals = abs(t.targets()-y); + if (t.has_weights()) residuals *= t.weights(); + return residuals.sum() / residuals.size(); +} + + +/* + double standard_error(const std::valarray& y, const std::pair& scaling) { + double a = scaling.first; + double b = scaling.second; + double n = y.size(); + double se = sqrt( pow(a+b*y-current_set->targets,2.0).sum() / (n-2)); + + double mean_y = y.sum() / n; + double sxx = pow( y - mean_y, 2.0).sum(); + + return se / sqrt(sxx); + } + + double scaled_mse(const std::valarray& y){ + std::pair scaling; + return scaled_mse(y,scaling); + } + + double scaled_mse(const std::valarray& y, std::pair& scaling) + { + scaling = scale(y); + + double a = scaling.first; + double b = scaling.second; + + std::valarray tmp = current_set->targets - a - b * y; + tmp *= tmp; + + if (weights.size()) + return (weights * tmp).sum(); + + return tmp.sum() / tmp.size(); + } + + double robust_mse(const std::valarray& ny, std::pair& scaling) { + + double smse = scaled_mse(ny,scaling); + + std::valarray y = ny; + // find maximum covariance case + double n = y.size(); + + int largest = 0; + + { + double y_mean = y.sum() / n; + + std::valarray y_var = (y - y_mean); + std::valarray cov = tcov * y_var; + + std::valarray maxcov = cov == cov.max(); + + for (unsigned i = 0; i < maxcov.size(); ++i) { + if (maxcov[i]) { + largest = i; + break; + } + } + } + + double y_mean = (y.sum() - y[largest]) / (n-1); + y[largest] = y_mean; // dissappears from covariance calculation + + std::valarray y_var = (y - y_mean); + std::valarray cov = tcov * y_var; + y_var *= y_var; + + double sumvar = y_var.sum(); + + if (sumvar == 0. || sumvar/n < 1e-7 || sumvar/n > 1e+7) // breakout when numerical problems are likely + return worst_performance(); + + double b = cov.sum() / sumvar; + double a = tmean - b * y_mean; + + std::valarray tmp = current_set->targets - a - b * y; + tmp[largest] = 0.0; + tmp *= tmp; + + double smse2 = tmp.sum() / (tmp.size()-1); + + static std::ofstream os("smse.txt"); + os << smse << ' ' << smse2 << '\n'; + + if (smse2 > smse) { + return worst_performance(); + //std::cerr << "overfit? " << smse << ' ' << smse2 << '\n'; + } + + scaling.first = a; + scaling.second = b; + + return smse2; + } + + class Sorter { + const std::valarray& scores; + public: + Sorter(const std::valarray& _scores) : scores(_scores) {} + + bool operator()(unsigned i, unsigned j) const { + return scores[i] < scores[j]; + } + }; + + double coc(const std::valarray& y) { + std::vector indices(y.size()); + for (unsigned i = 0; i < y.size(); ++i) indices[i] = i; + std::sort(indices.begin(), indices.end(), Sorter(y)); + + const std::valarray& targets = current_set->targets; + + double neg = 1.0 - targets[indices[0]]; + double pos = targets[indices[0]]; + + double cumpos = 0; + double cumneg = 0; + double sum=0; + + double last_score = y[indices[0]]; + + for(unsigned i = 1; i < targets.size(); ++i) { + + if (fabs(y[indices[i]] - last_score) < 1e-9) { // we call it tied + pos += targets[indices[i]]; + neg += 1.0 - targets[indices[i]]; + + if (i < targets.size()-1) + continue; + } + sum += pos * cumneg + (pos * neg) * 0.5; + cumneg += neg; + cumpos += pos; + pos = targets[indices[i]]; + neg = 1.0 - targets[indices[i]]; + last_score = y[indices[i]]; + } + + return sum / (cumneg * cumpos); + } + + // iterative re-weighted least squares (for parameters.classification) + double irls(const std::valarray& scores, std::pair& scaling) { + const std::valarray& t = current_set->targets; + + std::valarray e(scores.size()); + std::valarray u(scores.size()); + std::valarray w(scores.size()); + std::valarray z(scores.size()); + + parameters.use_irls = false; parameters.classification=false; + scaling = scale(scores); + parameters.use_irls=true;parameters.classification=true; + + if (scaling.second == 0.0) return worst_performance(); + + for (unsigned i = 0; i < 10; ++i) { + e = exp(scaling.first + scaling.second*scores); + u = e / (e + exp(-(scaling.first + scaling.second * scores))); + w = u*(1.-u); + z = (t-u)/w; + scaling = wls(scores, u, w); + //double ll = (log(u)*t + (1.-log(u))*(1.-t)).sum(); + //std::cout << "Scale " << i << ' ' << scaling.first << " " << scaling.second << " LL " << 2*ll << std::endl; + } + + // log-likelihood + u = exp(scaling.first + scaling.second*scores) / (1 + exp(scaling.first + scaling.second*scores)); + double ll = (log(u)*t + (1.-log(u))*(1.-t)).sum(); + return 2*ll; + } +*/ diff --git a/eo/contrib/mathsym/regression/Scaling.h b/eo/contrib/mathsym/regression/Scaling.h new file mode 100644 index 000000000..53d53d8bc --- /dev/null +++ b/eo/contrib/mathsym/regression/Scaling.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SCALING_H_ +#define SCALING_H_ + +#include "shared_ptr.h" + +#include +#include +#include + +class TargetInfo; + +class ScalingBase { + public: + + std::valarray apply(const std::valarray& x) { + std::valarray xtmp = x; + transform(xtmp); + return xtmp; + } + + virtual double transform(double input) const = 0; + virtual void transform(std::valarray& inputs) const = 0; + virtual std::ostream& print(std::ostream& os, std::string str) const = 0; + virtual std::valarray transform(const std::valarray& inputs) const = 0; +}; + +typedef shared_ptr Scaling; + +class LinearScaling : public ScalingBase { + + double a,b; + + public: + LinearScaling() : a(0.0), b(1.0) {} + LinearScaling(double _a, double _b) : a(_a), b(_b) {} + + double transform(double input) const { input *=b; input += a; return input; } + void transform(std::valarray& inputs) const { inputs *= b; inputs += a; } + std::valarray transform(const std::valarray& inputs) const { + std::valarray y = a + b * inputs; + return y; + } + + double intercept() const { return a; } + double slope() const { return b; } + + std::ostream& print(std::ostream& os, std::string str) const { + os.precision(16); + os << a << " + " << b << " * " << str; + return os; + } +}; + +class NoScaling : public ScalingBase{ + void transform(std::valarray&) const {} + double transform(double input) const { return input; } + std::valarray transform(const std::valarray& inputs) const { return inputs; } + std::ostream& print(std::ostream& os, std::string str) const { return os << str; } +}; + +extern Scaling slope(const std::valarray& inputs, const TargetInfo& targets); // slope only +extern Scaling ols(const std::valarray& inputs, const TargetInfo& targets); +extern Scaling wls(const std::valarray& inputs, const TargetInfo& targets); +extern Scaling med(const std::valarray& inputs, const TargetInfo& targets); + +extern Scaling ols(const std::valarray& inputs, const std::valarray& outputs); + +extern double mse(const std::valarray& y, const TargetInfo& t); +extern double rms(const std::valarray& y, const TargetInfo& t); +extern double mae(const std::valarray& y, const TargetInfo& t); + +// Todo Logistic Scaling + +#endif + + diff --git a/eo/contrib/mathsym/regression/TargetInfo.cpp b/eo/contrib/mathsym/regression/TargetInfo.cpp new file mode 100644 index 000000000..1d386e8c9 --- /dev/null +++ b/eo/contrib/mathsym/regression/TargetInfo.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "TargetInfo.h" + +using namespace std; + +TargetInfo::TargetInfo(const TargetInfo& org) { operator=(org); } + +TargetInfo& TargetInfo::operator=(const TargetInfo& org) { + _targets.resize(org._targets.size()); + _weights.resize(org._weights.size()); + _tcov_part.resize(org._tcov_part.size()); + + _targets = org._targets; + _weights = org._weights; + _tcov_part = org._tcov_part; + + _tmean = org._tmean; + _tvar = org._tvar; + _tstd = org._tstd; + _tmed = org._tmed; + return *this; +} + + +TargetInfo::TargetInfo(const std::valarray& t) { + _weights.resize(0); + _targets.resize(t.size()); + _targets = t; + + _tmean = _targets.sum()/_targets.size(); + + _tcov_part.resize(_targets.size()); + _tcov_part = _targets; + _tcov_part -= _tmean; + + std::valarray tmp = _tcov_part; + tmp = _tcov_part; + tmp *= tmp; + + _tvar = tmp.sum() / (tmp.size()-1); + _tstd = sqrt(_tvar); + _tmed = 0; +} + +TargetInfo::TargetInfo(const std::valarray& t, const std::valarray& w) { + + _targets.resize(t.size()); + _weights.resize(w.size()); + + _targets = t; + _weights = w; + + double sumw = _weights.sum(); + // scale weights so that they'll add up to 1 + _weights /= sumw; + + _tmean = (_targets * _weights).sum(); + _tcov_part.resize(_targets.size()); + _tcov_part = _targets; + _tcov_part -= _tmean; + + _tvar = (pow(_targets - _tmean, 2.0) * _weights).sum(); + _tstd = sqrt(_tvar); + _tmed = 0.; +} + +// calculate the members, now in the context of a mask +void TargetInfo::set_training_mask(const std::valarray& tmask) { + + TargetInfo tmp; + + if (has_weights() ) { + tmp = TargetInfo( _targets[tmask], _weights[tmask]); + } else { + tmp = TargetInfo( _targets[tmask] ); + } + + _tcov_part.resize(tmp._tcov_part.size()); + _tcov_part = tmp._tcov_part; + + _tmean = tmp._tmean; + _tvar = tmp._tvar; + _tstd = tmp._tstd; + _tmed = tmp._tmed; + + _training_mask.resize(tmask.size()); + _training_mask = tmask; +} + +struct SortOnTargets +{ + const valarray& t; + SortOnTargets(const valarray& v) : t(v) {} + + bool operator()(int i, int j) const { + return fabs(t[i]) < fabs(t[j]); + } +}; + +vector TargetInfo::sort() { + + vector ind(_targets.size()); + for (unsigned i = 0; i < ind.size(); ++i) { ind[i] = i; } + + std::sort(ind.begin(), ind.end(), SortOnTargets(_targets)); + + valarray tmptargets = _targets; + valarray tmpweights = _weights; + valarray tmpcov = _tcov_part; + + for (unsigned i = 0; i < ind.size(); ++i) + { + _targets[i] = tmptargets[ ind[i] ]; + _tcov_part[i] = tmpcov[ ind[i] ]; + if (_weights.size()) _weights[i] = tmpweights[ ind[i] ]; + } + + return ind; +} + + + diff --git a/eo/contrib/mathsym/regression/TargetInfo.h b/eo/contrib/mathsym/regression/TargetInfo.h new file mode 100644 index 000000000..ee9a307ff --- /dev/null +++ b/eo/contrib/mathsym/regression/TargetInfo.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TARGETINFO_H_ +#define TARGETINFO_H_ + +#include +#include + +class TargetInfo { + std::valarray _targets; + std::valarray _weights; + std::valarray _training_mask; + + // some stuff for ols + std::valarray _tcov_part; + double _tmean; + double _tvar; + double _tstd; + double _tmed; + + public: + TargetInfo() {} + + TargetInfo(const std::valarray& t); + TargetInfo(const std::valarray& t, const std::valarray& w); + + TargetInfo(const TargetInfo& org); + TargetInfo& operator=(const TargetInfo& org); + ~TargetInfo() {} + + const std::valarray& targets() const { return _targets; } + const std::valarray& weights() const { return _weights; } + const std::valarray& mask() const { return _training_mask; } + + void set_training_mask(const std::valarray& mask); + + bool has_weights() const { return _weights.size(); } + bool has_mask() const { return _training_mask.size(); } + + std::vector sort(); + + const std::valarray& tcov_part() const { return _tcov_part; } + double tmean() const { return _tmean; } + double tvar() const { return _tvar; } + double tstd() const { return _tstd; } + double devmedian() const { return _tmed; } +}; + +#endif + diff --git a/eo/contrib/mathsym/shared_ptr.h b/eo/contrib/mathsym/shared_ptr.h new file mode 100644 index 000000000..58353fe91 --- /dev/null +++ b/eo/contrib/mathsym/shared_ptr.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _SHARED_PTR_H +#define _SHARED_PTR_H + + +template class weak_ptr; + +template +class shared_ptr { + private: + T* ptr; + unsigned* count; // + + /* special case, null pointer (nil-code) */ + static unsigned* nil() { static unsigned nil_counter(1); return &nil_counter; } + + void decref() { if (--(*count) == 0) { delete ptr; delete count; }} + void incref() { ++(*count); } + + friend class weak_ptr; + + public: + + shared_ptr() : ptr(0), count(nil()) { incref(); } + ~shared_ptr() { decref(); } + + shared_ptr(const shared_ptr& o) : ptr(o.ptr), count(o.count) { incref(); } + shared_ptr(T* p) : ptr(p), count(new unsigned(1)) {} + explicit shared_ptr(const weak_ptr& w) : ptr(w.ptr), count(w.count) { incref(); } + + shared_ptr& operator=(const shared_ptr& o) { + if (ptr == o.ptr) return *this; + decref(); + ptr = o.ptr; + count = o.count; + incref(); + return *this; + } + + T* get() { return ptr; } + T* operator->() { return ptr; } + T& operator*() { return *ptr; } + + const T* get() const { return ptr; } + const T* operator->() const { return ptr; } + const T& operator*() const { return *ptr; } + + bool operator==(const shared_ptr& o) const { return ptr == o.ptr; } + bool operator!=(const shared_ptr& o) const { return ptr != o.ptr; } + bool operator<(const shared_ptr& o) const { return ptr < o.ptr; } + + unsigned refcount() const { return *count; } +}; + +template +class weak_ptr { + T* ptr; + unsigned* count; + + friend class shared_ptr; + + public: + + weak_ptr() : ptr(0), count(shared_ptr::nil()) {} + explicit weak_ptr( const shared_ptr& s) : ptr(s.ptr), count(s.count) {} + + shared_ptr lock() const { return shared_ptr(*this); } + + + T* get() { return ptr; } + T* operator->() { return ptr; } + T& operator*() { return *ptr; } + + const T* get() const { return ptr; } + const T* operator->() const { return ptr; } + const T& operator*() const { return *ptr; } + + bool operator==(const shared_ptr& o) const { return ptr == o.ptr; } + bool operator!=(const shared_ptr& o) const { return ptr != o.ptr; } + bool operator<(const shared_ptr& o) const { return ptr < o.ptr; } + + unsigned refcount() const { return *count; } + +}; + +#endif diff --git a/eo/contrib/mathsym/sym/README.cpp b/eo/contrib/mathsym/sym/README.cpp new file mode 100644 index 000000000..c62e6cbac --- /dev/null +++ b/eo/contrib/mathsym/sym/README.cpp @@ -0,0 +1,364 @@ + +/* + DESCRIPTION: + + +The class 'Sym' in this package provides a reference counted, hashed tree structure that can be used in genetic programming. +The hash table behind the scenes makes sure that every subtree in the application is stored only once. +This has a couple of advantages: + +o Memory: all subtrees are stored only once +o Comparison: comparison for equality for two subtrees boils down to a pointer comparison +o Overview: by accessing the hashtable, you get an instant overview of the state of the population + + +The disadvantage of this method is the constant time overhead for computing hashes. In practice, +it seems to be fast enough. + + +===== How to Use this ========= + +In essence, the Sym data structure contains two important pieces of data, +the 'token' (of type token_t = int) and the children, a vector of Sym (called SymVec). +The token should contain all information to be able to figure out which +function/terminal is represented by the node in the tree. By retrieving this token value +and the SymVec it is possible to write recursive traversal routines for evaluation, printing, +etc. + +*/ + +#include +#include "Sym.h" + +using namespace std; + + +/* + * Suppose token value '0' designates our terminal, and token value '1' designates a binary function. + * Later on a ternary function will be used as well, designated with token value '2' + * The function below will create a tree of size three +*/ +Sym test1() { + + SymVec children; + children.push_back( Sym(0) ); // push_back is a member from std::vector, SymVec is derived from std::vector + children.push_back( Sym(0) ); + + Sym tree = Sym(token_t(1), children); // creates the tree + + /* Done, now print some information about the node */ + + cout << "Size = " << tree.size() << endl; // prints 3 + cout << "Depth = " << tree.depth() << endl; // prints 2 + cout << "Refcount = " << tree.refcount() << endl; // prints 1 + + Sym tree2 = tree; // make a copy (this only changes refcount) + + cout << "Refcount now = " << tree.refcount() << endl; // print 2 + + return tree; // tree2 will be deleted and reference count returns to 1 +} + +/* To actually use the tree, evaluate it, the following simple recursive function + * can be used +*/ + +int eval(const Sym& sym) { + if (sym.token() == 0) { // it's a terminal in this example + return 1; + } + // else it's the function + const SymVec& children = sym.args(); // get the children out, children.size() is the arity + + // let's assume that we've also got a ternary function designated by token '2' + + if (sym.token() == token_t(1)) + return eval(children[0]) + eval(children[1]); // evaluate + + return eval(children[0]) + eval(children[1]) * eval(children[2]); // a ternary function +} + +/* Note that you simply use the stored token that was defined above. Simply checking the size of SymVec in + * this particular example could have sufficed, but it's instructive to use the tokens. + * + * And to test this: +*/ + +void test_eval() { + + Sym tree = test1(); + + cout << "Evaluating tree1 returns " << eval(tree) << endl; +} + +/* Writing initialization functions. + * + * As the Sym class is recursive in nature, initialization can simply be done using + * recursive routines as above. As an example, the following code does 'full' initialization. + */ + +Sym init_full(int depth_left) { + if (depth_left == 0) return Sym(0); // create terminal + // else create either a binary or a ternary function + + depth_left--; + + if (rand() % 2 == 0) { // create binary + SymVec vec(2); + vec[0] = init_full(depth_left); + vec[1] = init_full(depth_left); + + return Sym(token_t(1), vec); + + } else { // create ternary tree + SymVec vec(3); + vec[0] = init_full(depth_left); + vec[1] = init_full(depth_left); + vec[2] = init_full(depth_left); + + return Sym(token_t(2), vec); // token value 2 designates a ternary now, even though the arity can simply be read from the size of the 'SymVec' + } + +} + + +/* Examining the hash table. + * + * The hash table is a static member of the Sym class, but can be obtained and inspected + * at any point during the run. The hash table follows the SGI implementation of hashmap (and effectively + * uses it in gcc). An example: + */ + +void inspect_hashtable() { + SymMap& dag = Sym::get_dag(); // get the hashmap + unsigned i = 0; + for (SymMap::iterator it = dag.begin(); it != dag.end(); ++it) { + Sym node(it); // initialize a 'sym' with the iterator + + cout << "Node " << i++ << " size " << node.size(); + cout << " refcount " << node.refcount()-1; // -1: note that by creating the Sym above the refcount is increased + cout << " depth " << node.depth(); + cout << '\n'; + } + +} + +/* The above code effectively examines all distinct subtrees in use in the application and prints some stats for the node */ + +/* Manipulating trees + * + * The Sym class is set up in such a way that you cannot change a Sym, so how do you perform crossover and mutation? + * + * Simple, you create new syms. The Sym class supports two functions to make this easier: 'get_subtree' and 'insert_subtree'. + * These traverse the tree by index, where 0 designates the root and other values are indexed depth first. + */ + +Sym subtree_xover(Sym a, Sym b) { + + Sym to_insert = get_subtree(a, rand() % a.size() ); // select random subtree, will crash if too high a value is given + + /* 'insert' it into b. This will not really insert, it will however create a new sym, + * equal to 'b' but with a's subtree inserted at the designated spot. */ + return insert_subtree(b, rand() % b.size(), to_insert); + +} + +/* Tying it together, we can create a simple genetic programming system. Mutation is not implemented here, + * but would be easy enough to add by using recursion and/or 'set'. */ + +void run_gp() { + + int ngens = 50; + int popsize = 1000; + + cout << "Starting running " << popsize << " individuals for " << ngens << " generations." << endl; + + vector pop(popsize); + + // init population + for (unsigned i = 0; i < pop.size(); ++i) { + pop[i] = init_full(5); + } + + double best = 0.0; + + // do a very simple steady state tournament + for (unsigned gen = 0; gen < ngens * pop.size(); ++gen) { + int sel1 = rand()% pop.size(); + int sel2 = rand() % pop.size(); + int sel3 = rand() % pop.size(); + + double ev1 = eval(pop[sel1]); + double ev3 = eval(pop[sel3]); + + double bst = max(ev1,ev3); + if (bst > best) { + best = bst; + } + + if (ev3 > ev1) { + sel1 = sel3; // selection pressure + } + + Sym child = subtree_xover(pop[sel1], pop[sel2]); + + // Check for uniqueness + if (child.refcount() == 1) pop[ rand() % pop.size() ] = child; + } + + // and at the end: + + inspect_hashtable(); + + // and also count number of nodes in the population + int sz = 0; + for (unsigned i = 0; i < pop.size(); ++i) { sz += pop[i].size(); } + cout << "Number of distinct nodes " << Sym::get_dag().size() << endl; + cout << "Nodes in population " << sz << endl; + cout << "ratio " << double(Sym::get_dag().size())/sz << endl; + cout << "Best fitness " << best << endl; + +} + +/* One extra mechanism is supported to add annotations to nodes. Something derived from + * 'UniqueNodeStats' can be used to attach new information to nodes. For this to function, + * we need to supply a 'factory' function that creates these node-stats; attach this function to the + * Sym class, so that it gets called whenever a new node is created. The constructors of the Sym class + * take care of this. + * + * IMPORTANT: + * in a realistic application, the factory function needs to be set BEFORE any Syms are created + * Mixing Syms creating with and without the factory can lead to unexpected results + * + * First we derive some structure from UniqueNodeStats: */ + +struct MyNodeStats : public UniqueNodeStats { + + int sumsize; + + ~MyNodeStats() { cout << "MyNodeStats::~MyNodeStats, sumsize = " << sumsize << endl; } +}; + +/* then define the factory function. It will get a Sym, which is just created. */ +UniqueNodeStats* create_stats(const Sym& sym) { + MyNodeStats* stats = new MyNodeStats; // Sym will take care of memory management + + int sumsize = sym.size(); + for (unsigned i = 0; i < sym.args().size(); ++i) { + // retrieve the extra node stats of the child + UniqueNodeStats* unique_stats = sym.args()[i].extra_stats(); // extra_stats retrieves the stats + MyNodeStats* child_stats = static_cast(unique_stats); // cast it to the right struct + sumsize += child_stats->sumsize; + } + + stats->sumsize = sumsize; + return stats; // now it will get attached to the node and deleted when its reference count goes to zero +} + +void test_node_stats() { + + if (Sym::get_dag().size() != 0) { + cerr << "Cannot mix nodes with and without factory functions" << endl; + exit(1); + } + + /* Very Important: attach the factory function to the Sym class */ + Sym::set_factory_function(create_stats); + + Sym tree = init_full(5); // create a tree + + // get extra node stats out + MyNodeStats* stats = static_cast( tree.extra_stats() ); + + cout << "Size = " << tree.size() << " SumSize = " << stats->sumsize << endl; + + Sym::clear_factory_function(); // reset +} + + +/* And run the code above */ + +int main() { + srand(time(0)); + cout << "********** TEST EVALUATION **************\n"; + test_eval(); + cout << "********** TEST ALGORITHM ***************\n"; + run_gp(); + + cout << "********** TEST FACTORY ****************\n"; + test_node_stats(); // can work because there are no live nodes + +} + +/* ********** Member function reference: ******************** + * + * Sym() The default constructor will create an undefined node (no token and no children), check for empty() to see if a node is undefined + * + * Sym(token_t) Create a terminal + * + * Sym(token_t, const SymVec&) + * Create a node with token and SymVec as the children + * + * Sym(SymIterator it) + * Create a sym from an iterator (taken from the hashtable directly, or from Sym::iterator) + * + * dtor, copy-ctor and assignment + * + * UniqueNodeStats* extra_stats() + * Returns an UniqueNodeStats pointer (= 0 if no factory is defined) + * + * + * int hashcode() returns the hashcode for the node + * + * int refcount() returns the reference count for the node + * + * bool operator== checks for equality (note that this is a pointer compare, really really fast) + * + * bool empty() returns whether the node is undefined, i.e. created through the default ctor + * + * int arity() shorthand for sym.args().size() + * + * token_t token() return identifying token for the node + * + * const SymVec& args() + * returns the children of the node (in a vector) + * + * unsigned size() returns the size, i.e., number of nodes + * + * unsigned depth() returns the depth + * + * iterator() returns the pointer to the node in the hashtable + * + * + ********** Static functions: ******************** + * + * + * + * SymMap& get_dag() returns the hash table containing all nodes. This should only be used for inspection, + * even though the dag itself is not const. This to enable the use of the ctor Sym(SymIterator) to inspect + * using the Sym interface (rather than the hash table interface). This does allow you to make destructive + * changes to the class, so use with care + * + * set_factory_function( UniqueNodeStats (*)(const Sym&) ) + * Set the factory function + * + * clear_factory_function() + * Clears the factory function, allocated UniqueNodeStats will still be deleted, but no new ones will be created. + * + ********** Utility Functions ******************** + * + * Sym get_subtree(const Sym& org, int i) + * Retreive the i-th subtree from the Sym. Standard depth first ordering, where root has index 0 and the + * rightmost terminal has index sym.size()-1 + * + * Sym insert_subtree(const Sym& org, int i, const Sym& subtree) + * Returns a Sym that is equal to 'org', for which the i-th subtree (same ordering as get_subtree) is replaced + * by the third argument subtree. + * + * Sym next(const Sym&) + * Returns the successor of the argument sym from the hashtable with wrap around. This is implemented just because + * it can be done. It may be an interesting way to mutate... + * + * */ + + diff --git a/eo/contrib/mathsym/sym/Sym.cpp b/eo/contrib/mathsym/sym/Sym.cpp new file mode 100644 index 000000000..b426e1116 --- /dev/null +++ b/eo/contrib/mathsym/sym/Sym.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "Sym.h" + +using namespace std; + +typedef UniqueNodeStats* (*NodeStatFunc)(Sym&); + +UniqueNodeStats* (*Sym::factory)(const Sym&) = 0; + +void (*Sym::extra_dtor)(token_t) = 0; + +SymMap Sym::dag(100000); // reserve space for so many nodes + +size_t get_size(const SymVec& vec) { + size_t sz = 0; + for (unsigned i = 0; i < vec.size(); ++i) { + sz += vec[i].size(); + } + return sz; +} + +size_t get_depth(const SymVec& vec) { + size_t dp = 1; + for (unsigned i = 0; i < vec.size(); ++i) { + dp = std::max(dp, vec[i].depth()); + } + return dp; +} + +Sym::Sym(token_t tok, const SymVec& args_) +{ + detail::SymKey key(tok, detail::SymArgs(args_)); + detail::SymValue val; + + node = dag.insert(pair(key, val)).first; + + if (__unchecked_refcount() == 0) { // new node, set some stats + node->second.size = 1 + get_size(args_); + node->second.depth = 1 + get_depth(args_); + incref(); + node->first.fixate(); + // call the factory function if available + if (factory) node->second.uniqueNodeStats = factory(*this); + } + else incref(); +} + +Sym::Sym(token_t tok, const Sym& a) { + SymVec args_; args_.push_back(a); + detail::SymKey key(tok, detail::SymArgs(args_)); + detail::SymValue val; + + node = dag.insert(pair(key, val)).first; + + if (__unchecked_refcount() == 0) { // new node, set some stats + node->second.size = 1 + get_size(args_); + node->second.depth = 1 + get_depth(args_); + incref(); + node->first.fixate(); + // call the factory function if available + if (factory) node->second.uniqueNodeStats = factory(*this); + } + else incref(); +} + +Sym::Sym(token_t tok) { + detail::SymKey key(tok); + detail::SymValue val; + node = dag.insert(pair(key, val)).first; + + if (__unchecked_refcount() == 0) { // new node, set some stats + node->second.size = 1; + node->second.depth = 1; + incref(); + + // call the factory function if available + if (factory) node->second.uniqueNodeStats = factory(*this); + } + else incref(); +} + +std::pair insert_subtree_impl(const Sym& cur, size_t w, const Sym& nw) { + if (w-- == 0) return make_pair(nw, !(nw == cur)); + + const SymVec& vec = cur.args(); + std::pair result; + unsigned i; + + for (i = 0; i < vec.size(); ++i) { + if (w < vec[i].size()) { + result = insert_subtree_impl(vec[i], w, nw); + if (result.second == false) return std::make_pair(cur, false); // unchanged + break; + } + w -= vec[i].size(); + } + SymVec newvec = cur.args(); + newvec[i] = result.first; + return make_pair(Sym(cur.token(), newvec), true); +} + +Sym insert_subtree(const Sym& cur, size_t w, const Sym& nw) { + return insert_subtree_impl(cur,w,nw).first; +} +Sym get_subtree(const Sym& cur, size_t w) { + if (w-- == 0) return cur; + + const SymVec& vec = cur.args(); + for (unsigned i = 0; i < vec.size(); ++i) { + if (w < vec[i].size()) return get_subtree(vec[i], w); + w-=vec[i].size(); + } + return cur; +} + + diff --git a/eo/contrib/mathsym/sym/Sym.h b/eo/contrib/mathsym/sym/Sym.h new file mode 100644 index 000000000..0bf46bf0f --- /dev/null +++ b/eo/contrib/mathsym/sym/Sym.h @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SYMNODE_H_ +#define SYMNODE_H_ + +#include + +#if __GNUC__ == 3 +#include +#else +#include +using std::hash_map; +#endif + +/* Empty 'extra statistics' structure, derive from this to keep other characteristics of nodes */ +struct UniqueNodeStats { virtual ~UniqueNodeStats(){} }; + +#include "SymImpl.h" +#include "token.h" + +typedef hash_map SymMap; +typedef SymMap::iterator SymIterator; +class Sym; + +typedef std::vector SymVec; + +/* Sym is the tree, for which all the nodes are stored in a hash table. + * This makes checking for equality O(1) */ + +class Sym +{ + public: + + Sym() : node(dag.end()) {} + explicit Sym(token_t token, const SymVec& args); + explicit Sym(token_t token, const Sym& args); + explicit Sym(token_t var); + + explicit Sym(SymIterator it) : node(it) { incref(); } + + Sym(const Sym& oth) : node(oth.node) { incref(); } + ~Sym() { decref(); } + + const Sym& operator=(const Sym& oth) { + if (oth.node == node) return *this; + decref(); + node = oth.node; + incref(); + return *this; + } + + /* Unique Stats are user defined */ + UniqueNodeStats* extra_stats() const { return empty()? 0 : node->second.uniqueNodeStats; } + + int hashcode() const { detail::SymKey::Hash hash; return hash(node->first); } + + // Friends, need to touch the node + friend struct detail::SymKey::Hash; + friend struct detail::SymKey; + + unsigned refcount() const { return empty()? 0: node->second.refcount; } + + bool operator==(const Sym& other) const { + return node == other.node; + } + bool operator!=(const Sym& other) const { return !(*this == other); } + + bool empty() const { return node == dag.end(); } + + /* Support for traversing trees */ + unsigned arity() const { return node->first.arity(); } + token_t token() const { assert(!empty()); return node->first.token; } + + const SymVec& args() const { return node->first.vec(); } + + /* size() - depth */ + unsigned size() const { return empty()? 0 : node->second.size; } + unsigned depth() const { return empty()? 0 : node->second.depth; } + + SymMap::iterator iterator() const { return node; } + + /* Statics accessing some static members */ + static SymMap& get_dag() { return dag; } + + /* This function can be set to create some UniqueNodeStats derivative that can contain extra stats for a node, + * it can for instance be used to create ERC's and what not. */ + static void set_factory_function(UniqueNodeStats* (*f)(const Sym&)) { factory=f; } + static void clear_factory_function() { factory = 0; } + + static void set_extra_dtor( void (*extra)(token_t) ) { extra_dtor = extra; } + + unsigned address() const { return reinterpret_cast(&*node); } + + private : + + // implements getting subtrees + Sym private_get(size_t w) const; + + unsigned __unchecked_refcount() const { return node->second.refcount; } + + void incref() { + if (!empty()) + ++(node->second.refcount); + } + void decref() { + if (!empty() && --(node->second.refcount) == 0) { + if (extra_dtor) { + extra_dtor(token()); + } + dag.erase(node); + } + } + + // The one and only data member, an iterator into the static map below + SymIterator node; + + // A static hash_map that contains all live nodes.. + static SymMap dag; + + // Factory function for creating extra node stats, default will be 0 + static UniqueNodeStats* (*factory)(const Sym&); + + static void (*extra_dtor)(token_t); + +}; + +/* Utility hash functor for syms */ +class HashSym { + public: + int operator()(const Sym& sym) const { return sym.hashcode(); } +}; + +/* Utility Functions */ + +// get_subtree retrieves a subtree by standard ordering (0=root, and then depth first) +Sym get_subtree(const Sym& org, size_t w); + +// insert_subtree uses the same ordering as get and inserts the second argument, returning a new tree +Sym insert_subtree(const Sym& org, size_t w, const Sym& nw); + +/* Get the successor from the hashtable, no particular purpose other than an interesting way to mutate */ +inline Sym next(const Sym& sym) { + SymIterator it = sym.iterator(); + ++it; + if (it == Sym::get_dag().end()) it = Sym::get_dag().begin(); + return Sym(it); +} + +#endif diff --git a/eo/contrib/mathsym/sym/SymImpl.cpp b/eo/contrib/mathsym/sym/SymImpl.cpp new file mode 100644 index 000000000..a0f3d7017 --- /dev/null +++ b/eo/contrib/mathsym/sym/SymImpl.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "Sym.h" + +using namespace std; +namespace detail { + +class SymArgsImpl { + public: + vector owned_args; +}; + +size_t SymArgs::len() const { + return vec().size(); +} + +SymArgs::SymArgs() : pimpl( new SymArgsImpl ) { + args_ptr = &pimpl->owned_args; +} + +SymArgs::SymArgs(const std::vector& v) : pimpl(0) { + args_ptr = &v; +} + +SymArgs::~SymArgs() { + delete pimpl; +} + +SymArgs::SymArgs(const SymArgs& args) : pimpl(0), args_ptr(args.args_ptr) { + if (args.pimpl && args.args_ptr == &args.pimpl->owned_args) { + pimpl = new SymArgsImpl(*args.pimpl); + args_ptr = &pimpl->owned_args; + } +} + +const SymArgs& SymArgs::operator=(const SymArgs& args) { + if (args.pimpl && args.args_ptr == &args.pimpl->owned_args) { + pimpl = new SymArgsImpl(*args.pimpl); + args_ptr = &pimpl->owned_args; + } else { + args_ptr = args.args_ptr; + } + + return *this; +} + +void SymArgs::fixate() const { + assert(pimpl == 0); + pimpl = new SymArgsImpl; + pimpl->owned_args = *args_ptr; + args_ptr = &pimpl->owned_args; +} + +// For Tackett's hashcode +#define PRIMET 21523 +#define HASHMOD 277218551 + +const int nprimes = 4; +const unsigned long primes[] = {3221225473ul, 201326611ul, 1610612741ul, 805306457ul}; + +int SymKey::calc_hash() const { + unsigned long hash = unsigned(token); + hash *= PRIMET; + + const SymVec& v = args.vec(); + for (unsigned i = 0; i < v.size(); ++i) { + hash += ( (v[i].address() >> 3) * primes[i%nprimes]) % HASHMOD; + } + + return hash;// % HASHMOD; +} + +bool SymKey::operator==(const SymKey& other) const { + if (token != other.token) return false; + return args.vec() == other.args.vec(); +} + +/* Just to store this info somewhere: + * + * Address Based Hash Function Implementation + * uint32 address_hash(char* addr) + * { + * register uint32 key; + * key = (uint32) addr; + * return (key >> 3) * 2654435761; + * } + */ + +SymValue::SymValue() : refcount(0), size(0), depth(0), uniqueNodeStats(0) {} + +SymValue::~SymValue() { delete uniqueNodeStats; } + + + +} // namespace detail diff --git a/eo/contrib/mathsym/sym/SymImpl.h b/eo/contrib/mathsym/sym/SymImpl.h new file mode 100644 index 000000000..bc3538fbe --- /dev/null +++ b/eo/contrib/mathsym/sym/SymImpl.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __SYM_IMPL_H__ +#define __SYM_IMPL_H__ + +#include + +#include "token.h" + +class Sym; +namespace detail { + +class SymArgsImpl; +class SymArgs { + + mutable SymArgsImpl* pimpl; // contains circular reference to vector + mutable const std::vector* args_ptr; + + public: + + SymArgs(); + SymArgs(const std::vector& v); + ~SymArgs(); + + SymArgs(const SymArgs& args); + const SymArgs& SymArgs::operator=(const SymArgs& other); + + size_t len() const; + const std::vector& vec() const { return *args_ptr; } + void fixate() const; +}; + +class SymKey +{ + public: + SymKey(token_t _token) : args(), token(_token) {} + SymKey(token_t _token, const detail::SymArgs& _args) : args(_args), token(_token) {} + + + private: + detail::SymArgs args; + public: + bool operator==(const SymKey& other) const; + + struct Hash + { + int operator()(const SymKey& k) const { return k.calc_hash(); }; + }; + + unsigned arity() const { return args.len(); } + const std::vector& vec() const { return args.vec(); } + + token_t token; // identifies the function + + // fixates (i.e. claims memory) for the embedded vector of Syms + void fixate() const { args.fixate(); } + + private: + int calc_hash() const; +}; + +struct SymValue +{ + friend class Sym; + + SymValue(); + ~SymValue(); + + unsigned getRefCount() const { return refcount; } + unsigned getSize() const { return size; } + unsigned getDepth() const { return depth; } + + private : + + // for reference counting + unsigned refcount; + + // some simple stats + unsigned size; + unsigned depth; + + UniqueNodeStats* uniqueNodeStats; +}; + + +} // namespace detail + +#endif + diff --git a/eo/contrib/mathsym/sym/token.h b/eo/contrib/mathsym/sym/token.h new file mode 100644 index 000000000..68008959d --- /dev/null +++ b/eo/contrib/mathsym/sym/token.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef TOKEN_H +#define TOKEN_H + + +typedef unsigned token_t; + +struct functor_t { + token_t token; + unsigned arity; +}; + +#endif diff --git a/eo/contrib/mathsym/symreg.cpp b/eo/contrib/mathsym/symreg.cpp new file mode 100644 index 000000000..ee1149643 --- /dev/null +++ b/eo/contrib/mathsym/symreg.cpp @@ -0,0 +1,359 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; + +typedef EoSym EoType; + +static int functions_added = 0; + +void add_function(LanguageTable& table, eoParser& parser, string name, unsigned arity, token_t token, const FunDef& fun); +void setup_language(LanguageTable& table, eoParser& parser); + +template +T& select(bool check, T& a, T& b) { if (check) return a; return b; } + +class eoBestIndividualStat : public eoSortedStat { + public: + eoBestIndividualStat() : eoSortedStat("", "best individual") {} + + void operator()(const vector& _pop) { + ostringstream os; + os << (Sym) *_pop[0]; + value() = os.str(); + } + +}; + +class AverageSizeStat : public eoStat { + public: + AverageSizeStat() : eoStat(0.0, "Average size population") {} + + void operator()(const eoPop& _pop) { + double total = 0.0; + for (unsigned i = 0; i < _pop.size(); ++i) { + total += _pop[i].size(); + } + value() = total/_pop.size(); + } +}; + +class SumSizeStat : public eoStat { + public: + SumSizeStat() : eoStat(0u, "Number of subtrees") {} + + void operator()(const eoPop& _pop) { + unsigned total = 0; + for (unsigned i = 0; i < _pop.size(); ++i) { + total += _pop[i].size(); + } + value() = total; + } +}; + +class DagSizeStat : public eoStat { + public: + DagSizeStat() : eoStat(0u, "Number of distinct subtrees") {} + + void operator()(const eoPop& _pop) { + value() = Sym::get_dag().size(); + } +}; + +int main(int argc, char* argv[]) { + + eoParser parser(argc, argv); + + /* Language */ + LanguageTable table; + setup_language(table, parser); + + /* Data */ + + eoValueParam datafile = parser.createParam(string(""), "datafile", "Training data", 'd', string("Regression"), true); // mandatory + double train_percentage = parser.createParam(1.0, "trainperc", "Percentage of data used for training", 0, string("Regression")).value(); + + /* Population */ + + unsigned pop_size = parser.createParam(1500u, "population-size", "Population Size", 'p', string("Population")).value(); + + uint32_t seed = parser.createParam( uint32_t(time(0)), "random-seed", "Seed for rng", 'D').value(); + + cout << "Seed " << seed << endl; + rng.reseed(seed); + + double var_prob = parser.createParam( + 0.9, + "var-prob", + "Probability of selecting a var vs. const when creating a terminal", + 0, + "Population").value(); + + + double grow_prob = parser.createParam( + 0.5, + "grow-prob", + "Probability of selecting 'grow' method instead of 'full' in initialization and mutation", + 0, + "Population").value(); + + unsigned max_depth = parser.createParam( + 8u, + "max-depth", + "Maximum depth used in initialization and mutation", + 0, + "Population").value(); + + + bool use_uniform = parser.createParam( + false, + "use-uniform", + "Use uniform node selection instead of bias towards internal nodes (functions)", + 0, + "Population").value(); + + + double subtree_mut_prob = parser.createParam( + 0.2, + "subtree-mut-rate", + "Probability of performing subtree mutation", + 0, + "Population").value(); + + double node_mut_prob = parser.createParam( + 0.2, + "node-mut-rate", + "Probability of performing node mutation", + 0, + "Population").value(); + + double subtree_xover_prob = parser.createParam( + 0.4, + "xover-rate", + "Probability of performing subtree crossover", + 0, + "Population").value(); + + double homologous_prob = parser.createParam( + 0.4, + "homologous-rate", + "Probability of performing homologous crossover", + 0, + "Population").value(); + + unsigned max_gens = parser.createParam( + 50, + "max-gens", + "Maximum number of generations to run", + 'g', + "Population").value(); + + unsigned tournamentsize = parser.createParam( + 5, + "tournament-size", + "Tournament size used for selection", + 't', + "Population").value(); + + unsigned meas_param = parser.createParam( + 2u, + "measure", + "Error measure:\n\ + 0 -> absolute error\n\ + 1 -> mean squared error\n\ + 2 -> mean squared error scaled (equivalent with correlation)\n\ + ", + 'm', + "Regression").value(); + + ErrorMeasure::measure meas = ErrorMeasure::mean_squared_scaled; + if (meas_param == 0) meas = ErrorMeasure::absolute; + if (meas_param == 1) meas = ErrorMeasure::mean_squared; + + + if (functions_added == 0) { + cout << "ERROR: no functions defined" << endl; + exit(1); + } + + /* End parsing */ + if (parser.userNeedsHelp()) + { + parser.printHelp(std::cout); + return 1; + } + + Dataset dataset; + dataset.load_data(datafile.value()); + + cout << "Data " << datafile.value() << " loaded " << endl; + + /* Add Variables */ + unsigned nvars = dataset.n_fields(); + for (unsigned i = 0; i < nvars; ++i) { + table.add_function( SymVar(i).token(), 0); + } + + TreeBuilder builder(table, var_prob); + eoSymInit init(builder, grow_prob, max_depth); + + eoPop pop(pop_size, init); + + BiasedNodeSelector biased_sel; + RandomNodeSelector random_sel; + + NodeSelector& node_selector = select(use_uniform, random_sel, biased_sel); + + eoProportionalOp genetic_operator; + + eoSymSubtreeMutate submutate(builder, node_selector); + genetic_operator.add( submutate, subtree_mut_prob); + + eoSymNodeMutate nodemutate(table); + genetic_operator.add(nodemutate, node_mut_prob); + + //eoQuadSubtreeCrossover quad(node_selector); + eoBinSubtreeCrossover bin(node_selector); + genetic_operator.add(bin, subtree_xover_prob); + + eoBinHomologousCrossover hom; + genetic_operator.add(hom, homologous_prob); + + + IntervalBoundsCheck check(dataset.input_minima(), dataset.input_maxima()); + ErrorMeasure measure(dataset, train_percentage, meas); + + eoSymPopEval evaluator(check, measure); + + eoDetTournamentSelect selectOne(tournamentsize); + eoGeneralBreeder breeder(selectOne, genetic_operator); + eoPlusReplacement replace; + + // Terminators + eoGenContinue term(max_gens); + eoCheckPoint checkpoint(term); + + eoBestFitnessStat beststat; + checkpoint.add(beststat); + + eoBestIndividualStat printer; + AverageSizeStat avgSize; + DagSizeStat dagSize; + SumSizeStat sumSize; + + checkpoint.add(printer); + checkpoint.add(avgSize); + checkpoint.add(dagSize); + checkpoint.add(sumSize); + + eoStdoutMonitor genmon; + genmon.add(beststat); + genmon.add(printer); + genmon.add(avgSize); + genmon.add(dagSize); + genmon.add(sumSize); + + checkpoint.add(genmon); + + eoPop dummy; + evaluator(pop, dummy); + + eoEasyEA ea(checkpoint, evaluator, breeder, replace); + + ea(pop); // run + +} + +void add_function(LanguageTable& table, eoParser& parser, string name, unsigned arity, token_t token, const FunDef& fun, bool all) { + ostringstream desc; + desc << "Enable function " << name << " arity = " << arity; + bool enabled = parser.createParam(false, name, desc.str(), 0, "Language").value(); + + if (enabled || all) { + cout << "Func " << name << " enabled" << endl; + table.add_function(token, arity); + if (arity > 0) functions_added++; + } +} + +void setup_language(LanguageTable& table, eoParser& parser) { + + bool all = parser.createParam(false,"all", "Enable all functions").value(); + bool ratio = parser.createParam(false,"ratio","Enable rational functions (inv,min,sum,prod)").value(); + bool poly = parser.createParam(false,"poly","Enable polynomial functions (min,sum,prod)").value(); + + // assumes that at this point all tokens are defined (none are zeroed out, which can happen with ERCs) + vector lang = get_defined_functions(); + + for (token_t i = 0; i < lang.size(); ++i) { + + if (lang[i] == 0) continue; + + bool is_poly = false; + if (poly && (i == prod_token || i == sum_token || i == min_token) ) { + is_poly = true; + } + + bool is_ratio = false; + if (ratio && (is_poly || i == inv_token)) { + is_ratio = true; + } + + const FunDef& fun = *lang[i]; + + if (fun.has_varargs() ) { + + for (unsigned j = fun.min_arity(); j < fun.min_arity() + 8; ++j) { + if (j==1) continue; // prod 1 and sum 1 are useless + ostringstream nm; + nm << fun.name() << j; + bool addanyway = (all || is_ratio || is_poly) && j == 2; + add_function(table, parser, nm.str(), j, i, fun, addanyway); + } + } + else { + add_function(table, parser, fun.name(), fun.min_arity(), i, fun, all || is_ratio || is_poly); + } + } +} + + diff --git a/eo/contrib/mathsym/tcc.tar.gz b/eo/contrib/mathsym/tcc.tar.gz new file mode 100644 index 000000000..5b9354733 Binary files /dev/null and b/eo/contrib/mathsym/tcc.tar.gz differ diff --git a/eo/contrib/mathsym/test/test.o b/eo/contrib/mathsym/test/test.o new file mode 100644 index 000000000..fc16e3ae3 Binary files /dev/null and b/eo/contrib/mathsym/test/test.o differ diff --git a/eo/contrib/mathsym/test/test_compile.cpp b/eo/contrib/mathsym/test/test_compile.cpp new file mode 100644 index 000000000..03efbb0b8 --- /dev/null +++ b/eo/contrib/mathsym/test/test_compile.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "FunDef.h" +#include "sym_compile.h" + +#include "Dataset.h" +#include "ErrorMeasure.h" +#include "LanguageTable.h" +#include "BoundsCheck.h" +#include "TreeBuilder.h" + +#include + +using namespace std; + +void test_xover(); + +int main() { + Dataset dataset; + dataset.load_data("problem4.dat"); + + cout << "Records/Fields " << dataset.n_records() << ' ' << dataset.n_fields() << endl; + + LanguageTable table; + table.add_function(sum_token, 2); + table.add_function(prod_token, 2); + table.add_function(sum_token, 0); + table.add_function(prod_token, 0); + table.add_function(inv_token, 1); + table.add_function(min_token, 1); + + for (unsigned i = 0; i < dataset.n_fields(); ++i) { + table.add_function( SymVar(i).token(), 0); + } + + TreeBuilder builder(table); + + IntervalBoundsCheck bounds(dataset.input_minima(), dataset.input_maxima() ); + ErrorMeasure measure(dataset, 1.0); + + + unsigned n = 1000; + unsigned k = 0; + + vector pop; + double sumsize = 0; + for (unsigned i = 0; i < n; ++i) { + + Sym sym = builder.build_tree(6, i%2); + pop.push_back(sym); + sumsize += sym.size(); + } + + cout << "Size " << sumsize/pop.size() << endl; + + // shuffle + for (unsigned gen = 0; gen < 10; ++gen) { + random_shuffle(pop.begin(), pop.end()); + for (unsigned i = 0; i < pop.size(); i+=2) { + + unsigned p1 = rng.random(pop[i].size()); + unsigned p2 = rng.random(pop[i+1].size()); + + Sym a = insert_subtree(pop[i], p1, get_subtree(pop[i+1], p2)); + Sym b = insert_subtree(pop[i+1], p2, get_subtree(pop[i], p1)); + + pop[i] = a; + pop[i+1] = b; + + } + cout << gen << ' ' << Sym::get_dag().size() << endl; + } + + vector oldpop; + swap(pop,oldpop); + for (unsigned i = 0; i < oldpop.size(); ++i) { + Sym sym = oldpop[i]; + if (!bounds.in_bounds(sym)) { + k++; + continue; + } + pop.push_back(sym); + } + + cout << "Done" << endl; + + // full compilation + + time_t start_time = time(0); + time_t compile_time; + { + multi_function f = compile(pop); + compile_time = time(0); + vector out(pop.size()); + + for (unsigned j = 0; j < dataset.n_records(); ++j) { + f(&dataset.get_inputs(j)[0], &out[0]); + } + } + + time_t end_time = time(0); + + cout << "Evaluated " << n-k << " syms in " << end_time - start_time << " seconds, compile took " << compile_time - start_time << " seconds" << endl; + + start_time = time(0); + vector funcs; + compile(pop, funcs); + compile_time = time(0); + for (unsigned i = 0; i < pop.size(); ++i) { + + single_function f = funcs[i]; + for (unsigned j = 0; j < dataset.n_records(); ++j) { + f(&dataset.get_inputs(j)[0]); + } + + } + + end_time = time(0); + + cout << "Evaluated " << n-k << " syms in " << end_time - start_time << " seconds, compile took " << compile_time - start_time << " seconds" << endl; + return 0; // skip the 'slow' one-by-one method + start_time = time(0); + for (unsigned i = 0; i < pop.size(); ++i) { + + single_function f = compile(pop[i]); + for (unsigned j = 0; j < dataset.n_records(); ++j) { + f(&dataset.get_inputs(j)[0]); + } + + } + + end_time = time(0); + + cout << "Evaluated " << n-k << " syms in " << end_time - start_time << " seconds" << endl; + +} + +void test_xover() { + Sym c = SymVar(0); + Sym x = c + c * c + c; + + cout << c << endl; + cout << x << endl; + + vector pop; + for (unsigned i = 0; i < x.size(); ++i) { + for (unsigned j = 0; j < x.size(); ++j) { + + Sym s = insert_subtree(x, i, get_subtree(x, j)); + pop.push_back(s); + cout << i << ' ' << j << ' ' << s << endl; + } + } + + x = Sym(); + c = Sym(); + + SymMap& dag = Sym::get_dag(); + + for (SymMap::iterator it = dag.begin(); it != dag.end(); ++it) { + Sym s(it); + cout << s << ' ' << s.refcount() << endl; + } + + + +} + diff --git a/eo/contrib/mathsym/test/test_compile.o b/eo/contrib/mathsym/test/test_compile.o new file mode 100644 index 000000000..fab3f3cb2 Binary files /dev/null and b/eo/contrib/mathsym/test/test_compile.o differ diff --git a/eo/contrib/mathsym/test/testeo.cpp b/eo/contrib/mathsym/test/testeo.cpp new file mode 100644 index 000000000..ef6dd3dd8 --- /dev/null +++ b/eo/contrib/mathsym/test/testeo.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2005 Maarten Keijzer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "LanguageTable.h" +#include "TreeBuilder.h" +#include "FunDef.h" +#include "Dataset.h" + +#include "eoSymInit.h" +#include "eoSym.h" +#include "eoPop.h" +#include "eoSymMutate.h" +#include "eoSymCrossover.h" +#include "eoSymEval.h" + +typedef EoSym EoType; + +int main() { + + LanguageTable table; + table.add_function(sum_token, 2); + table.add_function(prod_token, 2); + table.add_function(inv_token, 1); + table.add_function(min_token, 1); + table.add_function( SymVar(0).token(), 0); + + table.add_function(tan_token, 1); + + table.add_function(sum_token, 0); + table.add_function(prod_token, 0); + + TreeBuilder builder(table); + + eoSymInit init(builder); + + eoPop pop(10, init); + + for (unsigned i = 0; i < pop.size(); ++i) { + // write out pretty printed + cout << (Sym) pop[i] << endl; + } + + BiasedNodeSelector node_selector; + eoSymSubtreeMutate mutate1(builder, node_selector); + eoSymNodeMutate mutate2(table); + + cout << "****** MUTATION ************" << endl; + + for (unsigned i = 0; i < pop.size(); ++i) { + + cout << "Before " << (Sym) pop[i] << endl; + mutate1(pop[i]); + cout << "After 1 " << (Sym) pop[i] << endl; + mutate2(pop[i]); + cout << "After 2 " << (Sym) pop[i] << endl; + } + + cout << "****** CROSSOVER ***********" << endl; + + eoQuadSubtreeCrossover quad(node_selector); + eoBinSubtreeCrossover bin(node_selector); + eoBinHomologousCrossover hom; + + for (unsigned i = 0; i < pop.size()-1; ++i) { + cout << "Before " << (Sym) pop[i] << endl; + cout << "Before " << (Sym) pop[i+1] << endl; + + hom(pop[i], pop[i+1]); + + cout << "After hom " << (Sym) pop[i] << endl; + cout << "After hom " << (Sym) pop[i+1] << endl; + + + quad(pop[i], pop[i+1]); + + cout << "After quad " << (Sym) pop[i] << endl; + cout << "After quad " << (Sym) pop[i+1] << endl; + + bin(pop[i], pop[i+1]); + + cout << "After bin " << (Sym) pop[i] << endl; + cout << "After bin " << (Sym) pop[i+1] << endl; + + cout << endl; + } + + cout << "****** Evaluation **********" << endl; + + Dataset dataset; + dataset.load_data("problem4.dat"); + IntervalBoundsCheck check(dataset.input_minima(), dataset.input_maxima()); + ErrorMeasure measure(dataset, 0.90, ErrorMeasure::mean_squared_scaled); + + eoSymPopEval evaluator(check, measure); + + eoPop dummy; + evaluator(pop, dummy); + + for (unsigned i = 0; i < pop.size(); ++i) { + cout << pop[i] << endl; + } + +} + diff --git a/eo/contrib/mathsym/test/testeo.o b/eo/contrib/mathsym/test/testeo.o new file mode 100644 index 000000000..c60cf5dd5 Binary files /dev/null and b/eo/contrib/mathsym/test/testeo.o differ diff --git a/eo/contrib/mathsym/test_data.txt b/eo/contrib/mathsym/test_data.txt new file mode 100644 index 000000000..a8c792b1a --- /dev/null +++ b/eo/contrib/mathsym/test_data.txt @@ -0,0 +1,102 @@ +# 101 2 nan nan + 0 -0 + 0.1 -8.89903723981037e-05 + 0.2 -0.00122598240763888 + 0.3 -0.00517587564272387 + 0.4 -0.0132382052428645 + 0.5 -0.0254643081877282 + 0.6 -0.0407070337997998 + 0.7 -0.057285499199392 + 0.8 -0.0737562490233578 + 0.9 -0.0892727708954409 + 1 -0.103268200413493 + 1.1 -0.114577577792354 + 1.2 -0.120446083316857 + 1.3 -0.116000062935524 + 1.4 -0.0946298417869761 + 1.5 -0.0493963195458011 + 1.6 0.0248409598316732 + 1.7 0.129207388804052 + 1.8 0.259260510831339 + 1.9 0.404709502287215 + 2 0.550653582802201 + 2.1 0.680124882844178 + 2.2 0.777313232294796 + 2.3 0.830628236863242 + 2.4 0.834788256127692 + 2.5 0.79140362503436 + 2.6 0.707953643967287 + 2.7 0.595509207315954 + 2.8 0.46588939354196 + 2.9 0.329064872475183 + 3 0.191504886385553 + 3.1 0.0558518299407852 + 3.2 -0.0781019284912663 + 3.3 -0.211542824409141 + 3.4 -0.344524221510933 + 3.5 -0.474312294176053 + 3.6 -0.594727989459508 + 3.7 -0.696713721292122 + 3.8 -0.769988957905497 + 3.9 -0.805344773512717 + 4 -0.796949283133396 + 4.1 -0.744036874310458 + 4.2 -0.651525836186196 + 4.3 -0.529396820025977 + 4.4 -0.39098574050144 + 4.5 -0.250612439788816 + 4.6 -0.121113466670896 + 4.7 -0.0118426008551395 + 4.8 0.0724429930487275 + 4.9 0.13163323998176 + 5 0.169341449166714 + 5.1 0.191319990014267 + 5.2 0.203657703492626 + 5.3 0.211210264725322 + 5.4 0.216611758596317 + 5.5 0.220036646440173 + 5.6 0.219677788419796 + 5.7 0.212731354762643 + 5.8 0.196574232374672 + 5.9 0.169803441763318 + 6 0.132875383837662 + 6.1 0.0882099910986659 + 6.2 0.0397733622937463 + 6.3 -0.00771703924831375 + 6.4 -0.0497388405970527 + 6.5 -0.0828196592845663 + 6.6 -0.105101954751146 + 6.7 -0.116508794142315 + 6.8 -0.118508967610477 + 6.9 -0.113576955648085 + 7 -0.104507044103426 + 7.1 -0.0937591677397028 + 7.2 -0.0829871341075209 + 7.3 -0.0728391340503617 + 7.4 -0.0630443677389944 + 7.5 -0.0527284491080759 + 7.6 -0.0408508284036276 + 7.7 -0.0266394584962638 + 7.8 -0.00991225704809318 + 7.9 0.00878546797299183 + 8 0.0282459694154097 + 8.1 0.0468334978875681 + 8.2 0.0628175943181446 + 8.3 0.0747179317764707 + 8.4 0.0815794072993519 + 8.5 0.0831208473565567 + 8.6 0.0797359724522078 + 8.7 0.072361534724142 + 8.8 0.0622560784562081 + 8.9 0.0507477567273995 + 9 0.0390091892966309 + 9.1 0.0279034956336959 + 9.2 0.0179233472968783 + 9.3 0.00922050032813963 + 9.4 0.00170282350837218 + 9.5 -0.00483635091477891 + 9.6 -0.010593872761556 + 9.7 -0.0156676782318098 + 9.8 -0.020019888098685 + 9.9 -0.0234934811028401 + 10 -0.0258701880584331