-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperations.py
91 lines (78 loc) · 2.24 KB
/
Operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from sympy import *
# combiner = can combine atoms
# if used in generation, use random constant as second atom
# multiple input non combiner functions have generations in the 'secondInputGen'
# to use as the second input
# types are simple, trigonometry, exponential, power
allOperations = {
'add': {
'func': Add,
'atomCombiner': True,
'numInputs': 2,
'type': 'simple'
},
'subtract': {
'func': lambda x, y: Add(x, Mul(Integer(-1), y)),
'atomCombiner': True,
'numInputs': 2,
'type': 'simple'
},
'multiply': {
'func': Mul,
'atomCombiner': True,
'numInputs': 2,
'type': 'simple'
},
'divide': {
'func': lambda x, y: Mul(x, Pow(y, Integer(-1))),
'atomCombiner': True,
'numInputs': 2,
'type': 'simple'
},
'power': {
'func': Pow,
'atomCombiner': False,
'numInputs': 2,
'secondInputGen': lambda: 2,
'type': 'power'
},
#'root': {
# 'func': lambda x, y: Pow(x, Rational(1, y)),
# 'atomCombiner': False,
# 'numInputs': 2,
# 'secondInputGen': lambda: 2,
# 'type': 'power'
#},
#'logarithm': {
# 'func': log,
# 'atomCombiner': False,
# 'numInputs': 1,
# 'type': 'exponentials'
#},
#'exponential': {
# 'func': exp,
# 'atomCombiner': False,
# 'numInputs': 1,
# 'type': 'exponentials'
#},
#'sine': {
# 'func': sin,
# 'atomCombiner': False,
# 'numInputs': 1,
# 'type': 'trigonometry'
#},
#'cosine': {
# 'func': cos,
# 'atomCombiner': False,
# 'numInputs': 1,
# 'type': 'trigonometry'
#},
#'tangent': {
# 'func': tan,
# 'atomCombiner': False,
# 'numInputs': 1,
# 'type': 'trigonometry'
#}
}
def operationsOfType(t):
return {name:info for name, info in allOperations.items() if info['type'] == t}