C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
f46bffcd69
commit
9910dc988d
|
@ -19,6 +19,33 @@ jobs:
|
||||||
- run: make all -j 2
|
- run: make all -j 2
|
||||||
- run: ./exprtk_test
|
- run: ./exprtk_test
|
||||||
|
|
||||||
|
build_gcc_11:
|
||||||
|
docker:
|
||||||
|
- image: gcc:11
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: c++ --version
|
||||||
|
- run: make all -j 2
|
||||||
|
- run: ./exprtk_test
|
||||||
|
|
||||||
|
build_gcc_12:
|
||||||
|
docker:
|
||||||
|
- image: gcc:12
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: c++ --version
|
||||||
|
- run: make all -j 2
|
||||||
|
- run: ./exprtk_test
|
||||||
|
|
||||||
|
build_gcc_13:
|
||||||
|
docker:
|
||||||
|
- image: gcc:13
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: c++ --version
|
||||||
|
- run: make all -j 2
|
||||||
|
- run: ./exprtk_test
|
||||||
|
|
||||||
build_gcc_latest:
|
build_gcc_latest:
|
||||||
docker:
|
docker:
|
||||||
- image: gcc:latest
|
- image: gcc:latest
|
||||||
|
@ -32,6 +59,44 @@ workflows:
|
||||||
version: 2
|
version: 2
|
||||||
build_and_test:
|
build_and_test:
|
||||||
jobs:
|
jobs:
|
||||||
- build_gcc_09
|
- build_gcc_09:
|
||||||
- build_gcc_10
|
filters:
|
||||||
- build_gcc_latest
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- release
|
||||||
|
|
||||||
|
- build_gcc_10:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- release
|
||||||
|
|
||||||
|
- build_gcc_11:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- release
|
||||||
|
|
||||||
|
- build_gcc_12:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- release
|
||||||
|
|
||||||
|
- build_gcc_13:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- release
|
||||||
|
|
||||||
|
- build_gcc_latest:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
- release
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -2,14 +2,15 @@
|
||||||
# **************************************************************
|
# **************************************************************
|
||||||
# * C++ Mathematical Expression Toolkit Library *
|
# * C++ Mathematical Expression Toolkit Library *
|
||||||
# * *
|
# * *
|
||||||
# * Author: Arash Partow (1999-2023) *
|
# * Author: Arash Partow (1999-2024) *
|
||||||
# * URL: https://www.partow.net/programming/exprtk/index.html *
|
# * URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
# * *
|
# * *
|
||||||
# * Copyright notice: *
|
# * Copyright notice: *
|
||||||
# * Free use of the Mathematical Expression Toolkit Library is *
|
# * Free use of the Mathematical Expression Toolkit Library is *
|
||||||
# * permitted under the guidelines and in accordance with the *
|
# * permitted under the guidelines and in accordance with the *
|
||||||
# * most current version of the MIT License. *
|
# * most current version of the MIT License. *
|
||||||
# * http://www.opensource.org/licenses/MIT *
|
# * https://www.opensource.org/licenses/MIT *
|
||||||
|
# * SPDX-License-Identifier: MIT *
|
||||||
# * *
|
# * *
|
||||||
# **************************************************************
|
# **************************************************************
|
||||||
#
|
#
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
|
|
||||||
COMPILER := -c++
|
COMPILER := -c++
|
||||||
#COMPILER := -clang++
|
#COMPILER := -clang++
|
||||||
OPTIMIZATION_OPT := -O1
|
OPTIMIZATION_OPT := -O2 -DNDEBUG
|
||||||
BASE_OPTIONS := -pedantic-errors -Wall -Wextra -Werror -Wno-long-long
|
BASE_OPTIONS := -pedantic-errors -Wall -Wextra -Werror -Wno-long-long
|
||||||
OPTIONS := $(BASE_OPTIONS) $(OPTIMIZATION_OPT)
|
OPTIONS := $(BASE_OPTIONS) $(OPTIMIZATION_OPT)
|
||||||
LINKER_OPT := -L/usr/lib -lstdc++ -lm
|
LINKER_OPT := -L/usr/lib -lstdc++ -lm
|
||||||
|
@ -46,9 +47,9 @@ valgrind :
|
||||||
fi done;
|
fi done;
|
||||||
|
|
||||||
pgo: exprtk_benchmark.cpp exprtk.hpp
|
pgo: exprtk_benchmark.cpp exprtk.hpp
|
||||||
$(COMPILER) $(BASE_OPTIONS) -O3 -march=native -fprofile-generate -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
$(COMPILER) $(BASE_OPTIONS) -O3 -DNDEBUG -march=native -fprofile-generate -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
||||||
./exprtk_benchmark
|
./exprtk_benchmark
|
||||||
$(COMPILER) $(BASE_OPTIONS) -O3 -march=native -fprofile-use -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
$(COMPILER) $(BASE_OPTIONS) -O3 -DNDEBUG -march=native -fprofile-use -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch
|
rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch
|
||||||
|
|
10026
exprtk.hpp
10026
exprtk.hpp
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* ExprTk vs Native Benchmarks *
|
* ExprTk vs Native Benchmarks *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -18,7 +19,6 @@
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
@ -26,8 +26,8 @@
|
||||||
#include "exprtk.hpp"
|
#include "exprtk.hpp"
|
||||||
|
|
||||||
|
|
||||||
const std::string global_expression_list[]
|
const std::string global_expression_list[] =
|
||||||
= {
|
{
|
||||||
"(y + x)",
|
"(y + x)",
|
||||||
"2 * (y + x)",
|
"2 * (y + x)",
|
||||||
"(2 * y + 2 * x)",
|
"(2 * y + 2 * x)",
|
||||||
|
@ -323,7 +323,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::cout << "--- EXPRTK ---" << std::endl;
|
printf("--- EXPRTK ---\n");
|
||||||
for (std::size_t i = 0; i < compiled_expr_list.size(); ++i)
|
for (std::size_t i = 0; i < compiled_expr_list.size(); ++i)
|
||||||
{
|
{
|
||||||
run_exprtk_benchmark(x,y,compiled_expr_list[i],global_expression_list[i]);
|
run_exprtk_benchmark(x,y,compiled_expr_list[i],global_expression_list[i]);
|
||||||
|
@ -331,7 +331,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::cout << "--- NATIVE ---" << std::endl;
|
printf("--- NATIVE ---\n");
|
||||||
run_native_benchmark(x, y, native<double>::func00,global_expression_list[ 0]);
|
run_native_benchmark(x, y, native<double>::func00,global_expression_list[ 0]);
|
||||||
run_native_benchmark(x, y, native<double>::func01,global_expression_list[ 1]);
|
run_native_benchmark(x, y, native<double>::func01,global_expression_list[ 1]);
|
||||||
run_native_benchmark(x, y, native<double>::func02,global_expression_list[ 2]);
|
run_native_benchmark(x, y, native<double>::func02,global_expression_list[ 2]);
|
||||||
|
@ -352,7 +352,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::cout << "--- PARSE ----" << std::endl;
|
printf("--- PARSE ----\n");
|
||||||
run_parse_benchmark(symbol_table);
|
run_parse_benchmark(symbol_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ double pgo_primer()
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t load_expression_file(const std::string& file_name, std::deque<std::string>& expression_list)
|
inline std::size_t load_expression_file(const std::string& file_name, std::deque<std::string>& expression_list)
|
||||||
{
|
{
|
||||||
std::ifstream stream(file_name.c_str());
|
std::ifstream stream(file_name.c_str());
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ void perform_file_based_benchmark(const std::string& file_name, const std::size_
|
||||||
|
|
||||||
if (0 == load_expression_file(file_name,expr_str_list))
|
if (0 == load_expression_file(file_name,expr_str_list))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to load any expressions from: " << file_name << "\n";
|
printf("Failed to load any expressions from: %s\n", file_name.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,6 +446,8 @@ void perform_file_based_benchmark(const std::string& file_name, const std::size_
|
||||||
double z = 4.123456;
|
double z = 4.123456;
|
||||||
double w = 5.123456;
|
double w = 5.123456;
|
||||||
|
|
||||||
|
exprtk::rtl::vecops::package<double> vector_package;
|
||||||
|
|
||||||
symbol_table.add_variable("a", a);
|
symbol_table.add_variable("a", a);
|
||||||
symbol_table.add_variable("b", b);
|
symbol_table.add_variable("b", b);
|
||||||
symbol_table.add_variable("c", c);
|
symbol_table.add_variable("c", c);
|
||||||
|
@ -481,6 +483,9 @@ void perform_file_based_benchmark(const std::string& file_name, const std::size_
|
||||||
symbol_table.add_function("poly11", poly11);
|
symbol_table.add_function("poly11", poly11);
|
||||||
symbol_table.add_function("poly12", poly12);
|
symbol_table.add_function("poly12", poly12);
|
||||||
|
|
||||||
|
symbol_table.add_package(vector_package);
|
||||||
|
|
||||||
|
|
||||||
static double e = exprtk::details::numeric::constant::e;
|
static double e = exprtk::details::numeric::constant::e;
|
||||||
symbol_table.add_variable("e", e, true);
|
symbol_table.add_variable("e", e, true);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 1 *
|
* Simple Example 01 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 2 *
|
* Simple Example 02 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +30,7 @@ void square_wave()
|
||||||
typedef exprtk::expression<T> expression_t;
|
typedef exprtk::expression<T> expression_t;
|
||||||
typedef exprtk::parser<T> parser_t;
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
|
||||||
const std::string expr_string =
|
const std::string expression_string =
|
||||||
"a *(4 / pi) * "
|
"a *(4 / pi) * "
|
||||||
"((1 / 1) * sin( 2 * pi * f * t) + (1 / 3) * sin( 6 * pi * f * t) + "
|
"((1 / 1) * sin( 2 * pi * f * t) + (1 / 3) * sin( 6 * pi * f * t) + "
|
||||||
" (1 / 5) * sin(10 * pi * f * t) + (1 / 7) * sin(14 * pi * f * t) + "
|
" (1 / 5) * sin(10 * pi * f * t) + (1 / 7) * sin(14 * pi * f * t) + "
|
||||||
|
@ -55,7 +56,7 @@ void square_wave()
|
||||||
expression.register_symbol_table(symbol_table);
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
parser_t parser;
|
parser_t parser;
|
||||||
parser.compile(expr_string,expression);
|
parser.compile(expression_string,expression);
|
||||||
|
|
||||||
const T delta = (T(4) * pi) / T(1000);
|
const T delta = (T(4) * pi) / T(1000);
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 3 *
|
* Simple Example 03 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 4 *
|
* Simple Example 04 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -31,31 +32,32 @@ void fibonacci()
|
||||||
typedef exprtk::function_compositor<T> compositor_t;
|
typedef exprtk::function_compositor<T> compositor_t;
|
||||||
typedef typename compositor_t::function function_t;
|
typedef typename compositor_t::function function_t;
|
||||||
|
|
||||||
|
T x = T(0);
|
||||||
|
|
||||||
compositor_t compositor;
|
compositor_t compositor;
|
||||||
|
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("fibonacci")
|
||||||
function_t( // define function: fibonacci(x)
|
.var("x")
|
||||||
"fibonacci",
|
.expression
|
||||||
" var w := 0; "
|
(
|
||||||
" var y := 0; "
|
|
||||||
" var z := 1; "
|
|
||||||
" switch "
|
" switch "
|
||||||
" { "
|
" { "
|
||||||
" case x == 0 : 0; "
|
" case x == 0 : 0; "
|
||||||
" case x == 1 : 1; "
|
" case x == 1 : 1; "
|
||||||
" default : "
|
" default : "
|
||||||
|
" { "
|
||||||
|
" var prev := 0; "
|
||||||
|
" var curr := 1; "
|
||||||
" while ((x -= 1) > 0) "
|
" while ((x -= 1) > 0) "
|
||||||
" { "
|
" { "
|
||||||
" w := z; "
|
" var temp := prev; "
|
||||||
" z := z + y; "
|
" prev := curr; "
|
||||||
" y := w; "
|
" curr += temp; "
|
||||||
" z "
|
|
||||||
" }; "
|
" }; "
|
||||||
" } ",
|
" }; "
|
||||||
"x"));
|
" } "
|
||||||
|
));
|
||||||
T x = T(0);
|
|
||||||
|
|
||||||
symbol_table_t& symbol_table = compositor.symbol_table();
|
symbol_table_t& symbol_table = compositor.symbol_table();
|
||||||
symbol_table.add_constants();
|
symbol_table.add_constants();
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 5 *
|
* Simple Example 05 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -31,14 +32,14 @@ struct myfunc : public exprtk::ifunction<T>
|
||||||
: exprtk::ifunction<T>(2)
|
: exprtk::ifunction<T>(2)
|
||||||
{ exprtk::disable_has_side_effects(*this); }
|
{ exprtk::disable_has_side_effects(*this); }
|
||||||
|
|
||||||
inline T operator()(const T& v1, const T& v2)
|
T operator()(const T& v1, const T& v2)
|
||||||
{
|
{
|
||||||
return T(1) + (v1 * v2) / T(3);
|
return T(1) + (v1 * v2) / T(3);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T myotherfunc(T v0, T v1, T v2)
|
T myotherfunc(T v0, T v1, T v2)
|
||||||
{
|
{
|
||||||
return std::abs(v0 - v1) * v2;
|
return std::abs(v0 - v1) * v2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 6 *
|
* Simple Example 06 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 7 *
|
* Simple Example 07 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 8 *
|
* Simple Example 08 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -28,27 +29,29 @@ void composite()
|
||||||
typedef exprtk::symbol_table<T> symbol_table_t;
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
typedef exprtk::expression<T> expression_t;
|
typedef exprtk::expression<T> expression_t;
|
||||||
typedef exprtk::parser<T> parser_t;
|
typedef exprtk::parser<T> parser_t;
|
||||||
typedef exprtk::parser_error::type error_t;
|
typedef exprtk::parser_error::type err_t;
|
||||||
typedef exprtk::function_compositor<T> compositor_t;
|
typedef exprtk::function_compositor<T> compositor_t;
|
||||||
typedef typename compositor_t::function function_t;
|
typedef typename compositor_t::function function_t;
|
||||||
|
|
||||||
compositor_t compositor;
|
|
||||||
|
|
||||||
T x = T(1);
|
T x = T(1);
|
||||||
T y = T(2);
|
T y = T(2);
|
||||||
|
|
||||||
|
compositor_t compositor;
|
||||||
|
|
||||||
symbol_table_t& symbol_table = compositor.symbol_table();
|
symbol_table_t& symbol_table = compositor.symbol_table();
|
||||||
symbol_table.add_constants();
|
symbol_table.add_constants();
|
||||||
symbol_table.add_variable("x",x);
|
symbol_table.add_variable("x",x);
|
||||||
symbol_table.add_variable("y",y);
|
symbol_table.add_variable("y",y);
|
||||||
|
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("f") // f(x) = sin(x / pi)
|
||||||
function_t("f","sin(x / pi)","x")); // f(x) = sin(x / pi)
|
.var("x")
|
||||||
|
.expression( "sin(x / pi)" ));
|
||||||
|
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("g") // g(x,y) = 3[f(x) + f(y)]
|
||||||
function_t("g","3*[f(x) + f(y)]","x","y")); // g(x,y) = 3[f(x) + f(y)]
|
.vars("x", "y")
|
||||||
|
.expression( "3*[f(x) + f(y)]" ));
|
||||||
|
|
||||||
std::string expression_string = "g(1 + f(x), f(y) / 2)";
|
std::string expression_string = "g(1 + f(x), f(y) / 2)";
|
||||||
|
|
||||||
|
@ -65,7 +68,7 @@ void composite()
|
||||||
|
|
||||||
for (std::size_t i = 0; i < parser.error_count(); ++i)
|
for (std::size_t i = 0; i < parser.error_count(); ++i)
|
||||||
{
|
{
|
||||||
const error_t error = parser.get_error(i);
|
const err_t error = parser.get_error(i);
|
||||||
|
|
||||||
printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
|
printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
|
||||||
static_cast<unsigned int>(i),
|
static_cast<unsigned int>(i),
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
**************************************************************
|
**************************************************************
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 9 *
|
* Simple Example 09 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -41,76 +42,98 @@ void primes()
|
||||||
compositor_t compositor(symbol_table);
|
compositor_t compositor(symbol_table);
|
||||||
|
|
||||||
//Mode 1 - if statement based
|
//Mode 1 - if statement based
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("is_prime_impl1")
|
||||||
function_t( // define function: is_prime_impl1(x,y)
|
.vars("x", "y")
|
||||||
"is_prime_impl1",
|
.expression
|
||||||
|
(
|
||||||
" if (y == 1,true, "
|
" if (y == 1,true, "
|
||||||
" if (0 == (x % y),false, "
|
" if (0 == (x % y),false, "
|
||||||
" is_prime_impl1(x,y - 1))) ",
|
" is_prime_impl1(x,y - 1))) "
|
||||||
"x","y"));
|
));
|
||||||
|
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("is_prime1")
|
||||||
function_t( // define function: is_prime1(x)
|
.var("x")
|
||||||
"is_prime1",
|
.expression
|
||||||
" if (frac(x) != 0, false, "
|
(
|
||||||
" if (x <= 0, false, "
|
" if (frac(x) != 0) "
|
||||||
" is_prime_impl1(x,min(x - 1,trunc(sqrt(x)) + 1)))) ",
|
" return [false]; "
|
||||||
"x"));
|
" else if (x <= 0) "
|
||||||
|
" return [false]; "
|
||||||
|
" else "
|
||||||
|
" is_prime_impl1(x,min(x - 1,trunc(sqrt(x)) + 1)); "
|
||||||
|
));
|
||||||
|
|
||||||
//Mode 2 - switch statement based
|
//Mode 2 - switch statement based
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("is_prime_impl2")
|
||||||
function_t( // define function: is_prime_impl2(x,y)
|
.vars("x", "y")
|
||||||
"is_prime_impl2",
|
.expression
|
||||||
|
(
|
||||||
" switch "
|
" switch "
|
||||||
" { "
|
" { "
|
||||||
" case y == 1 : true; "
|
" case y == 1 : true; "
|
||||||
" case (x % y) == 0 : false; "
|
" case (x % y) == 0 : false; "
|
||||||
" default : is_prime_impl2(x,y - 1); "
|
" default : is_prime_impl2(x,y - 1); "
|
||||||
" } ",
|
" } "
|
||||||
"x","y"));
|
));
|
||||||
|
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("is_prime2")
|
||||||
function_t( // define function: is_prime2(x)
|
.var("x")
|
||||||
"is_prime2",
|
.expression
|
||||||
|
(
|
||||||
" switch "
|
" switch "
|
||||||
" { "
|
" { "
|
||||||
" case x <= 0 : false; "
|
" case x <= 0 : false; "
|
||||||
" case frac(x) != 0 : false; "
|
" case frac(x) != 0 : false; "
|
||||||
" default : is_prime_impl2(x,min(x - 1,trunc(sqrt(x)) + 1)); "
|
" default : is_prime_impl2(x,min(x - 1,trunc(sqrt(x)) + 1)); "
|
||||||
" } ",
|
|
||||||
"x"));
|
|
||||||
|
|
||||||
//Mode 3 - switch statement and while-loop based
|
|
||||||
compositor
|
|
||||||
.add(
|
|
||||||
function_t( // define function: is_prime_impl3(x,y)
|
|
||||||
"is_prime_impl3",
|
|
||||||
" while (y > 0) "
|
|
||||||
" { "
|
|
||||||
" switch "
|
|
||||||
" { "
|
|
||||||
" case y == 1 : ~(y := 0,true); "
|
|
||||||
" case (x % y) == 0 : ~(y := 0,false); "
|
|
||||||
" default : y := y - 1; "
|
|
||||||
" } "
|
" } "
|
||||||
" } ",
|
));
|
||||||
"x","y"));
|
|
||||||
|
|
||||||
compositor
|
//Mode 3 - switch statement and for-loop based
|
||||||
.add(
|
compositor.add(
|
||||||
function_t( // define function: is_prime3(x)
|
function_t("is_prime3")
|
||||||
"is_prime3",
|
.var("x")
|
||||||
|
.expression
|
||||||
|
(
|
||||||
" switch "
|
" switch "
|
||||||
" { "
|
" { "
|
||||||
" case x <= 0 : false; "
|
" case x <= 1 : return [false]; "
|
||||||
" case frac(x) != 0 : false; "
|
" case frac(x) != 0 : return [false]; "
|
||||||
" default : is_prime_impl3(x,min(x - 1,trunc(sqrt(x)) + 1)); "
|
" case x == 2 : return [true ]; "
|
||||||
" } ",
|
" }; "
|
||||||
"x"));
|
" "
|
||||||
|
" var prime_lut[27] := "
|
||||||
|
" { "
|
||||||
|
" 2, 3, 5, 7, 11, 13, 17, 19, 23, "
|
||||||
|
" 29, 31, 37, 41, 43, 47, 53, 59, 61, "
|
||||||
|
" 67, 71, 73, 79, 83, 89, 97, 101, 103 "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" var upper_bound := min(x - 1, trunc(sqrt(x)) + 1); "
|
||||||
|
" "
|
||||||
|
" for (var i := 0; i < prime_lut[]; i += 1) "
|
||||||
|
" { "
|
||||||
|
" if (prime_lut[i] >= upper_bound) "
|
||||||
|
" return [true]; "
|
||||||
|
" else if ((x % prime_lut[i]) == 0) "
|
||||||
|
" return [false]; "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" var lower_bound := prime_lut[prime_lut[] - 1] + 2; "
|
||||||
|
" "
|
||||||
|
" for (var i := lower_bound; i < upper_bound; i += 2) "
|
||||||
|
" { "
|
||||||
|
" if ((x % i) == 0) "
|
||||||
|
" { "
|
||||||
|
" return [false]; "
|
||||||
|
" } "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" return [true]; "
|
||||||
|
));
|
||||||
|
|
||||||
std::string expression_str1 = "is_prime1(x)";
|
std::string expression_str1 = "is_prime1(x)";
|
||||||
std::string expression_str2 = "is_prime2(x)";
|
std::string expression_str2 = "is_prime2(x)";
|
||||||
|
@ -129,7 +152,7 @@ void primes()
|
||||||
parser.compile(expression_str2, expression2);
|
parser.compile(expression_str2, expression2);
|
||||||
parser.compile(expression_str3, expression3);
|
parser.compile(expression_str3, expression3);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < 100; ++i)
|
for (std::size_t i = 0; i < 15000; ++i)
|
||||||
{
|
{
|
||||||
x = static_cast<T>(i);
|
x = static_cast<T>(i);
|
||||||
|
|
||||||
|
@ -137,11 +160,16 @@ void primes()
|
||||||
const T result2 = expression2.value();
|
const T result2 = expression2.value();
|
||||||
const T result3 = expression3.value();
|
const T result3 = expression3.value();
|
||||||
|
|
||||||
printf("%03d Result1: %c Result2: %c Result3: %c\n",
|
const bool results_concur = (result1 == result2) &&
|
||||||
|
(result1 == result3) ;
|
||||||
|
|
||||||
|
printf("%03d Result1: %c Result2: %c Result3: %c "
|
||||||
|
"Results Concur: %c\n",
|
||||||
static_cast<unsigned int>(i),
|
static_cast<unsigned int>(i),
|
||||||
(result1 == T(1)) ? 'T' : 'F',
|
(result1 == T(1)) ? 'T' : 'F',
|
||||||
(result2 == T(1)) ? 'T' : 'F',
|
(result2 == T(1)) ? 'T' : 'F',
|
||||||
(result3 == T(1)) ? 'T' : 'F');
|
(result3 == T(1)) ? 'T' : 'F',
|
||||||
|
(results_concur) ? 'T' : 'F');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 10 *
|
* Simple Example 10 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -41,28 +42,29 @@ void newton_sqrt()
|
||||||
|
|
||||||
compositor_t compositor(symbol_table);
|
compositor_t compositor(symbol_table);
|
||||||
|
|
||||||
compositor
|
compositor.add(
|
||||||
.add(
|
function_t("newton_sqrt")
|
||||||
function_t( // define function: newton_sqrt(x)
|
.var("x")
|
||||||
"newton_sqrt",
|
.expression
|
||||||
|
(
|
||||||
" switch "
|
" switch "
|
||||||
" { "
|
" { "
|
||||||
" case x < 0 : null; "
|
" case x < 0 : null; "
|
||||||
" case x == 0 : 0; "
|
" case x == 0 : 0; "
|
||||||
" case x == 1 : 1; "
|
" case x == 1 : 1; "
|
||||||
" default: "
|
" default: "
|
||||||
" ~{ "
|
" { "
|
||||||
" var z := 100; "
|
" var remaining_itrs := 100; "
|
||||||
" var sqrt_x := x / 2; "
|
" var sqrt_x := x / 2; "
|
||||||
" repeat "
|
" repeat "
|
||||||
" if (equal(sqrt_x^2, x)) "
|
" if (equal(sqrt_x * sqrt_x, x)) "
|
||||||
" break[sqrt_x]; "
|
" break[sqrt_x]; "
|
||||||
" else "
|
" else "
|
||||||
" sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
|
" sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
|
||||||
" until ((z -= 1) <= 0); "
|
" until ((remaining_itrs -= 1) <= 0); "
|
||||||
" }; "
|
" }; "
|
||||||
" } ",
|
" } "
|
||||||
"x"));
|
));
|
||||||
|
|
||||||
const std::string expression_str = "newton_sqrt(x)";
|
const std::string expression_str = "newton_sqrt(x)";
|
||||||
|
|
||||||
|
@ -72,16 +74,20 @@ void newton_sqrt()
|
||||||
parser_t parser;
|
parser_t parser;
|
||||||
parser.compile(expression_str,expression);
|
parser.compile(expression_str,expression);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < 100; ++i)
|
for (x = T(0); x < T(500); x += T(0.5))
|
||||||
{
|
{
|
||||||
x = static_cast<T>(i);
|
|
||||||
|
|
||||||
const T result = expression.value();
|
const T result = expression.value();
|
||||||
|
const T real = std::sqrt(x);
|
||||||
|
const T error = std::abs(result - real);
|
||||||
|
|
||||||
printf("sqrt(%03d) - Result: %15.13f\tReal: %15.13f\n",
|
const bool err_in_bound = error <= exprtk::details::numeric::constant::pi;
|
||||||
static_cast<unsigned int>(i),
|
|
||||||
|
printf("sqrt(%6.2f) - Result: %15.13f\tReal: %15.13f\tError: %18.16f EIB: %c\n",
|
||||||
|
x,
|
||||||
result,
|
result,
|
||||||
std::sqrt(x));
|
real,
|
||||||
|
error,
|
||||||
|
err_in_bound ? 'T' : 'F');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 11 *
|
* Simple Example 11 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -31,10 +32,12 @@ void square_wave2()
|
||||||
|
|
||||||
const std::string wave_program =
|
const std::string wave_program =
|
||||||
" var r := 0; "
|
" var r := 0; "
|
||||||
|
" "
|
||||||
" for (var i := 0; i < 1000; i += 1) "
|
" for (var i := 0; i < 1000; i += 1) "
|
||||||
" { "
|
" { "
|
||||||
" r += (1 / (2i + 1)) * sin((4i + 2) * pi * f * t); "
|
" r += (1 / (2i + 1)) * sin((4i + 2) * pi * f * t); "
|
||||||
" }; "
|
" }; "
|
||||||
|
" "
|
||||||
" r *= a * (4 / pi); ";
|
" r *= a * (4 / pi); ";
|
||||||
|
|
||||||
static const T pi = T(3.141592653589793238462643383279502);
|
static const T pi = T(3.141592653589793238462643383279502);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 12 *
|
* Simple Example 12 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,12 +11,12 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "exprtk.hpp"
|
#include "exprtk.hpp"
|
||||||
|
@ -31,24 +31,24 @@ void bubble_sort()
|
||||||
|
|
||||||
const std::string bubblesort_program =
|
const std::string bubblesort_program =
|
||||||
" var upper_bound := v[]; "
|
" var upper_bound := v[]; "
|
||||||
" var swapped := false; "
|
" "
|
||||||
" repeat "
|
" repeat "
|
||||||
" swapped := false; "
|
" var new_upper_bound := 0; "
|
||||||
" for (var i := 0; i < upper_bound; i += 1) "
|
" "
|
||||||
|
" for (var i := 1; i < upper_bound; i += 1) "
|
||||||
" { "
|
" { "
|
||||||
" for (var j := i + 1; j < upper_bound; j += 1) "
|
" if (v[i - 1] > v[i]) "
|
||||||
" { "
|
" { "
|
||||||
" if (v[i] > v[j]) "
|
" v[i - 1] <=> v[i]; "
|
||||||
" { "
|
" new_upper_bound := i; "
|
||||||
" v[i] <=> v[j]; "
|
|
||||||
" swapped := true; "
|
|
||||||
" }; "
|
" }; "
|
||||||
" }; "
|
" }; "
|
||||||
" }; "
|
" "
|
||||||
" upper_bound -= 1; "
|
" upper_bound := new_upper_bound; "
|
||||||
" until (not(swapped) or (upper_bound == 0)); ";
|
" "
|
||||||
|
" until (upper_bound <= 1); ";
|
||||||
|
|
||||||
T v[] = { T(9.9), T(2.2), T(1.1), T(5.5), T(7.7), T(4.4), T(3.3) };
|
T v[] = { T(9.1), T(2.2), T(1.3), T(5.4), T(7.5), T(4.6), T(3.7) };
|
||||||
|
|
||||||
symbol_table_t symbol_table;
|
symbol_table_t symbol_table;
|
||||||
symbol_table.add_vector("v",v);
|
symbol_table.add_vector("v",v);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 13 *
|
* Simple Example 13 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -41,8 +42,8 @@ void savitzky_golay_filter()
|
||||||
" "
|
" "
|
||||||
" if (v_in[] >= weight[]) "
|
" if (v_in[] >= weight[]) "
|
||||||
" { "
|
" { "
|
||||||
" var lower_bound := trunc(weight[] / 2); "
|
" const var lower_bound := trunc(weight[] / 2); "
|
||||||
" var upper_bound := v_in[] - lower_bound; "
|
" const var upper_bound := v_in[] - lower_bound; "
|
||||||
" "
|
" "
|
||||||
" v_out := 0; "
|
" v_out := 0; "
|
||||||
" "
|
" "
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 14 *
|
* Simple Example 14 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 15 *
|
* Simple Example 15 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -30,20 +31,20 @@ void black_scholes_merton_model()
|
||||||
typedef exprtk::parser<T> parser_t;
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
|
||||||
const std::string bsm_model_program =
|
const std::string bsm_model_program =
|
||||||
" var d1 := (log(s / x) + (r + v^2 / 2) * t) / (v * sqrt(t)); "
|
" var d1 := (log(s / k) + (r + v^2 / 2) * t) / (v * sqrt(t)); "
|
||||||
" var d2 := d1 - v * sqrt(t); "
|
" var d2 := d1 - v * sqrt(t); "
|
||||||
" "
|
" "
|
||||||
" if (callput_flag == 'call') "
|
" if (callput_flag == 'call') "
|
||||||
" s * ncdf(d1) - x * e^(-r * t) * ncdf(d2); "
|
" s * ncdf(d1) - k * e^(-r * t) * ncdf(d2); "
|
||||||
" else if (callput_flag == 'put') "
|
" else if (callput_flag == 'put') "
|
||||||
" x * e^(-r * t) * ncdf(-d2) - s * ncdf(-d1); "
|
" k * e^(-r * t) * ncdf(-d2) - s * ncdf(-d1); "
|
||||||
" ";
|
" ";
|
||||||
|
|
||||||
T s = T(60.00); // Stock price
|
T s = T(60.00); // Spot / Stock / Underlying / Base price
|
||||||
T x = T(65.00); // Strike price
|
T k = T(65.00); // Strike price
|
||||||
|
T v = T( 0.30); // Volatility
|
||||||
T t = T( 0.25); // Years to maturity
|
T t = T( 0.25); // Years to maturity
|
||||||
T r = T( 0.08); // Risk free rate
|
T r = T( 0.08); // Risk free rate
|
||||||
T v = T( 0.30); // Volatility
|
|
||||||
|
|
||||||
std::string callput_flag;
|
std::string callput_flag;
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ void black_scholes_merton_model()
|
||||||
|
|
||||||
symbol_table_t symbol_table;
|
symbol_table_t symbol_table;
|
||||||
symbol_table.add_variable("s",s);
|
symbol_table.add_variable("s",s);
|
||||||
symbol_table.add_variable("x",x);
|
symbol_table.add_variable("k",k);
|
||||||
symbol_table.add_variable("t",t);
|
symbol_table.add_variable("t",t);
|
||||||
symbol_table.add_variable("r",r);
|
symbol_table.add_variable("r",r);
|
||||||
symbol_table.add_variable("v",v);
|
symbol_table.add_variable("v",v);
|
||||||
|
@ -64,27 +65,27 @@ void black_scholes_merton_model()
|
||||||
parser_t parser;
|
parser_t parser;
|
||||||
parser.compile(bsm_model_program,expression);
|
parser.compile(bsm_model_program,expression);
|
||||||
|
|
||||||
{
|
|
||||||
callput_flag = "call";
|
callput_flag = "call";
|
||||||
|
|
||||||
const T bsm = expression.value();
|
const T bsm_call_option_price = expression.value();
|
||||||
|
|
||||||
printf("BSM(%s,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f) = %10.6f\n",
|
|
||||||
callput_flag.c_str(),
|
|
||||||
s, x, t, r, v,
|
|
||||||
bsm);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
callput_flag = "put";
|
callput_flag = "put";
|
||||||
|
|
||||||
const T bsm = expression.value();
|
const T bsm_put_option_price = expression.value();
|
||||||
|
|
||||||
printf("BSM(%s,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f) = %10.6f\n",
|
printf("BSM(call, %5.3f, %5.3f, %5.3f, %5.3f, %5.3f) = %10.6f\n",
|
||||||
callput_flag.c_str(),
|
s, k, t, r, v,
|
||||||
s, x, t, r, v,
|
bsm_call_option_price);
|
||||||
bsm);
|
|
||||||
}
|
printf("BSM(put , %5.3f, %5.3f, %5.3f, %5.3f, %5.3f) = %10.6f\n",
|
||||||
|
s, k, t, r, v,
|
||||||
|
bsm_put_option_price);
|
||||||
|
|
||||||
|
const T put_call_parity_diff =
|
||||||
|
(bsm_call_option_price - bsm_put_option_price) -
|
||||||
|
(s - k * std::exp(-r * t));
|
||||||
|
|
||||||
|
printf("Put-Call parity difference: %20.17f\n", put_call_parity_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 16 *
|
* Simple Example 16 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 17 *
|
* Simple Example 17 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -48,8 +49,8 @@ void monte_carlo_pi()
|
||||||
typedef exprtk::parser<T> parser_t;
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
|
||||||
const std::string monte_carlo_pi_program =
|
const std::string monte_carlo_pi_program =
|
||||||
" var experiments[5 * 10^7] := [(rnd_01^2 + rnd_01^2) <= 1]; "
|
" var samples[2 * 10^8] := [(rnd_01^2 + rnd_01^2) <= 1]; "
|
||||||
" 4 * sum(experiments) / experiments[]; ";
|
" 4 * sum(samples) / samples[]; ";
|
||||||
|
|
||||||
rnd_01<T> rnd01;
|
rnd_01<T> rnd01;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 18 *
|
* Simple Example 18 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -39,14 +40,14 @@ void file_io()
|
||||||
" { "
|
" { "
|
||||||
" println('Failed to open file: ' + file_name); "
|
" println('Failed to open file: ' + file_name); "
|
||||||
" return [false]; "
|
" return [false]; "
|
||||||
" } "
|
" }; "
|
||||||
" "
|
" "
|
||||||
" var s := 'Hello world...\n'; "
|
" var s := 'Hello world...\n'; "
|
||||||
" "
|
" "
|
||||||
" for (var i := 0; i < 10; i += 1) "
|
" for (var i := 0; i < 10; i += 1) "
|
||||||
" { "
|
" { "
|
||||||
" write(stream,s); "
|
" write(stream,s); "
|
||||||
" } "
|
" }; "
|
||||||
" "
|
" "
|
||||||
" if (close(stream)) "
|
" if (close(stream)) "
|
||||||
" println('Sucessfully closed file: ' + file_name); "
|
" println('Sucessfully closed file: ' + file_name); "
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* C++ Mathematical Expression Toolkit Library *
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
* *
|
* *
|
||||||
* Simple Example 19 *
|
* Simple Example 19 *
|
||||||
* Author: Arash Partow (1999-2023) *
|
* Author: Arash Partow (1999-2024) *
|
||||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
* *
|
* *
|
||||||
* Copyright notice: *
|
* Copyright notice: *
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
* permitted under the guidelines and in accordance with the *
|
* permitted under the guidelines and in accordance with the *
|
||||||
* most current version of the MIT License. *
|
* most current version of the MIT License. *
|
||||||
* https://www.opensource.org/licenses/MIT *
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
* *
|
* *
|
||||||
**************************************************************
|
**************************************************************
|
||||||
*/
|
*/
|
||||||
|
@ -52,10 +53,11 @@ public:
|
||||||
std::size_t r0 = 0;
|
std::size_t r0 = 0;
|
||||||
std::size_t r1 = v.size() - 1;
|
std::size_t r1 = v.size() - 1;
|
||||||
|
|
||||||
|
using namespace exprtk::rtl::vecops::helper;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(1 == ps_index) &&
|
(1 == ps_index) &&
|
||||||
!exprtk::rtl::vecops::helper::
|
!load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0)
|
||||||
load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0)
|
|
||||||
)
|
)
|
||||||
return T(0);
|
return T(0);
|
||||||
|
|
||||||
|
@ -91,14 +93,14 @@ void vector_randu()
|
||||||
" { "
|
" { "
|
||||||
" println('Failed to generate noise'); "
|
" println('Failed to generate noise'); "
|
||||||
" return [false]; "
|
" return [false]; "
|
||||||
" } "
|
" }; "
|
||||||
" "
|
" "
|
||||||
" var noisy[6] := signal + (noise - 1/2); "
|
" var noisy[noise[]] := signal + (noise - 1/2); "
|
||||||
" "
|
" "
|
||||||
" for (var i := 0; i < noisy[]; i += 1) "
|
" for (var i := 0; i < noisy[]; i += 1) "
|
||||||
" { "
|
" { "
|
||||||
" println('noisy[',i,'] = ', noisy[i]); "
|
" println('noisy[',i,'] = ', noisy[i]); "
|
||||||
" } "
|
" }; "
|
||||||
" "
|
" "
|
||||||
" println('avg: ', avg(noisy)); "
|
" println('avg: ', avg(noisy)); "
|
||||||
" ";
|
" ";
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
**************************************************************
|
||||||
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
|
* *
|
||||||
|
* Simple Example 20 *
|
||||||
|
* Author: Arash Partow (1999-2024) *
|
||||||
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
|
* *
|
||||||
|
* Copyright notice: *
|
||||||
|
* Free use of the Mathematical Expression Toolkit Library is *
|
||||||
|
* permitted under the guidelines and in accordance with the *
|
||||||
|
* most current version of the MIT License. *
|
||||||
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
|
* *
|
||||||
|
**************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
struct vector_access_rtc : public exprtk::vector_access_runtime_check
|
||||||
|
{
|
||||||
|
typedef std::map<void*, std::string> map_t;
|
||||||
|
map_t vector_map;
|
||||||
|
|
||||||
|
bool handle_runtime_violation(violation_context& context)
|
||||||
|
{
|
||||||
|
const map_t::iterator itr = vector_map.find(static_cast<void*>(context.base_ptr));
|
||||||
|
std::string vector_name = (itr != vector_map.end()) ?
|
||||||
|
itr->second : "Unknown" ;
|
||||||
|
|
||||||
|
printf("Runtime vector access violation\n"
|
||||||
|
"Vector: %s base: %p end: %p access: %p typesize: %d\n",
|
||||||
|
vector_name.c_str(),
|
||||||
|
context.base_ptr ,
|
||||||
|
context.end_ptr ,
|
||||||
|
context.access_ptr ,
|
||||||
|
static_cast<unsigned int>(context.type_size));
|
||||||
|
|
||||||
|
throw std::runtime_error
|
||||||
|
("Runtime vector access violation. Vector: " + vector_name);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void vector_overflow_example()
|
||||||
|
{
|
||||||
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
|
typedef exprtk::expression<T> expression_t;
|
||||||
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
|
||||||
|
const std::string expression_str =
|
||||||
|
" for (var i := 0; i < max(v0[],v1[]); i += 1) "
|
||||||
|
" { "
|
||||||
|
" v0[i] := (2 * v0[i]) + (v1[i] / 3); "
|
||||||
|
" } ";
|
||||||
|
|
||||||
|
T v0[5 ] = { 0, 1, 2, 3, 4 };
|
||||||
|
T v1[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||||
|
|
||||||
|
vector_access_rtc vec_rtc;
|
||||||
|
|
||||||
|
vec_rtc.vector_map[v0] = "v0";
|
||||||
|
vec_rtc.vector_map[v1] = "v1";
|
||||||
|
|
||||||
|
symbol_table_t symbol_table;
|
||||||
|
expression_t expression;
|
||||||
|
parser_t parser;
|
||||||
|
|
||||||
|
symbol_table.add_vector("v0", v0);
|
||||||
|
symbol_table.add_vector("v1", v1);
|
||||||
|
|
||||||
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
|
parser.register_vector_access_runtime_check(vec_rtc);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!parser.compile(expression_str, expression))
|
||||||
|
{
|
||||||
|
printf("Error: %s\tExpression: %s\n",
|
||||||
|
parser.error().c_str(),
|
||||||
|
expression_str.c_str());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
expression.value();
|
||||||
|
}
|
||||||
|
catch(std::runtime_error& exception)
|
||||||
|
{
|
||||||
|
printf("Exception: %s\n",exception.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
vector_overflow_example<double>();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
/*
|
||||||
|
**************************************************************
|
||||||
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
|
* *
|
||||||
|
* Simple Example 21 *
|
||||||
|
* Author: Arash Partow (1999-2024) *
|
||||||
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
|
* *
|
||||||
|
* Copyright notice: *
|
||||||
|
* Free use of the Mathematical Expression Toolkit Library is *
|
||||||
|
* permitted under the guidelines and in accordance with the *
|
||||||
|
* most current version of the MIT License. *
|
||||||
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
|
* *
|
||||||
|
**************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void binomial_option_pricing_model()
|
||||||
|
{
|
||||||
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
|
typedef exprtk::expression<T> expression_t;
|
||||||
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
|
||||||
|
const std::string european_option_binomial_model_program =
|
||||||
|
" var dt := t / n; "
|
||||||
|
" var z := exp(r * dt); "
|
||||||
|
" var z_inv := 1 / z; "
|
||||||
|
" var u := exp(v * sqrt(dt)); "
|
||||||
|
" var u_inv := 1 / u; "
|
||||||
|
" var p_up := (z - u_inv) / (u - u_inv); "
|
||||||
|
" var p_down := 1 - p_up; "
|
||||||
|
" "
|
||||||
|
" var option_price[n + 1] := [0]; "
|
||||||
|
" "
|
||||||
|
" for (var i := 0; i <= n; i += 1) "
|
||||||
|
" { "
|
||||||
|
" var base_price := s * u^(n - 2i); "
|
||||||
|
" option_price[i] := "
|
||||||
|
" switch "
|
||||||
|
" { "
|
||||||
|
" case callput_flag == 'call' : max(base_price - k, 0); "
|
||||||
|
" case callput_flag == 'put' : max(k - base_price, 0); "
|
||||||
|
" }; "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" for (var j := n - 1; j >= 0; j -= 1) "
|
||||||
|
" { "
|
||||||
|
" for (var i := 0; i <= j; i += 1) "
|
||||||
|
" { "
|
||||||
|
" option_price[i] := z_inv * "
|
||||||
|
" (p_up * option_price[i] + p_down * option_price[i + 1]); "
|
||||||
|
" } "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" option_price[0]; ";
|
||||||
|
|
||||||
|
T s = T( 100.00); // Spot / Stock / Underlying / Base price
|
||||||
|
T k = T( 110.00); // Strike price
|
||||||
|
T v = T( 0.30); // Volatility
|
||||||
|
T t = T( 2.22); // Years to maturity
|
||||||
|
T r = T( 0.05); // Risk free rate
|
||||||
|
T n = T(1000.00); // Number of time steps
|
||||||
|
|
||||||
|
std::string callput_flag;
|
||||||
|
|
||||||
|
symbol_table_t symbol_table;
|
||||||
|
symbol_table.add_variable("s",s);
|
||||||
|
symbol_table.add_variable("k",k);
|
||||||
|
symbol_table.add_variable("t",t);
|
||||||
|
symbol_table.add_variable("r",r);
|
||||||
|
symbol_table.add_variable("v",v);
|
||||||
|
symbol_table.add_constant("n",n);
|
||||||
|
symbol_table.add_stringvar("callput_flag",callput_flag);
|
||||||
|
|
||||||
|
expression_t expression;
|
||||||
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
|
parser_t parser;
|
||||||
|
parser.compile(european_option_binomial_model_program,expression);
|
||||||
|
|
||||||
|
callput_flag = "call";
|
||||||
|
|
||||||
|
const T binomial_call_option_price = expression.value();
|
||||||
|
|
||||||
|
callput_flag = "put";
|
||||||
|
|
||||||
|
const T binomial_put_option_price = expression.value();
|
||||||
|
|
||||||
|
printf("BinomialPrice(call, %5.3f, %5.3f, %5.3f, %5.3f, %5.3f) = %10.6f\n",
|
||||||
|
s, k, t, r, v,
|
||||||
|
binomial_call_option_price);
|
||||||
|
|
||||||
|
printf("BinomialPrice(put , %5.3f, %5.3f, %5.3f, %5.3f, %5.3f) = %10.6f\n",
|
||||||
|
s, k, t, r, v,
|
||||||
|
binomial_put_option_price);
|
||||||
|
|
||||||
|
const T put_call_parity_diff =
|
||||||
|
(binomial_call_option_price - binomial_put_option_price) -
|
||||||
|
(s - k * std::exp(-r * t));
|
||||||
|
|
||||||
|
printf("Put-Call parity difference: %20.17f\n", put_call_parity_diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
binomial_option_pricing_model<double>();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
**************************************************************
|
||||||
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
|
* *
|
||||||
|
* Simple Example 22 *
|
||||||
|
* Author: Arash Partow (1999-2024) *
|
||||||
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
|
* *
|
||||||
|
* Copyright notice: *
|
||||||
|
* Free use of the Mathematical Expression Toolkit Library is *
|
||||||
|
* permitted under the guidelines and in accordance with the *
|
||||||
|
* most current version of the MIT License. *
|
||||||
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
|
* *
|
||||||
|
**************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void compute_option_implied_volatility()
|
||||||
|
{
|
||||||
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
|
typedef exprtk::expression<T> expression_t;
|
||||||
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
typedef exprtk::function_compositor<T> compositor_t;
|
||||||
|
typedef typename compositor_t::function function_t;
|
||||||
|
|
||||||
|
const std::string option_implied_volatility_program =
|
||||||
|
" const var epsilon := 0.0000001; "
|
||||||
|
" const var max_iters := 1000; "
|
||||||
|
" "
|
||||||
|
" var v := 0.5; /* Initial volatility guess */ "
|
||||||
|
" var itr := 0; "
|
||||||
|
" "
|
||||||
|
" while ((itr += 1) <= max_iters) "
|
||||||
|
" { "
|
||||||
|
" var price := "
|
||||||
|
" switch "
|
||||||
|
" { "
|
||||||
|
" case callput_flag == 'call' : bsm_call(s, k, r, t, v); "
|
||||||
|
" case callput_flag == 'put' : bsm_put (s, k, r, t, v); "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" var price_diff := price - target_price; "
|
||||||
|
" "
|
||||||
|
" if (abs(price_diff) <= epsilon) "
|
||||||
|
" { "
|
||||||
|
" break; "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" var vega := bsm_vega(s, k, r, t, v); "
|
||||||
|
" "
|
||||||
|
" if (vega < epsilon) "
|
||||||
|
" { "
|
||||||
|
" itr := max_iters + 1; "
|
||||||
|
" break; "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" v -= price_diff / vega; "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" itr <= max_iters ? v : null; ";
|
||||||
|
|
||||||
|
T s = T(100.00); // Spot / Stock / Underlying / Base price
|
||||||
|
T k = T(110.00); // Strike price
|
||||||
|
T t = T( 2.22); // Years to maturity
|
||||||
|
T r = T( 0.05); // Risk free rate
|
||||||
|
T target_price = T( 0.00);
|
||||||
|
|
||||||
|
std::string callput_flag;
|
||||||
|
|
||||||
|
symbol_table_t symbol_table(symbol_table_t::e_immutable);
|
||||||
|
symbol_table.add_variable("s",s);
|
||||||
|
symbol_table.add_variable("k",k);
|
||||||
|
symbol_table.add_variable("t",t);
|
||||||
|
symbol_table.add_variable("r",r);
|
||||||
|
symbol_table.add_stringvar("callput_flag",callput_flag);
|
||||||
|
symbol_table.add_variable ("target_price",target_price);
|
||||||
|
symbol_table.add_pi();
|
||||||
|
|
||||||
|
compositor_t compositor(symbol_table);
|
||||||
|
|
||||||
|
compositor.add(
|
||||||
|
function_t("bsm_call")
|
||||||
|
.vars("s", "k", "r", "t", "v")
|
||||||
|
.expression
|
||||||
|
(
|
||||||
|
" var d1 := (log(s / k) + (r + v^2 / 2) * t) / (v * sqrt(t)); "
|
||||||
|
" var d2 := d1 - v * sqrt(t); "
|
||||||
|
" s * ncdf(d1) - k * exp(-r * t) * ncdf(d2); "
|
||||||
|
));
|
||||||
|
|
||||||
|
compositor.add(
|
||||||
|
function_t("bsm_put")
|
||||||
|
.vars("s", "k", "r", "t", "v")
|
||||||
|
.expression
|
||||||
|
(
|
||||||
|
" var d1 := (log(s / k) + (r + v^2 / 2) * t) / (v * sqrt(t)); "
|
||||||
|
" var d2 := d1 - v * sqrt(t); "
|
||||||
|
" k * exp(-r * t) * ncdf(-d2) - s * ncdf(-d1); "
|
||||||
|
));
|
||||||
|
|
||||||
|
compositor.add(
|
||||||
|
function_t("bsm_vega")
|
||||||
|
.vars("s", "k", "r", "t", "v")
|
||||||
|
.expression
|
||||||
|
(
|
||||||
|
" var d1 := (log(s / k) + (r + v^2 / 2) * t) / (v * sqrt(t)); "
|
||||||
|
" s * sqrt(t) * exp(-d1^2 / 2) / sqrt(2pi); "
|
||||||
|
));
|
||||||
|
|
||||||
|
expression_t expression;
|
||||||
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
|
parser_t parser;
|
||||||
|
parser.compile(option_implied_volatility_program, expression);
|
||||||
|
|
||||||
|
{
|
||||||
|
callput_flag = "call";
|
||||||
|
target_price = T(18.339502);
|
||||||
|
|
||||||
|
const T option_implied_vol = expression.value();
|
||||||
|
|
||||||
|
printf("Call Option(s: %5.3f, k: %5.3f, t: %5.3f, r: %5.3f) "
|
||||||
|
"@ $%8.6f Implied volatility = %10.8f\n",
|
||||||
|
s, k, t, r, target_price, option_implied_vol);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
callput_flag = "put";
|
||||||
|
target_price = T(16.782764);
|
||||||
|
|
||||||
|
const T option_implied_vol = expression.value();
|
||||||
|
|
||||||
|
printf("Put Option(s: %5.3f, k: %5.3f, t: %5.3f, r: %5.3f) "
|
||||||
|
"@ $%8.6f Implied volatility = %10.8f\n",
|
||||||
|
s, k, t, r, target_price, option_implied_vol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
compute_option_implied_volatility<double>();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,136 @@
|
||||||
|
/*
|
||||||
|
**************************************************************
|
||||||
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
|
* *
|
||||||
|
* Simple Example 23 *
|
||||||
|
* Author: Arash Partow (1999-2024) *
|
||||||
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
|
* *
|
||||||
|
* Copyright notice: *
|
||||||
|
* Free use of the Mathematical Expression Toolkit Library is *
|
||||||
|
* permitted under the guidelines and in accordance with the *
|
||||||
|
* most current version of the MIT License. *
|
||||||
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
|
* *
|
||||||
|
**************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void real_1d_discrete_fourier_transform()
|
||||||
|
{
|
||||||
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
|
typedef exprtk::expression<T> expression_t;
|
||||||
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
typedef exprtk::function_compositor<T> compositor_t;
|
||||||
|
typedef typename compositor_t::function function_t;
|
||||||
|
|
||||||
|
const T sampling_rate = 1024.0; // ~1KHz
|
||||||
|
const T N = 8 * sampling_rate; // 8 seconds worth of samples
|
||||||
|
|
||||||
|
std::vector<T> input (static_cast<std::size_t>(N),0.0);
|
||||||
|
std::vector<T> output(static_cast<std::size_t>(N),0.0);
|
||||||
|
|
||||||
|
exprtk::rtl::io::println<T> println;
|
||||||
|
|
||||||
|
symbol_table_t symbol_table;
|
||||||
|
symbol_table.add_vector ("input" , input );
|
||||||
|
symbol_table.add_vector ("output" , output );
|
||||||
|
symbol_table.add_function ("println" , println );
|
||||||
|
symbol_table.add_constant ("N" , N );
|
||||||
|
symbol_table.add_constant ("sampling_rate", sampling_rate);
|
||||||
|
symbol_table.add_pi();
|
||||||
|
|
||||||
|
compositor_t compositor(symbol_table);
|
||||||
|
compositor.load_vectors(true);
|
||||||
|
|
||||||
|
compositor.add(
|
||||||
|
function_t("dft_1d_real")
|
||||||
|
.var("N")
|
||||||
|
.expression
|
||||||
|
(
|
||||||
|
" for (var k := 0; k < N; k += 1) "
|
||||||
|
" { "
|
||||||
|
" var k_real := 0.0; "
|
||||||
|
" var k_imag := 0.0; "
|
||||||
|
" "
|
||||||
|
" for (var i := 0; i < N; i += 1) "
|
||||||
|
" { "
|
||||||
|
" var theta := 2pi * k * i / N; "
|
||||||
|
" k_real += input[i] * cos(theta); "
|
||||||
|
" k_imag -= input[i] * sin(theta); "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" output[k] := hypot(k_real,k_imag); "
|
||||||
|
" } "
|
||||||
|
));
|
||||||
|
|
||||||
|
const std::string dft_program =
|
||||||
|
" "
|
||||||
|
" /* "
|
||||||
|
" Generate an aggregate waveform comprised of three "
|
||||||
|
" sine waves of varying frequencies and amplitudes. "
|
||||||
|
" */ "
|
||||||
|
" var frequencies[3] := { 100.0, 200.0, 300.0 }; /* Hz */ "
|
||||||
|
" var amplitudes [3] := { 10.0, 20.0, 30.0 }; /* Power */ "
|
||||||
|
" "
|
||||||
|
" for (var i := 0; i < N; i += 1) "
|
||||||
|
" { "
|
||||||
|
" var time := i / sampling_rate; "
|
||||||
|
" "
|
||||||
|
" for (var j := 0; j < frequencies[]; j += 1) "
|
||||||
|
" { "
|
||||||
|
" var frequency := frequencies[j]; "
|
||||||
|
" var amplitude := amplitudes [j]; "
|
||||||
|
" var theta := 2 * pi * frequency * time; "
|
||||||
|
" "
|
||||||
|
" input[i] += amplitude * sin(theta); "
|
||||||
|
" } "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" dft_1d_real(input[]); "
|
||||||
|
" "
|
||||||
|
" var freq_bin_size := sampling_rate / N; "
|
||||||
|
" var max_bin := ceil(N / 2); "
|
||||||
|
" var max_noise_level := 1e-5; "
|
||||||
|
" "
|
||||||
|
" /* Normalise amplitudes */ "
|
||||||
|
" output /= max_bin; "
|
||||||
|
" "
|
||||||
|
" println('1D Real DFT Frequencies'); "
|
||||||
|
" "
|
||||||
|
" for (var k := 0; k < max_bin; k += 1) "
|
||||||
|
" { "
|
||||||
|
" if (output[k] > max_noise_level) "
|
||||||
|
" { "
|
||||||
|
" var freq_begin := k * freq_bin_size; "
|
||||||
|
" var freq_end := freq_begin + freq_bin_size; "
|
||||||
|
" "
|
||||||
|
" println('Index: ', k,' ', "
|
||||||
|
" 'Freq. range: [', freq_begin, 'Hz, ', freq_end, 'Hz) ', "
|
||||||
|
" 'Amplitude: ', output[k]); "
|
||||||
|
" } "
|
||||||
|
" } "
|
||||||
|
" ";
|
||||||
|
|
||||||
|
expression_t expression;
|
||||||
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
|
parser_t parser;
|
||||||
|
parser.compile(dft_program,expression);
|
||||||
|
|
||||||
|
expression.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
real_1d_discrete_fourier_transform<double>();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
**************************************************************
|
||||||
|
* C++ Mathematical Expression Toolkit Library *
|
||||||
|
* *
|
||||||
|
* Simple Example 24 *
|
||||||
|
* Author: Arash Partow (1999-2024) *
|
||||||
|
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||||
|
* *
|
||||||
|
* Copyright notice: *
|
||||||
|
* Free use of the Mathematical Expression Toolkit Library is *
|
||||||
|
* permitted under the guidelines and in accordance with the *
|
||||||
|
* most current version of the MIT License. *
|
||||||
|
* https://www.opensource.org/licenses/MIT *
|
||||||
|
* SPDX-License-Identifier: MIT *
|
||||||
|
* *
|
||||||
|
**************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "exprtk.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, T Process(const unsigned char)>
|
||||||
|
struct char_process : public exprtk::igeneric_function<T>
|
||||||
|
{
|
||||||
|
typedef typename exprtk::igeneric_function<T> igfun_t;
|
||||||
|
typedef typename igfun_t::parameter_list_t parameter_list_t;
|
||||||
|
typedef typename igfun_t::generic_type generic_type;
|
||||||
|
typedef typename generic_type::string_view string_t;
|
||||||
|
|
||||||
|
using exprtk::igeneric_function<T>::operator();
|
||||||
|
|
||||||
|
char_process()
|
||||||
|
: exprtk::igeneric_function<T>("S")
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline T operator()(parameter_list_t parameters)
|
||||||
|
{
|
||||||
|
const unsigned char c = string_t(parameters[0])[0];
|
||||||
|
return Process(c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T is_digit_func(const unsigned char c)
|
||||||
|
{
|
||||||
|
return (('0' <= c) && (c <= '9')) ? T(1) : T(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T to_num_func(const unsigned char c)
|
||||||
|
{
|
||||||
|
return static_cast<T>(c - '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void rpn_example()
|
||||||
|
{
|
||||||
|
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||||
|
typedef exprtk::expression<T> expression_t;
|
||||||
|
typedef exprtk::parser<T> parser_t;
|
||||||
|
|
||||||
|
const std::string rpn_program =
|
||||||
|
" var stack[1000] := [0]; "
|
||||||
|
" var top_index := 0; "
|
||||||
|
" "
|
||||||
|
" for (var i := 0; i < rpn_expression[]; i += 1) "
|
||||||
|
" { "
|
||||||
|
" var c := rpn_expression[i : i + 1]; "
|
||||||
|
" "
|
||||||
|
" if (c == ' ') "
|
||||||
|
" { "
|
||||||
|
" continue; "
|
||||||
|
" } "
|
||||||
|
" else if (is_digit(c)) "
|
||||||
|
" { "
|
||||||
|
" stack[top_index] := to_num(c); "
|
||||||
|
" top_index += 1; "
|
||||||
|
" } "
|
||||||
|
" else "
|
||||||
|
" { "
|
||||||
|
" var operator := c; "
|
||||||
|
" var operand1 := stack[top_index - 2]; "
|
||||||
|
" var operand2 := stack[top_index - 1]; "
|
||||||
|
" top_index -= 2; "
|
||||||
|
" "
|
||||||
|
" switch "
|
||||||
|
" { "
|
||||||
|
" case operator == '+' : stack[top_index] := operand1 + operand2; "
|
||||||
|
" case operator == '-' : stack[top_index] := operand1 - operand2; "
|
||||||
|
" case operator == '*' : stack[top_index] := operand1 * operand2; "
|
||||||
|
" case operator == '/' : stack[top_index] := operand1 / operand2; "
|
||||||
|
" case operator == '^' : stack[top_index] := operand1 ^ operand2; "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" top_index += 1; "
|
||||||
|
" } "
|
||||||
|
" }; "
|
||||||
|
" "
|
||||||
|
" println(stack[0], ' = ', rpn_expression); "
|
||||||
|
" ";
|
||||||
|
|
||||||
|
std::string rpn_expression;
|
||||||
|
|
||||||
|
char_process<T,is_digit_func<T> > isdigit;
|
||||||
|
char_process<T,to_num_func<T> > tonum;
|
||||||
|
exprtk::rtl::io::println<T> println;
|
||||||
|
|
||||||
|
symbol_table_t symbol_table;
|
||||||
|
symbol_table.add_stringvar("rpn_expression", rpn_expression);
|
||||||
|
symbol_table.add_function ("println" , println );
|
||||||
|
symbol_table.add_function ("is_digit" , isdigit );
|
||||||
|
symbol_table.add_function ("to_num" , tonum );
|
||||||
|
|
||||||
|
expression_t expression;
|
||||||
|
expression.register_symbol_table(symbol_table);
|
||||||
|
|
||||||
|
parser_t parser;
|
||||||
|
parser.compile(rpn_program, expression);
|
||||||
|
|
||||||
|
const std::string rpn_expressions[] =
|
||||||
|
{
|
||||||
|
"2 3 8 / ^ 4 6 * + 3 9 / -", // 2 ^ (3 / 8) + 4 * 6 - 3 / 9
|
||||||
|
"1 2 / 6 5 2 - / * 7 +" , // (1 / 2) * (6 / (5 - 2)) + 7
|
||||||
|
"1 2 * 3 / 4 * 5 / 6 *" , // ((((1 * 2) / 3) * 4) / 5) * 6
|
||||||
|
"8 6 4 + * 2 /" // (8 * (6 + 4)) / 2
|
||||||
|
};
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < sizeof(rpn_expressions) / sizeof(std::string); ++i)
|
||||||
|
{
|
||||||
|
rpn_expression = rpn_expressions[i];
|
||||||
|
expression.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
rpn_example<double>();
|
||||||
|
return 0;
|
||||||
|
}
|
4590
exprtk_test.cpp
4590
exprtk_test.cpp
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,24 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 1999-2024 Arash Partow
|
||||||
|
|
||||||
|
https://www.partow.net/programming/exprtk/index.html
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
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 AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2035
readme.txt
2035
readme.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue