473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Execute Arbitrary Math Formulas

rob
I have the following scenario. A user requests some math calculations
from a server. The data and a library of basic formulas reside on the
server. Now the user should be able to create more complex formulas
based on the basic built in formulas as well as other complex formulas
that the user created himself. These formulas will be either stored on
the server or client and will be applied to the data on the server.
Some of the formulas will be used only once (if they don't work as
expected) wheras others might get used on a frequent basis. What is the
best way to approach this problem?

Thanks

Jun 19 '06 #1
11 1644
Don't know if this of any use.

http://www.codeguru.com/csharp/cshar...cle.php/c4245/
rob wrote:
I have the following scenario. A user requests some math calculations
from a server. The data and a library of basic formulas reside on the
server. Now the user should be able to create more complex formulas
based on the basic built in formulas as well as other complex formulas
that the user created himself. These formulas will be either stored on
the server or client and will be applied to the data on the server.
Some of the formulas will be used only once (if they don't work as
expected) wheras others might get used on a frequent basis. What is the
best way to approach this problem?

Thanks


Jun 19 '06 #2
Hi,

Depends, where the logic for evaluate the formulas reside? if you are going
to allow arbitrary formulas you need a formula evaluator. Depending of the
framework you are using you can evaluate them in the server or in the
client.

IMO you should provide more details about your environment.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"rob" <rm*******@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I have the following scenario. A user requests some math calculations
from a server. The data and a library of basic formulas reside on the
server. Now the user should be able to create more complex formulas
based on the basic built in formulas as well as other complex formulas
that the user created himself. These formulas will be either stored on
the server or client and will be applied to the data on the server.
Some of the formulas will be used only once (if they don't work as
expected) wheras others might get used on a frequent basis. What is the
best way to approach this problem?

Thanks

Jun 19 '06 #3
rob schrieb:
I have the following scenario. A user requests some math calculations
from a server. The data and a library of basic formulas reside on the
server. Now the user should be able to create more complex formulas
based on the basic built in formulas as well as other complex formulas
that the user created himself. These formulas will be either stored on
the server or client and will be applied to the data on the server.
Some of the formulas will be used only once (if they don't work as
expected) wheras others might get used on a frequent basis. What is the
best way to approach this problem?

Write a parser. Dunno if yacc/lex are available for visual studio. If not,
get a book about compiler construction and do a recursive parser.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.
Jun 19 '06 #4
"rob" <rm*******@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
I have the following scenario. A user requests some math calculations
from a server. The data and a library of basic formulas reside on the
server. Now the user should be able to create more complex formulas
based on the basic built in formulas as well as other complex formulas
that the user created himself. These formulas will be either stored on
the server or client and will be applied to the data on the server.
Some of the formulas will be used only once (if they don't work as
expected) wheras others might get used on a frequent basis. What is the
best way to approach this problem?
Sounds like SQL server for the data, predefined formulas as stored
procedures written in .NET, and user formulas as queries, possibly with
Javascript.NET postprocessing. This would permit compiling the queries for
repeated use.

Thanks

Jun 19 '06 #5
ANTLR <http://www.antlr.org/> is compiler compiler that generates C#
code.

Volker Hetzer wrote:
Write a parser. Dunno if yacc/lex are available for visual studio. If not,
get a book about compiler construction and do a recursive parser.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.


Jun 19 '06 #6
["Followup-To:" header set to microsoft.public.dotnet.framework.]
On 2006-06-19, rob <rm*******@yahoo.com> wrote:
I have the following scenario. A user requests some math calculations
from a server. The data and a library of basic formulas reside on the
server. Now the user should be able to create more complex formulas
based on the basic built in formulas as well as other complex formulas
that the user created himself. These formulas will be either stored on
the server or client and will be applied to the data on the server.
Some of the formulas will be used only once (if they don't work as
expected) wheras others might get used on a frequent basis. What is the
best way to approach this problem?


As already mentionned, store the 'command string' and evaluate it..
http://en.wikipedia.org/wiki/Reverse_polish_notation can be a good
start...

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Jun 19 '06 #7
rob
What is your opinion about on-the-fly/runtime compiling as another
solution and how would this be approched.

Thanks

Jun 20 '06 #8
Rob,

If your talking about using reflection then that would definitely be
the easiest. However, the security vulnerability you open up could be
huge. The compiler compiler option is probably the best overall, but
there is a huge learning curve. And of course you could always whip up
your own evaluator. Writing your own isn't terribly difficult. It
consists of 3 basic steps: First, tokenize the input string. Then
perform an infix to postfix conversion. That gets rid of paranthesis
and cumbersome operator precedence rules. Finally, evaluate by popping
operands of a stack and pushing the result until all operators are
consumed.

Brian

rob wrote:
What is your opinion about on-the-fly/runtime compiling as another
solution and how would this be approched.

Thanks


Jun 20 '06 #9
rob schrieb:
What is your opinion about on-the-fly/runtime compiling as another
solution and how would this be approched.

There is no "eval" statement there, probably for security reasons.
Also, the JIT compiler expects some IL code as far as I know, not source
code.
You *could* create a little C# program and compile it. Requires Visual
studio on the server (eurgh!!!) Won't work for more than very infrequent
use and creates a huge workload on the server.

You could install perl or tcl on the server. They *do* have
an eval statement. Write a small server that listens on a port,
gets the expression string, evaluates it and returns the result.

But really, an expression parser isn't that hard to do. A simple one
was a (very small) part of my diploma thesis and every CS student
does several during the course of his studies.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.
Jun 20 '06 #10
rob

Volker Hetzer wrote:
rob schrieb:
What is your opinion about on-the-fly/runtime compiling as another
solution and how would this be approched.

There is no "eval" statement there, probably for security reasons.
Also, the JIT compiler expects some IL code as far as I know, not source
code.
You *could* create a little C# program and compile it. Requires Visual
studio on the server (eurgh!!!) Won't work for more than very infrequent
use and creates a huge workload on the server.

You could install perl or tcl on the server. They *do* have
an eval statement. Write a small server that listens on a port,
gets the expression string, evaluates it and returns the result.

But really, an expression parser isn't that hard to do. A simple one
was a (very small) part of my diploma thesis and every CS student
does several during the course of his studies.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.


Unfortunatelly (for this particular problem) I have no CS degree
(though one from a different field). Well, I guess I'll have to learn
how to write a parser then. I just wonder if a parser isn't quite
inefficient. I need to repeate the calculation on hundreds of data
points. The first two steps of the parser probably would have to be
done only once but the last step seems still quite costly. But it seems
short of doing compilation at run time there isn't much else that can
be done.

Jun 20 '06 #11
You can get a good start on your parser, in C# V2, by consulting
http://www.frontiernet.net/~fredm/dps/Contents.htm , Chapter 3. The sample
parser will parse simple arithmetic expressions and can be expanded fairly
easily. You will have to write a lexical analyzer, but this is easily done
by using Regex.

"rob" <rm*******@yahoo.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...

Volker Hetzer wrote:
rob schrieb:
> What is your opinion about on-the-fly/runtime compiling as another
> solution and how would this be approched.

There is no "eval" statement there, probably for security reasons.
Also, the JIT compiler expects some IL code as far as I know, not source
code.
You *could* create a little C# program and compile it. Requires Visual
studio on the server (eurgh!!!) Won't work for more than very infrequent
use and creates a huge workload on the server.

You could install perl or tcl on the server. They *do* have
an eval statement. Write a small server that listens on a port,
gets the expression string, evaluates it and returns the result.

But really, an expression parser isn't that hard to do. A simple one
was a (very small) part of my diploma thesis and every CS student
does several during the course of his studies.

Lots of Greetings!
Volker
--
For email replies, please substitute the obvious.


Unfortunatelly (for this particular problem) I have no CS degree
(though one from a different field). Well, I guess I'll have to learn
how to write a parser then. I just wonder if a parser isn't quite
inefficient. I need to repeate the calculation on hundreds of data
points. The first two steps of the parser probably would have to be
done only once but the last step seems still quite costly. But it seems
short of doing compilation at run time there isn't much else that can
be done.

Jun 21 '06 #12

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

Similar topics

17
by: Harlan Messinger | last post by:
I am reviewing a set of pages, some of which include in-line mathematical formulas represented as images. I am addressing the accessibility issues behind those images. (Conformance to Section 508...
3
by: schwehr | last post by:
Done any one have a way (and examples) of how to do math markups in the docstrings of function and class definitions such that the equations get typeset in the generated html documentation? I'll...
4
by: Sehri | last post by:
Hi all, I have just started developing a math companion tool with VS2005 and I just ran into a problem when trying to add the description of a formula. Doed anyone know how can I add math...
11
by: rob | last post by:
I have the following scenario. A user requests some math calculations from a server. The data and a library of basic formulas reside on the server. Now the user should be able to create more...
15
by: lbrtchx | last post by:
I am trying to write up a page with Math formulas (statistical ones) ~ http://www.geocities.com/tekmonk2005/OnLineStats02.html ~ The thing is that I am not able to make it look OK using HTML. I...
15
by: Alasdair | last post by:
I need to apply the ceiling function to arbitrary sized (long) integers. However, division automatically returns the type of its operands, so that, for example: math.ceil(7/4) returns 1. I can use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.