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

Function to simplify units, e.g. m/ft -> dimensionless #34

Open
mdavezac opened this issue Oct 13, 2016 · 2 comments
Open

Function to simplify units, e.g. m/ft -> dimensionless #34

mdavezac opened this issue Oct 13, 2016 · 2 comments

Comments

@mdavezac
Copy link
Contributor

@ajkeller34, unless I'm mistaken, the following functionality (simplify) does not yet exist. Happy to try and implement it if it doesn't:

notsosimple = 1u"m/ft*kg"
simple = simplify(notsosimple)
@assert units(simple) === units(1u"kg")

It should be possible to determine which unit to use of m or ft, the same way it is done for +, viapromote_type

@ajkeller34
Copy link
Collaborator

There's this:

julia> notsosimple = 1u"m/ft*kg"
1 ft^-1 kg m

julia> upreferred(ans)
1250//381 kg

This may not be what you want though, since the result would be in kg even if the mass unit in the first expression were a different unit. What this does is look at the dimensions of the quantity, and for each power of length, have that many powers of a meter, etc., where the dimension-to-unit mapping is given by the @preferunit macro in the defaults. So this basically is a "convert to base SI units" function given what is usually in deps/Defaults.jl.

If you have different functionality in mind, how would you simplify when you have units of mixed dimensions like joules where it's not just length or mass or time but a combination?

@mdavezac
Copy link
Contributor Author

I guess I'm thinking of a function that would simplify units that have the exact same dimensions and leave those that partially overlap. More complex conversions would happen in #35 (for which upreferred would be one instance). I might trial an implementation so we have something concrete to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants