Maxima allows declaring a symbol both real and complex and even both real and imaginary. I think that in the second case, it should at least issue a warning, if not an error.
For the first case, where a symbol is declared both real and complex, Maxima behaves differently across csign, rectform and featurep:
(%i1) declare(x, real, x, complex);
(%o1) done
(%i2) csign(x);
(%o2) complex
(%i3) rectform(x);
(%o3) x
(%i4) featurep(x, real);
(%o4) true
(%i5) featurep(x, complex);
(%o5) true
These functions all have a different concept ...
Agreed this is a problem.
declare(x,real,x,complex)should report that there is an inconsistency, just asassume(x>0,x<0)does. Unfortunately, the return value ofdeclareis always "done" (except when the property is unknown, when it raises an error).Since the return value of
declaregives no information, perhaps we can presume that code (other than the test suite) never looks at it, and we can redefinedeclareto be consistent withassume, like this:And wouldn't it be grand if this were folded into
assume(while continuing to supportdeclarefor backward compatibility)? :Interestingly,
forgetalready takes thekindargument:I like the idea of folding
kindintoassume.Actually,
declarecan already fail when there's an inconsistency, like when declaring a symbol bothevenandodd, not only when the property is unknown. But most inconsistencies aren't detected.I'm not sure about
realandcomplex. There's at least one place in Maxima's code that explicitly handles the case when a symbol is declared bothrealandcomplex(thenrealwins).It boils down to the question: How do we define complex? As a superset of real numbers? As strictly non-real? As "probably" non-real? I find it quite tricky to come up with a definition that feels correct and useful and works nicely with the existing code and
featurep.Last edit: David Scherfgen 2026-06-01
Maxima is not very consistent about all this. For example, we have the
domain=real/complexvariable which sounds very powerful, but in fact the only thing it affects is the simplification of(a^b)^cas far as I can tell.One pragmatic definition of
kind(z,complex)is thatimagpart(z)returns the nounform'imagpart(z)and not 0.Grepping through the code, it looks as though there are three ways that the declaration is used:
kindp, decl-complexp, featurep. These are used forreal/complex/imaginaryin the filescompar (sign-any), conjugate (manifestly-XXX-p), rpart, simp. But I haven't looked at the transitive closure of function calls....I like your pragmatic definition.
We should extend
risplitso that it can raise errors (controlled by a flag) for expressions that do not describe real or complex numbers, for exampletrue,false,und,ind,inf,minf,zeroa,zerob, lists, equations, inequalities, logical expressions, sets, matrices, ...Then we can safely rely on
risplitin$featurep.Last edit: David Scherfgen 7 days ago
Lots of things should raise errors that don't currently:
These are not real numbers in the mathematical sense (members of R) -- in fact, they are not numbers at all:
ind, und, inf, minf, zeroa, zerob, but they are real in the sense of not having a non-zero imaginary part (as opposed toinfinity), which is probably what is needed by most uses.I pushed commit [46cd19], which restores some numerical inferences, detects lots of inconsistent type declarations and greatly simplifies
decl-realp. The issue "real vs. complex" is not resolved yet.Related
Commit: [46cd19]