473,789 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simplifying algebraic expressions

Hi,

Are there any libraries for manipulating algebraic expression trees?
In particular, take an expression tree and simplify it down.

I'm working up the next release of PyGene, the genetic programming and
genetic algorithms library.

Part of PyGene works with trees holding algebraic expressions. For
example, the expression:
f = x**2 + sqrt(y) + 7
is represented as the tree:

+
**
x
2
+
sqrt
y
7

My GP code is successfully evolving expression trees to solve problems,
however they're often full of redundancies, eg adding y in one part then
subtracting y later on.

I've added some simplification code which takes out some of the more
obvious redundancies - eg replacing 'x - x' with '0', and replacing
'y / 1' with 'y' etc. But there'd be a pile of work to make this code
smart enough to go deep into the tree and fix everything.

So if someone can point me in the direction of an algebraic expressions
library that can simplify expression trees and weed out redundancies, that
would be awesome.

Many thanks if you can help.

Cheers
David
Jun 26 '07 #1
6 5687
Hi,
>
Are there any libraries for manipulating algebraic expression trees?
In particular, take an expression tree and simplify it down.

I'm working up the next release of PyGene, the genetic programming and
genetic algorithms library.

Part of PyGene works with trees holding algebraic expressions. For
example, the expression:
f = x**2 + sqrt(y) + 7
is represented as the tree:

+
**
x
2
+
sqrt
y
7

My GP code is successfully evolving expression trees to solve problems,
however they're often full of redundancies, eg adding y in one part then
subtracting y later on.
I have seen this sort of evolution strategy in the past and it's very wrong to
attempt to simplify outside the genetic framework. The implication is that you
know better than the overall fitness requirement. The additional expressions and
redundancies allow for extra mutation and combination possibilities which is a
good thing for the whole population. If you must, add the requirement to the
target ie give extra fitness points to organisms which perform efficiently.
--
Robin Becker

Jun 26 '07 #2
On Tue, 26 Jun 2007 11:11:39 +0100, Robin Becker wrote:
I have seen this sort of evolution strategy in the past and it's very wrong to
attempt to simplify outside the genetic framework. The implication is that you
know better than the overall fitness requirement. The additional expressions and
redundancies allow for extra mutation and combination possibilities which is a
good thing for the whole population. If you must, add the requirement to the
target ie give extra fitness points to organisms which perform efficiently.
I'm sorry, but there's something important I forgot to mention - I only
want to do the simplification *after* a winning successful organism has
evolved and satisfied the fitness function.
Jun 26 '07 #3
Hi David

It seems that all you are asking for are the capabilities of
Mathematica or Maple or some other CAS. A quick Google reveals that
there is a CAS written in Python, called SAGE. That might be a good
place to start; but I'll admit that I know nothing about it.

I'm with Robin Becker on this one, if GP is good enough for your
problem, then the answers it produces should be good enough. Set the
fitness criteria in favour of shorter rather than longer expressions
and let you system run a little longer. Not only do you avoid having
to integrate into your system a novel library, you avoid a world of
pain trying to decide whether or not x**2 is 'simpler' than x*x, (is
x**4 'simpler' than (x**2)*(x**2) ?) and making sure that you don't
define any circular simplification rules.

If you don't like the computer algebra approach, you could google for
'program transformation' and follow some of the links.

Good luck !

Mark Westwood

On 26 Jun, 12:06, DavidM <nos...@nowhere .comwrote:
On Tue, 26 Jun 2007 11:11:39 +0100, Robin Becker wrote:
I have seen this sort of evolution strategy in the past and it's very wrong to
attempt to simplify outside the genetic framework. The implication is that you
know better than the overall fitness requirement. The additional expressions and
redundancies allow for extra mutation and combination possibilities which is a
good thing for the whole population. If you must, add the requirement to the
target ie give extra fitness points to organisms which perform efficiently.

I'm sorry, but there's something important I forgot to mention - I only
want to do the simplification *after* a winning successful organism has
evolved and satisfied the fitness function.

Jun 26 '07 #4
On Tue, 26 Jun 2007 04:22:23 -0700, Mark Westwood wrote:
I'm with Robin Becker on this one, if GP is good enough for your
problem, then the answers it produces should be good enough. Set the
fitness criteria in favour of shorter rather than longer expressions
and let you system run a little longer.
Thanks for your comments.

I tried this and came up with some very interesting results.

In the fitness function, I added a multiplier:

badness *= numnodes
Where 'badness' is the calculated fitness (always >0, lower is better),
and 'numnodes' is the number of nodes in the program tree.

Result? The population never evolved past a certain point, and problem
never got solved.

So I tried to make the multiplier more gentle:

badness *= math.log(1 + numnodes)

Same result.

Tried even more gentle:

badness *= math.pow(numnod es, 1.0/12)

That is, multiply badness by the twelfth root of the number of nodes.

Population evolved better, but still didn't breed a winning organism.

Finally, I set a threshold, and only punished organisms if they exceeded
this complexity threshold:

if numnodes threshold:
badness *= math.pow(numnod es - threshold, 1.0/12)

That worked.

Seems that I have to allow a 'punishment free' threshold of complexity,
otherwise the population stagnates.

Cheers
David
Jun 26 '07 #5
DavidM <no****@nowhere .comwrote:
...
Seems that I have to allow a 'punishment free' threshold of complexity,
otherwise the population stagnates.
Sounds like you've hit on a good simulation of life: to get innovation,
you must be very tolerant of errors!-)
Alex
Jun 27 '07 #6

"DavidM" <no****@nowhere .comwrote in message
news:46******** @news.orcon.net .nz...
So if someone can point me in the direction of an algebraic expressions
library that can simplify expression trees and weed out redundancies, that
would be awesome.
half-joking:

Maxima http://maxima.sourceforge.net/ --- ala os.popen('maxim a .... ') ... ^_^

The problem with genetic algorithm's, as I understand Stuar Kaufmann, is that
while "weeding out redundancies" the fitness space becomes more spiky and
therefore harder to search. The "optimal" solution decays into simple random
guessing in in infinite search space. So, sloppiness and waste is Good - it
helps by creating an area of the fitness space where the "creature" can "move"
i.e. adopt/evolve.
Jun 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
4416
by: Raymond Hettinger | last post by:
Peter Norvig's creative thinking triggered renewed interest in PEP 289. That led to a number of contributors helping to re-work the pep details into a form that has been well received on the python-dev list: http://www.python.org/peps/pep-0289.html In brief, the PEP proposes a list comprehension style syntax for creating fast, memory efficient generator expressions on the fly: sum(x*x for x in roots)
6
2776
by: DennisNedry | last post by:
Any general ideas on techniques for creating parsers for algebraic and linear equations?
2
5100
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I have to use all the expressions seperately? Here are my regular expressions that check for valid email address and link Dim Expression As String =
4
5187
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or adate LIKE "2004.01.10 __:15") .... into something like this: .... where adate LIKE "2004.01.10 __:(30/15)" ...
1
1602
by: Hul Tytus | last post by:
comp.infosystems.www.authoring.html simplifying mailto In form entry code, the "POST action=mailto:xxx@xxx.xxx" command requests a Subject and a CC heading from the reader -- in lynx that is, I haven't checked other browsers. Even with the -s & -c fields included, the reader is questioned. The object is to hide these two fields from the reader to avoid confusion or destination error. Can anyone suggest how?
0
2522
by: steve | last post by:
If you think you can easily translate most relational division problems to sql you should write a book. If your not even sure what relational division even is or how it can do done in a sane way then this should help: http://beyondsql.blogspot.com/2007/07/dataphor-simplifying-relational.html
9
3759
by: Cristian | last post by:
algebraic expression 'a*b+c' with CIN .Is it possible? How to transfer the algebraic expression 'a*b+c' to the variable s (all double) with cout in a "Console Application" ? cout<<"Input a,b,c and expression in a,b,c "<<endl; cin>>a; cin>>b; cin>>c;
2
2111
by: Federico Zenith | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello everybody, I am looking into a problem that probably someone had before, so I hope I can avoid reinventing the wheel... I am looking into different alternatives to simulate a chemical process with a number of unit operations (heat exchangers, chemical reactors and so on). There are some commercial products (such as Hysys) that do this,
14
3726
by: serave | last post by:
How do i evaulate a mathematical expression that is entered in a text field. Ex: Text Fields: Xo=23 X1= 250 Expression: y = Xoe^(x1+Xo)-cos(X0+X1)+23Xo
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.