How can i define such a macro in spin? - promela

I wrote the following model:
#define inc(sn)if :: sn < 255 -> sn = sn + 1; ::else -> sn = 1; fi;
#define inc_twice(sn) if :: sn+2 >255 -> sn= sn-253; ::else -> sn=sn+2; fi;
active proctype monitor()
{
byte sn = 255;
assert (inc(sn) ==1);
}
But the compiler fails as follows:
spin: test2.pml:9, Error: syntax error saw 'keyword: if' near 'if'
spin: test2.pml:9, Error: syntax error saw 'token: ::'
spin: test2.pml:9, Error: syntax error saw 'keyword: fi' near 'fi'
spin: test2.pml:11, Error: aborting (ana_stmnt)
child process exited abnormally.
How can i solve it?

I have met the same problem . And you can solve it by change your code into this :
#define inc(sn)if \\
:: sn < 255 -> sn = sn + 1 \\
::else -> sn = 1 \\
fi;
#define inc_twice(sn) if \\
:: sn+2 >255 -> sn= sn-253 \\
::else -> sn=sn+2 \\
fi;
I don't know what causes this issue, but I solve it by the above method.

Related

Syntax Errors in jquery.js for Doxygen

I'm seeing some errors with jquery.js with Doxygen external search.
Uncaught SyntaxError: Unexpected end of input
at b (jquery.js:2:765)
at Function.globalEval (jquery.js:2:2681)
at text script (jquery.js:2:81842)
at jquery.js:2:78358
at l (jquery.js:2:78475)
at XMLHttpRequest.<anonymous> (jquery.js:2:81117)
I looked at 'function b' on https://github.com/doxygen/doxygen/blob/master/jquery/jquery-3.6.0.min.js and it's identical to what I have on 1.9.1.
The code is compressed so it's hard to read & debug.
The function throwing one of the SyntaxErrors:
function b(e, t, n) {
var r, i, o = (n = n || E).createElement("script");
if (o.text = e, t)
for (r in c)(i = t[r] || t.getAttribute && t.getAttribute(r)) && o.setAttribute(r, i);
n.head.appendChild(o).parentNode.removeChild(o)
}

Octave parsing error

I making a basic bisection code, but a taking an error as:
>> asdfg
parse error near line 22 of file C:/Octave/Octave-4.2.1/bin\asdfg.m
syntax error
my code is :
a = [1 -9 -2 120 -130]
x0=1
x1=2
e=0,0132
while abs(x0-x1)/2 > e
gcc = (x0+x1)/2;
if polyval(a,x0)*polyval(a,gcc) < 0
x1=gcc;
else if polyval(a,x1)*polyval(a,gcc) < 0
x1=gcc;
else
printf("asfd")
end
end
BTW i made the code like matlab syntax as i know. I just know they are same syntax.
else if polyval(a,x1)*polyval(a,gcc) < 0
should be
elseif polyval(a,x1)*polyval(a,gcc) < 0
No space between else and if in MATLAB/Octave.

Julia: Inexact error when trying to get the integer part of a BigFloat

I am interested in getting the digits of a BigFloat in the form of bytes. I get a very strange error that I cannot debug. I provide a minimal example where the error appears.
function floatToBytes(x::BigFloat)
ret = zeros(UInt8, 4)
xs = significand(x)/2
b = UInt8(0)
for i = 1:4
xs *= 256
b = trunc(UInt8, xs)
ret[i] = b
xs -= b
end
return ret
end
println( floatToBytes(BigFloat(0.9921875001164153)) )
println( floatToBytes(BigFloat(0.9960937501164153)) )
What I get when running this is
UInt8[0xfe, 0x00, 0x00, 0x00]
ERROR: LoadError: InexactError()
Stacktrace:
[1] trunc(::Type{UInt8}, ::BigFloat) at ./mpfr.jl:201
etc.
It seems that it doesn't want to turn 255 into a UInt8. I can circumvent the problem by defining the function as
function floatToBytes(x::BigFloat)
ret = zeros(UInt8, 4)
xs = significand(x)/2
b = UInt8(0)
for i = 1:4
xs *= 256
try
b = trunc(UInt8, xs)
catch
b = trunc(UInt8, xs-1)+UInt8(1)
end
ret[i] = b
xs -= b
end
return ret
end
But this is highly unsatisfactory. What is going on here?
The problem looks like a bug in trunc for BigFloat. The problem is the current code does (typemin(T) <= x <= typemax(T)) || throw(InexactError(:trunc, T, x)) which throws an error because x is larger than 255 which is the typemax.
It actually needs to do the trunc in BigFloat domain and then cast to T (and have the cast check for typemax).
I've opened an issue regarding this at: https://github.com/JuliaLang/julia/issues/24041
In the meantime, a solution could be to do:
UInt8(trunc(xs))
i.e. trunc first and cast later. For example:
julia> UInt8(trunc(BigFloat(0.9960937501164153)*256))
0xff

How can I remove <math></math> multiline sections with Perl?

How can I remove multiline sections with Perl?
I have such wiki test code:
{|
|-
| colspan="2"|
: <math>
[\underbrace{\color{Red}4,2}_{4 > 2},5,1,7] \rightarrow
[2,\underbrace{\color{OliveGreen}4,5}_{4 < 5},1,7] \rightarrow
[2,4,\underbrace{\color{Red}5,1}_{5 > 1},7] \rightarrow
[2,4,1,\underbrace{\color{OliveGreen}5,7}_{5 < 7}]
</math>
|-
|
: <math>
[\underbrace{\color{OliveGreen}2,4}_{2 < 4},1,5,{\color{Blue}7}] \rightarrow
[2,\underbrace{\color{Red}4,1}_{4 > 1},5,{\color{Blue}7}] \rightarrow
[2,1,\underbrace{\color{OliveGreen}4,5}_{4 < 5},{\color{Blue}7}]
</math>
: <math>
[\underbrace{\color{Red}2,1}_{2 > 1},4,{\color{Blue}5},{\color{Blue}7}] \rightarrow
[1,\underbrace{\color{OliveGreen}2,4}_{2 < 4},{\color{Blue}5},{\color{Blue}7}]
</math>
: <math>
[\underbrace{\color{OliveGreen}1,2}_{1 < 2},{\color{Blue}4},{\color{Blue}5},{\color{Blue}7}]
</math>
|}
And I want to remove from this code all how to do it? I have done such code:
cat math-text.txt | perl -e 'while(<>) { s/<math>.+?<\/math>//gs; print $_; }'
It is not works but should since documentation explains that . will much new lines. How to do it?
The following is a python script which I use to extract all the mathematical formula from wikipedia dumps. Rather than using a multi-line regexp it scans for occurrences of <math> </math> and uses the position on the line to work out where the actual position on the line is and uses a finite state machine to find the actual equations, basically with two states determined by inEqn. It does a few other things like find the title and name space and attributes in the maths tags.
As dumps are in the order of 100MB using a line by line approach may well end up being more efficient than multi-line regexps.
import sys
import re
titleRE = re.compile('<title>(.*)</title>')
nsRE = re.compile('<ns>(.*)</ns>')
mathRE = re.compile('</?math(.*?)>')
pageEndRE = re.compile('</page>')
title =""
attr = ""
ns = -1
inEqn = 0
for line in sys.stdin:
m = titleRE.search(line)
if m :
title = m.group(1)
expression = ""
inEqn = 0
m = nsRE.search(line)
if m :
ns = m.group(1)
start = 0
pos = 0
m = mathRE.search(line,pos)
while m :
if m.group().startswith('<math'):
attr = m.group(1)
start = m.end()
pos = start
expression = ""
inEqn = 1
if m.group() == '</math>' :
end = m.start()
expression = ' '.join([expression,line[start:end]])
print title,'\t',attr,'\t',expression.lstrip().replace('<','<').replace('>','>').replace('&','&')
pos = m.end()
expression = ""
start = 0
inEqn = 0
m = mathRE.search(line,pos)
if start > 0 :
expression = line[start:].rstrip()
elif inEqn :
expression = ' '.join([expression,line.rstrip()])
Another option might be to consider an xml parser. A SAX or DOM based parser would be able to find the equations. This might be worth considering if you want to do more sophisticated analysis of the wiki-text.

Count number of occurances of an element in a list

I have the following function:
getcountof(x,l::ls) =
if x=l then (1 + getcountof(x,ls))
else getcountof(x,ls)
|getcountof(x,[]) = 0;
Can someone tell me whats wrong in it?
I get the error:
stdIn:1.2-1.17 Error: syntax error: deleting ELSE ID
stdIn:1.22-20.12 Error: syntax error: deleting RPAREN BAR ID
You've missed the fun keyword from the start of your definition!
Try this instead:
fun getcountof(x,l::ls) =
if x=l then (1 + getcountof(x,ls))
else getcountof(x,ls)
| getcountof(x,[]) = 0;
This is a trap for people familiar with Haskell.