Should declaring an assumption restrict values substituted?

36 views
Skip to first unread message

Amit Saha

unread,
Apr 23, 2015, 5:58:11 PM4/23/15
to sy...@googlegroups.com
Hi all,

Let's say I have a symbol:

>>> x = Symbol('x', positive=True)

Should the below substitution be permitted:

>>> (x+1).subs({x:-5})
-4

My thinking is if x is declared to be positive, substituting negative
values should result in an error. Does that make sense?

Best,
Amit.


--
http://echorand.me

Jason Moore

unread,
Apr 23, 2015, 6:02:36 PM4/23/15
to sy...@googlegroups.com
That makes sense, but I'm not sure whether "Garbage in - Garbage Out" should apply or whether SymPy should throw and error.


--
http://echorand.me

--
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+un...@googlegroups.com.
To post to this group, send email to sy...@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/CANODV3kKyVJ0%2BH4DmzTdVpgmuKYfmMRiwvODH420OzjRoKJi6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Sudhanshu Mishra

unread,
Apr 23, 2015, 6:03:31 PM4/23/15
to sy...@googlegroups.com
Hi,

There's also an old issue for this https://github.com/sympy/sympy/issues/4709

Sudhanshu Mishra

Joachim Durchholz

unread,
Apr 24, 2015, 4:01:38 AM4/24/15
to sy...@googlegroups.com
Am 24.04.2015 um 00:02 schrieb Jason Moore:
> That makes sense, but I'm not sure whether "Garbage in - Garbage Out"
> should apply or whether SymPy should throw and error.

If something is invalid, the user needs to be notified.
General policy.
Otherwise, if the expressions become large, the user will have
difficulties finding out where the garbage went in.

Joachim Durchholz

unread,
Apr 24, 2015, 4:23:46 AM4/24/15
to sy...@googlegroups.com
Am 23.04.2015 um 23:57 schrieb Amit Saha:
> My thinking is if x is declared to be positive, substituting negative
> values should result in an error. Does that make sense?

To me it does.

Personally, I'd prefer to label it as "just an inconsistency", such as
asserting And(Q, ~Q), or asking for the solution of a overdetermined
linear system.
People like to ignore inconsistencies if they don't matter. E.g.
And(False, And(Q, ~Q)) is often considered to be False.

I don't know how SymPy handles inconsistencies.

Aaron Meurer

unread,
Apr 24, 2015, 11:02:51 AM4/24/15
to sy...@googlegroups.com
Two questions here:

- Should subs be mathematical or structural? I think subs is generally
more mathematical (with things like xreplace being purely structural).

- How expensive is checking assumptions? In general, it could be quite
expensive. I think it would be useful to at least have an option to
subs to check this though.

Aaron Meurer
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@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/5539FD8E.7090908%40durchholz.org.

Amit Saha

unread,
Apr 24, 2015, 10:06:46 PM4/24/15
to sy...@googlegroups.com
+1, perhaps raise a ValueError('Attempt to substitute an invalid value
for symbol: %s' % s)


--
http://echorand.me

Amit Saha

unread,
Apr 24, 2015, 10:07:23 PM4/24/15
to sy...@googlegroups.com
On Sat, Apr 25, 2015 at 1:02 AM, Aaron Meurer <asme...@gmail.com> wrote:
> Two questions here:
>
> - Should subs be mathematical or structural? I think subs is generally
> more mathematical (with things like xreplace being purely structural).
>
> - How expensive is checking assumptions? In general, it could be quite
> expensive. I think it would be useful to at least have an option to
> subs to check this though.

Like, subs(.., strict=True) ?
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LTpPJLwB5pYDc6BMK-Ta-nf6Q-DSt6TkhEuyns6pFxhA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://echorand.me
Reply all
Reply to author
Forward
0 new messages