This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# Written by tools, never by hand: hide them from diffs' language stats and code review
|
||||
mojo/golden/** linguist-generated=true
|
||||
mojo/corpus/** linguist-generated=true
|
||||
mojo/mojo.lock.json linguist-generated=true
|
||||
syntax/mojo.xml linguist-generated=true
|
||||
status.json linguist-generated=true
|
||||
STATUS.md linguist-generated=true
|
||||
THIRD_PARTY.md linguist-generated=true
|
||||
@@ -0,0 +1,110 @@
|
||||
# pplus-library's gate. The library is data; its checks are pplus-core's tasks, run from a core checkout where the
|
||||
# library is `library/` (AGENTS.md). So this checks out core's default branch, puts this commit of the library where
|
||||
# core's submodule goes, does what core does when it takes a new library (moves its pointer, in this throwaway
|
||||
# checkout only, and regenerates what it derives: library-emit, mojo-emit), and runs core's whole gate, `pixi run ci`.
|
||||
#
|
||||
# What a green run shows: core's default branch, given this library and what core regenerates from it, passes every
|
||||
# test, mojo-status-strict, library-check (every routine at every level), mojo-local and the short fuzz. What it does
|
||||
# not show: that core pins this commit (that is a commit in core, made after this one is pushed; pplus-web's
|
||||
# release-check task checks the chain), that web works with it, or anything about a core branch other than the
|
||||
# default one. A red run can be core's own: look at core's latest run first. The repository variable CORE_REF, when
|
||||
# set, names another ref of core to test against (a branch made for the same change).
|
||||
#
|
||||
# Gitea Actions (host mode, as pplus-core's workflows); on GitHub Actions the same file runs with
|
||||
# `runs-on: ubuntu-latest`. core is read from the same owner on the same server as this repository.
|
||||
name: Test (in pplus-core)
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: test-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
CI: "true"
|
||||
PIXI_VERSION: "0.83.0"
|
||||
|
||||
jobs:
|
||||
in-core:
|
||||
# a pull request runs only from a branch of this repository: on a host runner a fork's workflow would run its
|
||||
# own code on the droplet (docs/deploy.md in pplus-web). Drop this line for a runner that is a throwaway VM.
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
|
||||
runs-on: quarto-deploy
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- name: pplus-core, its default branch (or CORE_REF)
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ github.repository_owner }}/pplus-core
|
||||
ref: ${{ vars.CORE_REF }}
|
||||
path: core
|
||||
- name: This commit of pplus-library, where core's submodule goes
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: core/library
|
||||
|
||||
# pixi: the host's when it is the pinned version, else the pinned release, fetched once into a cache directory
|
||||
# the runner's user owns (no sudo), checked by SHA-256
|
||||
- name: pixi, pinned
|
||||
shell: bash
|
||||
working-directory: core
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if command -v pixi >/dev/null && [ "$(pixi --version | cut -d' ' -f2)" = "$PIXI_VERSION" ]; then
|
||||
echo "pixi $PIXI_VERSION is on the host: $(command -v pixi)"; exit 0
|
||||
fi
|
||||
dir="${PPLUS_CI_CACHE:-$HOME/.cache/pplus-ci}/pixi-$PIXI_VERSION"
|
||||
if [ ! -x "$dir/pixi" ]; then
|
||||
case "$(uname -s)-$(uname -m)" in
|
||||
Linux-x86_64) asset=pixi-x86_64-unknown-linux-musl.tar.gz; sum=064f371e692aaa3400ac581c89da2843c91437f20c2d9155395a5d0037f33551 ;;
|
||||
Linux-aarch64) asset=pixi-aarch64-unknown-linux-musl.tar.gz; sum=d08403d8f048626ec93ba7b7c56e3b747a5f3a95c4e6e0c815ceb264f5f0b9ce ;;
|
||||
*) echo "no pinned pixi for $(uname -sm)" >&2; exit 1 ;;
|
||||
esac
|
||||
tmp="$(mktemp -d)"
|
||||
curl -fsSL --retry 3 -o "$tmp/$asset" "https://github.com/prefix-dev/pixi/releases/download/v$PIXI_VERSION/$asset"
|
||||
echo "$sum $tmp/$asset" | sha256sum -c -
|
||||
mkdir -p "$dir" && tar -xzf "$tmp/$asset" -C "$dir" pixi && rm -rf "$tmp"
|
||||
fi
|
||||
echo "$dir" >> "$GITHUB_PATH"
|
||||
"$dir/pixi" --version
|
||||
|
||||
- name: The pinned environment, exactly as core's pixi.lock has it
|
||||
working-directory: core
|
||||
run: pixi install --locked
|
||||
|
||||
# .tools/ (the pinned Dafny, mojo-local's answers) in the runner's cache, as in pplus-core's own workflow
|
||||
- name: The pinned Dafny
|
||||
working-directory: core
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cache="${PPLUS_CI_CACHE:-$HOME/.cache/pplus-ci}/core-tools"
|
||||
mkdir -p "$cache"
|
||||
if [ -d .tools ] && [ ! -L .tools ]; then echo ".tools is a directory in this checkout already: using it"; else ln -sfn "$cache" .tools; fi
|
||||
pixi run dafny-fetch
|
||||
|
||||
# what pplus-web's release-bump task does in core when the library moves; the commit stays on this runner
|
||||
- name: Core takes this library
|
||||
working-directory: core
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "core $(git rev-parse --short HEAD) pinned library $(git rev-parse --short HEAD:library); this library is $(git -C library rev-parse --short HEAD)"
|
||||
pixi run library-emit
|
||||
pixi run mojo-emit
|
||||
git add library src/library/generated.ts src/mojo/generated
|
||||
git -c user.name=CI -c user.email=ci@invalid -c commit.gpgsign=false commit -q --allow-empty -m "CI: take pplus-library $(git -C library rev-parse --short HEAD)"
|
||||
git -C library diff --stat --exit-code || { echo "mojo-emit changed the library: commit what it writes (pixi run mojo-emit in core)" >&2; exit 1; }
|
||||
|
||||
- name: pixi run ci (core's gate, with this library)
|
||||
working-directory: core
|
||||
run: pixi run ci
|
||||
|
||||
- name: Nothing the gate regenerates differs from what this commit holds
|
||||
working-directory: core
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git -C library diff --stat --exit-code
|
||||
@@ -0,0 +1,2 @@
|
||||
__pycache__/
|
||||
.DS_Store
|
||||
@@ -0,0 +1,47 @@
|
||||
# AGENTS.md
|
||||
|
||||
Rules for changing pplus-library, the ground truth of Programming+. Programming+ takes a procedure from an idea to Mojo to the machine. Its routines are written in pseudo (pseudocode precise enough to run, prove and translate). The checks are pplus-core's tasks: run them from a core checkout, where this repository is `library/`. A change here is committed here first, then in core with the new submodule pointer and whatever core regenerated from it.
|
||||
|
||||
## The gate
|
||||
|
||||
```bash
|
||||
pixi run library-check # in pplus-core: no check may fail
|
||||
pixi run library-emit # then core's registry, committed in core
|
||||
```
|
||||
|
||||
**A change is finished when `library-check` reports no failing check and `STATUS.md` shows what you expect.** A check may be `open` (the prover could not finish an obligation), `skipped` (a tool is missing, or a tool declines: core's Mojo interpreter or translator a construct, the fuzzer the routine's inputs) or `unverified` (no stored compiler answer for this exact text yet); none of those is a failure, and each is listed in your summary.
|
||||
|
||||
## Hard rules for routines
|
||||
|
||||
1. **One routine per file.** `routine.pseudo` holds USE lines and one FUNCTION or PROCEDURE, named as `routine.json` names it, and nothing else. A helper is a routine of its own, brought in with USE. That way every function in the library is checked on its own and appears once in generated Mojo.
|
||||
2. **The pseudo is the specification.** The cases' results come from running the pseudo; every reference implementation is held to them. Never change a case's expected value by hand: `status.json` records it from the run.
|
||||
3. **Do not edit generated files.** `status.json`, `STATUS.md` and everything under `golden/` are written by tools. A Mojo answer comes only from `pixi run library-verify-mojo`; a Dafny verdict only from `library-check` with the pinned Dafny.
|
||||
4. **Contracts the prover can hold.** REQUIRE everything the routine needs. Write an ENSURE when the prover proves it (whole numbers, comparisons, lengths); a claim about the value of FLOAT arithmetic belongs in the Dafny proof over exact numbers, because rounding is opaque to the prover. An obligation left open is explained in the routine's comment (see `special.ErfApprox`); core's `tests/documents.test.mjs` fails when a routine recorded *open* has no comment that says so.
|
||||
5. **Every tolerance is explained.** A reference held to the pseudo within `rel` or `abs` says in its note why the answers differ (a different order of additions, a different method, an approximation's stated bound), and for which inputs the tolerance holds when it does not hold for all. `tests/documents.test.mjs` fails on a tolerance with no note.
|
||||
6. **Cite the method.** `sources` names where it comes from: a paper with its DOI, a book with its edition and section, a manual page with its URL. `tests/documents.test.mjs` fails on a routine with no source of one of those kinds.
|
||||
7. **No new dependencies.** Python references use the standard library; C references use the C standard library and `-lm`; Mojo references use the standard library of the pinned Mojo.
|
||||
8. **US English**, plain sentences, in a routine's comments, notes and summaries (`tests/documents.test.mjs` fails on the British spellings it knows).
|
||||
|
||||
## Adding a routine
|
||||
|
||||
1. Make `modules/<module>/<kebab-name>/` with `routine.json` (name, summary, tags, sources, cases) and `routine.pseudo`.
|
||||
2. Add references under `ref/<lang>/<level>.<ext>`: the function only, named in snake case after the routine (`LennardJones` is `lennard_jones`). A list parameter is a list in Python and Mojo, and an array and its length in C. Add each to `routine.json` with its note and any tolerance.
|
||||
3. Add a Dafny proof under `proof/` when there is something worth proving over exact numbers, and name it in `routine.json`.
|
||||
4. Run `pixi run library-check` and `pixi run library-emit` in core; commit this repository, then core with the new pointer and registry.
|
||||
|
||||
## The Mojo corpus (`mojo/`)
|
||||
|
||||
The gate, in core: `pixi run mojo-status-strict` (offline) and `npm test`. Read core's `docs/mojo-corpus.md` first.
|
||||
|
||||
1. **Never claim Mojo compiles, runs, or prints something without the real compiler's answer.** Everything under `mojo/golden/` is written by `corpus.py verify` from godbolt's answers, and `STATUS.md` and `status.json` there by `corpus.py status`. Never edit them by hand.
|
||||
2. **Do not edit `mojo/corpus/` or `mojo/mojo.lock.json`.** They come from `pixi run mojo-harvest` at the refs in `mojo/pin.json`. To move to a new Mojo version, edit `mojo/pin.json` and follow core's `docs/mojo-corpus.md`.
|
||||
3. **Our programs are made with core's scripts:** `pixi run new-probe`, `new-exercise`, `new-stress`. A probe asks one question. An exercise program passes its own `# expect-stdout:` lines, or says with `# expect: fail` that the check must not hold (a starter with a bug for the student to find). A stress program's `# expect-stdout:` lines are the interpreter's prediction, checked against godbolt; a few stress programs are `# expect: compile-error` cases the compiler must reject. The header keys are in core's `docs/mojo-corpus.md`.
|
||||
4. **`syntax/mojo.xml` is generated** by `pixi run mojo-emit` in core, from the same words as core's `src/mojo/generated/`.
|
||||
|
||||
## Pseudo programs (`pseudo/`)
|
||||
|
||||
The gate, in core: `npm test` (`tests/corpus.test.mjs`, `tests/prover-soundness.test.mjs`, the sync tests).
|
||||
|
||||
1. **A regression program** is a file in `pseudo/programs/` named `<nn>-<name>.pseudo`, numbered after the last one, whose `// EXPECT:` lines are the output it must print (`// INPUT:` lines are what it reads), or whose `// STOPS: <kind>` line says how its run must stop, or whose `// ERRORS: <n>` line says how many errors the checker must report. Every translator in core is also run over it.
|
||||
2. **A prover soundness regression** is a file in `pseudo/prover/` whose `// MUST-NOT-PROVE: <kind>@<line>` names an obligation a run breaks, or `// RUN-STOPS: <kind>@<line>` where a run must stop. When a soundness bug is found, add its program here first, watch core's test fail, then fix the rule in core.
|
||||
3. **Never change an `// EXPECT:` line to match a new answer** without knowing why the old answer was wrong; the line is the specification.
|
||||
@@ -0,0 +1,33 @@
|
||||
# Changelog
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
pplus-library has no version numbers: pplus-core pins it by commit, and each core release says which commit it holds.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- The Mojo corpus is harvested for Mojo 1.2.0 (it was 1.1.0), at the release tag of modular/modular and the matching commits of the other sources, with godbolt's answer for every program.
|
||||
- Every Mojo program is built one stated way, `--target-cpu x86-64-v3 --fp-mode contract=off`, written once in `mojo/pin.json` (`build`): a godbolt listing no longer depends on which of its machines answers, and floating-point arithmetic is rounded one operation at a time. Every stored answer was asked again under those arguments.
|
||||
- A routine's compiled references (Mojo and C) read their cases at run time, from standard input. Written as literals, the cases were worked out by the compiler while building, so its agreement was its constant folder's.
|
||||
- Regression program 45 is `45-parallel-neighbor-race.pseudo`, and the programs' own words are in US English.
|
||||
- `syntax/mojo.xml` states its license as Apache-2.0 (it said MIT).
|
||||
|
||||
### Added
|
||||
|
||||
- Every routine's Mojo references have the pinned compiler's stored answer, and the probes record fourteen facts about Mojo 1.2.0 that core relies on, with two earlier questions corrected.
|
||||
- 31 prover soundness regressions from an audit of the prover, and a regression program for the rules an audit of the interpreter pinned.
|
||||
- Probes for what the translator's notes say about Mojo, for the Mojo the interpreter runs (typed list literals, slices, `ord` and `chr`, std.math's exact functions, `atof`, `match`), for reading input on a pipe, and for the build arguments themselves; `struct-field-loop-copy` records a crash in code Mojo 1.2.0 builds.
|
||||
- `55-statements.pseudo`, the shapes the statement fuzzer found the translator getting wrong.
|
||||
- A workflow that checks the library on every push, by running pplus-core's gate against it.
|
||||
- `THIRD_PARTY.md`, every harvested file with its source and license header, and `mojo/licenses/`, each source's license file at the pinned commit.
|
||||
- The Apache License 2.0, a NOTICE, contributing rules, a security policy, a code of conduct, and a citation file.
|
||||
|
||||
## 2026-10-06
|
||||
|
||||
The state of `main`.
|
||||
|
||||
### Added
|
||||
|
||||
- 16 verified routines in six modules (stats, numerics, align, md, seq, special), each written once in pseudo and checked at every level: cases, prover, fuzzer, generated Mojo, reference implementations in Python, C and Mojo, and a Dafny proof where one says something.
|
||||
- The Mojo corpus, the probes, the exercise and stress programs, godbolt's answers, and the pseudo regression and prover soundness programs, moved here from pplus-core.
|
||||
@@ -0,0 +1,20 @@
|
||||
cff-version: 1.2.0
|
||||
message: "If you use Programming+ in published work, please cite it as below."
|
||||
type: software
|
||||
title: "pplus-library: verified routines, the Mojo corpus and the regression programs of Programming+"
|
||||
authors:
|
||||
- family-names: Maldonado
|
||||
given-names: Alex M.
|
||||
email: alex@scient.ing
|
||||
orcid: "https://orcid.org/0000-0003-3280-062X"
|
||||
- name: Scientific Computing Studio, LLC
|
||||
email: us@scient.ing
|
||||
url: "https://pplus.scient.ing"
|
||||
repository-code: "https://git.scient.ing/pplus/pplus-library"
|
||||
license: Apache-2.0
|
||||
keywords:
|
||||
- programming education
|
||||
- pseudocode
|
||||
- Mojo
|
||||
- program verification
|
||||
- computer architecture
|
||||
@@ -0,0 +1,84 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at alex@scient.ing. All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# Contributing
|
||||
|
||||
Thank you for reading this far.
|
||||
pplus-library is the ground truth of Programming+: the routines, the Mojo corpus, and the programs the engines are held to. It is maintained by one person, and the rules below keep it honest about what it can take on.
|
||||
|
||||
## Two rules first
|
||||
|
||||
- **No outside code is merged until a contributor license agreement exists.** Until then, bug reports, failing programs, questions, and documentation fixes are welcome, and code changes are read and used as guidance but not merged. The agreement will be short and will ask you to confirm that you may license your change under Apache-2.0.
|
||||
- **No contributions from students enrolled at the University of Pittsburgh.** The maintainer teaches there, and this project is separate from that job. Students may use Programming+ like anyone else.
|
||||
|
||||
## Running the checks
|
||||
|
||||
Programming+ uses [pixi](https://pixi.sh/latest/) for its environments; it brings the pinned Mojo, Node and Python.
|
||||
The checks are pplus-core's tasks; run them in a pplus-core clone, where this repository is the submodule `library/`:
|
||||
|
||||
```sh
|
||||
pixi run test # build, then every test
|
||||
pixi run library-check # every check of every routine, at every level
|
||||
```
|
||||
|
||||
Without pixi, with Node 20 or later: `npm install && npm test` in pplus-core.
|
||||
`mojo/corpus/` is Modular's material, harvested at pinned commits: a change to it comes from upstream through a new harvest, not from a patch here.
|
||||
[AGENTS.md](AGENTS.md) has the rules every change follows, whoever writes it: one routine per file, the pseudo as the specification, the files only tools write, and how to cite a method.
|
||||
|
||||
## Reporting a bug
|
||||
|
||||
Say what you ran, what you expected, and what happened.
|
||||
The best report is a program: a pseudo program and the output it should print, a Mojo program and what the compiler says about it, or a program the prover calls proved that a run breaks (that one is a soundness bug, the most serious kind, and it belongs in `pseudo/prover/`).
|
||||
Where to file issues will be in the README once the repository is public.
|
||||
|
||||
## Style
|
||||
|
||||
US English, plain sentences.
|
||||
A commit says the problem first, then what each part of the change does, and a fix comes with a test that fails without it.
|
||||
Every change for a user has a line in `CHANGELOG.md`.
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
# Apache License
|
||||
|
||||
_Version 2.0, January 2004_
|
||||
_<<http://www.apache.org/licenses/>>_
|
||||
|
||||
## Terms and Conditions for use, reproduction, and distribution
|
||||
|
||||
### 1. Definitions
|
||||
|
||||
“License” shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
“Licensor” shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
“Legal Entity” shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, “control” means **(i)** the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or **(iii)** beneficial ownership of such entity.
|
||||
|
||||
“You” (or “Your”) shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
“Source” form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
“Object” form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
“Work” shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
“Derivative Works” shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
“Contribution” shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
“submitted” means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as “Not a Contribution.”
|
||||
|
||||
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
### 2. Grant of Copyright License
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
### 3. Grant of Patent License
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
### 4. Redistribution
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
* **(b)** You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
### 5. Submission of Contributions
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
### 6. Trademarks
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
### 7. Disclaimer of Warranty
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
### 8. Limitation of Liability
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
### 9. Accepting Warranty or Additional Liability
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
||||
@@ -0,0 +1,16 @@
|
||||
# pplus-library
|
||||
|
||||
Copyright 2026 Scientific Computing Studio, LLC
|
||||
|
||||
This product includes software developed by Scienting ([scient.ing](https://scient.ing/)).
|
||||
|
||||
Licensed under the Apache License, Version 2.0.
|
||||
See the `LICENSE.md` file for the full license text.
|
||||
|
||||
## Third-party material
|
||||
|
||||
`mojo/corpus/` holds material from Modular Inc.'s repositories modular/modular, modular/mojo-quest, modular/mojo-syntax, modular/vscode-mojo and modular/skills, harvested at the commits `mojo/mojo.lock.json` records. It is Copyright (c) Modular Inc. (and, for the mojo-syntax grammar, MagicStack Inc. and Microsoft Corporation) and stays under its own licenses: the Apache License v2.0 with LLVM Exceptions, the Apache License 2.0 and the MIT License, whose texts are in `mojo/licenses/`. Mojo Quest has no license file; see `THIRD_PARTY.md`, which lists every harvested file, its source, and the license header it carries. `mojo/golden/` holds the answers Compiler Explorer returned: the Mojo compiler's output for the programs here.
|
||||
|
||||
## Trademarks
|
||||
|
||||
"Mojo" and "Modular" are trademarks of Modular Inc. Programming+ is not affiliated with, sponsored by, or endorsed by Modular Inc.; it uses the names only to say which language and compiler it works with. "Compiler Explorer" and "godbolt.org" name the service by Matt Godbolt that Programming+ asks for the compiler's answers; Programming+ is not affiliated with it either.
|
||||
@@ -0,0 +1,99 @@
|
||||
# pplus-library
|
||||
|
||||
Programming+ takes a procedure from an idea to Mojo to the machine. pplus-library is its ground truth: the routines a program can use by name, the Mojo programs and stored compiler answers the engines are held to, and the regression programs they must run as written. The engines and the tools that check all of this live in pplus-core, which pins this repository as its submodule `library/`; pplus-web, the site, gets it through core.
|
||||
|
||||
- **Who it is for:** anyone adding a routine to Programming+, a question about the Mojo compiler, or a program the engines must handle, and anyone who wants to see what the engines are tested against.
|
||||
- **Status:** in development, with no tagged release; pplus-core pins it by commit ([CHANGELOG.md](CHANGELOG.md)). Nothing here runs on its own.
|
||||
- **Try it and run its checks:** from a pplus-core checkout, `pixi run library-check` ([Checking it](#checking-it)).
|
||||
- **Report a problem:** [SECURITY.md](SECURITY.md) says where to send a report and what counts as a security problem; [CONTRIBUTING.md](CONTRIBUTING.md) says what makes a good bug report.
|
||||
|
||||
Programming+ works in five notations:
|
||||
|
||||
- **lingo**: steps in plain English that a reader can run.
|
||||
- **matho**: equations written in LaTeX.
|
||||
- **pseudo**: pseudocode precise enough to run, prove and translate; every translation goes through it.
|
||||
- **speco**: a specification to prove against: what a routine requires and ensures, and what each loop keeps.
|
||||
- **Mojo**: Modular's programming language, pinned to version 1.2.0. Programming+ writes Mojo from pseudo, steps through it, and asks the real compiler about it.
|
||||
|
||||
This repository holds three kinds of material:
|
||||
|
||||
- **Verified routines** (`modules/`), written once in pseudo and used by name with `USE`.
|
||||
- **The Mojo corpus** (`mojo/`): the pinned Mojo version, material harvested from Modular's repositories at pinned commits, our own probes, exercise programs and stress programs, and godbolt's stored answer for every program we wrote and every harvested program that runs (the compiler's own diagnostic tests are asked only on request, and most have no stored answer).
|
||||
- **Pseudo programs** (`pseudo/`): regression programs with what each must print, stop with or be refused for, and the prover's soundness regressions.
|
||||
|
||||
## Verified routines
|
||||
|
||||
Each routine is written once in pseudo, and `pixi run library-check` checks it in every way a tool here can. The cases run. The prover proves every obligation, or the check is recorded *open* and the routine's comment says which obligation and why. The fuzzer finds no failure in the inputs it generates ([STATUS.md](STATUS.md) gives the count for each routine). The Mojo generated from the pseudo prints the same results, or results within 1e-9 relative where the compiler's `std.math` rounds differently. Every reference implementation agrees with the pseudo on the cases: Python and Mojo for every routine, C for a few, and a second level of care or optimization for some. Where one says something, a Dafny transcription of the method verifies over exact numbers.
|
||||
|
||||
A program uses a routine by name. A run steps over it; to step through a routine itself, open it from the site's library page, which opens it in the Bridge.
|
||||
|
||||
```
|
||||
USE md
|
||||
DECLARE R : FLOAT <- 1.5
|
||||
OUTPUT LennardJones(R, 0.238, 3.4), " ", MinimumImage(2.3, 1.0)
|
||||
```
|
||||
|
||||
prints `17380.997888282014 0.2999999999999998` (`pixi run cli run <file>` in pplus-core).
|
||||
|
||||
`USE md` brings in every routine of the module; `USE md.MinimumImage` brings in one. The prover uses each routine's REQUIRE and ENSURE lines at the call, so a program built from library routines is checked against what they promise, without proving them again.
|
||||
|
||||
## What is here
|
||||
|
||||
```
|
||||
modules/<module>/module.json the module's name, title and summary
|
||||
modules/<module>/<routine>/routine.pseudo the routine: one FUNCTION or PROCEDURE, its contracts, USE lines for what it calls
|
||||
modules/<module>/<routine>/routine.json name, summary, tags, sources, cases, references, proof
|
||||
modules/<module>/<routine>/ref/<lang>/<level>.<ext> reference implementations
|
||||
modules/<module>/<routine>/proof/<name>.dfy a Dafny proof, where one says something
|
||||
modules/<module>/<routine>/golden/ stored answers of real tools (written by tools only)
|
||||
status.json, STATUS.md what every check found (written by pixi run library-check)
|
||||
|
||||
mojo/pin.json the Mojo version, the godbolt compiler, each source repository and its ref (you edit this)
|
||||
mojo/mojo.lock.json what each ref resolved to: commit, zip sha256 (written by mojo-fetch, mojo-harvest)
|
||||
mojo/corpus/ processed material from Modular's repositories, each item with its provenance (mojo-harvest)
|
||||
mojo/probes/ one question about the pinned compiler per program (new-probe)
|
||||
mojo/local/ the Mojo of each catalog exercise, shipped in the app (new-exercise)
|
||||
mojo/stress/ programs that test core's Mojo interpreter, not shipped (new-stress): mostly realistic programs, and a few that the compiler must reject, for the checker
|
||||
mojo/golden/ godbolt's answer for each exact source, and STATUS.md, every item's verdict (mojo-verify, mojo-status)
|
||||
syntax/mojo.xml the pinned Mojo's words as a KDE syntax for Pandoc listings (mojo-emit)
|
||||
|
||||
pseudo/programs/<nn>-<name>.pseudo regression programs; their `// EXPECT:` lines are the output each must print, or a `// STOPS:` or `// ERRORS:` line says how its run must stop or how many errors the checker must report
|
||||
pseudo/prover/<name>.pseudo prover soundness regressions: `// MUST-NOT-PROVE: <kind>@<line>` or `// RUN-STOPS: <kind>@<line>`
|
||||
```
|
||||
|
||||
| Module | What it holds |
|
||||
|---|---|
|
||||
| `stats` | Mean, Variance (two-pass) |
|
||||
| `numerics` | KahanSum, LinearInterp, Trapezoid |
|
||||
| `align` | LinearGapPenalty, AffineGapPenalty, MatchScore, NeedlemanWunschScore |
|
||||
| `md` | LennardJones, LennardJonesForce, MinimumImage, PairDistance |
|
||||
| `seq` | GCContent, HammingDistance |
|
||||
| `special` | ErfApprox (Abramowitz and Stegun 7.1.26, stated error below 1.5e-7) |
|
||||
|
||||
[STATUS.md](STATUS.md) is the current state of every check.
|
||||
|
||||
## Checking it
|
||||
|
||||
From a pplus-core checkout (`git clone --recurse-submodules`; the library is its submodule `library/`), with [pixi](https://pixi.sh), which brings the pinned Mojo, Node and Python:
|
||||
|
||||
```bash
|
||||
pixi run library-check # every check of every routine; writes status.json, STATUS.md and the Dafny goldens
|
||||
pixi run library-emit # regenerate core's registry (src/library/generated.ts) from this checkout
|
||||
pixi run library-verify-mojo # ask the pinned Mojo compiler about every Mojo reference (network)
|
||||
pixi run mojo-status # judge every Mojo corpus item from the stored answers, offline; writes mojo/golden/STATUS.md
|
||||
pixi run mojo-verify # ask godbolt about every Mojo program with no stored answer yet (network)
|
||||
pixi run mojo-emit # regenerate core's src/mojo/generated/ and this repository's syntax/mojo.xml, offline
|
||||
npm test # core's tests: every program under pseudo/, and core's Mojo checker and interpreter held to godbolt's stored answers for the probes, exercise, stress, manual and Mojo Quest programs
|
||||
```
|
||||
|
||||
The Dafny proofs run only after `pixi run dafny-fetch` (once); without it their stored verdicts are compared. pplus-core's `docs/mojo-corpus.md` describes the Mojo corpus pipeline and how to move to a new Mojo version.
|
||||
|
||||
## Levels
|
||||
|
||||
A reference's level says how it differs from the plainest translation of the pseudo: `plain` computes what the pseudo computes with the language's plain operations (for PairDistance it takes one three-way `hypot`, or a square root of the sum of squares, where the pseudo nests `HYPOT`, so it carries a tolerance); other levels change the order of operations (`unrolled`, `fsum`), the method (`statistics`, `libm`, `two-rows`), or the arithmetic (`powers` against `multiply`). Each level is held to the pseudo's results exactly, or within a tolerance its `routine.json` states, and its note says why the tolerance is needed. C references run at `-O0` and `-O2`, so a difference between those two levels shows up; flags that allow reordering, such as `-ffast-math`, are not tried.
|
||||
|
||||
Read [AGENTS.md](AGENTS.md) before adding or changing a routine.
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2026 Scientific Computing Studio, LLC, under the Apache License 2.0 ([LICENSE.md](LICENSE.md)); [NOTICE.md](NOTICE.md) has the notices and a disclaimer of affiliation with Modular, and [THIRD_PARTY.md](THIRD_PARTY.md) lists what is not ours and its licenses.
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
# Security
|
||||
|
||||
pplus-library is data: routines, reference implementations, proofs, Mojo programs and stored compiler answers.
|
||||
Nothing here runs by itself, but pplus-core's checks run it: `pixi run library-check` compiles and runs every C, Python and Mojo reference implementation, and the Mojo programs, on the machine that runs the check; `pixi run mojo-verify` sends the corpus's Mojo programs to godbolt.org, and `pixi run library-verify-mojo` the Mojo references.
|
||||
Run them on a checkout you trust.
|
||||
|
||||
A routine whose contract the prover proves but a run breaks is a soundness bug and is treated like a security issue, because a program that uses the routine trusts the contract.
|
||||
A file here that makes a check of pplus-core do something other than check (write outside its working directory, reach the network outside `mojo-verify` and `library-verify-mojo`) is a security issue too.
|
||||
|
||||
Report a problem to Alex M. Maldonado at alex@scient.ing, with the routine or program that shows it and what happened.
|
||||
You will get an acknowledgment within a week.
|
||||
We promise no response time beyond that; one person maintains Programming+.
|
||||
Please do not open a public issue for a problem that could hurt someone else until a fix is out.
|
||||
|
||||
Only the latest commit on `main` gets fixes.
|
||||
@@ -0,0 +1,271 @@
|
||||
# Library status
|
||||
|
||||
<!-- Written by `pixi run library-check` in pplus-core. Do not edit. -->
|
||||
|
||||
Each routine, at each level. *pass*: checked and agrees; *open*: the prover could not finish every obligation (nothing is wrong, nothing is proved); *skipped*: the tool is not available here, or it declines the construct; *unverified*: no stored answer for this exact text yet.
|
||||
|
||||
## Sequence alignment (`align`)
|
||||
|
||||
| Routine | Cases | Prover | Fuzz | Generated Mojo | References | Proof |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `align.AffineGapPenalty` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `align.LinearGapPenalty` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `align.MatchScore` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `align.NeedlemanWunschScore` | pass | pass | pass | pass | python/plain: cpython pass<br>python/two-rows: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | · |
|
||||
|
||||
## Molecular simulation (`md`)
|
||||
|
||||
| Routine | Cases | Prover | Fuzz | Generated Mojo | References | Proof |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `md.LennardJones` | pass | pass | pass | pass | python/multiply: cpython pass<br>python/powers: cpython pass<br>c/multiply: cc -O0 pass, cc -O2 pass<br>mojo/multiply: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `md.LennardJonesForce` | pass | pass | pass | pass | python/multiply: cpython pass<br>mojo/multiply: interpreter pass, compiler pass, godbolt pass | · |
|
||||
| `md.MinimumImage` | pass | pass | pass | pass | python/plain: cpython pass<br>c/plain: cc -O0 pass, cc -O2 pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `md.PairDistance` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | · |
|
||||
|
||||
## Numerics (`numerics`)
|
||||
|
||||
| Routine | Cases | Prover | Fuzz | Generated Mojo | References | Proof |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `numerics.KahanSum` | pass | pass | pass | pass | python/plain: cpython pass<br>c/plain: cc -O0 pass, cc -O2 pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `numerics.LinearInterp` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | · |
|
||||
| `numerics.Trapezoid` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | · |
|
||||
|
||||
## Sequences (`seq`)
|
||||
|
||||
| Routine | Cases | Prover | Fuzz | Generated Mojo | References | Proof |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `seq.GCContent` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `seq.HammingDistance` | pass | pass | pass | pass | python/plain: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
|
||||
## Special functions (`special`)
|
||||
|
||||
| Routine | Cases | Prover | Fuzz | Generated Mojo | References | Proof |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `special.ErfApprox` | pass | open | pass | pass | python/plain: cpython pass<br>python/libm: cpython pass<br>mojo/plain: interpreter skipped, compiler pass, godbolt pass | · |
|
||||
|
||||
## Statistics (`stats`)
|
||||
|
||||
| Routine | Cases | Prover | Fuzz | Generated Mojo | References | Proof |
|
||||
| --- | --- | --- | --- | --- | --- | --- |
|
||||
| `stats.Mean` | pass | pass | pass | pass | python/plain: cpython pass<br>python/fsum: cpython pass<br>c/plain: cc -O0 pass, cc -O2 pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass<br>mojo/unrolled: interpreter pass, compiler pass, godbolt pass | dafny pass |
|
||||
| `stats.Variance` | pass | pass | pass | pass | python/plain: cpython pass<br>python/statistics: cpython pass<br>mojo/plain: interpreter pass, compiler pass, godbolt pass | · |
|
||||
|
||||
## Details
|
||||
|
||||
### align.AffineGapPenalty
|
||||
|
||||
- structure: pass. defines FUNCTION AffineGapPenalty
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 1 obligation(s) proved
|
||||
- fuzz: pass. no failure in 201 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 3 verified, 0 errors
|
||||
|
||||
### align.LinearGapPenalty
|
||||
|
||||
- structure: pass. defines FUNCTION LinearGapPenalty
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 1 obligation(s) proved
|
||||
- fuzz: pass. no failure in 123 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 2 verified, 0 errors
|
||||
|
||||
### align.MatchScore
|
||||
|
||||
- structure: pass. defines FUNCTION MatchScore
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 2 obligation(s) proved
|
||||
- fuzz: pass. no failure in 285 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 1 verified, 0 errors
|
||||
|
||||
### align.NeedlemanWunschScore
|
||||
|
||||
- structure: pass. defines FUNCTION NeedlemanWunschScore, using align.MatchScore, align.LinearGapPenalty
|
||||
- pseudo: pass. 4 case(s) run
|
||||
- prover: pass. all 11 obligation(s) proved
|
||||
- fuzz: pass. no failure in 300 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- python/two-rows, cpython: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 4 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 4 case(s) (exactly)
|
||||
|
||||
### md.LennardJones
|
||||
|
||||
- structure: pass. defines FUNCTION LennardJones
|
||||
- pseudo: pass. 4 case(s) run
|
||||
- prover: pass. all 2 obligation(s) proved
|
||||
- fuzz: pass. no failure in 252 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/multiply, cpython: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- python/powers, cpython: pass. agrees with the pseudo on 4 case(s) (within rel 1e-12, abs 0)
|
||||
- c/multiply, cc -O0: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- c/multiply, cc -O2: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/multiply, interpreter: pass. agrees with the pseudo on 4 case(s) in core's interpreter (exactly)
|
||||
- mojo/multiply, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/multiply, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 4 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 14 verified, 0 errors
|
||||
|
||||
### md.LennardJonesForce
|
||||
|
||||
- structure: pass. defines FUNCTION LennardJonesForce
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 3 obligation(s) proved
|
||||
- fuzz: pass. no failure in 252 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/multiply, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/multiply, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/multiply, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/multiply, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
|
||||
### md.MinimumImage
|
||||
|
||||
- structure: pass. defines FUNCTION MinimumImage
|
||||
- pseudo: pass. 6 case(s) run
|
||||
- prover: pass. all 1 obligation(s) proved
|
||||
- fuzz: pass. no failure in 241 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 6 case(s) (exactly)
|
||||
- c/plain, cc -O0: pass. agrees with the pseudo on 6 case(s) (exactly)
|
||||
- c/plain, cc -O2: pass. agrees with the pseudo on 6 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 6 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 6 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 6 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 4 verified, 0 errors
|
||||
|
||||
### md.PairDistance
|
||||
|
||||
- structure: pass. defines FUNCTION PairDistance, using md.MinimumImage
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 9 obligation(s) proved
|
||||
- fuzz: pass. no failure in 4 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints the pseudo's results to within 1.6e-16 of each value (the compiler's rounding and std.math), and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (within rel 1e-15, abs 0)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (within rel 1e-15, abs 0)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (within rel 1e-15, abs 0)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (within rel 1e-15, abs 0)
|
||||
|
||||
### numerics.KahanSum
|
||||
|
||||
- structure: pass. defines FUNCTION KahanSum
|
||||
- pseudo: pass. 4 case(s) run
|
||||
- prover: pass. all 1 obligation(s) proved
|
||||
- fuzz: pass. no failure in 263 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- c/plain, cc -O0: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- c/plain, cc -O2: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 4 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 4 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 2 verified, 0 errors
|
||||
|
||||
### numerics.LinearInterp
|
||||
|
||||
- structure: pass. defines FUNCTION LinearInterp
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 1 obligation(s) proved
|
||||
- fuzz: pass. no failure in 300 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
|
||||
### numerics.Trapezoid
|
||||
|
||||
- structure: pass. defines FUNCTION Trapezoid
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 4 obligation(s) proved
|
||||
- fuzz: pass. no failure in 227 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
|
||||
### seq.GCContent
|
||||
|
||||
- structure: pass. defines FUNCTION GCContent
|
||||
- pseudo: pass. 4 case(s) run
|
||||
- prover: pass. all 3 obligation(s) proved
|
||||
- fuzz: pass. no failure in 469 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 4 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 4 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 4 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 5 verified, 0 errors
|
||||
|
||||
### seq.HammingDistance
|
||||
|
||||
- structure: pass. defines FUNCTION HammingDistance
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 5 obligation(s) proved
|
||||
- fuzz: pass. no failure in 291 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
- proof: pass. Dafny 4.11.0: 5 verified, 0 errors
|
||||
|
||||
### special.ErfApprox
|
||||
|
||||
- structure: pass. defines FUNCTION ErfApprox
|
||||
- pseudo: pass. 7 case(s) run
|
||||
- prover: open. 0 of 1 obligation(s) proved; open: divide@15 (1.0 + 0.3275911 * A is not 0)
|
||||
- fuzz: pass. no failure in 269 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints the pseudo's results to within 5.3e-14 of each value (the compiler's rounding and std.math) (core's interpreter declines exp(...), which Mojo computes with a routine of its own that Programming+ does not reproduce digit for digit)
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 7 case(s) (exactly)
|
||||
- python/libm, cpython: pass. agrees with the pseudo on 7 case(s) (within rel 0, abs 1.5e-7)
|
||||
- mojo/plain, interpreter: skipped. core's Mojo interpreter declines exp(...), which Mojo computes with a routine of its own that Programming+ does not reproduce digit for digit
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 7 case(s) (within rel 0, abs 2e-13)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 7 case(s) (within rel 0, abs 2e-13)
|
||||
|
||||
### stats.Mean
|
||||
|
||||
- structure: pass. defines FUNCTION Mean
|
||||
- pseudo: pass. 5 case(s) run
|
||||
- prover: pass. all 2 obligation(s) proved
|
||||
- fuzz: pass. no failure in 262 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 5 case(s) (exactly)
|
||||
- python/fsum, cpython: pass. agrees with the pseudo on 5 case(s) (within rel 1e-15, abs 0)
|
||||
- c/plain, cc -O0: pass. agrees with the pseudo on 5 case(s) (exactly)
|
||||
- c/plain, cc -O2: pass. agrees with the pseudo on 5 case(s) (exactly)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 5 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 5 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 5 case(s) (exactly)
|
||||
- mojo/unrolled, interpreter: pass. agrees with the pseudo on 5 case(s) in core's interpreter (within rel 1e-15, abs 0)
|
||||
- mojo/unrolled, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 5 case(s) (within rel 1e-15, abs 0)
|
||||
- mojo/unrolled, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 5 case(s) (within rel 1e-15, abs 0)
|
||||
- proof: pass. Dafny 4.11.0: 9 verified, 0 errors
|
||||
|
||||
### stats.Variance
|
||||
|
||||
- structure: pass. defines FUNCTION Variance, using stats.Mean
|
||||
- pseudo: pass. 3 case(s) run
|
||||
- prover: pass. all 4 obligation(s) proved
|
||||
- fuzz: pass. no failure in 221 generated input(s)
|
||||
- mojo: pass. built by Mojo 1.2.0, the generated Mojo prints what the pseudo prints on every case, and in core's interpreter
|
||||
- python/plain, cpython: pass. agrees with the pseudo on 3 case(s) (exactly)
|
||||
- python/statistics, cpython: pass. agrees with the pseudo on 3 case(s) (within rel 1e-12, abs 0)
|
||||
- mojo/plain, interpreter: pass. agrees with the pseudo on 3 case(s) in core's interpreter (exactly)
|
||||
- mojo/plain, compiler: pass. built by Mojo 1.2.0, agrees with the pseudo on 3 case(s) (exactly)
|
||||
- mojo/plain, godbolt: pass. mojo_1_2_0 agrees with the pseudo on 3 case(s) (exactly)
|
||||
|
||||
Generated
+82
@@ -0,0 +1,82 @@
|
||||
# Third-party material in pplus-library
|
||||
|
||||
Generated by `python3 scripts/mojo/corpus.py emit` in pplus-core (`pixi run mojo-emit`) from `mojo/pin.json`, `mojo/mojo.lock.json` and the files under `mojo/corpus/`. Do not edit; pplus-core's `tests/third-party.test.mjs` fails while this file is out of date.
|
||||
|
||||
Everything in this repository is ours, under the Apache License 2.0 (`LICENSE.md`), except `mojo/corpus/`, which is Modular's material harvested for Mojo 1.2.0 and listed below; `mojo/licenses/`, the upstream license texts; and `mojo/golden/`, the answers Compiler Explorer (godbolt.org) returned for each program, which are the Mojo compiler's output for our programs and for the corpus. A file under `mojo/corpus/` is a test fixture: pplus-core's tests read it and the app does not ship it.
|
||||
|
||||
## Sources
|
||||
|
||||
| source | repository | commit | license the pin states | license file at that commit | copy here |
|
||||
|---|---|---|---|---|---|
|
||||
| modular | [modular/modular](https://github.com/modular/modular) | `527d069ee11a` | Apache-2.0 WITH LLVM-exception (per file headers; confirm the docs carry the same license) | `LICENSE`, checked 2026-11-12 | `mojo/licenses/modular-LICENSE.txt` |
|
||||
| mojo-quest | [modular/mojo-quest](https://github.com/modular/mojo-quest) | `8e884a709866` | Apache-2.0 WITH LLVM-exception per file headers; the repo has no LICENSE file, so confirm with Modular before showing exercises to students | none, checked 2026-11-12 | none |
|
||||
| mojo-syntax | [modular/mojo-syntax](https://github.com/modular/mojo-syntax) | `48cdeac4f6b5` | MIT | `LICENSE`, checked 2026-11-12 | `mojo/licenses/mojo-syntax-LICENSE.txt` |
|
||||
| skills | [modular/skills](https://github.com/modular/skills) | `c18d0e2b34e9` | Apache-2.0 WITH LLVM-exception | `LICENSE`, checked 2026-11-12 | `mojo/licenses/skills-LICENSE.txt` |
|
||||
| vscode-mojo | [modular/vscode-mojo](https://github.com/modular/vscode-mojo) | `e7f673213c2d` | Apache-2.0 | `LICENSE`, checked 2026-11-12 | `mojo/licenses/vscode-mojo-LICENSE.txt` |
|
||||
|
||||
What each check found:
|
||||
|
||||
- **modular**: The root LICENSE is Apache-2.0 WITH LLVM-exception for the whole repository, and the README says the repository and its contributions are under it; nothing carves out docs/. Licenses/LICENSE is the MAX Community License, which Licenses/README.md says ships with Modular's packaged products, not the repository's sources. The docs' .mdx pages carry no header of their own; docs/site/code/*.mojo carry Modular's Apache-2.0 WITH LLVM-exception header.
|
||||
- **mojo-quest**: The repository github.com/modular/mojo-quest is public and holds this commit (so the inferred name is right); at this commit it has no LICENSE, COPYING or NOTICE file; its README and package.json name no license. exercises/*.mojo carry Modular's Apache-2.0 WITH LLVM-exception header; src/data/issues.ts (the starters and the ticket text) carries none.
|
||||
- **mojo-syntax**: MIT, copyright Modular Inc., MagicStack Inc. and Microsoft Corporation. The MIT notice must go with copies of the grammar.
|
||||
- **skills**: Apache-2.0 WITH LLVM-exception (the LLVM Project's license text, verbatim). mojo-syntax/SKILL.md carries no header of its own.
|
||||
- **vscode-mojo**: Apache-2.0 (the plain license, no LLVM exception), with no NOTICE file.
|
||||
|
||||
## Harvested programs, by license header
|
||||
|
||||
Each `.mojo` file the processors wrote, with the header it carries in its first 40 lines. "Apache-2.0 WITH LLVM-exception" is Modular's header ("Copyright (c) <year>, Modular Inc. ... Licensed under the Apache License v2.0 with LLVM Exceptions").
|
||||
|
||||
| source | processor | files | with Modular's header | with another header | with no header |
|
||||
|---|---|---|---|---|---|
|
||||
| modular | diagnostics | 185 | 185 | 0 | 0 |
|
||||
| modular | manual | 206 | 175 | 0 | 31 |
|
||||
| mojo-quest | quest | 176 | 88 | 0 | 88 |
|
||||
| **all** | | **567** | **448** | **0** | **119** |
|
||||
|
||||
### Files with a header other than Modular's
|
||||
|
||||
None.
|
||||
|
||||
### Files with no license header (119)
|
||||
|
||||
These carry no header because the processor took them out of a file that has none: a manual page's program and its output (`docs/site/manual/*.mdx`), or a Mojo Quest starter (`src/data/issues.ts`). They fall under their repository's license, where it has one (see Sources).
|
||||
|
||||
- modular: `docs/site/manual/control-flow.mdx`: `manual/snippets/manual-control-flow-28.mojo`, `manual/snippets/manual-control-flow-29.mojo`, `manual/snippets/manual-control-flow-30.mojo`
|
||||
- modular: `docs/site/manual/errors.mdx`: `manual/snippets/manual-errors-1.mojo`, `manual/snippets/manual-errors-5.mojo`, `manual/snippets/manual-errors-6.mojo`, `manual/snippets/manual-errors-7.mojo`, `manual/snippets/manual-errors-8.mojo`
|
||||
- modular: `docs/site/manual/parameters/index.mdx`: `manual/snippets/manual-parameters-index-1.mojo`, `manual/snippets/manual-parameters-index-2.mojo`, `manual/snippets/manual-parameters-index-4.mojo`, `manual/snippets/manual-parameters-index-7.mojo`
|
||||
- modular: `docs/site/manual/pointers/using-pointers.mdx`: `manual/snippets/manual-pointers-using-pointers-4.mojo`
|
||||
- modular: `docs/site/manual/python/types.mdx`: `manual/snippets/manual-python-types-1.mojo`, `manual/snippets/manual-python-types-2.mojo`, `manual/snippets/manual-python-types-3.mojo`, `manual/snippets/manual-python-types-4.mojo`, `manual/snippets/manual-python-types-5.mojo`, `manual/snippets/manual-python-types-6.mojo`
|
||||
- modular: `docs/site/manual/types.mdx`: `manual/snippets/manual-types-7.mojo`
|
||||
- modular: `docs/site/manual/values/lifetimes.mdx`: `manual/snippets/manual-values-lifetimes-1.mojo`, `manual/snippets/manual-values-lifetimes-2.mojo`, `manual/snippets/manual-values-lifetimes-3.mojo`
|
||||
- modular: `docs/site/manual/values/ownership.mdx`: `manual/snippets/manual-values-ownership-1.mojo`, `manual/snippets/manual-values-ownership-2.mojo`, `manual/snippets/manual-values-ownership-3.mojo`, `manual/snippets/manual-values-ownership-4.mojo`, `manual/snippets/manual-values-ownership-5.mojo`
|
||||
- modular: `docs/site/manual/values/value-semantics.mdx`: `manual/snippets/manual-values-value-semantics-1.mojo`, `manual/snippets/manual-values-value-semantics-2.mojo`
|
||||
- modular: `docs/site/reference/decorators/parameter.mdx`: `manual/snippets/reference-decorators-parameter-1.mojo`
|
||||
- mojo-quest: `src/data/issues.ts`: `quest/starters/MQ_101.mojo`, `quest/starters/MQ_102.mojo`, `quest/starters/MQ_103.mojo`, `quest/starters/MQ_104.mojo`, `quest/starters/MQ_105.mojo`, `quest/starters/MQ_106.mojo`, `quest/starters/MQ_107.mojo`, `quest/starters/MQ_108.mojo`, `quest/starters/MQ_109.mojo`, `quest/starters/MQ_110.mojo`, `quest/starters/MQ_111.mojo`, `quest/starters/MQ_113.mojo`, `quest/starters/MQ_115.mojo`, `quest/starters/MQ_201.mojo`, `quest/starters/MQ_202.mojo`, `quest/starters/MQ_203.mojo`, `quest/starters/MQ_207.mojo`, `quest/starters/MQ_208.mojo`, `quest/starters/MQ_210.mojo`, `quest/starters/MQ_211.mojo`, `quest/starters/MQ_213.mojo`, `quest/starters/MQ_214.mojo`, `quest/starters/MQ_215.mojo`, `quest/starters/MQ_219.mojo`, `quest/starters/MQ_220.mojo`, `quest/starters/MQ_221.mojo`, `quest/starters/MQ_222.mojo`, `quest/starters/MQ_223.mojo`, `quest/starters/MQ_224.mojo`, `quest/starters/MQ_301.mojo`, `quest/starters/MQ_302.mojo`, `quest/starters/MQ_303.mojo`, `quest/starters/MQ_304.mojo`, `quest/starters/MQ_305.mojo`, `quest/starters/MQ_306.mojo`, `quest/starters/MQ_308.mojo`, `quest/starters/MQ_309.mojo`, `quest/starters/MQ_310.mojo`, `quest/starters/MQ_312.mojo`, `quest/starters/MQ_320.mojo`, `quest/starters/MQ_321.mojo`, `quest/starters/MQ_322.mojo`, `quest/starters/MQ_323.mojo`, `quest/starters/MQ_324.mojo`, `quest/starters/MQ_325.mojo`, `quest/starters/MQ_326.mojo`, `quest/starters/MQ_327.mojo`, `quest/starters/MQ_328.mojo`, `quest/starters/MQ_401.mojo`, `quest/starters/MQ_402.mojo`, `quest/starters/MQ_403.mojo`, `quest/starters/MQ_412.mojo`, `quest/starters/MQ_501.mojo`, `quest/starters/MQ_502.mojo`, `quest/starters/MQ_503.mojo`, `quest/starters/MQ_504.mojo`, `quest/starters/MQ_505.mojo`, `quest/starters/MQ_507.mojo`, `quest/starters/MQ_508.mojo`, `quest/starters/MQ_510.mojo`, `quest/starters/MQ_511.mojo`, `quest/starters/MQ_512.mojo`, `quest/starters/MQ_513.mojo`, `quest/starters/MQ_520.mojo`, `quest/starters/MQ_601.mojo`, `quest/starters/MQ_602.mojo`, `quest/starters/MQ_604.mojo`, `quest/starters/MQ_702.mojo`, `quest/starters/MQ_703.mojo`, `quest/starters/MQ_704.mojo`, `quest/starters/MQ_705.mojo`, `quest/starters/MQ_706.mojo`, `quest/starters/MQ_710.mojo`, `quest/starters/MQ_801.mojo`, `quest/starters/MQ_803.mojo`, `quest/starters/MQ_810.mojo`, `quest/starters/MQ_812.mojo`, `quest/starters/MQ_825.mojo`, `quest/starters/MQ_827.mojo`, `quest/starters/MQ_830.mojo`, `quest/starters/MQ_835.mojo`, `quest/starters/MQ_845.mojo`, `quest/starters/MQ_852.mojo`, `quest/starters/MQ_858.mojo`, `quest/starters/MQ_901.mojo`, `quest/starters/MQ_903.mojo`, `quest/starters/MQ_950.mojo`, `quest/starters/MQ_951.mojo`
|
||||
|
||||
## Data files
|
||||
|
||||
Files a processor derived from upstream files: lists of words, names, messages and test cases, in JSON. None can carry a header; each comes from the source and inputs named here.
|
||||
|
||||
| file | source | made from | what it holds |
|
||||
|---|---|---|---|
|
||||
| `mojo/corpus/SOURCES.md` | ours | the harvest itself | what came from where, and what each processor found |
|
||||
| `mojo/corpus/diagnostics/manifest.json` | modular | test | The compiler's own diagnostic tests: what it rejects, where, and in what words |
|
||||
| `mojo/corpus/editor/editor.json` | vscode-mojo | language-configuration.json, package.json | How an editor should treat Mojo, from the official VS Code extension |
|
||||
| `mojo/corpus/manual/manifest.json` | modular | docs/site/code, docs/site/manual | The Mojo Manual: its tested code samples, and its program/output pairs |
|
||||
| `mojo/corpus/messages/messages.json` | modular | lib/MojoParser | The compiler's diagnostic wording, and the fixes it offers, from its source |
|
||||
| `mojo/corpus/quest/manifest.json` | mojo-quest | src/data/issues.ts, exercises | Mojo Quest: 85 tickets, each a completed solution and a broken starter |
|
||||
| `mojo/corpus/release/release.json` | modular | docs/site/releases | Release notes for the pinned version, and whether the snapshot matches the pin |
|
||||
| `mojo/corpus/report.json` | ours | the harvest itself | what came from where, and what each processor found |
|
||||
| `mojo/corpus/skill/removed-syntax.json` | skills | mojo-syntax/SKILL.md | Modular's mojo-syntax skill: its table of removed syntax and replacements |
|
||||
| `mojo/corpus/stdindex/stdindex.json` | modular | stdlib/std | Which standard-library package exports each public name |
|
||||
| `mojo/corpus/stdtypes/stdtypes.json` | modular | stdlib/std | The standard library's structs and traits, as far as a checker needs them |
|
||||
| `mojo/corpus/syntax/cases.json` | mojo-syntax | tests, syntaxes/mojo.syntax.json | The Mojo TextMate grammar's tests, as plain highlighting cases |
|
||||
| `mojo/corpus/syntax/mojo.syntax.json` | mojo-syntax | syntaxes/mojo.syntax.json | The TextMate grammar itself, parsed and written back as JSON |
|
||||
| `mojo/corpus/tokens/tokens.json` | modular | include/Mojo/MojoParser/TokenKinds.def, lib/MojoParser | The words of the language, from the compiler and the stdlib themselves |
|
||||
|
||||
## Notices
|
||||
|
||||
- The files from modular/modular and modular/skills are Copyright (c) Modular Inc. and are distributed under the Apache License v2.0 with LLVM Exceptions (`mojo/licenses/modular-LICENSE.txt`, `mojo/licenses/skills-LICENSE.txt`); those from modular/vscode-mojo under the Apache License 2.0 (`mojo/licenses/vscode-mojo-LICENSE.txt`). Nothing was changed, except that a manual snippet was cut out of the page that holds it and a data file was derived as the table above says.
|
||||
- The files from modular/mojo-quest are Modular's. Its solutions carry Modular's Apache-2.0 WITH LLVM-exception header; the repository has no license file, and its starters and ticket text come from a module with no header (see Sources).
|
||||
- `mojo/corpus/syntax/mojo.syntax.json` is the TextMate grammar of modular/mojo-syntax, under the MIT license whose notice is `mojo/licenses/mojo-syntax-LICENSE.txt`.
|
||||
- "Mojo" and "Modular" are trademarks of Modular Inc. This project is not affiliated with or endorsed by Modular.
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "5a0a04933596877e8f881204d2508c4fd6f4fc5a37aa4d0a0dce95ac4da45730",
|
||||
"verdict": "verified",
|
||||
"summary": "3 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "9310c57a1b1128544f150ac943ea5d5efd387150ba0e55de119d84398627df70",
|
||||
"stdin": "3 1 -10 -1 5 -10 -1 3 -2 -2 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "-10\n-14\n-6",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
method AffineGapPenalty(length: int, open: int, extend: int) returns (result: int)
|
||||
requires length >= 1
|
||||
ensures result == open + (length - 1) * extend
|
||||
{
|
||||
result := open + (length - 1) * extend;
|
||||
}
|
||||
|
||||
// Position by position: the first position opens the gap, every later one extends it.
|
||||
method AffineByPositions(length: int, open: int, extend: int) returns (score: int)
|
||||
requires length >= 1
|
||||
ensures score == open + (length - 1) * extend
|
||||
{
|
||||
score := open;
|
||||
var i := 1;
|
||||
while i < length
|
||||
invariant 1 <= i <= length
|
||||
invariant score == open + (i - 1) * extend
|
||||
{
|
||||
score := score + extend;
|
||||
i := i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// With the same score for opening and extending, the affine model is the linear one.
|
||||
lemma AffineIsLinearWhenEqual(length: int, gap: int)
|
||||
requires length >= 1
|
||||
ensures gap + (length - 1) * gap == length * gap
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
def affine_gap_penalty(length: Int, open_: Int, extend: Int) -> Int:
|
||||
return open_ + (length - 1) * extend
|
||||
@@ -0,0 +1,2 @@
|
||||
def affine_gap_penalty(length, open_, extend):
|
||||
return open_ + (length - 1) * extend
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "AffineGapPenalty",
|
||||
"summary": "The score of a gap of Length positions when opening a gap scores Open and each further position scores Extend.",
|
||||
"tags": [
|
||||
"alignment",
|
||||
"gap model"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Gotoh, An improved algorithm for matching biological sequences, J. Mol. Biol. 162 (1982)",
|
||||
"url": "https://doi.org/10.1016/0022-2836(82)90398-9"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "AffineGapPenalty(1, -10, -1)"
|
||||
},
|
||||
{
|
||||
"call": "AffineGapPenalty(5, -10, -1)"
|
||||
},
|
||||
{
|
||||
"call": "AffineGapPenalty(3, -2, -2)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same formula."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same formula in Mojo."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/affine_gap.dfy",
|
||||
"note": "The formula equals the score built position by position, and with Open == Extend it equals the linear model."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// AffineGapPenalty: the score of a gap of Length positions under an affine
|
||||
// gap model (Gotoh, 1982): Open for the first position and Extend for each
|
||||
// one after it. When Open is more negative than Extend, one long gap scores
|
||||
// better than several short gaps of the same total length. With
|
||||
// Open == Extend it is the linear model.
|
||||
FUNCTION AffineGapPenalty(Length : INTEGER, Open : INTEGER, Extend : INTEGER) RETURNS INTEGER
|
||||
REQUIRE Length >= 1
|
||||
ENSURE RESULT == Open + (Length - 1) * Extend
|
||||
RETURN Open + (Length - 1) * Extend
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "1d61017b086bed77518f358dcbbc0fd011139347f77beb2d39479d9db7edb2de",
|
||||
"verdict": "verified",
|
||||
"summary": "2 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "8810a7c99a71768e1a9c7c26fb37cc87bdb3d6affd03dee8b2abaa35f44482e1",
|
||||
"stdin": "3 3 -2 0 -2 10 -1 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "-6\n0\n-10",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// A gap of `length` positions under a linear model: each position scores `gap`.
|
||||
method LinearGapPenalty(length: int, gap: int) returns (result: int)
|
||||
requires length >= 0
|
||||
ensures result == length * gap
|
||||
{
|
||||
result := length * gap;
|
||||
}
|
||||
|
||||
// The same score, built one position at a time: the product is the model, not a shortcut.
|
||||
method LinearGapByPositions(length: int, gap: int) returns (score: int)
|
||||
requires length >= 0
|
||||
ensures score == length * gap
|
||||
{
|
||||
score := 0;
|
||||
var i := 0;
|
||||
while i < length
|
||||
invariant 0 <= i <= length
|
||||
invariant score == i * gap
|
||||
{
|
||||
score := score + gap;
|
||||
i := i + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
def linear_gap_penalty(length: Int, gap: Int) -> Int:
|
||||
return length * gap
|
||||
@@ -0,0 +1,2 @@
|
||||
def linear_gap_penalty(length, gap):
|
||||
return length * gap
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "LinearGapPenalty",
|
||||
"summary": "The score of a gap of Length positions when every position of a gap scores Gap.",
|
||||
"tags": [
|
||||
"alignment",
|
||||
"gap model"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Durbin, Eddy, Krogh and Mitchison, Biological Sequence Analysis (Cambridge, 1998), chapter 2, Pairwise alignment",
|
||||
"url": "https://doi.org/10.1017/CBO9780511790492.003"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "LinearGapPenalty(3, -2)"
|
||||
},
|
||||
{
|
||||
"call": "LinearGapPenalty(0, -2)"
|
||||
},
|
||||
{
|
||||
"call": "LinearGapPenalty(10, -1)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same product."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same product in Mojo."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/linear_gap.dfy",
|
||||
"note": "The product equals the score built position by position: each of the Length positions adds Gap."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// LinearGapPenalty: the score of a gap of Length positions under a linear gap
|
||||
// model, where every position of a gap scores Gap (usually negative).
|
||||
FUNCTION LinearGapPenalty(Length : INTEGER, Gap : INTEGER) RETURNS INTEGER
|
||||
REQUIRE Length >= 0
|
||||
ENSURE RESULT == Length * Gap
|
||||
RETURN Length * Gap
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "374ce6664efd8802bb90e120a1107375c0ab607c9829987b26d73d5f5fd4b009",
|
||||
"verdict": "verified",
|
||||
"summary": "1 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "b0a5473abe88ee1d6bee716670978df110ceabab60ef98b9789ec3b7ae16f512",
|
||||
"stdin": "3 A A 1 -1 A G 1 -1 T T 5 -4 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "1\n-1\n5",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
method MatchScore(a: char, b: char, match_: int, mismatch: int) returns (r: int)
|
||||
ensures (a == b && r == match_) || (a != b && r == mismatch)
|
||||
{
|
||||
if a == b { r := match_; } else { r := mismatch; }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
def match_score(a: String, b: String, match_: Int, mismatch: Int) -> Int:
|
||||
if a == b:
|
||||
return match_
|
||||
return mismatch
|
||||
@@ -0,0 +1,2 @@
|
||||
def match_score(a, b, match, mismatch):
|
||||
return match if a == b else mismatch
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "MatchScore",
|
||||
"summary": "The score of aligning letter A with letter B: Match when they are the same, Mismatch otherwise.",
|
||||
"tags": [
|
||||
"alignment",
|
||||
"scoring"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Durbin, Eddy, Krogh and Mitchison, Biological Sequence Analysis (Cambridge, 1998), chapter 2, Pairwise alignment",
|
||||
"url": "https://doi.org/10.1017/CBO9780511790492.003"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "MatchScore('A', 'A', 1, -1)"
|
||||
},
|
||||
{
|
||||
"call": "MatchScore('A', 'G', 1, -1)"
|
||||
},
|
||||
{
|
||||
"call": "MatchScore('T', 'T', 5, -4)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same test."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same test in Mojo; a letter is a String of one character."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/match_score.dfy",
|
||||
"note": "The score is Match exactly when the letters agree."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// MatchScore: the score of aligning letter A with letter B: Match when they
|
||||
// are the same letter, Mismatch otherwise. The simplest substitution score;
|
||||
// a substitution matrix such as BLOSUM62 replaces it for proteins.
|
||||
FUNCTION MatchScore(A : CHAR, B : CHAR, Match : INTEGER, Mismatch : INTEGER) RETURNS INTEGER
|
||||
ENSURE (A == B AND RESULT == Match) OR (A != B AND RESULT == Mismatch)
|
||||
IF A == B THEN
|
||||
RETURN Match
|
||||
ENDIF
|
||||
RETURN Mismatch
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "align",
|
||||
"title": "Sequence alignment",
|
||||
"summary": "Scores for aligning two sequences: gap models, letter scores, and global alignment by dynamic programming."
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "cd659ffc727fffe9b7493b2f77e9e37e758ad6ff36e9afb122a10d29cb5aae57",
|
||||
"stdin": "4 GATTACA GCATGCU 1 -1 -1 ACGT ACGT 1 -1 -2 ACG 1 -1 -2 AAAA TTTT 2 -3 -1 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "<source>:7:13: warning: ref 'j' was never used, remove it?\n for j in range(m + 1):\n ^\n<source>:5:9: warning: ref 'i' was never used, remove it?\n for i in range(n + 1):\n ^",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "0\n4\n-6\n-8",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
def needleman_wunsch_score(s: String, t: String, match_: Int, mismatch: Int, gap: Int) -> Int:
|
||||
var n = s.count_codepoints()
|
||||
var m = t.count_codepoints()
|
||||
var d = List[List[Int]]()
|
||||
for i in range(n + 1):
|
||||
var row = List[Int]()
|
||||
for j in range(m + 1):
|
||||
row.append(0)
|
||||
d.append(row^)
|
||||
for i in range(n + 1):
|
||||
d[i][0] = i * gap
|
||||
for j in range(1, m + 1):
|
||||
d[0][j] = j * gap
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, m + 1):
|
||||
var score = mismatch
|
||||
if String(s[codepoint=i - 1]) == String(t[codepoint=j - 1]):
|
||||
score = match_
|
||||
var best = d[i - 1][j - 1] + score
|
||||
if d[i - 1][j] + gap > best:
|
||||
best = d[i - 1][j] + gap
|
||||
if d[i][j - 1] + gap > best:
|
||||
best = d[i][j - 1] + gap
|
||||
d[i][j] = best
|
||||
return d[n][m]
|
||||
@@ -0,0 +1,12 @@
|
||||
def needleman_wunsch_score(s, t, match, mismatch, gap):
|
||||
n, m = len(s), len(t)
|
||||
d = [[0] * (m + 1) for _ in range(n + 1)]
|
||||
for i in range(n + 1):
|
||||
d[i][0] = i * gap
|
||||
for j in range(1, m + 1):
|
||||
d[0][j] = j * gap
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, m + 1):
|
||||
diagonal = d[i - 1][j - 1] + (match if s[i - 1] == t[j - 1] else mismatch)
|
||||
d[i][j] = max(diagonal, d[i - 1][j] + gap, d[i][j - 1] + gap)
|
||||
return d[n][m]
|
||||
@@ -0,0 +1,10 @@
|
||||
def needleman_wunsch_score(s, t, match, mismatch, gap):
|
||||
m = len(t)
|
||||
prev = [j * gap for j in range(m + 1)]
|
||||
for i in range(1, len(s) + 1):
|
||||
cur = [i * gap] + [0] * m
|
||||
for j in range(1, m + 1):
|
||||
diagonal = prev[j - 1] + (match if s[i - 1] == t[j - 1] else mismatch)
|
||||
cur[j] = max(diagonal, prev[j] + gap, cur[j - 1] + gap)
|
||||
prev = cur
|
||||
return prev[m]
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "NeedlemanWunschScore",
|
||||
"summary": "The best score of a global alignment of two sequences with a linear gap model, by dynamic programming.",
|
||||
"tags": [
|
||||
"alignment",
|
||||
"dynamic programming"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Needleman and Wunsch, A general method applicable to the search for similarities in the amino acid sequence of two proteins, J. Mol. Biol. 48 (1970)",
|
||||
"url": "https://doi.org/10.1016/0022-2836(70)90057-4"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "NeedlemanWunschScore(\"GATTACA\", \"GCATGCU\", 1, -1, -1)"
|
||||
},
|
||||
{
|
||||
"call": "NeedlemanWunschScore(\"ACGT\", \"ACGT\", 1, -1, -2)"
|
||||
},
|
||||
{
|
||||
"call": "NeedlemanWunschScore(\"\", \"ACG\", 1, -1, -2)"
|
||||
},
|
||||
{
|
||||
"call": "NeedlemanWunschScore(\"AAAA\", \"TTTT\", 2, -3, -1)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same table, filled row by row."
|
||||
},
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "two-rows",
|
||||
"file": "ref/python/two-rows.py",
|
||||
"note": "Only the previous row is kept: memory grows with the length of T alone, the first step toward Hirschberg's linear-space alignment."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same table in Mojo, as a list of rows."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// NeedlemanWunschScore: the best score of a global alignment of S and T
|
||||
// (Needleman and Wunsch, 1970) with a linear gap model, by dynamic
|
||||
// programming. D[I, J] is the best score of aligning the first I letters of
|
||||
// S with the first J letters of T; each cell takes the best of three moves:
|
||||
// align S[I - 1] with T[J - 1], or put a gap in one sequence or the other.
|
||||
USE align.MatchScore
|
||||
USE align.LinearGapPenalty
|
||||
FUNCTION NeedlemanWunschScore(S : STRING, T : STRING, Match : INTEGER, Mismatch : INTEGER, Gap : INTEGER) RETURNS INTEGER
|
||||
DECLARE N : INTEGER <- LENGTH(S)
|
||||
DECLARE M : INTEGER <- LENGTH(T)
|
||||
DECLARE D : ARRAY[N + 1, M + 1] OF INTEGER
|
||||
FOR I <- 0 TO N + 1
|
||||
D[I, 0] <- LinearGapPenalty(I, Gap)
|
||||
NEXT I
|
||||
FOR J <- 1 TO M + 1
|
||||
D[0, J] <- LinearGapPenalty(J, Gap)
|
||||
NEXT J
|
||||
FOR I <- 1 TO N + 1
|
||||
FOR J <- 1 TO M + 1
|
||||
DECLARE Diagonal : INTEGER <- D[I - 1, J - 1] + MatchScore(S[I - 1], T[J - 1], Match, Mismatch)
|
||||
DECLARE Down : INTEGER <- D[I - 1, J] + Gap
|
||||
DECLARE Across : INTEGER <- D[I, J - 1] + Gap
|
||||
D[I, J] <- MAX(Diagonal, Down, Across)
|
||||
NEXT J
|
||||
NEXT I
|
||||
RETURN D[N, M]
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "6cc9da2b05065bbfb293aa17dd81dbbc91e091f91f5af3a878b944b17686bfda",
|
||||
"stdin": "3 1 0 1 0 1 0 78986244726619 -46 1 0 1 0 5 -1 535928355657089 -51 7656119366529843 -51 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "24.0\n-2.3738310467722616e-15\n168.49822326347663",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
def lennard_jones_force(r: Float64, epsilon: Float64, sigma: Float64) -> Float64:
|
||||
var s2 = (sigma / r) * (sigma / r)
|
||||
var s6 = s2 * s2 * s2
|
||||
return 24.0 * epsilon * (2.0 * s6 * s6 - s6) / r
|
||||
@@ -0,0 +1,4 @@
|
||||
def lennard_jones_force(r, epsilon, sigma):
|
||||
s2 = (sigma / r) * (sigma / r)
|
||||
s6 = s2 * s2 * s2
|
||||
return 24.0 * epsilon * (2.0 * s6 * s6 - s6) / r
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "LennardJonesForce",
|
||||
"summary": "The force between two particles at distance R under the Lennard-Jones potential: positive pushes them apart.",
|
||||
"tags": [
|
||||
"molecular dynamics",
|
||||
"force"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Allen and Tildesley, Computer Simulation of Liquids, 2nd edition (Oxford, 2017), section 1.3.2, Atomic systems: the potential whose derivative this is"
|
||||
},
|
||||
{
|
||||
"title": "Lennard-Jones, Cohesion, Proc. Phys. Soc. 43 (1931): the 12-6 form",
|
||||
"url": "https://doi.org/10.1088/0959-5309/43/5/301"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "LennardJonesForce(1.0, 1.0, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "LennardJonesForce(1.122462048309373, 1.0, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "LennardJonesForce(2.5, 0.238, 3.4)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "multiply",
|
||||
"file": "ref/python/multiply.py",
|
||||
"note": "The same multiplications."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "multiply",
|
||||
"file": "ref/mojo/multiply.mojo",
|
||||
"note": "The same multiplications in Mojo."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// LennardJonesForce: the force between two particles at distance R under
|
||||
// the Lennard-Jones potential, F(R) = -dV/dR
|
||||
// = 24 Epsilon / R (2 (Sigma / R)^12 - (Sigma / R)^6).
|
||||
// Positive pushes the particles apart; it is 0 at the bottom of the well.
|
||||
FUNCTION LennardJonesForce(R : FLOAT, Epsilon : FLOAT, Sigma : FLOAT) RETURNS FLOAT
|
||||
REQUIRE R > 0.0
|
||||
DECLARE S2 : FLOAT <- (Sigma / R) * (Sigma / R)
|
||||
DECLARE S6 : FLOAT <- S2 * S2 * S2
|
||||
RETURN 24.0 * Epsilon * (2.0 * S6 * S6 - S6) / R
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "0dc08be0ccc13bef1bbad5bc4fa8efc54c39005c803c770a79fec941913ffb86",
|
||||
"verdict": "verified",
|
||||
"summary": "14 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "b82a068dc7a6e6f2af826f55f6ccb5f3493c7b236f1ab8ae80686ac71db93861",
|
||||
"stdin": "4 1 0 1 0 1 0 78986244726619 -46 1 0 1 0 5 -1 535928355657089 -51 7656119366529843 -51 8106479329266893 -53 1 0 1 0 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "0.0\n-1.0\n32.09189752256677\n6.6361189532529234",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
function Pow(x: real, n: nat): real
|
||||
{
|
||||
if n == 0 then 1.0 else x * Pow(x, n - 1)
|
||||
}
|
||||
|
||||
function LJ(r: real, epsilon: real, sigma: real): real
|
||||
requires r > 0.0
|
||||
{
|
||||
4.0 * epsilon * (Pow(sigma / r, 12) - Pow(sigma / r, 6))
|
||||
}
|
||||
|
||||
lemma PowAdd(x: real, a: nat, b: nat)
|
||||
ensures Pow(x, a + b) == Pow(x, a) * Pow(x, b)
|
||||
{
|
||||
if a > 0 {
|
||||
PowAdd(x, a - 1, b);
|
||||
assert Pow(x, a + b) == x * Pow(x, a - 1 + b);
|
||||
}
|
||||
}
|
||||
|
||||
lemma Pow2(x: real)
|
||||
ensures Pow(x, 2) == x * x
|
||||
{
|
||||
assert Pow(x, 1) == x;
|
||||
}
|
||||
|
||||
lemma Pow6(s: real)
|
||||
ensures Pow(s, 6) == (s * s) * (s * s) * (s * s)
|
||||
{
|
||||
Pow2(s);
|
||||
PowAdd(s, 2, 2);
|
||||
PowAdd(s, 4, 2);
|
||||
}
|
||||
|
||||
lemma Pow12(s: real)
|
||||
ensures Pow(s, 12) == Pow(s, 6) * Pow(s, 6)
|
||||
{
|
||||
PowAdd(s, 6, 6);
|
||||
}
|
||||
|
||||
method LennardJones(r: real, epsilon: real, sigma: real) returns (v: real)
|
||||
requires r > 0.0
|
||||
ensures v == LJ(r, epsilon, sigma)
|
||||
{
|
||||
var s := sigma / r;
|
||||
var s2 := s * s;
|
||||
var s6 := s2 * s2 * s2;
|
||||
Pow6(s);
|
||||
Pow12(s);
|
||||
v := 4.0 * epsilon * (s6 * s6 - s6);
|
||||
}
|
||||
|
||||
// The potential crosses zero at R = Sigma.
|
||||
lemma ZeroAtSigma(epsilon: real, sigma: real)
|
||||
requires sigma > 0.0
|
||||
ensures LJ(sigma, epsilon, sigma) == 0.0
|
||||
{
|
||||
assert sigma / sigma == 1.0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
double lennard_jones(double r, double epsilon, double sigma) {
|
||||
double s2 = (sigma / r) * (sigma / r);
|
||||
double s6 = s2 * s2 * s2;
|
||||
return 4.0 * epsilon * (s6 * s6 - s6);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
def lennard_jones(r: Float64, epsilon: Float64, sigma: Float64) -> Float64:
|
||||
var s2 = (sigma / r) * (sigma / r)
|
||||
var s6 = s2 * s2 * s2
|
||||
return 4.0 * epsilon * (s6 * s6 - s6)
|
||||
@@ -0,0 +1,4 @@
|
||||
def lennard_jones(r, epsilon, sigma):
|
||||
s2 = (sigma / r) * (sigma / r)
|
||||
s6 = s2 * s2 * s2
|
||||
return 4.0 * epsilon * (s6 * s6 - s6)
|
||||
@@ -0,0 +1,2 @@
|
||||
def lennard_jones(r, epsilon, sigma):
|
||||
return 4.0 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6)
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "LennardJones",
|
||||
"summary": "The Lennard-Jones pair potential at distance R, with well depth Epsilon and zero-crossing distance Sigma.",
|
||||
"tags": [
|
||||
"molecular dynamics",
|
||||
"pair potential"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Jones, On the determination of molecular fields. II. From the equation of state of a gas, Proc. R. Soc. A 106 (1924)",
|
||||
"url": "https://doi.org/10.1098/rspa.1924.0082"
|
||||
},
|
||||
{
|
||||
"title": "Lennard-Jones, Cohesion, Proc. Phys. Soc. 43 (1931): the 12-6 form",
|
||||
"url": "https://doi.org/10.1088/0959-5309/43/5/301"
|
||||
},
|
||||
{
|
||||
"title": "Allen and Tildesley, Computer Simulation of Liquids, 2nd edition (Oxford, 2017), section 1.3.2, Atomic systems"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "LennardJones(1.0, 1.0, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "LennardJones(1.122462048309373, 1.0, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "LennardJones(2.5, 0.238, 3.4)"
|
||||
},
|
||||
{
|
||||
"call": "LennardJones(0.9, 1.0, 1.0)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "multiply",
|
||||
"file": "ref/python/multiply.py",
|
||||
"note": "The same multiplications."
|
||||
},
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "powers",
|
||||
"file": "ref/python/powers.py",
|
||||
"note": "The textbook formula with ** 12 and ** 6: the same function, rounded differently, held to agree to 12 digits on these cases. Near R = Sigma, where V is close to 0, the two roundings differ by far more relative to V (1.9e-8 at R = 1.000000001, Sigma = 1).",
|
||||
"rel": 1e-12
|
||||
},
|
||||
{
|
||||
"lang": "c",
|
||||
"level": "multiply",
|
||||
"file": "ref/c/multiply.c",
|
||||
"note": "The same multiplications in C."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "multiply",
|
||||
"file": "ref/mojo/multiply.mojo",
|
||||
"note": "The same multiplications in Mojo."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/lennard_jones.dfy",
|
||||
"note": "Over real numbers the multiplications compute the textbook formula exactly, and V(Sigma) = 0."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// LennardJones: the Lennard-Jones pair potential at distance R,
|
||||
// V(R) = 4 Epsilon ((Sigma / R)^12 - (Sigma / R)^6). Epsilon is the depth of
|
||||
// the well, reached at R = 2^(1/6) Sigma, and V is 0 at R = Sigma. The powers
|
||||
// are built by multiplication from (Sigma / R)^2, as simulation codes do,
|
||||
// instead of ^, which rounds a little differently.
|
||||
FUNCTION LennardJones(R : FLOAT, Epsilon : FLOAT, Sigma : FLOAT) RETURNS FLOAT
|
||||
REQUIRE R > 0.0
|
||||
DECLARE S2 : FLOAT <- (Sigma / R) * (Sigma / R)
|
||||
DECLARE S6 : FLOAT <- S2 * S2 * S2
|
||||
RETURN 4.0 * Epsilon * (S6 * S6 - S6)
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "9881217a957b2d8700997063d9bda129337d7c266a287aeb76a0881a1b0b1b08",
|
||||
"verdict": "verified",
|
||||
"summary": "4 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "b4edcbbb2f76c79b75d2ac0a4516169fb6ea5ca14441a401b656f9291c2f5f7c",
|
||||
"stdin": "6 3 -2 1 0 -3 -2 1 0 2589569785738035 -50 1 0 1 -1 1 0 -3 2 5 1 3039929748475085 -51 3602879701896397 -55 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "-0.25\n0.25\n0.2999999999999998\n-0.5\n-2.0\n-0.050000000000000044",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// MinimumImage, over real numbers: the image lies in [-box / 2, box / 2) and is a whole number of box lengths from dx.
|
||||
lemma ScaledBounds(g: real, box: real)
|
||||
requires box > 0.0
|
||||
requires -0.5 <= g < 0.5
|
||||
ensures -box / 2.0 <= g * box < box / 2.0
|
||||
{
|
||||
assert (g + 0.5) * box >= 0.0;
|
||||
assert (0.5 - g) * box > 0.0;
|
||||
}
|
||||
|
||||
method MinimumImage(dx: real, box: real) returns (r: real, k: int)
|
||||
requires box > 0.0
|
||||
ensures r == dx - box * (k as real)
|
||||
ensures -box / 2.0 <= r < box / 2.0
|
||||
{
|
||||
var q := dx / box + 0.5;
|
||||
k := q.Floor;
|
||||
assert (k as real) <= q < (k as real) + 1.0;
|
||||
var g := q - (k as real) - 0.5;
|
||||
assert -0.5 <= g < 0.5;
|
||||
assert dx == (q - 0.5) * box;
|
||||
r := dx - box * (k as real);
|
||||
assert r == g * box;
|
||||
ScaledBounds(g, box);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <math.h>
|
||||
|
||||
double minimum_image(double dx, double box) {
|
||||
return dx - box * floor(dx / box + 0.5);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
from std.math import floor
|
||||
|
||||
|
||||
def minimum_image(dx: Float64, box: Float64) -> Float64:
|
||||
return dx - box * floor(dx / box + 0.5)
|
||||
@@ -0,0 +1,5 @@
|
||||
import math
|
||||
|
||||
|
||||
def minimum_image(dx, box):
|
||||
return dx - box * math.floor(dx / box + 0.5)
|
||||
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "MinimumImage",
|
||||
"summary": "A displacement brought to its nearest periodic image in a box of length Box: the minimum image convention. Over real numbers the result lies in [-Box / 2, Box / 2); in FLOAT arithmetic it can land a rounding error outside that range.",
|
||||
"tags": [
|
||||
"molecular dynamics",
|
||||
"periodic boundary conditions"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Allen and Tildesley, Computer Simulation of Liquids, 2nd edition (Oxford, 2017), sections 1.6.2, Periodic boundary conditions, and 1.6.3, Potential truncation: the minimum image convention"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "MinimumImage(0.75, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "MinimumImage(-0.75, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "MinimumImage(2.3, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "MinimumImage(0.5, 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "MinimumImage(-12.0, 10.0)"
|
||||
},
|
||||
{
|
||||
"call": "MinimumImage(1.35, 0.1)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same formula with math.floor."
|
||||
},
|
||||
{
|
||||
"lang": "c",
|
||||
"level": "plain",
|
||||
"file": "ref/c/plain.c",
|
||||
"note": "The same formula with floor from math.h."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same formula in Mojo, with floor from std.math."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/minimum_image.dfy",
|
||||
"note": "Over real numbers the result lies in [-Box / 2, Box / 2) and differs from Dx by a whole number of box lengths."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// MinimumImage: the displacement Dx brought to its nearest periodic image in
|
||||
// a box of length Box, the minimum image convention: Dx minus the whole
|
||||
// number of box lengths that brings it into [-Box / 2, Box / 2). FLOOR of
|
||||
// Dx / Box + 0.5 rounds halves upward, so exactly half a box maps to -Box / 2.
|
||||
// That range holds over exact numbers (the Dafny proof). In FLOAT arithmetic
|
||||
// Dx / Box and the product are rounded, so the result can land a rounding
|
||||
// error outside it (MinimumImage(1.35, 0.1) is -0.050000000000000044), and
|
||||
// within a rounding error of half a box it can give the farther of the two
|
||||
// closest images (MinimumImage(0.49999999999999994, 1.0) is -0.5).
|
||||
FUNCTION MinimumImage(Dx : FLOAT, Box : FLOAT) RETURNS FLOAT
|
||||
REQUIRE Box > 0.0
|
||||
RETURN Dx - Box * FLOOR(Dx / Box + 0.5)
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "md",
|
||||
"title": "Molecular simulation",
|
||||
"summary": "Pair potentials, forces and periodic boxes, the inner loop of molecular dynamics."
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "a5c8003d3ef4f2bb00c3ec5bc2ae11fe1965c991acfcfc9f4e4df759c3c3f7d6",
|
||||
"stdin": "3 3 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3 8106479329266893 -53 8106479329266893 -53 8106479329266893 -53 1 0 3 0 0 0 0 0 0 3 3 0 1 2 0 0 5 2 3 1 0 1 1 3 0 3 1 0 1 1 3 0 5 0 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "0.34641016151377535\n5.0\n0.0",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
from std.math import floor, sqrt
|
||||
|
||||
|
||||
def pair_distance(a: List[Float64], b: List[Float64], box: Float64) -> Float64:
|
||||
var total: Float64 = 0.0
|
||||
for i in range(3):
|
||||
var d = a[i] - b[i]
|
||||
d = d - box * floor(d / box + 0.5)
|
||||
total = total + d * d
|
||||
return sqrt(total)
|
||||
@@ -0,0 +1,7 @@
|
||||
import math
|
||||
|
||||
|
||||
def pair_distance(a, b, box):
|
||||
d = [x - y for x, y in zip(a, b)]
|
||||
d = [v - box * math.floor(v / box + 0.5) for v in d]
|
||||
return math.hypot(*d)
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "PairDistance",
|
||||
"summary": "The distance between two points in a cubic periodic box, each coordinate difference taken by the minimum image convention.",
|
||||
"tags": [
|
||||
"molecular dynamics",
|
||||
"periodic boundary conditions"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Allen and Tildesley, Computer Simulation of Liquids, 2nd edition (Oxford, 2017), sections 1.6.2, Periodic boundary conditions, and 1.6.3, Potential truncation: the minimum image convention"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "PairDistance([0.1, 0.1, 0.1], [0.9, 0.9, 0.9], 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "PairDistance([0.0, 0.0, 0.0], [3.0, 4.0, 0.0], 20.0)"
|
||||
},
|
||||
{
|
||||
"call": "PairDistance([1.0, 2.0, 3.0], [1.0, 2.0, 3.0], 5.0)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same steps, with math.hypot of all three differences at once.",
|
||||
"rel": 1e-15
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same steps in Mojo, with the square root of the sum of squares.",
|
||||
"rel": 1e-15
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// PairDistance: the distance between two points in a cubic periodic box of
|
||||
// side Box, each coordinate difference taken by the minimum image
|
||||
// convention. HYPOT adds the squares without overflowing on the way.
|
||||
USE md.MinimumImage
|
||||
FUNCTION PairDistance(A : LIST OF FLOAT, B : LIST OF FLOAT, Box : FLOAT) RETURNS FLOAT
|
||||
REQUIRE LENGTH(A) == 3 AND LENGTH(B) == 3 AND Box > 0.0
|
||||
DECLARE Dx : FLOAT <- MinimumImage(A[0] - B[0], Box)
|
||||
DECLARE Dy : FLOAT <- MinimumImage(A[1] - B[1], Box)
|
||||
DECLARE Dz : FLOAT <- MinimumImage(A[2] - B[2], Box)
|
||||
RETURN HYPOT(HYPOT(Dx, Dy), Dz)
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "c4ce4ea3415a128e81393b13176e9cbf9f1266c14e2fe3d7588dacdc38cf259a",
|
||||
"verdict": "verified",
|
||||
"summary": "2 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "cbbcc76b6b043a613dc6983512073400b8b622127210bae94c5ea7011b5ddce3",
|
||||
"stdin": "4 3 1 0 1 1 3 0 11 1 0 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 2028240960365167 -104 10 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 3602879701896397 -55 0 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "6.0\n1.000000000000001\n1.0\n0.0",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
function Sum(x: seq<real>): real
|
||||
{
|
||||
if |x| == 0 then 0.0 else Sum(x[..|x| - 1]) + x[|x| - 1]
|
||||
}
|
||||
|
||||
// In exact arithmetic Kahan summation is the plain sum, and its compensation is always 0.
|
||||
method KahanSum(x: seq<real>) returns (total: real)
|
||||
ensures total == Sum(x)
|
||||
{
|
||||
total := 0.0;
|
||||
var c := 0.0;
|
||||
var i := 0;
|
||||
while i < |x|
|
||||
invariant 0 <= i <= |x|
|
||||
invariant total == Sum(x[..i])
|
||||
invariant c == 0.0
|
||||
{
|
||||
assert x[..i + 1][..i] == x[..i];
|
||||
var y := x[i] - c;
|
||||
var t := total + y;
|
||||
c := (t - total) - y;
|
||||
total := t;
|
||||
i := i + 1;
|
||||
}
|
||||
assert x[..|x|] == x;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
double kahan_sum(const double *x, long n) {
|
||||
double total = 0.0, c = 0.0;
|
||||
for (long i = 0; i < n; i++) {
|
||||
double y = x[i] - c;
|
||||
double t = total + y;
|
||||
c = (t - total) - y;
|
||||
total = t;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
def kahan_sum(x: List[Float64]) -> Float64:
|
||||
var total: Float64 = 0.0
|
||||
var c: Float64 = 0.0
|
||||
for i in range(len(x)):
|
||||
var y = x[i] - c
|
||||
var t = total + y
|
||||
c = (t - total) - y
|
||||
total = t
|
||||
return total
|
||||
@@ -0,0 +1,9 @@
|
||||
def kahan_sum(x):
|
||||
total = 0.0
|
||||
c = 0.0
|
||||
for v in x:
|
||||
y = v - c
|
||||
t = total + y
|
||||
c = (t - total) - y
|
||||
total = t
|
||||
return total
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "KahanSum",
|
||||
"summary": "The sum of a list of FLOAT values by compensated summation, whose error bound, to first order, does not grow with the length of the list.",
|
||||
"tags": [
|
||||
"summation",
|
||||
"rounding",
|
||||
"precision"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Kahan, Pracniques: further remarks on reducing truncation errors, CACM 8(1), 1965",
|
||||
"url": "https://doi.org/10.1145/363707.363723"
|
||||
},
|
||||
{
|
||||
"title": "Higham, Accuracy and Stability of Numerical Algorithms, 2nd edition (SIAM, 2002), section 4.3, Compensated summation"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "KahanSum([1.0, 2.0, 3.0])"
|
||||
},
|
||||
{
|
||||
"call": "KahanSum([1.0, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16])"
|
||||
},
|
||||
{
|
||||
"call": "KahanSum([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1])"
|
||||
},
|
||||
{
|
||||
"call": "KahanSum([])"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same compensated loop."
|
||||
},
|
||||
{
|
||||
"lang": "c",
|
||||
"level": "plain",
|
||||
"file": "ref/c/plain.c",
|
||||
"note": "The same loop in C. It survives -O2; it would not survive -ffast-math, which lets the compiler treat (t - total) - y as 0."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same loop in Mojo."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/kahan_sum.dfy",
|
||||
"note": "Over real numbers the compensation C stays 0 and the result is exactly the sum: what Kahan summation corrects is rounding, and nothing else."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// KahanSum: the sum of a list of FLOAT values by compensated summation
|
||||
// (Kahan, 1965). C holds the low-order part the last addition lost, and the
|
||||
// next addition puts it back, so the error bound, about twice the unit
|
||||
// roundoff times the sum of the absolute values (Higham, section 4.3), does
|
||||
// not grow with the length of the list, to first order. It is relative to
|
||||
// that sum of absolute values, not to the result: KahanSum([1.0e100, 1.0,
|
||||
// -1.0e100]) is 0.0. In exact arithmetic C is always 0 and this is the
|
||||
// plain sum: the compensation exists only because of rounding. A compiler
|
||||
// allowed to reorder FLOAT arithmetic (-ffast-math) can simplify C away.
|
||||
FUNCTION KahanSum(X : LIST OF FLOAT) RETURNS FLOAT
|
||||
DECLARE Total : FLOAT <- 0.0
|
||||
DECLARE C : FLOAT <- 0.0
|
||||
FOR I <- 0 TO LENGTH(X)
|
||||
DECLARE Y : FLOAT <- X[I] - C
|
||||
DECLARE T : FLOAT <- Total + Y
|
||||
C <- (T - Total) - Y
|
||||
Total <- T
|
||||
NEXT I
|
||||
RETURN Total
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "37a9981a11db40badf3c1515fa7e52d8ddcf0e062131d08b253320ec3a0f8289",
|
||||
"stdin": "3 0 0 0 0 5 1 5 0 1 2 1 0 1 1 3 0 1 1 5 -1 0 0 1 0 1 0 3 0 1 1 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "2.0\n2.0\n5.0",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
def linear_interp(x0: Float64, y0: Float64, x1: Float64, y1: Float64, x: Float64) -> Float64:
|
||||
return y0 + (y1 - y0) * (x - x0) / (x1 - x0)
|
||||
@@ -0,0 +1,2 @@
|
||||
def linear_interp(x0, y0, x1, y1, x):
|
||||
return y0 + (y1 - y0) * (x - x0) / (x1 - x0)
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "LinearInterp",
|
||||
"summary": "The value at X on the straight line through (X0, Y0) and (X1, Y1).",
|
||||
"tags": [
|
||||
"interpolation"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "NIST Digital Library of Mathematical Functions, section 3.3(ii), linear interpolation (equation 3.3.14)",
|
||||
"url": "https://dlmf.nist.gov/3.3.ii"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "LinearInterp(0.0, 0.0, 10.0, 5.0, 4.0)"
|
||||
},
|
||||
{
|
||||
"call": "LinearInterp(1.0, 2.0, 3.0, 2.0, 2.5)"
|
||||
},
|
||||
{
|
||||
"call": "LinearInterp(0.0, 1.0, 1.0, 3.0, 2.0)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same formula."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same formula in Mojo."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// LinearInterp: the value at X on the straight line through (X0, Y0) and
|
||||
// (X1, Y1). X may lie outside [X0, X1]: that is extrapolation, and the line
|
||||
// carries on. The REQUIRE names the difference the division divides by.
|
||||
FUNCTION LinearInterp(X0 : FLOAT, Y0 : FLOAT, X1 : FLOAT, Y1 : FLOAT, X : FLOAT) RETURNS FLOAT
|
||||
REQUIRE X1 - X0 != 0.0
|
||||
RETURN Y0 + (Y1 - Y0) * (X - X0) / (X1 - X0)
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "numerics",
|
||||
"title": "Numerics",
|
||||
"summary": "Summing, interpolating and integrating with FLOAT values, and, for summing, what rounding does."
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "64af3a830bfe088770c17b6dab589a5944de61b88d95d11c9670da169931c145",
|
||||
"stdin": "3 5 0 0 1 0 1 2 9 0 1 4 1 0 2 1 0 1 0 1 -1 3 0 0 1 -2 1 0 1 -1 end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "22.0\n0.5\n0.375",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
def trapezoid(y: List[Float64], h: Float64) -> Float64:
|
||||
var total: Float64 = (y[0] + y[len(y) - 1]) / 2.0
|
||||
for i in range(1, len(y) - 1):
|
||||
total = total + y[i]
|
||||
return total * h
|
||||
@@ -0,0 +1,5 @@
|
||||
def trapezoid(y, h):
|
||||
total = (y[0] + y[len(y) - 1]) / 2.0
|
||||
for i in range(1, len(y) - 1):
|
||||
total += y[i]
|
||||
return total * h
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "Trapezoid",
|
||||
"summary": "The integral of samples Y taken H apart, by the trapezoidal rule.",
|
||||
"tags": [
|
||||
"integration",
|
||||
"quadrature"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "NIST Digital Library of Mathematical Functions, section 3.5(i), the composite trapezoidal rule (equation 3.5.2)",
|
||||
"url": "https://dlmf.nist.gov/3.5.i"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "Trapezoid([0.0, 1.0, 4.0, 9.0, 16.0], 1.0)"
|
||||
},
|
||||
{
|
||||
"call": "Trapezoid([1.0, 1.0], 0.5)"
|
||||
},
|
||||
{
|
||||
"call": "Trapezoid([0.0, 0.25, 1.0], 0.5)"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same sums."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same sums in Mojo."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Trapezoid: the integral of samples Y taken H apart, by the composite
|
||||
// trapezoidal rule: the ends count half, every inside sample counts whole.
|
||||
// The error shrinks with H^2 for a smooth function.
|
||||
FUNCTION Trapezoid(Y : LIST OF FLOAT, H : FLOAT) RETURNS FLOAT
|
||||
REQUIRE LENGTH(Y) >= 2
|
||||
DECLARE Total : FLOAT <- (Y[0] + Y[LENGTH(Y) - 1]) / 2.0
|
||||
FOR I <- 1 TO LENGTH(Y) - 1
|
||||
Total <- Total + Y[I]
|
||||
NEXT I
|
||||
RETURN Total * H
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "f2c5d94943f4b176c99c71e1073bb1c6a8ec6d2eb560d03526aaa3476b9162b1",
|
||||
"verdict": "verified",
|
||||
"summary": "5 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "7e77f8af8921526ffde69bdb25bbf4b308866ab0477b7f440a4702475c301f5b",
|
||||
"stdin": "4 GATTACA GGCC ATAT GCNa end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "0.2857142857142857\n1.0\n0.0\n0.5",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
function GC(s: string, n: nat): nat
|
||||
requires n <= |s|
|
||||
{
|
||||
if n == 0 then 0 else GC(s, n - 1) + (if s[n - 1] == 'G' || s[n - 1] == 'C' then 1 else 0)
|
||||
}
|
||||
|
||||
lemma GCAtMost(s: string, n: nat)
|
||||
requires n <= |s|
|
||||
ensures GC(s, n) <= n
|
||||
{
|
||||
if n > 0 { GCAtMost(s, n - 1); }
|
||||
}
|
||||
|
||||
method GCContent(s: string) returns (f: real)
|
||||
requires |s| > 0
|
||||
ensures f == (GC(s, |s|) as real) / (|s| as real)
|
||||
ensures 0.0 <= f <= 1.0
|
||||
{
|
||||
var count := 0;
|
||||
var i := 0;
|
||||
while i < |s|
|
||||
invariant 0 <= i <= |s|
|
||||
invariant count == GC(s, i)
|
||||
{
|
||||
if s[i] == 'G' || s[i] == 'C' { count := count + 1; }
|
||||
i := i + 1;
|
||||
}
|
||||
GCAtMost(s, |s|);
|
||||
f := (count as real) / (|s| as real);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
def gc_content(s: String) -> Float64:
|
||||
var count = 0
|
||||
for i in range(s.count_codepoints()):
|
||||
var c = String(s[codepoint=i])
|
||||
if c == "G" or c == "C":
|
||||
count = count + 1
|
||||
return Float64(count) / Float64(s.count_codepoints())
|
||||
@@ -0,0 +1,6 @@
|
||||
def gc_content(s):
|
||||
count = 0
|
||||
for c in s:
|
||||
if c == "G" or c == "C":
|
||||
count += 1
|
||||
return count / len(s)
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "GCContent",
|
||||
"summary": "The fraction of the letters of a sequence that are G or C.",
|
||||
"tags": [
|
||||
"sequences",
|
||||
"counting"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"title": "Biopython, Bio.SeqUtils.gc_fraction: the G+C fraction of a sequence. Biopython also counts S and lowercase letters and, by default, leaves ambiguous letters out of the length; this routine counts only G and C and every letter in the length",
|
||||
"url": "https://biopython.org/docs/latest/api/Bio.SeqUtils.html#Bio.SeqUtils.gc_fraction"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
{
|
||||
"call": "GCContent(\"GATTACA\")"
|
||||
},
|
||||
{
|
||||
"call": "GCContent(\"GGCC\")"
|
||||
},
|
||||
{
|
||||
"call": "GCContent(\"ATAT\")"
|
||||
},
|
||||
{
|
||||
"call": "GCContent(\"GCNa\")"
|
||||
}
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"lang": "python",
|
||||
"level": "plain",
|
||||
"file": "ref/python/plain.py",
|
||||
"note": "The same count."
|
||||
},
|
||||
{
|
||||
"lang": "mojo",
|
||||
"level": "plain",
|
||||
"file": "ref/mojo/plain.mojo",
|
||||
"note": "The same count in Mojo."
|
||||
}
|
||||
],
|
||||
"proof": {
|
||||
"lang": "dafny",
|
||||
"file": "proof/gc_content.dfy",
|
||||
"note": "The count never exceeds the length, so the fraction lies in [0, 1]."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// GCContent: the fraction of the letters of S that are G or C. Other letters
|
||||
// (N for an unknown base, lowercase) count in the length and not in the count.
|
||||
FUNCTION GCContent(S : STRING) RETURNS FLOAT
|
||||
REQUIRE LENGTH(S) > 0
|
||||
DECLARE Count : INTEGER <- 0
|
||||
FOR I <- 0 TO LENGTH(S)
|
||||
IF S[I] == 'G' OR S[I] == 'C' THEN
|
||||
Count <- Count + 1
|
||||
ENDIF
|
||||
NEXT I
|
||||
RETURN Count / LENGTH(S)
|
||||
ENDFUNCTION
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"tool": "dafny",
|
||||
"version": "4.11.0",
|
||||
"flags": [
|
||||
"verify",
|
||||
"--resource-limit",
|
||||
"20000000"
|
||||
],
|
||||
"source_sha256": "0a1be187ee17e37bf36220aa4c326a907dd0e39eb38710cd77ed05bed2479950",
|
||||
"verdict": "verified",
|
||||
"summary": "5 verified, 0 errors"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"tool": "godbolt",
|
||||
"compiler": "mojo_1_2_0",
|
||||
"mojoVersion": "1.2.0",
|
||||
"source_sha256": "540ef6240c38a85fa0f31305ee9679f7dd0bcbe91da1c5cecd57a2b1c82b4e35",
|
||||
"stdin": "3 GATTACA GACTATA AAAA TTTT end\n",
|
||||
"args": "--target-cpu x86-64-v3 --fp-mode contract=off",
|
||||
"asked": "2026-11-12",
|
||||
"result": {
|
||||
"compiled": true,
|
||||
"buildStderr": "",
|
||||
"executed": true,
|
||||
"exitCode": 0,
|
||||
"stdout": "2\n0\n4",
|
||||
"stderr": "",
|
||||
"timedOut": false,
|
||||
"asm": null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
function Mismatches(s: string, t: string, n: nat): nat
|
||||
requires n <= |s| && n <= |t|
|
||||
{
|
||||
if n == 0 then 0 else Mismatches(s, t, n - 1) + (if s[n - 1] != t[n - 1] then 1 else 0)
|
||||
}
|
||||
|
||||
lemma MismatchesAtMost(s: string, t: string, n: nat)
|
||||
requires n <= |s| && n <= |t|
|
||||
ensures Mismatches(s, t, n) <= n
|
||||
{
|
||||
if n > 0 { MismatchesAtMost(s, t, n - 1); }
|
||||
}
|
||||
|
||||
method HammingDistance(s: string, t: string) returns (count: int)
|
||||
requires |s| == |t|
|
||||
ensures count == Mismatches(s, t, |s|)
|
||||
ensures 0 <= count <= |s|
|
||||
{
|
||||
count := 0;
|
||||
var i := 0;
|
||||
while i < |s|
|
||||
invariant 0 <= i <= |s|
|
||||
invariant count == Mismatches(s, t, i)
|
||||
{
|
||||
if s[i] != t[i] { count := count + 1; }
|
||||
i := i + 1;
|
||||
}
|
||||
MismatchesAtMost(s, t, |s|);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
def hamming_distance(s: String, t: String) -> Int:
|
||||
var count = 0
|
||||
for i in range(s.count_codepoints()):
|
||||
if String(s[codepoint=i]) != String(t[codepoint=i]):
|
||||
count = count + 1
|
||||
return count
|
||||
Loaded 100 of 1591 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user