Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Miscellaneous > Off-Topic > Script to replace "a^b" in an expression with "pow(a,b)"
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!
20.Sep: FOURTH CHAPTER IN `HISTORY OF...` PUBLISHED
13.Sep: NEWS ON THE FLY
06.Sep: APOLYTON DONATES TO HURRICANE RELIEF

bottom of page
   - CIVILIZATION 3 $9.99 - CIVILIZATION 2 from $6.95 - CIVILIZATION 2 from $4.25 - ALPHA CENTAURI + ALIEN CROSSFIRE (laptop collection) from $19.99 - ALPHA CENTAURI PC $9.99 -->
Author
Thread   
Pages (2): [ 1   2   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 01:13 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Script to replace "a^b" in an expression with "pow(a,b)" Support Apolyton, buy GURPS/ Alpha Centauri

I have a few beastly mathematical expressions that I need to use in C++, but I got it from Maple. Maple uses "^" as the exponentiation operator, incompatible with C (which uses pow().

So, I need a script to go from a^b to pow(a,b).

For instance, here's one of them:

1/12/d/k/tan(b)/a*((6*sqrt(3)*r*sqrt(-k^4*a^4-a^4*d^4*tan(b)^4*k^2-2*a^4*d^2*tan(b)^2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^2*r^2*tan(b)^4-6*k^2*a^3*r*tan(b)^2- 12*a^3*tan(b)^4*k*r+18*r*d*k^2*tan(b)^4*a^2+18*r*d
^3*k^2*tan(b)^4*a^2+18*r*d*k^3*tan(b)^2*a^2-36*r^2*d*k^2*tan(b)^4*a+3*a^4*tan(b)^4*k)*a^2)^(1/3));

I tried doing a find and replace shtick over and over again, but I definitely missed some things.

Any ideas?

DanS is offline DanS
Emperor
Kickball Capital of the World
Jan 1970
time: 00:22
  Old Post 26-02-2005 01:15 Visit DanS's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Enter the AD-FREE zone

What editor are you using? Emacs?

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 01:16 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Avatar Enlargement: We've got the solution

MS Visual Studio.

But I can use another editor if needed of course...

I should probably just go back and rewrite the program in Fortran which doesn't have this stupid restriction...

loinburger is offline loinburger
Emperor
Sweet Sauce Jones
Jul 1999
time: 00:22
  Old Post 26-02-2005 02:10 Visit loinburger's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Full PM-box? Change here!

Probably be easier to turn ^ into an operator in C++. Forget how that's done, though.

Or maybe you can only overload operators, not create new ones. I forget offhand, and my C++ blackbook is at work.

Edit: Nevermind, you can't define new operators, you can only overload existing ones. Piece of crap language...

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:22
  Old Post 26-02-2005 02:12
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Support Apolyton buy from Amazon

Problem is, the ^ operator is already defined on numbers and such in C++ - it's the bitwise xor.

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 02:23 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Increase the size of your Attachments

The problem with overloading ^ is the order in which C evaluates * and / in relation to it.

So 2*k^2 will end up being evaluated as (2*k)^2.

pchang is offline pchang
King
Cupertino?
Aug 1999
time: 05:22
  Old Post 26-02-2005 02:30
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

s/+\w\^+\w/pow($1,$2)/g;

in a perl script should do the trick
(if this is not the exact line, it comes real close)

edit: added + since your expressions may be more than 1 character long.

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 02:35 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

Thanks, I'll try that out.

Mercator is offline Mercator
King
Sorekara no Nanimo
Jan 1970
time: 06:22
  Old Post 26-02-2005 03:05 Visit Mercator's homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Support Apolyton, buy Call to Power 2

That doesn't even remotely cover it, pchang, I'm afraid... See the last use of the ^ in the one Ramo provided, for instance. It's got complex nested expressions. The one you suggested wouldn't even work with "tan(b)^4".

And, um, the one you suggested doesn't work. It should be:
s/(\w+)\^(\w+)/pow($1,$2)/g;

This one works a bit better, it'll also take functions (e.g. "tan(b)") or parenthesized expressions, but it won't work with nested parentheses:
s/(\w+(?:\([^()]*\))?)\^(\w*(?:\(.*?\))?)/pow($1,$2)/g;

That reduces the number of ^ from 794 to 4 in the one in your first post though, so you can reasonably finish it off manually.

pchang is offline pchang
King
Cupertino?
Aug 1999
time: 05:22
  Old Post 26-02-2005 03:10
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Full PM-box? Change here!

I bow to the superior intellect

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:22
  Old Post 26-02-2005 03:11
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Got spare money?

WTF is that thing anyway?

Mercator is offline Mercator
King
Sorekara no Nanimo
Jan 1970
time: 06:22
  Old Post 26-02-2005 03:21 Visit Mercator's homepage!
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

quote:
Originally posted by pchang
I bow to the superior intellect




You beat me to mentioning regular expressions though. I didn't mean to be too harsh.

quote:
Originally posted by Kuciwalker
WTF is that thing anyway?


I hope you're not talking about that regular expression. I'm wondering what the hell Ramo's monster expressions are.

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:22
  Old Post 26-02-2005 03:27
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Browse Apolyton AD-FREE

I'm talking about Ramo's monster.

Japher is offline Japher
Prince
Ook! Ook! Ack! Ack! Ack!
Jun 2002
time: 05:22
  Old Post 26-02-2005 03:27
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Enter the AD-FREE zone

quote:
s/(\w+(?:\([^()]*\))?)\^(\w*(?:\(.*?\))?)/pow($1,$2)/g;


And to think, that was going be the name of my next DL...

I Am Jeff is offline I Am Jeff
Chieftain
New Jersey
Feb 2002
time: 00:22
  Old Post 26-02-2005 03:30
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Enter the AD-FREE zone

Why don't you just write a C program to do what you need, to replace a^b with pow(a,b) should be too hard of a program to make.

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 03:58 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

Because I'm lazy, I hate programming, and it's not quite trivial given that "a" can be tan(b), parenthetical expressions, etc.

quote:
WTF is that thing anyway?


Shining light down on a plasma, and seeing where the ray intersects its surface. I can't solve it analytically since the plasma's surface has a funky transcendental shape, so I'm using Newton's method to find the solutions. For my initial guesses I quadratically expanded around a certain parameter of the plasma (something that I had absolutely no right to assume as being << 1), to get a cubic equation in the sine of the parametric variable for the plasma's surface. And that expression above is one of the solutions to that equation.

Thanks Mercator.

Japher is offline Japher
Prince
Ook! Ook! Ack! Ack! Ack!
Jun 2002
time: 05:22
  Old Post 26-02-2005 04:04
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
Support Apolyton

I applied for a job in Austin...

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 04:09 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

Where at?

Kuciwalker is offline Kuciwalker
Emperor
of Schmooism
Feb 2001
time: 00:22
  Old Post 26-02-2005 04:13
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Support Apolyton buy from Amazon

quote:
Originally posted by Ramo
Because I'm lazy, I hate programming, and it's not quite trivial given that "a" can be tan(b), parenthetical expressions, etc.

quote:
WTF is that thing anyway?


Shining light down on a plasma, and seeing where the ray intersects its surface. I can't solve it analytically since the plasma's surface has a funky transcendental shape, so I'm using Newton's method to find the solutions. For my initial guesses I quadratically expanded around a certain parameter of the plasma (something that I had absolutely no right to assume as being << 1), to get a cubic equation in the sine of the parametric variable for the plasma's surface. And that expression above is one of the solutions to that equation.

Thanks Mercator.


...

couldn't you just check random values until it fit? That'd be simpler...

Japher is offline Japher
Prince
Ook! Ook! Ack! Ack! Ack!
Jun 2002
time: 05:22
  Old Post 26-02-2005 04:14
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Tired of ads?

quote:
Where at?


Abbott Labs

Mercator is offline Mercator
King
Sorekara no Nanimo
Jan 1970
time: 06:22
  Old Post 26-02-2005 04:17 Visit Mercator's homepage!
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Increase Your PM Length

quote:
Originally posted by Ramo
Shining light down on a plasma, and seeing where the ray intersects its surface. (...)




quote:
Thanks Mercator.


No problem

Japher is offline Japher
Prince
Ook! Ook! Ack! Ack! Ack!
Jun 2002
time: 05:22
  Old Post 26-02-2005 04:18
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Get a bigger avatar today!

quote:
Shining light down on a plasma, and seeing where the ray intersects its surface. I can't solve it analytically since the plasma's surface has a funky transcendental shape, so I'm using Newton's method to find the solutions. For my initial guesses I quadratically expanded around a certain parameter of the plasma (something that I had absolutely no right to assume as being << 1), to get a cubic equation in the sine of the parametric variable for the plasma's surface. And that expression above is one of the solutions to that equation.


That's the nerdiest thing I have heard... since the OP

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 04:24 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Inflate your Upload Space


Hopefully I'll finish this soon so I can get well drunk and stoned and forget that I wasted a week on this.

quote:

couldn't you just check random values until it fit? That'd be simpler...


Yeah, but it'd take forever to compute.

pchang is offline pchang
King
Cupertino?
Aug 1999
time: 05:22
  Old Post 26-02-2005 04:25
Edit/Delete Message Reply w/Quote
#24 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

quote:
Originally posted by Kuciwalker


...

couldn't you just check random values until it fit? That'd be simpler...


That's essentially what Newton's method is.

BlackCat is offline BlackCat
Warlord

Jul 2004
time: 05:22
  Old Post 26-02-2005 04:30
Edit/Delete Message Reply w/Quote
#25 Report this post to a moderator
Support Apolyton, buy Civilization 2

Forget about doing that automaticlly - it's a waste of time. Also drop using MS tools - they sucks - use vi (no, this is not std MS bashing - I work on both unix and MS platforms, and vi is the winner).

Repeat search for ^ and make global subsititute for what you find one by one. It may sound tedious, but is much more effective than trying to figure out a way to solve it in one step. It isn't as bad as it may sound - there are of repeated statements that will be fixed by one statement.

Japher is offline Japher
Prince
Ook! Ook! Ack! Ack! Ack!
Jun 2002
time: 05:22
  Old Post 26-02-2005 04:32
Edit/Delete Message Reply w/Quote
#26 Report this post to a moderator
Increase Your PM Length

Watch Numb3rs tonight, I hear they go over this!

BlackCat is offline BlackCat
Warlord

Jul 2004
time: 05:22
  Old Post 26-02-2005 04:39
Edit/Delete Message Reply w/Quote
#27 Report this post to a moderator
Increase Your PM Length

If you have multiple files, then try using cscope to make changes in those files involved. It's quite effective - I once turned a pascal program into c with this tool.

Ramo is offline Ramo
King
Austin, Texas, USA
Oct 1999
time: 23:22
  Old Post 26-02-2005 04:46 Visit Ramo's homepage!
Edit/Delete Message Reply w/Quote
#28 Report this post to a moderator
Got spare money?

I don't know BC, Mercator's solution seems pretty good. Like I said, I tried finding and replacing, and screwed up somehow.

Mercator, I just installed Active Perl. Now, how would I run your script?

Provost Harrison is offline Provost Harrison
Emperor
The farce is strong with this one.
Feb 2000
time: 05:22
  Old Post 26-02-2005 04:55
Edit/Delete Message Reply w/Quote
#29 Report this post to a moderator
Full PM-box? Change here!

That is insane...

BlackCat is offline BlackCat
Warlord

Jul 2004
time: 05:22
  Old Post 26-02-2005 04:56
Edit/Delete Message Reply w/Quote
#30 Report this post to a moderator
Support Apolyton buy from Amazon

Problem is that you easily spend much more time trying to invent the smart solution than just do the boring stuff.

If it is something that you expect to do a lot in the future, then I'm in for the smart thing - otherwise it's my experience it's just a waste of time (admitted, it can be fun to make such a regexp )

 
Pages (2): [ 1   2   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:22.
Apolyton Time is 00:22.
    top of page
Rate This Thread:
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0660 seconds (91.78% PHP - 8.22% MySQL) with 30 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net