Skip to content

Commit

Permalink
Fix error in sympy bridge when acting on sub- or super-scripted expre…
Browse files Browse the repository at this point in the history
…ssions.
  • Loading branch information
Kasper Peeters committed Oct 2, 2024
1 parent 1b48cd3 commit d00706b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

name: Docker

on: [push]
# on: [push]

# on:
# release:
# types: [created]
on:
release:
types: [created]

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions core/SympyCdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ Ex::iterator sympy::apply(const Kernel& kernel, Ex& ex, Ex::iterator& it, const
std::cerr << "reparsed " << first.node << "\n" << Ex(first) << std::endl;
std::cerr << "before " << it.node << "\n" << Ex(it) << std::endl;
#endif
str_node::parent_rel_t pr = it->fl.parent_rel;
it = ex.move_ontop(it, first);
it->fl.parent_rel = pr;
#ifdef DEBUG
std::cerr << "after " << Ex(it) << std::endl;
std::cerr << "top node " << it.node << std::endl;
Expand Down
36 changes: 36 additions & 0 deletions tests/sympy_cdb.cdb
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,39 @@ def test05():

test05()

def test06():
# When acting on a super- or sub-script expression,
# make sure that this parent_rel is not dropped.
__cdbkernel__=create_scope()
{r,\theta}::Coordinate.
\partial{#}::PartialDerivative.
# Evaluate works, but that looks explicity at
# both sides separately and calls simplify on
# it without 'deep=True'.
ex:= \partial_{r}{\theta};
evaluate(ex, $$)
assert(ex==0)
print("Test 06a passed")
# When using 'deep=True', simplify gets called
# on the sub-script, and we need to be careful
# not to turn this into '\partial{r}{\theta}',
# as that is meaningless in sympy.
ex:= \partial_{r}{\theta};
simplify(ex, deep=True)
assert(ex==0)
print("Test 06b passed")

test06()

def test07():
__cdbkernel__=create_scope()
{r,\theta}::Coordinate.
\partial{#}::PartialDerivative.
f::Depends(r).
ex:= \partial_{r}{3 f};
simplify(ex, deep=True)
tst:= 3 \partial_{r}{f} - @(ex);
assert(tst==0)
print("Test 07 passed")

test07()

0 comments on commit d00706b

Please sign in to comment.