Squiggle Programming Language

repository·main·Indexed 42 days ago

https://github.com/quantified-uncertainty/squiggle

A JavaScript-based programming language designed for probabilistic estimation, featuring tools for parsing expressions, describing distributions, and visualizing results through React components. The ecosystem includes Squiggle Hub for workflow management, a dedicated website, and utilities for probabilistic modeling and evaluation.

Tokens
91.4K
Snippets
336
Records
506
Agent score
52%

What's inside Squiggle

  1. Overview of @quri/content package

    main

    The @quri/content package is an internal utility used for maintaining Content Collections. It serves as a centralized hub for managing structured content used across the Squiggle ecosystem, including documentation for the website and raw data for AI system prompts.

    This package re-exports all generated content collections and provides helper functions for interacting with them.

  2. Explore Squiggle models and writeups

    main

    You can find Squiggle models and related analytical writeups in several locations across the ecosystem:

    • Squiggle Hub: The primary application for hosting and interacting with models (squigglehub.org).
    • Effective Altruism Forum: Search for the Squiggle tag to find models and discussions.
    • Squiggle Models Repository: A dedicated list of QURI Squiggle models can be found in the squiggle-models repository.
  3. Understand the structure of the hub/src/lib directory

    main

    The apps/hub/src/lib directory contains shared logic for the Squiggle Hub application. It is organized by the intended runtime environment and usage pattern:

    • lib/server: Contains code that must only run on the server (e.g., database access, sensitive logic).
    • lib/hooks: Contains common React hooks intended for use in client-side components.
    • Other files: General shared logic that can be used in both server and client contexts.
  4. Use the Plot module to create distribution and function plots

    main

    The Plot module provides functions for visualizing distributions and mathematical functions.

    There are two ways to generate plots:

    1. Direct Plotting: Using raw functions and distributions, which are plotted using default parameters.
    2. Plot Objects: Using specific functions from this module that return plot objects. These objects provide granular control over chart parameters and allow for the creation of more complex chart types.
  5. Experimental Danger modules overview

    main

    The Danger library provides experimental modules that are less stable than the core Squiggle library. These modules are intended for testing new ideas rather than production environments. The available modules include:

    • Javascript: Provides near 1-to-1 matches of Javascript functions.
    • Math: Mathematical functions.
    • Combinatorics: Combinatorial functions.
    • Distributions: Statistical distribution functions.
    • Integration: Integration functions.
    • Optimization: Optimization functions.
    • JSON: JSON-like object serialization (Danger.json and Danger.jsonString).
  6. Metaforecast GraphQL Tech Stack and Code Layout

    main

    The Metaforecast website uses a specific stack for GraphQL implementation:

    Key Files:

    • schema.graphql: The generated GraphQL schema.
    • codegen.yml: Configuration for graphql-code-generator.
    • graphql.config.yaml: GraphQL Config for VS Code integration (enables type-checking in .graphql files).
    • src/pages/api/graphql.ts: The GraphQL HTTP endpoint and playground.
    • src/web/urql.ts: Helper functions for urql.
    • src/graphql/: Contains the GraphQL server implementation.
    • src/web/**/*.graphql: Contains fragments, queries, and mutations used on the frontend.
  7. What is Squiggle?

    main

    Squiggle is a minimalist programming language designed for intuitively-driven quantitative estimation. It allows users to perform math with probability distributions and encode functions as forecasts.

    Key Characteristics:

    • Purpose: Intuitively-driven estimation rather than data analysis or data-driven statistical techniques.
    • Embeddability: It is an embeddable language that can be integrated into JavaScript applications.
    • Not a Probabilistic Programming Language: Unlike standard probabilistic programming languages, Squiggle does not support Bayesian inference (backwards inference).
    • Not for Data Analysis: It is not intended to replace tools like Python or Julia for substantial data analysis, nor is it a replacement for enterprise Risk Analysis tools (e.g., Crystal Ball, @Risk).
  8. Handle 'a to b' expressions in @quri/squiggle-lang

    main

    Starting with @quri/squiggle-lang v0.8.0, the expression a to b always evaluates to a lognormal distribution. Note that the arguments must be positive-only. Previous versions allowed these to fall back to normal distributions for values zero or less, but this behavior has changed.

    // Evaluates to a lognormal distribution
    5 to 10