kotlin-mathematical-modeling

Transforms Kotlin modules using typed sets, classes, sequences, and interfaces.

Updated Feb 20, 2026
One-click install
npx skills add https://github.com/KrystianYCSilva/math-theory-lib --skill kotlin-mathematical-modeling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-mathematical-modeling
Source: https://github.com/KrystianYCSilva/math-theory-lib/tree/main/.gemini/skills/kotlin-mathematical-modeling
Command: npx skills add https://github.com/KrystianYCSilva/math-theory-lib --skill kotlin-mathematical-modeling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Translating formal mathematical and logical specifications into Kotlin code often leads to subtle runtime errors, incorrect invariants, and mixing of incompatible types. This Skill presents design patterns that push correctness to compile time by modeling closed universes, enforcing type safety, guaranteeing immutability, and enabling lazy representations of infinite structures.

Core Features & Use Cases

  • Sealed types for closed universes: Encode disjoint unions and force exhaustiveness in pattern matching to eliminate unhandled cases.
  • Value classes for zero-cost type safety: Create distinct numeric and domain types that compile down to primitives to avoid accidental mixing while keeping performance.
  • Immutability and persistent structures: Design extensional sets and other collections where operations return new instances, aligning code with mathematical definitions and improving thread safety.
  • Lazy sequences for infinite structures: Represent infinite sets like the naturals and compose lazily-evaluated transformations without materializing large collections.
  • Use Case: Build a Cardinality hierarchy (Finite, CountablyInfinite, Aleph, Unknown), a NaturalNumber value class, an immutable ExtensionalSet, and a NaturalNumbers lazy sequence to model and test mathematical properties in a Kotlin library.

Quick Start

Create a Kotlin module that models cardinality using sealed types, defines NaturalNumber as a value class, implements an immutable ExtensionalSet, and exposes a lazy sequence of natural numbers for testing and composition.

Frequently Asked Questions about kotlin-mathematical-modeling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce type safety for distinct numeric types in Kotlin without runtime overhead?

Kotlin value classes create distinct numeric and domain types that compile down to primitives, preventing accidental mixing while preserving JVM performance. They provide zero-cost wrappers for enforcing type safety in mathematical modeling.

What's the best way to model closed universes and ensure exhaustiveness in Kotlin?

Kotlin sealed classes encode disjoint unions and force exhaustiveness in pattern matching. Modeling closed universes with sealed types eliminates unhandled cases by pushing exhaustiveness checks to compile time.

How do I represent lazy infinite structures like natural numbers in Kotlin?

Kotlin sequences represent infinite sets and compose lazily-evaluated transformations without materializing large collections. You can model infinite structures like the naturals by exposing a lazy sequence for testing and composition.

Why use immutability for mathematical collections in Kotlin?

Immutability in Kotlin collections ensures operations return new instances, aligning code with mathematical definitions and improving thread safety. Persistent structures like extensional sets maintain correctness by preventing state mutation.

Can I use Kotlin sealed types and value classes together to model formal specifications?

Yes, Kotlin sealed types and value classes work together to translate formal mathematical and logical specifications into type-safe domain models. Sealed classes enforce invariants for closed universes while value classes wrap distinct numeric types.

When should I not use lazy sequences for mathematical modeling in Kotlin?

You should avoid Kotlin lazy sequences when you need strict evaluation or materialize large collections immediately. Sequences defer evaluation, which is unsuitable for mathematical models requiring eager computation or finite extensional sets.