<commit_before>(ns kolmogorov-music.test.kolmogorov
  (:require [kolmogorov-music.kolmogorov :as kolmogorov]
            [midje.sweet :refer :all]))

(defn foo [x] (inc x))
(defn bar [x] (+ (inc x) x))
(def baz (comp foo foo))

(fact "Kolmogorov complexity is how many symbols a definition comprises."
  (kolmogorov/complexity foo) => 2)

(fact "The symbol count includes nested sexprs."
  (kolmogorov/complexity bar) => 4)

(fact "The symbol count is recursive within the current namespace."
  (kolmogorov/complexity baz) => 7)

(fact "Symbols outside the current namespace are considered atoms."
  (kolmogorov/complexity inc) => 0)

(fact "Sexprs can also be analysed for complexity."
  (kolmogorov/complexity (+ foo (88 "bar" true))) => 7)

(defn minimal-complexity
  "A hypothetical function that determines the minimal Kolmogorov complexity of a natural number."
  [n]
  (inc n))

(defn first-that [applies? xs]
  (->> xs
       (drop-while (complement applies?))
       first))

(defn more-complex-than? [n limit]
  (< limit (minimal-complexity n)))

(defn enterprise*
  "Find the first natural number with a complexity greater than f."
  [expr ns]
  (->> (range)
       (first-that #(more-complex-than? % (kolmogorov/complexity* expr ns)))))

(defmacro enterprise
  [expr]
  (enterprise* expr *ns*))

(fact "The enterprise makes everything more complicated."
  (enterprise inc) => 0
  (enterprise baz) => 7
  (enterprise enterprise) => 25)

(def charset (map char (range 65 (+ 65 26))))

(defn extend-with [elements strings]
  (for [s strings e elements]
    (conj s e)))

(defn kleene* [elements]
  (->> (kleene* elements)
       (extend-with elements)
       lazy-seq
       (cons [])))

(defn lexicon []
  (->> charset
       kleene*
       (map (partial apply str))))

(fact "We can construct all strings as a lazy sequence."
  (->> (lexicon) (take 5)) => ["" "A" "B" "C" "D"]
  (->> (lexicon) (drop 26) (take 5)) => ["Z" "AA" "AB" "AC" "AD"])<commit_msg>Use all of the visible ASCII spectrum.<commit_after>(ns kolmogorov-music.test.kolmogorov
  (:require [kolmogorov-music.kolmogorov :as kolmogorov]
            [midje.sweet :refer :all]))

(defn foo [x] (inc x))
(defn bar [x] (+ (inc x) x))
(def baz (comp foo foo))

(fact "Kolmogorov complexity is how many symbols a definition comprises."
  (kolmogorov/complexity foo) => 2)

(fact "The symbol count includes nested sexprs."
  (kolmogorov/complexity bar) => 4)

(fact "The symbol count is recursive within the current namespace."
  (kolmogorov/complexity baz) => 7)

(fact "Symbols outside the current namespace are considered atoms."
  (kolmogorov/complexity inc) => 0)

(fact "Sexprs can also be analysed for complexity."
  (kolmogorov/complexity (+ foo (88 "bar" true))) => 7)

(defn minimal-complexity
  "A hypothetical function that determines the minimal Kolmogorov complexity of a natural number."
  [n]
  (inc n))

(defn first-that [applies? xs]
  (->> xs
       (drop-while (complement applies?))
       first))

(defn more-complex-than? [n limit]
  (< limit (minimal-complexity n)))

(defn enterprise*
  "Find the first natural number with a complexity greater than f."
  [expr ns]
  (->> (range)
       (first-that #(more-complex-than? % (kolmogorov/complexity* expr ns)))))

(defmacro enterprise
  [expr]
  (enterprise* expr *ns*))

(fact "The enterprise makes everything more complicated."
  (enterprise inc) => 0
  (enterprise baz) => 7
  (enterprise enterprise) => 25)

(def ascii
  (->> (range 32 127)
       (map char)))

(defn extend-with [elements strings]
  (for [s strings e elements]
    (conj s e)))

(defn kleene* [elements]
  (->> (kleene* elements)
       (extend-with elements)
       lazy-seq
       (cons [])))

(defn subsequence [start end s]
  (->> s (drop start) (take (- end start))))

(defn lexicon []
  (->> ascii
       kleene*
       (map (partial apply str))))

(fact "We can construct all strings as a lazy sequence."
  (->> (lexicon) (subsequence 0 5)) => ["" " " "!" "\"" "#"]
  (->> (lexicon) (subsequence 96 101)) => ["  " " !" " \"" " #" " $"]
  (nth (lexicon) 364645) => "GEB")
{'fraction_non_alphanumeric': 0.1550880626223092, 'fraction_numerical': 0.01223091976516634, 'mean_word_length': 3.518232044198895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3858125', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1404, 'n_words': 466}