From ea5dd7601d105391eab372d4cea3eeac58d6cb94 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Mon, 12 Feb 2024 11:09:54 +0530 Subject: [PATCH 1/5] Adding support for Pow instances in mrv function --- integration_tests/test_gruntz.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/integration_tests/test_gruntz.py b/integration_tests/test_gruntz.py index 33b940f86f..460dcd7b11 100644 --- a/integration_tests/test_gruntz.py +++ b/integration_tests/test_gruntz.py @@ -2,9 +2,9 @@ from sympy import Symbol, log 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 @@ -12,6 +12,20 @@ def mmrv(e: S, x: S) -> list[S]: arg0: S = e.args[0] list2: list[S] = mmrv(arg0, x) return list2 + elif e.func == Pow and e.args[0] != E: + e1: S = S(1) + while e.func == Pow: + b1: S = e.args[0] + e1 = e1 * e.args[1] + e = b1 + if b1 == S(1): + return empty_list + if not e.has(x): + list3: list[S] = mmrv(b1, x) + return list3 + else: + # TODO + pass else: raise From d7020c9e92ffd80a05dff61decab6dc5ac61eba5 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 15 Feb 2024 19:08:44 +0530 Subject: [PATCH 2/5] Added visit_WhileLoop --- src/libasr/pass/replace_symbolic.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 96a1469765..b21e352d20 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -976,6 +976,18 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor(x); + transform_stmts(xx.m_body, xx.n_body); + if (ASR::is_a(*xx.m_test)) { + ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast(xx.m_test); + if (intrinsic_func->m_type->type == ASR::ttypeType::Logical) { + 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) { if (!symbolic_vars_to_free.empty()){ for (ASR::symbol_t* symbol : symbolic_vars_to_free) { From a41a4e3b72b5165427994bc03982af397054cd3f Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sat, 24 Feb 2024 14:57:55 +0530 Subject: [PATCH 3/5] Added case 4 --- integration_tests/test_gruntz.py | 38 ++++++++++++++++++---------- src/libasr/pass/replace_symbolic.cpp | 4 ++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/integration_tests/test_gruntz.py b/integration_tests/test_gruntz.py index 460dcd7b11..0a3948f722 100644 --- a/integration_tests/test_gruntz.py +++ b/integration_tests/test_gruntz.py @@ -1,5 +1,5 @@ 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] = [] @@ -12,17 +12,22 @@ def mmrv(e: S, x: S) -> list[S]: arg0: S = e.args[0] list2: list[S] = mmrv(arg0, x) return list2 - elif e.func == Pow and e.args[0] != E: - e1: S = S(1) - while e.func == Pow: - b1: S = e.args[0] - e1 = e1 * e.args[1] - e = b1 - if b1 == S(1): - return empty_list - if not e.has(x): - list3: list[S] = mmrv(b1, x) - return list3 + 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 @@ -49,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() \ No newline at end of file diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index b21e352d20..e2629819ad 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -997,7 +997,9 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor Date: Thu, 14 Mar 2024 10:25:32 +0530 Subject: [PATCH 4/5] Update src/libasr/pass/replace_symbolic.cpp Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com> --- src/libasr/pass/replace_symbolic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 6092ce3292..39e092fd05 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -1012,7 +1012,7 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor(*xx.m_test)) { ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast(xx.m_test); - if (intrinsic_func->m_type->type == ASR::ttypeType::Logical) { + if (ASRUtils::is_logical(intrinsic_func->m_type)) { ASR::expr_t* function_call = process_attributes(xx.base.base.loc, xx.m_test); xx.m_test = function_call; } From 05653b4f8d5c475d612516a4270cb307f3b415d1 Mon Sep 17 00:00:00 2001 From: Anutosh Bhat <87052487+anutosh491@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:47:14 +0530 Subject: [PATCH 5/5] Update replace_symbolic.cpp --- src/libasr/pass/replace_symbolic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 39e092fd05..83da75603f 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -1012,7 +1012,7 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor(*xx.m_test)) { ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast(xx.m_test); - if (ASRUtils::is_logical(intrinsic_func->m_type)) { + if (ASR::is_a(*intrinsic_func->m_type)) { ASR::expr_t* function_call = process_attributes(xx.base.base.loc, xx.m_test); xx.m_test = function_call; }