@@ -138,35 +138,35 @@ Since we want to rewrite statements of our dialect, the entry point we define in
138138``` python
139139from dataclasses import dataclass
140140
141- from kirin.rewrite import abc, result
141+ from kirin.rewrite import abc
142142from kirin.dialects import py
143143
144144
145145@dataclass
146146class RewritePauliMult (abc .RewriteRule ):
147- def rewrite_Statement (self , node : ir.Statement) -> result .RewriteResult:
147+ def rewrite_Statement (self , node : ir.Statement) -> abc .RewriteResult:
148148 if not isinstance (node, py.binop.Mult): # (1)!
149- return result .RewriteResult()
149+ return abc .RewriteResult()
150150
151151 if not isinstance (node.lhs.owner, PauliOperator) and not isinstance (node.rhs.owner, PauliOperator): # (2)!
152- return result .RewriteResult()
152+ return abc .RewriteResult()
153153
154154 if isinstance (node.lhs.owner, py.Constant): # (3)!
155155 new_op = self .number_pauli_mult(node.lhs.owner, node.rhs.owner)
156156 node.replace_by(new_op)
157- return result .RewriteResult(has_done_something = True )
157+ return abc .RewriteResult(has_done_something = True )
158158 elif isinstance (node.rhs.owner, py.Constant): # (4)!
159159 new_op = self .number_pauli_mult(node.rhs.owner, node.lhs.owner)
160160 node.replace_by(new_op)
161- return result .RewriteResult(has_done_something = True )
161+ return abc .RewriteResult(has_done_something = True )
162162
163163
164164 if not isinstance (node.lhs.owner, PauliOperator) or not isinstance (node.rhs.owner, PauliOperator): # (5)!
165- return result .RewriteResult()
165+ return abc .RewriteResult()
166166
167167 new_op = self .pauli_pauli_mult(node.lhs.owner, node.rhs.owner) # (6)!
168168 node.replace_by(new_op)
169- return result .RewriteResult(has_done_something = True )
169+ return abc .RewriteResult(has_done_something = True )
170170
171171 ...
172172```
@@ -411,9 +411,9 @@ The basic principle is the same as before.
411411``` python
412412@dataclass
413413class RewriteDistributeMult (abc .RewriteRule ):
414- def rewrite_Statement (self , node : ir.Statement) -> result .RewriteResult:
414+ def rewrite_Statement (self , node : ir.Statement) -> abc .RewriteResult:
415415 if not isinstance (node, py.binop.Mult): # (1)!
416- return result .RewriteResult()
416+ return abc .RewriteResult()
417417
418418 if isinstance (node.lhs.owner, py.binop.Add): # (2)!
419419 m1 = py.binop.Mult(node.lhs.owner.lhs, node.rhs) # (3)!
@@ -424,7 +424,7 @@ class RewriteDistributeMult(abc.RewriteRule):
424424
425425 a = py.binop.Add(m1.result, m2.result) # (5)!
426426 node.replace_by(a) # (6)!
427- return result .RewriteResult(has_done_something = True )
427+ return abc .RewriteResult(has_done_something = True )
428428
429429 if isinstance (node.rhs.owner, py.binop.Add):
430430 m1 = py.binop.Mult(node.lhs, node.rhs.owner.lhs)
@@ -435,9 +435,9 @@ class RewriteDistributeMult(abc.RewriteRule):
435435
436436 a = py.binop.Add(m1.result, m2.result)
437437 node.replace_by(a)
438- return result .RewriteResult(has_done_something = True )
438+ return abc .RewriteResult(has_done_something = True )
439439
440- return result .RewriteResult()
440+ return abc .RewriteResult()
441441```
442442
4434431 . Again, we want to make sure we're looking at a multiplication.
@@ -633,7 +633,7 @@ print(cool_example()) # (2)!
6336331 . Register an implementation for the statement ` X() ` .
6346342 . Notice that we are actually * calling* the function this time.
635635
636- And, sure enough, when running the code, we now obtain a $2x2$ matrix:
636+ And, sure enough, when running the code, we now obtain a 2 x 2 matrix:
637637
638638``` python
639639[[ 2 .+ 2.j - 2 .+ 2.j ]
@@ -675,7 +675,7 @@ Amazing.
675675
676676But, wait:
677677if constant folding can evaluate additions, couldn't it also evaluate multiplications?
678- Wouldn't the make our multiplication rewrite pass obsolete?
678+ Wouldn't that make our multiplication rewrite pass obsolete?
679679Sort of:
680680this would mean that you still evaluate a whole bunch of matrix products, just at compile time rather than at runtime.
681681Our rewriting pass, instead uses a symbolic approach to rewrite multiplications without the need to actually evaluate a matrix multiplication.
0 commit comments