Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
565 views
in Technique[技术] by (71.8m points)

z3 - Z3PY converting Ints to Python int

Is there a way to convert the Z3PY datatypes to native Python datatypes?

When my formula is solved by Z3, I can print it out by calling the model()-function. But how do I save the model output as ordinary ints in variables? So I can use them.

Can I convert them to ordinary ints so I can use them in the rest of my Python code in my program?

My whole purpose of using the solver is to take the result as an input to another Python program. So I need it to be able to process it.

question from:https://stackoverflow.com/questions/65911213/z3py-converting-ints-to-python-int

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Suppose your variable declared was x:

x = z3.Int("x")

You would get it as a Python int like this:

model[x].as_long()

z3 models are also iterable. Retrieving all parameters in a list comprehension:

[model[v] for v in model]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...