aboutsummaryrefslogtreecommitdiff
path: root/monad.go
blob: e7be48c3c97ba5415d764d29be518907da96f60a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main

import "math/cmplx"

var monads = map[rune]Monad{
	'+': conjugate,
	'-': negate,
	'×': direction,
	'÷': reciprocal,
}

func conjugate(w complex128) complex128  { return cmplx.Conj(w) }
func negate(w complex128) complex128     { return -w }
func direction(w complex128) complex128  { return w / complex(cmplx.Abs(w), 0) }
func reciprocal(w complex128) complex128 { return 1.0 / w }

var dyads = map[rune]Dyad{
	'+': plus,
	'-': minus,
	'×': times,
	'÷': divide,
}

func plus(a, w complex128) complex128   { return a + w }
func minus(a, w complex128) complex128  { return a - w }
func times(a, w complex128) complex128  { return a * w }
func divide(a, w complex128) complex128 { return a / w }