Skip to content

Commit 4fba9a6

Browse files
authored
Tentative fix of .has for FunctionSymbol (symengine#446)
* Tentative fix of .has for FunctionSymbol * SymEngine supports FunctionSymbol in has_symbol
1 parent b7e2cc2 commit 4fba9a6

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 2.8.12)
33
if (POLICY CMP0057)
44
cmake_policy(SET CMP0057 NEW) # needed for llvm >= 16
55
endif ()
6+
if (POLICY CMP0074)
7+
cmake_policy(SET CMP0074 NEW) # allow user to set *_ROOT variables
8+
endif()
69

710
project(python_wrapper)
811

symengine/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Gt, Lt, And, Or, Not, Nand, Nor, Xor, Xnor, perfect_power, integer_nthroot,
2727
isprime, sqrt_mod, Expr, cse, count_ops, ccode, Piecewise, Contains, Interval, FiniteSet,
2828
linsolve,
29-
FunctionSymbol as AppliedUndef,
29+
FunctionSymbol,
3030
golden_ratio as GoldenRatio,
3131
catalan as Catalan,
3232
eulergamma as EulerGamma,
@@ -37,6 +37,7 @@
3737
from .printing import init_printing
3838

3939

40+
AppliedUndef = FunctionSymbol # an alias
4041
EmptySet = wrapper.S.EmptySet
4142
UniversalSet = wrapper.S.UniversalSet
4243
Reals = wrapper.S.Reals

symengine/lib/symengine.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ cdef extern from "<symengine/prime_sieve.h>" namespace "SymEngine":
930930
unsigned next_prime() nogil
931931

932932
cdef extern from "<symengine/visitor.h>" namespace "SymEngine":
933-
bool has_symbol(const Basic &b, const Symbol &x) nogil except +
933+
bool has_symbol(const Basic &b, const Basic &x) nogil except +
934934
rcp_const_basic coeff(const Basic &b, const Basic &x, const Basic &n) nogil except +
935935
set_basic free_symbols(const Basic &b) nogil except +
936936
set_basic free_symbols(const MatrixBase &b) nogil except +

symengine/lib/symengine_wrapper.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,12 +4846,11 @@ def powermod_list(a, b, m):
48464846
def has_symbol(obj, symbol=None):
48474847
cdef Basic b = _sympify(obj)
48484848
cdef Basic s = _sympify(symbol)
4849-
require(s, Symbol)
4849+
require(s, (Symbol, FunctionSymbol))
48504850
if (not symbol):
48514851
return not b.free_symbols.empty()
48524852
else:
4853-
return symengine.has_symbol(deref(b.thisptr),
4854-
deref(symengine.rcp_static_cast_Symbol(s.thisptr)))
4853+
return symengine.has_symbol(deref(b.thisptr), deref(s.thisptr))
48554854

48564855

48574856
cdef class _Lambdify(object):

symengine/tests/test_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_derivative():
8585
assert s.variables == (x,)
8686

8787
fxy = Function("f")(x, y)
88+
assert (1+fxy).has(fxy)
8889
g = Derivative(Function("f")(x, y), x, 2, y, 1)
8990
assert g == fxy.diff(x, x, y)
9091
assert g == fxy.diff(y, 1, x, 2)

0 commit comments

Comments
 (0)