Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitutions for GenericSeries and MathematicalExpression #647

Open
vhirtham opened this issue Nov 16, 2021 · 4 comments
Open

Substitutions for GenericSeries and MathematicalExpression #647

vhirtham opened this issue Nov 16, 2021 · 4 comments
Labels
core weldx core classes and functions feature new API features low priority low priority issues during ☕

Comments

@vhirtham
Copy link
Collaborator

vhirtham commented Nov 16, 2021

I do not want to include this into the first version of the GenericSeries since it is already enough work, but I think we should definitely consider it in the future:

Sometimes there are expressions that have repetitive terms. For example, consider the following I used in the GenericSeries tutorial:

expr = "tanh((x-t)/5) - tanh(x-t-10)"

Here the term x-t is used twice. Not so bad you might think and it isn't as long as you do not start using units. Here x is a spatial dimension with a length unit and t is time. Also, consider that tanh requires an angular unit or no unit at all and suddenly you get a total mess. To get everything sorted out, you need to bloat this subterm to a * x + b * t where a and b are parameters that are just there to clear the units. And no, clearing the units from the variables in advance (before we evaluate) is also no option because x and t might appear in other terms where the unit does not need to be cleared. The simple solution would be to have a substitution like this:

expr = "tanh(s/5) - tanh(s-10)"
subs = {"s": "a * x + b * t"}

Apart from some minor difficulties, this shouldn't be a big issue since it can be a simple text replacement in the beginning and get some more depth later (strings are not the only method to define a math expression or think of chained substitutions). This should probably be implemented as a feature of the MathematicalExpression

@vhirtham vhirtham added feature new API features low priority low priority issues during ☕ core weldx core classes and functions labels Nov 16, 2021
@CagtayFabry
Copy link
Member

I think a string replacement before evaluation is a good (and simple) solution, everything else might be a bit overkill for the scope of weldx for now

PS: just seeing tanh(x-t-10) makes my skin crawl when thinking about the units (and we should avoid automatically ' just clearing' units because this would defeat the whole purpose in the first place. There is no such thing as 'clearing units', there is only conversion 📜

@vhirtham
Copy link
Collaborator Author

PS: just seeing tanh(x-t-10) makes my skin crawl when thinking about the units

It's not that bad. Not much worse as when describing a sine weaving motion, just with an extra (incompatible) dimension.
The equation is just a modified version of a traveling wave 😉

(and we should avoid automatically ' just clearing' units because this would defeat the whole purpose in the first place.

exactly

There is no such thing as 'clearing units', there is only conversion 📜

have a word with my 🧽

@CagtayFabry
Copy link
Member

PS: just seeing tanh(x-t-10) makes my skin crawl when thinking about the units

It's not that bad. Not much worse as when describing a sine weaving motion, just with an extra (incompatible) dimension. The equation is just a modified version of a traveling wave 😉

I meant concerning that it should always be in the form of tanh(a*x+b*t-10) (which looks pretty ⭐ )

@vhirtham
Copy link
Collaborator Author

PS: just seeing tanh(x-t-10) makes my skin crawl when thinking about the units

It's not that bad. Not much worse as when describing a sine weaving motion, just with an extra (incompatible) dimension. The equation is just a modified version of a traveling wave 😉

I meant concerning that it should always be in the form of tanh(a*x+b*t-10) (which looks pretty ⭐ )

True, but that's the target equation. In the tutorial, we start simple (no parameters, no units) and get there step by step 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core weldx core classes and functions feature new API features low priority low priority issues during ☕
Projects
None yet
Development

No branches or pull requests

2 participants