Jump to content

Math notation: multi-letter variables


Danijel Gorupec

Recommended Posts

What is your opinion on using multi-letter variables in math formulas? Should they be used more often or avoided?

 

If I use a quantity called 'Gross Domestic Product' in a formula, I might want to use 'GDP' as the variable name representing it. But this actually seems as a rare example - I cannot think of many such examples, can you?

 

Should I better come up with a single letter representing some money quantity (like 'M') and then use the 'GDP' description in its index? That is what I usually do when I have several quantities of the same type in the same formula (for example, to represent a current through resistor R1 and a current through resistor R2 I might use indexed variables i_R1 and i_R2).

 

If I still use multi-letter variables, should I always explicitly use the multiplying dot (cdot) between any two variables or is the 'invisible times' still appropriate?

 

We already use multi-letter function names often. There are also some multi-letter measurement units (mol, cd).

 

In my opinion, there are some examples where typing whole words might be beneficial. Like when you state a definition or a law... In the following three examples, I find example #2 to be the clearest:

Example1: a distance equals to the product of speed and time

Example2: distance = speed x time

Example3: s = v t

 

When using computers, multi-letter variables might be easier to type than indexed variables. On the other hand, computer monitors are of limited width so one might prefer single-letter variables.

 

I am posting this into the lounge because I am mostly interested in your personal opinions and aesthetics.

Link to comment
Share on other sites

In my C/C++ programs I use single letters for loop counters, like i,j,k,l,...

 

For coords primary are x,y,z, then x0,y0,z0, then x1,y2,z2 etc.

 

For other variables multi-letter name immediately identifying what variable contains.

 

Couple examples from my currently opened project in Visual Studio:

position, position0, position1, position2,

normal, normal0, normal1, normal2,

polygon_list, polygon, polygon_count,

point_list, point_count, point,

cursor_position, origin, font_scale, metrics,

segment_length

Edited by Sensei
Link to comment
Share on other sites

To borrow from programming a abit. When writing a section of code all variables should be written in a form such that on returning to a section of code or when somebody new looks at your code your variables should be easily recognizable and not confusing without a long winded explanation. For instance the variable device_width_in_pixels should contain the device width in pixels.

 

 

If I still use multi-letter variables, should I always explicitly use the multiplying dot (cdot) between any two variables or is the 'invisible times' still appropriate?

 

It should be written in a clear and concise manner at all times. For instance.

 

3 + 4 * 5

 

This is unclear and ambiguous unless standards tell you to do things a certain way you should describe the order of precedence in some manner. In javascript it would be evaluated as 23 in another language it could be evaluated as 35

 

(3 + (4 * 5))

 

This is better using brackets to denote precedence. Thus evaluating to 23 and

 

((3 + 4) * 5)

 

evaluating to 35.

Link to comment
Share on other sites

I would want to avoid 'AB' being mistaken for 'A times B' (whatever times means here) in a paper. I would not worry about this for certain maps that are well knows, like Tr or Det or Span etc.

 

 

For programming, I would worry less as clarity of the inputs is important.

Link to comment
Share on other sites

In programming, minified code often uses indexed variables, but it makes it nearly impossible for a human to follow the code and debug issues. Minified code is often generated as a way to save space, especially in javascript, however.

 

The standard in our shop is to use camel case for anything that isn't a constant, and all upper case for constants. So you would have:

 

DAYS_PER_WEEK and currentDayOfTheWeek for example.

Link to comment
Share on other sites

Ok, I see that you are not very crazy about using multi-letter variables inside math formulas. This is understandable, some people say that using single-letter variables makes it easier to see the equation structure. I agree.

 

Also, copying line after line of math is easier if variables are shorter.

 

I tried to write the Pythagorean theorem using names BC, AB and AC for triangle sides (instead of a, b and c): AC^2=BC^2+AB^2... This looked very weird at first, but after I was looking at it for some longer time it settled down. The important thing imo is that if you ever decide to use multi-letter variables in your math formulas, then you should always use cdot (and keep this consistent through the whole paper).

 

Multi-letter function names are often cast in some different font to reduce ambiguity. Also, function names are often standard and well known.

 

(Ajb, I noticed that you used capital first letter in your function names - Is this Mathematica influence or your suggestion?)

 

...

 

Regarding programming, I would generally allow single-letter variables only for a very short scope (several lines). Very few exceptions from that. (Unless, of course, the intention is to make sw unreadable).... Interesting is this difference between multi-letter variable usage in pen-written math and keyboard-written software.

Link to comment
Share on other sites

I noticed that you used capital first letter in your function names - Is this Mathematica influence or your suggestion?

I tend to use capitals (and a font change), I am not sure why, but you are right that Mathematica typically requires this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.