Re: [swift-users] Dimensional analysis

2016-12-04 Thread Rick Mann via swift-users

> On Dec 1, 2016, at 11:36 , Dave Abrahams via swift-users 
>  wrote:
> 
> 
> on Mon Nov 28 2016, Rick Mann  wrote:
> 
>> My earlier post about converting Decimal to Double was part of a
>> larger effort by me to write a calculator app that supports
>> dimensional analysis/unit conversions. I've explored some existing
>> libraries on the topic, ranging from this one in Common Lisp
>> () to this
>> nice-looking C++ header-only implementation
>> (). Here's one done in Swift
>> (), which has similarities
>> to the C++ library.
>> 
>> My calculator allows expressions like this:
>> 
>>  1-3/4" x 2 + (4.3 mm + 0.1") ->  mm
>> 
>> And produces values in both inch and mm, but I want to be able to expand 
>> that to more units.
>> 
>> I also want to support proper dimensional analysis:
>> 
>>  2 mm x 4" -> 203.2 mm^2
>> 
>> While my calculator generally only works with lengths, areas, and angles, I 
>> figure a general-purpose
>> dimensional analysis library would be useful.
>> 
>> Dimensional analysis has come up before
>> (
>> and
>> ).
>>  It
>> seems support for constant expressions is useful for dimensional
>> analysis, and Swift doesn't currently support that.
>> 
>> Given that limitation, what approach would the gurus recommend? The library 
>> should support:
>> 
>> • Generating a result with derived units based on the input
>> • Simplifying composite units to some canonical form
>> • Validating conversion from one (derived) unit to another
>> • Supporting leniency in conversions (e.g. conflating lb and lb•f).
> 
> Is that conflating pounds with foot-pounds?  If so that seems
> undesirable, and also incompatible with the very next bullet.  If not,
> what are you suggesting?

lb and lb-force. They are mass and force, respectively, but in a 1-gee gravity 
field, they result in the same value. Ideally, the library would support being 
lenient, if desired, but with the (usual) option of being strict.

> 
>> • Compile-time errors when mixing incompatible types.
> 
> Because of the lack of numeric generic parameters in Swift, we don't
> know how to create a library that satisfies the latter requirement.

Right, that's what I gathered from the older posts touching on the subject.

-- 
Rick






-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Dimensional analysis

2016-12-02 Thread Jeremy Pereira via swift-users
>> • Supporting leniency in conversions (e.g. conflating lb and lb•f).
> 
> Is that conflating pounds with foot-pounds?  If so that seems
> undesirable, and also incompatible with the very next bullet.  If not,
> what are you suggesting?

It’s pounds force isn’t it? It still shouldn’t be conflated with pounds mass 
which has different dimensions.

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Dimensional analysis

2016-12-01 Thread Dave Abrahams via swift-users

on Mon Nov 28 2016, Rick Mann  wrote:

> My earlier post about converting Decimal to Double was part of a
> larger effort by me to write a calculator app that supports
> dimensional analysis/unit conversions. I've explored some existing
> libraries on the topic, ranging from this one in Common Lisp
> () to this
> nice-looking C++ header-only implementation
> (). Here's one done in Swift
> (), which has similarities
> to the C++ library.
>
> My calculator allows expressions like this:
>
>   1-3/4" x 2 + (4.3 mm + 0.1") ->  mm
>
> And produces values in both inch and mm, but I want to be able to expand that 
> to more units.
>
> I also want to support proper dimensional analysis:
>
>   2 mm x 4" -> 203.2 mm^2
>
> While my calculator generally only works with lengths, areas, and angles, I 
> figure a general-purpose
> dimensional analysis library would be useful.
>
> Dimensional analysis has come up before
> (
> and
> ).
>  It
> seems support for constant expressions is useful for dimensional
> analysis, and Swift doesn't currently support that.
>
> Given that limitation, what approach would the gurus recommend? The library 
> should support:
>
> • Generating a result with derived units based on the input
> • Simplifying composite units to some canonical form
> • Validating conversion from one (derived) unit to another
> • Supporting leniency in conversions (e.g. conflating lb and lb•f).

Is that conflating pounds with foot-pounds?  If so that seems
undesirable, and also incompatible with the very next bullet.  If not,
what are you suggesting?

> • Compile-time errors when mixing incompatible types.

Because of the lack of numeric generic parameters in Swift, we don't
know how to create a library that satisfies the latter requirement.


-- 
-Dave

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Dimensional analysis

2016-11-30 Thread Howard Lovatt via swift-users
Another feature I would like would be a dimensions wrapper for an array. So
that I can mark all values in the array as having the same units, rather
than mark each individual element as having a particular unit.

It is conceivable that wrapping each element, both performance and memory
wise, is OK depending on implementation. However my experience with
Mathematica's Quantity is that wrapping each element is a significant
overhead. Therefore I would like a dimensioned array.

As an aside. It might be a lot easier to write an array wrapper when we get
Conditional Conformance To Protocols with the improved generics slated for
Swift 4.1. Therefore it might be worth waiting until 4.1. before attempting
a dimensioned array.

  -- Howard.

On 1 December 2016 at 01:17, Maury Markowitz via swift-users <
swift-users@swift.org> wrote:

> Let me add my support for this as well. I am currently using a bridge
> version of:
>
> https://github.com/unixpickle/Expressions
>
> And it works quite well. But I think a pure Swift implementation,
> especially with dimensional analysis, would be useful to a great number of
> people.
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Dimensional analysis

2016-11-30 Thread Maury Markowitz via swift-users
Let me add my support for this as well. I am currently using a bridge version 
of:

https://github.com/unixpickle/Expressions

And it works quite well. But I think a pure Swift implementation, especially 
with dimensional analysis, would be useful to a great number of people.
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Dimensional analysis

2016-11-29 Thread Howard Lovatt via swift-users
Great idea to have dimensions library. I use Quantity in Mathematica all the 
time and it is great. Even if some of the checks are at runtime it is still 
useful, better to throw an assert rather than nothing. All the rest of your 
list, in addition to compile time check, I also use.

-- Howard.

> On 29 Nov. 2016, at 9:37 am, Rick Mann via swift-users 
>  wrote:
> 
> My earlier post about converting Decimal to Double was part of a larger 
> effort by me to write a calculator app that supports dimensional 
> analysis/unit conversions. I've explored some existing libraries on the 
> topic, ranging from this one in Common Lisp 
> () to this nice-looking 
> C++ header-only implementation (). Here's 
> one done in Swift (), which has 
> similarities to the C++ library.
> 
> My calculator allows expressions like this:
> 
>1-3/4" x 2 + (4.3 mm + 0.1") ->  mm
> 
> And produces values in both inch and mm, but I want to be able to expand that 
> to more units.
> 
> I also want to support proper dimensional analysis:
> 
>2 mm x 4" -> 203.2 mm^2
> 
> While my calculator generally only works with lengths, areas, and angles, I 
> figure a general-purpose dimensional analysis library would be useful.
> 
> Dimensional analysis has come up before 
> (
>  and 
> ).
>  It seems support for constant expressions is useful for dimensional 
> analysis, and Swift doesn't currently support that.
> 
> Given that limitation, what approach would the gurus recommend? The library 
> should support:
> 
> • Generating a result with derived units based on the input
> • Simplifying composite units to some canonical form
> • Validating conversion from one (derived) unit to another
> • Supporting leniency in conversions (e.g. conflating lb and lb•f).
> • Compile-time errors when mixing incompatible types.
> 
> In my case, the latter requirement is not so important, since all the 
> expressions will be input by the user.
> 
> The existing Swift library might be sufficient for my purposes, but I was 
> interested in the experts' opinions and suggestions.
> 
> Thanks!
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Dimensional analysis

2016-11-28 Thread Rick Mann via swift-users
My earlier post about converting Decimal to Double was part of a larger effort 
by me to write a calculator app that supports dimensional analysis/unit 
conversions. I've explored some existing libraries on the topic, ranging from 
this one in Common Lisp () 
to this nice-looking C++ header-only implementation 
(). Here's one done in Swift 
(), which has similarities to the 
C++ library.

My calculator allows expressions like this:

1-3/4" x 2 + (4.3 mm + 0.1") ->  mm

And produces values in both inch and mm, but I want to be able to expand that 
to more units.

I also want to support proper dimensional analysis:

2 mm x 4" -> 203.2 mm^2

While my calculator generally only works with lengths, areas, and angles, I 
figure a general-purpose dimensional analysis library would be useful.

Dimensional analysis has come up before 
(
 and 
).
 It seems support for constant expressions is useful for dimensional analysis, 
and Swift doesn't currently support that.

Given that limitation, what approach would the gurus recommend? The library 
should support:

• Generating a result with derived units based on the input
• Simplifying composite units to some canonical form
• Validating conversion from one (derived) unit to another
• Supporting leniency in conversions (e.g. conflating lb and lb•f).
• Compile-time errors when mixing incompatible types.

In my case, the latter requirement is not so important, since all the 
expressions will be input by the user.

The existing Swift library might be sufficient for my purposes, but I was 
interested in the experts' opinions and suggestions.

Thanks!

-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users