Skip to content

Commit

Permalink
Merge pull request lcompilers#2488 from anutosh491/symbolic_compare
Browse files Browse the repository at this point in the history
Fixing symbolic compare for test_gruntz.py
  • Loading branch information
certik authored Feb 8, 2024
2 parents 6285062 + 59599c4 commit 0b9f575
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
24 changes: 18 additions & 6 deletions integration_tests/test_gruntz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
from sympy import Symbol

def mmrv(e: S, x: S) -> list[S]:
l: list[S] = []
if not e.has(x):
return l
list0: list[S] = []
return list0
elif e == x:
list1: list[S] = [x]
return list1
else:
raise

def test_mrv1():
def test_mrv():
# Case 1
x: S = Symbol("x")
y: S = Symbol("y")
ans: list[S] = mmrv(y, x)
assert len(ans) == 0
ans1: list[S] = mmrv(y, x)
print(ans1)
assert len(ans1) == 0

test_mrv1()
# Case 2
ans2: list[S] = mmrv(x, x)
ele1: S = ans2[0]
print(ele1)
assert ele1 == x
assert len(ans2) == 1

test_mrv()
9 changes: 9 additions & 0 deletions src/libasr/pass/replace_symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,15 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
xx.m_test = new_logical_not;
}
}
} else if (ASR::is_a<ASR::SymbolicCompare_t>(*xx.m_test)) {
ASR::SymbolicCompare_t *s = ASR::down_cast<ASR::SymbolicCompare_t>(xx.m_test);
ASR::expr_t* function_call = nullptr;
if (s->m_op == ASR::cmpopType::Eq) {
function_call = basic_compare(xx.base.base.loc, "basic_eq", s->m_left, s->m_right);
} else {
function_call = basic_compare(xx.base.base.loc, "basic_neq", s->m_left, s->m_right);
}
xx.m_test = function_call;
}
}

Expand Down

0 comments on commit 0b9f575

Please sign in to comment.