Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matheval #1644

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
41491ad
Initial upload :octocat:
hmenke Nov 7, 2017
6824ed5
Travis CI
hmenke Nov 7, 2017
d8cebd1
Enable OS X build
hmenke Nov 7, 2017
02de3a2
AppVeyor
hmenke Nov 7, 2017
3a5ed26
Make parsing case sensitive
hmenke Nov 7, 2017
c8a59e6
Build documentation on Travis
Nov 7, 2017
a5233f9
Build on default Xcode
hmenke Nov 7, 2017
f0f1883
A little more documentation
hmenke Nov 7, 2017
5e78039
Build test on AppVeyor
hmenke Nov 7, 2017
9b099d8
Hand-written build matrix
hmenke Nov 8, 2017
0274e0a
Add a class based interface as well
Nov 9, 2017
b8ec892
Revert to std::map for compatibility; more README
hmenke Nov 9, 2017
72edf4c
Fix for older Boost versions
hmenke Nov 9, 2017
6e77515
Fix stack overflow in eval_ast
hmenke Nov 10, 2017
aefcdc7
Added constant folding support to Parser.
fweik Nov 11, 2017
8e6c53a
and -> &&
fweik Nov 11, 2017
9ac5c4b
Make tests actually test something; correct a comment
Nov 12, 2017
f76f010
Suppress warnings about sequence points
hmenke Nov 28, 2017
de1c4ca
Add expectation points (Fixes #6)
hmenke Dec 8, 2017
cb55f90
Fix parsing ambiguity of atan and atan2
hmenke Dec 8, 2017
79b9d77
Build with Boost 1.55 on Travis
hmenke Dec 11, 2017
c000d9b
AppVeyor build matrix
hmenke Dec 11, 2017
7dae74e
Allow failures for documentation build
hmenke Dec 11, 2017
c899f6c
Replace % by the last result in calculator
hmenke Dec 15, 2017
7f36433
Add more functions; add golden ratio
Dec 16, 2017
ea8b603
Optionally build the desktop calculator
hmenke Dec 17, 2017
85affa8
Increase coverage
hmenke Dec 17, 2017
f94019c
Generate coverage report
hmenke Dec 17, 2017
4dea0c2
calc: Don't die on SIGINT
hmenke Dec 18, 2017
9c908d1
Increase coverage
hmenke Dec 19, 2017
4eb6290
Lua module
hmenke Apr 21, 2018
cd015cf
Enable static analysis
hmenke Jul 3, 2018
dc0a87f
AppVeyor removed Boost 1.59.0
hmenke Jul 3, 2018
ffb7f8c
More checks for static analysis
hmenke Jul 12, 2018
0a58dd2
Old versions of stdlibc++ do not have sufficient noexcept
hmenke Jul 12, 2018
a90eddd
[libs] Potentials from mathematical expression
hmenke Oct 10, 2019
572523f
Complete rewrite, also with X3 variant
hmenke Oct 16, 2019
884082c
Unify API a little better
hmenke Oct 24, 2019
e913719
Use Boost.Test header-only
hmenke Oct 24, 2019
59e2b14
Implement all tests for QI and X3
hmenke Oct 24, 2019
bcfe4b9
Build my own coverage report
hmenke Oct 24, 2019
4e23428
Update documentation
hmenke Oct 24, 2019
1298073
Prefix all targets
hmenke Oct 24, 2019
9c20cc1
target_compile_features
hmenke Oct 24, 2019
8038bce
EXCLUDE_FROM_ALL requires binary directory to be specified
hmenke Oct 27, 2019
fc5b394
Logical, relational, and equality operators
hmenke Oct 31, 2019
013f28c
BOOST_SPIRIT_NO_PREDEFINED_TERMINALS and formatting
hmenke Oct 31, 2019
fa2885b
Remove libs/matheval
RudolfWeeber Jan 23, 2020
6c6b714
Add 'libs/matheval/' from commit '013f28cb001b30a3d9d47758cf1a9e6456d…
RudolfWeeber Jan 23, 2020
21f77a6
Support new version of Matheval
RudolfWeeber Jan 23, 2020
740b59e
Merge branch 'python' of git://github.com/espressomd/espresso into pr…
RudolfWeeber Jan 23, 2020
ba33441
Guard guard MathEval uses. Let CMake decide, whether it is present
RudolfWeeber Jan 23, 2020
4256fd1
Formatting
RudolfWeeber Jan 23, 2020
d219177
Merge branch 'python' of git://github.com/espressomd/espresso into pr…
RudolfWeeber Feb 4, 2020
873232d
Missing feautre renames
RudolfWeeber Feb 4, 2020
288367d
Somewhat more programmatic EXTERNAL handling in gen_featuredefs.py
RudolfWeeber Feb 4, 2020
d9ea8c3
Remove legacy Py 2 code
RudolfWeeber Feb 4, 2020
adedc1a
Revert "Missing feautre renames"
RudolfWeeber Feb 4, 2020
55bc651
Config: Remove EXTERNAL features from config sets
RudolfWeeber Feb 4, 2020
fb6df24
Cmake: Disable matheval, if boost is <1.65.1
RudolfWeeber Feb 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ option(WITH_PYTHON "Build with Python bindings" ON)
option(WITH_GSL "Build with GSL support" ON)
option(WITH_CUDA "Build with GPU support" ON)
option(WITH_HDF5 "Build with HDF5 support" ON)
option(WITH_MATHEVAL "Build with MathEval support" ON)
option(WITH_TESTS "Enable tests" ON)
option(WITH_SCAFACOS "Build with Scafacos support" OFF)
option(WITH_BENCHMARKS "Enable benchmarks" OFF)
Expand Down Expand Up @@ -399,6 +400,17 @@ if(Boost_VERSION VERSION_GREATER_EQUAL 106400 AND Boost_VERSION VERSION_LESS 106
endif()
endif()


if (WITH_MATHEVAL)
# Note: Boost version check can be removed, once 1.65.1 is required
if(EXISTS "${CMAKE_SOURCE_DIR}/libs/matheval" AND (Boost_VERSION VERSION_GREATER_EQUAL 106501))
set(MATHEVAL 1)
else()
unset(MATHEVAL)
endif()
endif()


#
# Paths
#
Expand Down
3 changes: 3 additions & 0 deletions cmake/cmake_config.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#cmakedefine H5MD

#cmakedefine MATHEVAL


#cmakedefine SCAFACOS

#cmakedefine GSL
Expand Down
5 changes: 5 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ add_library(Random123 INTERFACE)
target_include_directories(Random123 SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/Random123-1.09/include)

target_compile_definitions(Random123 INTERFACE R123_USE_MULHILO64_C99)

if (MATHEVAL)
add_subdirectory(matheval)
endif()

18 changes: 18 additions & 0 deletions libs/matheval/.appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
image: Visual Studio 2017

platform: x64

environment:
GENERATOR: "Visual Studio 15 2017 Win64"
CONFIG: Debug
matrix:
- BOOST_ROOT: "C:\\Libraries\\boost_1_65_1"

build_script:
- mkdir build
- cd build
- cmake -G "%GENERATOR%" -DCMAKE_BUILD_TYPE="%CONFIG%" -DBOOST_ROOT="%BOOST_ROOT%" ..
- cmake --build "./examples" --target "examples" --config "%CONFIG%"

test_script:
- cmake --build "./tests" --target "check" --config "%CONFIG%"
52 changes: 52 additions & 0 deletions libs/matheval/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
dist: bionic
sudo: false

language: cpp

script:
- mkdir build
- cd build
- cmake -DWITH_COVERAGE=ON -DWITH_CLANG_TIDY=ON ..
- make -k -j 2 examples
- make -k -j 2 check
- curl -s https://codecov.io/bash | bash -

matrix:
include:
- os: linux
compiler: clang
addons:
apt:
packages:
- libboost-dev
- libboost-test-dev
- os: linux
compiler: gcc
addons:
apt:
packages:
- libboost-dev
- libboost-test-dev
- os: osx
install:
- brew link --force readline
compiler: clang
- if: branch = master
os: linux
env: docs=yes
addons:
apt:
packages:
- doxygen
- lcov
- libboost-dev
- libboost-test-dev
script:
- mkdir build
- cd build
- bash ../doc/prepare_documentation.sh
- cmake -DWITH_COVERAGE=ON ..
- make -k -j 2 examples
- make -k -j 2 check
- bash ../doc/update_documentation.sh
- curl -s https://codecov.io/bash | bash -s - -X gcov
48 changes: 48 additions & 0 deletions libs/matheval/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)

project(boost_matheval CXX)

# Default build type is Debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the build type" FORCE)
endif()

# Add local package finders
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Build options
option(WITH_COVERAGE "Generate code coverage report" OFF)
if(WITH_COVERAGE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
link_libraries(gcov)
else()
message(WARNING "Coverage information only supported on GCC")
endif()
endif()

if(CMAKE_VERSION VERSION_GREATER 3.5.2 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF)
endif()
if(WITH_CLANG_TIDY)
string(REGEX REPLACE "^([1-9]+\\.[0-9]+).*$" "\\1" CLANG_MINOR_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy-${CLANG_MINOR_VERSION}" "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}"
"-checks=-*,bugprone-*,cert-*,clang-analyzer-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,readability-*"
"-header-filter=.*")
#"-warnings-as-errors=*")
endif()
endif()

# Subdirectories

add_subdirectory(src/qi EXCLUDE_FROM_ALL)
add_subdirectory(src/x3 EXCLUDE_FROM_ALL)
23 changes: 23 additions & 0 deletions libs/matheval/LICENSE_1_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
114 changes: 114 additions & 0 deletions libs/matheval/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Boost Matheval

[![Build status][travis-svg]][travis-link]
[![AppVeyor build status][appveyor-svg]][appveyor-link]
[![Code coverage report][codecov-svg]][codecov-link]
[Documentation][doxygen-link]
[Coverage][coverage-link]

This library uses [Boost.Spirit](http://www.boost.org/libs/spirit/index.html)
(QI for C++98 and X3 for C++14) and
[Boost.Fusion](http://www.boost.org/libs/fusion/index.html) (and
[Boost.Phoenix](http://www.boost.org/libs/phoenix/index.html) with C++98) to
parse and evaluate mathematical expressions.

The examples below use the X3 variant of Boost Matheval.

### Motivating example 1

```cpp
#include <iostream>
#include "matheval.hpp"

int main() {
std::cout << matheval::parse("1+1") << '\n';
}
```
Outputs
```
2
```

### Motivating example 2

```cpp
#include <iostream>
#include <map>
#include "matheval.hpp"

int main() {
std::map<std::string,double> symtab;
symtab.emplace(std::make_pair("x", 2));
symtab.emplace(std::make_pair("y", -1));
std::cout << matheval::parse("cbrt(x/2 + sqrt(x**2/4 + y**3/24))",symtab) << '\n';
}
```
Outputs
```
1.25548
```

### Motivating example 3

We can also evaluate an expression multiple times without paying the
cost of parsing again.
```cpp
#include <iostream>
#include <map>
#include "matheval.hpp"

int main() {
matheval::Parser parser;
parser.parse("x + 1");
std::cout << parser.evaluate({std::make_pair("x",1)}) << ' '
<< parser.evaluate({std::make_pair("x",2)}) << '\n';
}
```
Outputs
```
2 3
```

### Build instructions

To build Boost Matheval, just follow the usual CMake workflow.
```bash
mkdir build
cd build
cmake ..
make # build the library and the examples
make check # build and run the tests
```

### Requirements and Limitations

General:

* C++14 compatible compiler, i.e. GCC >= 4.8, Clang, Visual Studio 2015.
* Boost.Spirit, Boost.Phoenix, and Boost.MathConstants.
* No support for ternary functions (e.g. `if`).
* No support for complex numbers.

### Alternatives

* [GNU libmatheval](https://www.gnu.org/software/libmatheval/) is a C
library built using the parser generator YACC with about the same
scope as Boost Matheval.
* [ExprTk](http://www.partow.net/programming/exprtk/) is a true
monster with almost 40000 lines in a single header file. It
implements a complete state machine including things like logical
operations, control structures, and even file IO. Compilation time
is even longer than with Boost Matheval.

### License

Distributed under the [Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt).

[travis-svg]: https://travis-ci.org/hmenke/boost_matheval.svg?branch=master
[travis-link]: https://travis-ci.org/hmenke/boost_matheval
[appveyor-svg]: https://ci.appveyor.com/api/projects/status/bphe1739kownt81c/branch/master?svg=true
[appveyor-link]: https://ci.appveyor.com/project/hmenke/boost-matheval/branch/master
[codecov-svg]: https://codecov.io/gh/hmenke/boost_matheval/branch/master/graph/badge.svg
[codecov-link]: https://codecov.io/gh/hmenke/boost_matheval
[doxygen-link]: https://hmenke.github.io/boost_matheval/doxygen/html/
[coverage-link]: https://hmenke.github.io/boost_matheval/coverage/html/
9 changes: 9 additions & 0 deletions libs/matheval/cmake/FindReadline.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(FindPackageHandleStandardArgs)

find_path(READLINE_INCLUDE_DIR NAMES readline/readline.h)

find_library(READLINE_LIBRARY NAMES readline)

find_package_handle_standard_args(READLINE DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR)

mark_as_advanced(READLINE_INCLUDE_DIR READLINE_LIBRARY)
9 changes: 9 additions & 0 deletions libs/matheval/doc/doxygen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
find_package(Doxygen)

if(DOXYGEN_FOUND)
add_custom_target(doxygen
COMMAND
SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/../../
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
COMMENT "Building HTML documentation with Doxygen")
endif()
Loading