hwayne / lets-prove-leftpad Goto Github PK
View Code? Open in Web Editor NEWProving leftpad correct two-dozen different ways
License: Other
Proving leftpad correct two-dozen different ways
License: Other
It's because it uses a lemma from the Lean4 std (nat.sub_add_eq_max
) but the online prover is running Lean3
An example of using refinement types and dependent types to write a padded string in ATS described below:
http://blog.vmchale.com/article/practical-ats
More about ATS: https://en.wikipedia.org/wiki/ATS_(programming_language)
Hi! Thanks very much for this repo & your write-up, I really enjoy them.
Would a Cryptol version be welcome? Here's a first attempt at one:
module leftpad where
leftpad: {pad, in, out}
(fin pad, fin in, fin out, pad >= in, out == max pad in) =>
Char -> String in -> String out
leftpad c s = repeat`{pad - in} c # s
leftpadLength: {pad, in, out}
(fin pad, fin in, fin out, pad >= in, out == max pad in) =>
Char -> String in -> Bit
property leftpadLength c s = length (leftpad`{pad, in, out}c s) == `out
leftpadPrefix: {pad, in, out}
(fin pad, fin in, fin out, pad >= in, out == max pad in) =>
Char -> String in -> Bit
property leftpadPrefix c s = take`{pad - in}(leftpad`{pad, in, out}c s) == repeat`{pad - in}c
leftpadSuffix: {pad, in, out}
(fin pad, fin in, fin out, pad >= in, out == max pad in) =>
Char -> String in -> Bit
property leftpadSuffix c s = drop`{pad - in}(leftpad`{pad, in, out}c s) == s
Though the cryptol
REPL can prove things via the :prove
command, it "cannot directly prove polymorphic properties as they may hold for certain monomorphic instances while not for others." For instance,
┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻
┃ ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃
┗━╸╹┗╸ ╹ ╹ ╹ ┗━┛┗━╸
version 2.13.0
https://cryptol.net :? for help
Loading module Cryptol
Cryptol> :l leftpad.cry
Loading module Cryptol
Loading module leftpad
leftpad> :prove leftpadLength
Not a monomorphic type:
{pad, in, out}
(fin pad, fin in, fin out, pad >= in, out == max pad in) =>
[8] -> [in][8] -> Bit
(Total Elapsed Time: 0.000s)
leftpad> :prove leftpadLength`{10,3,10}
Q.E.D.
(Total Elapsed Time: 0.019s, using "Z3")
This can be nice in some respects; for instance, :prove leftpadLength`{10,3,0}
throws an error about the unsolvable constraint 0 == 10
. That said, I'm not sure needing explicitly specify pad
, in
, and out
yourself fulfills the spirit of this challenge.
Thanks again!
I found this repository incredibly interesting.
I think it would be very informative to extract some kind of naive summary statistics (e.g. LOC) to understand the compromises between different proof systems.
As an old user of Spec#, Dafny's precursor, I was pleasantly surprised to see how well Dafny and other systems (e.g. Lean, Agda, F*, Coq/SSReflect or Idris) compare to Isabelle or Liquid Haskell.
I proved leftpad in rust, using creusot: https://github.com/suhr/leftpad
How to verify:
cargo creusot --span-mode=absolute -- --features=contracts
«creusot repo»/ide target/debug/leftpad-rlib.mlcfg
NB: you need to apply “Split VC” on the leftpad VC to avoid CVC5 timeout.
Creusot is a research software, so I'm not sure if I should make a PR yet.
I'll add more as I run into them
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.