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

Multiplication of complex number is modelled incorrectly #8375

Closed
andreast271 opened this issue Jul 10, 2024 · 1 comment · Fixed by #8376
Closed

Multiplication of complex number is modelled incorrectly #8375

andreast271 opened this issue Jul 10, 2024 · 1 comment · Fixed by #8376
Labels
pending merge soundness Soundness bug? Review and add "aws" if it is, or remove "soundness" if it isn't.

Comments

@andreast271
Copy link
Contributor

CBMC version: 6.0.2
Operating system: Linux x86_64
Exact command line resulting in the issue: cbmc complex.c
What behaviour did you expect: assertion "right" succeeds, assertion "wrong" fails
What happened instead: assertion "right" fails, assertion "wrong" succeeds

Here is the code of complex.c:

#include <complex.h>

int main() {
  char choice;
  float re = choice ? 1.3f : 2.1f; // a non-constant well-behaved float
  float complex z1 = I + re;
  float complex z2 = z1 * z1;
  float complex expected = 2*I*re + re*re - 1; // (a+i)^2 = 2ai + a^2 - 1 
  float complex actual = re*re + I; // (a1 + b1*i)*(a2 + b2*i) = (a1*a2 + b1*b2*i)
  __CPROVER_assert(z2 == expected, "right");
  __CPROVER_assert(z2 == actual, "wrong");
  return 0;
}

CBMC behaves as if complex multiplication was done separately for the real and the imaginary part, like complex addition. I.e. (a*b).real = a.real * b.real and (a*b).img = a.img * b.img . That is not how this works.

@tautschnig tautschnig added the soundness Soundness bug? Review and add "aws" if it is, or remove "soundness" if it isn't. label Jul 11, 2024
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jul 11, 2024
Multiplication and division of complex numbers are not just pointwise
applications of those operations.

Fixes: diffblue#8375
@tautschnig
Copy link
Collaborator

tautschnig commented Jul 11, 2024

Thank you for the report and helpful test. #8376 will eventually fix this, but still requires further work as not only the back-end was broken, but also remove_complex needs fixing.

tautschnig added a commit to tautschnig/cbmc that referenced this issue Jul 11, 2024
Multiplication and division of complex numbers are not just pointwise
applications of those operations.

Fixes: diffblue#8375
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jul 11, 2024
Multiplication and division of complex numbers are not just pointwise
applications of those operations.

Fixes: diffblue#8375
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jul 11, 2024
Multiplication and division of complex numbers are not just pointwise
applications of those operations.

Fixes: diffblue#8375
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jul 12, 2024
Multiplication and division of complex numbers are not just pointwise
applications of those operations.

Fixes: diffblue#8375
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jul 12, 2024
Multiplication and division of complex numbers are not just pointwise
applications of those operations.

Fixes: diffblue#8375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending merge soundness Soundness bug? Review and add "aws" if it is, or remove "soundness" if it isn't.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants