Add your own alternative version
Stats
217.3K views 8.9K downloads 244 bookmarked
Posted
1 Nov 2008

Comments and Discussions



Another great article. Fun coding





Just found a collection of mathematical formulas covering a wide variety of topics & relevant equations:
Topic, Page Number
Greek Alphabet 3
Indices and Logarithms 3
Trigonometric Identities 4
Complex Numbers 6
Hyperbolic Identities 6
Series 7
Derivatives 9
Integrals 11
Laplace Transforms 13
Z Transforms 16
Fourier Series and Transforms 17
Numerical Formulae 19
Vector Formulae 23
Mechanics 25
Algebraic Structures 27
Statistical Distributions 29
F  Distribution 29
Normal Distribution 31
t  Distribution 32
2 (Chisquared)  Distribution 33
Physical and Astronomical constants 34
http://www.maths.manchester.ac.uk/~kd/ma2m1/tables.pdf[^]





Hi Dmitri,
Thanks for the wonderful program. I've 2 questions:
Q1. Is it possible to convert this code to an equation and subsequently representation in MathML?
for (i=1; i<10; i++){
x=x+1;
}
Q2. Do you know of any software that I can use to convert my C code into equation and/or MathML representation?
for example,
input: sqrt(x)
output (MathML): <math><mrow><msqrt><mi>x</mi></msqrt></mrow></math>
Thanks.





I'm afraid I cannot offer help in either of those cases. Even though theoretically what you're asking is implementable, in practice, even codetoflowchart implementation is hard enough, and conversion to equations is even harder. Good luck finding existing solutions, but I certainly don't know of any.





Thanks for the quick response. Will continue to search for a code > equation software and will update you if we eventually find one.
Wonder how would the equation(s) for the 'for loop' example looks like?





Loops would translate to series of functions. See: http://en.wikipedia.org/wiki/Series_%28mathematics%29[^]
MathML (generated from the equation by Word 2010) for the code for(int i = 0; i < 10; i++) x = x + 1; should be following:
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"><mml:mrow><mml:munderover><mml:mo stretchy="false">∑</mml:mo><mml:mrow><mml:mi>n</mml:mi><mml:mo>=</mml:mo><mml:mn>0</mml:mn></mml:mrow><mml:mrow><mml:mn>9</mml:mn></mml:mrow></mml:munderover><mml:mrow><mml:mi>x</mml:mi><mml:mo>=</mml:mo><mml:mi>x</mml:mi><mml:mo>+</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:mrow></mml:math>
Mind the formatting please.
modified on Tuesday, August 17, 2010 3:53 AM





Nice article, thanks.
May be you've seen somewhere wpf mathml editor,didn't you? //yes, I've googled, btw; nothing useful
I've used WinForms editor from soft4science...
It was realy unstable,despite the code was crammed with empty catch clauses. As a result, it was required to reflect it and fix lots of drawing bugs. But even after fixing all bugs that was found, it works bad in wpf application.
I have not found any wpf mathml editor, and now it looks like i'll have to write it myself...





Nope, haven't seen anything. Try asking on StackOverflow.





Три года вопросу (: Я уже даже не помню что сделал с тем проектом...





<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>time</ci>
</bvar>
<ci>p53</ci>
</apply>
<apply>
<minus/>
<ci>V_10</ci>
<ci>V_11</ci>
</apply>
</apply>
</math>





Hmm, I don't recognize 'bvar' or 'ci'... what app did you use to generate this?





Thanks for the article!

CenterSpace Software
www.centerspace.net






Hi Dmitri,
Nice article, but as per me there is no much sense in handling math equations in C#...
Such mathematical (actually any mathematical) calculations are much more better applicable to functional programming and F# in particular. With F# you would get really highly performant, scalable and maintainable code.
Microsoft is currently investing enormous resources into F# development and for instance, MS Gaming platform guys are already using it. We are considering F# in our project as sole language for math calculations. F# is a future of a serverside programming.
Nothing personal , but I would think twice before implementing math in C#.
Vitaliy Liptchinsky





I did put up a question on StackOverflow about this, with no conclusive results. It might be argued that SSE or GPGPU is better (performancewise), but... at any rate, I could easily change my program to support F# (err, I think), but I'm not sure it would benefit that many people. Now C++, well, that's another story.





Hi Dmitri,
Dmitri Nesteruk wrote: Neither is F#
I wouldn't say that. Just google a little bit about F# and functional programming, before saying it. It's not even about performance and concurrency advantages. It's about F# is natural language for mathematical calculations. F# is based on .NET, so it can be perfectly integrated with C# components. In F# you wouldn't need any additional tools for linear algebra even such nice tools as yours .
Vitaliy Liptchinsky





I've logged ideas for supporting F# in my FogBugz tracker, so it might just be that some F# support will be forthcoming... that said, F# itself is on my TODO list, so it might take some time.





Hi, Vitaliy,
This way, MSIL is not for math.
Anything that can be implemented in F# can be implemented in C#.
What do you mean by "not for math" if not performance advantages? This way mathlab and maple is for math.
If performance is essential for math, than asm, C, and, for example, CUDA is for math.
There are many kinds of math (:
Vitaliy Liptchinsky wrote: natural language for mathematical calculations
This means F# is a language designed for mathematicians. Not for programmers.
Usually, mathematicians do not care how fast (and even how generally) calculations are performed. But languages like prolog had proved they are useless in really complex calculations.
Cheers,
Andrew





Hello Andrew,
x4mmm wrote: What do you mean by "not for math" if not performance advantages?
Except of some several features, like tailrecursion and custom delegates (FastFunc), performance of F# application should be the same as analogues C# application.
I mean, that in F# it is much easier to implement code, that will look like mathematical formulas provided in project specification and F# is easier to pick up by mathematicians.
x4mmm wrote: This means F# is a language designed for mathematicians.
Nope, I believe this is a misunderstanding. F# is, as well as C#, general purpose language.
Vitaliy Liptchinsky





Vitaliy Liptchinsky wrote: in F# it is much easier to implement code
It's harder to read code than to write it. [(c) J Spolsky or mb smb befor him]
Hence, next reason is more important.
Vitaliy Liptchinsky wrote: F# is easier to pick up by mathematicians
So,
x4m wrote: F# is a language designed for mathematicians
Finally, past a certain level of complexity all programming languages are equivalent. [(c)Turing or mb Brooks, i'm not shure]
modified on Tuesday, October 27, 2009 9:46 AM





Andrew,
I do not really understand what you are trying to prove, but our discussion starts being destructive.
I really do not want to sound rude, but before citing famous people in software development and applied mathematics you could at least check F# official sites and Microsoft research page.
Vitaliy Liptchinsky





Vitaliy,
I understand that you use F# in commercial project and you would like to defend your system's architecture. It would be excuse even if you sound rude.
Vitaliy Liptchinsky wrote: I do not really understand what you are trying to prove
There is not less sense in handling math equations in C# than handling it in F#.
Vitaliy Liptchinsky wrote: check F# official sites
If I'll check astrology web sites, I'll find out that magic in common sense exists. Furthermore, it'll be available nearly for free right after i supply authors with my cc number. Do you really belive in every MS word?
Anyway, I've checked them. [[I know, vsl not dead, but] I didn't like Haskell, neither I like F#.]
I've even installed MSVS 10b2. And compiled F# tutorial (: . And reflected it. Gamedev with F# sounds just like a joke. It's not just far from optimal. Currently I'm lecturing computer graphics, I've at least small view of game development. XNA is not just F#. (:
So, what about parsing MathML to C#?
Actually, there aren't too much things to parse. What is a purpose of parsing one AST to another through human oriented code? It was a routine work to be done.
Serverside programming  it's wide area. It's including calculations.
But F# is generalizing coding complexity reduction. It leads to losing speed. Generalized solutions nearly always work slower.
PS. I've done it! I didn't citated anyone of famous people.
М.б. будем писать на русском? У меня с английским также как с бытовой магией. Хотя есть ненулевая вероятность того, что вообще дальше писать не будем.





I do not want to continue this discussion. I propose you to post a question on stackoverflow.com about C# vs F# in mathematics (and put there all your statements in this post). And do not forget to send me a link, please.
Vitaliy Liptchinsky
modified on Tuesday, October 27, 2009 3:45 PM






Well, I guess you were right after all
I just released a commercialized version of what's in this article here[^]
I ended up using F# for both parsing and prettyprinting, leaving C# to handle the UI.





Hi Dmitri,
We are already using F# in our project for quite a while. Would be nice to share some opinions
My email is liptchinski_vit at yahoo dot com
Vitaliy Liptchinsky





"Usually, mathematicians do not care how fast (and even how generally) calculations are performed."
Just plain false. There's a whole field devoted to just that topic, in fact. It's called "numerical analysis".





I can attest to that. A course on numerical analysis was required for my computer science degree.
The United States invariably does the right thing, after having exhausted every other alternative. Winston Churchill





Ага, русские жгут. Всегда уважал программы, связанные с математикой. Большое спасибо!





Laserson wrote: Russian Developers are the Best
Modesty is the best policy.
Девелопстры супер монстры.





Difference between string and String Class





There's no difference. "string" is just an alias for "String", just like int is to System.Int32.
the cake is a lie.





Why are you answering someone's interview question in my article discussion?!? Hehe, just kidding.





why the .exe does not run??





I don't know. Maybe you don't have .NET 3.5?





OK, maybe due to this, thanks, I will try later on my another computer with.net 3.5





administrator can run this program





Thanks a lot for sharing!
Jm
www.menendezpoo.com





I think the use of this type of program breaks down for algorithms requiring several equations or subterms that are entire equations in themselves. Some terms may only need computing once and then are used later in several places. Also, many iterative processes require loops where some terms change and some stay constant.
An optimizing compiler will handle many of these situations even when the programmer doesn't quite get it.
Unless you rewrite MathCad, I can't see using this. Understand that Word is a wordprocessor  even though it's gotten out of hand lately, as in the last 10 years. It's meant to print nice pretty equations. But the math is very unstructured and ambiguous for a computer to interpret. MathCad works because there is a huge library of functions behind the scenes to translate complex quatities  even integrals.
A software engineer needs to look at the entire algorithm being implemented and not so much on the individual equations. Is it really that hard to code equations?
I know you said hundreds at one point, but then, wouldn't the optimized subterms be EVEN MORE important. Often, denominators need to be checked for division by zero errors and logs can't use zero, etc. This is called domain checking.
I'd love to hear where this is actually going to be useful.





Thanks for your comments! Indeed, the program presently does not identify large blocks that repeat themselves, and does not try to take it out of the equation. What the latest version does, however, is check that expressions which participate in, e.g., division, are not equal to zero. I also intend to check on positivity for anything that appears under a root. Such checks are generally possible in this program.
In actual fact, coding a single equation is not hard. Coding many equations is tougher. The examples I present here are the kind of equations I've come up against in work, and that's the type that one would require to implement. Of course it's doable by hand, but look at it this way: the first equation of state probably takes about 5 minutes to write. Other equations might take longer  some are so complex that you end up writing it on several lines just so you can organize your thoughts and match them to what you've got in the document. While writing a hundred of these (that's a real number from what we've had to deal with), you're guaranteed to make stupid errors that are annoyingly difficult to catch because empirical data (i.e. test cases) for these are hard to come by. And I don't need to tell you what making a mistake in an equation can mean.
Admittedly, a lot of the equations are, in fact, iterative, and a lot of this stuff is domainspecific and requires substitution of constants taken from tables, for example. So of course you still need to program those by hand. But my program offers a kind of salvation from the routine of manually programming equations that are simple  precisely so that you have more time to spend on the more complicated stuff.





Mmm...I'm still not convinced, but I do admit that you've written a tool, that, if it fits a work pattern that seems to come up often and you just want to get the equation into code to begin a much larger process of integrating it within a overall project, then it's a tool worth using.
I write a lot of timesaving tools as well, either for myself, or for others, whether they are programming or processing data with nasty spreadsheets  which I endeavour to erase from the face of the earth. I can't recall having this particular problem, but that's diversity for you.
Basically, any tool is only valuable if the benefit of using it outweights the cost of not using it  this can be multiplied by the number of times you do use it. Maybe for a oneoff it's not worth the effort, but for many times, it could be. This assumes errors don't cause you to take two steps back for every step forward.





1. GravityGuy
Status Bronze. Member No. 5668330 Bookmark Bookmark Watch Watch
Messages Posted 2  Poster
Articles Submitted 0  Browser
Its one of my habits. When I see someone really start to trash what I think is a great article I love to go to their profile and see what THEY'VE contributed to the community.
So, Dmitri, take it with a grain of salt. You did a great job here.





Hey, I love criticism, and I don't mind people pointing out shortcomings of the program. I do realize that it doesn't fit all scenarios, but I do also know that in my particular case (exemplified by equations in the article), the tool does save a modicum of time.
Soon I'll be able to gauge the community's reaction to some other tools I'm planning to present.
Thanks for your comments, both of you!





Although this might depend to a large extent on the Math features of Word, would your tool handle such constructs as derivatives, integrals etc? If so, I'll thank you profusely in advance! But otherwise, I'd suggest that as a worthwhile pursuit to extend its capability! Thanks for a very useful contribution, in any case!





This is genuinely tough. The problem is that I'm not a mathematician, so I've managed to implement simple linear algebra, but for the advanced stuff (like, e.g., symbolic differentiation) I would need a better understanding of how it's done in C# first of all. If you (or someone you know) is prepared to offer advice on how to implement this in C#, I'd certainly be interested!





I think that the concept here is how one implements such a device, not specifically what types of equations he's implemented it to handle. It's a neat little demonstration of machine translation. I love that kind of thing, and I do it a lot, so I might be biased, but I'm impressed





Seems good, however the Pi character can also mean sum.





Product, you mean? But if it is, it will be in a Munderover element instead of an Mi element.





Hi,
I like the idea and the article. Did you think about taking it a step farther, and translating the MathML straight to an expression tree?
This has the advantage of testing or running the equation straight a way ...





Umm, could you elaborate a bit more on the advantages that would give? From what little I know about expression trees, it would seem that if I decide to use that notation instead of what I presented in this article, it would be kind of like supermegaobfuscation. Or am I wrong?







General News Suggestion Question Bug Answer Joke Praise Rant Admin Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

