Skip to content

Commit

Permalink
Adding support for mutually inductive datatypes to well-formed constr…
Browse files Browse the repository at this point in the history
…aint reasoning
  • Loading branch information
JOSHCLUNE committed Jan 10, 2025
1 parent 008a6c5 commit 37a909c
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 102 deletions.
16 changes: 16 additions & 0 deletions Auto/IR/SMT.lean
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ instance : ToString SMTOption where
( declare-sort 〈symbol〉 〈numeral〉 )
( define-fun 〈function_def〉 )
( define-fun-rec 〈function_def〉 )
( define-funs-rec ( ⟨function_dec⟩ⁿ⁺¹ ) ( ⟨term⟩ⁿ⁺¹ ) )
( define-sort 〈symbol〉 ( 〈symbol〉∗ ) 〈sort〉 )
( declare-datatype 〈symbol〉 〈datatype_dec〉)
...
Expand All @@ -327,6 +328,12 @@ inductive Command where
| declSort : (name : String) → (arity : Nat) → Command
| defFun : (isRec : Bool) → (name : String) → (args : Array (String × SSort)) →
(resTy : SSort) → (body : STerm) → Command
-- `defFuns` is used for the command `define-funs-rec`. Each element in the array it takes in contains:
-- `String` : Function name
-- `Array (String × SSort)` : Function args
-- `SSort` : Function return sort
-- `STerm` : Function body
| defFuns : Array (String × Array (String × SSort) × SSort × STerm) → Command
| defSort : (name : String) → (args : Array String) → (body : SSort) → Command
| declDtype : (name : String) → DatatypeDecl → Command
-- String × Nat : sort_dec
Expand Down Expand Up @@ -358,6 +365,15 @@ def Command.toString : Command → String
let binders := "(" ++ String.intercalate " " (args.map (fun (name, sort) => s!"({SIdent.symb name} {sort})")).toList ++ ") "
let trail := s!"{resTy} " ++ STerm.toString body (args.map (fun (name, _) => SIdent.symb name)) ++ ")"
pre ++ binders ++ trail
| .defFuns defs =>
let pre := "(define-funs-rec "
let declStringOfDef : String × Array (String × SSort) × SSort × STerm → String := fun (name, args, resSort, _) =>
let argBinders := "(" ++ String.intercalate " " (args.map (fun (name, sort) => s!"({SIdent.symb name} {sort})")).toList ++ ") "
s!"({SIdent.symb name} {argBinders} {resSort})"
let decls := "(" ++ String.intercalate " " (defs.map declStringOfDef).toList ++ ") "
let bodies := "(" ++ String.intercalate " " (defs.map (fun (_, args, _, body) => STerm.toString body (args.map (fun (name, _) => SIdent.symb name)))).toList ++ ")"
let trail := ")"
pre ++ decls ++ bodies ++ trail
| .defSort name args body =>
let pre := s!"(define-sort {SIdent.symb name} ("
let sargs := String.intercalate " " args.toList ++ ") "
Expand Down
2 changes: 1 addition & 1 deletion Auto/Tactic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def querySMTForHints (exportFacts : Array REntry) (exportInds : Array MutualIndI
- The index of the argument it is a selector for
- The mvar used to represent the selector function -/
let mut selectorArr : Array (String × Expr × Nat × Expr) := #[]
for (selName, selIsProjection, selCtor, argIdx, datatypeName, selOutputType) in selInfos do
for (selName, selIsProjection, selCtor, argIdx, datatypeName, _selInputType, selOutputType) in selInfos do
if !selIsProjection then -- Projections already have corresponding values in Lean and therefore don't need to be added to `selectorArr`
let selCtor ←
SMT.withExprValuation sni state.h2lMap (fun tyValMap varValMap etomValMap => do
Expand Down
Loading

0 comments on commit 37a909c

Please sign in to comment.