Implement hyperbolic functions for various Algebras #118

Merged
CommanderTvis merged 14 commits from hyp-trig-functions into dev 2020-08-11 18:18:06 +03:00
2 changed files with 8 additions and 2 deletions
Showing only changes of commit 837150b5eb - Show all commits

View File

@ -153,7 +153,7 @@ object ComplexField : ExtendedField<Complex>, Norm<Complex, Complex> {
*/ */
operator fun Double.times(c: Complex): Complex = Complex(c.re * this, c.im * this) operator fun Double.times(c: Complex): Complex = Complex(c.re * this, c.im * this)
override fun norm(arg: Complex): Complex = arg.conjugate * arg override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg)
override fun symbol(value: String): Complex = if (value == "i") i else super.symbol(value) override fun symbol(value: String): Complex = if (value == "i") i else super.symbol(value)
} }

View File

@ -1,6 +1,7 @@
package scientifik.kmath.operations package scientifik.kmath.operations
import kotlin.math.* import kotlin.math.PI
import kotlin.math.abs
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
@ -64,4 +65,9 @@ internal class ComplexFieldTest {
ComplexField { i * 8 }.let { it.im.toInt() to it.re.toInt() }, ComplexField { i * 8 }.let { it.im.toInt() to it.re.toInt() },
ComplexField { Complex(2, 2) pow 2 }.let { it.im.toInt() to it.re.toInt() }) ComplexField { Complex(2, 2) pow 2 }.let { it.im.toInt() to it.re.toInt() })
} }
@Test
fun testNorm() {
assertEquals(2.toComplex(), ComplexField { norm(2 * i) })
}
} }