Skip to content

Commit f71668b

Browse files
committed
Fixing LazyList name clash and adding Duper.lean
1 parent 04c9be6 commit f71668b

File tree

7 files changed

+39
-41
lines changed

7 files changed

+39
-41
lines changed

Duper.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import Duper.Tactic

Duper/DUnif/Bindings.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def withoutModifyingMCtx (x : MetaM α) : MetaM α := do
2929
finally
3030
setMCtx s
3131

32-
def iteration (F : Expr) (p : UnifProblem) (eq : UnifEq) (funcArgOnly : Bool) : MetaM (LazyList <| MetaM (Array UnifProblem)) := do
32+
def iteration (F : Expr) (p : UnifProblem) (eq : UnifEq) (funcArgOnly : Bool) : MetaM (Duper.LazyList <| MetaM (Array UnifProblem)) := do
3333
setMCtx p.mctx
3434
let Fty ← Meta.inferType F
3535
Meta.forallTelescopeReducing Fty fun xs β₁ => (do
@@ -79,8 +79,8 @@ def iteration (F : Expr) (p : UnifProblem) (eq : UnifEq) (funcArgOnly : Bool) :
7979
)
8080
-- Get rid of metavariables in `xys`
8181
setMCtx p.mctx
82-
let iterAtIArr := iterAtIFuns.map (fun f => (LazyList.nats 0).map f)
83-
return LazyList.interleaveN iterAtIArr
82+
let iterAtIArr := iterAtIFuns.map (fun f => (Duper.LazyList.nats 0).map f)
83+
return Duper.LazyList.interleaveN iterAtIArr
8484
)
8585

8686
/-- `F` is a metavariable -/
@@ -185,7 +185,7 @@ def imitProj (F : Expr) (nLam : Nat) (iTy : Expr) (oTy : Expr) (name : Name) (id
185185
the left-hand side, we will see that `h + n - k - len(bin_F) = m - len(bin_g)`, i.e.
186186
· `h = m + k + len(bin_F) - n - len(bin_g)`
187187
The above equation can be used to determine the value of `h`.
188-
188+
189189
Now we specify the types of fresh metavariables and the resulting equations
190190
· The type of `?Hᵢ (1 ≤ i ≤ min (l, h))` is taken care of by `forallMetaTelescopeReducing`
191191
· If `h ≤ l`, the type of `binding` should be unified with the type of `F`. This
@@ -233,7 +233,7 @@ def imitation (F : Expr) (g : Expr) (p : UnifProblem) (eq : UnifEq) : MetaM (Arr
233233
MVarId.assign F.mvarId! mt
234234
return #[{(← p.pushParentRuleIfDbgOn (.Imitation eq F g mt)) with checked := false, mctx := ← getMCtx}]
235235

236-
def elimination (F : Expr) (p : UnifProblem) (eq : UnifEq) : MetaM (LazyList <| MetaM (Array UnifProblem)) := do
236+
def elimination (F : Expr) (p : UnifProblem) (eq : UnifEq) : MetaM (Duper.LazyList <| MetaM (Array UnifProblem)) := do
237237
setMCtx p.mctx
238238
let lctx₀ ← getLCtx
239239
let Fty ← Meta.inferType F
@@ -341,4 +341,4 @@ def identification (F : Expr) (G : Expr) (p : UnifProblem) (eq : UnifEq) : MetaM
341341
MVarId.assign G.mvarId! mtG
342342
let up' := {(← p.pushParentRuleIfDbgOn (.Identification eq F G mtF mtG))
343343
with checked := false, mctx := ← getMCtx, identVar := p.identVar.insert mH}
344-
return .NewArray #[up']
344+
return .NewArray #[up']

Duper/DUnif/UnifProblem.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,5 @@ def structInfo (p : UnifProblem) (e : Expr) : MetaM (Expr × StructType) := do
400400
-- Bool : True -> Succeed, False -> Fail
401401
inductive UnifRuleResult
402402
| NewArray : Array UnifProblem → UnifRuleResult
403-
| NewLazyList : LazyList (MetaM (Array UnifProblem)) → UnifRuleResult
403+
| NewLazyList : Duper.LazyList (MetaM (Array UnifProblem)) → UnifRuleResult
404404
| Succeed : UnifRuleResult

Duper/DUnif/UnifRules.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ def applyRules (p : UnifProblem) (config : Config) : MetaM UnifRuleResult := do
329329
if config.iterationOn then
330330
let liter ← DUnif.iteration lh p eq false
331331
let riter ← DUnif.iteration rh p eq false
332-
return LazyList.interleave liter riter
332+
return Duper.LazyList.interleave liter riter
333333
else
334-
return LazyList.nil)
334+
return Duper.LazyList.nil)
335335
-- Identification
336336
let mut arr := #[]
337337
match (← DUnif.identification lh rh p eq) with
338338
| .NewArray a => arr := arr.append a
339-
| .NewLazyList l => ll := LazyList.interleave l ll
339+
| .NewLazyList l => ll := Duper.LazyList.interleave l ll
340340
| .Succeed => throwError "applyRules :: identification never succeeds"
341341
-- JP style projection
342342
if ¬ p.identVar.contains lh then
@@ -355,10 +355,10 @@ def applyRules (p : UnifProblem) (config : Config) : MetaM UnifRuleResult := do
355355
if config.iterationOn then
356356
DUnif.iteration lh p eq true
357357
else
358-
return LazyList.nil)
358+
return Duper.LazyList.nil)
359359
-- Eliminations
360360
let elims ← DUnif.elimination lh p eq
361-
return .NewLazyList (LazyList.cons (pure decomp) (LazyList.interleave elims iters))
361+
return .NewLazyList (Duper.LazyList.cons (pure decomp) (Duper.LazyList.interleave elims iters))
362362
else
363363
-- No equations left
364364
return .Succeed
@@ -369,7 +369,7 @@ def applyRules (p : UnifProblem) (config : Config) : MetaM UnifRuleResult := do
369369

370370
inductive QueueElement
371371
| Problem : UnifProblem → QueueElement
372-
| LazyListOfProblem : LazyList (MetaM (Array UnifProblem)) → QueueElement
372+
| LazyListOfProblem : Duper.LazyList (MetaM (Array UnifProblem)) → QueueElement
373373
deriving Inhabited
374374

375375
structure UnifierGenerator where

Duper/SubsumptionTrie.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def emptyNode : SubsumptionTrie := node #[]
229229

230230
def singleton (c : Clause) (features : FeatureVector) : SubsumptionTrie :=
231231
match features with
232-
| nil => leaf (HashSet.empty.insert c)
232+
| [] => leaf (HashSet.empty.insert c)
233233
| fstFeature :: restFeatures => node #[(fstFeature, singleton c restFeatures)]
234234

235235
private def insertHelper (t : SubsumptionTrie) (c : Clause) (features : FeatureVector) : RuleM SubsumptionTrie :=
@@ -243,7 +243,7 @@ private def insertHelper (t : SubsumptionTrie) (c : Clause) (features : FeatureV
243243
return node children'
244244
curIdx := curIdx + 1
245245
return node (children.push (fstFeature, singleton c restFeatures))
246-
| leaf vals, nil => return leaf (vals.insert c)
246+
| leaf vals, [] => return leaf (vals.insert c)
247247
| _, _ => throwError "Features: {features} length does not match depth of trie {t}"
248248

249249
def insert (t : SubsumptionTrie) (c : Clause) : RuleM SubsumptionTrie :=
@@ -260,7 +260,7 @@ private def deleteHelper (t : SubsumptionTrie) (c : Clause) (features : FeatureV
260260
return node children'
261261
curIdx := curIdx + 1
262262
return node children -- c not found in t, so just return original t
263-
| leaf vals, nil => return leaf (vals.erase c)
263+
| leaf vals, [] => return leaf (vals.erase c)
264264
| _, _ => throwError "Features: {features} length does not match depth of trie {t}"
265265

266266
def delete (t : SubsumptionTrie) (c : Clause) : RuleM SubsumptionTrie :=
@@ -274,7 +274,7 @@ private def getPotentialSubsumingClausesHelper (t : SubsumptionTrie) (features :
274274
if SubsumptionTrieFeatureValueLe childFeature fstFeature then
275275
potentialSubsumingClauses := potentialSubsumingClauses.append (← getPotentialSubsumingClausesHelper childTrie restFeatures)
276276
return potentialSubsumingClauses
277-
| leaf vals, nil => return vals.toArray
277+
| leaf vals, [] => return vals.toArray
278278
| _, _ => throwError "Features: {features} length does not match depth of trie {t}"
279279

280280
def getPotentialSubsumingClauses (t : SubsumptionTrie) (c : Clause) : RuleM (Array Clause) :=
@@ -292,7 +292,7 @@ private def getPotentialSubsumedClausesHelper (t : SubsumptionTrie) (features :
292292
if SubsumptionTrieFeatureValueLe fstFeature childFeature then
293293
potentialSubsumingClauses := potentialSubsumingClauses.append (← getPotentialSubsumedClausesHelper childTrie restFeatures)
294294
return potentialSubsumingClauses
295-
| leaf vals, nil => return vals.toArray
295+
| leaf vals, [] => return vals.toArray
296296
| _, _ => throwError "Features: {features} length does not match depth of trie {t}"
297297

298298
def getPotentialSubsumedClauses (t : SubsumptionTrie) (c : Clause) : RuleM (Array Clause) :=

Duper/Util/LazyList.lean

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Author: Leonardo de Moura
55
-/
66

7-
inductive LazyList (α : Type u)
7+
inductive Duper.LazyList (α : Type u)
88
| nil : LazyList α
99
| cons (hd : α) (tl : LazyList α) : LazyList α
1010
| delayed (t : Thunk (LazyList α)): LazyList α
1111

1212
-- @[extern cpp inline "#2"]
13-
def List.toLazy {α : Type u} : List α → LazyList α
14-
| [] => LazyList.nil
15-
| (h::t) => LazyList.cons h (List.toLazy t)
13+
def Duper.List.toLazy {α : Type u} : List α → Duper.LazyList α
14+
| [] => Duper.LazyList.nil
15+
| (h::t) => Duper.LazyList.cons h (Duper.List.toLazy t)
1616

17-
namespace LazyList
17+
namespace Duper.LazyList
1818
variable {α : Type u} {β : Type v} {δ : Type w}
1919

20-
instance : Inhabited (LazyList α) :=
20+
instance : Inhabited (Duper.LazyList α) :=
2121
⟨nil⟩
2222

2323
partial def nats i := cons i (delayed (nats (i + 1)))
@@ -178,43 +178,40 @@ def approxToString [ToString α] (as : LazyList α) (n : Nat := 10) : String :=
178178

179179
instance [ToString α] : ToString (LazyList α) := ⟨approxToString⟩
180180

181-
end LazyList
182-
183-
181+
end Duper.LazyList
184182

185183
-- Other utilities
186184

187-
def List.lazySubsequences {α : Type u} : List α → LazyList (List α)
185+
def List.lazySubsequences {α : Type u} : List α → Duper.LazyList (List α)
188186
| .nil => .cons .nil .nil
189-
| .cons a as => List.lazySubsequences as ++ .delayed (LazyList.map (List.cons a) (lazySubsequences as))
187+
| .cons a as => List.lazySubsequences as ++ .delayed (Duper.LazyList.map (List.cons a) (lazySubsequences as))
190188

191189

192190

193191
-- Testing
192+
def fib : Duper.LazyList Nat :=
193+
Duper.LazyList.iterate₂ (·+·) 0 1
194194

195-
def fib : LazyList Nat :=
196-
LazyList.iterate₂ (·+·) 0 1
197-
198-
def tst : LazyList String := do
199-
let x ← [1, 2, 3].toLazy
200-
let y ← [2, 3, 4].toLazy
195+
def tst : Duper.LazyList String := do
196+
let x ← Duper.List.toLazy [1, 2, 3]
197+
let y ← Duper.List.toLazy [2, 3, 4]
201198
-- dbgTrace (toString x ++ " " ++ toString y) $ λ _,
202199
guard (x + y > 5)
203200
pure (toString x ++ " + " ++ toString y ++ " = " ++ toString (x+y))
204201

205-
open LazyList
202+
open Duper.LazyList
206203

207-
def iota (i : UInt32 := 0) : LazyList UInt32 :=
204+
def iota (i : UInt32 := 0) : Duper.LazyList UInt32 :=
208205
iterate (·+1) i
209206

210207
set_option pp.explicit true
211208

212-
partial def sieve : LazyList UInt32 → LazyList UInt32
209+
partial def sieve : Duper.LazyList UInt32 → Duper.LazyList UInt32
213210
| nil => nil
214211
| (cons a as) => cons a (delayed (sieve (filter (λ b => b % a != 0) as)))
215212
| (delayed as) => sieve as.get
216213

217-
partial def primes : LazyList UInt32 :=
214+
partial def primes : Duper.LazyList UInt32 :=
218215
sieve (iota 2)
219216

220217
def maintest : IO Unit := do
@@ -229,4 +226,4 @@ def maintest : IO Unit := do
229226
-- IO.println $ ((iota.map (+10)).filter (λ v, v % 2 == 0)),
230227
pure ()
231228

232-
partial def natuple := LazyList.bindω (LazyList.nats 0) (fun i => (LazyList.nats 0).zip (repeats i))
229+
partial def natuple := Duper.LazyList.bindω (Duper.LazyList.nats 0) (fun i => (Duper.LazyList.nats 0).zip (repeats i))

Main.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Duper.Tactic
1+
import Duper
22
import Duper.TPTP -- Note: this import is needed to make sure that TPTP is compiled for the github actions
33
import Duper.TPTPParser.PrattParser
44

0 commit comments

Comments
 (0)