# Same code, (vastly) different results locally and at aleph.sagemath.org

I have SageMath 9.4 for Ubuntu 20.04 downloaded from a french mirror (link) and I am trying to run an LWE estimator (link) by Albrecht et al (link).

### Running on Aleph

Without any problem, I can paste the estimator.py code (link) into Aleph (link), followed by my parameters, e.g.:

```
n, stdv = 1024, 2^-30.0
set_verbose(1)
_ = estimate_lwe(n, sqrt(2*pi)*stdv, 2^32, reduction_cost_model=BKZ.sieve, secret_distribution=(0,1))
```

from which I obtain

```
Warning: the LWE secret is assumed to have Hamming weight 512.
usvp: rop: â‰ˆ2^108.0, red: â‰ˆ2^108.0, Î´_0: 1.005242, Î²: 266, d: 1889, m: 864, repeat: 1, k: 0, postprocess: 0
dec: rop: â‰ˆ2^131.5, m: 1198, red: â‰ˆ2^131.5, Î´_0: 1.004529, Î²: 332, d: 2222, babai: â‰ˆ2^117.5, babai_op: â‰ˆ2^132.6, repeat: 17, Îµ: 0.250000
dual: rop: â‰ˆ2^112.1, m: 994, red: â‰ˆ2^112.1, Î´_0: 1.005070, Î²: 280, repeat: â‰ˆ2^60.8, d: 1986, c: 8, k: 32, postprocess: 1
```

which tells me that I have 108.0 bits of security (2nd line: `usvp: rop: â‰ˆ2^108.0`

). Until here -- fine.

### Running locally

Now I need to process a heap of parameters automatically, which I am trying to run locally (using the aforementioned version of SageMath). Problems arise (with 1-3 possibly irrelevant, 4 indeed relevant):

- With the very same code I get:
`ImportError: cannot import name complex_mpfr`

, which seems to be resolved by adding`import sage.all`

in the very beginning. - Then I get:
`n, stdv = 1024, 2^-30.0 .. TypeError: unsupported operand type(s) for ^: 'int' and 'float'`

which I fix by replacing`2^-30.0`

with`9.3132257e-10`

. - Next run:
`NameError: name 'set_verbose' is not defined`

which I solved by importing`from sage.misc.verbose import verbose, set_verbose, get_verbose`

(still some warnings -- deprecated stuff and syntax -- which I ignore) - Final run: I get the results,

but with completely different numbers:

```
Warning: the LWE secret is assumed to have Hamming weight 512.
usvp: rop: â‰ˆ2^44.9, red: â‰ˆ2^44.9, Î´_0: 1.013310, Î²: 40, d: 1024, m: -1, repeat: 1, k: 0, postprocess: 0
dec: rop: â‰ˆ2^43.6, m: -614, red: â‰ˆ2^43.6, Î´_0: 1.021759, Î²: 40, d: 410, babai: 1, babai_op: â‰ˆ2^15.1, repeat: 1, Îµ: 1
```

(and then `TypeError: unable to convert '2.5275472536193645856387667200778292581e-30+2.6845375638424411831060264943943048062e9*I' to a real number`

which I ignore)

Compared to 108.0 from Aleph, my local result 44.9 is completely false, though running the same code. I also pasted the modified code into Aleph and it still gives 108.0.

Find my final code at Pastebin (link) (gives results both on Aleph and locally).

Find the links at https://stackoverflow.com/questions/71065271 (https://stackoverflow.com/questions/7...)

Please check your reliance on Sage's preparser, e.g. by running

`preparse(""""your code here""")`

inside Sage. For example`^`

between numbers should be replaced by`**`

when using Python directly without the preparser (as you seem to be doing). In Python,`2^32`

is`34`

(bitwise xor).(upvote for your comment) preparse did the job, but I'd rather recommend to run

`$ sage --preparse estimator.sage`

and only then`$ sage estimator.sage.py`