Download presentation
Presentation is loading. Please wait.
1
Program Analyses using Newton's Method
Thomas Reps University of Wisconsin and GrammaTech, Inc.
2
Sidestepping Undecidability
Reachable States Bad States Universe of States
3
Sidestepping Undecidability
Overapproximate the reachable states Reachable States Bad States . . . which can be portrayed as I’ve shown here. False positive! Universe of States
4
Big Picture: Dataflow Analysis
Program Abstraction engine System of Dataflow Equations In this work, we combine two methods for solving equations to create an improved equation solver In terms of a typical system for program analysis, which has the pipeline shown on this slide, the algorithm plays the role of the equation solver. It takes as input the equation system that abstracts the actions of the program, and produces as output the solution to the equation system. That solution is then used to identify possible program flaws, or to establish the correctness of the program’s behavior. <CLICK> In essence, what we did was to combine two known techniques to create an improved equation solver. Equation solver Solution (= dataflow facts)
5
Five Pieces of General CS Knowledge
Regular languages 𝐿 𝐹𝑆𝑀 =𝐿 𝑅𝑒𝑔𝐸𝑥𝑝 =𝑅𝑒𝑔 For a left-linear CFG, e.g., 𝑊∷=𝑊 𝑐 𝑊 𝑑 𝜖, ℒ 𝑊 ∈𝑅𝑒𝑔, e.g., ℒ 𝑊 = 𝑐+𝑑 ∗ ∈𝑅𝑒𝑔 For the linear CFG 𝑋 ∷= 𝑎 𝑋 𝑏 | 𝜖, ℒ 𝑋 = 𝑎 𝑖 𝑏 𝑖 ∉𝑅𝑒𝑔 For the linear CFG 𝑋 ∷= 𝑎 1 𝑋 𝑏 1 | 𝑎 2 𝑋 𝑏 2 | 𝜖, ℒ 𝑋 = …, 𝑎 1 𝑎 2 𝑏 2 𝑏 1 , 𝑎 2 𝑎 1 𝑏 1 𝑏 2 , 𝑎 2 𝑎 1 𝑎 2 𝑏 2 𝑏 1 𝑏 2 ,… ∉𝑅𝑒𝑔
6
Ingredients of the Story
Regular languages LCFLs, such as 𝑎 𝑖 𝑏 𝑖 Isaac Newton Gottfried Wilhelm Leibniz
7
Five Pieces of General CS Knowledge
Regular languages 𝐿 𝐹𝑆𝑀 =𝐿 𝑅𝑒𝑔𝐸𝑥𝑝 =𝑅𝑒𝑔 For a left-linear CFG, e.g., 𝑊∷=𝑊 𝑐 𝑊 𝑑 𝜖, ℒ 𝑊 ∈𝑅𝑒𝑔, e.g., ℒ 𝑊 = 𝑐+𝑑 ∗ ∈𝑅𝑒𝑔 For the linear CFG 𝑋 ∷= 𝑎 𝑋 𝑏 | 𝜖, ℒ 𝑋 = 𝑎 𝑖 𝑏 𝑖 ∉𝑅𝑒𝑔 For the linear CFG 𝑋 ∷= 𝑎 1 𝑋 𝑏 1 | 𝑎 2 𝑋 𝑏 2 | 𝜖, ℒ 𝑋 = …, 𝑎 1 𝑎 2 𝑏 2 𝑏 1 , 𝑎 2 𝑎 1 𝑏 1 𝑏 2 , 𝑎 2 𝑎 1 𝑎 2 𝑏 2 𝑏 1 𝑏 2 ,… ∉𝑅𝑒𝑔 Composition of relations = two-step reachability = multiplication of Boolean adjacency matrices 𝐴 𝑃, 𝑃 ′ ⊗𝐵 𝑄, 𝑄 ′ = ∃ 𝑃 ′ ,𝑄. (𝐴 𝑃, 𝑃 ′ ∧𝐵(𝑄, 𝑄 ′ )∧ 𝑃 ′ =𝑄 ) = × =
8
Outline Background on dataflow analysis
Functional approach to interprocedural analysis Newtonian program analysis Newtonian program analysis via tensor product
9
Possibly Uninitialized Variables (PUV)
“May Contain Junk” Start ∅ 𝜆𝑆.{𝑤,𝑥,𝑦} x = 3 {𝑤,𝑥,𝑦} 𝜆𝑆.𝑆−{𝑥} if . . . {𝑤,𝑦} 𝜆𝑆.𝑆 𝜆𝑆.𝑆 y = x {𝑤,𝑦} 𝜆𝑆.𝑖𝑓 𝑥∈𝑆 𝑡ℎ𝑒𝑛 𝑆∪ 𝑦 𝑒𝑙𝑠𝑒 𝑆 −{𝑦} {𝑤,𝑦} y = w 𝜆𝑆.𝑖𝑓 𝑤∈𝑆 𝑡ℎ𝑒𝑛 𝑆∪ 𝑦 𝑒𝑙𝑠𝑒 𝑆 −{𝑦} w = 8 {𝑤} 𝜆𝑆.𝑆−{𝑤} printf(y) ∅⊕ 𝑤,𝑦 = 𝑤,𝑦
10
Possibly Uninitialized Variables (PUV)
“May Contain Junk” Start ∅ 𝜆𝑆.{𝑤,𝑥,𝑦} Reachable States x = 3 {𝑤,𝑥,𝑦} 𝜆𝑆.𝑆−{𝑥} if . . . {𝑤,𝑦} 𝜆𝑆.𝑆 𝜆𝑆.𝑆 y = x {𝑤,𝑦} 𝜆𝑆.𝑖𝑓 𝑥∈𝑆 𝑡ℎ𝑒𝑛 𝑆∪ 𝑦 𝑒𝑙𝑠𝑒 𝑆 −{𝑦} {𝑤,𝑦} y = w 𝜆𝑆.𝑖𝑓 𝑤∈𝑆 𝑡ℎ𝑒𝑛 𝑆∪ 𝑦 𝑒𝑙𝑠𝑒 𝑆 −{𝑦} w = 8 {𝑤} 𝜆𝑆.𝑆−{𝑤} printf(y) ∅⊕ 𝑤,𝑦 = 𝑤,𝑦
11
Possibly Uninitialized Variables (PUV)
“May Contain Junk” Start ∅ 𝜆𝑆.{𝑤,𝑥,𝑦} x = 3 {𝑤,𝑥,𝑦} 𝜆𝑆.𝑆−{𝑥} if . . . 𝑤,𝑦 ⊕ 𝑤,𝑥,𝑦 ={𝑤,𝑥,𝑦} {𝑤,𝑦} 𝜆𝑆.𝑆 𝜆𝑆.𝑆 y = x {𝑤,𝑦} {𝑤,𝑥,𝑦} 𝜆𝑆.𝑖𝑓 𝑥∈𝑆 𝑡ℎ𝑒𝑛 𝑆∪ 𝑦 𝑒𝑙𝑠𝑒 𝑆 −{𝑦} {𝑤,𝑥,𝑦} {𝑤,𝑦} x = w 𝜆𝑆.𝑖𝑓 𝑤∈𝑆 𝑡ℎ𝑒𝑛 𝑆∪ 𝑥 𝑒𝑙𝑠𝑒 𝑆 −{𝑥} w = 8 {𝑤} {𝑤,𝑥,𝑦} 𝜆𝑆.𝑆−{𝑤} 𝜆𝑆.𝑆 printf(y) {𝑥,𝑦}⊕ 𝑤,𝑥,𝑦 = 𝑤,𝑥,𝑦 ∅⊕ 𝑤,𝑥,𝑦 = 𝑤,𝑥,𝑦
12
Path Semantics for Intraprocedural Analysis
𝑓 1 𝑓 2 𝑓 𝑘−1 𝑓 𝑘 start n 𝑝 𝑓 𝑝 = 𝑓 1 ⊗ 𝑓 2 ⊗…⊗ 𝑓 𝑘−1 ⊗ 𝑓 𝑘 𝐶𝑂𝑃 𝑛 = 𝑝∈𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑛] 𝑝 𝑓 𝑝 (𝐶)
13
Path Semantics for Intraprocedural Analysis
𝑓 1 𝑓 2 𝑓 𝑘−1 𝑓 𝑘 start n 𝑝 𝑓 𝑝 = 𝑓 1 ⊗ 𝑓 2 ⊗…⊗ 𝑓 𝑘−1 ⊗ 𝑓 𝑘 𝜑[𝑠𝑡𝑎𝑟𝑡,𝑛]= 𝑝∈𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑛] 𝑝 𝑓 𝑝 𝜑 𝑠𝑡𝑎𝑟𝑡,𝑛 : transition relation (two-vocabulary formula) To obtain the dataflow value at 𝑛, perform 𝜑 𝑠𝑡𝑎𝑟𝑡,𝑛 (C)
14
From Path Semantics to Equational Semantics
𝜑[𝑠,𝑛]= 𝑝∈𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑛] 𝑝 𝑓 𝑝 Path semantics: 𝜑 𝑠,𝑠 =𝐼𝑑 𝜑 𝑠,𝑛 = 𝑚 𝑖 ,𝑛 ∈𝐸𝑑𝑔𝑒𝑠 𝜑 𝑠, 𝑚 𝑖 ⊗𝑓[ 𝑚 𝑖 ,𝑛] 𝑖𝑓 𝑛≠𝑠 Equational semantics: s x n m1 mk f[m1,n] f[mk,n] 𝜑[s,mk] 𝜑[s,m1] . . . ⊕ 𝜑[s,n] s x 𝜑[s,s] = Id Mark Wegman Susan Graham
15
Outline Background on dataflow analysis
Functional approach to interprocedural analysis Newtonian program analysis Newtonian program analysis via tensor product
16
Swap Procedure 𝜑[𝑠𝑡𝑎𝑟𝑡,𝑒𝑥𝑖𝑡] ⊕ Procedure summary for swap() start
𝑖𝑓 (∗) void swap(bool p1, bool p2) { if (*) { bool t = p1; p1 = p2; p2 = t; } else { p1 = p1 ^ p2; p2 = p1 ^ p2; 𝑡= 𝑝 1 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 1 = 𝑝 2 𝑝 2 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 2 =𝑡 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 The family of phi functions that play a particularly important role in this talk are those from start to exit; these phi functions summarize all paths through the function and act as procedure summaries. ⊕ 𝜑[𝑠𝑡𝑎𝑟𝑡,𝑒𝑥𝑖𝑡] 𝑒𝑥𝑖𝑡 Procedure summary for swap()
17
“Inter” Becomes “Intra” When Procedure Summaries are in Hand
x P 𝑐 1 𝑟 1 𝑐 2 𝑟 2 𝐼 𝑛 1 𝑂𝑢 𝑡 1 𝐼 𝑛 2 𝑂𝑢 𝑡 2 𝑠′ 𝑥′ 𝜑[ 𝑠 ′ , 𝑥 ′ ]
18
“Inter” Becomes “Intra” When Procedure Summaries are in Hand
x P 𝑐 1 𝑟 1 𝑐 2 𝑟 2 𝐼 𝑛 1 ⊗𝜑 𝑠 ′ , 𝑥 ′ ⊗𝑂𝑢 𝑡 1 𝐼 𝑛 2 ⊗𝜑 𝑠 ′ , 𝑥 ′ ⊗𝑂𝑢 𝑡 2 ∴ Now can solve using any intraprocedural method
19
find a procedure summary for each 𝑃 𝑖 ∈𝑃
Problem Statement Given a collection of possibly recursive procedures 𝑃={ 𝑃 𝑖 }, and an abstract semantics, i.e., a transformer on each edge of each control-flow graph extend (⊗) and combine (⊕) operations, find a procedure summary for each 𝑃 𝑖 ∈𝑃
20
Swap Procedure start 𝑖𝑓 (∗) void swap(bool p1, bool p2) { if (*) {
bool t = p1; p1 = p2; p2 = t; } else { p1 = p1 ^ p2; p2 = p1 ^ p2; 𝑡= 𝑝 1 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 1 = 𝑝 2 𝑝 2 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 2 =𝑡 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑒𝑥𝑖𝑡
21
Predicate Abstraction (Boolean Programs)
pre-state assignment ( 𝑝 1 , 𝑝 2 ) post-state assignment ( 𝑝 1 ′ , 𝑝 2 ′ ) 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (01) (10) (11) 𝑝 2 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (01) (10) (11) 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (01) (10) (11)
22
Predicate Abstraction (Boolean Programs)
(00) (01) (10) (11) (00) (01) (10) (11) (00) (01) (10) (11) 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 2 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (01) (10) (11) 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 ; 𝑝 2 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2
23
Predicate Abstraction (Boolean Programs)
(00) (01) (10) (11) (00) (01) (10) (11) (00) (01) (10) (11) 𝑠𝑤𝑎𝑝( 𝑝 1 , 𝑝 2 ) (00) (01) (10) (11) 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 2 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (00) (01) (01) (10) (10) (11) (11) 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 ; 𝑝 2 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2 ; 𝑝 1 ≔ 𝑝 1 𝑥𝑜𝑟 𝑝 2
24
Swap Procedure ? start 𝑖𝑓 (∗) void swap(bool p1, bool p2) { if (*) {
bool t = p1; p1 = p2; p2 = t; } else { p1 = p1 ^ p2; p2 = p1 ^ p2; 𝑡= 𝑝 1 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 1 = 𝑝 2 𝑝 2 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 2 =𝑡 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (01) (10) (11) ? 𝑒𝑥𝑖𝑡
25
Predicate Abstraction (Boolean Programs)
t≔ 𝑝 1 pre-state assignment ( 𝑝 1 , 𝑝 2 ,𝑡) post-state ( 𝑝 1 ′ , 𝑝 2 ′ ,𝑡′) (010) (000) (001) (011) (100) (101) (110) (111) (001) (000) (010) (011) (100) (101) (110) (111) 𝑝 1 ≔ 𝑝 2 (110) (000) (001) (010) (011) (100) (101) (111) 𝑝 2 ≔𝑡
26
Predicate Abstraction (Boolean Programs)
(010) (000) (001) (011) (100) (101) (110) (111) (001) (000) (010) (011) (100) (101) (110) (111) (110) (000) (001) (010) (011) (100) (101) (111) t≔ 𝑝 1 𝑝 1 ≔ 𝑝 2 𝑝 2 ≔𝑡 (010) (000) (001) (011) (100) (101) (110) (111)
27
Predicate Abstraction (Boolean Programs)
(010) (000) (001) (011) (100) (101) (110) (111) (001) (000) (010) (011) (100) (101) (110) (111) (110) (000) (001) (010) (011) (100) (101) (111) t≔ 𝑝 1 𝑝 1 ≔ 𝑝 2 𝑝 2 ≔𝑡 (00) (01) (10) (11) (000) (000) (001) (001) (010) (010) exit scope (011) (011) (100) (100) 𝑠𝑤𝑎𝑝( 𝑝 1 , 𝑝 2 ) (101) (101) (110) (110) (111) (111)
28
Swap Procedure 𝜑[𝑠𝑡𝑎𝑟𝑡,𝑒𝑥𝑖𝑡] ⊕ Procedure summary for swap() start
𝑖𝑓 (∗) void swap(bool p1, bool p2) { if (*) { bool t = p1; p1 = p2; p2 = t; } else { p1 = p1 ^ p2; p2 = p1 ^ p2; 𝑡= 𝑝 1 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 1 = 𝑝 2 𝑝 2 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 𝑝 2 =𝑡 𝑝 1 = 𝑝 1 𝑥𝑜𝑟 𝑝 2 (00) (01) (10) (11) (00) (01) (10) (11) ⊕ 𝜑[𝑠𝑡𝑎𝑟𝑡,𝑒𝑥𝑖𝑡] 𝑒𝑥𝑖𝑡 (00) (01) (10) (11) Procedure summary for swap()
29
From Path Semantics to Equational Semantics
𝜑[𝑠,𝑛]= 𝑝∈𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑛] 𝑝 𝑓 𝑝 Path semantics: 𝜑 𝑠,𝑠 =𝐼𝑑 𝜑 𝑠,𝑛 = 𝑚 𝑖 ,𝑛 ∈𝐸𝑑𝑔𝑒𝑠 𝜑 𝑠, 𝑚 𝑖 ⊗𝑓[ 𝑚 𝑖 ,𝑛] 𝑖𝑓 𝑛≠𝑠 Equational semantics: s x n m1 mk f[m1,n] f[mk,n] 𝜑[s,mk] 𝜑[s,m1] . . . ⊕ 𝜑[s,n] s x 𝜑[s,s] = Id Mark Wegman Susan Graham
30
Interprocedural Equational Semantics
x 𝜑[s,s] = Id 𝜑 𝑠,𝑠 =𝐼𝑑 𝜑 𝑠,𝑛 = 𝑚 𝑖 ,𝑛 ∈𝐸𝑑𝑔𝑒𝑠 𝜑 𝑠, 𝑚 𝑖 ⊗𝑓[ 𝑚 𝑖 ,𝑛] 𝑖𝑓 𝑛≠𝑠 𝜑 𝑠,𝑟 =𝜑 𝑠,𝑐 ⊗𝐼 𝑛 𝑐, 𝑠 ′ ⊗𝜑 𝑠 ′ , 𝑥 ′ ⊗𝑂𝑢 𝑡 𝑥 ′ ,𝑟 𝑠 𝑥 c r 𝑠′ 𝑥′ 𝜑[ 𝑠 ′ , 𝑥 ′ ] 𝜑[𝑠,𝑐] 𝜑[𝑠,𝑟] 𝐼 𝑛 𝑐,𝑠′ 𝑂𝑢 𝑡 𝑥 ′ ,𝑟 s x n m1 mk f[m1,n] f[mk,n] 𝜑[s,mk] 𝜑[s,m1] . . . ⊕ 𝜑[s,n]
31
Conventional Approach to Summary Functions
Set up equation system: 𝜑 𝑠,𝑠 =𝐼𝑑 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆𝑡𝑎𝑟𝑡𝑁𝑜𝑑𝑒𝑠 𝜑 𝑠,𝑛 = 𝑚 𝑖 ,𝑛 ∈𝐸𝑑𝑔𝑒𝑠 𝜑 𝑠, 𝑚 𝑖 ⊗𝑓[ 𝑚 𝑖 ,𝑛] 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑠∈𝑆𝑡𝑎𝑟𝑡𝑁𝑜𝑑𝑒𝑠∧𝑛∉𝑆𝑡𝑎𝑟𝑡𝑁𝑜𝑑𝑒𝑠 𝜑 𝑠,𝑟 =𝜑 𝑠,𝑐 ⊗𝐼 𝑛 𝑐, 𝑠 ′ ⊗𝜑 𝑠 ′ , 𝑥 ′ ⊗𝑂𝑢 𝑡 𝑥 ′ ,𝑟 𝑓𝑜𝑟 𝑎𝑙𝑙 𝑐,𝑟 ∈𝐶𝑎𝑙𝑙𝑆𝑖𝑡𝑒𝑠∧ 𝑐, 𝑠 ′ ∈𝐶𝑎𝑙𝑙𝑠 Summary for called procedure Summary for call site Solve using successive approximation (Kleene evaluation or chaotic iteration) Micha Sharir Amir Pnueli Patrick Cousot Radhia Cousot ⊥
32
Outline Background on dataflow analysis
Functional approach to interprocedural analysis Newtonian program analysis Newtonian program analysis via tensor product
33
Big Picture: Dataflow Analysis
Program Abstraction engine System of Dataflow Equations In terms of a typical system for program analysis, which has the pipeline shown on this slide, the algorithm plays the role of the equation solver. It takes as input the equation system that abstracts the actions of the program, and produces as output the solution to the equation system. That solution is then used to identify possible program flaws, or to establish the correctness of the program’s behavior. <CLICK> In essence, what we did was to combine two known techniques to create an improved equation solver. NPA: An alternative equation solver for finding procedure summaries Equation solver Solution (dataflow facts; procedure summaries)
34
Newton’s Method for Finding Roots
y A way to find successively better approximations of a root of a function Given a function f, its derivative f’ and an initial x0, repeatedly perform 𝑥 𝑖+1 = 𝑥 𝑖 − 𝑓 𝑥 𝑖 𝑓 ′ 𝑥 𝑖 f(xi) f(xi+1) x xi+2 xi+1 xi Brief overview of Newton’s method – for Calculus. (Motivates why it is proper to call the method of Esparza et al. a variation on Newton’s method.) Newtonian Program Analysis: The same general idea—repeatedly create and solve a linear model—can be applied to programs, too Isaac Newton Create a linear model of the function and use it to find a better approximation of the solution
35
Newton’s Method for Programs
Kleene iteration 𝜈 (0) = ⊥ 𝜈 (𝑖+1) = 𝑓 ( 𝜈 (𝑖) ) NPA iteration 𝜈 (0) = ⊥ 𝜈 (𝑖+1) = 𝑓 𝜈 𝑖 ⊕𝐿𝑖𝑛𝑒𝑎𝑟𝐶𝑜𝑟𝑟𝑒𝑐𝑡𝑖𝑜𝑛𝑇𝑒𝑟𝑚 𝑓 , 𝜈 (𝑖) ⊥ In program analysis, we typically use iterative algorithms, such as Kleene iteration, which works up a lattice to find a fixed point. The so-called Newtonian Program Analysis of Esparza, Luttenberger, and Kiefer is based on the observation that numerical analysts also use iterative algorithms, but instead of something like Kleene iteration, they use Newton’s method. I’ll say more about this over the next few slides, but the high-level picture is that NPA is quite similar to Kleene iteration, except that there is an adjustment made each round in the form of some linear correction term, which has the effect of reducing the number of iterative rounds that need to be performed.
36
Newton’s Method for Programs
Kleene iteration 𝜈 (0) = ⊥ 𝜈 (𝑖+1) = 𝑓 ( 𝜈 (𝑖) ) NPA iteration 𝜈 (0) = ⊥ 𝜈 (𝑖+1) = 𝑓 𝜈 𝑖 ⊕𝐿𝑖𝑛𝑒𝑎𝑟𝐶𝑜𝑟𝑟𝑒𝑐𝑡𝑖𝑜𝑛𝑇𝑒𝑟𝑚 𝑓 , 𝜈 (𝑖) ⊥ In program analysis, we typically use iterative algorithms, such as Kleene iteration, which works up a lattice to find a fixed point. So-called Newtonian Program Analysis is based on the observation that numerical analysts also use iterative algorithms, but instead of something like Kleene iteration, they use Newton’s method. I’ll say more about this over the next few slides, but the high-level picture is that NPA is quite similar to Kleene iteration, except that there is an adjustment made each round in the form of some linear correction term, which has the effect of reducing the number of iterative rounds that need to be performed. Mark Hopkins Dexter Kozen Kousha Etessami Mihalis Yannakakis Non-numeric equations with a commutative multiplication Numeric equations from probabilistic programs 37
37
Newton’s Method for Programs
Kleene iteration 𝜈 (0) = ⊥ 𝜈 (𝑖+1) = 𝑓 ( 𝜈 (𝑖) ) NPA iteration 𝜈 (0) = ⊥ 𝜈 (𝑖+1) = 𝑓 𝜈 𝑖 ⊕𝐿𝑖𝑛𝑒𝑎𝑟𝐶𝑜𝑟𝑟𝑒𝑐𝑡𝑖𝑜𝑛𝑇𝑒𝑟𝑚 𝑓 , 𝜈 (𝑖) ⊥ Javier Esparza Stefan Kiefer Michael Luttenberger Non-numeric equations from interprocedural dataflow analysis: non-commutative multiplication 38
38
Newton’s Method for Program Analysis [Esparza et al.]
Esparza et al. had to finesse certain differences Real-valued equations Algebraic semiring Root finding versus fixed-point finding? Derivatives? Mathematics Program Analysis Multiplication: x Abstract Compose: ⨂ Addition: + Join: ⨁ To bring out the analogy, we’ll use the semiring formulation of dataflow-analysis problems. This formulation is really just a change in nomenclature: dataflow problems are equations over a formal multiplication operator and a formal sum operator. The semiring values are abstract transformers of exactly the kind used in interprocedural dataflow analysis, namely abstractions of the program’s transition functions: multiplication is just an abstraction of function composition; and plus is what is more commonly called join.
39
Polynomial Equations for Summary Functions
proc X1 proc X2 x1() { a; x2(); } x2() { if (*) d; else{ b; x2(); c; } a b X2 X2 d X2 X2 c Here is a program that I’ll use as a running example. Each summand represents a path in the (acyclic) control-flow graph. Esparza et al. handle loops by assuming that all loops have been converted to calls on tail-recursive procedures. In general, they have a precise method for solving systems of recursive, loop-free equations. One of the contributions of our paper that I will not talk about in this presentation is a different method for handling loops that does not rely on such a normalizing transformation. Equation System 𝑋 1 =𝑎 ⨂ 𝑋 2 𝑋 2 =𝑑 ⨁ 𝑏 ⨂ 𝑋 2 ⨂ 𝑋 2 ⨂ 𝑐
40
Polynomial Equations for Summary Functions
proc X1 proc X2 x1() { a; x2(); } x2() { if (*) d; else{ b; x2(); c; } a b X2 X2 d X2 c If we go back to the running example, we see that we have a quadratic equation system because of the two calls along one branch of procedure X2 Equation System This term is quadratic 𝑋 1 =𝑎 ⨂ 𝑋 2 𝑋 2 =𝑑 ⨁ 𝑏 ⨂ 𝑋 2 ⨂ 𝑋 2 ⨂ 𝑐
41
We have no minus operation in dataflow analysis
Problematic Issues . . . We have no minus operation in dataflow analysis 𝑓(𝑥) = 𝑥 𝑓 𝑥 −𝑥=0 What the heck do we do about 𝑓 ′ ⋅ ? Esparza et al. had to finesse a couple of problems. We might try to reduce our fixed-point problem to a root-finding problem merely by subtracting x from both sides; however, this approach is a non-starter because we have no minus operation in dataflow analysis Then if you look at the iteration step, it has a derivative in it. What the heck do we do about that? 𝑥 𝑖+1 = 𝑥 𝑖 − 𝑓 𝑥 𝑖 𝑓 ′ 𝑥 𝑖
42
Newton’s Method for Programs [Esparza et al.]
Leibniz product rule Gottfried Wilhelm Newton’s Method for Programs [Esparza et al.] Finesse the derivative question by fiat: 𝐷 𝑔⊕ℎ =𝐷𝑔⊕𝐷ℎ 𝐷 𝑔⊗ℎ = 𝐷𝑔⊗ℎ ⊕ 𝑔⊗𝐷ℎ Outer fixpoint computation NPA iteration 𝜈 (0) = 𝑓 ( 0 ) 𝜈 (𝑖+1) = 𝑌 (𝑖) where 𝑌 (𝑖) is the least solution of 𝑌 = 𝑓 𝜈 𝑖 𝐷 𝑓 | 𝜈 𝑖 ( 𝑌 ) 𝐷𝑓(𝑋) | 𝜈 𝑌 = 𝑌 𝐷𝑔(𝑋) | 𝜈 𝑌 ⊕𝐷ℎ(𝑋) | 𝜈 𝑌 𝐷𝑔(𝑋) | 𝜈 𝑌 ⊗ℎ 𝜈 ⊕ 𝑔 𝜈 ⊗𝐷ℎ 𝑋 | 𝜈 𝑌 if 𝑓(𝑋) is a constant if 𝑓(𝑋)=𝑋 if 𝑓(𝑋)=𝑔(𝑋)⊕ℎ(𝑋) if 𝑓 𝑋 =𝑔 𝑋 ⊗ℎ(𝑋) Really a differential: 𝑓 𝑋 𝑣 𝑓 ′ 𝑣 ⊗𝑌, modulo non-commutativity of ⊗ Inner fixpoint computation Example 1: 𝑋⊗𝑋 𝑣 𝑌⊗𝑣 ⊕ 𝑣⊗𝑌 Linear correction term Example 2: 𝑏⊗𝑋⊗𝑋⊗𝑐 𝑣 𝑏⊗𝑌⊗𝑣⊗𝑐 ⊕ 𝑏⊗𝑣⊗𝑌⊗𝑐
43
Polynomial Equations for Summary Functions
𝑦 2 is the value of 𝑌 2 from the previous Newton round – i.e., some constant for the current round Polynomial Equations for Summary Functions Differentiated equations Original equations Apply the linearization operator 𝑌 1 = 𝑎⨂ 𝑦 2 ⨁ 𝑎⨂ 𝑌 2 𝑋 1 =𝑎 ⨂ 𝑋 2 y x xi xi+1 xi+2 f(xi) 𝑌 2 = 𝑑 𝑋 2 =𝑑 ⨁ 𝑏 ⨂ 𝑋 2 ⨂ 𝑋 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑦 2 ⨂ 𝑐 Each summand now only has one variable; this system of equations is linear! ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑌 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑌 2 ⨂ 𝑦 2 ⨂ 𝑐 proc X1 proc X2 a b X2 X2 d X2 c
44
Polynomial Equations for Summary Functions
Differentiated equations Original equations Apply the linearization operator 𝑌 1 = 𝑎⨂ 𝑦 2 ⨁ 𝑎⨂ 𝑌 2 𝑋 1 =𝑎 ⨂ 𝑋 2 𝑌 2 = 𝑑 𝑋 2 =𝑑 ⨁ 𝑏 ⨂ 𝑋 2 ⨂ 𝑋 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑦 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑌 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑌 2 ⨂ 𝑦 2 ⨂ 𝑐 Operational interpretation: 𝑦 2 is the current approximation At first call, use 𝑦 2 ; at second call, perform exploration (of the transformed procedure) At first call, perform exploration (of the transformed procedure); at second call, use 𝑦 2 Combine (⊕) proc X1 proc X2 Y2 proc Y1 a y2 y2 b proc Y2 d c Y2 a b X2 X2 d X2 c
45
Goal: Precise Solution of Linear Equations
Pre-call action Post-call action start exit 𝑎 𝑝,𝑘 𝑏 𝑝,𝑘 Matched path 𝑝 𝑎 𝑝,2 𝑏 𝑝,2 𝑎 𝑝,1 𝑏 𝑝,1 𝑝 𝑓 𝑝 = 𝑎 𝑝,𝑘 ⊗…⊗ 𝑎 𝑝,2 ⊗ 𝑎 𝑝,1 ⊗𝑏 𝑝,1 ⊗ 𝑏 𝑝,2 ⊗…⊗ 𝑏 𝑝,𝑘 = 𝑎 𝑝,𝑘 … 𝑎 𝑝,2 𝑎 𝑝,1 𝑏 𝑝,1 𝑏 𝑝,2 … 𝑏 𝑝,𝑘 𝜑 𝑠𝑡𝑎𝑟𝑡,𝑒𝑥𝑖𝑡 = 𝑝∈𝑀𝑎𝑡𝑐ℎ𝑒𝑑𝑃𝑎𝑡ℎ𝑠𝑇𝑜 𝑒𝑥𝑖𝑡 𝑝 𝑓 𝑝 = 𝑝∈𝑀𝑎𝑡𝑐ℎ𝑒𝑑𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑒𝑥𝑖𝑡] 𝑎 𝑝,𝑘 … 𝑎 𝑝,2 𝑎 𝑝,1 𝑏 𝑝,1 𝑏 𝑝,2 … 𝑏 𝑝,𝑘
46
Outline Background on dataflow analysis
Functional approach to interprocedural analysis Newtonian program analysis Newtonian program analysis via tensor product
47
Big Picture: Dataflow Analysis
Program Abstraction engine System of Dataflow Equations In terms of a typical system for program analysis, which has the pipeline shown on this slide, the algorithm plays the role of the equation solver. It takes as input the equation system that abstracts the actions of the program, and produces as output the solution to the equation system. That solution is then used to identify possible program flaws, or to establish the correctness of the program’s behavior. <CLICK> In essence, what we did was to combine two known techniques to create an improved equation solver. NPA-TP: Combines NPA with Tarjan’s method to create an improved NPA solver (for finding procedure summaries) Equation solver Solution (dataflow facts; procedure summaries)
48
A Misconception on My Part
Polynomial → Linear Interprocedural analysis → Intraprocedural analysis On each Newton round, use a fast intraprocedural solver, such as Tarjan’s path-expression method! This work got started due to a misconception on my part. We tried out Newtonian Program Analysis, and found that although it was true that there were very few rounds, each round took quite a long time performing Kleene iteration on each linear problem. I suggested that we try a fast intraprocedural method, namely, Tarjan’s path-expression method. I was surprised by my student’s answer, which was that there was an essential mismatch that prevented us from applying Tarjan’s method.
49
Tarjan’s Path-Expression Method
FSM-to-regular-expression conversion == the most-general dataflow-analysis problem Tarjan’s Path-Expression Method Dataflow analysis for a single control-flow graph (CFG) (“intraprocedural analysis”) For each 𝑛∈𝑁𝑜𝑑𝑒𝑠, find a regular expression 𝑅 𝑛 CFG = finite-state machine over alphabet of edges Convert FSM to a regular expression (Kleene’s theorem) 𝑅 𝑛 characterizes all paths from the start node to 𝑛 For each “client” analysis Interpret each alphabet symbol as the abstract transformer of the corresponding CFG edge Interpret +, ⋅, and * using suitable operations ⊕, ⊗, and ⊛ Evaluate each 𝑅 𝑛 , 𝑛∈𝑁𝑜𝑑𝑒𝑠 Robert Tarjan
50
A Misconception on My Part
Issue: Extend (⨂) typically models the reversal of function composition: 𝑓 ⨂ 𝑔 ≝𝑔 ○𝑓 In general, ⨂ is not commutative In a semiring 𝐷 𝑋 2 | 𝜈 (𝑌) = 𝐷 𝑋⊗𝑋 | 𝜈 (𝑌) = 𝐷 𝑋 | 𝜈 𝑌 ⊗𝜈 ⊕𝜈⊗𝐷 𝑋 | 𝜈 𝑌 = 𝑌⊗ 𝜈⊕𝜈 𝑌 ≠ 𝜈⊗𝑌⊕𝜈⊗𝑌 In calculus 𝐷 𝑋 2 | 𝜈 (𝑌) = 𝐷 𝑋×𝑋 | 𝜈 (𝑌) = 𝐷 𝑋 | 𝜈 𝑌 𝜈 + 𝜈 𝐷 𝑋 | 𝜈 𝑌 = 𝑌 𝜈+ 𝜈 𝑌 =𝜈×𝑌+𝜈×𝑌 =2𝜈𝑌 =2𝑋𝑑𝑋 𝑏⨂ 𝑦 2 ⨂ 𝑌 2 ⨂𝑐 ≠ 𝑌 2 ⨂𝑏⨂ 𝑦 2 ⨂𝑐 ≠b⨂ 𝑦 2 ⨂𝑐⨂ 𝑌 2 Esparza’s linear equations are not left-linear or right-linear, which Tarjan requires
51
Doesn’t the Pumping Lemma Imply . . . Fuggedaboutit?
If we represent the Esparza linearized system as a grammar, we obtain a linear context-free grammar 𝑌 1 ∷=𝑎𝑦2 | 𝑎 𝑌 2 𝑌 2 ∷=𝑑 | 𝑏 𝑦 2 𝑦 2 𝑐 𝑏 𝑌 2 𝑦 2 𝑐 𝑏 𝑦 2 𝑌 2 𝑐 One learns early on in a formal-language course that not all languages defined by a linear context-free grammar are regular In particular, { 𝑎𝑖𝑏𝑖 | 𝑖 𝑁 } is the canonical example of an LCFL language that is not regular: X ::= a X b | ε Suggests that we are barking up the wrong tree . . . <Mirrored Symmetry> . . . Dana Scott Michael Rabin
52
LCFLs from NPA ∉ Regular languages
Sanity Check? Tarjan’s path-expression method (a technique based on Regular languages) LCFLs from NPA ∉ Regular languages
53
Doesn’t the Pumping Lemma Imply . . . Fuggedaboutit?
If we represent the Esparza linearized system as a grammar, we obtain a linear context-free grammar 𝑌 1 ∷=𝑎𝑦2 | 𝑎 𝑌 2 𝑌 2 ∷=𝑑 | 𝑏 𝑦 2 𝑦 2 𝑐 𝑏 𝑌 2 𝑦 2 𝑐 𝑏 𝑦 2 𝑌 2 𝑐 One learns early on in a formal-language course that not all languages defined by a linear context-free grammar are regular In particular, { 𝑎𝑖𝑏𝑖 | 𝑖 𝑁 } is the canonical example of an LCFL language that is not regular: X ::= a X b | ε Suggests that we are barking up the wrong tree But we aren’t! We are not abstracting the program to a grammar We can sidestep the issue with some “magic” from algebra . . . <Mirrored Symmetry> . . . Dana Scott Michael Rabin
54
Converting to Tarjan The challenge:
Devise a way to accumulate matching quantities on both the left and right sides However, in a regular language, we can only accumulate values on one side Suggests using pairs of values (lhs, rhs): 𝑌 1 = 𝑎⨂ 𝑦 2 ⨁ 𝑎⨂ 𝑌 2 𝑌 2 = 𝑑 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑦 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑌 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑌 2 ⨂ 𝑦 2 ⨂ 𝑐 becomes 𝑍 1 = (1,𝑎⨂ 𝑦 2 ) 𝑌 1 =ℛ( 𝑍 1 ) ⊕ 𝑝 𝑍 2 ⨂ 𝑝 (𝑎,1) 𝑌 2 =ℛ( 𝑍 2 ) 𝑍 2 = (1,𝑑) ⊕ 𝑝 (1,𝑏⨂ 𝑦 2 ⨂ 𝑦 2 𝑐) ⊕ 𝑝 𝑍 2 ⨂ 𝑝 (𝑏⨂ 𝑦 2 ,𝑐) ⊕ 𝑝 𝑍 2 ⨂ 𝑝 (𝑏, 𝑦 2 ⨂𝑐) LCFL Each variable occurrence is now leftmost in its summand; this system of equations is left-linear! Left-recursive = Regular
55
Converting to Tarjan The challenge:
Devise a way to accumulate matching quantities on both the left and right sides However, in a regular language, we can only accumulate values on one side Suggests using pairs of values (lhs, rhs): 𝑎 1 , 𝑏 1 ⊕ 𝑝 𝑎 2 , 𝑏 2 = 𝑑𝑓 𝑎 1 ⊕ 𝑎 2 , 𝑏 1 ⊕ 𝑏 2 𝑎 1 , 𝑏 1 ⨂ 𝑝 𝑎 2 , 𝑏 2 = 𝑑𝑓 𝑎 2 ⨂ 𝑎 1 , 𝑏 1 ⨂ 𝑏 2 Given a pair 𝑎,𝑏 , define the readout operation ℛ( 𝑎,𝑏 )≝𝑎⨂𝑏 Thus, ℛ( 𝑎 1 , 𝑏 1 ⨂ 𝑝 𝑎 2 , 𝑏 2 )=ℛ( 𝑎 1 , 𝑏 1 ⨂ 𝑝 𝑎 2 , 𝑏 2 ) =ℛ( 𝑎 2 ⨂ 𝑎 1 , 𝑏 1 ⨂ 𝑏 2 ) = 𝑎 2 ⨂ 𝑎 1 ⨂ 𝑏 1 ⨂ 𝑏 2 . . . <Reversal in the paired multiplication operator> . . . . . . <Mirrored Symmetry> . . .
56
Converting to Tarjan The challenge: ⨁ 𝑎⨂ 𝑌 2 𝑌 2 = 𝑑
Devise a way to accumulate matching quantities on both the left and right sides However, in a regular language, we can only accumulate values on one side 𝑌 1 = 𝑎⨂ 𝑦 2 ⨁ 𝑎⨂ 𝑌 2 𝑌 2 = 𝑑 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑦 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑦 2 ⨂ 𝑌 2 ⨂ 𝑐 ⨁ 𝑏⨂ 𝑌 2 ⨂ 𝑦 2 ⨂ 𝑐 𝑍 1 = (1,𝑎⨂ 𝑦 2 ) 𝑌 1 =ℛ( 𝑍 1 ) ⊕ 𝑝 𝑍 2 ⨂ 𝑝 𝑎, 𝑌 2 = ℛ( 𝑍 2 ) 𝑍 2 = (1,𝑑) ⊕ 𝑝 (1,𝑏⨂ 𝑦 2 ⨂ 𝑦 2 𝑐) ⊕ 𝑝 𝑍 2 ⨂ 𝑝 (𝑏⨂ 𝑦 2 ,𝑐) ⊕ 𝑝 𝑍 2 ⨂ 𝑝 (𝑏, 𝑦 2 ⨂𝑐) (3) (3) (1) (1) (2) (2) (b, y2c) (1,d) (by2, c) b b d This slide shows how the paired system simulates the computations of the original system y2 y2 ℛ((1,d) 𝑝(b,y2c) 𝑝(b y2,c)) = ℛ(b y2 b 1, d y2c c) = b y2 b 1d y2c c (1,d) 𝑝(b,y2c) 𝑝(b y2,c) c c
57
Pairing Fails to Deliver . . .
X1 = X2 = a1X1b1 ⊕ a2X1b2 Z1 = (1, 1) Z2 = Z1 p (a1, b1) ⊕p Z1 p (a2, b2) proc X1 1 X1 proc X2 a1 a2 b2 b1 proc Z1 (1,1) Z1 proc X2 (a2,b2) (a1, b1) Least solution (⊕p of the two paths): Z2 = (1,1) ⊗ 𝑝 (a1, b1) ⊕p (1,1) ⊗ 𝑝 (a2, b2) = (a1, b1) ⊕p (a2, b2) = a1⊕a2,b1⊕b2 ℛ((a1⊕a2, b1⊕b2)) = (a1⊕a2) (b1⊕b2) = a1b1 ⊕ a2b1 ⊕ a1b2 ⊕ a2b2 Conservative, but loses precision Least solution (⊕ of the two paths): X2 = a11b1 ⊕ a21b2 = a1b1 ⊕ a2b2
58
Doesn’t the Pumping Lemma Imply . . . Fuggedaboutit?
If we represent the Esparza linearized system as a grammar, we obtain a linear context-free grammar 𝑌 1 ∷=𝑎𝑦2 | 𝑎 𝑌 2 𝑌 2 ∷=𝑑 | 𝑏 𝑦 2 𝑦 2 𝑐 𝑏 𝑌 2 𝑦 2 𝑐 𝑏 𝑦 2 𝑌 2 𝑐 Fuggedaboutit? One learns early on in a formal-language course that not all languages defined by a linear context-free grammar are regular In particular, { aibi | i N } is the canonical example of an LCFL language that is not regular: X ::= a X b | ε Suggests that we are barking up the wrong tree . . . <Mirrored Symmetry> . . . Dana Scott Michael Rabin
59
A Glimmer of Hope . . . A transformation of the linearized problem to left-linear form is not actually forced to use pairing From the pair (𝑎,𝑏), we can recover 𝑎 From the pair (𝑎,𝑏), we can recover 𝑏 Given a “coupled value” 𝑐 = 𝑐𝑜𝑢𝑝𝑙𝑒(𝑎, 𝑏), we never need to recover from 𝑐 the value of 𝑎 or 𝑏 alone We only need to be able to obtain the value 𝑎⊗𝑏 Pairing is overkill! ⇒ Use some kind of “blending” of 𝑎 and 𝑏 So what saves us? Well, there is one glimmer of hope. We are not actually forced to use pairing per se. We need to produce some kind of coupled value; however, the property of pairing is that one can recover each individual argument from the pair, and we never have to do that. You can think of a coupled value c as some kind of blending of a and b. It just has to be a blending from which we can recover “a extend b” later, if we so choose. One analogy is RSA public keys: the public key is a blending of two primes. In that case, you can extract the arguments, but not without doing a lot of work.
60
How to Blend Two Values, A and B
Hint: Kronecker product of matrices: 𝐴⨀𝐵 = 𝑎 1,1 𝑎 1,2 𝑎 2,1 𝑎 2,2 ⨀ 𝑏 1,1 𝑏 1,2 𝑏 2,1 𝑏 2,2 = 𝑎 1,1 𝐵 𝑎 1,2 𝐵 𝑎 2,1 𝐵 𝑎 2,2 𝐵 = 𝑎 1,1 𝑏 1,1 𝑎 1,1 𝑏 1,2 𝑎 1,1 𝑏 2,1 𝑎 1,1 𝑏 2,2 𝑎 1,2 𝑏 1,1 𝑎 1,2 𝑏 1,2 𝑎 1,2 𝑏 2,1 𝑎 1,2 𝑏 2,2 𝑎 2,1 𝑏 1,1 𝑎 2,1 𝑏 1,2 𝑎 2,1 𝑏 2,1 𝑎 2,1 𝑏 2,2 𝑎 2,2 𝑏 1,1 𝑎 2,2 𝑏 1,2 𝑎 2,2 𝑏 2,1 𝑎 2,2 𝑏 2,2 A? B? Leopold Kronecker
61
Converting to Tarjan We need a “magic” pairing operator, 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎,𝑏 , with the property and a readout operator with the properties 𝑟𝑒𝑎𝑑𝑜𝑢𝑡(𝑐𝑜𝑢𝑝𝑙𝑒 𝑚,𝑛 ) = 𝑚⨂𝑛 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐 1 ⊕ 𝑐 2 =𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐 1 ⊕𝑟𝑒𝑎𝑑𝑜𝑢𝑡( 𝑐 2 ) Such a construction does not create cross-terms no loss of precision 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎 1 , 𝑏 1 ⊗𝑐𝑜𝑢𝑝𝑙𝑒( 𝑎 2 , 𝑏 2 ) =𝑐𝑜𝑢𝑝𝑙𝑒( 𝑎 2 ⊗ 𝑎 1 , 𝑏 1 ⊗ 𝑏 2 ) (†) 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎 1 , 𝑏 1 ⊕𝑐𝑜𝑢𝑝𝑙𝑒( 𝑎 2 , 𝑏 2 ) =𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎 1 , 𝑏 1 ⨁𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐𝑜𝑢𝑝𝑙𝑒( 𝑎 2 , 𝑏 2 ) = 𝑎 1 𝑏 1 ⨁ 𝑎 2 𝑏 2 versus ℛ 𝑎 1 , 𝑏 1 ⨁ 𝑝 𝑎 2 , 𝑏 2 =ℛ((𝑎1⊕𝑎2, 𝑏1⊕𝑏2)) = 𝑎1⊕𝑎2 ⊗(𝑏1⊕𝑏2) = 𝑎 1 𝑏 1 ⨁ 𝑎 2 𝑏 1 ⨁ 𝑎 1 𝑏 2 ⨁ 𝑎 2 𝑏 2 Thomas Reps Akash Lal Tayssir Touili Nick Kidd
62
Converting to Tarjan We need a “magic” pairing operator, 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎,𝑏 , with the property and a readout operator with the properties 𝑟𝑒𝑎𝑑𝑜𝑢𝑡(𝑐𝑜𝑢𝑝𝑙𝑒 𝑚,𝑛 ) = 𝑚⨂𝑛 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐 1 ⊕ 𝑐 2 =𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑐 1 ⊕𝑟𝑒𝑎𝑑𝑜𝑢𝑡( 𝑐 2 ) Such a construction does not create cross-terms no loss of precision 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎 1 , 𝑏 1 ⊗𝑐𝑜𝑢𝑝𝑙𝑒( 𝑎 2 , 𝑏 2 ) =𝑐𝑜𝑢𝑝𝑙𝑒( 𝑎 2 ⊗ 𝑎 1 , 𝑏 1 ⊗ 𝑏 2 ) (†) For predicate abstraction, all transformers are square Boolean matrices The Kronecker product (of square matrices) has property (†) 𝑐𝑜𝑢𝑝𝑙𝑒 𝑎,𝑏 ≝ 𝑎 𝑡 ⊙𝑏 where ⨀ is Kronecker product ⋅ 𝑡 is matrix transpose 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑎 𝑡 ⊙𝑏 =𝑎⊗𝑏, and distributes over ⊕ 𝑘 Converts an LCFL linear system into a Regular linear system!! albeit the latter involves larger matrices ⨂ is matrix multiplication ⨁ is pointwise of matrices
63
The Key Intuition ⨂ is matrix multiplication
⨁ is pointwise of matrices The Key Intuition For predicate abstraction, all transformers are square Boolean matrices The Kronecker product of square matrices is 𝐴 𝑡 ⨀𝐵= 𝑎 1,1 𝑎 2,1 𝑎 1,2 𝑎 2,2 ⨀ 𝑏 1,1 𝑏 1,2 𝑏 2,1 𝑏 2,2 = 𝑎 1,1 𝐵 𝑎 2,1 𝐵 𝑎 1,2 𝐵 𝑎 2,2 𝐵 = 𝑎 1,1 𝑏 1,1 𝑎 1,1 𝑏 1,2 𝑎 1,1 𝑏 2,1 𝑎 1,1 𝑏 2,2 𝑎 2,1 𝑏 1,1 𝑎 2,1 𝑏 1,2 𝑎 2,1 𝑏 2,1 𝑎 2,1 𝑏 2,2 𝑎 1,2 𝑏 1,1 𝑎 1,2 𝑏 1,2 𝑎 1,2 𝑏 2,1 𝑎 1,2 𝑏 2,2 𝑎 2,2 𝑏 1,1 𝑎 2,2 𝑏 1,2 𝑎 2,2 𝑏 2,1 𝑎 2,2 𝑏 2,2 𝑐𝑜𝑢𝑝𝑙𝑒 𝐴 1 ,𝐵 ⊗𝑐𝑜𝑢𝑝𝑙𝑒 𝐴 2 , 𝐵 2 = 𝐴 1 𝑡 ⨀ 𝐵 1 ⊗ 𝑘 𝐴 2 𝑡 ⨀ 𝐵 2 = 𝐴 1 𝑡 ⨂ 𝐴 2 𝑡 ⨀ 𝐵 1 ⨂ 𝐵 2 = 𝐴 2 ⨂ 𝐴 1 𝑡 ⨀ 𝐵 1 ⨂ 𝐵 2 =𝑐𝑜𝑢𝑝𝑙𝑒( 𝐴 2 ⊗ 𝐴 1 , 𝐵 1 ⊗ 𝐵 2 ) 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝐴 2 ⨂ 𝐴 1 𝑡 ⨀ 𝐵 1 ⨂ 𝐵 2 = A 2 ⊗ 𝐴 1 ⊗ 𝐵 1 ⊗ 𝐵 2 Leopold Kronecker
64
NPA-TP is a Nested Fixpoint Computation
Tensored differential produces left-linear expressions 𝐷 𝒯 𝑔⊕ℎ = 𝐷 𝒯 𝑔 ⊕ 𝑘 𝐷 𝒯 ℎ 𝐷 𝒯 𝑔⊗ℎ =( 𝐷 𝒯 𝑔 ⊗ 𝑘 1⊙ℎ ) ⊕ 𝑘 ( 𝐷 𝒯 ℎ ⊗ 𝑘 𝑔 𝑡 ⊙1 ) Leibniz product rule in tensored form Gottfried Wilhelm Leibniz Outer fixpoint: iterative NPA iteration 𝜈 (0) = 𝑓 ( 0 ) 𝜈 (𝑖+1) = 𝑌 (𝑖) where 𝑌 (𝑖) is the least solution of 𝑌 = 𝑓 𝜈 𝑖 𝐷 𝑓 | 𝜈 𝑖 ( 𝑌 ) NPA-TP iteration 𝜈 (0) = 𝑓 ( ⊥ ) 𝜈 (𝑖+1) =𝑟𝑒𝑎𝑑𝑜𝑢𝑡( 𝑍 𝑖 ) where 𝑍 (𝑖) is the least solution of 𝑍 = (1⊙ 𝑓 𝜈 𝑖 ) ⊕ 𝑘 𝐷 𝒯 𝑓 | 𝜈 𝑖 𝑍 Inner fixpoint: Tarjan applied to left-linear equations
65
NPA-TP Yields Precise Linear-Equation Solution
the 𝑍 paths ≃ the 𝑌 paths (i.e., regular-language 𝑍 paths ≃ matched 𝑌 paths) 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 distributes over ⊕ start exit ( 𝑎 𝑝,1 𝑡 ⨀ 𝑏 𝑝,1 ) ( 𝑎 𝑝,2 𝑡 ⨀ 𝑏 𝑝,2 ) ( 𝑎 𝑝,𝑘 𝑡 ⨀ 𝑏 𝑝,𝑘 ) 𝑝 𝑓 𝑝 = 𝑎 𝑝,1 𝑡 ⨀ 𝑏 𝑝,1 ⊗ 𝑎 𝑝,2 𝑡 ⨀ 𝑏 𝑝,2 ⊗…⊗( 𝑎 𝑝,𝑘 𝑡 ⨀ 𝑏 𝑝,𝑘 ) = 𝑎 𝑝,𝑘 … 𝑎 𝑝,2 𝑎 𝑝,1 𝑡 ⨀ (𝑏 𝑝,1 𝑏 𝑝,2 … 𝑏 𝑝,𝑘 ) 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑝 𝑓 𝑝 = 𝑎 𝑝,𝑘 … 𝑎 𝑝,2 𝑎 𝑝,1 𝑏 𝑝,1 𝑏 𝑝,2 … 𝑏 𝑝,𝑘 𝜑[𝑠𝑡𝑎𝑟𝑡,𝑒𝑥𝑖𝑡]=𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑝∈𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑒𝑥𝑖𝑡] 𝑝 𝑓 𝑝 = 𝑝∈𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑒𝑥𝑖𝑡] 𝑟𝑒𝑎𝑑𝑜𝑢𝑡(𝑝 𝑓 𝑝 ) = 𝑝∈𝑀𝑎𝑡𝑐ℎ𝑒𝑑𝑃𝑎𝑡ℎ𝑠𝑇𝑜[𝑒𝑥𝑖𝑡] 𝑎 𝑝,𝑘 … 𝑎 𝑝,2 𝑎 𝑝,1 𝑏 𝑝,1 𝑏 𝑝,2 … 𝑏 𝑝,𝑘
66
What To Do Next? Compositional Recurrence Analysis (CRA)
Finds numeric invariants Intraprocedural analysis via Tarjan Abstract domain of formulas (non-linear arithmetic) ⊕ is ∨ (no loss of precision) 𝜑⊛ performs extract a system of recurrence (in)equations entailed by 𝜑 solve them convert answer to a formula What To Do Next? 9/2015-present: Combined CRA and NPA-TP: Interprocedural CRA (ICRA) Interprocedural analyzer for numeric invariants Infinite ascending chains (convergence is not guaranteed) [PLDI17] Entailment is undecidable (convergence can’t be detected) [PLDI17] Non-linear arithmetic [POPL18] Other issues [POPL19a, POPL19b]
67
Some Intuition About Kronecker Product
𝐴 𝑡 ⨀𝐵= 𝑎 1,1 𝑎 2,1 𝑎 1,2 𝑎 2,2 ⨀ 𝑏 1,1 𝑏 1,2 𝑏 2,1 𝑏 2,2 = 𝑎 1,1 𝐵 𝑎 2,1 𝐵 𝑎 1,2 𝐵 𝑎 2,2 𝐵 = 𝑎 1,1 𝑏 1,1 𝑎 1,1 𝑏 1,2 𝑎 1,1 𝑏 2,1 𝑎 1,1 𝑏 2,2 𝑎 2,1 𝑏 1,1 𝑎 2,1 𝑏 1,2 𝑎 2,1 𝑏 2,1 𝑎 2,1 𝑏 2,2 𝑎 1,2 𝑏 1,1 𝑎 1,2 𝑏 1,2 𝑎 1,2 𝑏 2,1 𝑎 1,2 𝑏 2,2 𝑎 2,2 𝑏 1,1 𝑎 2,2 𝑏 1,2 𝑎 2,2 𝑏 2,1 𝑎 2,2 𝑏 2,2 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑎 1,1 𝑏 1,1 𝑎 1,1 𝑏 1,2 𝑎 1,1 𝑏 2,1 𝑎 1,1 𝑏 2,2 𝑎 2,1 𝑏 1,1 𝑎 2,1 𝑏 1,2 𝑎 2,1 𝑏 2,1 𝑎 2,1 𝑏 2,2 𝑎 1,2 𝑏 1,1 𝑎 1,2 𝑏 1,2 𝑎 1,2 𝑏 2,1 𝑎 1,2 𝑏 2,2 𝑎 2,2 𝑏 1,1 𝑎 2,2 𝑏 1,2 𝑎 2,2 𝑏 2,1 𝑎 2,2 𝑏 2,2 = 𝑎 1,1 𝑏 1,1 ∨ 𝑎 1,2 𝑏 2,1 𝑎 1,1 𝑏 1,2 ∨ 𝑎 1,2 𝑏 2,2 𝑎 2,1 𝑏 1,1 ∨ 𝑎 2,2 𝑏 2,1 𝑎 2,1 𝑏 1,2 ∨ 𝑎 2,2 𝑏 2,2 = 𝑎 1,1 𝑎 1,2 𝑎 2,1 𝑎 2,2 × 𝑏 1,1 𝑏 1,2 𝑏 2,1 𝑏 2,2 =𝐴⊗𝐵 readout is ∃ 𝑃 ′ ,𝑄. (𝑇 𝑃 ′ ,𝑄,𝑃, 𝑄 ′ ∧ 𝑃 ′ =𝑄 ) 𝑎 𝑃,𝑃′ 𝑏 𝑄,𝑄′ Leopold Kronecker
68
Kronecker Product from a Logical Perspective
𝐴 𝑃, 𝑃 ′ 𝑡 ⊙𝐵 𝑄, 𝑄 ′ = 𝐴 𝑅 𝑃′,𝑃 ∧𝐵(𝑄, 𝑄 ′ )=𝐴 𝑃, 𝑃 ′ ∧𝐵(𝑄, 𝑄 ′ ) Kronecker Product from a Logical Perspective 𝐴 𝑡 ⨀𝐵= 𝑎 1,1 𝑎 2,1 𝑎 1,2 𝑎 2,2 ⨀ 𝑏 1,1 𝑏 1,2 𝑏 2,1 𝑏 2,2 = 𝑎 1,1 𝐵 𝑎 2,1 𝐵 𝑎 1,2 𝐵 𝑎 2,2 𝐵 = 𝑎 1,1 𝑏 1,1 𝑎 1,1 𝑏 1,2 𝑎 1,1 𝑏 2,1 𝑎 1,1 𝑏 2,2 𝑎 2,1 𝑏 1,1 𝑎 2,1 𝑏 1,2 𝑎 2,1 𝑏 2,1 𝑎 2,1 𝑏 2,2 𝑎 1,2 𝑏 1,1 𝑎 1,2 𝑏 1,2 𝑎 1,2 𝑏 2,1 𝑎 1,2 𝑏 2,2 𝑎 2,2 𝑏 1,1 𝑎 2,2 𝑏 1,2 𝑎 2,2 𝑏 2,1 𝑎 2,2 𝑏 2,2 𝑟𝑒𝑎𝑑𝑜𝑢𝑡 𝑎 1,1 𝑏 1,1 𝑎 1,1 𝑏 1,2 𝑎 1,1 𝑏 2,1 𝑎 1,1 𝑏 2,2 𝑎 2,1 𝑏 1,1 𝑎 2,1 𝑏 1,2 𝑎 2,1 𝑏 2,1 𝑎 2,1 𝑏 2,2 𝑎 1,2 𝑏 1,1 𝑎 1,2 𝑏 1,2 𝑎 1,2 𝑏 2,1 𝑎 1,2 𝑏 2,2 𝑎 2,2 𝑏 1,1 𝑎 2,2 𝑏 1,2 𝑎 2,2 𝑏 2,1 𝑎 2,2 𝑏 2,2 = 𝑎 1,1 𝑏 1,1 ∨ 𝑎 1,2 𝑏 2,1 𝑎 1,1 𝑏 1,2 ∨ 𝑎 1,2 𝑏 2,2 𝑎 2,1 𝑏 1,1 ∨ 𝑎 2,2 𝑏 2,1 𝑎 2,1 𝑏 1,2 ∨ 𝑎 2,2 𝑏 2,2 = 𝑎 1,1 𝑎 1,2 𝑎 2,1 𝑎 2,2 × 𝑏 1,1 𝑏 1,2 𝑏 2,1 𝑏 2,2 =𝐴⊗𝐵 Kronecker product of formulas: 𝐴 𝑃, 𝑃 ′ 𝑡 ⊙𝐵 𝑄, 𝑄 ′ readout is ∃ 𝑃 ′ ,𝑄. (𝑇 𝑃 ′ ,𝑄,𝑃, 𝑄 ′ ∧ 𝑃 ′ =𝑄 ) Four vocabularies: 𝑇(1,1,1,1) = 𝑎 1,1 𝑏 1,1 𝑎 𝑃,𝑃′ 𝑏 𝑄,𝑄′ Pre-call action Post-call continuation Leopold Kronecker 𝐴 𝑃, 𝑃 ′ ⊗𝐵 𝑄, 𝑄 ′ = ∃ 𝑃 ′ ,𝑄. (𝐴 𝑃, 𝑃 ′ ∧𝐵(𝑄, 𝑄 ′ )∧ 𝑃 ′ =𝑄 )
69
Experimental Results (Predicate Abstraction) The Good News
NPA-TP better than NPA Geometric mean: 1.62 NPA On the roughly 500 hardest examples in the Static Driver Verifier test suite of Boolean programs NPA via Tensor Product
70
Experimental Results (Predicate Abstraction) The Bad News
Chaotic iteration better than NPA-TP Geometric mean: 5.20 NPA via Tensor Product Chaotic iteration
71
Experimental Results (Numeric Invariants)
On a variety of benchmark suites (mainly from SV-COMP16) Competitive with verification tools based on abstraction refinement Encouraging because abstraction refinement has a 20-year head start
72
Experimental Results (Non-Linear Invariants)
On programs with non-linear assertions Competitive with verification tools based on abstraction refinement Encouraging because abstraction refinement has a 20-year head start
73
LCFLs from NPA ∉ Regular languages
Main Take-Aways CFL 𝑁𝑒𝑤𝑡𝑜𝑛 𝑇𝑟𝑎𝑛𝑠𝑓𝑜𝑟𝑚 LCFL 𝐾𝑟𝑜𝑛𝑒𝑐𝑘𝑒𝑟 𝑃𝑟𝑜𝑑𝑢𝑐𝑡 𝑇𝑟𝑖𝑐𝑘 Regular (Variants of) NPA-TP are competitive with abstraction refinement NPA-TP much faster Neither approach dominates with respect to precision Beware of sanity checks! Tarjan’s path-expression method (a technique based on Regular languages) LCFLs from NPA ∉ Regular languages Regular languages LCFLs, such as 𝑎 𝑖 𝑏 𝑖
74
Mark Wegman Susan Graham Radhia Cousot Patrick Micha Sharir Amir
Pnueli Isaac Newton Dexter Kozen Mark Hopkins Javier Esparza Stefan Kiefer Michael Luttenberger Mihalis Yannakakis Kousha Etessami Dana Scott Michael Rabin Robert Tarjan Gottfried Wilhelm Leibniz That brings me to the end of our story, and the long chain of the people whose ideas we’ve used today. Along the way, we attempted to use formal-language theory as a sanity check, which suggested that we give up. But a little algebra magic rescued us. I like this result very much, and hope that you enjoyed hearing about it. Thank you for your attention, and I’m happy to take questions. Leopold Kronecker Thomas Reps Akash Lal Tayssir Touili Nick Kidd Emma Turetsky Thomas Reps Prathmesh Prabhu
75
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.