Author Topic: Electr, Interactive language for electronic formulas (on the command line)  (Read 6657 times)

0 Members and 1 Guest are viewing this topic.

Offline FrankBussTopic starter

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Looks like a good idea:
https://github.com/lkdjiin/electr
I think best way to add comments or feature requests is in the "Issues" menu.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline timofonic

  • Frequent Contributor
  • **
  • Posts: 904
  • Country: es
  • Eternal Wannabe Geek
It looks interesting. I would like to be able to be used as a plugin for other software too. From EDA software to office suites, this could save me time switching between my calculator and my computer while doing homework

I also would like a CLI in KiCad, but maybe that's a bit so mainstream idea....

Of course, it would be nice to export the formula in MatML or that weird LibreOffice syntax.

I like CLIs mixed with GUIs, call me a pervert and/or insane if you want it ;)

(Isn't this thread is not appellate in the open source section?)
 

Offline FrankBussTopic starter

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
To be used as a plugin and maybe even for implementing my own hardware calculator, it should be written in C or C++. Should be not too difficult with lex and bison for the engine, and then an API for using it, like feeding command lines, setting and reading variables etc.

Don't know if it should be in the open source section, it is an electronics tools project, but not an open source hardware project.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Instead of writing from the scratch, Python has two nice packages for numerical and symbolic computation: NumPy and SymPy. SymPy has no other dependencies. Writing the UI component and expression parser and evaluator should not be too complicated as the numerical engine is already available. Integrating to Kicad shouldn't be too difficult either as Kicad is already using Python.

Edit: SymPy can also produce MathML output in addition to the formatted ascii output.
« Last Edit: August 28, 2015, 02:40:12 pm by Kalvin »
 

Offline dom0

  • Super Contributor
  • ***
  • Posts: 1483
  • Country: 00
Why bother writing a language in Python when you can so easily implement a DSL in Python? Okay, fort very-very-shorthand notations you might wand a littl' extra parser, but that hardly justifies a language of it's own.
,
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
+1 DSL.

Use the PyParsing module to tokenize and parse the input and you get tokenized output.

PyParsing has it's own DSL that you can use to specify the grammar, in a form very similar to BNF.

no lex or bison needed :)
 

Offline FrankBussTopic starter

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
PyParsing looks interesting. A DSL written in Python (with functions, classes etc.) would be not a good idea, because the extra notation that Python requires, is too much to write for this simple calculator like idea.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Why not just type your formulas into Google Search? It knows about dimensional consistency, fundamental constants, even currency conversions if you happen to get electricity prices from an unfamiliar source (contrived example for sure, bear with me)

"1/2 * (1 A)^2 * 100 milliohm"
"1 * avogadro's number * electron charge * 5 volts * (1 NZD per kilowatt hour)"

That's all I've ever needed, and there's always a browser bar on my screen somewhere. And you can link others to your working without forcing them to download some software. Can't get more convenient than that!

Having said that, the possibility of substituting variables is nice. But then, if I'm doing some full-on Monte Carlo analysis or something, I'll just use something familiar and powerful like MATLAB. So for me personally at least, there is no niche between Google Search and MATLAB that this will fill.

I also would like a CLI in KiCad, but maybe that's a bit so mainstream idea....

KiCad does have an interactive python shell I thought?
 

Offline timofonic

  • Frequent Contributor
  • **
  • Posts: 904
  • Country: es
  • Eternal Wannabe Geek
Why not just type your formulas into Google Search? It knows about dimensional consistency, fundamental constants, even currency conversions if you happen to get electricity prices from an unfamiliar source (contrived example for sure, bear with me)

"1/2 * (1 A)^2 * 100 milliohm"
"1 * avogadro's number * electron charge * 5 volts * (1 NZD per kilowatt hour)"

That's all I've ever needed, and there's always a browser bar on my screen somewhere. And you can link others to your working without forcing them to download some software. Can't get more convenient than that!

Having said that, the possibility of substituting variables is nice. But then, if I'm doing some full-on Monte Carlo analysis or something, I'll just use something familiar and powerful like MATLAB. So for me personally at least, there is no niche between Google Search and MATLAB that this will fill.

I also would like a CLI in KiCad, but maybe that's a bit so mainstream idea....

KiCad does have an interactive python shell I thought?

Google, don't be evil and shit like that. I would prefer to not depend on cloud stuff all time, I have enough with Dropbox and Gmail.

MatLab is expensive as hell, no option to students, poor researchers, poor engineers and FOSS guys that don't want to be locked-in in one vendor. Maybe something can be done with QtOctave/Octave, Genius, FreeMat, R, SageMath, SciPy, Julia, NCL, Scilab, Rlab. Maybe something with the features of WP34S/HP50G. Whatever, I'm still staying to learn maths and physics in a useful way, so I didn't look at that software carefully.

It seems QUCS uses Octave.

Python shell? I didn't look at it at all, my Eagle to KiCad transition is going write painful to me, the lack of file format import/export and GUI quirks are making a difficult transition to me. Anyway, is that a bit similar to a classic CLI in some way? That may be a new paradigm that I need to mean, I was something happy with Eagle CLI, despite having tons of limitations (I could do some operations a lot faster as command or shortcuts than just using the GUI).

Anyway, I'm still as stupid in programming than with electronics, I just see other people messages with envy and amazed if their knowledge superiority, using cool testing equipment and told I still couldn't afford. Too much to learn, too much to improve my learning and time organization skills.
« Last Edit: August 29, 2015, 05:02:40 pm by Circuiteromalaguito »
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11859
  • Country: us
It looks interesting and similar thoughts have occurred to me many times. It's a neat idea for a little mental diversion. But if I needed it badly enough I would simply write it for myself. No need to wait for someone else to do it.
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
I've also used SMath Studio for things like this in the past.

Smath Studio is a free (but not open source) Mathcad clone.  It's really well done and understands units as well as the SI multipliers like pico, kilo, etc..

It is written in C#, and uses  .Net on Windows and runs with Mono on Linux. I've used it on Linux just fine.

http://en.smath.info/

Here is a few of my previous posts where I did some calcs in SMath Studio:
https://www.eevblog.com/forum/projects/variable-dc-dc-converter/msg331111/#msg331111
https://www.eevblog.com/forum/beginners/buck-fb-compensation-for-varying-v_out/msg117855/#msg117855
https://www.eevblog.com/forum/projects/(help)ferrite-chip-as-a-smps-secondary-filter/msg119445/#msg119445





 

Offline FrankBussTopic starter

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
smath looks nice. But how do you enter "ohm"? I've read the manual and micro works fine (for example to enter 7 uF, you enter "7 m ctrl-g F tab". But "O ctrl-g", which should result in ohm, or "7 k o ctrl-g tab", which I would expect to show 7 kohm (with the greek letter, the forum has problems with it), doesn't work.

Is it possible to use just the SI unit prefix, like "k" or "n", instead of the full unit? In the units list there are a lot of derived units, like kV, kW etc., but I can't find just the unit prefixes. But then this might resukt in some amgibuity, like k for Boltzmann constant or kilo, so not a big problem to enter the full unit all the time. But seems like some units are missing, like fF (femtofarad).

A big problem is the output scaling. I tried 1 kohm+200 ohm = and it says 10200 ohm. I would like to have 10.2 kohm. Is it possible that it auto-converts it to the next useful unit prefix?

I tried the examples from the electr page, and it works, but maybe a bit too many keystrokes needed sometimes. But very good for presentation, or if you want to interactively change values. A living notepad, like in Mathematica, or a spreadsheet in Excel, but more free-form and better to edit.


So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11859
  • Country: us
Oh, that output doesn't look right. Numeric results should be scaled in engineering notation according to the "rule of three", where there are 1-3 digits before the decimal.

Hence 10200 ohm becomes 10.200 kohm, 7034 Hz becomes 7.034 kHz, 1000 pF becomes 1.000 nF, etc.
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
For ohms I've always just selected it from the Symbols tab on the right.  Seems like a bug if you can't do O ctrl-g

As for the output units, I think it definitely has some issues there that need to be fixed.  For example, look at this snippet from one of my earlier posts. My inputs are derived units like kHz, but the output was a derived unit Farads without any engineering rules applied.  It seems you can set the max decimal places, but not engineering rules.



I had to summarize the result in uF on the last line there.

It's even worse in the clipping from this thread:
https://www.eevblog.com/forum/projects/lm399-based-10-v-reference/msg219394/#msg219394

note the output from SMath was in units of kg m2 / A s3 , which is a Volt in SI base units:) But it gets other derived units OK, like Farad in the previous example.



It would be so much cleaner if it could output the obvious nA and pA that I can see right there... and uV, mV, etc...
« Last Edit: August 29, 2015, 08:25:22 pm by codeboy2k »
 

Offline FrankBussTopic starter

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Oh, that output doesn't look right. Numeric results should be scaled in engineering notation according to the "rule of three", where there are 1-3 digits before the decimal.

Hence 10200 ohm becomes 10.200 kohm, 7034 Hz becomes 7.034 kHz, 1000 pF becomes 1.000 nF, etc.
There is a bug report for the unit prefix problem:
http://smath.info/bts/Issues/IssueDetail.aspx?id=1245
I voted for it. At least for presentation it is already possible to manually change the unit, as demonstrated here. But there should be a menu option, which enables the engineering standard rule of three.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
I sure would like to see SMath Studio open sourced.  It's the most capable live math notebook that I've seen that is a very good clone of the excellent Mathcad program. 

The only other one that might come close to it is the Ipython Notebook.

IPython doesn't do physical quantities directly, but you can use the Physics module from https://bitbucket.org/birkenfeld/ipython-physics/raw/default/physics.py

An example is below, in standard IPython, not an IPython Notebook, but you could do the same in a live Notebook.




By the way, Microsoft's F# has units : https://msdn.microsoft.com/en-us/library/dd233243.aspx
 

Offline dom0

  • Super Contributor
  • ***
  • Posts: 1483
  • Country: 00
No need to type print(xx) in a Python shell...
,
 

Offline FrankBussTopic starter

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
For ohms I've always just selected it from the Symbols tab on the right.  Seems like a bug if you can't do O ctrl-g
I created a new bug report for it:
http://smath.info/bts/Issues/IssueDetail.aspx?id=2277
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
No need to type print(xx) in a Python shell...

I know. :)
Since I was doing a demo then it makes it more obvious to the uninitiated what I am doing when I type print(s), rather than just s

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf