# LeveledSHEBase\<Element\>::EvalAutomorphism code order

**URL:** <https://openfhe.discourse.group/t/leveledshebase-element-evalautomorphism-code-order/1802>\
**Category:** Library Questions\
**Created:** [December 23, 2024, 5:44am UTC](https://openfhe.discourse.group/t/leveledshebase-element-evalautomorphism-code-order/1802 "2024-12-23T05:44:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhaoqiming](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zhaoqiming](https://openfhe.discourse.group/u/zhaoqiming)\
**Post date:** [December 23, 2024, 5:44am UTC](https://openfhe.discourse.group/t/leveledshebase-element-evalautomorphism-code-order/1802/1 "2024-12-23T05:44:46Z")

</div>

hello, why do KeySwitchInPlace first in LeveledSHEBase::EvalAutomorphism?  
If I change the code order, the result is wrong.

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [December 23, 2024, 10:29pm UTC](https://openfhe.discourse.group/t/leveledshebase-element-evalautomorphism-code-order/1802/2 "2024-12-23T22:29:07Z")

</div>

Same answer as for [EvalAutomorphismKeyGen ModInverse index - #2 by ypolyakov](https://openfhe.discourse.group/t/evalautomorphismkeygen-modinverse-index/1801/2) It is needed for the improved (double) hoisting optimization.
