问题标签 [gmpy]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
97 浏览

python - How to tackle calculating then verifying 10^8 solutions to find the one true answer?

I have a number which is 615 digits in length. Throughout the number, there 8 fixed places where a digit is missing. I have to find what those missing digits are. So there are 10^8 possibilities. After computing them I have to raise a ciphetext to each possible number, and see what the output is (mod N), and see which number gives the correct output. In other words, I am trying to find the decryption key in an RSA problem. My main concern right now is how to efficiently/properly create all 10^8 possible answers.

I am using gmpy2, and to get that to work, I had to download Python2.7 just to not get an error when trying to install gmpy2. I hope they are adequate enough to tackle this problem. If not, I would really appreciate someone pointing me in the correct direction.

I have not tried anything yet, as Im sure this will take hours to compute. So I really want to make sure I am doing everything correct so that if I let my laptop run for a couple hours, I do not mess up the insides, nor will it freeze and I will be sitting here not knowing if my laptop messed up, or if its still computing.

So I suppose I am trying to seek advice on how I should proceed further.

In terms of actual code, I suppose looping through 0-9 8 times is not that hard, but I dont know how to a number into another number. In Python, how do I make it so that a number will only be inserted into the position I need it to? The number looks like this example:

where each "_" is where a number is missing.

I am completely at a loss on how to do this.

Once all the numbers are generated, I aim to loop through them all and raise them until I get the answer required. This part seems to be a bit easier, as it seems like just a simple loop.

So I guess my main question is how to loop through 10^8 numbers but placing them in a specific spot inside a number that is already 615 digits long? I am seeking advice on technical as well as code design so as to not take too long to generate them all.

Thank you for reading.

0 投票
1 回答
90 浏览

python-3.x - How to get the gmpy2 module in RPI2 Buildroot

I am unable to get the gmpy2 Python module working in a Buildroot build for Raspberry Pi2. Buildroot does not include the gmpy2 module by default.

Buildroot does not include the GCC as well, so I compiled the gmpy2 module from source on Raspbian on another RPI2 board (having the same Python version -- 3.7.2 -- as the Buildroot board) and copied the resulting gmpy2.cpython-37m-arm-linux-gnueabihf.so to Buildroot board's /usr/lib/python3.7/site-packages/ and put a link gmpy2.so in the same directory.

I expected Python to be able to see the module, but instead I get:

#xA;

Any help is much appreciated!

0 投票
1 回答
825 浏览

google-colaboratory - 有没有人在 colab 上安装 ludwig 时遇到过同样的错误?

在 colab 上安装 ludwig 时出现以下错误。尝试了一些事情,但无法解决这个问题。

错误:命令“/usr/bin/python3 -u -c 'import setuptools, tokenize; file ='”'“'/tmp/pip-install-klvuqhbh/gmpy/setup.py'“'”';f=getattr (tokenize, '"'"'open'"'"', open)( file );code=f.read().replace('"'"'\r\n'"'"', '"'" '\n'"'"');f.close();exec(compile(code, file , '"'"'exec'"'"'))' install --record /tmp/pip-record-uo0mqy_u /install-record.txt --single-version-externally-managed --compile" 失败,错误代码 1 在 /tmp/pip-install-klvuqhbh/gmpy/**

0 投票
1 回答
266 浏览

python - gmpy2 mpfr 值限制为 301,033 位,其中 301,032 位是正确的

我正在编写一个 Python3(64 位)程序,以使用 64 位 Windows 10 上的 gmpy2 模块将 pi 计算到至少一百万位。我正在使用 Chudnovsky 算法。级数算术是天才,易于理解且易于实现。我遇到的问题是用 gmpy2 表示非常大的精度实数。

我把这个问题归结为一个非常简单的测试。

  1. 检查 gmpy2 系统限制。他们看起来很棒。
  2. 根据需要为一百万位 pi 设置精度上下文。
  3. 用一百万位 pi 分配一个字符串变量。
  4. 使用 mpfr('million digit pi') 为 mpfr 变量分配字符串转换
  5. 打印字符串变量,它有一百万位数字。
  6. 打印 mpfr 它有超过 300,000 位数字。

当我将 mpfr 转换为字符串并打印时,我得到了类似的结果。

这里发生了什么,我如何从 gmpy2 中挤出一百万位精度?

在我的输出中,我得到了打印的最大值、最小值、上下文、百万位 pi 字符串和大约 pi 的前 300,000 个(给或取)位。我很想准确地向您展示输出,但系统指责我格式精美的输出是代码,并且不让我这样做。我想不出办法。

0 投票
1 回答
3889 浏览

python - Python:Windows 10 上的“pip install gmpy”返回“cl.exe”失败,退出状态为 2”

我在 Windows10 上安装了 Pyhton 3.7,当我运行pip install gmpy控制台时返回此错误:

错误在这一行:

基本上,这意味着 Python 需要cl.exe并期望它:

没问题,我转到环境变量,然后为我的用户和系统添加该路径:

在此处输入图像描述

然后我通过在终端中cl.exe输入来检查路径是否成功,它可以工作:cl

在此处输入图像描述

但是当我再次运行时,我遇到pip install gmpy了同样的错误。

编辑:我也试过了pip install gmpy2,我收到了同样的错误。

我哪里错了?

0 投票
1 回答
3958 浏览

python - Python 3.7:无法在 Windows 10 的 venv 中安装 gmpy2

我正在尝试gmpy2在 Windows 10 的虚拟环境中安装。

最初,我收到以下错误。

通过从https://visualstudio.microsoft.com/downloads/安装Visual Studio 的构建工具,我能够克服这个错误。

我又试了一次,这次我得到了以下错误。

我尝试将版本指定为2.1.0a4,然后指定为,然后指定2.1.0a22.0.8. 但我得到了同样的错误。

注意:我正在尝试通过PyCharm Settings -> Project Interpreter安装这个包。

0 投票
1 回答
155 浏览

python - 是否有与 python gmpy2 库 divm(...) 函数相同的 c++ gmp 库函数?

正如标题所说,我试图在 C++ gmp 库中找到一个与 gmpy2 python 库的 divm(...) 函数执行相同操作的函数。

我无法想象 gmpy2 有这个方法,而 gmp C++ 库没有任何东西可以做同样的计算。

如果这不存在,我将不胜感激有关从头开始制作 divm 函数的任何建议(仍然必须使用 gmp,因为我正在通过 mpz_class 处理大于标准整数的值)。

谢谢!

0 投票
1 回答
17 浏览

series - .series() 的问题和从 mpmath 的转换

我遇到了以下看似奇怪的行为(这是一个显示基本问题的测试用例)。

这会产生类似“TypeError:gmpy.mpq() 需要数字或字符串参数”的错误

另一方面,如果我将 1.0 更改为 1:

它给出了正确的答案。有人可以解释我为什么吗?

0 投票
1 回答
260 浏览

python - Cython 具有不同类型的相同类

我有两个 cdef 类BC它们的方法完全相同。它们之间的唯一区别是它们的属性类型:一个有mpz属性,另一个有int属性。

我的第一个猜测是使用一个抽象类A,它会被Band覆盖C。问题是 Cython 显然不希望我覆盖属性(另外,我应该为抽象类的属性赋予哪种类型?)。我这样做的错误是:

我的第二个猜测是使用像这样的融合类型的单个类:

但是 Cython 抱怨我使用这种类型进行操作(例如%,即使它是为这两种类型定义的)。我得到的错误是:

现在,我复制/粘贴了这两个类,但这是一个肮脏的 hack,显然,每次我必须修改这些类的方法时,我都会哭:)

我认为要走的路是使用融合类型,但是我怎样才能找到解决这个问题的方法呢?

0 投票
0 回答
194 浏览

python - 如何在 Heroku 中使用 gmpy2?

我正在尝试将 gmpy2 作为我在 Heroku 中的 Python 包的一部分,但我在构建过程中遇到了问题。

我正在使用两个不同的 buildpack:标准 Python buildpack 和 APT (heroku-buildpack-apt),因此我可以安装以下依赖项:

  • libmpfr-dev
  • libmpc-开发
  • libgmp-dev
  • libgmp3-dev

这是构建日志中的错误:

我应该看什么?我可以在这个 buildpack 中使用 gcc 命令的标志吗?