Skip to content

Commit

Permalink
Starting root finding/paving for interval arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
toastedcrumpets committed Jul 30, 2021
1 parent 9e512ef commit edb2695
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
cmake_minimum_required (VERSION 3.0)

#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake/")

if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
Expand Down Expand Up @@ -171,6 +174,7 @@ if(GTest_FOUND)
stator_test(symbolic_numeric_test)
stator_test(symbolic_parser_test)
stator_test(symbolic_ad_test)

stator_test(symbolic_interval_test)
#stator_test(symbolic_integration_test)
else()
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ print(derivative(funcs, x)) # [0, 1, 4*x/4, 18*x^2/36, cos x, 0]
print(sub(funcs, {x:1, Expr('y'): 2})) # [1.0, 1.0, 0.5, 0.16666666666666666, 0.8414709848078965, 0.9092974268256817]
```

# Requirements

You need the Google test library to build the unit tests. The Boost
interval library is needed for interval arithmetic support.

# Alternatives/Similar software

For the compile-time C++ library:
Expand All @@ -58,3 +63,7 @@ For the python bindings:
- [sympy](https://www.sympy.org/): The full-featured CAS for python, but also quite slow.
- [symengine](https://symengine.org/index.html): Just like
stator. It's actually a C++ CAS engine with python wrappers.

For the interval arithmetic
- [Kodiak](https://github.com/nasa/Kodiak) This is a full library for interval arithmatic solving.
- [Julia](https://github.com/JuliaIntervals/IntervalArithmetic.jl) A brilliant implementation of interval solving.
5 changes: 3 additions & 2 deletions stator/symbolic/interval.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <boost/numeric/interval.hpp>
#include <stator/symbolic/symbolic.hpp>
#include <boost/numeric/interval.hpp> //filib++

namespace sym {
using boost::numeric::interval;
using boost::numeric::interval;

template<class Config = DefaultReprConfig, class ...Args>
inline std::string repr(const sym::interval<Args...>& f)
Expand Down
15 changes: 14 additions & 1 deletion tests/symbolic_interval_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

//stator
#include <stator/symbolic/symbolic.hpp>
#include <stator/symbolic/interval.hpp>
#define UNIT_TEST_SUITE_NAME Symbolic_
#define UNIT_TEST_GOOGLE
Expand All @@ -27,6 +26,7 @@
static constexpr char x_str[] = "x";
static constexpr char y_str[] = "y";


UNIT_TEST( symbolic_interval_basic ) {
sym::interval<double> i1(0, 2);
auto out = i1 * i1 - 2.0 * i1 + 1.0;
Expand All @@ -45,3 +45,16 @@ UNIT_TEST( symbolic_interval_basic ) {

UNIT_TEST_CHECK_EQUAL(sym::repr(out), "-3...5");
}

template<class F, class X>
auto root_find(const F& f, const X& x, const sym::interval<double>& range) {
return sym::interval<double>(0.0, 0.0);
}

UNIT_TEST( symbolic_interval_root ) {
sym::Var<x_str> x;

auto f = x * x - 2.0 * x + 1.0;

auto res = root_find(f, x, sym::interval<double>(0.0, 0.0));
}

0 comments on commit edb2695

Please sign in to comment.