Skip to content

Commit 90c1094

Browse files
Adding support for Pow instances in mrv function (#2528)
* Adding support for Pow instances in mrv function * Added visit_WhileLoop * Added case 4 * Update src/libasr/pass/replace_symbolic.cpp Co-authored-by: Thirumalai Shaktivel <[email protected]> * Update replace_symbolic.cpp --------- Co-authored-by: Thirumalai Shaktivel <[email protected]>
1 parent 44c6b96 commit 90c1094

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

integration_tests/test_gruntz.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
from lpython import S
2-
from sympy import Symbol, log
2+
from sympy import Symbol, log, E, Pow
33

44
def mmrv(e: S, x: S) -> list[S]:
5+
empty_list : list[S] = []
56
if not e.has(x):
6-
list0: list[S] = []
7-
return list0
7+
return empty_list
88
elif e == x:
99
list1: list[S] = [x]
1010
return list1
1111
elif e.func == log:
1212
arg0: S = e.args[0]
1313
list2: list[S] = mmrv(arg0, x)
1414
return list2
15+
elif e.func == Pow:
16+
if e.args[0] != E:
17+
e1: S = S(1)
18+
newe: S = e
19+
while newe.func == Pow:
20+
b1: S = newe.args[0]
21+
e1 = e1 * newe.args[1]
22+
newe = b1
23+
if b1 == S(1):
24+
return empty_list
25+
if not e1.has(x):
26+
list3: list[S] = mmrv(b1, x)
27+
return list3
28+
else:
29+
# TODO as noted in #2526
30+
pass
31+
else:
32+
# TODO
33+
pass
1534
else:
1635
raise
1736

@@ -35,6 +54,13 @@ def test_mrv():
3554
ele2: S = ans3[0]
3655
print(ele2)
3756
assert ele2 == x
38-
assert len(ans2) == 1
57+
assert len(ans3) == 1
58+
59+
# Case 4
60+
ans4: list[S] = mmrv(x**S(2), x)
61+
ele3: S = ans4[0]
62+
print(ele3)
63+
assert ele3 == x
64+
assert len(ans4) == 1
3965

4066
test_mrv()

src/libasr/pass/replace_symbolic.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,18 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
10071007
}
10081008
}
10091009

1010+
void visit_WhileLoop(const ASR::WhileLoop_t &x) {
1011+
ASR::WhileLoop_t &xx = const_cast<ASR::WhileLoop_t&>(x);
1012+
transform_stmts(xx.m_body, xx.n_body);
1013+
if (ASR::is_a<ASR::IntrinsicScalarFunction_t>(*xx.m_test)) {
1014+
ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast<ASR::IntrinsicScalarFunction_t>(xx.m_test);
1015+
if (ASR::is_a<ASR::Logical_t>(*intrinsic_func->m_type)) {
1016+
ASR::expr_t* function_call = process_attributes(xx.base.base.loc, xx.m_test);
1017+
xx.m_test = function_call;
1018+
}
1019+
}
1020+
}
1021+
10101022
void visit_Return(const ASR::Return_t &x) {
10111023
// freeing out variables
10121024
if (!symbolic_vars_to_free.empty()){

0 commit comments

Comments
 (0)