How to run datalog in Z3 using commad line - z3

I try to run datalog file (test.dl, from http://rise4fun.com/Z3/tutorialcontent/fixedpoints#h21) as following in Z3 (version:4.3.2).
(set-option :fixedpoint.engine datalog)
(define-sort s () (_ BitVec 3))
(declare-rel edge (s s))
(declare-rel path (s s))
(declare-var a s)
(declare-var b s)
(declare-var c s)
(rule (=> (edge a b) (path a b)))
(rule (=> (and (path a b) (path b c)) (path a c)))
(rule (edge #b001 #b010))
(rule (edge #b001 #b011))
(rule (edge #b010 #b100))
(query (path #b001 #b100))
(query (path #b011 #b100))
(query (path #b001 b)
:print-answer true)
Use the command z3 test.dl, but there is erorr msg:
Can someone help how to run the datalog file?
Thanks.

The input format for this file is SMT2, not Datalog. Even though you want to run the Datalog engine, the file isn't in Datalog format and so the parser gives you the error that you see.
Running Z3 with the command z3 -smt2 test.dl was successful, as this forces Z3 to use the SMT2 parser and not the Datalog one. Alternatively, renaming the file to test.smt2 and running z3 test.smt2 works.
Both commands produced what I believe is the expected output
sat
unsat
sat
(or (= (:var 0) #b011) (= (:var 0) #b010) (= (:var 0) #b100))

Related

batch resize images with gimp

I want to resize every jpg in a directory.
This is the gimp script I've found. Looks sensible to me.
(define (batch-resize pattern)
(let*
((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* (
(filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-active-drawable image)))
(cur-width (car (gimp-image-width image)))
(cur-height (car (gimp-image-height image)))
(width (* 0.25 cur-width))
(height (* 0.25 cur-height))
)
(gimp-message filename)
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(let
((nfilename (string-append "thumb_" filename)))
(gimp-file-save RUN-NONINTERACTIVE image drawable nfilename nfilename)
)
(gimp-image-delete image)
)
(set! filelist (cdr filelist))
)
)
)
I saved this as C:\Users\rwb\.gimp-2.8\scripts\batch-resize.scm and then call
"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b '(batch-resize "*.JPG")' -b '(gimp-quit 0)'
The ouptut is
>"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b '(batch-resize "*.JPG")' -b '(gimp-quit 0)'
(gimp-console-2.8.exe:7568): LibGimpBase-WARNING **: gimp-console-2.8.exe: gimp_wire_read(): error
batch command executed successfully
batch command executed successfully
At which point it just hangs.
I was expecting the (gimp-message filename) to print the filenames but nothing!
I really have no idea what is going on here! Can you offer any suggestions? Even printing the filenames would be a start.
The problem arises from the way you are quoting the command-line. This should work:
"c:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -b "(batch-resize \"*.JPG\")" -b "(gimp-quit 0)"
Note that it is updated for GIMP 2.10. Additionally, user script files now live in:
c:\Users\rwb\AppData\Roaming\GIMP\2.10\scripts
And finally, the code block in your question was formatted with the final parenthesis outside the block, which made it easy to miss. I've updated that.

'Unknown logical symbol map.Map.const' message in Why3

I'm experimenting with why3 by following their tutorial, but I get the message Unknown logical symbol map.Map.const for multiple provers. Here are the contents of the theory I'm trying to prove:
theory List
type list 'a = Nil | Cons 'a (list 'a)
predicate mem(x: 'a) (l: list 'a) = match l with
| Nil -> false
| Cons y r -> x = y || mem x r
end
goal G1: mem 2 (Cons 1 (Cons 2 (Cons 3 Nil)))
end
Here are the results of a variety of provers:
z3:
▶ why3 prove -P z3 demo_logic.why
File "/usr/local/share/why3/drivers/z3_bare.drv", line 172, characters 36-41:
Unknown logical symbol map.Map.const
cvc4:
▶ why3 prove -P cvc4 demo_logic.why
File "/usr/local/share/why3/drivers/cvc4_bare.drv", line 180, characters 36-41:
Unknown logical symbol map.Map.const
pvs:
▶ why3 prove -P pvs demo_logic.why
File "/usr/local/share/why3/drivers/pvs-common.gen", line 41, characters 18-23:
Unknown logical symbol map.Map.const
This is my why3 version information:
▶ why3 --version
Why3 platform, version -n 0.85+git (build date: Tue Mar 10 08:27:47 EDT 2015)
The timestamps on the .drv files mentioned in the error messages match the timestamp on my why3 executable.
Is there something wrong with my theory or my installation?
Edit to add: In the tutorial itself it says to use why3 demo_logic.why to prove the theory, but when I try that I get this result:
▶ why3 demo_logic.why
'demo_logic.why' is not a Why3 command.
If instead I just do why3 prove demo_logic.why, the result is just (approximately) an echo of the theory:
▶ why3 prove demo_logic.why
theory List
(* use why3.BuiltIn.BuiltIn *)
type list 'a =
| Nil
| Cons 'a (list 'a)
predicate mem (x:'a) (l:list 'a) =
match l with
| Nil -> false
| Cons y r -> x = y || mem x r
end
goal G1 : mem 2 (Cons 1 (Cons 2 (Cons 3 (Nil:list int))))
end
Do you installed a previous version of why3? Problems in the execution of provers are often due to a new why3 using a configuration file of an old why3. And I have seen your particular instance fixed by this:
rm ~/.why3.conf
why3 config --detect

In LaTeX, how to escape to print out a block of text

The Problem: I just want to print a sequence like this in plain text:
a (10)
_/ \_
/ \
(4) b c (4)
_/ \___
/ \
(8) d _ e _ (5)
/ \ / | \
f g h i j
(2) (4) (1) (1) (6)
I would like to avoid escaping all characters along the way, including special characters for preserving spaces. Essentially, I am drawing an ASCII picture!
For a pure ASCII-picture interpretation, use the verbatim environment:
\documentclass{article}
\begin{document}
\begin{verbatim}
a (10)
_/ \_
/ \
(4) b c (4)
_/ \___
/ \
(8) d _ e _ (5)
/ \ / | \
f g h i j
(2) (4) (1) (1) (6)
\end{verbatim}
\end{document}
The verbatim environment sets interprets spaces, line breaks and special characters as-is.

Why this is not grammar LL(1)

I have been given a task to transform this grammar to LL(1)
E → E+E | E-E | E*E | E/E | E^E | -E | (E)| id | num
So for first step I eliminated ambiguity and got this:
E → E+T | E-T | T
T → T*P | T/P | P
P → P ^ F | F
F → id | num | -E | (E)
And after that I have eliminated left-recursion and got this:
E → TE'
E' → +TE' | -TE' | ɛ
T → PT'
T' → *PT' | /PT' | ɛ
P → FP'
P' → ^FP' | ɛ
F → id | num | -E | (E)
When I put this into JFLAP and click 'Build LL(1) parse table' I get warning that grammar above is not LL(1).
Why this grammar is not LL(1), and what do I need to change to be LL(1).
Your grammar is still ambiguous, so it can't be LL(1).
This production F → -E makes it possible to mix an expression with lower precedence operators in a level (unary operator) where they shouldn't appear.
Note that id + - id + id has two derivation trees.
You shouldn't use E there, but a symbol that represents an atomic value. You could replace
F → id | num | -E | (E)
with
F → -A | A
A → id | num | (E)
Or F → -F | A if you want to allow multiple unary minuses.

z3 # command line behaving differently than online

the (rather small) query that I have here:
http://rise4fun.com/Z3/W4sf
works just fine on the website (above) but hangs
when I run it on my mac, with
z3 -in
followed by pasting in the exact text above, which is:
(declare-const x Real)
(assert (not (= 0.0 x)))
(assert (not (< 0.0 (* x x))))
(check-sat)
Any ideas? I thought it might be that I have an old version but its 4.3.2
rjhala#borscht ~/bin [130]> z3 -help
Z3 [version 4.3.2 - 64 bit - build hashcode 5b5a474b5443].
Am I missing some parameters? Or any other suggestions? Many thanks!
Ranjit.
It also seemed not to return for me using that, but it seems to work as:
z3 -in -smt2
Followed by pasting the query, so I think it may need the -smt2 parameter. I tried it on Windows with 4.3.3 (I thought I had 4.3.2, but it seems I updated from the latest unstable branch):
C:\Users\tjohnson>z3 -in -smt2
(declare-const x Real)
(assert (not (= 0.0 x)))
(assert (not (< 0.0 (* x x))))
(check-sat)
unsat
It also worked for me by pasting the query into test.smt and running:
C:\Users\tjohnson>z3 -smt2 test.smt
unsat

Resources