{"id":16603148,"url":"https://github.com/laserpants/dyckword","last_synced_at":"2025-09-04T04:41:40.668Z","repository":{"id":62435877,"uuid":"89880695","full_name":"laserpants/dyckword","owner":"laserpants","description":":surfer: A Haskell library for working with binary Dyck words.","archived":false,"fork":false,"pushed_at":"2018-01-15T16:11:24.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-23T22:55:02.454Z","etag":null,"topics":["formal-languages","haskell","math","parentheses"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/dyckword","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laserpants.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-30T22:19:30.000Z","updated_at":"2017-12-14T07:57:44.000Z","dependencies_parsed_at":"2022-11-01T20:46:07.460Z","dependency_job_id":null,"html_url":"https://github.com/laserpants/dyckword","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laserpants%2Fdyckword","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laserpants%2Fdyckword/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laserpants%2Fdyckword/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laserpants%2Fdyckword/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laserpants","download_url":"https://codeload.github.com/laserpants/dyckword/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242729418,"owners_count":20175943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formal-languages","haskell","math","parentheses"],"created_at":"2024-10-12T00:47:47.294Z","updated_at":"2025-03-09T17:35:34.982Z","avatar_url":"https://github.com/laserpants.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dyckword [![Build Status](https://img.shields.io/travis/laserpants/dyckword/master.svg?style=flat)](https://travis-ci.org/laserpants/dyckword) [![License](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Language](https://img.shields.io/badge/language-Haskell-yellow.svg)](https://www.haskell.org/) [![Hackage](https://img.shields.io/hackage/v/dyckword.svg)](http://hackage.haskell.org/package/dyckword)\n\n## Table of Contents\n\n* [Background](#background)\n* [Documentation](#documentation)\n* [Install](#install)\n* [Examples](#examples)\n\n## Background\n\nIn formal language theory, the *Dyck language* consists of all strings of evenly balanced left and right parentheses, brackets, or some other symbols, together with the *empty* word. Words in this language (named after German mathematician Walther von Dyck) are known as *Dyck words*, some examples of which are `()()()`, `(())((()))`, and `((()()))()`.\n\nThe type of Dyck language considered here is defined over a binary alphabet. If we take this alphabet to be the set Σ = {(, )}, then the binary Dyck language is the subset of Σ* (the Kleene closure of Σ) of all words that satisfy two conditions:\n\n1. The number of left brackets must be the same as the number of right brackets.\n2. Going from left to right, for each character read, the total number of right brackets visited must be less than or equal to the number of left brackets up to the current position.\n\nE.g., `(()(()` and `())(())()` are **not** Dyck words.\n\nWhen regarded as a combinatorial class \u0026ndash; with the size of a word defined as the number of bracket pairs it contains \u0026ndash; the counting sequence associated with the Dyck language is the *Catalan numbers*.\n\n```\nλ\u003e take 15 $ (length . wordsOfSize) \u003c$\u003e [0..]\n[1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440]\n```\n\n## Documentation\n\nSee [Hackage](http://hackage.haskell.org/package/dyckword/docs/Math-DyckWord-Binary.html).\n\n## Install\n\n```\ncabal install dyckword\n```\n\n## Examples\n\n```\nλ\u003e :set -XOverloadedStrings \n\nλ\u003e toText $ unrank (10^889)\n(()((()((())(()()((()()()((()((())())(()(()()()(())()()()))((()()))())(()()(())((((()())((((()()(()()(())((()(())\n((((())))))(((((((()((())()()((())))()(()((())))(((())))))()())()()()()))(()))()(())(((())))))))()(())))()))()(()\n(((()())((()())()(()())())))())))))))))(((((()((())()))((()())()(((()()()(()(()))))((())((()))))((()())())())((()\n(()()))))))())()((())((((()(()(()()()((())((((((((()(((((((((()(())()(()()()((()))))()((())(((())(()())())((()())\n((()(()))())()())(()))))))()((()((())(())())(()))))()())()()(())(()()))()))((((()())(()()()))(())))((())))))())((\n()))))))))()(())((()((((((())(())))()(()(((((()()()))())))())(((())(()((()(((((((())())((())(()))((()(()()(()(()(\n())()(()))()()(((()(((()))(())))(()))((()))()(()))((())(()()()((()()())))(()))())(()))))()()))((())()())())(()())\n)))((()()))(((()))(()))((()))))())())()(()(()))())((())))()()()()(()())()(())())(((((()))())()(()())()()(((((())(\n)))(()(()))(((()()()())()()())())())(((((()())))))()))())())))(()()))()))()()))))())()(((((((())()(()(()))))(((((\n((((((()()((()())())(())))())))()(()))((((()))()()((()()()(()(((()))((())(((((((()()((())))())(()()(((()(()))))))\n))))()()((()(()()))())(())()(())(((()((((())))((()(((())(((()())))))(((((()))()(()((()()((()())())(((())())(())()\n)(()))())((((()(()())()(())(()(((()())()(()))()(()((()(((())))(())(()())))())(())()))((((()()(()))()()((((())()((\n((((())())())(()()((()(()())))))())())())))()))()))))((())((()))()()))((()()))(((()())()()()))()())))(((())))))))\n(((((())())()(())))((()()())()((((()())((((((((()(()()))))(()(())))))(())()(()((()()))(((((()(((())(((((((()))(((\n))(()(()(()()()(((())())))()((((((((())((((()((()(((((()))(())((()))))())(()(()())))((((())(()((()()))(((((()((((\n(((())()())())(()))()))()(()(()(((((()))(()))))))()())()))))()()())())((()(())))((())(((((((()()))((()()))))(((((\n(((()())()()))()())()(())()(()()(()))))))()))))()))())((())))))((()())(()(()))()()))()(())())((()())()))()())(())\n())(()()))())(()()))(()()()())()()())((())))))()(()())(()))()()())))(((())()(()()((()()))))))())((((((()()())))()\n())())((()())(((((()()(((((())()()()((()()(((((()((()(()())))(()(())(()()(()()(()(())))))()()(()())(()()))((())))\n))(())()))((()(()())((()))((()()()()()())))))())))()))()(((((((())))))))((())))))(((()()()())()()()()(()(()))(()(\n()())()(()()(()()(((())(())))))()((()))((()))(((((()(()()(()(((()((())))(()()(()()()(()((())()((()))()))(()()))))\n)()())((((())())(())()()()()((((()))))))((()()((())((()((((()())()))()((()((())())()()(((())()(((()(((((()((()))(\n)))))(())((()())()(()(((())))((((()(((()()())((()()()())())((((()(((()))()((((()(()))(()(((()()(()))())))())()(((\n()((()((())))(())))))))(()())()))()())())()))())()))())))))(((())))))))(()))((()())((())()())((()))))))()(()))())\n)(())))))))()())())))))))(()()(((())))(())((()(()()))(()()()()))(()()((()()()())))(()(()(()()))(())))(()())((())(\n)((()((()))(()()(()(()))(())))))))()()))())))))))))(()()))))(()))))())()(()()))()))((())))))()()()(()))))()(()(()\n((()))()(()(()(()))))()))())))()\n\nλ\u003e size $ unrank (10^989)\n1651\n\nλ\u003e rank $ fromText' \"(())()(((())))\"\n480\n\nλ\u003e rank $ fromText' \"ooxxoxooooxxxx\"\n480\n\nλ\u003e fromText \"aaaa\"\nLeft \"bad input\"\n\nλ\u003e fromText \"()()\" \u003e fromText \"(())\"\nTrue\n\nλ\u003e mapM_ print (toText \u003c$\u003e wordsOfSize 5)\n\"((((()))))\"\n\"(((()())))\"\n\"(((())()))\"\n\"(((()))())\"\n\"(((())))()\"\n\"((()(())))\"\n\"((()()()))\"\n\"((()())())\"\n\"((()()))()\"\n\"((())(()))\"\n\"((())()())\"\n\"((())())()\"\n\"((()))(())\"\n\"((()))()()\"\n\"(()((())))\"\n\"(()(()()))\"\n\"(()(())())\"\n\"(()(()))()\"\n\"(()()(()))\"\n\"(()()()())\"\n\"(()()())()\"\n\"(()())(())\"\n\"(()())()()\"\n\"(())((()))\"\n\"(())(()())\"\n\"(())(())()\"\n\"(())()(())\"\n\"(())()()()\"\n\"()(((())))\"\n\"()((()()))\"\n\"()((())())\"\n\"()((()))()\"\n\"()(()(()))\"\n\"()(()()())\"\n\"()(()())()\"\n\"()(())(())\"\n\"()(())()()\"\n\"()()((()))\"\n\"()()(()())\"\n\"()()(())()\"\n\"()()()(())\"\n\"()()()()()\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaserpants%2Fdyckword","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaserpants%2Fdyckword","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaserpants%2Fdyckword/lists"}