/[escript]/branches/symbolic_from_3470/escript/py_src/symbolic/functions.py
ViewVC logotype

Contents of /branches/symbolic_from_3470/escript/py_src/symbolic/functions.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3474 - (show annotations)
Thu Mar 17 00:19:36 2011 UTC (7 years, 11 months ago) by caltinay
File MIME type: text/x-python
File size: 4909 byte(s)
Added a range of other functions that can now be used in symbolic expressions.
Not many simplifications implemented yet.

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 extra functions that can be used in symbolic expressions
24 """
25
26 from sympy.core.function import Function
27 from sympy import S
28
29 class wherePositive(Function):
30 """Returns:
31 1 where expr > 0
32 0 else
33 """
34 nargs = 1
35 is_bounded = True
36 is_negative = False
37 is_real = True
38
39 @classmethod
40 def eval(cls, arg):
41 if arg is S.NaN:
42 return S.NaN
43 if arg.is_positive: return S.One
44 if arg.is_negative or arg is S.Zero: return S.Zero
45 if arg.is_Function:
46 if arg.func is wherePositive: return arg
47 if arg.func is whereNegative: return arg
48
49 def _eval_conjugate(self):
50 return self
51
52 def _eval_derivative(self, x):
53 return S.Zero
54
55 class whereNonPositive(Function):
56 """Returns:
57 0 where expr > 0
58 1 else
59 """
60 nargs = 1
61 is_bounded = True
62 is_negative = False
63 is_real = True
64
65 @classmethod
66 def eval(cls, arg):
67 return 1-wherePositive(arg)
68
69 def _eval_conjugate(self):
70 return self
71
72 def _eval_derivative(self, x):
73 return S.Zero
74
75 class whereNegative(Function):
76 """Returns:
77 1 where expr < 0
78 0 else
79 """
80 nargs = 1
81 is_bounded = True
82 is_negative = False
83 is_real = True
84
85 @classmethod
86 def eval(cls, arg):
87 if arg is S.NaN:
88 return S.NaN
89 if arg.is_nonnegative: return S.Zero
90 if arg.is_negative: return S.One
91 if arg.is_Function:
92 if arg.func is wherePositive: return S.Zero
93
94 def _eval_conjugate(self):
95 return self
96
97 def _eval_derivative(self, x):
98 return S.Zero
99
100 class whereNonNegative(Function):
101 """Returns:
102 0 where expr < 0
103 1 else
104 """
105 nargs = 1
106 is_bounded = True
107 is_negative = False
108 is_real = True
109
110 @classmethod
111 def eval(cls, arg):
112 return 1-whereNegative(arg)
113
114 def _eval_conjugate(self):
115 return self
116
117 def _eval_derivative(self, x):
118 return S.Zero
119
120 class whereZero(Function):
121 """Returns:
122 1 where expr == 0
123 0 else
124 """
125 nargs = 1
126 is_bounded = True
127 is_negative = False
128 is_real = True
129
130 @classmethod
131 def eval(cls, arg):
132 if arg is S.NaN:
133 return S.NaN
134 if arg.is_zero: return S.One
135 if arg.is_nonzero: return S.Zero
136 if arg.is_Function:
137 if arg.func is whereZero: return 1-arg
138
139 def _eval_conjugate(self):
140 return self
141
142 def _eval_derivative(self, x):
143 return S.Zero
144
145 class whereNonZero(Function):
146 """Returns:
147 0 where expr == 0
148 1 else
149 """
150 nargs = 1
151 is_bounded = True
152 is_negative = False
153 is_real = True
154
155 @classmethod
156 def eval(cls, arg):
157 return 1-whereZero(arg)
158
159 def _eval_conjugate(self):
160 return self
161
162 def _eval_derivative(self, x):
163 return S.Zero
164
165 class log10(Function):
166 """Returns the base-10 logarithm of the argument (same as log(x,10))
167 """
168 nargs = 1
169
170 @classmethod
171 def eval(cls, arg):
172 from sympy.functions.elementary.exponential import log
173 return log(arg,10)
174
175 class inverse(Function):
176 """Returns the inverse of the argument
177 """
178 nargs = 1
179
180 class minval(Function):
181 """Returns the minimum value over all components of the argument
182 """
183 nargs = 1
184
185 class maxval(Function):
186 """Returns the maximum value over all components of the argument
187 """
188 nargs = 1
189
190 class trace(Function):
191 """Returns the trace of the argument with optional axis_offset
192 """
193 nargs = (1,2)
194
195 class transpose(Function):
196 """Returns the transpose of the argument
197 """
198 nargs = (1,2)
199
200 class symmetric(Function):
201 """Returns the symmetric part of the argument
202 """
203 nargs = 1
204
205 class nonsymmetric(Function):
206 """Returns the non-symmetric part of the argument
207 """
208 nargs = 1
209
210 class swap_axes(Function):
211 """Returns the 'swap' of the argument
212 """
213 nargs = (1,2,3)
214
215 class grad(Function):
216 """Returns the spatial gradient of the argument
217 """
218 nargs = (1,2)
219
220 #
221 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26