Skip to content

Commit

Permalink
Exposing the has_symbol function through cwrapper.h (#1978)
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Sep 27, 2023
1 parent 6da98cf commit a3867fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions symengine/cwrapper.cpp
Expand Up @@ -30,6 +30,7 @@ using SymEngine::DenseMatrix;
using SymEngine::down_cast;
using SymEngine::function_symbol;
using SymEngine::FunctionSymbol;
using SymEngine::has_symbol;
using SymEngine::Integer;
using SymEngine::integer_class;
using SymEngine::LambdaRealDoubleVisitor;
Expand Down Expand Up @@ -280,6 +281,11 @@ int number_is_complex(const basic s)
return (int)((down_cast<const Number &>(*(s->m))).is_complex());
}

int basic_has_symbol(const basic e, const basic s)
{
return (int)(has_symbol(*(e->m), *(s->m)));
}

CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i)
{
CWRAPPER_BEGIN
Expand Down
3 changes: 3 additions & 0 deletions symengine/cwrapper.h
Expand Up @@ -168,6 +168,9 @@ int number_is_positive(const basic s);
//! Returns 1 if s is complex; 0 otherwise
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);

//! Assign to s, a long.
CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i);
//! Assign to s, a ulong.
Expand Down
12 changes: 12 additions & 0 deletions symengine/tests/cwrapper/test_cwrapper.c
Expand Up @@ -55,9 +55,21 @@ void test_cwrapper()
basic_str_free(s);

integer_set_ui(e, 456);
SYMENGINE_C_ASSERT(basic_has_symbol(e, x) == 0);
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_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_has_symbol(e, x) == 1);
SYMENGINE_C_ASSERT(basic_has_symbol(e, y) == 1);
SYMENGINE_C_ASSERT(basic_has_symbol(e, z) == 0);
basic_div(e, e, z);
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) == 1);
s = basic_str(e);
SYMENGINE_C_ASSERT(strcmp(s, "y*(456 + x)/z") == 0);
basic_str_free(s);
Expand Down

0 comments on commit a3867fc

Please sign in to comment.