josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.32k stars 1.24k forks source link

Mathjs : generating formula for RX and Tx exchange between two different equipments not speaking same language #1699

Closed yboujraf closed 2 years ago

yboujraf commented 4 years ago

Dear @jherdman , @pavpanchekha , @tmcw , @tmpvar , @garrison

translate from different protocols data with properties.

One of the properties is "Formulas".

Formulas ( Rx / Tx)

• Formulas provide a way to project values received from an equipment to another value range or representation. • For example, an equipment might send gain values as INTEGERs ranging from 0 to 65535, while the actual gain range in is -64db to 12db. Obviously, the user of a front-end application prefers to deal with the gain values in db instead of the technical INTEGER range. • To accommodate for this need, I am looking to provides the concept of formulas.

• This will create a basic formula which does not alter the input value – meaning it returns the identity of the input value:

image

Picture from lawo.de

• The input value of the formula is denoted with the symbol $. You can use this symbol in an arithmetic expression which yields the desired output range. • The line “$ =“ defines the input value (as sent by the device) of the formula. • The following line “RX($) =“ defines the expression used to convert values that have been received from the device. • The following line “TX($) =” defines the expression used to convert values that are about to get sent to the device. This expression has to reverse the projection made in the RX expression.

• To follow the ifSpeed example, let’s display the speed of the interface in megabytes per second instead of bits per second: o Enter a test input value in the “$ =” field, e.g. “10000000” (10 megabit) o Enter the expression $ / 8000000.0 into the “RX” field. 8000000 is the factor used to turn unit bits into unit megabyte. o To reverse the RX expression, enter the expression $ * 8000000.0 into the “TX” field. o You will now see the following:

image

Picture from lawo.de

o You can see that the result of the RX expression is 1.25 (megabytes) and the result of the TX expression, which uses 1.25 as input value, is 10000000 (bits per second, which is equal to the input value of the RX expression).

INPUT RANGE

• I have an Analog to Digital convert 12 bits (4096 positions) • The manufacturer of the A/D converter infor you for 0 = -128dB and for 4095 = +15 dB

I am looking to create as above "Formula" with possibility to select linear or log the Rx and Tx formula.

Data model of my paramater

{
                    "identifier": "ParameTypeStream",
                    "description": "Stream PPM MAIN",
                    "value": 0,
                    "minimum": -4096,
                    "maximum": 480,
                    "access": "read",
                    "format": "%8.2f°",
                    "enumeration": "",
                    "factor": 32,
                    "isOnline": true,
                    "default": -1024,
                    "type": "integer",
                }

The properties : formula

The Minimum & Maximum are :

"minimum": -4096,
"maximum": 480,

Then I need to generate the correct formula for Rx & Tx.

  "formula": "1*\n1/"

The /n indicate the separation between the Rx formula and the TX formula.

Before we used F# and Windows OS for doing this but now we are using nodejs and javascript and better if typescript cross platform for doing this.

I don't know if mathjs could help us o figure out our requirement?

Best Wishes Youssef

josdejong commented 4 years ago

I don't know if mathjs could help us o figure out our requirement?

mathjs could definitely be used to parse and evaluate expressions like $ / 8000000.0. I'm not sure though what your formula "1*\n1/" means, it's not syntax that the expression parser of mathjs will understand out of the box.

It's maybe easiest to just play around a bit with the expression parser to get a feel of what it can do.

yboujraf commented 4 years ago

Dear @josdejong

Yes it think MAthjs could do what I need but need some help or an example in javascript.

Regarding *formula "1\n1/"**

That means when the client receives this properties the "/n" is the separation from RX formula then TX formula then no needs two properties

Use case - write the formula - RX

  1. the client introduces the formula in an editbox. Just the '$' indicates the value I need to passing into the math expression and get the result.

Use case - write the formula - TX

If the RX formula is already written in the editbox , I need and expect with Mathjs library to generate the invert formula for TX and vice-versa if Tx is filled, then I got RX.

If RX = $/1000
then I need to get for TX = $*1000

The formula could be complex (log, square, ^, (expression)*log) I attached a document from my friend written for F# (Microsoft) long time ago and now we are using nodejs and javascript.

Ember+ Formulas.pdf

I hope you could make a simple example of code how to use it and then I will try it ;-)

Best Wishes for 2020 Youssef

josdejong commented 4 years ago

Math.js does not have support for inverting formulas, though we would love to have this! It is not a trivial thing to solve though. It depends also on whether you want to solve it numerically or algebraically. There is an open issue for this, about support for a solver: #38.

yboujraf commented 4 years ago

Dear @josdejong

I think I don't need this.

Is just need in the formula properties to write the equation (formula) provided by the manufacturer to get the readable value for client side like celsius, -14.00dB instead of 4054.

But when the client want to interact, which is the revert formula to convert to the sensor or other.

RX = $/1000 TX = $*1000

Not problem to write it and math could do the job.

But when you have

RX = ln($*sin(34°)) TX = ? I will die

Best Regards, Youssef

josdejong commented 4 years ago

Well, mathjs can definitely parse an expression like $ / 1000 or log($ * sin(34 deg)) for you and evaluate it. It can also work with units, that may be interesting for you too :).

yboujraf commented 4 years ago

Dear @josdejong

Great news but I need reverse also then I could use it on my framework.

Could you generate on the fly the TX or RX depend which formula is available?

If yes, my 2020 will start with happiness ;-) Youssef

josdejong commented 4 years ago

Now I'm confused.

yboujraf: I need and expect with Mathjs library to generate the invert formula for TX and vice-versa if Tx is filled, then I got RX

Jos: Math.js does not have support for inverting formulas, ...

yboujraf: I think I don't need this.

yboujraf: Great news but I need reverse also then I could use it on my framework.

So I guess you do need support for automatically inverting a formula? Or not? Or are you going to write the reversed version yourself and enter it in the system? Anyway, like I said before, mathjs doesn't have support for calculating the inverse of a formula at this moment.

yboujraf commented 4 years ago

Dear @josdejong

Apology,

Ususaly I add always topic with description to answer.

Topic - Mathjs for formula RX or TX

With your library I could calculate the value to send to the Client (RX) OR the sensor (TX).

That's great and will try it in my proof of concept.

Topic - Mathjs - enhanced functionality - reverse a formula

If you could add in your roadmap the possibility to reverse the formula from RX or TX would be great.

I found in python, F# but we are nodejs typescript / javascript and don't want to use wrapper for using only this functionality from different languages.

I am sure this reverse functionality will give more success to your library.

I hope now this is clear

Youssef

josdejong commented 4 years ago

Thanks, yes, clear to me :)

If you could add in your roadmap the possibility to reverse the formula from RX or TX would be great.

It is on the "roadmap" since it's an open issue, but it has been for a long time and isn't picked up yet by anyone (I will not be able to pick it up by myself on sort term either). If it's really important to you maybe you can consider contributing it yourself :)

josdejong commented 2 years ago

Closing this issue now, it has been inactive for a long time