Ask Your Question
1

Declaring variable to be in a particular field/ring/group

asked 2014-11-28 17:44:44 +0100

a1846583 gravatar image

Is it possible to have Sage symbolically simplify expressions involving variables subject to the assumption that the variables take values in a defined domain (field/ring/group/etc)?

The closest I've gotten is to declare a dummy polynomial ring over my domain of interest so that its variable has some notion of the domain, e.g.:

Z3=Integers(3)
Dummy.<x> = PolynomialRing(Z3)
3*x

evaluates to "0" as I'd expect, but sage fails to simplify "x^3" to "x", which ISTM should be doable if it really understood that x is a variable in Z/3Z.

Related things I've found in my searches that haven't panned out:
1. var('x', domain=foo) -- apparently foo can only be one of real/complex/positive (where I'd like to be able to say 'Z3' in the example above)
2. assume('x is Z3') - doesn't seem to have any effect.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-12-02 07:07:43 +0100

a1846583 gravatar image

updated 2014-12-02 07:09:45 +0100

I think I found a workaround: make x not be the variable of the polynomial ring but rather that of the quotient of that ring by the ideal generated by z^2-z. In other words:

var('X'); x=PolynomialRing(Integers(3), 'X').quotient([X^2-1], 'x').gens()[0]
print x^3==x and x^2==1 and 3*x==0

evals to True

edit flag offensive delete link more
0

answered 2014-11-29 09:14:20 +0100

rws gravatar image

updated 2014-11-29 10:18:01 +0100

What you are telling Sage with the code snippet is a polynomial whose coefficients are in Z/3Z, but you want a symbolic expression where the variable x is integer and whose values are in Z/3Z, or in other words, modulo 3.

sage: assume(x, "integer")
sage: (x^3).mod(3)
x^3

That would be the most natural way to express it but, as you see, the result is wrong. The Pari-style alternative Mod function only accepts numeric input.

Note that with noninteger x the result wold not be x but -3*floor(x^3/3)+x^3.

EDIT: There is an old ticket at trac #9935 that is a prerequisite for such simplifications.

edit flag offensive delete link more

Comments

Thanks for your answer. I guess there are two issues here: 1) the feature request you point out as #9935 to make mod work with symbolic expressions; and 2) that sage should know that PolynomialRing(Integers(3)) doesn't need to track powers higher than 2 (and generally that PR(I(p)) doesn't need to track powers higher than p-1). Is that natural fallout from #9935 or do you think that deserves its own feature request?

At any rate, it seems the short answer to my original question is "it's not possible (yet)". Unless you can think of a workaround?

a1846583 gravatar imagea1846583 ( 2014-11-30 00:32:24 +0100 )edit

I think it would be natural to add this logic to #9935, just like special functions get immediately expanded for specific values, depending on said assumptions here.

rws gravatar imagerws ( 2014-11-30 15:59:04 +0100 )edit
1

Some more head-smacking revealed I can take a quotient to get what I wanted; see my self-answer above. Thanks again for your feedback!

a1846583 gravatar imagea1846583 ( 2014-12-02 07:09:22 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-11-28 17:44:44 +0100

Seen: 4,090 times

Last updated: Dec 02 '14