Skip to content

Former Compile functions match their arguments again - #7

Merged
rocky merged 2 commits into
masterfrom
fix-compiled-arg-patterns
Oct 30, 2026
Merged

rocky merged 2 commits into
masterfrom
fix-compiled-arg-patterns

Conversation

@tombouctou

Copy link
Copy Markdown
Contributor

Found while running the examples of Skiena and Pemmaraju's Computational Discrete Mathematics with this package under Mathics3, comparing every result with WMA 15.

Several internal functions were Compiled in the original. Their uncompiled definitions tested the arguments with ?Integer, ?IntegerQ or ?NumberQ, which a list never passes. n_?Integer matches nothing at all, since Integer[n] is never True. So these functions stayed unevaluated, and so did everything built on them:

Function Was Now Used by
LP n_?Integer n_Integer LexicographicPermutations
NC l_?Integer l_List NextComposition
NKS ss_?Integer ss_List NextKSubset
NthPair n_?Integer n_Integer RandomGraph
RGFs1 n_?Integer n_Integer RGFs
TC e_?Integer e_List TransitiveClosure
TR, TRAcyclic closure_?Integer closure_List TransitiveReduction, HasseDiagram
DP1, DP2 p_?NumberQ, q_?IntegerQ _List weighted AllPairsShortestPath, Eccentricity, Diameter, Radius
BF e1_?IntegerQ, w1_?NumberQ, ... _List BellmanFord

LP also assigned to parts of its argument #, which only a compiled function can do; it now works on a local copy.

I checked these functions against WMA 15's Combinatorica, for example AllPairsShortestPath, BellmanFord, Eccentricity and Diameter on a weighted Cycle[5]. With Mathics3/mathics-core#2088 (BinomialDistribution), RandomGraph gives graphs again.

Package tests: 18 passed.

🤖 Generated with Claude Code

tombouctou and others added 2 commits October 30, 2026 11:20
LP, NC, NKS, NthPair, RGFs1, TC, TR and TRAcyclic were compiled
functions; their uncompiled definitions took arguments as n_?Integer,
which matches nothing (Integer[n] is never True), so they stayed
unevaluated. Integer arguments are now n_Integer and integer vectors and
matrices _List. That makes RandomGraph, NextComposition, NextKSubset,
RandomSetPartition, TransitiveClosure, TransitiveReduction and
HasseDiagram give graphs and lists again.

LP assigned to parts of its argument, which only a compiled function
can do; it now works on a local copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like the other former Compile functions, their uncompiled definitions
tested arrays with ?NumberQ or ?IntegerQ, which a list never passes, so
weighted AllPairsShortestPath (and with it Eccentricity, Diameter and
Radius of weighted graphs) and BellmanFord stayed unevaluated. Arrays
are now matched as _List.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rocky

rocky commented Oct 30, 2026

Copy link
Copy Markdown
Member

Thanks!

@rocky
rocky merged commit 3a019cb into master Oct 30, 2026
1 check passed
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.

2 participants