Skip to content

Commit 7b3d778

Browse files
authored
feat: simprocs for String.toList and String.push (#12642)
This PR adds dsimprocs for reducing `String.toList` and `String.push`.
1 parent e7e3588 commit 7b3d778

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/Lean/Meta/Tactic/Simp/BuiltinSimprocs/String.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ builtin_dsimproc [simp, seval] reduceOfList (String.ofList _) := fun e => do
3535
unless e.isAppOfArity ``String.ofList 1 do return .continue
3636
reduceListChar e.appArg! ""
3737

38+
builtin_dsimproc [simp, seval] reduceToList (String.toList _) := fun e => do
39+
unless e.isAppOfArity ``String.toList 1 do return .continue
40+
let some s ← fromExpr? e.appArg! | return .continue
41+
return .done <| toExpr s.toList
42+
43+
builtin_dsimproc [simp, seval] reducePush (String.push _ _) := fun e => do
44+
unless e.isAppOfArity ``String.push 2 do return .continue
45+
let some n ← fromExpr? e.appFn!.appArg! | return .continue
46+
let some m ← Char.fromExpr? e.appArg! | return .continue
47+
return .done <| toExpr (n.push m)
48+
3849
@[inline] def reduceBinPred (declName : Name) (arity : Nat) (op : String → String → Bool) (e : Expr) : SimpM Step := do
3950
unless e.isAppOfArity declName arity do return .continue
4051
let some n ← fromExpr? e.appFn!.appArg! | return .continue

tests/lean/run/simprocString.lean

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
-- String.reduceAppend
2+
example : "hello" ++ " " ++ "world" = "hello world" := by simp
3+
example : "" ++ "a" = "a" := by simp
4+
example : "a" ++ "" = "a" := by simp
5+
example : "" ++ "" = "" := by simp
6+
7+
-- String.reduceOfList
8+
example : String.ofList ['a', 'b', 'c'] = "abc" := by simp
9+
example : String.ofList [] = "" := by simp
10+
example : String.ofList ['x'] = "x" := by simp
11+
12+
-- String.reduceToList
13+
example : "abc".toList = ['a', 'b', 'c'] := by simp
14+
example : "".toList = [] := by simp
15+
example : "x".toList = ['x'] := by simp
16+
example : "hello".toList = ['h', 'e', 'l', 'l', 'o'] := by simp
17+
18+
-- String.reducePush
19+
example : "abc".push 'd' = "abcd" := by simp
20+
example : "".push 'a' = "a" := by simp
21+
22+
-- String.reduceEq
23+
example : "hello" = "hello" := by simp
24+
example : "hello" = "foo" → False := by simp
25+
26+
-- String.reduceNe
27+
example : "hello""foo" := by simp
28+
29+
-- String.reduceBEq
30+
example : ("hello" == "hello") = true := by simp
31+
example : ("hello" == "foo") = false := by simp
32+
33+
-- String.reduceBNe
34+
example : ("hello" != "foo") = true := by simp
35+
example : ("hello" != "hello") = false := by simp
36+
37+
-- String.reduceLT
38+
example : "abc" < "abd" := by simp
39+
example : "a" < "b" := by simp
40+
41+
-- String.reduceLE
42+
example : "abc""abc" := by simp
43+
example : "abc""abd" := by simp
44+
45+
-- String.reduceGT
46+
example : "abd" > "abc" := by simp
47+
example : "b" > "a" := by simp
48+
49+
-- String.reduceGE
50+
example : "abc""abc" := by simp
51+
example : "abd""abc" := by simp
52+
53+
-- Combined: roundtrip toList/ofList
54+
example : String.ofList "hello".toList = "hello" := by simp

0 commit comments

Comments
 (0)