Sorts
String Sort
The built-in string sort:Z3_mk_string_sort(c) (api_seq.cpp:92)
Character Sort
Individual Unicode characters:Z3_mk_char_sort(c) (api_seq.cpp:102)
Sequence Sort
Sequences of arbitrary element types:Z3_mk_seq_sort(c, domain) (api_seq.cpp:27)
String Literals
Create Strings
Z3_mk_string(c, str)- from null-terminated string (api_seq.cpp:47)Z3_mk_lstring(c, sz, str)- from length-prefixed string (api_seq.cpp:58)Z3_mk_u32string(c, sz, chars)- from Unicode code points (api_seq.cpp:71)
Character Literals
Z3_mk_char(c, ch) - create character from code point (api_seq.cpp:82)
String Operations
Concatenation
Z3_mk_seq_concat (api_seq.cpp:285)
Length
Z3_mk_seq_length (api_seq.cpp:301)
Substring (Extract)
Z3_mk_seq_extract(c, s, offset, length) (api_seq.cpp:294)
Character At
Get character at position:Z3_mk_seq_at (api_seq.cpp:299)
Index Of
Find first occurrence of substring:Z3_mk_seq_index(c, s, substr, offset) (api_seq.cpp:302)
Last Index Of
Find last occurrence:Z3_mk_seq_last_index (api_seq.cpp:303)
Replace
Replace first occurrence:Z3_mk_seq_replace(c, s, src, dst) (api_seq.cpp:295)
Replace All
Replace all occurrences:Z3_mk_seq_replace_all (api_seq.cpp:296)
Prefix and Suffix
Z3_mk_seq_prefix, Z3_mk_seq_suffix (api_seq.cpp:286-287)
Contains
Z3_mk_seq_contains (api_seq.cpp:288)
String Predicates
Lexicographic Comparison
Z3_mk_str_lt, Z3_mk_str_le (api_seq.cpp:289-290)
Conversion Operations
String to/from Integer
Z3_mk_str_to_int, Z3_mk_int_to_str (api_seq.cpp:307-308)
String to/from Code
Convert between strings and Unicode code points:Z3_mk_string_to_code, Z3_mk_string_from_code (api_seq.cpp:291-292)
Character to/from Integer
Z3_mk_char_to_int (api_seq.cpp:349)
Character to/from Bit-Vector
Z3_mk_char_to_bv, Z3_mk_char_from_bv (api_seq.cpp:350-351)
Bit-Vector to String
Z3_mk_ubv_to_str, Z3_mk_sbv_to_str (api_seq.cpp:309-310)
Regular Expressions
Regular Expression Sort
Z3_mk_re_sort(c, domain) (api_seq.cpp:37)
Basic Regex Constructors
Z3_mk_re_empty, Z3_mk_re_full, Z3_mk_re_allchar (api_seq.cpp:345-346, 344)
Regex Operations
Z3_mk_re_concat(api_seq.cpp:341)Z3_mk_re_union(api_seq.cpp:339)Z3_mk_re_intersect(api_seq.cpp:340)Z3_mk_re_complement(api_seq.cpp:337)Z3_mk_re_star(api_seq.cpp:335)Z3_mk_re_plus(api_seq.cpp:334)Z3_mk_re_option(api_seq.cpp:336)Z3_mk_re_range(api_seq.cpp:342)Z3_mk_re_loop(api_seq.cpp:313)Z3_mk_re_power(api_seq.cpp:323)
String Matching
Test if string matches regex:Z3_mk_seq_in_re(c, s, re) (api_seq.cpp:305)
Replace with Regex
Z3_mk_seq_replace_re, Z3_mk_seq_replace_re_all (api_seq.cpp:297-298)
Sequence Operations
All string operations also work on sequences:Z3_mk_seq_empty, Z3_mk_seq_unit, Z3_mk_seq_nth (api_seq.cpp:282, 284, 300)
Advanced Operations
Map Over Sequence
Apply function to each element:Z3_mk_seq_map (api_seq.cpp:354)
Map with Index
Apply function with index:Z3_mk_seq_mapi (api_seq.cpp:355)
Fold (Reduce)
Fold function over sequence:Z3_mk_seq_foldl (api_seq.cpp:356)
Fold with Index
Z3_mk_seq_foldli (api_seq.cpp:357)
Complete Examples
Example 1: Email Validation
Example 2: SQL Injection Detection
Example 3: Password Strength
Example 4: Path Traversal Detection
Example 5: String Parsing
Character Predicates
Check if Digit
Z3_mk_char_is_digit (api_seq.cpp:352)
Character Comparison
Z3_mk_char_le (api_seq.cpp:348)
Implementation Notes
- Strings are sequences of Unicode code points
- Efficient decision procedures for linear constraints
- Regular expressions compiled to automata
- Sequence theory is parametric (works with any element type)
References
- Implementation:
src/api/api_seq.cpp - Theory plugin:
src/ast/seq_decl_plugin.h - Solver:
src/smt/theory_seq.h
