# Enhancement: engineering symbol notation as input (e.g: 2n == 2e-9) #2348

Open
opened this Issue Aug 27, 2012 · 8 comments

Projects
None yet
5 participants

### kubaraczkowski commented Aug 27, 2012

 Hi, I have an enhancement idea, though on one hand I am not sure if it was not previously suggested and on the other hand I am not sure if it is 'implementable' without changes to the mainstream python... The idea is to be able to use the notation of numbers commonly used by engineers, but not the one with numbers, the one with letters. As an electrical engineer I use it every day (every second in fact), and all of my colleagues do as well. It is usable in many 'electronic' languages such as SKILL, Spectre (netlist), verilog, etc. Example: We often use ipython as calculator, don't we? Let's try to calculate the time constant of an RC filter ( t=RC ). So we type: ``````t = 2k * 5n and we get t = 10u (okey, now I know. 10 microseconds!) `````` Isn't it more clear than : ``````t = 2e3 * 5e-9 -> t = 1e-5 ??? (hmmm.... e-5 means tens of e-6, so it is in fact 10e-6, ah yes... 10 microseconds) `````` It is not important that the units are present or correct. We know what we put there, so we know what we expect. The main plan is to EASILY put (and get) real-life numbers/values. I don't know if this is easily implementable, since it would perhaps require changes to the main parser... On the other hand it does not overlap neigher variable nor number definitions (variables don't start with a digit, numbers don't use letters except E). Any comments? It feels like a possible great addition to ipython, an already superb engineering 'calculator' :)
Owner

### Carreau commented Aug 27, 2012

 Le 27 août 2012 à 09:51, Kuba Raczkowski a écrit : Hi, I have an enhancement idea, though on one hand I am not sure if it was not previously suggested and on the other hand I am not sure if it is 'implementable' without changes to the mainstream python... The idea is to be able to use the notation of numbers commonly used by engineers, but not the one with numbers, the one with letters. As an electrical engineer I use it every day (every second in fact), and all of my colleagues do as well. It is usable in many 'electronic' languages such as SKILL, Spectre (netlist), verilog, etc. Example: We often use ipython as calculator, don't we? Let's try to calculate the time constant of an RC filter ( t=RC ). So we type: t = 2k * 5n and we get t = 10u (okey, now I know. 10 microseconds!) Isn't it more clear than : t = 2e3 * 5e-9 -> t = 1e-5 ??? (hmmm.... e-5 means tens of e-6, so it is in fact 10e-6, ah yes... 10 microseconds) It is not important that the units are present or correct. We know what we put there, so we know what we expect. The main plan is to EASILY put (and get) real-life numbers/values. I don't know if this is easily implementable, since it would perhaps require changes to the main parser... On the other hand it does not overlap neigher variable nor number definitions (variables don't start with a digit, numbers don't use letters except E). Any comments? It feels like a possible great addition to ipython, an already superb engineering 'calculator' :) could you have a look at http://wiki.ipython.org/Extensions_Index physics extension. It might give you ideas, or already implement what you ask. also discussion on #2293 and #2301 Matthias

### kubaraczkowski commented Aug 27, 2012

 Hi, Well, what I mean is in fact simpler (or perhaps lower level) and different than the physics package. There physical values and physical units are considered (like mass -> kg, length -> m) and "1 m" means "1 meter". This is still very useful, but different to what I'm proposing. The idea is in fact simpler - let "1m" be "1 milli" (without units!) being simply equal to 1e-3. I guess that the latter quoted discussions are more relevant: they propose modifications to the parser (if I understand correctly what AST means/does - no expert here). That's more like it: I want to think 1nano, write "1n", and get a variable with a value of 1e-9. Or even better - get a variable that when printed displays "1n". Regards, K
Owner

### Carreau commented Aug 27, 2012

 Le 27 août 2012 à 12:45, Kuba Raczkowski a écrit : Hi, Well, what I mean is in fact simpler (or perhaps lower level) and different than the physics package. There physical values and physical units are considered (like mass -> kg, length -> m) and "1 m" means "1 meter". This is still very useful, but different to what I'm proposing. The idea is in fact simpler - let "1m" be "1 milli" (without units!) being simply equal to 1e-3. It seems that physics extension already have prefixes _prefixes = [ ('Y', 1.e24), ('Z', 1.e21), ('E', 1.e18), ('P', 1.e15), ('T', 1.e12), ('G', 1.e9), ('M', 1.e6), ('k', 1.e3), ('h', 1.e2), ('da', 1.e1), ('d', 1.e-1), ('c', 1.e-2), ('m', 1.e-3), ('mu', 1.e-6), ('n', 1.e-9), ('p', 1.e-12), ('f', 1.e-15), ('a', 1.e-18), ('z', 1.e-21), ('y', 1.e-24), ] You just need to think of it as (or create a) ' unitless' unit. like `deg` or `rad` Prefix might not work on their own but it might be worth considering. I guess that the latter quoted discussions are more relevant: they propose modifications to the parser (if I understand correctly what AST means/does - no expert here). That's more like it: I want to think 1nano, write "1n", and get a variable with a value of 1e-9. Or even better - get a variable that when printed displays "1n". Regards, K — Reply to this email directly or view it on GitHub.
Owner

### minrk commented Jan 20, 2013

 There's nothing to do here, right? Isn't this a proposal for an extension that does a subset of the physics extension?

### kubaraczkowski commented Jan 20, 2013

 Well, in fact... not... I am a noob in the internals of python, but the physics extension is: a) an overkill b) does something quite different, c) if implemented as proposed would mix up with the physics package (think 1 m - is it "one meter" or "one milli" == 1e-3 ??). I think it has something to do with the parser of python/ipython itself, perhaps a different extension would need to be built. A bit like the physics one in the sense that it modifies the parser, but different. The key idea here is that there "should" be no connection between the prefix/suffix (well it is in fact a suffix to a number, isn't it?) and any "unit". It is "just" a matter of interpreting numbers input by the user. Again, a perfect example is the SKILL language of Cadence, but of course it is not publicly available... Again the idea: typing "1n" is perfectly equivalent to typing "1e-9", just shorter and more understandable for (electrical?) engineers. typing "1.54n * 10.235k" is more natural and more readable than (1.54e-9 * 10.235e-3). If you are an electrical engineer, this is perfectly natural. There are no units here, it's just parsing of the letter trailing the number. As an extra value, printing numbers could be set to such notation as well: e.g: "print(1n_1k)" would spit out "1u", but also "print(1e-4_1e-2)" would spit out "1u". Just for engineering convenience. Again, the physics extension is a superb idea, but the slight difference of a space between the number and the suffix makes a whole different experience (and as said earlier, it mixes up the two things). In fact it would be great to be able to write "1n m/s" and to get a nanometer/second (yes, equivalent to "1 nm/s" but it's in the freedom of choice). I don't know if this will go through, but for electrical engineers would be really great. Would implement it myself, but as I said, I am a noob in the internals...
Owner

### takluyver commented Jan 20, 2013

 As far as I recall, the physics extension handles those prefixes along with a unit - so you can do `1 nm`, but not just `1 n`. If you want this to happen, I'd suggest that you either contact Georg Brandl, the author of the physics extension, about adding these features, or work on it yourself, using the physics extension code as an example (but be aware that we're working on updating the input transformation framework).
Contributor

### juhasch commented Jan 20, 2013

 The physics extension can be modified to accept "1m" and "1 m" by changing the regular expression for quantity: quantity = number + r'(?:\s++/-\s+' + number + ')?' + r'\s*' + unit I haven't tested too much for side effects. Changing the extension to allow omitting units, i.e. "1n" instead of "1nm" leads to ambigous situations like "1m" can mean 1 meter or 1/1000. Unfortunately, the physics extension is not really useable in the notebook, as it only works for single line cells.
Contributor

### juhasch commented Jan 22, 2013

 You might want to try this gist It allows to specify units like "1n" or "1 n", even "1e3p" = 1e9 I don't find it too useful currently, but l would be interested to know if it works well for you.