build_function tier1 & tier3 - #18
Merged
Merged
Conversation
`build_function(expr::GiacExpr, vars::GiacExpr...)` returns a Julia callable equivalent to `to_julia(substitute(expr, Pair.(vars, vals)...))`, suitable as a drop-in argument to `Plots.plot`, `Plots.surface`, broadcasting, and matrix comprehensions. Tier 1 wrapper only — Tier 2 (in-house codegen) and Tier 3 (Symbolics.build_function delegation) remain follow-ups per issue #17. Closes #17. (066-build-function) - src/build_function.jl: thin wrapper via private fixed-arity callable struct (`<: Function`) so wrong-arity calls raise MethodError. - docs/src/julia_functions.md: new `Using build_function` section with comparison table to Symbolics.build_function and SymPy.lambdify. - examples/04_plotting.jl: new section 2b demonstrating the multivariate surface plot with build_function alongside the existing manual cells. - test/test_build_function.jl: 10 testsets covering clauses C1–C10 including a 3-expression × 100-sample behavioral equivalence sweep. - Project.toml: 0.12.0 -> 0.13.0 (additive MINOR); Random added to test extras / compat for the equivalence sweep.
`build_function` gains a `backend::Symbol = :giac` keyword. The default is unchanged from v0.13. The new `backend = :symbolics` (requires `using Symbolics`) round-trips the expression through `to_symbolics` and compiles it via `Symbolics.build_function`, returning a native Julia callable that is autodiff-friendly (ForwardDiff, SciML solvers) and ~140× faster than the :giac backend on hot-loop workloads. Closes #17 tier 3. - src/build_function.jl: backend keyword + missing-Symbolics ArgumentError + internal `_build_function_symbolics_impl` hook (declared with no methods so the extension's method doesn't trigger the precompile-time "method overwriting" error). - ext/GiacSymbolicsExt.jl: extension's method on the hook does the to_symbolics + Symbolics.build_function compilation, with build-time free-symbol validation (clause B6). - test/test_build_function_tier3.jl: 6 testsets covering clauses B1-B4, B6, B7, B8 + behavioral equivalence sweep (3 expressions x 100 samples) + ForwardDiff smoke (B3). - Project.toml: 0.13.0 -> 0.14.0; ForwardDiff added to test extras and compat. Symbolics stays a weakdep (FR-003). - docs/src/julia_functions.md: new "Choosing a backend" subsection with comparison table, equivalence example, benchmark snippet, autodiff example, naming-conflict caveat, error-paths summary. Naming caveat (Option B from design discussion): `Symbolics` also exports `build_function`, so `using Giac, Symbolics` requires qualification — `Giac.build_function(...)`. Documented in the docstring and docs page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #18 +/- ##
==========================================
+ Coverage 79.28% 79.50% +0.21%
==========================================
Files 21 22 +1
Lines 2810 2840 +30
==========================================
+ Hits 2228 2258 +30
Misses 582 582 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related #17