Skip to content
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

Merged
merged 25 commits into from
Dec 14, 2022

Conversation

genkifs
Copy link
Contributor

@genkifs genkifs commented Oct 29, 2022

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:

  • The PR edits only existing draft PRs.
  • The build passes.
  • Your GitHub username or email address is listed in the 'author' header of all affected PRs, inside .
  • If matching on email address, the email address is the one publicly listed on your GitHub profile.

@genkifs genkifs requested a review from eth-bot as a code owner October 29, 2022 01:03
@github-actions github-actions bot added c-new Creates a brand new proposal s-draft This EIP is a Draft t-erc labels Oct 29, 2022
@eth-bot
Copy link
Collaborator

eth-bot commented Oct 29, 2022

A critical exception has occurred:
Message: pr 5850 is already merged; quitting
(cc @alita-moore, @mryalamanchi)

@Pandapip1 Pandapip1 changed the title Genki fs Add EIP-5850: Complex Numbers stored in Bytes32 types Oct 30, 2022
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Show resolved Hide resolved
EIPS/eip-5850.md Outdated Show resolved Hide resolved
EIPS/eip-5850.md Show resolved Hide resolved
genkifs and others added 5 commits October 30, 2022 22:32
Co-authored-by: Pandapip1 <45835846+Pandapip1@users.noreply.github.com>
Language improvements

Co-authored-by: Pandapip1 <45835846+Pandapip1@users.noreply.github.com>
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.
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@Pandapip1 Pandapip1 left a 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.

@eth-bot eth-bot enabled auto-merge (squash) December 14, 2022 18:42
@eth-bot eth-bot merged commit 99c553e into ethereum:master Dec 14, 2022
@genkifs
Copy link
Contributor Author

genkifs commented Dec 16, 2022

I really feel this standard is too under-specified to be useful as it stands right now,

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.

@genkifs genkifs deleted the GenkiFS branch December 17, 2022 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-new Creates a brand new proposal s-draft This EIP is a Draft t-erc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants