From ddba11b87021209c64c1e3a6b21035ef807db16d Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Fri, 29 Sep 2023 21:20:36 +0530 Subject: [PATCH 1/4] Exposed some query methods --- symengine/cwrapper.cpp | 20 ++++++++++++++++++++ symengine/cwrapper.h | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/symengine/cwrapper.cpp b/symengine/cwrapper.cpp index 8e9261faaa..0e3c4cb38d 100644 --- a/symengine/cwrapper.cpp +++ b/symengine/cwrapper.cpp @@ -286,6 +286,26 @@ int basic_has_symbol(const basic e, const basic s) return (int)(has_symbol(*(e->m), *(s->m))); } +int basic_is_Add(const basic s) +{ + return basic_get_type(s) == SYMENGINE_ADD ? 1 : 0; +} + +int basic_is_Mul(const basic s) +{ + return basic_get_type(s) == SYMENGINE_MUL ? 1 : 0; +} + +int basic_is_Pow(const basic s) +{ + return basic_get_type(s) == SYMENGINE_POW ? 1 : 0; +} + +int basic_is_Log(const basic s) +{ + return basic_get_type(s) == SYMENGINE_LOG ? 1 : 0; +} + CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i) { CWRAPPER_BEGIN diff --git a/symengine/cwrapper.h b/symengine/cwrapper.h index 37c0b907a7..9a29f24776 100644 --- a/symengine/cwrapper.h +++ b/symengine/cwrapper.h @@ -170,6 +170,14 @@ int number_is_complex(const basic s); //! Returns 1 if `e` contains the symbol `s`; 0 otherwise int basic_has_symbol(const basic e, const basic s); +//! Returns 1 if `s` is of type Add; 0 otherwise +int basic_is_Add(const basic s); +//! Returns 1 if `s` is of type Mul; 0 otherwise +int basic_is_Mul(const basic s); +//! Returns 1 if `s` is of type Pow; 0 otherwise +int basic_is_Pow(const basic s); +//! Returns 1 if `s` is of type Log; 0 otherwise +int basic_is_Log(const basic s); //! Assign to s, a long. CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i); From 7f910c3c22df7e2659f26405f90d91a13b035ebf Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sat, 30 Sep 2023 16:54:49 +0530 Subject: [PATCH 2/4] added support for basic_is_exp --- symengine/cwrapper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/symengine/cwrapper.cpp b/symengine/cwrapper.cpp index 0e3c4cb38d..dd87f5b508 100644 --- a/symengine/cwrapper.cpp +++ b/symengine/cwrapper.cpp @@ -306,6 +306,12 @@ int basic_is_Log(const basic s) return basic_get_type(s) == SYMENGINE_LOG ? 1 : 0; } +int basic_is_Exp(const basic s) +{ + SYMENGINE_ASSERT(basic_is_Pow(s) == 1); + return (down_cast(*(s->m))).get_exp() == SymEngine::E ? 1 : 0; +} + CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i) { CWRAPPER_BEGIN From e534b4868f2a7cc3b8c8dfb09a143eee8bfc1e94 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sat, 30 Sep 2023 17:13:00 +0530 Subject: [PATCH 3/4] Added tests --- symengine/cwrapper.cpp | 3 ++- symengine/cwrapper.h | 2 ++ symengine/tests/cwrapper/test_cwrapper.c | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/symengine/cwrapper.cpp b/symengine/cwrapper.cpp index dd87f5b508..837bd1fb4d 100644 --- a/symengine/cwrapper.cpp +++ b/symengine/cwrapper.cpp @@ -28,6 +28,7 @@ using SymEngine::ComplexDouble; using SymEngine::CSRMatrix; using SymEngine::DenseMatrix; using SymEngine::down_cast; +using SymEngine::E; using SymEngine::function_symbol; using SymEngine::FunctionSymbol; using SymEngine::has_symbol; @@ -309,7 +310,7 @@ int basic_is_Log(const basic s) int basic_is_Exp(const basic s) { SYMENGINE_ASSERT(basic_is_Pow(s) == 1); - return (down_cast(*(s->m))).get_exp() == SymEngine::E ? 1 : 0; + return (down_cast(*(s->m))).get_exp() == E ? 1 : 0; } CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i) diff --git a/symengine/cwrapper.h b/symengine/cwrapper.h index 9a29f24776..f1bf1f2732 100644 --- a/symengine/cwrapper.h +++ b/symengine/cwrapper.h @@ -178,6 +178,8 @@ int basic_is_Mul(const basic s); int basic_is_Pow(const basic s); //! Returns 1 if `s` is of type Log; 0 otherwise int basic_is_Log(const basic s); +//! Returns 1 if `s` is of type Exp; 0 otherwise +int basic_is_Exp(const basic s); //! Assign to s, a long. CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i); diff --git a/symengine/tests/cwrapper/test_cwrapper.c b/symengine/tests/cwrapper/test_cwrapper.c index f16e4a3996..20ee2d22d4 100644 --- a/symengine/tests/cwrapper/test_cwrapper.c +++ b/symengine/tests/cwrapper/test_cwrapper.c @@ -59,10 +59,12 @@ void test_cwrapper() SYMENGINE_C_ASSERT(basic_has_symbol(e, y) == 0); SYMENGINE_C_ASSERT(basic_has_symbol(e, z) == 0); basic_add(e, e, x); + SYMENGINE_C_ASSERT(basic_is_Add(e) == 1); SYMENGINE_C_ASSERT(basic_has_symbol(e, x) == 1); SYMENGINE_C_ASSERT(basic_has_symbol(e, y) == 0); SYMENGINE_C_ASSERT(basic_has_symbol(e, z) == 0); basic_mul(e, e, y); + SYMENGINE_C_ASSERT(basic_is_Mul(e) == 1); SYMENGINE_C_ASSERT(basic_has_symbol(e, x) == 1); SYMENGINE_C_ASSERT(basic_has_symbol(e, y) == 1); SYMENGINE_C_ASSERT(basic_has_symbol(e, z) == 0); @@ -102,7 +104,9 @@ void test_cwrapper() integer_set_ui(e, 123); basic_sqrt(e, e); + SYMENGINE_C_ASSERT(basic_is_Pow(e) == 1); basic_exp(e, e); + SYMENGINE_C_ASSERT(basic_is_Exp(e) == 1); s = basic_str(e); SYMENGINE_C_ASSERT(strcmp(s, "exp(sqrt(123))") == 0); @@ -1389,6 +1393,7 @@ void test_functions() integer_set_ui(res, 2); basic_log(res, res); + SYMENGINE_C_ASSERT(basic_is_Log(res) == 1); SYMENGINE_C_ASSERT(basic_eq(res, ans)); real_double_set_d(res, 1.1); From e2d5d13d259b746417fc0a053af3ecc5ce60a591 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Tue, 3 Oct 2023 12:56:10 +0530 Subject: [PATCH 4/4] made requested changes --- symengine/cwrapper.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/symengine/cwrapper.cpp b/symengine/cwrapper.cpp index 837bd1fb4d..facab7cacb 100644 --- a/symengine/cwrapper.cpp +++ b/symengine/cwrapper.cpp @@ -289,28 +289,29 @@ int basic_has_symbol(const basic e, const basic s) int basic_is_Add(const basic s) { - return basic_get_type(s) == SYMENGINE_ADD ? 1 : 0; + return basic_get_type(s) == SYMENGINE_ADD; } int basic_is_Mul(const basic s) { - return basic_get_type(s) == SYMENGINE_MUL ? 1 : 0; + return basic_get_type(s) == SYMENGINE_MUL; } int basic_is_Pow(const basic s) { - return basic_get_type(s) == SYMENGINE_POW ? 1 : 0; + return basic_get_type(s) == SYMENGINE_POW; } int basic_is_Log(const basic s) { - return basic_get_type(s) == SYMENGINE_LOG ? 1 : 0; + return basic_get_type(s) == SYMENGINE_LOG; } int basic_is_Exp(const basic s) { SYMENGINE_ASSERT(basic_is_Pow(s) == 1); - return (down_cast(*(s->m))).get_exp() == E ? 1 : 0; + auto args = s->m->get_args(); + return args[1] == E; } CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i)