Function Request: Make Argument Dimensionless

Issue #672 new
Damian Gronsky created an issue

First off, I'm loving v0.12; thanks so much to the team for all of the effort that has gone into this project so far.

The new custom functions and units features are a fantastic addition, which I'm finding very useful. I have some custom functions that I've built that require dimensionless arguments, and it doesn't appear that there's currently a built-in function for removing the dimension from an argument. Can such a function be included in a future release?

Thanks.

Comments (6)

  1. Pol Welter

    User functions should work just fine with quantities that do have a dimension. The usual way to deal with such an issue is to divide by the unit.

    The numeric value of a quantity is not well defined without specifying a unit serving as a reference. For instance what is the numeric value of 5 inch? Is it 5 or 0.127?

    I see that such a function might be useful, but I'll have to let the idea mature in my head. For now, dividing by the unit seems to be a non-ambiguous and straightforward enough way.

  2. Helder Correia repo owner

    For now, dividing by the unit seems to be a non-ambiguous and straightforward enough way.

    Not sure I understand Damian's use case completely, but it seems to me that your workaround is fine if you know the unit you'll be passing in advance. But that may not be case, in which situation I do think such a function to remove the unit of an argument is indeed useful. Something like type casts in C++.

  3. Pol Welter

    I could imagine something like

    numeric_value(5 meter)
    = 5
    
    numeric value(5 meter -> foot)
    = 16.4041994750656167979
    

    Basically if no unit is specified, it defaults to SI.

  4. Damian Gronsky reporter

    Hi Pol and Helder,

    Thanks for the conversation on this topic. My current custom functions that rely on dimensionless arguments work just fine if the dimensions are removed when the arguments are passed to the function, as Pol recommended -- e.g., if two arguments have units of length, the function input would be: "f(x/meter;y/meter)". I suppose the primary reason for my request for a "numeric_value()" function is so that it can be embedded within my custom functions, so that it is not necessary to remove the units from the arguments when passed to the custom function, thereby making input quicker and maybe slightly more intuitive in some cases. Some of my custom functions take arguments that are not always of a particular unit type. Though I have not come across this yet, and as Helder mentioned above, there may be cases where the units of the arguments may not be easily dealt with (i.e. removed ahead of time), since the units may be unknown. I think this could potentially happen, for example, when particular custom functions are nested within other custom functions. In these cases, I think a function like "numeric_value()", as Pol suggested above, could be useful.

    To summarize, in the short-term I do not currently need a "numeric_value()" function, though I would currently find it useful. In the long-term, I believe it would be a worthwhile enhancement to the program.

    Thanks again!

  5. Pol Welter

    Some of my custom functions take arguments that are not always of a particular unit type.

    Ah, I see. Did not think of that.

    Still, a numeric_value() function (or whatever we decide to call it) might behave unexpectedly if you do not specify the units. By definition, this will be the case if you don't even know the dimension of the arguments.

    Either way, I agree that we need such a function (although for a different reason: if we include units with the scientific constants, people will become very sad if there is no way to turn dimensions off again).

    Glad you like SC, you're welcome.

  6. Log in to comment