v0.2.0 #206
@ -46,8 +46,8 @@ private val PI_DIV_2 = Complex(PI / 2, 0)
|
||||
* A field of [Complex].
|
||||
*/
|
||||
public object ComplexField : ExtendedField<Complex>, Norm<Complex, Complex>, RingWithNumbers<Complex> {
|
||||
public override val zero: Complex by lazy { 0.0.toComplex() }
|
||||
public override val one: Complex by lazy { 1.0.toComplex() }
|
||||
public override val zero: Complex = 0.0.toComplex()
|
||||
public override val one: Complex = 1.0.toComplex()
|
||||
|
||||
/**
|
||||
* The imaginary unit.
|
||||
|
@ -36,23 +36,23 @@ public val Quaternion.r: Double
|
||||
*/
|
||||
public object QuaternionField : Field<Quaternion>, Norm<Quaternion, Quaternion>, PowerOperations<Quaternion>,
|
||||
ExponentialOperations<Quaternion>, RingWithNumbers<Quaternion> {
|
||||
override val zero: Quaternion by lazy { 0.toQuaternion() }
|
||||
override val one: Quaternion by lazy { 1.toQuaternion() }
|
||||
override val zero: Quaternion = 0.toQuaternion()
|
||||
override val one: Quaternion = 1.toQuaternion()
|
||||
|
||||
/**
|
||||
* The `i` quaternion unit.
|
||||
*/
|
||||
public val i: Quaternion by lazy { Quaternion(0, 1) }
|
||||
public val i: Quaternion = Quaternion(0, 1)
|
||||
|
||||
/**
|
||||
* The `j` quaternion unit.
|
||||
*/
|
||||
public val j: Quaternion by lazy { Quaternion(0, 0, 1) }
|
||||
public val j: Quaternion = Quaternion(0, 0, 1)
|
||||
|
||||
/**
|
||||
* The `k` quaternion unit.
|
||||
*/
|
||||
public val k: Quaternion by lazy { Quaternion(0, 0, 0, 1) }
|
||||
public val k: Quaternion = Quaternion(0, 0, 0, 1)
|
||||
|
||||
public override fun add(a: Quaternion, b: Quaternion): Quaternion =
|
||||
Quaternion(a.w + b.w, a.x + b.x, a.y + b.y, a.z + b.z)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package kscience.kmath.structures
|
||||
package kscience.kmath.complex
|
||||
|
||||
import kscience.kmath.complex.Complex
|
||||
import kscience.kmath.complex.complex
|
||||
import kscience.kmath.structures.Buffer
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
@ -0,0 +1,26 @@
|
||||
package kscience.kmath.complex
|
||||
|
||||
import kscience.kmath.expressions.FunctionalExpressionField
|
||||
import kscience.kmath.expressions.bind
|
||||
import kscience.kmath.expressions.invoke
|
||||
import kscience.kmath.expressions.symbol
|
||||
import kscience.kmath.operations.invoke
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class ExpressionFieldForComplexTest {
|
||||
val x by symbol
|
||||
|
||||
@Test
|
||||
fun testComplex() {
|
||||
val context = FunctionalExpressionField(ComplexField)
|
||||
|
||||
val expression = context {
|
||||
val x = bind(x)
|
||||
x * x + 2 * x + one
|
||||
}
|
||||
|
||||
assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0))
|
||||
//assertEquals(expression(), Complex(9.0, 0.0))
|
||||
}
|
||||
}
|
@ -11,12 +11,6 @@ kotlin.sourceSets {
|
||||
api(project(":kmath-memory"))
|
||||
}
|
||||
}
|
||||
|
||||
commonTest {
|
||||
dependencies {
|
||||
api(project(":kmath-complex"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readme {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package kscience.kmath.expressions
|
||||
|
||||
import kscience.kmath.operations.RealField
|
||||
import kscience.kmath.complex.*
|
||||
import kscience.kmath.operations.invoke
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
@ -23,19 +22,6 @@ class ExpressionFieldTest {
|
||||
assertFails { expression() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testComplex() {
|
||||
val context = FunctionalExpressionField(ComplexField)
|
||||
|
||||
val expression = context {
|
||||
val x = bind(x)
|
||||
x * x + 2 * x + one
|
||||
}
|
||||
|
||||
assertEquals(expression(x to Complex(1.0, 0.0)), Complex(4.0, 0.0))
|
||||
//assertEquals(expression(), Complex(9.0, 0.0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun separateContext() {
|
||||
fun <T> FunctionalExpressionField<T, *>.expression(): Expression<T> {
|
||||
|
Loading…
Reference in New Issue
Block a user