Add Gradle Wrapper and clean up docs a bit #28
@ -1,38 +1,40 @@
|
|||||||
## Spaces and fields
|
## Spaces and fields
|
||||||
|
|
||||||
An obvious first choice of mathematical objects to implement in context-oriented style are algebra elements like spaces,
|
An obvious first choice of mathematical objects to implement in a context-oriented style are algebraic elements like spaces,
|
||||||
rings and fields. Those are located in a `scientifik.kmath.operations.Algebra.kt` file. Alongside algebric context
|
rings and fields. Those are located in the `scientifik.kmath.operations.Algebra.kt` file. Alongside common contexts, the file includes definitions for algebra elements like `FieldElement`. A `FieldElement` object
|
||||||
themselves, the file includes definitions for algebra elements such as `FieldElement`. A `FieldElement` object
|
stores a reference to the `Field` which contains additive and multiplicative operations, meaning
|
||||||
stores a reference to the `Field` which contains a additive and multiplicative operations for it, meaning
|
it has one fixed context attached and does not require explicit external context. So those `MathElements` can be operated without context:
|
||||||
it has one fixed context attached to it and does not require explicit external context. So those `MathElements` could be
|
|
||||||
operated without context:
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val c1 = Complex(1.0, 2.0)
|
val c1 = Complex(1.0, 2.0)
|
||||||
val c2 = ComplexField.i
|
val c2 = ComplexField.i
|
||||||
val c3 = c1 + c2
|
val c3 = c1 + c2
|
||||||
```
|
```
|
||||||
`ComplexField` also features special operations to mix complex numbers with real numbers like:
|
|
||||||
|
`ComplexField` also features special operations to mix complex and real numbers, for example:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val c1 = Complex(1.0,2.0)
|
val c1 = Complex(1.0,2.0)
|
||||||
val c2 = ComplexField.run{ c1 - 1.0} //returns [re:0.0, im: 2.0]
|
val c2 = ComplexField.run{ c1 - 1.0} // Returns: [re:0.0, im: 2.0]
|
||||||
val c3 = ComplexField.run{ c1 - i*2.0}
|
val c3 = ComplexField.run{ c1 - i*2.0}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note**: In theory it is possible to add behaviors directly to the context, but currently kotlin syntax does not support
|
**Note**: In theory it is possible to add behaviors directly to the context, but currently kotlin syntax does not support
|
||||||
that. Watch [KT-10468](https://youtrack.jetbrains.com/issue/KT-10468) for news.
|
that. Watch [KT-10468](https://youtrack.jetbrains.com/issue/KT-10468) for updates.
|
||||||
|
|
||||||
## Nested fields
|
## Nested fields
|
||||||
|
|
||||||
Algebra contexts allow to create more complex structures. For example, it is possible to create a `Matrix` from complex
|
Contexts allow one to build more complex structures. For example, it is possible to create a `Matrix` from complex elements like so:
|
||||||
elements like this:
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val element = NDElements.create(field = ComplexField, shape = intArrayOf(2,2)){index: IntArray ->
|
val element = NDElements.create(field = ComplexField, shape = intArrayOf(2,2)){index: IntArray ->
|
||||||
Complex(index[0] - index[1], index[0] + index[1])
|
Complex(index[0] - index[1], index[0] + index[1])
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
The `element` in this example is a member of `Field` of 2-d structures, each element of which is a member of its own
|
|
||||||
`ComplexField`. The important thing is that one does not need to create a special nd-structure to hold complex
|
|
||||||
numbers and implements operations on it, one need just to provide a field for its elements.
|
|
||||||
|
|
||||||
**Note**: Fields themselves do not solve problem of JVM boxing, but it is possible to solve with special contexts like
|
The `element` in this example is a member of the `Field` of 2-d structures, each element of which is a member of its own
|
||||||
|
`ComplexField`. The important thing is one does not need to create a special n-d class to hold complex
|
||||||
|
numbers and implement operations on it, one just needs to provide a field for its elements.
|
||||||
|
|
||||||
|
**Note**: Fields themselves do not solve the problem of JVM boxing, but it is possible to solve with special contexts like
|
||||||
`BufferSpec`. This feature is in development phase.
|
`BufferSpec`. This feature is in development phase.
|
Loading…
Reference in New Issue
Block a user