Slide 1

Slide 1 text

Kotlin + Maths Dinorah Tovar @ddinorahtovar Google Developer Expert - Android Santo Domingo

Slide 2

Slide 2 text

Disclaimer - I’m not a data science engineer

Slide 3

Slide 3 text

Left Aligned Title Kotlin help us to solve many problems - but specially in maths! Math’s are coolest thing! • A fast operational language • Mathematical expressions • Algebraic data types (sealed class) • We can do simple functions - from basic to complex

Slide 4

Slide 4 text

Simple quote or statement goes here. Ideally limit to four or five lines max. This function takes mseconds 258 fun main() { val y = complex(2, 1) var x = complex(0, 0) val time = measureTimeMillis { repeat(10000000) { x += y x *= y x -= y x /= y } } }

Slide 5

Slide 5 text

Simple quote or statement goes here. Ideally limit to four or five lines max. This function takes seconds 2.76 def main(): z = complex(2, 1) w = complex(0, 0) start = time.time() for i in range(0, 10000000): w += z w *= z w -= z w /= z ende = time.time()

Slide 6

Slide 6 text

9 times At least more efficient

Slide 7

Slide 7 text

Mathematical expressions are pretty much pseudocode

Slide 8

Slide 8 text

Left Aligned Title 2x + 10 First degree equation fun calc(x: Int) : Int { return 2*x + 10 }

Slide 9

Slide 9 text

Left Aligned Title 10 ∑ i=1 1 i + 1 Summation val sum = 0 for (i in 1..10) { sum += 1/(i+1) } fun f() = (1..10).map { i -> 1 / (i + 1) }.sum()

Slide 10

Slide 10 text

Left Aligned Title 3 ∏ i=1 i Product fun f() = (1..3).fold( 1L, Long::times)

Slide 11

Slide 11 text

ADT is a type which is represented by several other subtypes

Slide 12

Slide 12 text

Simple quote or statement goes here. Ideally limit to four or five lines max. ADT are only Class Sealed sealed class Tree data class Node( val value: T, val left: Tree = Empty, val right: Tree = Empty ) : Tree()

Slide 13

Slide 13 text

Simple quote or statement goes here. Ideally limit to four or five lines max. ADT can create Sequences Nodes fun f() { val tree = Node( 10, 20, Node(40, 20, 10) ) // we can create ext function // and get the result }

Slide 14

Slide 14 text

Algebraic operations

Slide 15

Slide 15 text

Left Aligned Title {1,2,4,10} Average Max - Min fun f() { val seq = floatArrayOf( 1F, 2F, 4F, 10F ) val avg = seq.average() val max = seq.max() val min = seq.min() }

Slide 16

Slide 16 text

Left Aligned Title ( 222 222 222 ) Multi- dimensional Vectors fun f() { val mx = arrayOf( arrayOf(floatArrayOf(2F, 2F, 2F)), arrayOf(floatArrayOf(2F, 2F, 2F)), arrayOf(floatArrayOf(2F, 2F, 2F)) ) val normArray = mx.map { column -> column.map { row -> row.map { element -> element / 255F } } } }

Slide 17

Slide 17 text

Probability and Statistics

Slide 18

Slide 18 text

Let’s solve a problem Let’s calculate the probability of the weather in the last week in Mexico City! Last week weather Partially Sunny Rainy Rainy Cloudy Partially Sunny

Slide 19

Slide 19 text

Just rainy probability val weatherMexicoCity = arrayOf( "Partially Sunny", "Rainy" , "Partially Sunny" , "Cloudy", "Rainy" ) val rainyProbability = weatherMexicoCity.count { it == "Rainy" } / weatherMexicoCity.size

Slide 20

Slide 20 text

How about all the weathers val weatherMexicoCity = arrayOf( "Partially Sunny", "Rainy" , "Partially Sunny" , "Cloudy", "Rainy" ) val generalProbability = weatherMexicoCity.map { label -> labels.count { it == label } / labels.size }

Slide 21

Slide 21 text

Charts + Statistics

Slide 22

Slide 22 text

Kotlin has integration for Notebooks - specifically for Jupiter

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Kotlin + Maths Dinorah Tovar @ddinorahtovar Google Developer Expert - Android Santo Domingo