Re: [sage-devel] Re: Is there a math alternative to range and interval?
On Friday, October 19, 2018 at 10:16:28 AM UTC+9, William wrote: > > > > (4) is this "range" the vanilla python built-in? > > Yes. Type "range??" in Sage to see. > Right. I didn't know that range first converts the argument to int, which is why "range(Integer(10))" works. By the way, I am happy with ellipsis notation. So everything is fine. I will just forget "interval". Thanks everyone! -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: Piecewise affine functions
Xavier, For code for piecewise linear functions of several variables, see here: https://github.com/mkoeppe/cutgeneratingfunctionology/blob/master/piecewise_functions.sage I'd be quite interested in getting something like this into sage. There's no ticket for this yet. Also, you might be interested in https://trac.sagemath.org/ticket/20877 Best, Matthias On Thursday, October 18, 2018 at 4:37:17 PM UTC-5, Xavier Caruso wrote: > > Hello, > > For some application I have in mind (related to ticket #26471 for > those who are interested), I need to have support for piecewise > affine functions in Sage. More precisely, what I mostly need is: > . to add, compose, take the sup/inf of these functions > . to check continuity, convexity, bijectivity > . to compute the inverse (for composition) when appropriate > > I'd be happy to implement this but I'm unsure how it should fit > in the current framework. Notably, I noticed that there already > exists support for piecewise defined functions: > > http://doc.sagemath.org/html/en/reference/functions/sage/functions/piecewise.html > > So I guess that I should derive from this class. > But I'm unsure because I realized that the behavior of piecewise > defined functions is sometimes a bit different for what I'd like > to have. For instance, if f and g are PiecewiseAffineFunction, I > would expect f + g to be a PiecewiseAffineFunction as well. And > f.derivative() as well, etc. > It's not exactly the case for piecewise defined function: > > sage: f = piecewise([((0,1), 2*x), ([-1,0], 3*x)]) > sage: type(f) == type(f + f) > False > sage: type(f) == type(f.derivative()) > False > > (I saw that there is a method piecewise_add() but I would expect > it to be the default __add__; why isn't it the case?) > > Moreover it seems that composition of piecewise defined functions > is presumably broken[#] (or not implemented): > > sage: f(f) > Traceback (most recent call last): > ... > TypeError: __call__() takes exactly 2 arguments (3 given) > > sage: f(f(x)) > Traceback (most recent call last): > ... > TypeError: __call__() takes exactly 2 arguments (3 given) > > So my question is: what should I do in order to implement piecewise > affine functions and the features I would like to have? Do you have > any good advise? > > Best, > --Xavier > > [#] By the way, I noticed: > sage: f(x) = 2*x + 3 > sage: f(f) > 4*x + 9 > Shouldn't it x |--> 4*x + 9 instead? > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Re: Is there a math alternative to range and interval?
On Thu, Oct 18, 2018 at 5:58 PM Kwankyu Lee wrote: > (2) interval should be redefined to give a list of Integers. Do you agree? I wouldn't change it, because that code that depends on how it works will break. And having a 1-year deprecation policy for this would be very ugly. Also, it doesn't start with "s" like srange and xsrange. Type "interval??" to see the source code of interval -- it's just a 1-line wrapper around range. That said, I didn't know about this function until just now, by the way. > (3) srange, xsrange are intended to be alternatives to range, for my purpose. They are versions in Sage, that behave more naturally wrt to their input types. > (4) is this "range" the vanilla python built-in? Yes. Type "range??" in Sage to see. > I suspect not because "range" accepts Integer input. If range was redefined > somewhere in sage to accept Integer as well as int, then perhaps range could > be redefined to give a list of Integers for Integer input and a list of ints > for int input. Am I wrong? > I would be wary of changing range, for fear of breaking code... > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- William (http://wstein.org) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: Is there a math alternative to range and interval?
Thanks for your inputs. Let me summarize: ellipsis notation: gives a list of Integers sage: [0..9] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] sage: preparse('[0..9]') '(ellipsis_range(Integer(0),Ellipsis,Integer(9)))' sage: type([0..9].pop()) ZZ.range: gives a list of integers sage: ZZ.range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] sage: type(ZZ.range(10).pop()) interval: gives a list of ints sage: interval(0,9) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] sage: type(interval(0,9).pop()) srange: gives a list of Integers sage: srange(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] sage: type(srange(10).pop()) xsrange: an interator that generates Integers. sage: xsrange(10) sage: [e for e in xsrange(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] range: gives a list of ints sage: range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] sage: type(range(10).pop()) sage: preparse('range(10)') 'range(Integer(10))' It seems to me: (1) ellipsis notation is easiest alternative for my purpose. (2) interval should be redefined to give a list of Integers. Do you agree? (3) srange, xsrange are intended to be alternatives to range, for my purpose. (4) is this "range" the vanilla python built-in? I suspect not because "range" accepts Integer input. If range was redefined somewhere in sage to accept Integer as well as int, then perhaps range could be redefined to give a list of Integers for Integer input and a list of ints for int input. Am I wrong? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Piecewise affine functions
Hello, For some application I have in mind (related to ticket #26471 for those who are interested), I need to have support for piecewise affine functions in Sage. More precisely, what I mostly need is: . to add, compose, take the sup/inf of these functions . to check continuity, convexity, bijectivity . to compute the inverse (for composition) when appropriate I'd be happy to implement this but I'm unsure how it should fit in the current framework. Notably, I noticed that there already exists support for piecewise defined functions: http://doc.sagemath.org/html/en/reference/functions/sage/functions/piecewise.html So I guess that I should derive from this class. But I'm unsure because I realized that the behavior of piecewise defined functions is sometimes a bit different for what I'd like to have. For instance, if f and g are PiecewiseAffineFunction, I would expect f + g to be a PiecewiseAffineFunction as well. And f.derivative() as well, etc. It's not exactly the case for piecewise defined function: sage: f = piecewise([((0,1), 2*x), ([-1,0], 3*x)]) sage: type(f) == type(f + f) False sage: type(f) == type(f.derivative()) False (I saw that there is a method piecewise_add() but I would expect it to be the default __add__; why isn't it the case?) Moreover it seems that composition of piecewise defined functions is presumably broken[#] (or not implemented): sage: f(f) Traceback (most recent call last): ... TypeError: __call__() takes exactly 2 arguments (3 given) sage: f(f(x)) Traceback (most recent call last): ... TypeError: __call__() takes exactly 2 arguments (3 given) So my question is: what should I do in order to implement piecewise affine functions and the features I would like to have? Do you have any good advise? Best, --Xavier [#] By the way, I noticed: sage: f(x) = 2*x + 3 sage: f(f) 4*x + 9 Shouldn't it x |--> 4*x + 9 instead? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: no conversion between number fields (extensions) over base rings which have conversion
On Thursday, October 18, 2018 at 11:55:14 AM UTC-7, Simon Brandhorst wrote: > I would say because there is no canonically defined embedding as one can > send i to -i as well. > > That's in principle true, but in sage names of generators carry essential information. For instance: sage: parent(QQ['x'].0+ZZ['x,y'].1) Multivariate Polynomial Ring in x, y over Rational Field so there's an argument to be made that the "natural" map in this case would be to map i to i. I think that choice could be justifiable in sage, but I also expect it will be too expensive to support properly in this case: One would also need to check that the minimal polynomials of the different "i"s are compatible. They are in this case, but that requires quite a bit of work to figure out. > On Thursday, October 18, 2018 at 1:38:24 PM UTC+2, Daniel Krenn wrote: >> >> sage: CyclotomicField(3).extension(x^2+1, 'i')(QQ.extension(x^2+1, >> 'i').gen()) >> >> returns >> >> TypeError: Cannot coerce element into this number field >> >> Does anyone have some idea why this is not working? >> >> (This is https://trac.sagemath.org/ticket/26443) >> >> Best, Daniel >> > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: no conversion between number fields (extensions) over base rings which have conversion
I would say because there is no canonically defined embedding as one can send i to -i as well. On Thursday, October 18, 2018 at 1:38:24 PM UTC+2, Daniel Krenn wrote: > > sage: CyclotomicField(3).extension(x^2+1, 'i')(QQ.extension(x^2+1, > 'i').gen()) > > returns > > TypeError: Cannot coerce element into this number field > > Does anyone have some idea why this is not working? > > (This is https://trac.sagemath.org/ticket/26443) > > Best, Daniel > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Is there a math alternative to range and interval?
IMHO the concept of type is mathematical enough to be mentioned early on, otherwise they'll continue to be confused by the difference between floats, ints, rationals, etc etc. So this is a very instructive for students kind of error you have hit. On Thu, 18 Oct 2018, 13:10 Kwankyu Lee, wrote: > Hi, > > I am teaching sage to a class of first year math students. Today I was > embarrassed when I tried > > [i.is_prime() for i in range(1,10)] > > because this raises an error. Until this point, I deliberately did not > mention that there are in fact two kinds of "integers" in sage and avoided > to explain about differences of "int" and "Integer". > > I think that it should be possible for math students to use sage without > ever knowing "int". Then there should be an alternative to "range" that > produces "Integer"s rather than "int"s. It seems that "interval" should > play that role. But to my disappointment, "interval" also produces list of > "int"s! > > Am I missing something? Is there an alternative to "range" and "interval" > for my purpose? If not, I suggest to redefine "interval" to produce > Integers (and make it iterator), because this is, I think, intended for > math students. I seek your opinions. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: Is there a math alternative to range and interval?
Le jeudi 18 octobre 2018 14:13:33 UTC+2, Simon King a écrit : > > > Such as srange(i,j)? > > Btw, I've just noticed that in Python3-built Sage 8.4.rc1, srange returns a list. Shouldn't it return an iterator instead? Eric. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: Is there a math alternative to range and interval?
Hi, An alternative to Simon's answer is sage: [i.is_prime() for i in [1..9]] [False, True, True, False, True, False, True, False, False] Best wishes, Eric. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Re: Is there a math alternative to range and interval?
Hi Kwankyu, On 2018-10-18, Kwankyu Lee wrote: > I am teaching sage to a class of first year math students. Today I was > embarrassed when I tried > > [i.is_prime() for i in range(1,10)] > > because this raises an error. Until this point, I deliberately did not > mention that there are in fact two kinds of "integers" in sage and avoided > to explain about differences of "int" and "Integer". > > I think that it should be possible for math students to use sage without > ever knowing "int". Then there should be an alternative to "range" that > produces "Integer"s rather than "int"s. Such as srange(i,j)? Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Is there a math alternative to range and interval?
Hi, I am teaching sage to a class of first year math students. Today I was embarrassed when I tried [i.is_prime() for i in range(1,10)] because this raises an error. Until this point, I deliberately did not mention that there are in fact two kinds of "integers" in sage and avoided to explain about differences of "int" and "Integer". I think that it should be possible for math students to use sage without ever knowing "int". Then there should be an alternative to "range" that produces "Integer"s rather than "int"s. It seems that "interval" should play that role. But to my disappointment, "interval" also produces list of "int"s! Am I missing something? Is there an alternative to "range" and "interval" for my purpose? If not, I suggest to redefine "interval" to produce Integers (and make it iterator), because this is, I think, intended for math students. I seek your opinions. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] no conversion between number fields (extensions) over base rings which have conversion
sage: CyclotomicField(3).extension(x^2+1, 'i')(QQ.extension(x^2+1, 'i').gen()) returns TypeError: Cannot coerce element into this number field Does anyone have some idea why this is not working? (This is https://trac.sagemath.org/ticket/26443) Best, Daniel -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.