Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
573 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 Reply

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...