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

September 2025

S M T W T F S
 1 2345 6
78910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 8th, 2025 06:20 am
Powered by Dreamwidth Studios