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

Convenient name for AlgebraicField & ElementaryFunctions #100

Open
NevinBR opened this issue Jan 24, 2020 · 6 comments
Open

Convenient name for AlgebraicField & ElementaryFunctions #100

NevinBR opened this issue Jan 24, 2020 · 6 comments

Comments

@NevinBR
Copy link
Contributor

NevinBR commented Jan 24, 2020

The natural place to write many generic algorithms is the protocol composition AlgebraicField & ElementaryFunctions, as it provides all the basic arithmetic operations including negation and division, as well as powers, roots, and transcendental functions.

To facilitate and encourage this practice, we should provide a convenient name for that composition.

@stephentyrone
Copy link
Member

It's worth listing what types can actually plausibly conform to such a protocol:

The elementary functions generally don't make sense for finite fields, and also don't make sense for anything "below" the reals. At the same time AlgebraicField requires commutative multiplication, so rules out anything "past" the complex numbers in some sense.

So the set of things that could conform is basically the reals and the complex numbers, plus a giant family of exotic non-Archimedian fields that could conform, but are relatively unlikely to be implemented.

@NevinBR
Copy link
Contributor Author

NevinBR commented Jan 24, 2020

So the set of things that could conform is basically the reals and the complex numbers

There could also be an ElementwiseMatrix type, which conforms using elementwise operations when its elements themselves do. I suspect this might be useful for machine-learning applications.

• • •

Some ideas for naming the protocol composition:

Math
BasicMath
Mathematical
Transcendental
Analytic

@NevinBR
Copy link
Contributor Author

NevinBR commented Jan 24, 2020

It’s worth noting that in Swift today, one cannot extend a protocol composition.

This suggests that either we should make a refining protocol instead of a typealias, or we should push on Swift Evolution to make it possible to extend a composition.

@stephentyrone
Copy link
Member

stephentyrone commented Mar 23, 2020

@NevinBR You can do a constrained extension to accomplish essentially the same thing (which is not to say that we shouldn't make a refining protocol):

extension ElementaryFunctions where Self: AlgebraicField {
  public func logisticCurve(
    _ x: Self,
    ceiling: Self = 1,
    rate: Self = 1,
    midpoint: Self = 0
  ) -> Self {
    return ceiling / 1 + .exp(rate * (midpoint - x))
  }
}

@NevinBR
Copy link
Contributor Author

NevinBR commented Mar 23, 2020

Right, my point is to make this easy and convenient for users.

@stephentyrone
Copy link
Member

Yup, just wanted to stick it on this thread so anyone searching for a solution to the issue finds it here =)

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