Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pow(a,b) not supported as such #29

Open
rll2021 opened this issue Apr 19, 2021 · 5 comments
Open

pow(a,b) not supported as such #29

rll2021 opened this issue Apr 19, 2021 · 5 comments

Comments

@rll2021
Copy link

rll2021 commented Apr 19, 2021

The code assumes that binary operators are infix. No prefix binary operator is handled correctly, viz., 'atan2(a,b)', 'pow(a,b)'. While atan2 is noted as "NOT supported at this time" in file operators_list.txt, we do not so denote pow.

  • I propose to add 'pow(a,b)' to the "NOT supported" list, with a parenthetical note that the infix form (a**b) is supported.

Additionally, 'pow' appears twice in the set 'operators' in base_class.py, first as "ast.Pow: tf.pow, # e.g., a ** 2", and later as "'pow': tf.pow, # e.g., pow(a, b)".

  • I propose striking the latter.
@asksak
Copy link

asksak commented May 10, 2021

The code assumes that binary operators are infix. No prefix binary operator is handled correctly, viz., 'atan2(a,b)', 'pow(a,b)'. While atan2 is noted as "NOT supported at this time" in file operators_list.txt, we do not so denote pow.

  • I propose to add 'pow(a,b)' to the "NOT supported" list, with a parenthetical note that the infix form (a**b) is supported.

Additionally, 'pow' appears twice in the set 'operators' in base_class.py, first as "ast.Pow: tf.pow, # e.g., a ** 2", and later as "'pow': tf.pow, # e.g., pow(a, b)".

  • I propose striking the latter.

Hello,

a^b is a good idea, I've been looking for operators to add.

Will do it and post the method.

Regards

Aymen

@kstaats
Copy link
Owner

kstaats commented Jun 2, 2021 via email

@rll2021
Copy link
Author

rll2021 commented Jun 2, 2021

No, I do not, but the suggestion I made above is a two line fix.
I have not heard from Asksak, so I don't know if he has anything.

@asksak
Copy link

asksak commented Jun 17, 2021

No, I do not, but the suggestion I made above is a two line fix.
I have not heard from Asksak, so I don't know if he has anything.

Hello,

The first (pow) is ** in operators and is x^2, while the second (pow) is pow in operators which is a^b so I did this in labels:

def fx_eval_label(self, tree, node_id):
	
		'''
		Evaluate all or part of a Tree (starting at node_id) and return a raw mutivariate expression ('algo_raw').
		
		This method is called once per Tree, but may be called at any time to prepare an expression for any full or 
		partial (branch) Tree contained in 'population'. Pass the starting node for recursion via the local variable 
		'node_id' where the local variable 'tree' is a copy of the Tree you desire to evaluate.
		
		Called by: fx_eval_poly, fx_eval_label (recursively)
		
		Arguments required: tree, node_id
		'''
		
		# if tree[6, node_id] == 'not': tree[6, node_id] = ', not' # temp until this can be fixed at data_load
		
		node_id = int(node_id)
		
		if tree[8, node_id] == '0': # arity of 0 for the pattern '[term]'
			return tree[6, node_id] # 'node_label' (function or terminal)
			
		else:
			if tree[8, node_id] == '1': # arity of 1 for the explicit pattern 'not [term]'
				return tree[6, node_id] + self.fx_eval_label(tree, tree[9, node_id])	 # rll 20210201

			elif tree[8, node_id] == '2': # arity of 2 for the pattern '[func] [term] [func]'
				if tree[6, node_id] == 'min':
					return tree[6, node_id]  + self.fx_eval_label(tree, tree[9, node_id]) + self.fx_eval_label(tree, tree[10, node_id]) #asksak
				if tree[6, node_id] == 'max':
					return tree[6, node_id]  + self.fx_eval_label(tree, tree[9, node_id]) + self.fx_eval_label(tree, tree[10, node_id]) #asksak
				if tree[6, node_id] == 'pow':
					return tree[6, node_id]  + self.fx_eval_label(tree, tree[9, node_id]) + self.fx_eval_label(tree, tree[10, node_id]) #asksak, could combine all three lines with OR
				else:
					return self.fx_eval_label(tree, tree[9, node_id]) + tree[6, node_id] + self.fx_eval_label(tree, tree[10, node_id])	#asksak
				
			elif tree[8, node_id] == '3': # arity of 3 for the explicit pattern 'if [term] then [term] else [term]'
				# This fails in sympify. rll 20210206
				#This needs a new set of code. #asksak
				return tree[6, node_id] + self.fx_eval_label(tree, tree[9, node_id]) + ' then ' + self.fx_eval_label(tree, tree[10, node_id]) + ' else ' + self.fx_eval_label(tree, tree[11, node_id])

Note THE ARITY:

operator, arity
+,2
-,2
*,2
/,2
**,2
min,2
max,2
pow,2
sqrt,1
abs,1
log,1
cos,1
sin,1
exp,1
expm1,1

I will add all the code when I learn where and how to upload on GitHub.

As a side note (so far)

  1. I added min, max
  2. I fixed arity
  3. I modified fx_eval_label for compatibility
  4. I added dynamic mutation and standard mutation, both selectable at program startup
  5. I optimized memory utilization of the program (collected garbage)
  6. I optimized variable assignment
  7. I optimized loops
  8. I removed all '(' and ',' from fx_eval_label which I had added but turned out to interfere with sympy, kstaats version was better.
  9. I tested all the above with known test functions and all results solved in a few generations.

Will update u soon

@kstaats
Copy link
Owner

kstaats commented Jul 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants