Giter Site home page Giter Site logo

gabriel-fallen / lets-prove-leftpad Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hwayne/lets-prove-leftpad

0.0 0.0 0.0 474 KB

Proving leftpad correct in a dozen different ways

License: Other

Python 3.62% C 2.96% Java 1.50% Common Lisp 13.04% Haskell 6.03% Tcl 0.42% Ada 2.68% Rust 2.22% Standard ML 5.99% Coq 4.43% Agda 1.98% Idris 1.12% SystemVerilog 18.48% Isabelle 10.84% Lean 8.70% SMT 4.86% TLA 7.37% F* 1.19% Dafny 2.57%

lets-prove-leftpad's Introduction

Let's Prove Leftpad

This is a repository of provably-correct versions of Leftpad. You can read more about the project's motivations and history here.

What is "provably-correct"?

Provably correct code is code that you can totally guarantee does what you say it does. You do this by providing a proof that a computer can check. If the proof is wrong, the code won't compile.

Compare to something like testing: even if you test your function for 1,000 different inputs, you still don't know for sure that the 1,001st test will pass. With a proof, though, you know your function will work for all inputs, regardless of whether you try a thousand or ten trillion different test cases. Proving code correct is really, really powerful. It's also mindbogglingly hard, which is why most programmers don't do it.

This is a sampler of all the different tools we can use to prove code correct, standardized by all being proofs for Leftpad.

What is "leftpad"?

Leftpad is a function that takes a character, a length, and a string, and pads the string to that length. It pads it by adding the character to the left. So it's adding padding on the left. Leftpad.

>> leftpad('!', 5, "foo")
!!foo
>> leftpad('!', 0, "foo")
foo

Why are we proving leftpad?

Because it's funny.

And because leftpad is a great demo for different proof techniques. The idea is simple, the implementation is simple, but the specification (what you actually, formally want it to do) is surprisingly tricky. Specifically, you need to prove things for it to be leftpad:

  1. The length of the output is max(n, len(str))
  2. The prefix of the output is padding characters and nothing but padding characters
  3. The suffix of the output is the original string.

A proof of leftpad is going to be small enough to be (mostly) grokkable by Formal Methods outsiders, while being complex enough to differentiate the ways we prove code correct.

I want to contribute!

We'd love to have you! Please read the contribution guidelines, and then submit your favorite proofs!

Plug

If you want to learn more about formal methods, I shout at clouds on my website and on bluesky.

lets-prove-leftpad's People

Contributors

07151129 avatar 17451k avatar alperaltuntas avatar davecturner avatar ezrakilty avatar gabriel-fallen avatar gallais avatar graydon avatar hako avatar hwayne avatar icecream17 avatar kanigsson avatar kini avatar louy2 avatar mpu avatar muenchnerkindl avatar porglezomp avatar pron avatar ranjitjhala avatar reedoei avatar shapr avatar suhr avatar tirix avatar tjoppen avatar valpackett avatar vthriller avatar waldyrious avatar wilfred avatar will62794 avatar zac-hd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.