/ README.adoc
README.adoc
1 = BetLang Playground 2 :toc: macro 3 :icons: font 4 5 // SPDX-License-Identifier: AGPL-3.0-or-later 6 7 image:https://img.shields.io/badge/Language-BetLang-red[BetLang] 8 image:https://img.shields.io/badge/Logic-Ternary-purple[Ternary Logic] 9 image:https://img.shields.io/badge/Programming-Probabilistic-orange[Probabilistic] 10 image:https://img.shields.io/badge/License-AGPL--3.0-blue[License] 11 12 *Playground for BetLang - Ternary Logic & Probabilistic Programming* 13 14 toc::[] 15 16 == Overview 17 18 BetLang explores ternary logic and probabilistic programming, providing tools for reasoning under uncertainty. 19 20 === Key Features 21 22 * **Ternary Logic**: True, False, and Unknown values 23 * **Probabilistic Programming**: Distributions, sampling, inference 24 * **Uncertainty Modeling**: Combine logic with probability 25 * **Bayesian Inference**: Bayes' theorem and belief updating 26 27 == Ternary Logic 28 29 === Three-Valued Logic 30 31 BetLang extends boolean logic with an "Unknown" value: 32 33 |=== 34 | Value | Symbol | Meaning 35 36 | True | T | Definitely true 37 | False | F | Definitely false 38 | Unknown | U | Uncertain/undefined 39 |=== 40 41 === Truth Tables 42 43 [source] 44 ---- 45 AND | T | U | F | OR | T | U | F | 46 ----+---+---+---+ ----+---+---+---+ 47 T | T | U | F | T | T | T | T | 48 U | U | U | F | U | T | U | U | 49 F | F | F | F | F | T | U | F | 50 ---- 51 52 === Example 53 54 [source,betlang] 55 ---- 56 -- Sensor readings with uncertainty 57 let sensor_a: Ternary = T -- Known true 58 let sensor_b: Ternary = U -- Faulty sensor (unknown) 59 let sensor_c: Ternary = F -- Known false 60 61 -- Ternary operations 62 let result = sensor_a AND sensor_b -- U (unknown propagates) 63 let any_true = sensor_a OR sensor_b -- T (true dominates in OR) 64 ---- 65 66 == Probabilistic Programming 67 68 === Probability Types 69 70 [source,betlang] 71 ---- 72 -- Probability values (0 to 1) 73 let coin_flip: Probability = 0.5 74 let biased_coin: Probability = 0.7 75 76 -- Sampling 77 let heads = bernoulli(coin_flip) -- true or false 78 let value = uniform(0, 10) -- float in [0, 10) 79 let sample = normal(0, 1) -- standard normal 80 ---- 81 82 === Bayesian Inference 83 84 [source,betlang] 85 ---- 86 -- Bayes' theorem: P(A|B) = P(B|A) * P(A) / P(B) 87 let prior = 0.01 -- P(disease) 88 let sensitivity = 0.99 -- P(positive|disease) 89 let evidence = 0.0594 -- P(positive) 90 91 let posterior = bayes(sensitivity, prior, evidence) 92 -- P(disease|positive) = 0.1667 93 ---- 94 95 == Uncertainty Modeling 96 97 Combine ternary logic with probability: 98 99 [source,betlang] 100 ---- 101 -- Convert probability to ternary based on confidence 102 fn probability_to_ternary(p: Probability) -> Ternary: 103 if p > 0.9: 104 T -- High confidence true 105 else if p < 0.1: 106 F -- High confidence false 107 else: 108 U -- Uncertain 109 ---- 110 111 == Project Structure 112 113 [source] 114 ---- 115 betlang-playground/ 116 ├── src/ 117 │ ├── main.ts # Main entry point 118 │ ├── ternary.ts # Ternary logic implementation 119 │ └── probability.ts # Probabilistic programming 120 ├── examples/ # Example programs 121 ├── test/ # Test suite 122 ├── docs/ # Documentation 123 ├── deno.json # Deno configuration 124 ├── rescript.json # ReScript configuration 125 ├── justfile # Build commands 126 └── Mustfile # Mandatory checks 127 ---- 128 129 == Getting Started 130 131 [source,bash] 132 ---- 133 # Clone the repository 134 git clone https://github.com/hyperpolymath/betlang-playground.git 135 cd betlang-playground 136 137 # Run the demo 138 just dev 139 140 # Run tests 141 just test 142 143 # Run ternary logic demo 144 just ternary-demo 145 146 # Run probability demo 147 just probability 148 ---- 149 150 == Examples 151 152 * `src/ternary.ts` - Ternary logic operations and truth tables 153 * `src/probability.ts` - Probability distributions and inference 154 * `test/` - Comprehensive test suite 155 156 == License 157 158 SPDX-License-Identifier: AGPL-3.0-or-later