<div dir="ltr"><div>So, this has been discussed before on the list many times in the past. The core team has stated that their preferred process for this is to have individuals write their own libraries, get real-world adoption, then (as consensus emerges) propose their inclusion as a core library.</div><div><br></div><div>Keep in mind that the _standard_ library is what's available by default without importing anything; it is deliberately small and includes only the most basic types that need compiler support. This is different to be distinguished from core libraries like Foundation and Dispatch.</div><div><br></div><div>With that exhortation in mind, I have written a math library that provides protocol-based trigonometry. For expediency it wraps Darwin or Glibc at the moment. It is intended to be an exercise in creating a plausible design that respects existing Swift conventions. On top of that, it includes implementations for complex and rational numbers, as well as pseudorandom number generators (unfinished at the moment); I include the link here as a reply regarding what I feel would be the optimal design (in terms of free function vs. members) for such a math protocol:</div><div><br></div><div><a href="https://github.com/xwu/NumericAnnex">https://github.com/xwu/NumericAnnex</a><br></div><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 7:37 PM, Taylor Swift via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">I’d be completely in favor of this. Structs for priority queues, skiplists, trees, binary search and more sorting functions would also be on my wishlist. I think Python made a very good choice in choosing to vend separate standard modules for stuff like that instead of bloating its builtin namespace.<br></div><div class="gmail-HOEnZb"><div class="gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 2:22 PM, Hooman Mehr <span dir="ltr"><<a href="mailto:hooman@mac.com" target="_blank">hooman@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>Maybe we need more than one level of standard library: The core (which is most of what we have now (but maybe not all of it) and multiple opt-in standard modules for hash functions, math, specialized data structures, etc.</div><div><div class="gmail-m_5710313277668806029h5"><br><div><blockquote type="cite"><div>On Jul 31, 2017, at 11:10 AM, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com" target="_blank">kelvin13ma@gmail.com</a>> wrote:</div><br class="gmail-m_5710313277668806029m_-16665392533933857Apple-interchange-newline"><div><div dir="ltr">I’m not sure why only the stdlib is inlineable and specializable, but I believe it has something to do with ABI. I’m not an ABI expert though. I strongly disagree that a Swift Math library should be delegated to a third party. Math is “common” enough that there should really only be one “standard” implementation of it, under the direction of the Swift Project; we don’t want 5 competing third party Vector standards.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 2:02 PM, Hooman Mehr <span dir="ltr"><<a href="mailto:hooman@mac.com" target="_blank">hooman@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">I know. I hear you. I have some special arrangmnents to keep such things manageable, and I am not happy about how things stand right now.<div><br></div><div>What I am hoping to open up stdlib special compiler mode to other (low-level) libraries and also letting such libraries gain optimizations similar to stdlib when included in a project.<div><br></div><div>So, instead of putting things in stdlib, I want stdlib’s special privileges being made available to a certain category of third-party or internal modules.<div><div class="gmail-m_5710313277668806029m_-16665392533933857h5"><br><div><br><div><blockquote type="cite"><div>On Jul 31, 2017, at 10:54 AM, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com" target="_blank">kelvin13ma@gmail.com</a>> wrote:</div><br class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435Apple-interchange-newline"><div><div dir="ltr">Isn’t the point of standard inlineable library module to prevent the need to copy and paste code like this into every project? Currently I have a “math.swift” file I copy and paste into all of my projects, and since I occasionally update it, there exists about 15 different versions of it floating around, so I know this is not a sustainable practice.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 1:45 PM, Hooman Mehr <span dir="ltr"><<a href="mailto:hooman@mac.com" target="_blank">hooman@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">I prefer an approach that preserves how I am used to seeing math expressions. I use this myself:<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;background-color:rgb(255,255,255)"><div style="margin:0px;line-height:normal"><span style="color:rgb(186,45,162)">protocol</span> FloatingPointMath: <span style="color:rgb(112,61,170)">FloatingPoint</span></div><div style="margin:0px;line-height:normal">{</div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> sqrt(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;font-size:12px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> sin(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> cos(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> tan(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> asin(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> acos(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> atan(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal;min-height:13px"> <br class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459webkit-block-placeholder"></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> ln(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> log(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>, base: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> pow(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>, exponent:<span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal"> <span style="color:rgb(186,45,162)">static</span> <span style="color:rgb(186,45,162)">func</span> exp(<span style="color:rgb(186,45,162)">_</span> value: <span style="color:rgb(79,129,135)">Self</span>) -> <span style="color:rgb(112,61,170)">Self</span></div><div style="margin:0px;line-height:normal">}</div><div><br></div></div></div><div>It does not pollute the global namespace and gives nice contextual auto-completion. And I don’t want it in the standard library: I only add the file when I need it. (it is not a separate module for optimization reasons).</div><div><div class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435h5"><div><br><div><blockquote type="cite"><div>On Jul 31, 2017, at 10:29 AM, Taylor Swift via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459Apple-interchange-newline"><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 31, 2017 at 1:23 PM, Adrian Zubarev <span dir="ltr"><<a href="mailto:adrian.zubarev@devandartist.com" target="_blank">adrian.zubarev@devandartist.c<wbr>om</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div id="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459m_-5678978844789218338bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;margin:0px">I’m not sure how I would feel about this. To be honest I’d avoid such additional changes from the stdlib, because they really don’t belong there. Instead some `Math` module/package would be a better fit than clustering everything into stdlib until we end up also adding UI stuff.</div> <div><br></div>Furthermore, I don’t think a function would make any sense here. It really should be a computed property.<div><div class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459h5"><br> <div id="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459m_-5678978844789218338bloop_sign_1501521568263739136" class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459m_-5678978844789218338bloop_sign"></div> <br></div></div></div></blockquote><div><br></div><div>I think a standard Math module would be a good idea, but only if it benefits from the same inlining and specialization as the standard library. Also squareRoot() should be moved to the Math module if it is ever created.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459h5"><p class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459m_-5678978844789218338airmail_on">Am 31. Juli 2017 um 19:03:49, Taylor Swift via swift-evolution (<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>) schrieb:</p> </div></div><blockquote type="cite" class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459m_-5678978844789218338clean_bq"><span><div><div></div><div><div><div class="gmail-m_5710313277668806029m_-16665392533933857m_204244033810488435m_5301210826314882459h5">
<div dir="ltr">
<div>How would people feel about adding a protocol<br>
<br>
<span style="font-family:monospace,monospace">protocol
MathFloatingPoint:FloatingPoin<wbr>t<br>
{<br>
func sin() -> Self<br>
func cos() -> Self<br>
func tan() -> Self<br>
func asin() -> Self<br>
func acos() -> Self<br>
func atan() -> Self<br>
<br></span></div>
<div><span style="font-family:monospace,monospace"> func ln()
-> Self<br></span></div>
<div><span style="font-family:monospace,monospace"> func
log(base:Self) -> Self<br></span></div>
<div><span style="font-family:monospace,monospace"> func
pow(exponent:Self) -> Self<br></span></div>
<div><span style="font-family:monospace,monospace"> func exp()
-> Self<br></span></div>
<div><span style="font-family:monospace,monospace">}</span><br>
<br></div>
to the standard library? Float and Double would then be made to
conform by default using Swift implementations instead of having to
import Glibc / Darwin and writing the extensions, depending on
platform.<br></div></div></div><span>
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br></span></div></div></span></blockquote></div></blockquote></div><br></div></div>
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></div></div></div></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>