Maxima中如何将可整除的多项式商保存为新多项式?
Got it, let's work through this issue. The problem here is that using := (delayed assignment) for h(x,y) makes Maxima re-run the quotient calculation every time you call h(x,y)—including when x=0, which triggers a division-by-zero error even though the polynomials are clearly divisible.
Since you only care about cases where f is divisible by g, we can fix this by computing the polynomial quotient once at the symbolic level and assigning that result directly to h(x,y), instead of delaying the calculation. Here are two reliable approaches:
Approach 1: Use ratsimp for Simplified Exact Division
ratsimp will simplify the fraction f(x,y)/g(x,y) directly to its polynomial quotient when division is exact:
f(x,y) = x*y; g(x,y) = x; # Compute and assign the simplified quotient to h(x,y) h(x,y) = ratsimp(f(x,y)/g(x,y));
Now when you call h(0,0), it will return 0 without any errors—because h(x,y) is just defined as y under the hood, no division happens at runtime.
Approach 2: Use divide for Explicit Polynomial Division
Maxima's divide function is purpose-built for polynomial division: it returns a list containing the quotient and remainder. Since you know f is divisible by g, the remainder will be 0, and we can grab the quotient directly:
f(x,y) = x*y; g(x,y) = x; # Get quotient and remainder (remainder will be 0 for exact division) [h_expr, remainder] = divide(f(x,y), g(x,y)); # Assign the quotient to h(x,y) h(x,y) = h_expr;
This method is more explicit about the polynomial division operation, which can be helpful if you want to verify the remainder is indeed zero for your use case.
Why do these work? Both approaches compute the quotient once at the symbolic level, so h(x,y) ends up being a simple polynomial expression (in your case, y) instead of a function that re-runs division every time it's called. No division means no division-by-zero errors, even when evaluating at x=0.
内容的提问来源于stack exchange,提问作者antizaba

