The correct way of configuring tactics in z3.py is using "With".
E.g.
t = With(Tactic('simplify'), som=True)
However, some option names contain a "." in it, such as "arith.solver" in tactic "qflia". If we code in the same way
t = With(Tactic('qflia'), arith.solver=1)
The system gives an error "SyntaxError: keyword can't be an expression". I guess this is against the syntax rule for keyword in python.
How should I configure the options whose names contain "."? Or I am referring to a wrong list of tactics configuration options? The one I was using is output by command "(help-tactic)" on z3 not z3.py.
The trick is instead of using "With", we should use "set_param" or "set_option". E.g.
set_param('smt.phase_selection',5)
Related
I am new to Latex, and the question is just for curiosity. I wonder why the \newcommand command in latex has a different syntax than other commands?
The syntax of \newcommand is
\newcommand{<arg>}[<options>][<options>]{<arg>}
while the syntax for user-defined commands (or macros?) are like
\<command>[<options>]{<arg>}{<arg>}
I did not find any method for a user to define a command whose use model is something like: (i.e. [] appears after {})
\<command>{<args>}[<options>]{<args>}
So how do we differentiate the \newcommand command with other user-defined commands? Call them preserved command? Some commands whose syntax not definable by the user?
It does not really have a different syntax, it's just defined in a way that gobbles its arguments differently. Here are some examples to highlight this...
Consider
\documentclass{article}
\newcommand{\firstcmd}[1]{first: #1}
\newcommand{\secondcmd}[2][opt2]{second: #1/#2}
\newcommand{\thirdcmd}[1]{third: #1 \fourthcmd}
\newcommand{\fourthcmd}[2][opt4]{fourth: #1/#2}
\begin{document}
\firstcmd{abc}
\secondcmd{def}
\secondcmd[abc]{def}
\thirdcmd{ghi}{jkl}
\thirdcmd{ghi}[jkl]{mno}
\fourthcmd{mno}
\fourthcmd[mno]{pqr}
\end{document}
\firstcmd, \secondcmd and \fourthcmd are all defined in the usual way. \firstcmd takes a single, mandatory argument, while \secondcmd and \fourthcmd each take a single optional argument followed by a mandatory argument. That is, they have the form \<cmd>[.]{..}.
\thirdcmd is defined to take a single, mandatory argument, but is nested with \fourthcmd. So, while it's definition seems to require one argument, nesting it causes it's use to resemble something that could take two or three arguments, depending on whether you supply an optional argument or not.
In this way, any configuration of optional/mandatory argument sequence is possible. \newcommand is defined in a similar way. Regardless, you should consider usability when defining commands that may have optional arguments scattered throughout its argument sequence. For example, let's say you defined \mycmd{.}[..][...]{....}, hoping to allow two optional arguments next each other. If the end-user specifies
\mycmd{.}[..]{....}
the execution (picking up appropriate arguments in the way they're intended) would happen as expected. However, if the end-user specifies
\mycmd{.}[...]{....}
hoping to skip the second optional argument [..], the execution will most certainly fail (or not happen as expected), since there's no distinction which optional argument is being left out/supplied.
A general approach to avoiding this confusion would be to use a key-valued approach. For example, define a command with a single optional argument that takes a key-value list:
\mycmd[key1=value, key2=value, ...]{<arg>}{...}
This will clearly distinguish what is being passed as optional content, and allow you to specify default values for keys that are not present (see the keyval or xkeyval packages).
Regardless, other packages also provide an easier means to intermix optional and mandatory arguments, if that's what you're after. Here's on example using xparse:
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\mycmd}{o m O{opt2} m}{%
mycmd:
\IfValueTF{#1}
{#1}
{no opt1}%
/#2/#3/#4%
}
\begin{document}
\mycmd{abc}{def}
\mycmd[abc]{def}{ghi}
\mycmd{abc}[def]{ghi}
\mycmd[abc]{def}[ghi]{jkl}
\end{document}
I should check existence of values based on some conditions.
i.e. i have 3 variables, varA, varB and varC. varC should not be empty only if varA>varB (condition).
i normally use some syntax to check any of the variables and run a frequency of any of them to see if there are errors:
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
exe.
fre ck_varC.
exe.
I had some errors when the condition became complex and when in the condition there are missing() or other functions but i could have made a mistake.
do you think there is an easier way of doing this checks?
thanks in advance
EDIT: here an example of what i mean, think at a questionnaire with some routing, you ask age to anyone, if they are between 17 and 44 ask them if they work, if they work ask them how many hours.
i have an excel tool where i put down all variables with all conditions, then it will generate the syntax in the example, all with the same structure for all variables, considering both situations, we have a value that shouldn't be there or we don't have a value that should be there.
is there an easier way of doing that? is this structure always valid no matter what is the condition?
In SPSS, missing values are not numbers. You need to explicitly program those scenarios as well. you got varC covered (partially), but no scenario where varA or varB have missing data is covered.
(As good practice, maybe you should initialize your check variable as sysmis or 0, using syntax):
numeric ck_varC (f1.0).
compute ck_varC=0.
if missing(varC) and (varA>varB) ck_varC=1.
if not(missing(varC)) and not(varA>varB) ck_varC=2.
***additional conditional scenarios go here:.
if missing(varA) or missing(varB) ck_varC=3.
...
fre ck_varC.
By the way - you do not need any of the exe. commands if you are going to run your syntax as a whole.
Later Edit, after the poster updated the question:
Your syntax would be something like this. Note the use of the range function, which is not mandatory, but might be useful for you in the future.
I am also assuming that work is a string variable, so its values need to be referenced using quotation signs.
if missing(age) ck_age=1.
if missing(work) and range(age,17,44) ck_work=1.
if missing(hours) and work="yes" ck_hours=1.
if not (missing (age)) and not(1>0) ck_age=2. /*this will never happen because of the not(1>0).
if not(missing(work)) and (not range(age,17,44)) ck_work=2. /*note that if age is missing, this ck_work won't be set here.
if not(missing(hours)) and (not(work="yes")) ck_hours=2.
EXECUTE.
String variables are case sensitive
There is no missing equivalent in strings; an empty blank string ("") is still a string. not(work="yes") is True when work is blank ("").
I am using the Data > Merge Files > Add Variables in SPSS. The two .sav files both contain a variable called "Student_No" which is numeric with the same width in each file. I am using this as the key variable in which to match cases. I am not indicating that cases are not sorted. It makes no difference if I indicate that the active or non-active data set is keyed. In either case the new variables are not properly matched with the cases.
What are some of the potential problems that might be causing this mismatch?
The dialog box pastes STAR JOIN syntax in some cases and MATCH FILES in others. There were some problems with STAR JOIN in older versions of Statistics, so you might need to use MATCH FILES instead. See the Command Syntax Reference for that command on how to do this.
Frequently, PSPP/SPSS syntax documentation (example) suggests I must to pass a list of variables with /VARIABLES=var_list and this is not an optional subcommand.
But I have a lot of datasets to process. I would like to programmatically get a list of all variables in the active dataset, pass that to a procedure, and then generate a file from the procedure output.
I've tried /VARIABLES=* but that didn't work.
error: DESCRIPTIVES: Syntax error at `*': expecting variable name.
You can use display variables. or display dictionary. to generate a table of all variables and their attributes which could then be captured using OMS. However if you want to pass all variables to a function that expects a list you can use all, i.e. descriptives /variables= all..
/VARIABLES is often optional in procedures, but ALL stands for all the variables. If you need to refine by a particular measurement level, type or other metadata, try the SPSSINC SELECT VARIABLES extension command. This command applies various filters based on the metadata and creates a macro with the variables that pass. You can then use that in any context.
Suppose I define a solver in z3py as:
s = Then('qflia','skip').solver()
Is there way a to check the values of configuration options for s?
You can use the help function to get a list of parameters that the tactic is sensitive to, and if not set to anything else, they will have their default values. Note that tactics may change parameters internally, e.g., when the with tactic is used. Since tactics can override parameters multiple times, using different parameters at different points, there is in general not just a single value for a given parameter, and thus also no way to extract the current parameter settings.