Mar. 27th, 2019

juan_gandhi: (Default)
Just figured out how to calculate elements of yx for two sets (passed here as lists)

An element of an exponential is a Map[X, Y].

  /**
    * Set of all possible maps from set xs to set ys
    * @param xs domain of maps
    * @param ys codomain of maps
    * @tparam X type of domain elements
    * @tparam Y type of codomain elements
    * @return the set of all possible maps
    */
  def exponent[X, Y](xs: Set[X], ys: Set[Y]): Set[Map[X, Y]] = {
    setOf(allMaps(xs.toList, ys.toList),
      pow(ys size, xs size),
      (m: Map[X, Y]) => xs == m.keySet
    )
  }

  def allMaps[X, Y](xs: List[X], ys: List[Y]): List[Map[X, Y]] =
    (List(Map.empty[X, Y]) /: xs)((maps, x) =>
      maps flatMap (m => ys map (y => m + (x -> y)))
    )
juan_gandhi: (Default)
Глухая "л", как в навахо. Voilà mon oncle. Так вот эта последняя "л" - не звонкая. Буду теперь переваривать и стараться. 

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

July 2025

S M T W T F S
  12345
6789 1011 12
131415 1617 1819
20212223242526
2728 293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 30th, 2025 10:31 pm
Powered by Dreamwidth Studios