Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Unicode Greek symbols for variables in python 3

Tags:

python

unicode

I can use Unicode symbols inside Python. As a researcher this excites me because it could make my equations more readable.

  1. Will there be problems writing complicated equations involving several such variables?

  2. Will the performance of the code be affected?

For an example, this is a piece from my re-written code with Unicode characters:

# Use iterative solver to find the solution
φ_equi = math_op.itr_sol_search(still, 0, φ_max)

# Evaluate the slop of the GZ Curve at the new equilibrium angle
GZ_slope = math_op.cspline_deriv(φ_equi, φ_pts, GZ_pts) * 180/π

N_Roll_MI = (m * g * GM_T * Tφ**2)/(4 * π**2)
Om_R = sqrt( (m * g * GZ_slope) / N_Roll_MI )  
like image 427
sreenath subramaniam Avatar asked Oct 16 '22 08:10

sreenath subramaniam


1 Answers

Don't, you actually decrease readability. The give-away is that you need to comment the variables what they do. Instead of writing φ_pts and a comment, you could name it equilibrium_angle directly. Now almost everyone can understand it, not only a researcher that is familiar with the subject matter.

Maths with one letter Greek variable names stems from a long ago time and is optimised for writing with chalk on shale or a blackboard. Computer programming is not the same, so do not blindly apply tools and traditions from other subjects.

The problems are not in the area you are asking about, there are no foreseeable technical or performance problem. It's the human factor you need to worry about.

like image 101
daxim Avatar answered Oct 20 '22 10:10

daxim