This proposal is a little far-reaching, but I think it solves some real issues with the ease of use of refine and provides a reasonable way forward for typed symbols.
The problem with refine is that: (1) It's wordy. Assumptions on symbols are succinct and easy. (2) It requires explicit invocation so it requires the developer to refine before simplifying and simplify can't take advantage of refinements. (3) You must track your simplifying assumptions and since these are separate from the expression, it's too easy to refine on assumptions that later don't apply. Introduce a new type: Guard Guard(expr,axiom) - an expression which has meaning if the axiom is true Expr.with(axiom) - turns an expression into a Guard based on the given axiom This solves the problem by: (1) still allowing assumptions attached to symbols, handling them in a sane way (2) tracking your assumptions so they can be used while simplifying (3) requiring you to explicitly detach an expression from its assumptions For the simplest case, this provides typed expressions: (x**2).with(Q.integer(x)) ---> Guard(x**2, Q.integer(x)) Axioms distribute over application, so each expression only needs one set of axioms a1.with(p1) + a2.with(p2) ---> Guard(a1 + a2, p1 & p2) x.with(Q.positive(x)) + x.with(Q.real(x)) ---> Guard(2*x,Q.positive(x) & Q.real(x)) Axioms are taken to be the current assumption context, so rewrite rules can be applied more immediately. sqrt(x**2).with(Q.nonnegative(x)) ---> Guard(x,Q.nonnegative(x)) This elegantly solves the issue of typed expressions by unifying their assumptions, possibly resulting in a contradiction (which may be implemented as a special value or a ContradictionError) Q.positive(x)+Q.negative(x) ---> x.with(Q.positive(x) & Q.negative(x)) simplify(_) ---> Contradiction Thoughts? -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/2179e8b1-a241-44ca-a479-3fe2c0f35e4f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.