-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EIP-5850: Complex Numbers stored in Bytes32 types #5850
Conversation
A critical exception has occurred: |
Co-authored-by: Pandapip1 <[email protected]>
Language improvements Co-authored-by: Pandapip1 <[email protected]>
EIPS/eip-5850.md
Outdated
|
||
Complex numbers can be represented in many different forms (polynomial, cartesian, polar, exponential). The EIP creates a standard that can accomodate cartesian, polar and exponential formats with example code given for the Cartesian representation, where a complex number is just the pair of real numbers which gives the real and imaginary co-ordinates of the complex number. Equal storage capacity is assigned to both components and the order they appear is explicitly defined. | ||
|
||
Packing complex numbers into a single bytes32 data object halves storage costs and creates a more natural code object that can be passed around the solidity ecosystem. Existing code may not need to be rewritten for complex numbers. For example, mappings by bytes32 are common and indexing in the 2D complex plane may improve code legibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thank you for the EIP draft!
My question is regarding movitation: Could you help give more concrete examples of real world usage of on-chain imaginary numbers?
Also, is EIP/ERC the best place or is it better to be proposed as a Solidity/Vyper language feature?
@axic FYI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help give more concrete examples of real world usage of on-chain imaginary numbers?
Fundamentally, this EIP is essential if you want to track/control/record a variable (but more likely an array) that is complex in nature.
This EIP was focused on defining the storage aspect of the complex number building block, not how or why it would be manipulated on-chain. However, there is no harm discussing use cases outside of the EIP document.
-
Complex numbers are invaluable for electrical engineering specifications and calculations. A live certified safety standard defined as a working calculation (using the gasless view functionality) is much more valuable than a dead pdf equation.
-
Time-series analysis use Fourier Transforms for calculations and statistical distributions are defined via their complex number based characteristic function.
-
Linear algebra can easily enter into the realm of complex numbers.
-
Polynomials with non-real roots shouldn't necessarily interrupt your algorithm.
-
Code can be simpler, more readable and reusable if complex numbers are used (e.g. 2D rotations).
Even if you believe the above sorts of calculations will never be performed on-chain, some intermediate and final results will likely be reported as complex numbers.
But the simplest (and maybe most useful) use case/hack would be to define a 2d space within a single bytes32
data type.
proposed as a Solidity/Vyper language feature
Even though I gave the specification example in solidity, this EIP is language independent. The EVM stores data in 32 byte chunks. If we standardize that the least significant 16 bytes are Real and the most significant 16 bytes are Imaginary then any higher level language (Solidity/Vyper/etc.) can follow this implementation. If this were just a Solidity standard then other contracts written in Vyper would have difficulty understanding and interacting with these bytes32
objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @xinbenlv's point was that this should be proposed as a feature either on the solidity or vyper (or both) repos. I think this could be an EIP, but the fact that it doesn't support floating point is a major hurdle to getting this adopted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be proposed as a feature either on the solidity or vyper (or both) repos
I believe this is at a language independent level, but as long as the standard is set with real numbers in the lower 16 bytes and imaginary numbers in the upper 16 bytes then I'm not that bothered where it lives.
the fact that it doesn't support floating point is a major hurdle
Neither fixed nor floating point are specified by the EIP. As currently defined, any number representation can be supported, so long as it fits inside the 16 bytes space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As currently defined, any number representation can be supported, so long as it fits inside the 16 bytes space.
This was unclear when reading the EIP. I would highly suggest indicating this in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarification added to the spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really feel this standard is too under-specified to be useful as it stands right now, but this meets the minimum requirements of a draft.
If the community evolves this into a stronger, more detailed specification then that is fine by me. My preference would be for a signed fixed point, 18 decimal place number format but I don't want to force this as other representations may be better suited. |
When opening a pull request to submit a new EIP, please use the suggested template: https://github.com/ethereum/EIPs/blob/master/eip-template.md
We have a GitHub bot that automatically merges some PRs. It will merge yours immediately if certain criteria are met: