• This repository has been archived on 25/Apr/2022
  • Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language Idris
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a theorem prover for intuitionistic propositional logic in Idris, with metaprogramming features

Hezarfen

An Idris implementation of a theorem prover for Roy Dyckhoff's LJT, a sequent calculus for propositional intuitionistic logic that is decidable and does not need loop checking. Initially ported from Ayberk Tosun's Standard ML implementation.

The main goal of the project is to make use of the elaborator reflection. Similar to Lennart Augustsson's Djinn, a theorem prover that generates Haskell expressions, Hezarfen generates Idris expressions. Unlike Djinn, Hezarfen is not a standalone program, it is a library that generates Idris expressions of the type Raw, one of the types used for the inner representation of the core language of Idris. This means these expressions can easily be spliced into your programs. Hezarfen provides a tactic that lets you do this:

f2 : (a -> b) -> (b -> c) -> (c -> d) -> a -> d
f2 = %runElab hezarfenExpr

However, instead of creating proof terms, you can also create definitions that are more readable when you print their definitions.

f2 : (a -> b) -> (b -> c) -> (c -> d) -> a -> d
%runElab (hezarfen `{f2})

Or with the more readable syntax extension:

demorgan3 : Either (Not p) (Not q) -> Not (p, q)
derive demorgan3

contrapositive : (p -> q) -> (Not q -> Not p)
derive contrapositive

It can also make use of your existing lemmas:

evenOrOdd : (n : Nat) -> Either (Even n) (Odd n)
... -- some definition of an existing lemma

oddOrEven : (n : Nat) -> Either (Odd n) (Even n)
%runElab (hezarfen' `{oddOrEven} !(add [`{evenOrOdd}]))

-- something more complex, but passing the constructors for Even and Odd
-- using the more readable syntax
evenOrOddSS : (n : Nat) -> Either (Even (S (S n))) (Odd (S (S n)))
obtain evenOrOddSS from [`{evenOrOdd}, `{EvenSS}, `{OddSS}]

We also have a Coq-style hint database system that lets us keep a list of hint names that will be used to prove theorems. To use the hints in proofs, change derive to derive' and obtain to obtain'. Then the names in the hint database will be automatically added to the context in which the theorem prover runs.

hint evenOrOdd
hint EvenSS
hint OddSS

evenOrOddSS : (n : Nat) -> Either (Even (S (S n))) (Odd (S (S n)))
derive' evenOrOddSS

The even/odd example is beyond the logic Hezarfen is trying to decide. Even n and Even (S (S n)) happen to be one function away, namely EvenSS.

Hezarfen attempts to prove a tiny bit more than propositional intuitionistic logic, especially when it comes to equalities and Dec. Even though this part is a bit ad hoc, it can currently prove things of this nature:

eqDec : x = y -> Dec (y = x)
derive eqDec

decCongB : x = y -> Dec (not x = not y)
derive decCongB

For details, look at Examples.idr.

Edit-Time Tactics

The original purpose of Hezarfen was to be a part of a master's thesis on "edit-time tactics", meaning that we would be able to run it from the editor. Then it would be an alternative to the built-in proof search in Idris. Here is the draft of the thesis. And below you can see how it works in the editor:

Screencast of how Hezarfen works in Emacs

The feature that allows this has not landed on the Idris compiler or the Idris mode yet, but it should be merged soon!

Future Work

Some support for deriving terms with type classes can be implemented, à la Djinn.

One of the end goals of Hezarfen is to generate proofs that are easy to read:

  • Fresh variable names should be readable. Currently there is a hacky fresh function in Prover.idr that does that.
  • There is already some work on simplifying the proof terms generated by Hezarfen. There are some tricks Hezarfen can learn from Haskell's pointfree package. (web version)
  • Currently Hezarfen primarily generates expressions as proofs. However when we are writing functions, we often use function definitions instead of lambda terms, and we pattern match on pairs in the function definition, instead of writing let a = fst p in let b = snd p in ... or case p of (x, y) => ... to do projections. There is some work on translating these proof terms to readable function definitions.

The definition it generates looks like this:

> :printdef contrapositive
contrapositive : (p -> q) -> Not q -> Not p
contrapositive c d = void . d . c

As opposed to proof term:

contrapositive : (p -> q) -> Not q -> Not p
contrapositive = \i20, j20 => void . j20 . i20

hezarfen (/hezaɾfæn/, sounds like "has are fan") is a Turkish word that means polymath, literally "a thousand sciences".

More Repositories

1

zor-yoldan-haskell

Turkish translation of Learn Haskell Fast and Hard by Yann Esposito.
153
star
2

latex-unicoder.vim

A plugin to type Unicode chars in Vim, using their LaTeX names.
Vim Script
85
star
3

vim-starter

Quick starter kit for Vim beginners.
Vim Script
66
star
4

Divan.hs

Ottoman Divan poetry vezin checker in Haskell!
Haskell
38
star
5

WangsAlgorithm

A classical propositional theorem prover in Haskell, using Wang's Algorithm.
Haskell
35
star
6

type.systems

joke page until I decide what to do with this domain name
HTML
35
star
7

turkish-deasciifier.vim

Vim plugin to use emres/turkish-deasciifier
Vim Script
19
star
8

dilacar

A rule-based machine translation system from Ottoman Turkish to Modern Turkish.
TeX
18
star
9

virtual-piano

Terminal based virtual piano in Haskell, with ncurses and Euterpea
Haskell
16
star
10

proof-tree-builder

A web-based graphical proof assistant for LK and Hoare logic.
JavaScript
14
star
11

fuzzy

Fuzzy string search in Haskell
Haskell
14
star
12

Guguk

Turkish NLP library in Haskell.
Haskell
13
star
13

direct-reflection-for-free

using Data and Typeable to get a direct reflection system for free, when we're implementing a toy language in Haskell
TeX
13
star
14

regexp-agda

Agda
10
star
15

distributed-hash-table

A Haskell implementation of distributed hash tables with two-phase commit.
Haskell
10
star
16

modal

Compilation of modal logic based functional language ML5 to JavaScript.
Agda
9
star
17

edit-time-tactics

Documents (TeX, slides, poster etc.) for my master's thesis, titled "Edit-Time Tactics in Idris", and the TyDe '18 paper, titled "Extensible Type-Directed Editing"
TeX
9
star
18

dilim

A structure editor for a simple functional programming language, with Vim-like shortcuts and commands.
Rust
8
star
19

metaprogrammable-editor

Documents (TeX, slides etc.) and code for the editor side metaprogramming in Coq.
TeX
7
star
20

twitter-timeline-scraper

Scraper for Twitter embedded timelines.
JavaScript
6
star
21

turkish-deasciifier.hs

Haskell port of Deniz Yuret's Turkish deasciifier.
Haskell
6
star
22

idris-microKanren

Simple microKanren implementation in Idris.
Idris
5
star
23

thesis-modal

TeX files of my thesis
TeX
4
star
24

herbrand-prolog

A pseudo-Prolog that tries to answer queries by building the least Herbrand model.
Haskell
4
star
25

civ

Civilization-like game in Haskell.
Haskell
2
star
26

foma.hs

Simple Haskell bindings for Foma.
Haskell
2
star
27

vimrc

my vim settings / plugins
Vim Script
2
star
28

connection-booster

Class project for COS561 with Prof. Jennifer Rexford: a Chrome app that calculates the optimal number of TCP parallel connections for maximum performance and loads in parallel.
JavaScript
2
star
29

matrix-challenge

Simple matrix determinant calculator in different programming languages
Swift
1
star
30

node-youtube2mp3

Node.js replica of YouTube to MP3 web apps.
JavaScript
1
star