/[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 3473 - (show annotations)
Wed Mar 16 05:54:30 2011 UTC (8 years, 5 months ago) by caltinay
File MIME type: text/x-python
File size: 2819 byte(s)
Added where(Non)Negative/Positive symbolic functions.

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 #
121 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26