|
From: Stavros M. <mac...@gm...> - 2025-11-28 13:00:24
|
I hope it's clearer now how to use *integer_partitions*. As for your original syntax, partition_set(...,length(list)=*2)*, Maxima doesn't set *list* (or any other variable) to the candidate partition -- you'd need to write an explicit lambda-expression. Here is a little introduction to the magic variables in Maxima written by Gemini: Maxima has several "magical" system variables which are implicitly set by > Maxima as side effects of functions or to track interaction history. > > Here are the most notable ones, categorized by their behavior: > > 1. The "Context" Variables (Like piece) > > These are variables that are bound temporarily during the execution of a > specific function or rule. > > - > > *piece*: > - > > *Context:* Used inside substpart and substinpart. > - > > *Magic:* It refers to the specific sub-expression currently being > replaced. > - > > *Example:* substpart(piece^2, x+y+z, 2) replaces y with y^2. > > piece is unique because it captures a *context-dependent value during execution* (specifically inside substpart), > - > > *Pattern Matching Variables*: > - > > *Context:* Used in defmatch, defrule, tellsimp, and let. > - > > *Magic:* When you define a pattern with matchdeclare(x, predicate), > the variable x is automatically bound to the matching part of the > expression when the rule executes. > - > > *Example:* If you define matchdeclare(a, true) and a rule for a^2, > when the rule matches (x+1)^2, the variable a is momentarily bound > to x+1 inside the rule's body. > > 2. The "Side-Effect" Variables (Set by specific functions) > > Unlike piece, these variables persist *after* a command is finished. They > are often used to inspect "how" a problem was solved or to get details that > didn't fit in the main return value. > > - > > *multiplicities*: > - > > *Context:* Set by solve and allroots. > - > > *Magic:* It becomes a list of integers corresponding to the > multiplicity of each solution returned. > - > > *Example:* > Maxima > > solve((x-1)^2 * (x-2) = 0, x);/* Returns [x=1, x=2] */multiplicities;/* Returns [2, 1] */ > > - > > *method* (and friends in ode2): > - > > *Context:* Set by ode2 (the ordinary differential equation solver). > - > > *Magic:* After solving an ODE, method is set to the name of the > method Maxima used (e.g., linear, separable, exact). > - > > *Related Variables:* > - > > intfactor: Set to the integrating factor used (if any). > > - > > odeindex: Set to the index for Bernoulli or Euler equations. > - > > yp: Set to the particular solution found when using variation of > parameters. > > 3. The "Generated Symbol" Variables > > Maxima automatically creates and increments these counters to ensure > uniqueness in solutions. > > - > > *%c, %k1, %k2*: > - > > *Context:* Integration constants generated by ode2 and contrib_ode. > - > > *Magic:* %c is for 1st order, %k for 2nd order. They are > system-managed constants but appear in your output. > > - > > *%r variables* (e.g., %r1, %r2): > - > > *Context:* Set by solve or algsys. > - > > *Magic:* These represent arbitrary parameters in the solution of an > under-determined system (like a line of solutions). They are > tracked in the list %rnum_list. > > > 4. The "History" Variables > > - > > *%*: The result of the *last* command (output). > > - > > *_*: The *input* of the last command. > - > > *%%*: The result of the *previous statement* inside a block (e.g., block(a:2, > a+2, %% * 10) returns 40). > - > > *%th(k)*: The *k-th* previous output (e.g., %th(2) is the one before % > ). > - > > *%i / %o / %t labels*: > - > > %i5: Input #5. > - > > %o5: Output #5. > - > > %t5: *Intermediate* expressions. These often appear when solving > large systems or generating code; Maxima labels a sub-expression %t5 > and prints it separately to keep the main output readable. > > 5. Loop Variables (Not Magical) > > It is worth noting that unlike some languages (like Perl's $_ or awk's NR), > Maxima *does not* have an implicit variable for the current element in a > map or apply. You must always explicitly name your iterator (e.g., map(lambda([u], > u^2), [1,2,3])). > |