简体   繁体   English

如何使用多项式代替位来提高性能?

[英]How to use polynomials instead of bits to improve the performance?

I have a 128-bit string, and my supervisor has asked me to represent those 128 bits as a polynomial. 我有一个128位的字符串,我的主管要求我将这些128位表示为多项式。 This is a scan of the paper he was writing on: 这是他所写论文的扫描:

将位转换为多项式

His idea is, since we are eliminating the 0s from these bits, we will be able to perform the next operations (most of which are XOR between the bits/polynomials) much faster than if we worked on all bits. 他的想法是,由于我们从这些位中消除了0,因此与执行所有位相比,我们将能够以更快的速度执行下一个运算(其中大多数是位/多项式之间的XOR)。

I understand what the requirement is, and I can do it on paper, and also in the application. 我了解要求是什么,我可以在纸上以及在应用程序中做到。 But my way will not achieve his goal, which is improving the performance. 但是我的方法无法实现他的目标,那就是提高性能。 He actually said that there are libraries already that do this, but unfortunately I couldn't find any. 他实际上说已经有图书馆这样做,但是不幸的是我找不到任何图书馆。 The only thing I found was a Polynomial class that evaluates polynomials, which is not what I want. 我发现的唯一东西是评估多项式的​​多项式类,这不是我想要的。

So do you guys know how can I implement this to improve the performance? 那么,你们知道我该如何实施以提高性能? Any code/snippets/articles is very much appreciated. 非常感谢任何代码/代码片段/文章。

The application is written in Java, if that makes any difference. 该应用程序用Java编写,如果有任何不同的话。

Thanks, 谢谢,

Mota 莫塔

Update: 更新:

My supervisor says that this C library will do the task. 我的主管说,这个C库将完成任务。 I couldn't though figure out how it works and how it will do this. 我虽然无法弄清楚它是如何工作的以及它将如何做到这一点。

Is your supervisor familiar with a BitSet ? 您的主管熟悉BitSet吗? 128 bits is 16 bytes, which could be stored as 2 longs . 128位是16个字节,可以存储为2个longs However, using a BitSet, you won't need to worry about dealing with the combination of 2 longs . 但是,使用BitSet无需担心处理2个longs的组合。 BitSet also provides methods for all the common bit operations. BitSet还提供了用于所有常见位操作的方法。 I think you'd be pretty hard-pressed to find a better solution than this. 我认为您很难找到比这更好的解决方案。

The polynomial approach is a pretty cool idea, but I think it's more theoretical than practical. 多项式方法是一个很酷的主意,但我认为它比理论上更实用。

What he's proposing is a Monomial that you can compose into Polynomial - think Composite pattern. 他的建议的是一个Monomial ,你可以撰写成Polynomial -想Composite模式。 Define all the usual math operations for both (addition, subtraction, multiplication, division) and any others you think you might need (eg differentiation and integration). 定义所有常规的数学运算(加法,减法,乘法,除法)以及您认为可能需要的其他所有数学运算(例如微分和积分)。

Polynomial will really shine for cases like x^1000 + 1 , because you can capture it with just two terms. 对于x^1000 + 1类的情况,多项式确实会发光,因为您只需两个项即可捕获它。

The real question is: What does your boss imagine you're saving? 真正的问题是:您的老板认为您要储蓄什么? A few bits? 几位? Speed? 速度? Development time? 开发时间? I agree with ziesemer - you'll be hard pressed to do much better than a BitSet . 我同意ziesemer-您将很难做到比BitSet更好。 The savings s/he's thinking of seems like a micro-optimization to me, the kind of thing that wouldn't show up if you profiled your application. 他/她所想到的节省对我来说似乎是微优化,如果您对应用程序进行了概要分析,则不会出现这种情况。

But s/he is the boss...is it worth the argument? 但是他/她老板...值得争论吗?

Maybe you can abstract this detail away and profile the two. 也许您可以将这个细节抽象化并剖析两者。

If you have multiple strings that need XOR ing it will actually cause performance overhead. 如果您有多个需要XOR的字符串,则实际上会导致性能开销。 This is because you need to match the weights. 这是因为您需要匹配权重。

It all depends on what you are XOR ing it with and how many times you have to do this to calculate the advantage to take this approach. 这完全取决于您对其进行异或操作,以及您必须执行多少次才能计算出采用此方法的优势。

I would go with ziesemer's solution. 我会选择ziesemer的解决方案。

I doubt very much you are going to get any benefit on 128-bit strings. 我非常怀疑您会在128位字符串上获得任何好处。 128 bits are 16 bytes; 128位为16字节; any object will take at least 40, so (almost) any supporting structure will be more expensive than the data it stores. 任何对象至少要占用40个对象,因此(几乎)任何支持结构都将比其存储的数据昂贵。

Still, here's a good survey of existing methods—and one novel one, which may (or may not) be beneficial for you. 尽管如此,这里还是对现有方法的一个很好的综述 ,以及一种可能会(或可能不会)对您有益的新颖方法。 Not as if it was an answer to your question, and agree that but ziesemer's solution is the best for such a huge numbers, but if you want to broad your horizons, take a look. 并不是说这是对您问题的答案,并且同意ziesemer的解决方案对于如此众多的用户来说是最好的,但是如果您想开阔眼界,请看一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM