evaluationmaxima

How to force maxima to evaluate a sum? (Evaluation Logic)


(%i1)   load("distrib");
(%o1)   "/opt/homebrew/Cellar/maxima/5.46.0_11/share/maxima/5.46.0/share/distrib/distrib.mac"

(%i2)   T1: sum( pdf_binomial(si,SM,p) * p^2 , si, 0, SM ) $

(%i3)   float(ev(T1, [SM=7,p=0.3]));
(%o3)   sum(binomial(7.0,si)*0.7^(7-si)*0.3^(si+2),si,0.0,7.0)

(%i6)   SM:7 $  float(ev(T1, [p=0.3])); kill(SM) $
(%o5)   sum(binomial(7.0,si)*0.7^(7-si)*0.3^(si+2),si,0.0,7.0)

(%i9)   SM: 7 $ T2: sum( pdf_binomial(si,SM,p) * p^2 , si, 0, SM ) $
    ev(T2, [p=0.3]);
(%o9)   0.08999999999999997

if I define SM before I define the expression (T2), it "works" (evaluates to a number). However, maxima no longer gives numerical values if SM is defined after T1 is defined. Not shown, if I define T2 as T1 (T2: T1), I believe maxima internally stores the symbol T1 into T2, not the expression that is in T1, and this again does not evaluate. it's somehow about context. all ok --- I just need to know how to force evaluation when I need to.

advice appreciated.


Solution

  • Maxima represents partially-evaluated expressions as so-called noun expressions. Many mathematical functions return noun expressions when the arguments aren't specific enough to permit complete evaluations. sum, integrate, diff, limit, etc. return noun expressions; programming functions such as length, first, op, etc., complain with an error message if arguments aren't specific enough.

    Nouns can be "verbified" via ev(expr, nouns). You can also nounify just one operator (if there's more than one nounified expression present) by saying the name of the operator, e.g. ev(expr, sum) to verbify just sum. In this case, the appropriate incantation is:

    ev(T2, SM = 7, p = 0.3, nouns);
    

    You can explicitly construct a noun expression via the single quote ' applied to an operator, e.g. 'integrate(sin(x), x).