# Pokémons, FP e Type Theory

## Hi!

• Computer Engineer
• Programming
• Electronics
• Math <3 <3
• Physics
• Lego
• Meetups
• Animals
• Coffee
• GIFs

# Mathematics + Programming

## Agenda

• Logic
• Functional Programming with Pokémon
• Intro to Lambda Calculus and Mathematical Formalism
• Type Theory

# Can you think about strong typed languages and the opposite?

## p:P

• This is not an emoji
• "The value p has the type P"
• And so what? Then we analyse the functions, implications and mathematical constructions.
• Look carefully and think about functions (form Algebra)
• D(f):{2,9} or
• Value and Types could express domains and ranges in functions!

# What is correct?

• Write arguments that can be checked mechanically
• Study properties
• Elaborate semantic meanings

WAT

## It's simple:

• Lambda calculus
• Lisp
• Scala
• Clojure
• Papers
• Category Theory
• λ
• λ
• λ

## Pokémon

We give instructions to Pokémon in a battle

## Programming

We also give instructions to code

i = i+1;

## Pokémon

We must know how some things work:

## Programming

We must know how to manage information in our software

• Data types
• Evolution
• How to group them
• Important attributes
• Pokémon types
• Evolution
• Team strategy
• EV/IV
• Moves
• Items

level >=16

f(evol)

output level is the same as the input

How can I get a Charizard from a Charmander?

level >=16

f(evol)

output level is the same as the input

output level is the same as the input

f(up)

level = 36

level=36

f(evol)

level = 36

# Or:

level >=36

f(evol)

output level is the same as the input

f(evol)

output level is the same as the input

# High Order Function

f(x) => g(x) => h(x)

# In some competitions, there is a maximum value for the sum of the levels of the Pokémon on the team

## Team

• Charizard, lvl 100
• Lapras, lvl 100
• Dragonite, lvl 100
• Rhydon, lvl 100
• Pidgeotto, lvl 100
• Gengar, lvl 100

## Level sum: 600

• Gengar, lvl 100
• Charizard, lvl 100
• Lapras, lvl 100
• Rhydon, lvl 100
• Pidgeotto, lvl 100
• Dragonite, lvl 100

## Level sum: 600

• Lapras, lvl 100
• Gengar, lvl 100
• Charizard, lvl 100
• Rhydon, lvl 100
• Pidgeotto, lvl 100
• Dragonite, lvl 100
• Pidgeotto, lvl 100
• Lapras, lvl 100
• Gengar, lvl 100
• Dragonite, lvl 100
• Charizard, lvl 100
• Rhydon, lvl 100
`Credits: @bitemyapp and @argumatronic - http://haskellbook.com/`

# sumEverythong AndGiveTheResult([100,100, 100,100,100,100])

## fold|reduce|other_names

`(reduce + [100 100 100 100 100 100])  ;;=> 600`

# Eggs

## Team

• Charizard, lvl 100
• Lapras, lvl 100
• Dragonite, lvl 100
• Egg
• Pidgeotto, lvl 100
• Gengar, lvl 100

# Egg works as an identity element to the level.

• Gengar, lvl 100
• Charizard, lvl 100
• Lapras, lvl 100
• Egg
• Pidgeotto, lvl 100
• Dragonite, lvl 100

## Level sum: 500

• Lapras, lvl 100
• Gengar, lvl 100
• Charizard, lvl 100
• Egg
• Pidgeotto, lvl 100
• Dragonite, lvl 100
• Pidgeotto, lvl 100
• Lapras, lvl 100
• Gengar, lvl 100
• Dragonite, lvl 100
• Charizard, lvl 100
• Egg

## reduce

`(reduce + 0[100 100 100 100 100])  ;;=> 500`

# Collection

```(map upgrade                        )

```
`;;=>`

# Optional

```(map change              )

```
`;;=>`
`[`
`]`
`[`
`]`

# ]

In some part of the game you will have the badges

# ]

```(map other_cont              )

```
`;;=>`

# Move set

## and moves

{Surf: 15},

{Fissure: 5},

{Solarbeam: 10},

{Eruption: 5}

Moves

[

]

{Surf: 15},

{Fissure: 5},

{Solarbeam: 10},

{Eruption: 5}

Moves

decrease_pp_used_move[{Surf: 15}]

[

]

[{Surf: 14}],

{Fissure: 5},

{Solarbeam: 10},

{Eruption: 5}

[

]

[]

[            ]

[                     ]

{Surf: 15},

{Fissure: 5},

{Solarbeam: 10},

{Eruption: 5}

Moves

[

]

{Surf: 14},

{Fissure: 5},

{Solarbeam: 10},

{Eruption: 5}

```(flatten decrease_pp [{Surf:15}])

```
`;;=> [{Surf: 14}, {Fissure: 5}, {Solarbeam: 10}, {Eruption: 5}]`

# Collection

Item

[Scope Lens]

boost_move

{Fissure:5},

{Surf:15},

{Solarbeam: 10},

{Eruption: 5}

[

]

{Fissure:5},

[{Surf:15:boosted}],

{Solarbeam: 10},

{Eruption: 5}

[

]

Item

[Scope Lens]

{Fissure:5},

{Surf:15},

{Solarbeam: 10},

{Eruption: 5}

[

]

# Optional

```(flatten boost_move [{Surf:15}]
```
`;;=> [{Fissure:5}, {Surf: 15:boosted}, {Solarbeam: 10}, {Eruption: 5}]`

{Fissure:5},

{Surf:15},

{Solarbeam: 10},

{Eruption: 5}

[

]

{Fissure:5},

{Surf:15},

{Solarbeam: 10},

{Eruption: 5}

[

]

Moves

forget

{Fissure:5},

[],

{Solarbeam: 10},

{Eruption: 5}

[

]

{Fissure:5},

{Surf:15},

{Solarbeam: 10},

{Eruption: 5}

[

]

# Future

```(flatten forget [{Surf:15}]
```
`;;=> [{Fissure:5}, {Solarbeam: 10}, {Eruption: 5]}`

{Fissure:5},

{Surf:15},

{Solarbeam: 10},

{Eruption: 5}

[

]

Moves

### No matter which move set you have (if it exists, if you have items, if you haven't learned the move yet):

• Get the element
• Apply a function if convenient
• flatten
• Allow call chain

# Objects => Functions

• Individual Variables => x, y, z
• Applications => (e1, e2) [apply expression e1 to e2]
• Abstractions => (λx, e) [f(x) = e]

# λ-calculus: Topics

• Substitution
• Evaluation
• Untyped or Typed
• http://www.cs.le.ac.uk/people/amurawski/mgs2011-tlc.pdf

# FINALLY! Type Theory

Types

Functions

Propositions

Proofs

Isomorfismo

## Topics

How can we turn this into Mathematics?

Simplifying

## We can apply all this formalism for

• Naming
• Generalisations
• Derivability

An then we can analyse programming statements with Mathematics.

## Credits and references:

• GIRARD, Jean-Yves. Proofs and Types.
• @lafp, @romulostotel, @pedrofelipee: GIFs
• @klauss_weyl, for showing me the importance of logic and Type Theory
• Henrique
• http://www.cs.le.ac.uk/people/amurawski/mgs2011-tlc.pdf
• http://www.andres-loeh.de/LambdaPi/LambdaPi.pdf

## More credits and references:

• @bitemyapp, @argumatronic and @FunctionalWorks
• @txustice - http://blog.txus.io/
• http://www.amazon.com/Functional-Programming-Practice-Bruce-Maclennan/dp/0201137445/ref=sr_1_9?ie=UTF8&qid=1445967378&sr=8-9&keywords=functional+programming
• http://media.eurucamp.org/ (@eurucamp)