From 85f6165b1a675238f8d36db3489d56f4f09cca77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 19:57:51 +0000 Subject: [PATCH 1/4] Initial plan From 0b724ead9859bdbd4e9e6f27b2de4ef5b4f1d478 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 20:08:59 +0000 Subject: [PATCH 2/4] Implement multi-line PARI formulas for multiple functions Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com> --- src/form/pari.cpp | 12 +++++++++++- tests/formula/pari-function.txt | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/form/pari.cpp b/src/form/pari.cpp index e40fe4a3..33a58208 100644 --- a/src/form/pari.cpp +++ b/src/form/pari.cpp @@ -142,7 +142,17 @@ std::string PariFormula::toString() const { } return buf.str(); } else { - return main_formula.toString("; ", true); + // Get the list of functions to check if there are multiple + auto functions = + FormulaUtil::getDefinitions(main_formula, Expression::Type::FUNCTION); + if (functions.size() > 1) { + // Multiple functions: use newline separator and no brackets + return main_formula.toString("\n", false); + } else { + // Single function: use semicolon separator with brackets (original + // behavior) + return main_formula.toString("; ", true); + } } } diff --git a/tests/formula/pari-function.txt b/tests/formula/pari-function.txt index e7895d2a..d5e0ac3e 100644 --- a/tests/formula/pari-function.txt +++ b/tests/formula/pari-function.txt @@ -1,6 +1,8 @@ A000023: a(n) = if(n==3,-2,if(n==2,2,if(n==1,-1,if(n==0,1,local(l1=a(n-1)); (n-1)*(2*a(n-2)+l1)-l1)))) A000027: a(n) = n A000032: a(n) = if(n==2,3,if(n==1,1,if(n==0,2,a(n-1)+a(n-2)))) -A000058: (a(n) = b(n)+1); (b(n) = if(n==0,1,local(l1=b(n-1)); l1*(l1+1))) +A000058: a(n) = b(n)+1 + b(n) = if(n==0,1,local(l1=b(n-1)); l1*(l1+1)) A000247: a(n) = 2^n-n-2 -A001715: (a(n) = truncate(b(n)/6)); (b(n) = if(n==0,1,n*b(n-1))) +A001715: a(n) = truncate(b(n)/6) + b(n) = if(n==0,1,n*b(n-1)) From 546fc7b802a0e2fde52b375ea19d2a38ff0bac72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 20:10:25 +0000 Subject: [PATCH 3/4] Document multi-line PARI formula feature in CHANGELOG Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66cb3bc5..8afed578 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +### Enhancements + +* Support multi-line output for PARI/GP formulas with multiple functions + ## v25.11.2 ### Bugfixes From 6c04d7cc3ce9e8aa602befb2ca613a39f623ea7b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 5 Nov 2025 20:12:19 +0000 Subject: [PATCH 4/4] Improve comments based on code review feedback Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com> --- src/form/pari.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/form/pari.cpp b/src/form/pari.cpp index 33a58208..a1d46bf4 100644 --- a/src/form/pari.cpp +++ b/src/form/pari.cpp @@ -142,15 +142,14 @@ std::string PariFormula::toString() const { } return buf.str(); } else { - // Get the list of functions to check if there are multiple + // Get all function definitions in the formula to determine output format auto functions = FormulaUtil::getDefinitions(main_formula, Expression::Type::FUNCTION); if (functions.size() > 1) { // Multiple functions: use newline separator and no brackets return main_formula.toString("\n", false); } else { - // Single function: use semicolon separator with brackets (original - // behavior) + // Single function: use semicolon separator with brackets (original behavior) return main_formula.toString("; ", true); } }