WIP: add an enhance macro to create variables#35
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
I really like this idea. This is really useful |
There was a problem hiding this comment.
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
@symsmacro with a smallVarDecltype hierarchy for parsing assumption/tensor/function declarations. - Wire
decl.jlintoGiac.jland 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.
| """ | ||
| macro syms(xs...) | ||
| if isempty(xs) | ||
| throw(ArgumentError("@giac_var requires at least one argument")) |
| function parserange(expr) | ||
| range = eval(expr) | ||
| isa(range, AbstractRange) || parseerror() | ||
| range | ||
| end |
There was a problem hiding this comment.
Hmm, that is a good point.
| 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 |
There was a problem hiding this comment.
Another good point.
|
Quite busy now (and the next 2 weeks)... so running just a Copilot review for now |
|
Yes, I was thinking this could replace |
No rush at all, I just had some free time yesterday to try this out. |
This borrows features from SymPy's
@symsmacro (which was inspired by on in Symbolics) to enhance@giac_varby 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_varif the PR is to be merged.