@@ -15,13 +15,15 @@ impl Visitor for DesugarConditionals {
1515 fn signature ( & mut self , sig : & mut ast:: Signature ) -> Action {
1616 // Process conditional constraints and convert them to facts
1717 let mut new_facts = Vec :: new ( ) ;
18-
18+
1919 for conditional_constraint in & sig. conditional_constraints {
2020 match self . desugar_conditional_constraint ( conditional_constraint) {
2121 Ok ( facts) => new_facts. extend ( facts) ,
2222 Err ( err) => {
2323 // Report error immediately and exit
24- eprintln ! ( "[ERROR] Conditional constraint desugaring failed:" ) ;
24+ eprintln ! (
25+ "[ERROR] Conditional constraint desugaring failed:"
26+ ) ;
2527 eprintln ! ( " - {}" , err. kind) ;
2628 std:: process:: exit ( 1 ) ;
2729 }
@@ -37,7 +39,6 @@ impl Visitor for DesugarConditionals {
3739 Action :: Continue
3840 }
3941 }
40-
4142}
4243
4344impl DesugarConditionals {
@@ -131,58 +132,46 @@ impl DesugarConditionals {
131132 // Handle all comparison operators
132133 match condition. op {
133134 OrderOp :: Gt => {
134- // !(a > b) becomes (a <= b), which we represent as (b >= a)
135- Ok ( ast:: OrderConstraint :: gte (
136- condition. right . clone ( ) ,
135+ // !(a > b) becomes (a <= b)
136+ Ok ( ast:: OrderConstraint :: lte (
137137 condition. left . clone ( ) ,
138+ condition. right . clone ( ) ,
138139 ) )
139140 }
140141 OrderOp :: Gte => {
141- // !(a >= b) becomes (a < b), which we represent as (b > a)
142+ // !(a >= b) becomes (a < b)
143+ Ok ( ast:: OrderConstraint :: lt (
144+ condition. left . clone ( ) ,
145+ condition. right . clone ( ) ,
146+ ) )
147+ }
148+ OrderOp :: Lt => {
149+ // !(a < b) becomes (a >= b)
150+ Ok ( ast:: OrderConstraint :: gte (
151+ condition. left . clone ( ) ,
152+ condition. right . clone ( ) ,
153+ ) )
154+ }
155+ OrderOp :: Lte => {
156+ // !(a <= b) becomes (a > b)
142157 Ok ( ast:: OrderConstraint :: gt (
158+ condition. left . clone ( ) ,
143159 condition. right . clone ( ) ,
160+ ) )
161+ }
162+ OrderOp :: Neq => {
163+ // !(a != b) becomes (a == b)
164+ Ok ( ast:: OrderConstraint :: eq (
144165 condition. left . clone ( ) ,
166+ condition. right . clone ( ) ,
145167 ) )
146168 }
147169 OrderOp :: Eq => {
148- // !(a == b) - Handle binary/boolean domain cases
149- if let ast:: Expr :: Concrete ( n) = & condition. right {
150- // For boolean/binary domains, flip 0<->1
151- if * n == 0 || * n == 1 {
152- let negated_val = if * n == 0 { 1 } else { 0 } ;
153- Ok ( ast:: OrderConstraint :: eq (
154- condition. left . clone ( ) ,
155- ast:: Expr :: concrete ( negated_val) ,
156- ) )
157- } else {
158- Err ( Error :: misc ( format ! (
159- "Cannot negate equality condition with non-boolean literal: {} == {}" ,
160- "expr" , n
161- ) ) )
162- }
163- } else if let ast:: Expr :: Concrete ( n) = & condition. left {
164- // Handle case where left side is the literal
165- if * n == 0 || * n == 1 {
166- let negated_val = if * n == 0 { 1 } else { 0 } ;
167- Ok ( ast:: OrderConstraint :: eq (
168- condition. right . clone ( ) ,
169- ast:: Expr :: concrete ( negated_val) ,
170- ) )
171- } else {
172- Err ( Error :: misc ( format ! (
173- "Cannot negate equality condition with non-boolean literal: {} == {}" ,
174- n, "expr"
175- ) ) )
176- }
177- } else {
178- // For complex expressions, we can't negate equality directly
179- // This would require disjunction (A != B means A < B || A > B)
180- // Since Filament doesn't have disjunction, this is unsupported
181- Err ( Error :: misc (
182- "Cannot negate equality between complex expressions. \
183- Consider restructuring your constraint to use comparison operators.". to_string ( )
184- ) )
185- }
170+ // !(a == b) becomes (a != b)
171+ Ok ( ast:: OrderConstraint :: neq (
172+ condition. left . clone ( ) ,
173+ condition. right . clone ( ) ,
174+ ) )
186175 }
187176 }
188177 }
0 commit comments