Skip to content

WIP: add an enhance macro to create variables#35

Open
jverzani wants to merge 5 commits into
s-celles:mainfrom
jverzani:decl
Open

WIP: add an enhance macro to create variables#35
jverzani wants to merge 5 commits into
s-celles:mainfrom
jverzani:decl

Conversation

@jverzani

Copy link
Copy Markdown
Contributor

This borrows features from SymPy's @syms macro (which was inspired by on in Symbolics) to enhance @giac_var by adding the ability to put a limited number of assumptions on the variable and to create arrays of variables, like @giac_several_vars.

I left the name as @syms, but would imagine this could replace @giac_var if the PR is to be merged.

@codecov-commenter

codecov-commenter commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 121 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.56%. Comparing base (681f1ad) to head (5d88858).

Files with missing lines Patch % Lines
src/decl.jl 0.00% 121 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
- Coverage   79.76%   76.56%   -3.21%     
==========================================
  Files          23       24       +1     
  Lines        2891     3012     +121     
==========================================
  Hits         2306     2306              
- Misses        585      706     +121     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@s-celles

Copy link
Copy Markdown
Owner

I really like this idea. This is really useful
But I think we should have only macros starting with giac_var to create new Giac variables.
Wondering if we couldn't have even just one macro for creating variables.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new @syms macro (adapted from SymPyCore.jl) that extends @giac_var with support for assumptions (e.g., ::(integer, positive)), tensors of symbols (x[1:3]), and symbolic functions (w(t)). The implementation lives in a new src/decl.jl file, exported from the top-level module. A stray blank line in macros.jl is also removed. PR is marked WIP and the author notes @syms could eventually replace @giac_var.

Changes:

  • Introduce @syms macro with a small VarDecl type hierarchy for parsing assumption/tensor/function declarations.
  • Wire decl.jl into Giac.jl and export @syms.
  • Minor whitespace cleanup in macros.jl.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/decl.jl New file implementing @syms, parsing helpers, assumption application via Commands.assume/additionally, and tensor/function support.
src/Giac.jl Includes decl.jl and exports @syms.
src/macros.jl Removes a blank line inside @giac_several_vars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/decl.jl Outdated
"""
macro syms(xs...)
if isempty(xs)
throw(ArgumentError("@giac_var requires at least one argument"))
Comment thread src/decl.jl
Comment on lines +159 to +163
function parserange(expr)
range = eval(expr)
isa(range, AbstractRange) || parseerror()
range
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that is a good point.

Comment thread src/decl.jl
Comment on lines +175 to +198
function symbols(x, args...; kwargs...)
if contains(x, ",")
nm = [giac_eval(string(xᵢ)) for xᵢ ∈ split(x, ",")]
else
nm = giac_eval(x)
Commands.purge(nm)
for a in args
if a ∈ (:complex, :real, :rational, :integer)
Commands.assume(nm, string(a))
end
end
for a in args
a == :negative && Commands.additionally(nm < 0)
a == :nonpositive && Commands.additionally(nm <= 0)
a == :nonnegative && Commands.additionally(nm >= 0)
a == :positive && Commands.additionally(nm > 0)
if a == :finite
Commands.additionally("$nm > -infinity")
Commands.additionally("$nm < infinity")
end
end
end
nm
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good point.

@s-celles

Copy link
Copy Markdown
Owner

Quite busy now (and the next 2 weeks)... so running just a Copilot review for now

@jverzani

Copy link
Copy Markdown
Contributor Author

Yes, I was thinking this could replace @giac_var as it replicates and extends that functionality. It doesn't do what @giac_several_vars does, but that could be included given the right syntax to specify what is desired.

@jverzani

Copy link
Copy Markdown
Contributor Author

Quite busy now (and the next 2 weeks)... so running just a Copilot review for now

No rush at all, I just had some free time yesterday to try this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants