Skip to content

new proof terms #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
680176a
wip wip
c-cube Jan 15, 2025
a9fbe83
wip
c-cube Feb 21, 2025
c0c912f
wip: proof rules
c-cube Mar 4, 2025
3f63cf0
json spec
c-cube Mar 4, 2025
d5872c2
proof gen: generate recursive sum types for proofs
c-cube Mar 4, 2025
edf3e5e
detail
c-cube Mar 4, 2025
8c073eb
small change
c-cube Mar 5, 2025
2cd0bc7
wip
c-cube Mar 5, 2025
5874c24
proof: basic proof writer
c-cube Mar 6, 2025
3c540f9
add reader
c-cube Mar 6, 2025
f2b57fc
format
c-cube Mar 6, 2025
ce817df
fix: avoid new dep on iostream
c-cube Mar 6, 2025
c320147
feat cir: details for typereg
c-cube Mar 10, 2025
78a37fe
feat proof3: more proof writer helpers
c-cube Mar 10, 2025
7e2af62
update python+rust
c-cube Mar 10, 2025
9228454
make scope a generated type
c-cube Mar 10, 2025
aea4253
refactor
c-cube Mar 10, 2025
25c9b64
no offset for scope
c-cube Mar 10, 2025
cadbf08
scope enter takes an argumetn
c-cube Mar 10, 2025
7c42846
modify entrypoint
c-cube Mar 10, 2025
6302302
tweak
c-cube Mar 10, 2025
b34200b
feat proof: add iter functions
c-cube Mar 10, 2025
6ffa895
fix proof3: require mir state in decoder
c-cube Mar 10, 2025
7affdcc
better printer for offset_for
c-cube Mar 10, 2025
c2d578d
use hex plz
c-cube Mar 10, 2025
ab1ee56
wip: proof3
c-cube Mar 10, 2025
82ebb29
wip
c-cube Mar 10, 2025
71519fc
much work on proof3 with Christoph
c-cube Mar 11, 2025
90aad4f
CI
c-cube Mar 11, 2025
e7abadd
format
c-cube Mar 11, 2025
a1fe357
cool ur jets with doc
c-cube Mar 11, 2025
8d9e596
more CI
c-cube Mar 11, 2025
a9373dd
add a deep proof step that refers to another file
c-cube Mar 11, 2025
e742d20
Add proof3 in_channel reader
wintersteiger Mar 14, 2025
3a9baca
Fix typos
wintersteiger Mar 20, 2025
c21689c
proof3: use json5 for spec, add more doc
c-cube May 12, 2025
8defc91
feat proof3: use yojson5 to read spec file with richer docstrings
c-cube May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- id: 'dune-fmt'
name: 'dune build @fmt'
run: |-
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/bffc22eb12172e6db3c5dde9e3e5628f8e3e7912.tar.gz dep/format.nix --command "make check-format DUNE=dune"
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/bffc22eb12172e6db3c5dde9e3e5628f8e3e7912.tar.gz dep/format.nix --command "make check-format DUNE=dune DUNE_OPTS='--ignore-promoted-rules'"
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
imandrakit
imandrakit-log
imandrakit-io
(yojson-five :with-build)
(pbrt
(>= 3.0))
(pbrt_yojson
Expand Down
1 change: 1 addition & 0 deletions imandrax-api.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ depends: [
"imandrakit"
"imandrakit-log"
"imandrakit-io"
"yojson-five" {with-build}
"pbrt" {>= "3.0"}
"pbrt_yojson" {>= "3.0"}
"ocaml-protoc" {>= "3.1.1" & with-dev-setup}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/cir/typed_symbol.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include Imandrax_api_common.Typed_symbol

type t = Type.t t_poly [@@deriving twine, typereg, eq, ord, show]
type t = Type.t Imandrax_api_common.Typed_symbol.t_poly
[@@deriving twine, typereg, eq, ord, show]
(** A value with its type schema *)

let pp_ = ref pp
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cir/var.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include Imandrax_api_common.Var

type t = Type.t t_poly [@@deriving twine, typereg, show]
type t = Type.t Imandrax_api_common.Var.t_poly [@@deriving twine, typereg, show]

open Imandrax_api

Expand Down
5 changes: 5 additions & 0 deletions src/lib/genbindings/gen_python.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ from . import twine

__all__ = ['twine']

# offset in file
type OffsetFor[T] = int

type Error = Error_Error_core
def twine_result[T,E](d: twine.Decoder, off: int, d0: Callable[...,T], d1: Callable[...,E]) -> T | E:
match d.get_cstor(off=off):
Expand Down Expand Up @@ -122,6 +125,8 @@ let rec gen_type_expr (ty : tyexpr) : string =
spf "%s | %s" (gen_type_expr x) (gen_type_expr y)
| "Imandrakit_error__Error_core.Data.t", [] -> spf "unit"
| "option", [ x ] -> spf "None | %s" (gen_type_expr x)
| "Imandrakit_twine.offset_for", [ x ] ->
spf "OffsetFor[%s]" (gen_type_expr x)
| "Util_twine_.With_tag7.t", [ x ] -> spf "WithTag7[%s]" (gen_type_expr x)
| "Util_twine_.Q.t", [] -> "tuple[int, int]"
| s, [] -> mangle_ty_name s
Expand Down
1 change: 1 addition & 0 deletions src/lib/genbindings/resolve_ty_defs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let names_to_exclude : Str_set.t =
"Util_twine_.With_tag7.t";
"Imandrakit_error__Error_core.Data.t";
"Imandrax_api_eval__Value.Custom_value.t";
"Imandrakit_twine.offset_for";
"option";
"Util_twine_.Z.t";
"Util_twine_.Q.t";
Expand Down
1 change: 1 addition & 0 deletions src/lib/gentypereg/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
imandrax-api.eval
imandrax-api.report
imandrax-api.proof
imandrax-api.proof3
imandrax-api.tasks
imandrax-api.artifact)
(flags :standard -linkall))
1 change: 1 addition & 0 deletions src/lib/proof3/.ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
types.ml
5 changes: 5 additions & 0 deletions src/lib/proof3/common_pr_.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Mir = Imandrax_api_mir
module MT = Mir.Term
module MTy = Mir.Type

type 'a offset_for = 'a Imandrakit_twine.offset_for [@@deriving eq, show, twine]
5 changes: 5 additions & 0 deletions src/lib/proof3/deep_proof_step.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include Types

type t = deep_proof_step

let iter = iter_deep_proof_step
11 changes: 11 additions & 0 deletions src/lib/proof3/deep_sequent.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(** A deep sequent, ie a constructive sequent of sequents. *)

open Common_

(** A deep sequent, ie a constructive sequent of sequents. *)
type t = {
hyps: Imandrax_api_mir.Sequent.t list; (** List of hypothese *)
concl: Imandrax_api_mir.Sequent.t; (** Conclusion *)
}
[@@deriving eq, twine, typereg, show { with_path = false }]
(** A deep sequent: constructive sequent of sequents *)
36 changes: 36 additions & 0 deletions src/lib/proof3/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(library
(name imandrax_api_proof3)
(public_name imandrax-api.proof3)
(synopsis "Proof terms for ImandraX.")
(flags
:standard
-open
Imandrakit
-open
Imandrax_api
-open
Imandrax_api_common)
(preprocess
(pps ppx_deriving.std imandrakit.twine.ppx imandrakit.typereg.ppx))
(libraries imandrakit imandrax-api imandrax-api.common imandrax-api.mir))

(rule
(targets types.ml)
(mode promote)
(action
(with-stdout-to
%{targets}
(run ./gen/mk_rules.exe))))

;(rule
; (targets doc.md)
; (mode promote)
; (action
; (with-stdout-to
; %{targets}
; (run gen/mk_rules.exe --doc))))
;
;(install
; (section doc)
; (package imandrax-api)
; (files doc.md))
7 changes: 7 additions & 0 deletions src/lib/proof3/entrypoint.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(** Entrypoint of a proof file.

This is the record containing the actual proof. *)
type t = { tree: Tree_node.t Types.offset_for (** The proof tree *) }
[@@deriving twine, make, typereg, show { with_path = false }]
(** This is the entrypoint into a proof file, from which we explore proof steps,
the proof tree, etc. *)
92 changes: 92 additions & 0 deletions src/lib/proof3/gen/codegen_md.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module P = Spec_

(*
let bpf = Printf.bprintf
let spf = Printf.sprintf

let indent n s =
match String.split_on_char '\n' s with
| [] -> ""
| [ _ ] -> s
| s :: tl ->
String.concat "\n"
@@ (s :: List.map (fun line -> String.make n ' ' ^ line) tl)

let terms_by_ret_type_ : (P.meta_type, P.dag_term list) Hashtbl.t =
let res = Hashtbl.create 32 in
List.iter
(fun (t : P.dag_term) ->
let l = Hashtbl.find_opt res t.ret |> Option.value ~default:[] in
Hashtbl.replace res t.ret (t :: l))
spec.dag_terms;
res

let is_dag_type s : bool = Hashtbl.mem terms_by_ret_type_ (P.M_ty s)

let rec pp_meta_type (m : P.meta_type) : string =
match m with
| M_ty s -> s
| M_list s -> spf "[%s]" (pp_meta_type s)
| M_option s -> spf "optional(%s)" (pp_meta_type s)
| M_tuple l -> spf "(%s)" @@ String.concat ", " @@ List.map pp_meta_type l

let gendoc (out : Buffer.t) : unit =
let emit_dag_term (t : P.dag_term) : unit =
bpf out "- `%s : %s -> %s`\n" t.name
(String.concat ", " @@ List.map pp_meta_type t.args)
(pp_meta_type t.ret);
Option.iter
(fun n2 -> bpf out " (full name used for codegen: `%s`)\n" n2)
t.full_name;
bpf out " %s\n\n" (indent 2 t.doc)
in

let emit_dag_type (ty : P.dag_type) : unit =
bpf out "- `%s`: %s\n\n" ty.name ty.doc
in

bpf out "\n## DAG types \n\n";
List.iter emit_dag_type spec.dag_types;

bpf out "\n## DAG terms\n\n";

Hashtbl.iter
(fun (ty : P.meta_type) ts ->
bpf out "### Terms returning `%s`\n\n" (pp_meta_type ty);
List.iter emit_dag_term ts;
bpf out "\n")
terms_by_ret_type_;

let emit_builtin_sym (t : P.builtin_symbol) =
(* TODO: a comment with the type signature *)
if t.ret = P.M_ty "Type" then (
assert (t.args = []);
bpf out "- type builtin `%s`\n\n" t.name
) else
bpf out "- builtin symbol `%s : %s%s -> %s`\n\n" t.name
(match t.params with
| [] -> ""
| l -> spf "forall %s. " (String.concat "," l))
(String.concat ", " @@ List.map pp_meta_type t.args)
(pp_meta_type t.ret)
(* TODO: doc? *)
in

(* shortcuts for builtins *)
bpf out "\n## Builtin symbols\n\n";
List.iter emit_builtin_sym spec.builtin_symbols;

()

let codegen (oc : out_channel) : unit =
let module M = Make (struct
let spec = P.spec
end) in
let buf = Buffer.create 32 in
bpf buf "# Imandra Proof System\n\n";
M.gendoc buf;
Buffer.output_buffer oc buf
*)

(* TODO *)
let gen = ignore
24 changes: 24 additions & 0 deletions src/lib/proof3/gen/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(executable
(name mk_rules)
(modules mk_rules parse_spec spec_ codegen_md)
(flags :standard)
(preprocess
(pps ppx_deriving_yojson ppx_deriving.std))
(libraries containers yojson-five))

(rule
(targets spec_.ml)
(deps
(:file proof_spec.json5))
(action
(with-stdout-to
%{targets}
(progn
(echo "let spec = {json|")
(cat %{file})
(echo "|json}")))))

(install
(package imandrax-api)
(section share)
(files proof_spec.json))
Loading