Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding support for Pow instances in mrv function #2528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions integration_tests/test_gruntz.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
from lpython import S
from sympy import Symbol, log
from sympy import Symbol, log, E, Pow

def mmrv(e: S, x: S) -> list[S]:
empty_list : list[S] = []
if not e.has(x):
list0: list[S] = []
return list0
return empty_list
elif e == x:
list1: list[S] = [x]
return list1
elif e.func == log:
arg0: S = e.args[0]
list2: list[S] = mmrv(arg0, x)
return list2
elif e.func == Pow:
if e.args[0] != E:
e1: S = S(1)
newe: S = e
while newe.func == Pow:
b1: S = newe.args[0]
e1 = e1 * newe.args[1]
newe = b1
if b1 == S(1):
return empty_list
if not e1.has(x):
list3: list[S] = mmrv(b1, x)
return list3
else:
# TODO as noted in #2526
pass
else:
# TODO
pass
else:
raise

Expand All @@ -35,6 +54,13 @@ def test_mrv():
ele2: S = ans3[0]
print(ele2)
assert ele2 == x
assert len(ans2) == 1
assert len(ans3) == 1

# Case 4
ans4: list[S] = mmrv(x**S(2), x)
ele3: S = ans4[0]
print(ele3)
assert ele3 == x
assert len(ans4) == 1

test_mrv()
12 changes: 12 additions & 0 deletions src/libasr/pass/replace_symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,18 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
}
}

void visit_WhileLoop(const ASR::WhileLoop_t &x) {
ASR::WhileLoop_t &xx = const_cast<ASR::WhileLoop_t&>(x);
transform_stmts(xx.m_body, xx.n_body);
if (ASR::is_a<ASR::IntrinsicScalarFunction_t>(*xx.m_test)) {
ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast<ASR::IntrinsicScalarFunction_t>(xx.m_test);
if (ASR::is_a<ASR::Logical_t>(*intrinsic_func->m_type)) {
ASR::expr_t* function_call = process_attributes(xx.base.base.loc, xx.m_test);
xx.m_test = function_call;
}
}
}

void visit_Return(const ASR::Return_t &x) {
// freeing out variables
if (!symbolic_vars_to_free.empty()){
Expand Down