🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Programming and Higher Mathematics

Started by
58 comments, last by dr3w 5 years, 9 months ago
36 minutes ago, Fulcrum.013 said:

Really it much easier tasks than graphis programming,phisic simulations and so on. I has worked as Lead Engeneer-Programmer on accounting departament 3 years while studing. Lead mean that i has to project  and implemented myself  factory wide accounting systems  for datacentre of factory with 40k+ employes. After get a diploma i has been promoted to Intern Engineer-Programmer of  FA departament. And it really has been a promotion (salary 2 times higher.) and field much harder to understand while software critically responsible instead of accounting software. 

For some years, I worked in mission critical distributed computing systems in Investment Banks.

At one point I was responsible for the system side (the code for the distributed computing engine, data gathering and such) of a system that ran on a farm of 2000 machines and did distributed calculations of the value of custom Financial Instruments (specifically, Over The Counter Stock Derivatives) which were held in the books of Traders in a whole department of the bank (total values adding up to many millions, even billions of dollars). Each node in our farm had a calculation engine which implementated the formulas that calculated the estimated values of those financial instruments (as they where not in an open market so their values had to be estimated), said calculation engines done and maintained by a team of specialists called Quants, which were more Mathematicians than Programmers.

One day, just before the crash of 2008,our whole computing farm went down. We would restart it and after a while all nodes would die. It turns out, the calculation engine in the nodes was crashing and taking down the rest of the program. The night before, the value of Bear Stearns stock had gone down massively and the whole company became worth something like 1 dollar (not 1 dollar per-stock, 1 dollar for ALL stocks), so I suggested that maybe some of the calculations used the first order derivative of the price of that stock, which because of the extremely fast and big change was basically infinity, thus causing either a crash directly or if used in the wrong side of a division would cause a divide-by-zero error which would crash the calculation engine (which was a C++ library).

The Quants checked it and I was right. Their reason for not having put an exception check around the code that used that 1st order derivative was "we never thought this would happen" (Yes, the very same excuse for most of the massive losses in the 2008 crash).

So THIS is what Advanced Financials is and this is also my example of how a programmer who wasn't even on the Mathematical heavy side, by knowing Mathematics saved the whole team a lot of time and headaches and possibly saved the banks millions (as that calculation engine was mission critical and it being down meant that the Traders would not know what was the right price to sell or buy certain things).

That said, the bank is was working with, Lehman Brothers, went bankrupt a week later, so it didn't really matter all that much in the end ?

Advertisement
2 hours ago, NikiTo said:

The simplest example is people using 4x4 matrices to translate 2D shapes around.....WHY

Becouse standart mathematical libraries have a 4x4 matrices only becouse both AVX and GPU use 4 component vectors. Also 2D rotation is just a 3D rotation around z axe only,  so can be performed using same mechanizm.  Also matrices have feature to accumulate transformations. So you no need a code to perform a each kind of transformation with vertex buffer. Yo can just accumulate required sequence of transformations on single matix and then apply it all to vertices by single vector to matrix multiplication per vertex. In example that only translate a vertices it may look a really stupid. But on real usage where it unknown what same transformations matrix has accumulated,  it just much simply to apply any kind of transformation to vertices by single kind of operation.

So thay just follow a concept of superposition that says that optiaml elements not varranty a optimal composition. Or by other worlds to win in big it require to sacrafice in little. Other similar example - search in sorted array. Linear search is chache friendly but have O(n) complexity. Binary search is not chache friendly but have a O(log n) complexity. So to have much faster algo we have to sacrafice hardware optimization. With matrices it little bit complexive - it sacrafice a small algo and memory optimization to win both algo and hardware optimisation in much large scale.

#define if(a) if((a) && rand()%100)

Everyone, thank you for responding. I was wondering, can I see a code example of how much easier it is to do something with knowledge of Calculus/Trigonometry? Preferably in Java or some other C-Like language? Currently, I am learning about logarithms and graphing in my college Precalculus class. 

17 hours ago, RidiculousName said:

I was wondering, can I see a code example of how much easier it is to do something with knowledge of Calculus/Trigonometry?

Just a example of function that calculates normal to triangle

TVec3 GetNormal(const TPoint3& A, const TPoint3& B, const TPoint3& C) { return (B-A)%(C-A).Normalized();}

It uses overloaded operators % for cross production of vectors and  - for vector substractions.

Normalized vector inside looks like

TVec3 TVec3::Normalized() const { return *this/Abs();}  

Abs() method looks like  

float TVec3::Abs() const { return sqtr((*this) * (*this));} 

 where * is overloaded operator of dot production that looks like.

float TVec3:: operator * (const TVec3& r) const { return x*r.x+y*r.y+z*r.z;} 

Also function that calculates area of triangle looks like:

float GetArea(const TPoint3& A, const TPoint3& B, const TPoint3& C) {return (B-A)%(C-A).Abs()/2;}

And so on. Using a linear algebra any computations in 3D space described by set of tiny (in most cases single-line) but multi-purpose methods. Bigest of it like a LookAt matrix calculation have 4 lines length.

Same with using calculus. Really any phisic theories described by sets of  differential equations, so any phisics simulations can not be done without integration of its equations. If we see in actual code tiny sequence of base arithmethic operations like

void TBody::UpdatePos (float dTime){

   I += Thrust * dTime ;

   mass -= FuelConsumption * dTime; 

   TVec3 OldVelocity = Velocity; 

   Velocity = I/mass;

   Pos += 0.5*dTime*(Velocity+OldVelocity);

}

It mean that calculus has been used to find it sequence of arithmetic operations  that perfom a numerical integration of given by phisic theories differential equations. So it not a "much easy to do using calculus",  it is "imposible to do without calculus". 

#define if(a) if((a) && rand()%100)

20 hours ago, RidiculousName said:

how much easier

In 3D - matrices. Knowledge of matrices makes your life much easier.
For accelerations you can play with numbers and move a character around too. But it helps to understand trigonometric graphs.

@Fulcrum.013 You first code example is pretty hard to read. It could be coded much more readable. A lot more readable.
When i code my own implementations of math functions, i code it in the easiest way to read possible. This way i can always look to them as looking to a tutorial when i need the same function but forgot how it works. Instead googling it again, i can read it from my own code. It pays to be readable.
 

3 hours ago, Fulcrum.013 said:

it is "imposible to do without calculus".

Still i can copy the formulas from internet :P (not copy the code, but copy the formulas. In some sites they explain how the formulas were obtained. If I read that explanation, i would understand how they work, but i just don't need to do that.)

1 minute ago, NikiTo said:

Knowledge of matrices makes your life much easier.

Exactly, but matrices,vectors and operations over it introduced by linear algebra. Also other specific case of linear algebra - analitical geometry, widely used for 3D too, but for purposes to find intersections, align directions and so on.

 

6 minutes ago, NikiTo said:

Still i can copy the formulas from internet :P

Copying formulas from internet you downloading a communism to your PC and inserting to you code bugs maked by other people, that you can not find without knowledge of formulas background. And of cource yo can not improve or adopt solution to your specific case without knowledge of backgrount. Also it just a most simple formulas available for googling. Somesing little bit commplecsive than recalculation of position vector with no respect to physical lows, usualy available in differential equations form only. 

12 minutes ago, NikiTo said:

You first code example is pretty hard to read. It could be coded much more readable. A lot more readable.

Its depend. For me, then closer formula code to mathematical notation than easier to understand what same it do. Of cource C++ don't allow to use all set of mathematical symbols as names of opperators, so some of it have to be raplaced by unused in math symbols that present in C++ operators names set, so make notation library implementation dependent.

#define if(a) if((a) && rand()%100)

2 minutes ago, Fulcrum.013 said:

Also it just a most simple formulas available for googling.

The occasional times i needed more complex formulas, still googling can solve it. There are a lot of technical papers people have published in internet. I first read vaguely the description and the speed/precision/result graphs. And if it looks nice, I code it myself reading the technical paper. And finally ONLY if needed i could learn the danm algebra behind the formulas grrrrrr

My original point was "Sukcing at Math is not a reason to give up on programming"

I don't want to devalue mathematicians. I think i would be not able to code fire particles and sparkles. I could only code fire particles math from others, not create my own. I admit this. I think somebody good at math should do that.
I just say, so far, being bad at math haven't stopped me.

14 minutes ago, NikiTo said:

I just say, so far, being bad at math haven't stopped me.

Just lack of required math often stop any progress of project of cource. And you have to google and try, google and try solutions of similar tasks, on things that can be once googled at whole and adopted exactly to your  specific case much faster.

#define if(a) if((a) && rand()%100)

1 minute ago, Fulcrum.013 said:

Just lack of required math often stop any progress of project of cource.

Was you born knowing about dot products?
I learn upon demand. Code upon demand. For a stand alone developer, it is very important to save time.

Just now, NikiTo said:

Was you born knowing about dot products?

I has study it in secondary school.

#define if(a) if((a) && rand()%100)

This topic is closed to new replies.

Advertisement