Re: [sage-support] Re: Set and real intervals
>It seems like it would be relatively easy to implement a Sage class >for real intervals that represents finite unions of open, closed, half >open, and unbounded intervals and implements union() and >intersection() methods. I did it. I attach my piece of code. This is only python, but it is going to make the job. Technically I define a class Interval that represent an interval (closed or open at each extremities). This class has the important __contrain__() method that tests if a number is contained in the interval. Then class ContinuousSet that represent finite union and intersections of intervals. Its main attribute is a list of disjoint intervals. These intervals represent the set. For the moment, I have working union() and __contain__() methods; the delicate part is to express the union of two lists of disjoints intervals as a new list of disjoint intervals. I'm working on intersections and I plan to be able to test inclusion. doctest of the working methods are included in the code. Up to writing better documentation and finishing the work, do one think that it can be included in some place in Sage ? Have a good day Laurent -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org #! /usr/bin/python # -*- coding: utf8 -*- import doctest def constructorContinuouSet(A): if type(A)==ContinuousSet: return A if type(A)==Interval: return ContinuousSet([A],[]) def EmptySet(): return ContinuousSet([],[]) class Interval(object): """ Represent the real interval between a and b. By default, the interval is closed : [a,b] if low_open is false, the interval is lower opened if up_open is false, the interval is upper opened. Examples DEFINITION OF INTERVALS >>> I=Interval(0,2,low_open=False,up_open=True) >>> J=Interval(-2,-1) >>> K=Interval(1,3,low_open=False,up_open=True) >>> print I [0 , 2[ >>> print J [-2 , -1] >>> print K [1 , 3[ INTERSECTION >>> X = I.intersection(K) >>> print X [1 , 2[ >>> print 1 in X True >>> print 2 in X False FUSION The intervals I and J have no intersection, so the union is disjoint : >>> Y=I.fusion(J) >>> for a in Y: ... print a [0 , 2[ [-2 , -1] The intervals I and K have intersection, so the union is one interval: >>> Y=I.fusion(K) >>> for a in Y: ... print a ... [0 , 3[ UNION Asking the union of two intervals returns an object ContinuousSet >>> import math >>> I=Interval(1,4,low_open=False,up_open=False) >>> J=Interval(0,2,low_open=True,up_open=True) >>> M=Interval(7,8,low_open=True,up_open=False) >>> print I.union(J) ]0 , 4] >>> print I.union(M) ]7 , 8] U [1 , 4] >>> 7 in I.union(M) False >>> math.pi in I.union(M) True """ def __init__(self,a,b,low_open=False,up_open=False): self.low_bound=a self.up_bound=b self.low_open=low_open self.up_open=up_open def contains_oo(x): if x>a and xa and x<=b : return True return False def contains_co(x): if x>=a and x=a and x<=b : return True return False if self.low_open and self.up_open: self.contains=contains_oo elif self.low_open and not self.up_open: self.contains=contains_oc elif not self.low_open and self.up_open: self.contains=contains_co elif not self.low_open and not self.up_open: self.contains=contains_cc def intersection(self,A): if self.low_bound in A or self.up_bound in A or A.low_bound in self or A.up_bound in self : low_bound=self.low_bound up_bound=self.up_bound low_open=self.low_open up_open=self.up_open if A.low_bound>self.low_bound: low_bound=A.low_bound low_open=A.low_open if A.low_bound==self.low_bound: low_open = self.low_bound and A.low_bound if A.up_bound>> I=Interval(1,4,low_open=False,up_open=False) >>> J=Interval(0,2,low_open=True,up_open=True) >>> K=Interval(3,5,low_open=False,up_open=True) >>> L=Interval(6,7,low_open=False,up_open=False) >>> X=I.fusion_with_list([J,K,L]) >>> for a in X: ... print a [6 , 7] ]0 , 5[ The result does not depend on the order of the list: >>> X=I.fusion_with_list([L,K,J]) >>> for a in X: ... print a [6 , 7] ]0 , 5[ """ new_list=[] happend_fusion=False for I in intervals_list: a = self.fusion(I) if len(a)==1: if happend_fusion == False: new_guy=a[0] happend_fusion=True else : new_list.append(a[0]) if len(a)==2: new_list.append(I) if happend_fusion : return new_guy.fusion_with_list(new_list) else : new_list.append(self) return tuple(new_list) def union(self,A): return constructorContinuouSet(self).union(constructorContinuouSet(A)) def copy(self): """ Return a copy of the interval which is a new object. >>> I=Interval(1,4,low_open=False,up_open=False) >>> X=I.copy() >>> I.low_open=T
[sage-support] experimental vtk_meta_1 package (sage 4.6 ubuntu linux 10.04.1 LTS)
I have tried installing this package without success on a source build of sage 4.6 - (I can forward the full build log to the maintainer if required - and it seems maybe some opengl libraries or some linkage might be missing - the only package to fail is vtk itsellf - relevant extract of log below). I can try and correct this but I am reluctant to try again as every time I attempt this lengthy build the sage system is hosed in that any attempt to use the notebook seems to indicate that the symbol __iteract__ has gone missing! I am obliged to reinstall (or rollback the entire sage tree) in order to get a working system again. Anyone with similar experiences, hints or tips to getting this installed cleanly would be much appreciated. ... -- Looking for glXGetProcAddressARB -- Looking for glXGetProcAddressARB - not found -- Looking for glXGetProcAddress -- Looking for glXGetProcAddress - not found -- Could not find extension loader. Extensions disabled. CMake Error: This project requires some variables to be set, and cmake can not find them. Please set the following variables: OPENGL_INCLUDE_DIR (ADVANCED) OPENGL_gl_LIBRARY (ADVANCED) -- Configuring done Error configuring VTK real0m27.959s user0m6.890s sys 0m3.500s sage: An error occurred while installing vtk-5.0.3-1 Please email sage-devel http://groups.google.com/group/sage-devel explaining the problem and send the relevant part of of /usr/local/sage/install.log. Describe your computer, operating system, etc. If you want to try to fix the problem yourself, *don't* just cd to /usr/local/sage/spkg/build/vtk-5.0.3-1 and type 'make check' or whatever is appropriate. Instead, the following commands setup all environment variables correctly and load a subshell for you to debug the error: (cd '/usr/local/sage/spkg/build/vtk-5.0.3-1' && '/usr/local/sage/sage' -sh) When you are done debugging, you can type "exit" to leave the subshell. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: show()ing 3-tuples of matrices as images?
On Dec 9, 9:57 pm, Dan Drake wrote: > *facepalm* That was stupid -- matrix_plot() already accepts numpy arrays > of shape (x,y,3) and plots them as a color image exactly the way I want. > No need to mess around with pylab.imshow(). > > Sorry for the noise. Actually, your message gave me some good ideas of how to visualize the SVD decomposition in my linear algebra class, so not noise at all :) Thanks, Joris -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: experimental vtk_meta_1 package (sage 4.6 ubuntu linux 10.04.1 LTS)
seb wrote: I have tried installing this package without success on a source build of sage 4.6 - (I can forward the full build log to the maintainer if required - and it seems maybe some opengl libraries or some linkage might be missing - the only package to fail is vtk itsellf - relevant extract of log below). The experimental vtk_meta package is hopeless out of date! Have a look at: http://sage.math.washington.edu/home/jsp/SPKGS/ETS/ I didn't put much effort in maintaining lately, so you may be on your own. But I'm happy to answer questions. Cheers, Jaap I can try and correct this but I am reluctant to try again as every time I attempt this lengthy build the sage system is hosed in that any attempt to use the notebook seems to indicate that the symbol __iteract__ has gone missing! I am obliged to reinstall (or rollback the entire sage tree) in order to get a working system again. Anyone with similar experiences, hints or tips to getting this installed cleanly would be much appreciated. ... -- Looking for glXGetProcAddressARB -- Looking for glXGetProcAddressARB - not found -- Looking for glXGetProcAddress -- Looking for glXGetProcAddress - not found -- Could not find extension loader. Extensions disabled. CMake Error: This project requires some variables to be set, and cmake can not find them. Please set the following variables: OPENGL_INCLUDE_DIR (ADVANCED) OPENGL_gl_LIBRARY (ADVANCED) -- Configuring done Error configuring VTK real0m27.959s user0m6.890s sys 0m3.500s sage: An error occurred while installing vtk-5.0.3-1 Please email sage-devel http://groups.google.com/group/sage-devel explaining the problem and send the relevant part of of /usr/local/sage/install.log. Describe your computer, operating system, etc. If you want to try to fix the problem yourself, *don't* just cd to /usr/local/sage/spkg/build/vtk-5.0.3-1 and type 'make check' or whatever is appropriate. Instead, the following commands setup all environment variables correctly and load a subshell for you to debug the error: (cd '/usr/local/sage/spkg/build/vtk-5.0.3-1'&& '/usr/local/sage/sage' -sh) When you are done debugging, you can type "exit" to leave the subshell. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] Re: show()ing 3-tuples of matrices as images?
On Fri, 10 Dec 2010 at 10:09AM -0800, jvkersch wrote: > Actually, your message gave me some good ideas of how to visualize the > SVD decomposition in my linear algebra class, so not noise at all :) I'll publish my worksheet when I'm finished and post back here. Dan -- --- Dan Drake - http://mathsci.kaist.ac.kr/~drake --- signature.asc Description: Digital signature
[sage-support] Confused about rmul and lmul
Hi, Below is a passage in the Reference manual on the coercion model: If R is the base of S (as in the first example), simply implement _rmul_ and/or _lmul_ on the Elements of S. In this case r * s gets handled as s._rmul_(r) and s * r as s._lmul_(r). The argument to _rmul_ and _lmul_ are guaranteed to be Elements of the base of S (with coercion happening beforehand if necessary). The second sentence seems wrong. "rmul" and "lmul" seems reversed. Am I right? or am I confused? At least, the following docs are inconsistent with the sentence. sage: r=1/2; parent(r) Rational Field sage: P.=QQ[x] sage: s=1/2*x;parent(s) Univariate Polynomial Ring in x over Rational Field sage: s._rmul_? ... Definition: s._rmul_(self, right) Docstring: File: sage/rings/polynomial/polynomial_rational_flint.pyx (starting at line 933) Returns self * right, where right is a rational number. ... sage: s._lmul_? ... Definition: s._lmul_(self, right) Docstring: File: sage/rings/polynomial/polynomial_rational_flint.pyx (starting at line 913) Returns right times self, where right is a rational number. -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org