CVC4 parsing error(the same formula passes Z3) - cvc4

The following SMT folumas pass Z3 constraint solving while CVC4 flags an parsing error: "Symbol 'None' previously declared as a variable". I have tested using both CVC4 1.4 and CVC 1.5 on windows. Any suggestions or thoughts?
(set-logic ALL)
(declare-datatypes () ((Enum13 (Green) (Yellow) (None))))
(declare-datatypes () ((Enum0 (True) (False) (None))))
(declare-datatypes () ((Enum9 (Star_3) (Star_2) (Star_1) (None))))
(declare-fun Decomp
(Enum9 Enum13 Enum0)
Enum13)
(declare-fun var_36 () Enum0)
(declare-fun var_37 () Enum13)
(declare-fun var_71 () Enum9)
(declare-fun var_38 () Enum13)
(declare-fun var_31 () Real)
(assert (and true
true
true
(= var_38
(Decomp var_71 var_37 var_36))))
(assert (>= var_31 0.0))
(assert (<= var_31 700.0))
(check-sat)

CVC4 does not accept datatype definitions where the names of constructors are duplicated. So, "None" cannot be both a Enum13, Enum0, and Enum9. Instead you could use unique names like None13, None0, None9 and CVC4 would not give a syntax error.
Btw, the latest version of CVC4 accepts SMT LIB 2.6 by default, where the format for datatypes is bit different: http://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2017-07-18.pdf
To use the old format you can still use --lang=smt2.5
Hope this helps,
Andy

Related

How do I make toLowerCase() and toUpperCase() consistent across browsers

Are there JavaScript polyfill implementations of String.toLowerCase() and String.toUpperCase(), or other methods in JavaScript that can work with Unicode characters and are consistent across browsers?
Background info
Performing the following will give difference results in browsers, or even between browser versions (E.g FireFox 54 vs 55):
document.write(String.fromCodePoint(223).normalize("NFKC").toLowerCase().toUpperCase().toLowerCase())
In Firefox 55 it gives you ss, in Firefox 54 it gives you ß.
Generally this is fine, and mechanisms such as Locales handle a lot of the cases you'd want; however, when you need consistent behavior across platforms such as talking to BaaS systems like google-cloud-firestore it can greatly simplify interactions where you're essentially processing internal data on the client.
Note that this issue only seems to affect outdated versions of Firefox, so unless you explicitly need to support those old versions, you could choose to just not bother at all. The behavior for your example is the same in all modern browsers (since the change in Firefox). This can be verified using jsvu + eshost:
$ jsvu # Update installed JavaScript engine binaries to the latest version.
$ eshost -e '"\xDF".normalize("NFKC").toLowerCase().toUpperCase().toLowerCase()'
#### Chakra
ss
#### V8 --harmony
ss
#### JavaScriptCore
ss
#### V8
ss
#### SpiderMonkey
ss
#### xs
ss
But you asked how to solve this problem, so let’s continue.
Step 4 of https://tc39.github.io/ecma262/#sec-string.prototype.tolowercase states:
Let cuList be a List where the elements are the result of toLowercase(cpList), according to the Unicode Default Case Conversion algorithm.
This Unicode Default Case Conversion algorithm is specified in section 3.13 Default Case Algorithms of the Unicode standard.
The full case mappings for Unicode characters are obtained by using the mappings from SpecialCasing.txt plus the mappings from UnicodeData.txt, excluding any of the latter mappings that would conflict. Any character that does not have a mapping in these files is considered to map to itself.
[…]
The following rules specify the default case conversion operations for Unicode strings. These rules use the full case conversion operations, Uppercase_Mapping(C), Lowercase_Mapping(C), and Titlecase_Mapping(C), as well as the context-dependent mappings based on the casing context, as specified in Table 3-17.
For a string X:
R1 toUppercase(X): Map each character C in X to Uppercase_Mapping(C).
R2 toLowercase(X): Map each character C in X to Lowercase_Mapping(C).
Here’s an example from SpecialCasing.txt, with my annotation added below:
00DF ; 00DF ; 0053 0073; 0053 0053; # LATIN SMALL LETTER SHARP S
<code>; <lower>; <title> ; <upper> ; (<condition_list>;)? # <comment>
This line says that U+00DF ('ß') lowercases to U+00DF (ß) and uppercases to U+0053 U+0053 (SS).
Here’s an example from UnicodeData.txt, with my annotation added below:
0041 ; LATIN CAPITAL LETTER A; Lu;0;L;;;;;N;;;; 0061 ;
<code>; <name> ; <ignore> ; <lower>; <upper>
This line says that U+0041 ('A') lowercases to U+0061 ('a'). It doesn’t have an explicit uppercase mapping, meaning it uppercases to itself.
Here’s another example from UnicodeData.txt:
0061 ; LATIN SMALL LETTER A; Ll;0;L;;;;;N;; ;0041; ; 0041
<code>; <name> ; <ignore> ; <lower>; <upper>
This line says that U+0061 ('a') uppercases to U+0041 ('A'). It doesn’t have an explicit lowercase mapping, meaning it lowercases to itself.
You could write a script that parses these two files, reads each line following these examples, and builds lowercase/uppercase mappings. You could then turn those mappings into a small JavaScript library that provides spec-compliant toLowerCase/toUpperCase functionality.
This seems like a lot of work. Depending on the old behavior in Firefox and what exactly changed (?) you could probably limit the work to just the special mappings in SpecialCasing.txt. (I’m making this assumption that only the special casings changed in Firefox 55, based on the example you provided.)
// Instead of…
function normalize(string) {
const normalized = string.normalize('NFKC');
const lowercased = normalized.toLowerCase();
return lowercased;
}
// …one could do something like:
function lowerCaseSpecialCases(string) {
// TODO: replace all SpecialCasing.txt characters with their lowercase
// mapping.
return string.replace(/TODO/g, fn);
}
function normalize(string) {
const normalized = string.normalize('NFKC');
const fixed = lowerCaseSpecialCases(normalized); // Workaround for old Firefox 54 behavior.
const lowercased = fixed.toLowerCase();
return lowercased;
}
I wrote a script that parses SpecialCasing.txt and generates a JS library that implements the lowerCaseSpecialCases functionality mentioned above (as toLower) as well as toUpper. Here it is: https://gist.github.com/mathiasbynens/a37e3f3138069729aa434ea90eea4a3c Depending on your exact use case, you might not need the toUpper and its corresponding regex and map at all. Here’s the full generated library:
const reToLower = /[\u0130\u1F88-\u1F8F\u1F98-\u1F9F\u1FA8-\u1FAF\u1FBC\u1FCC\u1FFC]/g;
const toLowerMap = new Map([
['\u0130', 'i\u0307'],
['\u1F88', '\u1F80'],
['\u1F89', '\u1F81'],
['\u1F8A', '\u1F82'],
['\u1F8B', '\u1F83'],
['\u1F8C', '\u1F84'],
['\u1F8D', '\u1F85'],
['\u1F8E', '\u1F86'],
['\u1F8F', '\u1F87'],
['\u1F98', '\u1F90'],
['\u1F99', '\u1F91'],
['\u1F9A', '\u1F92'],
['\u1F9B', '\u1F93'],
['\u1F9C', '\u1F94'],
['\u1F9D', '\u1F95'],
['\u1F9E', '\u1F96'],
['\u1F9F', '\u1F97'],
['\u1FA8', '\u1FA0'],
['\u1FA9', '\u1FA1'],
['\u1FAA', '\u1FA2'],
['\u1FAB', '\u1FA3'],
['\u1FAC', '\u1FA4'],
['\u1FAD', '\u1FA5'],
['\u1FAE', '\u1FA6'],
['\u1FAF', '\u1FA7'],
['\u1FBC', '\u1FB3'],
['\u1FCC', '\u1FC3'],
['\u1FFC', '\u1FF3']
]);
const toLower = (string) => string.replace(reToLower, (match) => toLowerMap.get(match));
const reToUpper = /[\xDF\u0149\u01F0\u0390\u03B0\u0587\u1E96-\u1E9A\u1F50\u1F52\u1F54\u1F56\u1F80-\u1FAF\u1FB2-\u1FB4\u1FB6\u1FB7\u1FBC\u1FC2-\u1FC4\u1FC6\u1FC7\u1FCC\u1FD2\u1FD3\u1FD6\u1FD7\u1FE2-\u1FE4\u1FE6\u1FE7\u1FF2-\u1FF4\u1FF6\u1FF7\u1FFC\uFB00-\uFB06\uFB13-\uFB17]/g;
const toUpperMap = new Map([
['\xDF', 'SS'],
['\uFB00', 'FF'],
['\uFB01', 'FI'],
['\uFB02', 'FL'],
['\uFB03', 'FFI'],
['\uFB04', 'FFL'],
['\uFB05', 'ST'],
['\uFB06', 'ST'],
['\u0587', '\u0535\u0552'],
['\uFB13', '\u0544\u0546'],
['\uFB14', '\u0544\u0535'],
['\uFB15', '\u0544\u053B'],
['\uFB16', '\u054E\u0546'],
['\uFB17', '\u0544\u053D'],
['\u0149', '\u02BCN'],
['\u0390', '\u0399\u0308\u0301'],
['\u03B0', '\u03A5\u0308\u0301'],
['\u01F0', 'J\u030C'],
['\u1E96', 'H\u0331'],
['\u1E97', 'T\u0308'],
['\u1E98', 'W\u030A'],
['\u1E99', 'Y\u030A'],
['\u1E9A', 'A\u02BE'],
['\u1F50', '\u03A5\u0313'],
['\u1F52', '\u03A5\u0313\u0300'],
['\u1F54', '\u03A5\u0313\u0301'],
['\u1F56', '\u03A5\u0313\u0342'],
['\u1FB6', '\u0391\u0342'],
['\u1FC6', '\u0397\u0342'],
['\u1FD2', '\u0399\u0308\u0300'],
['\u1FD3', '\u0399\u0308\u0301'],
['\u1FD6', '\u0399\u0342'],
['\u1FD7', '\u0399\u0308\u0342'],
['\u1FE2', '\u03A5\u0308\u0300'],
['\u1FE3', '\u03A5\u0308\u0301'],
['\u1FE4', '\u03A1\u0313'],
['\u1FE6', '\u03A5\u0342'],
['\u1FE7', '\u03A5\u0308\u0342'],
['\u1FF6', '\u03A9\u0342'],
['\u1F80', '\u1F08\u0399'],
['\u1F81', '\u1F09\u0399'],
['\u1F82', '\u1F0A\u0399'],
['\u1F83', '\u1F0B\u0399'],
['\u1F84', '\u1F0C\u0399'],
['\u1F85', '\u1F0D\u0399'],
['\u1F86', '\u1F0E\u0399'],
['\u1F87', '\u1F0F\u0399'],
['\u1F88', '\u1F08\u0399'],
['\u1F89', '\u1F09\u0399'],
['\u1F8A', '\u1F0A\u0399'],
['\u1F8B', '\u1F0B\u0399'],
['\u1F8C', '\u1F0C\u0399'],
['\u1F8D', '\u1F0D\u0399'],
['\u1F8E', '\u1F0E\u0399'],
['\u1F8F', '\u1F0F\u0399'],
['\u1F90', '\u1F28\u0399'],
['\u1F91', '\u1F29\u0399'],
['\u1F92', '\u1F2A\u0399'],
['\u1F93', '\u1F2B\u0399'],
['\u1F94', '\u1F2C\u0399'],
['\u1F95', '\u1F2D\u0399'],
['\u1F96', '\u1F2E\u0399'],
['\u1F97', '\u1F2F\u0399'],
['\u1F98', '\u1F28\u0399'],
['\u1F99', '\u1F29\u0399'],
['\u1F9A', '\u1F2A\u0399'],
['\u1F9B', '\u1F2B\u0399'],
['\u1F9C', '\u1F2C\u0399'],
['\u1F9D', '\u1F2D\u0399'],
['\u1F9E', '\u1F2E\u0399'],
['\u1F9F', '\u1F2F\u0399'],
['\u1FA0', '\u1F68\u0399'],
['\u1FA1', '\u1F69\u0399'],
['\u1FA2', '\u1F6A\u0399'],
['\u1FA3', '\u1F6B\u0399'],
['\u1FA4', '\u1F6C\u0399'],
['\u1FA5', '\u1F6D\u0399'],
['\u1FA6', '\u1F6E\u0399'],
['\u1FA7', '\u1F6F\u0399'],
['\u1FA8', '\u1F68\u0399'],
['\u1FA9', '\u1F69\u0399'],
['\u1FAA', '\u1F6A\u0399'],
['\u1FAB', '\u1F6B\u0399'],
['\u1FAC', '\u1F6C\u0399'],
['\u1FAD', '\u1F6D\u0399'],
['\u1FAE', '\u1F6E\u0399'],
['\u1FAF', '\u1F6F\u0399'],
['\u1FB3', '\u0391\u0399'],
['\u1FBC', '\u0391\u0399'],
['\u1FC3', '\u0397\u0399'],
['\u1FCC', '\u0397\u0399'],
['\u1FF3', '\u03A9\u0399'],
['\u1FFC', '\u03A9\u0399'],
['\u1FB2', '\u1FBA\u0399'],
['\u1FB4', '\u0386\u0399'],
['\u1FC2', '\u1FCA\u0399'],
['\u1FC4', '\u0389\u0399'],
['\u1FF2', '\u1FFA\u0399'],
['\u1FF4', '\u038F\u0399'],
['\u1FB7', '\u0391\u0342\u0399'],
['\u1FC7', '\u0397\u0342\u0399'],
['\u1FF7', '\u03A9\u0342\u0399']
]);
const toUpper = (string) => string.replace(reToUpper, (match) => toUpperMap.get(match));

using as.ppp on data frame to create marked process

I am using a data frame to create a marked point process using as.ppp function. I get an error Error: is.numeric(x) is not TRUE. The data I am using is as follows:
dput(head(pointDataUTM[,1:2]))
structure(list(POINT_X = c(439845.0069, 450018.3603, 451873.2925,
446836.5498, 445040.8974, 442060.0477), POINT_Y = c(4624464.56,
4629024.646, 4624579.758, 4636291.222, 4614853.993, 4651264.579
)), .Names = c("POINT_X", "POINT_Y"), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
I can see that the first two columns are numeric, so I do not know why it is a problem.
> str(pointDataUTM)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 5028 obs. of 31 variables:
$ POINT_X : num 439845 450018 451873 446837 445041 ...
$ POINT_Y : num 4624465 4629025 4624580 4636291 4614854 ...
Then I also checked for NA, which shows no NA
> sum(is.na(pointDataUTM$POINT_X))
[1] 0
> sum(is.na(pointDataUTM$POINT_Y))
[1] 0
When I tried even only the first two columns of the data.frame, the error I get on using as.ppp is this:
Error: is.numeric(x) is not TRUE
5.stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"), ch), call. = FALSE, domain = NA)
4.stopifnot(is.numeric(x))
3.ppp(X[, 1], X[, 2], window = win, marks = marx, check = check)
2.as.ppp.data.frame(pointDataUTM[, 1:2], W = studyWindow)
1.as.ppp(pointDataUTM[, 1:2], W = studyWindow)
Could someone tell me what is the mistake here and why I get the not numeric error?
Thank you.
I'm on the phone, so can't check but I think it is happens because you have a tibble and not a data.frame. Please try to convert to a data.frame using as.data.frame first.
The critical check is whether PointDataUTM[,1] is numeric, rather than PointDataUTM$POINT_X.
Since PointDataUTM is a tbl object, and tbl is a function from the dplyr package, what is probably happening is that the subset operator for the tbl class is returning a data frame, and not a numeric vector, when a single column is extracted. Whereas the $ operator returns a numeric vector.
I suggest you convert your data to data.frame using as.data.frame() before calling as.ppp.
In the next version of spatstat we will make our code more robust against this kind of problem.

CVC4 Expecting at most 3 arguments for operator 'ITE', found 5

When inputting the following file to cvc4, I get the following error:
(error "Parse Error: <stdin>:11.221: Expecting at most 3 arguments for operator 'ITE', found 5")
The file test.txt was:
(declare-fun start!1 () Bool)
(assert start!1)
(declare-fun lt!2 () String)
(declare-datatypes () ( (JValue!1 (JInt!1 (v!75 (_ BitVec 32))) (JString!1 (v!76 String))) ))
(declare-fun a!0 () JValue!1)
(assert (=> start!1 (not (= lt!2 (ite false "" (ite (and (is-JString!1 a!0) (= (v!76 a!0) "")) """""" (ite (and (is-JInt!1 a!0) (= (v!75 a!0) #x00000000)) "0" (ite (and (is-JString!1 a!0) (= (v!76 a!0) "a")) """a""" lt!2))))))))
The command line:
cat test.txt | cvc4.exe
I needed to add the option --lang smt2.5 for the format to support double quote escaping using the new standard.
So:
cat test.txt | cvc4.exe --lang smt2.5

reading in a top-level definition

Chicken Scheme 4.8.0.5
Greetings all,
Assuming I have a text file containing a top-level definition
topLevelDef.txt
(define techDisplays '(
( AG1 fillerIgnore AG1_fillerIgnore t t nil t nil )
( AG2 drawing AG2_drawing t t nil t t )
)
)
and I bring it in as an include
trythis.scm
(use extras format posix posix-extras regex regex-literals utils srfi-13)
(include "./mytech/mytech.tf.techDisplays") ; works when hard-coded
;include inn-file) ; want to pass it in as an arg
(define write-out-techDisplays
(lambda()
(for-each
(lambda(rule-as-list-of-symbols)
(begin
(set! rule-as-list-of-strings ( map symbol->string rule-as-list-of-symbols))
(print (string-join rule-as-list-of-strings ))
)
)
techDisplays
)
)
)
(define (main args)
(set! inn-file ( car args))
(set! out-file (cadr args))
(with-output-to-file out-file write-out-techDisplays)
0
)
So how can I achieve this? Either by delaying evaluation of the include somehow? Or reading in the contents of inn-file and evaluating the string somehow? Or something else?
TIA,
Still-learning Steve
just pass the list you want as an argument to your outer lambda.
your formatting is misleading, you could try to pretty print your code.
(define write-out-techdisplays
(lambda (techdisps)
(for-each
(lambda (rule)
(begin
(set! rule-string (map symbol->string rule))
(print (string-join rule-string)))) ;inner-lambda closes here
techdisps)))
(define alldisps
(call-with-input-file "./mytech/mytech.tf.techDisplays"
read)))
;since the last arg is thunk the way to invoke it is to wrap
;our call to write-out-techdisplays with a lambda to set the correct list
(with-output-to-file out-file
(lambda ()
(write-output-techdisplays alldisps)))
finally, you could redesign your code to work without sideffects (those set!s).
that for-each could be a map.

In ClojureScript, how do I take a string and see if a function with that name exists in the Math object?

I'd like to take a user-supplied string, e.g. "abs", and see whether a function with that name exists in the Math object.
So, something like:
(.lookup Math "abs") ;; => <function>
(.lookup Math "abdominals") ;; => nil
I'd also like to get the function itself, so something like this would work:
((.lookup Math "abs") -1) ;; => 1
And how can constants be accessed?
(.lookup Math "PI") => 3.14159265
If it's the same as functions, there has to be a way to distinguish between functions and constants.
I've tried using .hasOwnProperty:
(print (.hasOwnProperty Math "E"))
But that results in errors:
TypeError: cljsfiddle.Math is undefined
Use js/Math, try on https://himera.herokuapp.com/index.html
Himera REPL v0.1.5
cljs.user> js/Math
#<[object Math]>
cljs.user> (.-abs js/Math)
#<function abs() { [native code] }>
cljs.user> (type (.-abs js/Math))
#<function Function() { [native code] }>
cljs.user> (fn? (.-abs js/Math))
true
also read https://himera.herokuapp.com/synonym.html
The immediate error is that Math is not accessible. The solution to that is to use js/Math.
ClojureScript:cljs.user> (.hasOwnProperty js/Math "E")
true
ClojureScript:cljs.user> (.hasOwnProperty js/Math "Earst")
false
Then, to get these properties out of Math, eval has to be used:
ClojureScript:cljs.user> (js/eval "Math.min")
#<function min() { [native code for Math.min, arity=2] }
>
ClojureScript:cljs.user> ((js/eval "Math.min") 1 3)
1
ClojureScript:cljs.user> (js/eval "Math.E")
2.718281828459045
Using eval on user-supplied strings is always dangerous, but this can be made be somewhat safe, by first checking .hasOwnProperty to ensure you're not running arbitrary code with eval. It's still suboptimal, though.
Finally, we can use number? and fn? to tell the difference between constants and functions:
ClojureScript:cljs.user> (number? (js/eval "Math.E"))
true
ClojureScript:cljs.user> (fn? (js/eval "Math.E"))
false
ClojureScript:cljs.user> (number? (js/eval "Math.sin"))
false
ClojureScript:cljs.user> (fn? (js/eval "Math.sin"))
true

Resources