473,474 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UCALC equivalent

http://www.ucalc.com/mathparser/index.html

There is a great library called UCALC which allows you to set up an
expression and evaluate it
for e.g. you an define an expression by calling a function in UCALC
then call it with various values of x

for e.g. see this page
http://www.ucalc.com/mathparser/sample6.html
It is very fast. I have used it in VB when there is lot of number
crunching to be done.
Is there a Python equivalent.

I looked at numPy and SciPy sites (just skimmed through) did'nt seem
to have what I wanted.

Any pointers?
--
DarkCowherd
Aug 12 '05 #1
11 1748
Python has built in eval function and doesn't require
a library.

Larry Bates

Dark Cowherd wrote:
http://www.ucalc.com/mathparser/index.html

There is a great library called UCALC which allows you to set up an
expression and evaluate it
for e.g. you an define an expression by calling a function in UCALC
then call it with various values of x

for e.g. see this page
http://www.ucalc.com/mathparser/sample6.html
It is very fast. I have used it in VB when there is lot of number
crunching to be done.
Is there a Python equivalent.

I looked at numPy and SciPy sites (just skimmed through) did'nt seem
to have what I wanted.

Any pointers?

Aug 12 '05 #2
Python has built in eval function and doesn't require
a library.

Larry Bates

Dark Cowherd wrote:
http://www.ucalc.com/mathparser/index.html

There is a great library called UCALC which allows you to set up an
expression and evaluate it
for e.g. you an define an expression by calling a function in UCALC
then call it with various values of x

for e.g. see this page
http://www.ucalc.com/mathparser/sample6.html
It is very fast. I have used it in VB when there is lot of number
crunching to be done.
Is there a Python equivalent.

I looked at numPy and SciPy sites (just skimmed through) did'nt seem
to have what I wanted.

Any pointers?


Aug 12 '05 #3
max
Larry Bates <lb****@syscononline.com> wrote in
news:42**************@syscononline.com:
Python has built in eval function and doesn't require
a library.

Larry Bates


Are you kidding? Read the original post a little more closely. The
o.p. is looking for a library that evaluates mathematical expressions
and is callable from python code.

max
Aug 12 '05 #4
max wrote:
Larry Bates <lb****@syscononline.com> wrote in
news:42**************@syscononline.com:
Python has built in eval function and doesn't require a library.


Are you kidding? Read the original post a little more closely. The
o.p. is looking for a library that evaluates mathematical expressions
and is callable from python code.


He is absolutely correct.
From the web page referenced:

ucDefineFunction("area(length,width) = length*width");
ucDefineFunction("frac(x)=abs(abs(x)-int(abs(x)))");
ucDefineFunction("test() = 5");
ucDefineFunction("abc(x, y=10) = x + y");
ucDefineFunction("shl[x, y] = x * 2^y");

cout.precision(16);
cout << ucEval("frac(150/17) * area(20,30)") << endl;
cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)")
<< endl;
The python equivalent:

exec "def area(length,width): return length*width"
exec "def frac(x): return abs(abs(x) - int(abs(x)))"
exec "def test(): return 5"
exec "def abc(x, y=10): return x + y"
exec "def shl(x, y): return x * 2^y"

print eval("frac(150/17) * area(20,30)")
print eval("abc(5) - abc(3,4) * shl(0x0E, 1)")

--Scott David Daniels
Sc***********@Acm.Org
Aug 12 '05 #5
Scott David Daniels <Sc***********@Acm.Org> wrote in
news:42********@nntp0.pdx.net:
max wrote:
Larry Bates <lb****@syscononline.com> wrote in
news:42**************@syscononline.com:
Python has built in eval function and doesn't require a library.


Are you kidding? Read the original post a little more closely.
The o.p. is looking for a library that evaluates mathematical
expressions and is callable from python code.


He is absolutely correct.
From the web page referenced:

ucDefineFunction("area(length,width) = length*width");
ucDefineFunction("frac(x)=abs(abs(x)-int(abs(x)))");
ucDefineFunction("test() = 5");
ucDefineFunction("abc(x, y=10) = x + y");
ucDefineFunction("shl[x, y] = x * 2^y");

cout.precision(16);
cout << ucEval("frac(150/17) * area(20,30)") << endl;
cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)")
<< endl;
The python equivalent:

exec "def area(length,width): return length*width"
exec "def frac(x): return abs(abs(x) - int(abs(x)))"
exec "def test(): return 5"
exec "def abc(x, y=10): return x + y"
exec "def shl(x, y): return x * 2^y"

print eval("frac(150/17) * area(20,30)")
print eval("abc(5) - abc(3,4) * shl(0x0E, 1)")

--Scott David Daniels
Sc***********@Acm.Org


Ouch, I sure was wrong. You did such a good job making me look
foolish that it was mentioned in Python-URL!. At least Larry Bates
had the grace not to call me an idiot.

max
Aug 12 '05 #6
Max Erickson wrote:
Scott David Daniels <Sc***********@Acm.Org> wrote in
news:42********@nntp0.pdx.net:

max wrote:
From the web page referenced:
...
cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)")
<< endl;
The python equivalent:
...
print eval("abc(5) - abc(3,4) * shl(0x0E, 1)")


Ouch, I sure was wrong. You did such a good job making me look
foolish that it was mentioned in Python-URL!.

Sorry, I wasn't trying to make you look foolish. I was trying to
nip a misconception in the bud.

I also forgot how to convert binary to an integer (the #b01101 above)
when I was writing it, so that last line should read:
print eval("abc(5) - abc(3,4) * shl(int('01101', 2), 1)")
--Scott David Daniels
Sc***********@Acm.Org
Aug 13 '05 #7
In article <Xn*********************************@216.168.3.44> ,
Max Erickson <ma*********@gmail.com> wrote:
Aug 13 '05 #8
thx,

Well moving to Python from another language needs lots of chanegs
inside your head.

--
DarkCowherd
Aug 13 '05 #9
Dark Cowherd <da*********@gmail.com> wrote:
http://www.ucalc.com/mathparser/index.html

There is a great library called UCALC which allows you to set up an
expression and evaluate it
for e.g. you an define an expression by calling a function in UCALC
then call it with various values of x

for e.g. see this page
http://www.ucalc.com/mathparser/sample6.html

It is very fast. I have used it in VB when there is lot of number
crunching to be done.
Is there a Python equivalent.

I looked at numPy and SciPy sites (just skimmed through) did'nt seem
to have what I wanted.

Any pointers?


Python has 'eval' and 'exec', so you can process at run-time anything
that you can type into script file. However, it will be a bit more
verbose than UCALC, because Python is more general.

If you're looking for scientific calculator, which can be embedded or
scripted, then perhaps you should take a look at
http://home.eol.ca/~parkw/index.html#rpn
It is RPN calculator with full support for <math.h> functions and some
features found in typical programmable scientific calculators.

Eg.
3+4/5-8 --> rpn 4 5 / 3 + 8 - = --> -4.2

x^2+5x-10
--> rpn 'f(x)= dup 5 + x 10 -'
rpn 1 'f(x)' = --> -4
rpn 5 'f(x)' = --> 40
or it can be scripted directly using shell function, like
--> func () {
rpn $1 dup 5 + x 10 - =
}
func 1
func 5

Sum(x^2+5, 1, 10). I assume this is sum of x^2+5, for x=1,2,...,10
--> rpn clear
for i in {1..10}; do
rpn $i x^2 5 + +
done
rpn = --> 435

--
William Park <op**********@yahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/
Aug 13 '05 #10
Scott David Daniels wrote:
max wrote:
Larry Bates <lb****@syscononline.com> wrote in
news:42**************@syscononline.com:
Python has built in eval function and doesn't require a library.

Are you kidding? Read the original post a little more closely. The
o.p. is looking for a library that evaluates mathematical expressions
and is callable from python code.

He is absolutely correct.
From the web page referenced:

ucDefineFunction("area(length,width) = length*width");
ucDefineFunction("frac(x)=abs(abs(x)-int(abs(x)))");
ucDefineFunction("test() = 5");
ucDefineFunction("abc(x, y=10) = x + y");
ucDefineFunction("shl[x, y] = x * 2^y");

cout.precision(16);
cout << ucEval("frac(150/17) * area(20,30)") << endl;
cout << ucEval("abc(5)-abc(3,4)*(#b01101 shl 1)")
<< endl;
The python equivalent:

exec "def area(length,width): return length*width"
exec "def frac(x): return abs(abs(x) - int(abs(x)))"
exec "def test(): return 5"
exec "def abc(x, y=10): return x + y"
exec "def shl(x, y): return x * 2^y"


Perhaps this should be:
exec "def shl(x, y): return x * 2 ** y"
or
exec "def shl(x, y): return x << y"

print eval("frac(150/17) * area(20,30)")
print eval("abc(5) - abc(3,4) * shl(0x0E, 1)")

--Scott David Daniels
Sc***********@Acm.Org

Aug 13 '05 #11
John Machin wrote:
Scott David Daniels wrote:
max wrote:
Larry Bates <lb****@syscononline.com> wrote in

The python equivalent:
...
exec "def shl(x, y): return x * 2^y"


Perhaps this should be:
exec "def shl(x, y): return x * 2 ** y"
or
exec "def shl(x, y): return x << y"

Exactly.
Demonstrating the problems of not actually running a test case
with known results.

--Scott David Daniels
Sc***********@Acm.Org
Aug 13 '05 #12

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

Similar topics

14
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
1
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different...
7
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s :...
10
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
0
by: Dancorbier | last post by:
uCalc Fast Math Parser 2.95 is now available. This component allows your applications to evaluate math expressions defined at runtime. The two major new enhancements in this version are faster...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.