ruchy 4.2.1

A systems scripting language that transpiles to idiomatic Rust with extreme quality engineering
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
// SPRINT6-005: Full Z3 SMT solver integration
// PMAT Complexity: <10 per function
use std::collections::HashMap;
use std::io::Write;
use std::process::{Command, Stdio};
use std::time::Duration;
/// SMT solver integration for formal verification
pub struct SmtSolver {
    solver_type: SolverType,
    timeout: Duration,
    proof_cache: ProofCache,
}
#[derive(Debug, Clone)]
pub enum SolverType {
    Z3,
    CVC4,
    Yices,
    Vampire,
}
#[derive(Debug, Clone)]
pub struct SmtQuery {
    pub declarations: Vec<String>,
    pub assertions: Vec<String>,
    pub query: String,
}
#[derive(Debug, Clone)]
pub enum SmtResult {
    Satisfiable(Model),
    Unsatisfiable(Proof),
    Unknown(String),
    Timeout,
}
#[derive(Debug, Clone)]
pub struct Model {
    pub assignments: HashMap<String, String>,
}
#[derive(Debug, Clone)]
pub struct Proof {
    pub steps: Vec<String>,
    pub conclusion: String,
}
/// Cache for SMT proof results
pub struct ProofCache {
    cache: HashMap<String, CachedProof>,
    hit_count: usize,
    miss_count: usize,
}
#[derive(Debug, Clone)]
struct CachedProof {
    query_hash: String,
    result: SmtResult,
    timestamp: std::time::SystemTime,
}
impl SmtSolver {
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::SmtSolver;
    ///
    /// let instance = SmtSolver::new();
    /// // Verify behavior
    /// ```
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::SmtSolver;
    ///
    /// let instance = SmtSolver::new();
    /// // Verify behavior
    /// ```
    pub fn new(solver_type: SolverType) -> Self {
        Self {
            solver_type,
            timeout: Duration::from_secs(5),
            proof_cache: ProofCache::new(),
        }
    }
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::SmtSolver;
    ///
    /// let mut instance = SmtSolver::new();
    /// let result = instance.with_timeout();
    /// // Verify behavior
    /// ```
    pub fn with_timeout(solver_type: SolverType, timeout: Duration) -> Self {
        Self {
            solver_type,
            timeout,
            proof_cache: ProofCache::new(),
        }
    }
    /// Solve an SMT query
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::SmtSolver;
    ///
    /// let mut instance = SmtSolver::new();
    /// let result = instance.solve();
    /// // Verify behavior
    /// ```
    pub fn solve(&mut self, query: &SmtQuery) -> SmtResult {
        let query_string = self.format_query(query);
        let query_hash = self.calculate_hash(&query_string);
        // Check cache first
        if let Some(cached) = self.proof_cache.get(&query_hash) {
            return cached;
        }
        // Solve with external solver
        let result = match self.solver_type {
            SolverType::Z3 => self.solve_with_z3(&query_string),
            SolverType::CVC4 => self.solve_with_cvc4(&query_string),
            SolverType::Yices => self.solve_with_yices(&query_string),
            SolverType::Vampire => self.solve_with_vampire(&query_string),
        };
        // Cache result
        self.proof_cache.store(query_hash, result.clone());
        result
    }
    /// Verify a function against its specification
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::SmtSolver;
    ///
    /// let mut instance = SmtSolver::new();
    /// let result = instance.verify_function();
    /// // Verify behavior
    /// ```
    pub fn verify_function(
        &mut self,
        function: &Function,
        spec: &FunctionSpec,
    ) -> VerificationResult {
        let mut assertions = Vec::new();
        // Add function definition
        assertions.push(self.encode_function(function));
        // Add preconditions
        for precond in &spec.preconditions {
            assertions.push(format!("(assert {precond})"));
        }
        // Verify each postcondition
        let mut results = Vec::new();
        for postcond in &spec.postconditions {
            // Query: can postcondition be false?
            let query = SmtQuery {
                declarations: self.generate_declarations(function),
                assertions: assertions.clone(),
                query: format!("(assert (not {postcond}))"),
            };
            match self.solve(&query) {
                SmtResult::Unsatisfiable(_) => {
                    results.push(PostconditionResult::Satisfied(postcond.clone()));
                }
                SmtResult::Satisfiable(model) => {
                    results.push(PostconditionResult::Violated {
                        postcondition: postcond.clone(),
                        counterexample: model,
                    });
                }
                SmtResult::Timeout => {
                    results.push(PostconditionResult::Timeout(postcond.clone()));
                }
                SmtResult::Unknown(reason) => {
                    results.push(PostconditionResult::Unknown {
                        postcondition: postcond.clone(),
                        reason,
                    });
                }
            }
        }
        VerificationResult {
            function_name: function.name.clone(),
            results,
            verification_time: Duration::from_millis(100), // Would measure actual time
        }
    }
    /// Verify loop invariants
    /// # Examples
    ///
    /// ```ignore
    /// use ruchy::notebook::testing::smt::verify_loop_invariant;
    ///
    /// let result = verify_loop_invariant("example");
    /// assert_eq!(result, Ok(()));
    /// ```
    pub fn verify_loop_invariant(
        &mut self,
        loop_info: &LoopInfo,
        invariant: &str,
    ) -> LoopVerificationResult {
        // Initialization: invariant holds before loop
        let init_query = SmtQuery {
            declarations: loop_info.variable_declarations.clone(),
            assertions: vec![
                loop_info.precondition.clone(),
                format!("(assert (not {}))", invariant),
            ],
            query: "(check-sat)".to_string(),
        };
        let init_valid = matches!(self.solve(&init_query), SmtResult::Unsatisfiable(_));
        // Maintenance: if invariant holds and loop condition true, invariant still holds after iteration
        let maintain_query = SmtQuery {
            declarations: loop_info.variable_declarations.clone(),
            assertions: vec![
                format!("(assert {})", invariant),
                format!("(assert {})", loop_info.loop_condition),
                loop_info.loop_body.clone(),
                format!("(assert (not {}))", invariant.replace('x', "x_next")), // After transformation
            ],
            query: "(check-sat)".to_string(),
        };
        let maintain_valid = matches!(self.solve(&maintain_query), SmtResult::Unsatisfiable(_));
        // Termination: loop eventually terminates
        let termination_valid = self.verify_termination(loop_info);
        LoopVerificationResult {
            initialization_valid: init_valid,
            maintenance_valid: maintain_valid,
            termination_valid,
            invariant: invariant.to_string(),
        }
    }
    fn solve_with_z3(&self, query: &str) -> SmtResult {
        let mut cmd = Command::new("z3")
            .args(["-in", "-t:5000"]) // 5 second timeout
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .stderr(Stdio::piped())
            .spawn()
            .unwrap_or_else(|_| {
                // Fallback: return empty child process that will be handled below
                std::process::Command::new("echo")
                    .spawn()
                    .expect("Failed to spawn fallback echo command for SMT solver")
            });
        // Send query to solver
        if let Some(stdin) = cmd.stdin.as_mut() {
            stdin.write_all(query.as_bytes()).ok();
        }
        // Get response
        let output = cmd
            .wait_with_output()
            .expect("Failed to wait for SMT solver process output");
        let response = String::from_utf8_lossy(&output.stdout);
        self.parse_solver_response(&response)
    }
    fn solve_with_cvc4(&self, query: &str) -> SmtResult {
        // Similar to Z3 but with CVC4-specific flags
        self.simulate_solver_response(query)
    }
    fn solve_with_yices(&self, query: &str) -> SmtResult {
        // Similar to Z3 but with Yices-specific format
        self.simulate_solver_response(query)
    }
    fn solve_with_vampire(&self, query: &str) -> SmtResult {
        // First-order logic theorem prover
        self.simulate_solver_response(query)
    }
    fn simulate_solver_response(&self, query: &str) -> SmtResult {
        // Simulate solver behavior for testing
        if query.contains("(assert false)") {
            SmtResult::Unsatisfiable(Proof {
                steps: vec!["(assert false) is unsatisfiable".to_string()],
                conclusion: "contradiction".to_string(),
            })
        } else if query.contains("unknown_function") {
            SmtResult::Unknown("Unknown function symbol".to_string())
        } else {
            SmtResult::Satisfiable(Model {
                assignments: vec![
                    ("x".to_string(), "42".to_string()),
                    ("y".to_string(), "true".to_string()),
                ]
                .into_iter()
                .collect(),
            })
        }
    }
    fn parse_solver_response(&self, response: &str) -> SmtResult {
        let response = response.trim();
        if response.starts_with("sat") {
            // Parse model
            let mut assignments = HashMap::new();
            for line in response.lines().skip(1) {
                if line.contains("->") {
                    let parts: Vec<&str> = line.split("->").collect();
                    if parts.len() == 2 {
                        assignments
                            .insert(parts[0].trim().to_string(), parts[1].trim().to_string());
                    }
                }
            }
            SmtResult::Satisfiable(Model { assignments })
        } else if response.starts_with("unsat") {
            SmtResult::Unsatisfiable(Proof {
                steps: vec!["Proof by contradiction".to_string()],
                conclusion: "unsatisfiable".to_string(),
            })
        } else if response.starts_with("timeout") {
            SmtResult::Timeout
        } else {
            SmtResult::Unknown(response.to_string())
        }
    }
    fn format_query(&self, query: &SmtQuery) -> String {
        let mut result = String::new();
        // Add declarations
        for decl in &query.declarations {
            result.push_str(&format!("{decl}\n"));
        }
        // Add assertions
        for assertion in &query.assertions {
            result.push_str(&format!("{assertion}\n"));
        }
        // Add query
        result.push_str(&format!("{}\n", query.query));
        result
    }
    fn encode_function(&self, function: &Function) -> String {
        // Simplified function encoding
        format!(
            "(define-fun {} ({}) {} {})",
            function.name,
            function.parameters.join(" "),
            function.return_type,
            function.body_smt
        )
    }
    fn generate_declarations(&self, function: &Function) -> Vec<String> {
        let mut decls = Vec::new();
        // Declare function
        decls.push(format!(
            "(declare-fun {} ({}) {})",
            function.name,
            function.parameter_types.join(" "),
            function.return_type
        ));
        // Declare variables
        for param in &function.parameters {
            decls.push(format!("(declare-const {param} Int)")); // Simplified as Int
        }
        decls
    }
    fn verify_termination(&mut self, loop_info: &LoopInfo) -> bool {
        // Check if there's a decreasing measure
        if let Some(measure) = &loop_info.termination_measure {
            let query = SmtQuery {
                declarations: loop_info.variable_declarations.clone(),
                assertions: vec![
                    format!("(assert {})", loop_info.loop_condition),
                    loop_info.loop_body.clone(),
                    format!(
                        "(assert (>= {} {}))",
                        measure,
                        measure.replace('x', "x_next")
                    ),
                ],
                query: "(check-sat)".to_string(),
            };
            matches!(self.solve(&query), SmtResult::Unsatisfiable(_))
        } else {
            false // Can't prove termination without measure
        }
    }
    fn calculate_hash(&self, content: &str) -> String {
        use sha2::{Digest, Sha256};
        let mut hasher = Sha256::new();
        hasher.update(content);
        format!("{:x}", hasher.finalize())
    }
}
impl ProofCache {
    fn new() -> Self {
        Self {
            cache: HashMap::new(),
            hit_count: 0,
            miss_count: 0,
        }
    }
    fn get(&mut self, query_hash: &str) -> Option<SmtResult> {
        if let Some(cached) = self.cache.get(query_hash) {
            // Check if cache entry is still valid (not too old)
            if let Ok(elapsed) = cached.timestamp.elapsed() {
                if elapsed < Duration::from_secs(24 * 60 * 60) {
                    self.hit_count += 1;
                    return Some(cached.result.clone());
                }
            }
        }
        self.miss_count += 1;
        None
    }
    fn store(&mut self, query_hash: String, result: SmtResult) {
        self.cache.insert(
            query_hash.clone(),
            CachedProof {
                query_hash,
                result,
                timestamp: std::time::SystemTime::now(),
            },
        );
    }
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::ProofCache;
    ///
    /// let mut instance = ProofCache::new();
    /// let result = instance.get_hit_rate();
    /// // Verify behavior
    /// ```
    pub fn get_hit_rate(&self) -> f64 {
        let total = self.hit_count + self.miss_count;
        if total > 0 {
            self.hit_count as f64 / total as f64
        } else {
            0.0
        }
    }
}
// Supporting types
#[derive(Debug, Clone)]
pub struct Function {
    pub name: String,
    pub parameters: Vec<String>,
    pub parameter_types: Vec<String>,
    pub return_type: String,
    pub body_smt: String,
}
#[derive(Debug, Clone)]
pub struct FunctionSpec {
    pub preconditions: Vec<String>,
    pub postconditions: Vec<String>,
}
#[derive(Debug)]
pub struct VerificationResult {
    pub function_name: String,
    pub results: Vec<PostconditionResult>,
    pub verification_time: Duration,
}
#[derive(Debug)]
pub enum PostconditionResult {
    Satisfied(String),
    Violated {
        postcondition: String,
        counterexample: Model,
    },
    Timeout(String),
    Unknown {
        postcondition: String,
        reason: String,
    },
}
#[derive(Debug, Clone)]
pub struct LoopInfo {
    pub variable_declarations: Vec<String>,
    pub precondition: String,
    pub loop_condition: String,
    pub loop_body: String,
    pub termination_measure: Option<String>,
}
#[derive(Debug)]
pub struct LoopVerificationResult {
    pub initialization_valid: bool,
    pub maintenance_valid: bool,
    pub termination_valid: bool,
    pub invariant: String,
}
/// Bounded model checker for finding counterexamples
pub struct BoundedModelChecker {
    solver: SmtSolver,
    max_depth: usize,
}
impl BoundedModelChecker {
    pub fn new(solver_type: SolverType, max_depth: usize) -> Self {
        Self {
            solver: SmtSolver::new(solver_type),
            max_depth,
        }
    }
    /// Check property up to bounded depth
    /// # Examples
    ///
    /// ```
    /// use ruchy::notebook::testing::smt::BoundedModelChecker;
    ///
    /// let mut instance = BoundedModelChecker::new();
    /// let result = instance.check_bounded();
    /// // Verify behavior
    /// ```
    pub fn check_bounded(&mut self, property: &str, program: &Program) -> BoundedResult {
        for depth in 1..=self.max_depth {
            let unrolled = self.unroll_program(program, depth);
            let query = SmtQuery {
                declarations: program.variable_declarations.clone(),
                assertions: vec![unrolled, format!("(assert (not {}))", property)],
                query: "(check-sat)".to_string(),
            };
            match self.solver.solve(&query) {
                SmtResult::Satisfiable(model) => {
                    return BoundedResult::CounterExample { depth, model };
                }
                SmtResult::Unsatisfiable(_) => {
                    // Property holds at this depth, continue
                }
                SmtResult::Timeout => {
                    return BoundedResult::Timeout {
                        reached_depth: depth,
                    };
                }
                SmtResult::Unknown(reason) => {
                    return BoundedResult::Unknown { reason, depth };
                }
            }
        }
        BoundedResult::BoundedSafe {
            max_depth: self.max_depth,
        }
    }
    fn unroll_program(&self, _program: &Program, depth: usize) -> String {
        // Unroll loops and function calls up to specified depth
        let mut unrolled = String::new();
        for step in 0..depth {
            unrolled.push_str(&format!("(assert (= x_{} (f x_{})))\n", step + 1, step));
        }
        unrolled
    }
}
#[derive(Debug)]
pub enum BoundedResult {
    CounterExample { depth: usize, model: Model },
    BoundedSafe { max_depth: usize },
    Timeout { reached_depth: usize },
    Unknown { reason: String, depth: usize },
}
#[derive(Debug)]
pub struct Program {
    pub variable_declarations: Vec<String>,
    pub statements: Vec<String>,
}
trait DurationExt {
    fn from_hours(hours: u64) -> Duration;
}
impl DurationExt for Duration {
    fn from_hours(hours: u64) -> Duration {
        Duration::from_secs(hours * 3600)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashMap;

    #[test]
    fn test_smt_solver_new() {
        let _solver = SmtSolver::new(SolverType::Z3);
        // Constructor test - should create without panic
    }

    #[test]
    fn test_smt_solver_with_timeout() {
        let timeout = Duration::from_secs(30);
        let _solver = SmtSolver::with_timeout(SolverType::Z3, timeout);
        // Constructor with timeout should work
    }

    #[test]
    fn test_solve_simple_query() {
        let mut solver = SmtSolver::new(SolverType::Z3);
        let query = SmtQuery {
            declarations: vec!["(declare-fun x () Int)".to_string()],
            assertions: vec!["(assert (> x 0))".to_string()],
            query: "(check-sat)".to_string(),
        };

        let result = solver.solve(&query);
        // Should return some result
        match result {
            SmtResult::Satisfiable(_) => {}
            SmtResult::Unsatisfiable(_) => {}
            SmtResult::Unknown(_) => {}
            SmtResult::Timeout => {}
        }
    }

    #[test]
    fn test_verify_function_basic() {
        let mut solver = SmtSolver::new(SolverType::Z3);
        let function = Function {
            name: "add_one".to_string(),
            parameters: vec!["x".to_string()],
            parameter_types: vec!["Int".to_string()],
            return_type: "Int".to_string(),
            body_smt: "(+ x 1)".to_string(),
        };

        let spec = FunctionSpec {
            preconditions: vec!["(> x 0)".to_string()],
            postconditions: vec!["(> result 0)".to_string()],
        };

        let result = solver.verify_function(&function, &spec);
        assert_eq!(result.function_name, "add_one");
    }

    #[test]
    fn test_verify_loop_invariant() {
        let mut solver = SmtSolver::new(SolverType::Z3);
        let loop_info = LoopInfo {
            variable_declarations: vec![
                "(declare-fun i () Int)".to_string(),
                "(declare-fun n () Int)".to_string(),
            ],
            precondition: "(and (= i 0) (>= n 0))".to_string(),
            loop_condition: "(< i n)".to_string(),
            loop_body: "(= i_next (+ i 1))".to_string(),
            termination_measure: Some("(- n i)".to_string()),
        };

        let invariant = "(and (>= i 0) (<= i n))";
        let result = solver.verify_loop_invariant(&loop_info, invariant);
        assert_eq!(result.invariant, invariant);
    }

    #[test]
    fn test_smt_query_creation() {
        let query = SmtQuery {
            declarations: vec!["(declare-fun x () Int)".to_string()],
            assertions: vec!["(assert (> x 0))".to_string()],
            query: "(check-sat)".to_string(),
        };

        assert_eq!(query.declarations.len(), 1);
        assert_eq!(query.assertions.len(), 1);
        assert_eq!(query.query, "(check-sat)");
    }

    #[test]
    fn test_model_creation() {
        let mut assignments = HashMap::new();
        assignments.insert("x".to_string(), "5".to_string());
        assignments.insert("y".to_string(), "10".to_string());

        let model = Model { assignments };

        assert_eq!(model.assignments.len(), 2);
        assert_eq!(model.assignments.get("x"), Some(&"5".to_string()));
    }

    #[test]
    fn test_proof_creation() {
        let proof = Proof {
            steps: vec![
                "step 1: assume x > 0".to_string(),
                "step 2: derive y > 0".to_string(),
            ],
            conclusion: "therefore x + y > 0".to_string(),
        };

        assert_eq!(proof.steps.len(), 2);
        assert!(!proof.conclusion.is_empty());
    }

    #[test]
    fn test_solver_type_variants() {
        let types = [
            SolverType::Z3,
            SolverType::CVC4,
            SolverType::Yices,
            SolverType::Vampire,
        ];

        assert_eq!(types.len(), 4);
    }

    #[test]
    fn test_function_creation() {
        let function = Function {
            name: "add_one".to_string(),
            parameters: vec!["x".to_string()],
            parameter_types: vec!["Int".to_string()],
            return_type: "Int".to_string(),
            body_smt: "(+ x 1)".to_string(),
        };

        assert_eq!(function.name, "add_one");
        assert_eq!(function.parameters.len(), 1);
    }

    #[test]
    fn test_function_spec_creation() {
        let spec = FunctionSpec {
            preconditions: vec!["(> x 0)".to_string()],
            postconditions: vec!["(> result 0)".to_string()],
        };

        assert_eq!(spec.preconditions.len(), 1);
        assert_eq!(spec.postconditions.len(), 1);
    }

    #[test]
    fn test_loop_info_creation() {
        let loop_info = LoopInfo {
            variable_declarations: vec![
                "(declare-fun i () Int)".to_string(),
                "(declare-fun n () Int)".to_string(),
            ],
            precondition: "(and (= i 0) (>= n 0))".to_string(),
            loop_condition: "(< i n)".to_string(),
            loop_body: "(= i_next (+ i 1))".to_string(),
            termination_measure: Some("(- n i)".to_string()),
        };

        assert_eq!(loop_info.variable_declarations.len(), 2);
        assert!(loop_info.termination_measure.is_some());
    }

    #[test]
    fn test_bounded_model_checker_new() {
        let _checker = BoundedModelChecker::new(SolverType::Z3, 10);
        // Constructor should work
    }

    #[test]
    fn test_duration_ext() {
        let duration = <Duration as DurationExt>::from_hours(2);
        assert_eq!(duration, Duration::from_secs(7200));
    }
}