Suppose i have such table
if i use syntax to indicate missing values for variables, i must for each variable write something like
if missing (s1) s1=999.
MISSING VALUES s1 (999).
exe
if missing (s20) s20=999.
MISSING VALUES s20 (999).
exe
and so on.
but if i have 100 variables it will long and difficult.
is it possible to inditace missing values at once for all vars in my data
something like?
if missing (s1-q35) s1-q35=999.
MISSING VALUES s1-q35 (999).
exe
You can use recode like this:
recode s1 s2 s3 s4 s5 s6 .... q1 q2 q3 q4 q5 ..... (miss=999).
If some of your variables are consecutive in the data you can use "to". For example:
recode s1 to s21 q1 to q35 (miss=999).
If they are all consecutive you can use to for all of them:
missing values s1 to q35 (999).
I would like to rearrange an equation in a way that certain variables only appear on the left side using wxMaxima.
%i: eq: term1 = term2 ;
%i: fun(eq,[v]);
%o: term3 = term4
Where the allowed symbols for the terms would be something like this:
term1 = all
term2 = all
term3 = only [v] and operators
term4 = all but [v]
[v] = the variable (or list) that I want to be on the left side
I tried to get something done with matchdeclare and defrule but I couldn't even get the b of a=b+c to the left side. I am not even sure if defrule is the correct approach as term 1 and 2 have nothing to do with 3 and 4. Is there a way to solve for lists?
UPDATE:
I came up with "something". It is not yet what I initially wanted, but at least closer.
It is basically a substitution. I can provide a left hand side and the function tries to solve for it. Of course this exact left side might not be possible so that some variables remain on the right side. But one can specify one variable that should be eliminated on the right.
expr: a=b+c*d+e $
left: log(a+b) $
notright: b $
solve_form( expr, left, notright);
results in:
[log(b+a)=log(-e-c*d+2*a)]
Now, if I instead choose log(a-b) for the left side the output is:
[log(a-b)=log(e+c*d)]
which is pretty much what I wanted. Variables a and b are on the left side, but not on the right.
But I have to give an explicit left side. I would love to have a function that would find an arbitrary left side on its own so that neither a nor b are on the right side.
The obvious solution would have been:[a-b=e+c*d]
Function:
solve_form(expr,lterm,substvar) := block(
[z],
lterm: z = lterm,
solve(lterm,substvar),
ev(expr,%%),
solve(%%,z),
ev(%%,lterm)
)$
Alternative function that does not need the notright input.
solveform(expr,zz_term) := block(
[z,zz_term_vars,slist],
zz_term: zz = zz_term,
zz_term_vars: listofvars(rhs(zz_term)),
slist:[],
for i:1 thru length(zz_term_vars) do block(
solve(zz_term,zz_term_vars[i]),
ev(expr,%%),
slist: append(slist,solve(%%,zz))
),
listify(setify(ev(slist,zz_term)))
)$
I think solve, linsolve, algsys, and eliminate have more or less the effect you are looking for.
I'm trying to debug "dypgen", a parser-generator and so a program that is writing another program, because I noticed some bug, that is essential for my project. I have asked the developer, but he doesn't answer and I asked also over the mailing list. Nothing happend, so I try.
My project is the following, I have presented the essential part in an unanswered question on stackoverflow:
ambiguity handling of dypgen
I found there some difference, where should be no difference in parsing two different, but very similar expressions. I have a parser, that parses
K1|K2 u K3|K4
as:
kon1 { K1 u K4 }
kon1 { K2 u K4 }
and
K1|K2 y K3|K4
as
kon2 { K1 y K3 }
kon2 { K2 y K3 }
kon2 { K1 y K4 }
kon2 { K2 y K4 }
the non-terminals "kon1" and "kon2" are implemented very similar and there should be no difference. all should be a permutation as the second case.
I run the ocamldebugger with a script through the two cases and wrote the output into two files (2-4 MB). Here is screenshot of meld (an editor, that can find differences between files and show them graphically), that shows a little part of the comparison. On the border you can see two major parts in green, where differences show up.
One thing with this comparison is, that I would like to get rid of all these steps through List, Set, Hashtable modules and see just the important parts, that go out from my files. I would like to have a function in ocamldebug as "step over" not step into.
But there is another problem, precisely, that this automaton, that dypgen creates, consists of lists of objects and functions. List.fold is used to work on these lists. How I can find out, where I am in the parser-automaton with these List.fold-calls?
thx for any help!
I have two sequences of strings. I wanna wether get a sequence which is reduced by those items, which are also in sequence 2; or to compare those two sequences and get the information, if at least one item of sequence 1 is also in sequence 2.
A simple compare ( $seq1 = $seq2 ) works for me only with a sequence of numbers, or am I doing something wrong?
Glad about any help! :)
The = operator should suffice, see example http://xsltransform.net/gWmuiJ6 which does
<xsl:variable name="seq1" select="'foo', 'bar', 'foobar'"/>
<xsl:variable name="seq2" select="'a', 'foo', 'b'"/>
<xsl:variable name="seq3" select="'a', 'b', 'c'"/>
<xsl:value-of select="$seq1 = $seq2, $seq1 = $seq3"/>
and outputs true false.
If you want some value based intersection then see also http://www.xsltfunctions.com/xsl/functx_value-intersect.html.
I want to make an arithmetic solver in Prolog that can have +,-,*,^ operations on numbers >= 2. It should also be possible to have a variable x in there. The input should be a prefix expression in a list.
I have made a program that parses an arithmetic expression in prefix format into a syntax tree. So that:
?- parse([+,+,2,9,*,3,x],Tree).
Tree = plus(plus(num(2), num(9)), mul(num(3), var(x))) .
(1) At this stage, I want to extend this program to be able to solve it for a given x value. This should be done by adding another predicate evaluate(Tree, Value, Solution) which given a value for the unknown x, calculates the solution.
Example:
?- parse([*, 2, ^, x, 3],Tree), evaluate(Ast, 2, Solution).
Tree = mul(num(2), pow(var(x), num(3))) ,
Solution = 16.
I'm not sure how to solve this problem due to my lack of Prolog skills, but I need a way of setting the var(x) to num(2) like in this example (because x = 2). Maybe member in Prolog can be used to do this. Then I have to solve it using perhaps is/2
Edit: My attempt to solving it. Getting error: 'Undefined procedure: evaluate/3 However, there are definitions for: evaluate/5'
evaluate(plus(A,B),Value,Sol) --> evaluate(A,AV,Sol), evaluate(B,BV,Sol), Value is AV+BV.
evaluate(mul(A,B),Value,Sol) --> evaluate(A,AV,Sol), evaluate(B,BV,Sol), Value is AV*BV.
evaluate(pow(A,B),Value,Sol) --> evaluate(A,AV,Sol), evaluate(B,BV,Sol), Value is AV^BV.
evaluate(num(Num),Value,Sol) --> number(Num).
evaluate(var(x),Value,Sol) --> number(Value).
(2) I'd also want to be able to express it in postfix form. Having a predicate postfixform(Tree, Postfixlist)
Example:
?- parse([+, *, 2, x, ^, x, 5 ],Tree), postfix(Tree,Postfix).
Tree = plus(mul(num(2), var(x)), pow(var(x), num(5))) ,
Postfix = [2, x, *, x, 5, ^, +].
Any help with (1) and (2) would be highly appreciated!
You don't need to use a grammar for this, as you are doing. You should use normal rules.
This is the pattern you need to follow.
evaluate(plus(A,B),Value,Sol) :-
evaluate(A, Value, A2),
evaluate(B, Value, B2),
Sol is A2+B2.
And
evaluate(num(X),_Value,Sol) :- Sol = X.
evaluate(var(x),Value,Sol) :- Sol = Value.