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

Algebraic numbers, index problem #5807

Closed
makkiato83 opened this issue Feb 2, 2022 · 2 comments
Closed

Algebraic numbers, index problem #5807

makkiato83 opened this issue Feb 2, 2022 · 2 comments
Labels

Comments

@makkiato83
Copy link

makkiato83 commented Feb 2, 2022

Hello, I am experimenting with z3 in Python.

I am not sure, but it looks like the index() method of the AlgebraicNumRef class is not working properly:

x, y = Reals('x y')
s = Solver()
s.add( x*x == 2 )
s.add( x>0)
s.add( y*y == 2 )
s.add( y<0)
s.check()
m = s.model()
val_x = m.get_interp(x)
val_y = m.get_interp(y)

print(f"The solutions are: x={val_x} and y={val_y}")
print(f"The defining polynomial of x has integer coefficients", val_x.poly(), " and root index ", val_x.index())
print(f"The defining polynomial of y has integer coefficients", val_y.poly(), " and root index ", val_y.index())

the output is:

The solutions are: x=1.4142135623? and y=-1.4142135623?

the defining polynomial of x has integer coefficients [-2, 0, 1]  and root index  0

the defining polynomial of y has integer coefficients [-2, 0, 1]  and root index  0

The polynomial defining the solutions is correct: polynomial $1x^2 + 0x -2 = 0$

But the two roots are both getting index 0.

@NikolajBjorner
Copy link
Contributor

You are the only user of this feature. I am afraid you would have to fix this on your own.

janvrany added a commit to janvrany/z3 that referenced this issue Mar 8, 2022
In some cases, Z3_algebraic_get_i() returned 0. For example, in the following
Python snippet, the last assert would fail:

    import z3
    x = z3.Real('x')
    s = z3.Solver()
    s.add( (x * x) - 2 == 0, x <= 0)
    s.check()
    val_x = s.model().get_interp(x)
    assert val_x.index() == 1

The problem was that `algebraic_numbers::manager::imp::get_i()` did not
check whether the root index was properly initialized.

This commit fixes this issue by checking whether root index is initialized
the same way various other routines do.

Fixes issue Z3Prover#5807.

Signed-off-by: Jan Vrany <jan.vrany@labware.com>
janvrany added a commit to janvrany/z3 that referenced this issue Mar 8, 2022
In some cases, Z3_algebraic_get_i() returned 0. For example, in the following
Python snippet, the last assert would fail:

    import z3
    x = z3.Real('x')
    s = z3.Solver()
    s.add( (x * x) - 2 == 0, x <= 0)
    s.check()
    val_x = s.model().get_interp(x)
    assert val_x.index() == 1

The problem was that `algebraic_numbers::manager::imp::get_i()` did not
check whether the root index was properly initialized.

This commit fixes this issue by checking whether root index is initialized
the same way various other routines do.

Fixes issue Z3Prover#5807.

Signed-off-by: Jan Vrany <jan.vrany@labware.com>
@janvrany
Copy link
Contributor

janvrany commented Mar 8, 2022

Fix in PR #5888 should fix the problem.

NikolajBjorner pushed a commit that referenced this issue Mar 17, 2022
…#5888)

In some cases, Z3_algebraic_get_i() returned 0. For example, in the following
Python snippet, the last assert would fail:

    import z3
    x = z3.Real('x')
    s = z3.Solver()
    s.add( (x * x) - 2 == 0, x <= 0)
    s.check()
    val_x = s.model().get_interp(x)
    assert val_x.index() == 1

The problem was that `algebraic_numbers::manager::imp::get_i()` did not
check whether the root index was properly initialized.

This commit fixes this issue by checking whether root index is initialized
the same way various other routines do.

Fixes issue #5807.

Signed-off-by: Jan Vrany <jan.vrany@labware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants