I've built cvc4 from source according to their manual here.
I ran make check which went perfect, then sudo make install.
Then, I've tried running a simple example that works with z3:
(declare-const i Int)
(declare-const j Int)
(assert (= i 5))
(assert (= (+ i j) 9))
(check-sat)
(get-value (i j))
But I get this error:
CVC4 Error:
internal error: unhandled language LANG_AUTO in AntlrInput::newInput
What am I doing wrong? Thanks!
It turns out I invoked it wrong from the command line. Here's what works:
cvc4 --quiet --produce-models --lang=smt2 ./example.txt
Which produces the following result:
sat
((i 5) (j 4))
Related
For a project I need the output of a Lisp program, however I have never heard of Lisp before and I cannot make it run. I have downloaded the file (.lsp) from a website and looked at it with a texteditor to understand its logic. The lisp file gets a certain input and reduces that input through some iterative steps. I want to know not only the output but also the iteratrion process, which is why a logfile of that would be great. I have downloaded Portacle and some other Lisp interpreters/compilers, but I cannot make it work. It is so frustrating. Is there a simple way to run a lisp file from a directory? I have watched several tutorials and read thorugh some threads here, but I have still no clue how to run the Lisp file like I would run a Python file.
I am so immensely grateful for any help! I am pretty sure there is a simple way that I am just not seeing.
Thank you so much in advance!
If you have to spend some time working on this, it is worth installing at least Quicklisp and Slime, following this tutorial:
https://lisp-lang.org/learn/getting-started/
You can however start with only the interpreter. You need to install sbcl, and I recommend having rlwrap too because SBCL prompt does not have fancy readline features.
$ rlwrap sbcl
Then, you'll be in a Lisp REPL. Execute this to ensure the code is compiled with the maximum level of debugging:
* (sb-ext:restrict-compiler-policy 'debug 3)
The environment should reply with:
((DEBUG . 3))
NIL
Then, you can compile your input file (use an absolute path, or a path relative to the directory where you stared sbcl):
* (compile-file "/tmp/concepts")
A lot of text will be emitted, but the interpreter replies with the name of the object file being produced (e.g. "/tmp/concepts.fasl"), you can load it by supplying * as an argument, since the asterisk means the last result.
* (load *)
Following the comments in the file (between #| and |#), you can test it as follows:
* (test-concepts shepard)
This performs a lot of tests.
You can trace individual functions if you want with (trace X Y Z) where X , Y and Z are function names (you can also untrace them).
To simplify, here is a list where all (I think) symbols described in the comments are traced:
(trace frequency-of-properties
frequency-of-pairs
count-of-n
simplify-eight
remove-non-minimals
replace-lis-in-concept
print-linear-models
simplify-quads
make-master-list
make-pairs-for-quads
find-pair-quads
memberprop-lis
max-length
count-of-n
frequency-of-pairs
find-pairs-that-simplify
find-pair-to-simplify
remove-non-minimals
triples
three-pairs
simplify-by-mates
doubles
co
remove-non-minimals
replace-lis-in-concept
simplify-by-mates
singles
remove-non-minimals
replace-lis-in-concept
simplify-by-mates
print-linear-models
simplify-by-mates)
Using the same test as above, the last test prints the following trace:
Problem 6 0: (PRINT-LINEAR-MODELS (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
AB-C A-BC -ABC -A-B-C
0: PRINT-LINEAR-MODELS returned NIL
0: (FREQUENCY-OF-PROPERTIES (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
0: FREQUENCY-OF-PROPERTIES returned
((((A)) 2) (((B)) 2) (((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2))
0: (COUNT-OF-N ((((A)) 2) (((B)) 2) (((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
1: (COUNT-OF-N ((((B)) 2) (((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
2: (COUNT-OF-N ((((- C)) 2) (((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
3: (COUNT-OF-N ((((- B)) 2) (((C)) 2) (((- A)) 2)) 4)
4: (COUNT-OF-N ((((C)) 2) (((- A)) 2)) 4)
5: (COUNT-OF-N ((((- A)) 2)) 4)
6: (COUNT-OF-N NIL 4)
6: COUNT-OF-N returned NIL
5: COUNT-OF-N returned NIL
4: COUNT-OF-N returned NIL
3: COUNT-OF-N returned NIL
2: COUNT-OF-N returned NIL
1: COUNT-OF-N returned NIL
0: COUNT-OF-N returned NIL
0: (SIMPLIFY-BY-MATES (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
1: (MAX-LENGTH (((A) (B) (- C)) ((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))))
2: (MAX-LENGTH (((A) (- B) (C)) ((- A) (B) (C)) ((- A) (- B) (- C))) 3)
3: (MAX-LENGTH (((- A) (B) (C)) ((- A) (- B) (- C))) 3)
4: (MAX-LENGTH (((- A) (- B) (- C))) 3)
5: (MAX-LENGTH NIL 3)
5: MAX-LENGTH returned 3
4: MAX-LENGTH returned 3
3: MAX-LENGTH returned 3
2: MAX-LENGTH returned 3
1: MAX-LENGTH returned 3
0: SIMPLIFY-BY-MATES returned NIL
No simplification possible. Number of models 4
This should give a better understanding of what is happening.
You can also use (step (test shepard)), in which case the execution breaks in the debugger; use help to have more information about the commands you can invoke. For example you can write STEP (or just S) to step into an expression, NEXT to skip over an expression and go to the next one, OUT to step out of the current frame, etc.
I'm trying to run the following unsat example with both Z3 and CVC4.
If I replace "\x00" with (seq.unit #x00) then it's not a problem for Z3,
but CVC4 complains it doesn't know seq.unit.
(declare-fun AB_serial_1_version_0 () String)
(declare-fun AB_serial_1_version_1 () String)
(assert (= (str.len AB_serial_1_version_0) 16))
(assert (= (str.len AB_serial_1_version_1) (str.len AB_serial_1_version_0)))
(assert (= (str.at AB_serial_1_version_1 15) "\x00"))
;;; (assert (= (str.at AB_serial_1_version_1 15) (seq.unit #x00)))
(assert (= (str.indexof (str.substr AB_serial_1_version_1 0 (- 16 0)) "\x00" 0) (- 0 1)))
(check-sat)
Here is the command line call:
cvc4 --strings-exp --quiet --produce-models --lang=smt2 ./example.txt
And here is what cvc4 complains about when I use the seq.unit line instead:
(error "Parse Error: ./example.txt:7.54: Symbol 'seq.unit' not declared as a variable
...= (str.at AB_serial_1_version_1 15) (seq.unit #x00)))
^
")
This is the answer from CVC4/issues (brought here for completeness):
Thanks for the benchmark. Unfortunately there isn't anything that
converts between bitvectors and strings at the moment.
We are planning to add support for sequences soon (issue #1122).
Although of course there isn't an SMT standard for sequences yet. I
will keep this issue in mind when we add support for sequences.
I am using the book SICP and attempting to solve this exercise:
1.2.4 Exponentiation
Exercise 1.18. Using the results of exercises 1.16 and 1.17, devise
a procedure that generates an iterative process for multiplying two
integers in terms of adding, doubling, and halving and uses a
logarithmic number of steps
I am trying to solve this with the following code:
(define (double x)
(+ x x))
(define (halve x)
(floor (/ x 2)))
(define (* a b)
(define (iter count accumulate)
(cond ((= count 1) accumulate)
((even? a) (iter (halve count) (+ accumulate (double b))))
(else empty)))
(iter a 0))
As you might see, I am trying to deal with even numbers first.
I am using the SICP wiki as my solutions-guide. They suggest some tests to see if the code works:
(* 2 4)
(* 4 0)
What I do not get is that my code passes on these two first tests, dealing only with even numbers.
However, when I try some big numbers which are multiples of two, the code fails. I checked the result using Python. For instance,
(IN PYTHON)
2**100
>> 1267650600228229401496703205376
2**98
>> 316912650057057350374175801344
a = 2**100
b = 2**98
a*b
>> 401734511064747568885490523085290650630550748445698208825344
When I use my function inside Dr. Racket with these values I get a different result:
(* 1267650600228229401496703205376 316912650057057350374175801344)
My result is: 63382530011411470074835160268800, which is wrong, as Python built-in functions suggest.
Why this is happening?
The recursive step seems wrong, and what's that empty doing there? also, what happens if b is negative? this solution should work:
(define (mul a b)
(define (iter a b acc)
(cond ((zero? b) acc)
((even? b) (iter (double a) (halve b) acc))
(else (iter a (- b 1) (+ a acc)))))
(if (< b 0)
(- (iter a (- b) 0))
(iter a b 0)))
For example:
(mul 1267650600228229401496703205376 316912650057057350374175801344)
=> 401734511064747568885490523085290650630550748445698208825344
Working on an assignment right now (racket) and came across this problem.
> (define a '(even?))
> a
(even?)
> (first a)
even?
> (even? 2)
#t
> ((first a) 2)
. . application: not a procedure;
expected a procedure that can be applied to arguments
given: even?
arguments.:
Why is this not working?
Isn't ((first a) 2) equivalent to (even? 2) ??
'(even?) is equivalent to (quote (even?)) which returns a list with a symbol even? (not the function).
If you want the code you're describing to work you need to have the first define look like (define a (list even?)) which is a list with the procedure even? in it.
Essentially I am trying to code up a macro which will print out exactly some statement I am trying to evaluate, and the value it evaluates to.
What I have so far is the following:
(defmacro dbg (statement)
(format t "~a: ~a" statement (eval statement)))
and by typing the following into the slime repl: (dbg (* 2 2)) I get the desired result which is:
"(* 2 2): 4"
However when I try to use it in the following function **:
(defun get-start-position (curr-prime)
(dbg (/ (- (* curr-prime curr-prime) 3) 2))
(/ (- (* curr-prime curr-prime) 3) 2))
slime reports that curr-prime is unbound (and just sticking everything in a let doesn't help). To be more specific the act of trying to compile the function get-start-position results in:
2 compiler notes:
primes.lisp:27:3:
error:
during macroexpansion of (DBG (- # 3)). Use *BREAK-ON-SIGNALS* to intercept:
The variable CURR-PRIME is unbound.
primes.lisp: 29:9:
note:
deleting unreachable code
==>
CURR-PRIME
Compilation failed.
Presumably (and the second warning baffles me), the error comes about because the macro is expanded before the function which calls it gets a chance to bind curr-prime to some value (am I correct here?). That said I have no clue how to get round this issue
What am I doing wrong?
** for what its worth I am coding up a prime sieve where the indicator array has the following elements:
(3,5,7,9, ...)
This particular function will get me the index of the square of a given prime
Not a pro on Lisp macros, but this will do:
(defmacro dbg (statement)
(let ((result (gensym)))
`(let ((,result ,statement))
(format t "~a: ~a" ',statement ,result)
,result)))
then
(dbg (* 2 2))
=> (* 2 2): 4
4
and
(defun get-start-position (curr-prime)
(dbg (/ (- (* curr-prime curr-prime) 3) 2)))
(get-start-position 1)
=> (/ (- (* CURR-PRIME CURR-PRIME) 3) 2): -1
-1