Electr, Interactive language for electronic formulas (on the command line) - Page 1
Forum section: electronics / projects

author: FrankBuss
author_rank: Unknown
timestamp: August 27, 2015, 11:21:54 pm
content: Looks like a good idea:https://github.com/lkdjiin/electrI think best way to add comments or feature requests is in the "Issues" menu.

author: timofonic
author_rank: Frequent Contributor
timestamp: August 27, 2015, 11:52:57 pm
content: 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 homeworkI 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?)

author: FrankBuss
author_rank: Unknown
timestamp: August 28, 2015, 12:08:45 am
content: 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.

author: Kalvin
author_rank: Super Contributor
timestamp: August 28, 2015, 02:35:29 pm
content: 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.

author: dom0
author_rank: Super Contributor
timestamp: August 28, 2015, 03:51:44 pm
content: 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.

author: codeboy2k
author_rank: Super Contributor
timestamp: August 29, 2015, 06:54:00 am
content: +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

author: FrankBuss
author_rank: Unknown
timestamp: August 29, 2015, 11:55:52 am
content: 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.

author: rs20
author_rank: Super Contributor
timestamp: August 29, 2015, 12:23:11 pm
content: 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.Quote from: Circuiteromalaguito on August 27, 2015, 11:52:57 pmKiCad does have an interactive python shell I thought?

author: timofonic
author_rank: Frequent Contributor
timestamp: August 29, 2015, 04:14:50 pm
content: Quote from: rs20 on August 29, 2015, 12:23:11 pmGoogle, 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.

author: IanB
author_rank: Super Contributor
timestamp: August 29, 2015, 04:35:03 pm
content: 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.

author: codeboy2k
author_rank: Super Contributor
timestamp: August 29, 2015, 06:05:54 pm
content: 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/#msg331111https://www.eevblog.com/forum/beginners/buck-fb-compensation-for-varying-v_out/msg117855/#msg117855https://www.eevblog.com/forum/projects/(help)ferrite-chip-as-a-smps-secondary-filter/msg119445/#msg119445

author: FrankBuss
author_rank: Unknown
timestamp: August 29, 2015, 07:13:33 pm
content: 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.

author: IanB
author_rank: Super Contributor
timestamp: August 29, 2015, 07:24:45 pm
content: 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.

author: codeboy2k
author_rank: Super Contributor
timestamp: August 29, 2015, 08:20:07 pm
content: 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-gAs 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/#msg219394note 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...

author: FrankBuss
author_rank: Unknown
timestamp: August 29, 2015, 08:43:28 pm
content: Quote from: IanB on August 29, 2015, 07:24:45 pmThere is a bug report for the unit prefix problem:http://smath.info/bts/Issues/IssueDetail.aspx?id=1245I voted for it. At least for presentation it is already possible to manually change the unit, as demonstratedhere. But there should be a menu option, which enables the engineering standard rule of three.

author: codeboy2k
author_rank: Super Contributor
timestamp: August 29, 2015, 08:50:01 pm
content: 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 theIpython Notebook.IPython doesn't do physical quantities directly, but you can use the Physics module fromhttps://bitbucket.org/birkenfeld/ipython-physics/raw/default/physics.pyAn 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

author: dom0
author_rank: Super Contributor
timestamp: August 29, 2015, 08:53:32 pm
content: No need to type print(xx) in a Python shell...

author: FrankBuss
author_rank: Unknown
timestamp: August 29, 2015, 08:54:33 pm
content: Quote from: codeboy2k on August 29, 2015, 08:20:07 pmI created a new bug report for it:http://smath.info/bts/Issues/IssueDetail.aspx?id=2277

author: codeboy2k
author_rank: Super Contributor
timestamp: August 29, 2015, 09:01:51 pm
content: Quote from: dom0 on August 29, 2015, 08:53:32 pmI 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