Re: The "evolution" of GA Math
- Posted by DB James <larch at adelphia.net> Oct 03, 2005
- 608 views
Al Getz wrote: SNIP > > Hi Quark, > > Yes, i had found that eval.e cant handle a multiplication before > a function such as a*ln(x) or k*sin(x), etc., so i ended up doing > the same thing temporarily. Putting parens around the function > seemed to work so i did that too: y=a*(ln(x+1)) > This means i was doing basically the same thing you were doing :) > BTW i used "ln" instead of "log" because in the math world "log" > usually refers to log base 10 and ln refers to log base e, and > in GA Math i ended up making it skip the "l" and the "n" as variables > (it wanted to make l and n variables at first). > > The interesting thing is, both of your runs came out algebraically > either exact or nearly so, so perhaps my run was a fluke or something > where it somehow got sidetracked, or perhaps returning a large > negative number as a 'penalty' isnt a good idea? > So what did you use for the log function in GA Math then... > when the number is positive i guess it's log(), but what about > when it's negative, or zero? Those are three possibilities so > if i knew what lines you used in GA Math for function #11 i could > try the same. > > > Take care, > Al Hello Al, Here is the relevant code: elsif op=11 then --decimal fraction if p[i][REG][from1]>0 then p[i][REG][store]=log(p[i][REG][from1]) else --"null" response... p[i][REG][store]=0 end if The GA Math "experience" seems to be a study in the complex interaction of decisions made in coding. There never seems to be a state where one can say: "I have ideally optimized this". If we had access to a nice used NSA super-computer, we could set it to work on ways to evolve self-optimizing code :^D By the way, you may want to pop the already existing trig functions of eval.e into GA Math to see what effect that has on some of your test problems. I dont't know how you want to handle the modification necessary to get GA Math to deal with multiple-character tokens in formula entry. Here is what I did, in case it is useful to you: At the top I added a new constant to be a list of recognizable functions: constant EVALKEYWORDS={"log"}--many could be added here Then I created the MarkMatch function (not tested carefully yet): ------------------------------------------------- function MarkMatch(sequence s,sequence m) --Quark 10/05 --create sequence with match locs of m in s where m is a --sequence like {"this","that","whatever"} and s is a string integer x,oldx sequence t t={} for i=1 to length(m) do x=match(m[i],s) while x do for j=1 to length(m[i]) do t&=x+j-1 end for oldx=x if x+length(m[i])<=length(s) then x=match(m[i],{s[x+length(m[i])]}) if x then x+=oldx+length(m[i])-1 end if end if end while end for return t -- or sort(t) end function ------------------------------------------------- Then used that in GetFormula() this way: skip=MarkMatch(f,EVALKEYWORDS)--e.g. if f="a=log(x)", skip={3,4,5} indicating "log" cnt=2 t={} for i=x+1 to length(f) do if not find(i,skip) then--<<<< * This is the key line * if Alpha(f[i]) then if not find(f[i],t) then t&=f[i] cnt+=1 end if end if end if end for return {f,t} ------------------------------------------------------- You may well have a handier way to deal with all that. Your investigations have been really interesting -- please continue to let me know how it goes... --Quark