Changeset 7868:11c9d8388d66
- Timestamp:
- 12/22/07 18:49:39 (5 years ago)
- Branch:
- default
- Parents:
- 7853:186281b13d81 (diff), 7867:f843ab589376 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- sage
- Files:
-
- 7 edited
-
calculus/calculus.py (modified) (7 diffs)
-
calculus/calculus.py (modified) (4 diffs)
-
graphs/graph.py (modified) (2 diffs)
-
graphs/graph.py (modified) (1 diff)
-
plot/plot3d/base.pyx (modified) (8 diffs)
-
plot/plot3d/base.pyx (modified) (1 diff)
-
server/notebook/notebook.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sage/calculus/calculus.py
r7837 r7868 614 614 param = A[0] 615 615 f = lambda x: self(x) 616 #f = self.fast_float_function() 616 617 else: 617 618 A = self.variables() … … 3032 3033 return self.parent()(self._maxima_().partfrac(var)) 3033 3034 3034 3035 3035 ################################################################### 3036 # Fast Evaluation 3037 ################################################################### 3038 def fast_float_function(self): 3039 return self._fast_float_() 3040 3041 def _fast_float_(self): 3042 return lambda x: float(self(x)) 3043 3036 3044 3037 3045 class Symbolic_object(SymbolicExpression): … … 3187 3195 if isinstance(self._obj, int): 3188 3196 return True 3197 3198 def _fast_float_(self): 3199 z = float(self) 3200 return lambda x: z 3189 3201 3190 3202 def _recursive_sub(self, kwds): … … 4214 4226 return hash(self._name) 4215 4227 4228 def _fast_float_(self): 4229 return lambda x: x 4230 4216 4231 def _recursive_sub(self, kwds): 4217 4232 # do the replacement if needed … … 4969 4984 return float(f._approx_(float(g))) 4970 4985 4986 def _fast_float_(self): 4987 f = self._operands[0]._fast_float_() 4988 g = self._operands[1]._fast_float_() 4989 return lambda x: f(g(x)) 4990 4971 4991 def __complex__(self): 4972 4992 """ … … 5370 5390 return SymbolicComposition(self, SR(x)) 5371 5391 5392 def _fast_float_(self): 5393 return math.sin 5394 5372 5395 sin = Function_sin() 5373 5396 _syms['sin'] = sin … … 5392 5415 return math.cos(x) 5393 5416 return SymbolicComposition(self, SR(x)) 5417 5418 def _fast_float_(self): 5419 return math.cos 5394 5420 5395 5421 -
sage/calculus/calculus.py
r7866 r7868 2012 2012 sage: f(x) = exp(-sqrt(x)) 2013 2013 sage: f.nintegral(x, 0, 1) 2014 (0.52848223531423055, 4.163 3141378838452e-11, 231, 0)2014 (0.52848223531423055, 4.163...e-11, 231, 0) 2015 2015 2016 2016 We can also use the \code{numerical_integral} function, which calls … … 2064 2064 maximum_num_subintervals) 2065 2065 except TypeError, err: 2066 if "ERROR NUMBER = 6" in str(err):2066 if "ERROR" in str(err): 2067 2067 raise ValueError, "Maxima (via quadpack) cannot compute the integral to that precision" 2068 2068 else: … … 3565 3565 def number_of_arguments(self): 3566 3566 """ 3567 Returns the number of argu ements this object can take.3567 Returns the number of arguments this object can take. 3568 3568 3569 3569 EXAMPLES: … … 4864 4864 """ 4865 4865 SymbolicOperation.__init__(self, [f,g]) 4866 4867 def _polynomial_(self, R): 4868 """ 4869 Symbolic compositions cannot be converted to polynomials unless 4870 they are constants. 4871 4872 EXAMPLES: 4873 sage: sqrt(2).polynomial(RR) 4874 1.41421356237310 4875 4876 sage: sqrt(2).polynomial(CC) 4877 1.41421356237310 4878 4879 sage: cos(x).polynomial(QQ) 4880 Traceback (most recent call last): 4881 .... 4882 TypeError: cannot convert self (= cos(x)) to a polynomial 4883 4884 sage: sqrt(x).polynomial(QQ) 4885 Traceback (most recent call last): 4886 .... 4887 TypeError: cannot convert self (= sqrt(x)) to a polynomial 4888 4889 sage: K3.<a> = NumberField(sqrt(x)) 4890 Traceback (most recent call last): 4891 .... 4892 TypeError: polynomial (=sqrt(x)) must be a polynomial. 4893 """ 4894 if self.number_of_arguments() == 0: 4895 #Convert self into R's base ring and then into R since 4896 #self must be a constant. 4897 return R( R.base_ring()(self) ) 4898 else: 4899 raise TypeError, "cannot convert self (= %s) to a polynomial"%str(self).strip() 4900 4901 4902 def number_of_arguments(self): 4903 """ 4904 Returns the number of arguments that self can take. 4905 4906 EXAMPLES: 4907 sage: sqrt(x).number_of_arguments() 4908 1 4909 sage: sqrt(2).number_of_arguments() 4910 0 4911 """ 4912 try: 4913 return self.__number_of_args 4914 except AttributeError: 4915 pass 4916 variables = self.variables() 4917 if not self.is_simplified(): 4918 n = self.simplify().number_of_arguments() 4919 else: 4920 # Note that we use self._operands[1:] so we don't include the 4921 # number of arguments that the function takes since it is 4922 # already being "called" 4923 n = max( max(map(lambda i: i.number_of_arguments(), self._operands[1:])+[0]), len(variables) ) 4924 self.__number_of_args = n 4925 return n 4866 4926 4867 4927 def _recursive_sub(self, kwds): -
sage/graphs/graph.py
r7824 r7868 2815 2815 color_by_label=color_by_label, 2816 2816 heights=heights).show(**kwds) 2817 2818 2819 def plot3d_new(self, bgcolor=(1,1,1), 2820 vertex_colors=None, vertex_size=0.06, 2821 edge_colors=None, edge_size=0.015, 2822 pos3d=None, 2823 iterations=50, color_by_label=False, **kwds): 2824 from sage.plot.plot3d.all import Sphere, LineSegment, Arrow 2825 line = Arrow if self.is_directed() else Line 2826 2827 verts = self.vertices() 2828 2829 if vertex_colors is None: 2830 vertex_colors = { (1,0,0) : verts } 2831 if pos3d is None: 2832 pos3d = graph_fast.spring_layout_fast(self, dim=3, iterations=iterations) 2833 2834 if color_by_label: 2835 if edge_colors is None: 2836 # do the coloring 2837 edge_colors = self._color_by_label(format='rgbtuple') 2838 elif edge_colors is None: 2839 edge_colors = { (0,0,0) : self.edges() } 2840 2841 try: 2842 graphic = 0 2843 for color in vertex_colors: 2844 for v in vertex_colors[color]: 2845 graphic += Sphere(vertex_size, color=color).translate(*pos3d[v]) 2846 2847 for color in edge_colors: 2848 for u, v, l in edge_colors[color]: 2849 graphic += line(pos3d[u], pos3d[v], radius=edge_size, color=color, closed=False) 2850 2851 return graphic 2852 2853 except KeyError: 2854 raise KeyError, "Oops! You haven't specified positions for all the vertices." 2855 2856 2817 2857 2818 2858 def transitive_closure(self): … … 4885 4925 f.write( print_graph_eps(self.vertices(), self.edge_iterator(), pos) ) 4886 4926 f.close() 4887 4927 4928 4888 4929 def plot3d(self, bgcolor=(1,1,1), 4889 4930 vertex_colors=None, vertex_size=0.06, -
sage/graphs/graph.py
r7866 r7868 4188 4188 sage: E[0][0] 4189 4189 -1.61803398875 4190 sage: E[1][0] 4190 sage: E[1][0] # eigenspace computation is somewhat random 4191 4191 Vector space of degree 5 and dimension 1 over Real Double Field 4192 4192 User basis matrix: -
sage/plot/plot3d/base.pyx
r7848 r7868 46 46 import os 47 47 from math import atan2 48 from random import randint 48 49 49 50 import sage.misc.misc … … 68 69 69 70 def __add__(self, other): 70 if other is 0 or other is None: 71 # Use == not "other is 0" here, since e.g., Sage integer zero is not 0. 72 if other == 0 or other is None: 71 73 return self 72 elif self is0 or self is None:74 elif self == 0 or self is None: 73 75 return other 74 76 return Graphics3dGroup([self, other]) … … 175 177 return "\n".join(flatten_list([self.obj_repr(render_params), ""])) 176 178 177 def export_jmol(self, filename='jmol_shape. script'):179 def export_jmol(self, filename='jmol_shape.jmol', force_reload=False, zoom=100, spin=False, background=(1,1,1), stereo=False): 178 180 render_params = self.default_render_params() 179 181 render_params.output_file = filename 182 render_params.force_reload = render_params.randomize_counter = force_reload 180 183 f = open(filename, 'w') 184 # Set the scene background color 185 f.write('background [%s,%s,%s]\n'%tuple([int(a*255) for a in background])) 186 if spin: 187 f.write('spin ON\n') 188 else: 189 f.write('spin OFF\n') 190 if stereo: 191 if stereo is True: stereo = "redblue" 192 f.write('stereo %s\n' % stereo) 193 194 f.write('zoom %s\n'%zoom) 195 196 # Put the rest of the object in 181 197 f.write("\n".join(flatten_list([self.jmol_repr(render_params), ""]))) 182 198 f.close() 183 199 184 200 def jmol_repr(self, render_params): 185 201 raise NotImplementedError 186 202 187 203 def texture_set(self): 188 204 return set() … … 197 213 return self.transform(T=T) 198 214 199 def show(self, filename="shape", verbosity=0, **kwds): 215 def show(self, viewer="jmol", filename="shape", verbosity=0, figsize=4, **kwds): 216 """ 217 INPUT: 218 viewer -- string (default: 'jmol') which viewing system to use. 219 'jmol': an embedded non-OpenGL 3d java applet 220 'tachyon': an embedded ray tracer 221 'java3d': a popup OpenGL 3d java applet 222 filename -- string (default: 'shape'); file to save the image to 223 verbosity -- display information about rendering the figure 224 figsize -- (default: 4); x or pair [x,y] for numbers, e.g., [4,4]; controls 225 the size of the output figure. E.g., with jmol the number of 226 pixels in each direction is 100 times figsize[0]. 227 **kwds -- other options, which make sense for particular rendering engines 228 """ 229 if not isinstance(figsize, (list,tuple)): 230 figsize = [figsize, figsize] 200 231 from sage.plot.plot import EMBEDDED_MODE, DOCTEST_MODE 232 import sage.misc.misc 233 ext = None 201 234 if DOCTEST_MODE: 202 235 opts = '-res 10 10' … … 204 237 else: 205 238 opts = '' 206 tachyon_rt(self.tachyon(**kwds), filename+".png", verbosity, True, opts) 207 f = open(filename+".obj", "w") 208 f.write("mtllib %s.mtl\n" % filename) 209 f.write(self.obj()) 210 f.close() 211 f = open(filename+".mtl", "w") 212 f.write(self.mtl_str()) 213 f.close() 239 240 if DOCTEST_MODE or viewer=='tachyon' or (viewer=='java3d' and EMBEDDED_MODE): 241 tachyon_rt(self.tachyon(**kwds), filename+".png", verbosity, True, opts) 242 ext = "png" 243 import sage.misc.viewer 244 viewer_app = sage.misc.viewer.browser() 245 if DOCTEST_MODE or viewer=='java3d': 246 f = open(filename+".obj", "w") 247 f.write("mtllib %s.mtl\n" % filename) 248 f.write(self.obj()) 249 f.close() 250 f = open(filename+".mtl", "w") 251 f.write(self.mtl_str()) 252 f.close() 253 ext = "obj" 254 viewer_app = sage.misc.misc.SAGE_LOCAL + "/java/java3d/start_viewer" 255 256 if DOCTEST_MODE or viewer=='jmol': 257 # Encode the desired applet size in the end of the filename: 258 base, ext = os.path.splitext(filename) 259 filename = '%s-size%s%s'%(base, figsize[0]*100, ext) 260 self.export_jmol(filename + ".jmol", force_reload=EMBEDDED_MODE, **kwds) 261 viewer_app = sage.misc.misc.SAGE_LOCAL + "/java/jmol/jmol" 262 ext = "jmol" 263 264 if ext is None: 265 raise ValueError, "Unknown 3d plot type: %s" % viewer 214 266 if not DOCTEST_MODE and not EMBEDDED_MODE: 215 267 viewer = sage.misc.misc.SAGE_LOCAL + "/java/java3d/start_viewer" 216 268 os.system("%s %s.obj 2>/dev/null 1>/dev/null &"%(viewer, filename)) 217 269 if verbosity: 270 pipes = "2>&1" 271 else: 272 pipes = "2>/dev/null 1>/dev/null &" 273 os.system('%s "%s.%s" %s' % (viewer_app, filename, ext, pipes)) 218 274 219 275 class Graphics3dGroup(Graphics3d): … … 378 434 return "Center %s radius %s" % (self.cen, self.r) 379 435 def __add__(self, other): 436 # Use == not "other is 0" here, since e.g., Sage integer zero is not 0. 437 if other == 0 or other is None: 438 return self 439 elif self == 0 or self is None: 440 return other 380 441 if self.cen == other.cen: 381 442 return self if self.r > other.r else other … … 397 458 def __init__(self, **kwds): 398 459 self._uniq_counter = 0 460 self.randomize_counter = 0 399 461 self.output_file = sage.misc.misc.tmp_filename() 400 462 self.obj_vertex_offset = 1 … … 415 477 416 478 def unique_name(self, desc="name"): 417 self._uniq_counter += 1 479 if self.randomize_counter: 480 self._uniq_counter = randint(1,1000000) 481 else: 482 self._uniq_counter += 1 418 483 return "%s_%s" % (desc, self._uniq_counter) 419 484 -
sage/plot/plot3d/base.pyx
r7866 r7868 265 265 raise ValueError, "Unknown 3d plot type: %s" % viewer 266 266 if not DOCTEST_MODE and not EMBEDDED_MODE: 267 viewer = sage.misc.misc.SAGE_LOCAL + "/java/java3d/start_viewer" 268 os.system("%s %s.obj 2>/dev/null 1>/dev/null &"%(viewer, filename)) 267 269 if verbosity: 268 270 pipes = "2>&1" -
sage/server/notebook/notebook.py
r7848 r7868 1422 1422 1423 1423 head +=' <script type="text/javascript" src="/javascript/sage3d.js"></script>\n' 1424 head +=' <script type="text/javascript" src="/java/jmol/appletweb/Jmol.js"></script>\n' 1425 head +=' <script>jmolInitialize("/java/jmol");</script>\n' # this must stay in the <body> 1424 1426 return head 1425 1427
Note: See TracChangeset
for help on using the changeset viewer.
