kumi 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CLAUDE.md +160 -8
  3. data/README.md +278 -200
  4. data/{documents → docs}/AST.md +29 -29
  5. data/{documents → docs}/DSL.md +3 -3
  6. data/{documents → docs}/SYNTAX.md +107 -24
  7. data/docs/features/README.md +45 -0
  8. data/docs/features/analysis-cascade-mutual-exclusion.md +89 -0
  9. data/docs/features/analysis-type-inference.md +42 -0
  10. data/docs/features/analysis-unsat-detection.md +71 -0
  11. data/docs/features/array-broadcasting.md +170 -0
  12. data/docs/features/input-declaration-system.md +42 -0
  13. data/docs/features/performance.md +16 -0
  14. data/examples/federal_tax_calculator_2024.rb +43 -40
  15. data/examples/game_of_life.rb +97 -0
  16. data/examples/simple_rpg_game.rb +1000 -0
  17. data/examples/static_analysis_errors.rb +178 -0
  18. data/examples/wide_schema_compilation_and_evaluation_benchmark.rb +1 -1
  19. data/lib/kumi/analyzer/analysis_state.rb +37 -0
  20. data/lib/kumi/analyzer/constant_evaluator.rb +22 -16
  21. data/lib/kumi/analyzer/passes/broadcast_detector.rb +251 -0
  22. data/lib/kumi/analyzer/passes/{definition_validator.rb → declaration_validator.rb} +8 -7
  23. data/lib/kumi/analyzer/passes/dependency_resolver.rb +106 -26
  24. data/lib/kumi/analyzer/passes/input_collector.rb +105 -23
  25. data/lib/kumi/analyzer/passes/name_indexer.rb +2 -2
  26. data/lib/kumi/analyzer/passes/pass_base.rb +11 -28
  27. data/lib/kumi/analyzer/passes/semantic_constraint_validator.rb +110 -0
  28. data/lib/kumi/analyzer/passes/toposorter.rb +45 -9
  29. data/lib/kumi/analyzer/passes/type_checker.rb +34 -11
  30. data/lib/kumi/analyzer/passes/type_consistency_checker.rb +2 -1
  31. data/lib/kumi/analyzer/passes/type_inferencer.rb +128 -21
  32. data/lib/kumi/analyzer/passes/unsat_detector.rb +312 -13
  33. data/lib/kumi/analyzer/passes/visitor_pass.rb +4 -3
  34. data/lib/kumi/analyzer.rb +41 -24
  35. data/lib/kumi/atom_unsat_solver.rb +45 -0
  36. data/lib/kumi/cli.rb +449 -0
  37. data/lib/kumi/compiler.rb +194 -16
  38. data/lib/kumi/constraint_relationship_solver.rb +638 -0
  39. data/lib/kumi/domain/validator.rb +0 -4
  40. data/lib/kumi/error_reporter.rb +6 -6
  41. data/lib/kumi/evaluation_wrapper.rb +20 -4
  42. data/lib/kumi/explain.rb +28 -28
  43. data/lib/kumi/export/node_registry.rb +26 -12
  44. data/lib/kumi/export/node_serializers.rb +1 -1
  45. data/lib/kumi/function_registry/collection_functions.rb +117 -9
  46. data/lib/kumi/function_registry/function_builder.rb +4 -3
  47. data/lib/kumi/function_registry.rb +8 -2
  48. data/lib/kumi/input/type_matcher.rb +3 -0
  49. data/lib/kumi/input/validator.rb +0 -3
  50. data/lib/kumi/parser/declaration_reference_proxy.rb +36 -0
  51. data/lib/kumi/parser/dsl_cascade_builder.rb +19 -8
  52. data/lib/kumi/parser/expression_converter.rb +80 -12
  53. data/lib/kumi/parser/input_builder.rb +40 -9
  54. data/lib/kumi/parser/input_field_proxy.rb +46 -0
  55. data/lib/kumi/parser/input_proxy.rb +3 -3
  56. data/lib/kumi/parser/nested_input.rb +15 -0
  57. data/lib/kumi/parser/parser.rb +2 -0
  58. data/lib/kumi/parser/schema_builder.rb +10 -9
  59. data/lib/kumi/parser/sugar.rb +171 -18
  60. data/lib/kumi/schema.rb +3 -1
  61. data/lib/kumi/schema_instance.rb +69 -3
  62. data/lib/kumi/syntax/array_expression.rb +15 -0
  63. data/lib/kumi/syntax/call_expression.rb +11 -0
  64. data/lib/kumi/syntax/cascade_expression.rb +11 -0
  65. data/lib/kumi/syntax/case_expression.rb +11 -0
  66. data/lib/kumi/syntax/declaration_reference.rb +11 -0
  67. data/lib/kumi/syntax/hash_expression.rb +11 -0
  68. data/lib/kumi/syntax/input_declaration.rb +12 -0
  69. data/lib/kumi/syntax/input_element_reference.rb +12 -0
  70. data/lib/kumi/syntax/input_reference.rb +12 -0
  71. data/lib/kumi/syntax/literal.rb +11 -0
  72. data/lib/kumi/syntax/root.rb +1 -0
  73. data/lib/kumi/syntax/trait_declaration.rb +11 -0
  74. data/lib/kumi/syntax/value_declaration.rb +11 -0
  75. data/lib/kumi/types/compatibility.rb +8 -0
  76. data/lib/kumi/types/validator.rb +1 -1
  77. data/lib/kumi/vectorization_metadata.rb +108 -0
  78. data/lib/kumi/version.rb +1 -1
  79. data/scripts/generate_function_docs.rb +22 -10
  80. metadata +38 -17
  81. data/CHANGELOG.md +0 -25
  82. data/lib/kumi/domain.rb +0 -8
  83. data/lib/kumi/input.rb +0 -8
  84. data/lib/kumi/syntax/declarations.rb +0 -23
  85. data/lib/kumi/syntax/expressions.rb +0 -30
  86. data/lib/kumi/syntax/terminal_expressions.rb +0 -27
  87. data/lib/kumi/syntax.rb +0 -9
  88. data/test_impossible_cascade.rb +0 -51
  89. /data/{documents → docs}/FUNCTIONS.md +0 -0
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kumi
4
- module Syntax
5
- module Expressions
6
- CallExpression = Struct.new(:fn_name, :args) do
7
- include Node
8
- def children = args
9
- end
10
- CascadeExpression = Struct.new(:cases) do
11
- include Node
12
- def children = cases
13
- end
14
-
15
- WhenCaseExpression = Struct.new(:condition, :result) do
16
- include Node
17
- def children = [condition, result]
18
- end
19
-
20
- ListExpression = Struct.new(:elements) do
21
- include Node
22
- def children = elements
23
-
24
- def size
25
- elements.size
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "node"
4
-
5
- module Kumi
6
- module Syntax
7
- module TerminalExpressions
8
- # Leaf expressions that represent a value or reference and terminate a branch.
9
-
10
- Literal = Struct.new(:value) do
11
- include Node
12
- def children = []
13
- end
14
-
15
- # For field usage/reference in expressions (input.field_name)
16
- FieldRef = Struct.new(:name) do
17
- include Node
18
- def children = []
19
- end
20
-
21
- Binding = Struct.new(:name) do
22
- include Node
23
- def children = []
24
- end
25
- end
26
- end
27
- end
data/lib/kumi/syntax.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kumi
4
- module Syntax
5
- include Declarations
6
- include Expressions
7
- include TerminalExpressions
8
- end
9
- end
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require_relative "lib/kumi"
5
-
6
- # This test demonstrates that the UnsatDetector still correctly catches
7
- # genuinely impossible cascade conditions after our fix
8
-
9
- puts "🧪 Testing UnsatDetector Catches Impossible Cascade Conditions"
10
- puts "=" * 60
11
-
12
- begin
13
- impossible_schema = Class.new do
14
- extend Kumi::Schema
15
-
16
- schema do
17
- input do
18
- integer :age, domain: 0..150
19
- end
20
-
21
- # These traits are individually satisfiable
22
- trait :very_young, input.age, :<, 25
23
- trait :very_old, input.age, :>, 65
24
-
25
- # This cascade condition combines contradictory traits - should be caught!
26
- value :impossible_condition do
27
- on :very_young, :very_old, "Impossible: young AND old" # age < 25 AND age > 65
28
- base "Normal"
29
- end
30
- end
31
- end
32
-
33
- puts "❌ ERROR: Should have caught impossible cascade condition!"
34
-
35
- rescue Kumi::Errors::SemanticError => e
36
- if e.message.include?("conjunction") && e.message.include?("logically impossible")
37
- puts "✅ CORRECTLY CAUGHT impossible cascade condition!"
38
- puts " Error: #{e.message}"
39
- puts
40
- puts " This proves the UnsatDetector still works for genuinely impossible conditions"
41
- puts " while allowing valid mutually exclusive cascades."
42
- else
43
- puts "❌ UNEXPECTED ERROR: #{e.message}"
44
- end
45
- end
46
-
47
- puts
48
- puts "🎉 UnsatDetector Fix Validation Complete!"
49
- puts " ✅ Valid mutually exclusive cascades: WORK"
50
- puts " ✅ Impossible cascade conditions: CAUGHT"
51
- puts " ✅ Existing functionality: PRESERVED"
File without changes