[Scilab-users] Generating a boolean vector or matrix

Federico Miyara fmiyara at fceia.unr.edu.ar
Thu Sep 5 09:30:47 CEST 2019


Christophe,

Thanks!

Two more questions (for anybody reading and willing to reply):

1) Is there an exclusive or function? I couldn't find it, a search leads 
to the XOR mode of combining graphic pixels. It would be most useful 
since it is one of the operations in the Galois field GF(2). Currently, 
as I needed it, I created a very simple implementtion of the xor using 
and, or and negation, but I wonder if a direct implementation would be 
more efficient.

2) How much memory does it take a boolean scalar? Does a boolean vector 
eploit the fact that a byte could theoretically host up to 8 boolean 
components?

By the way, using booleans I very much improved speed in massive 
operations involving sequences of 0's and 1's respect to using decimal 
o's nd 1's and applying modulo 2 to the sum.

This is a sample code:

// Defining exclusive or, xor

function  u=xor(v, w)
    // Probably some parenthesis are unnecessary
    u  =  ((~v)&w)  |  (v&(~w));
endfunction
After running this,n  =  11;

tic
//A = ones(1,n);
A  =  ones(1,n)  &  %t;
no  =  n  -  2;
for  k=1:2^n  -1
     y(k)  =  A(n);
     //A = [modulo(A(n)+ A(no), 2), A(1:n-1)];
     A  =  [(xor(A(n),A(no)),  A(1:n-1)];
end
toc

It can be checked that using the commented lines for A instead of the 
uncommented ones the computing time is larger using the modulo 2 way of 
simulating a XOR than using boolean variables. For n larger the 
difference is even more noticeable.

This is part of a code I will post when ready for generating maximum 
length sequences.

Regards,

Federico Miyara

On 04/09/2019 04:49, Dang Ngoc Chan, Christophe wrote:
> Hello,
>
>> De : Federico Miyara
>> Envoyé : mercredi 4 septembre 2019 09:11
>>
>> I need to create a boolean vector, such as [%t, %t, %t, %t] […] I
>> couldn't find a function similar to ones(1,n).
>>
>> However I've found a workaround:
>>
>> a = ones(1,n) & %t
>> […]
>> 1) Why does it work?
> Because "A number is considered as %F (false) if it is 0 or 0+0i. Otherwise (including %nan), it is equivalent to %T (true)."
>
> https://help.scilab.org/docs/6.0.2/en_US/and.html
>
>> 2) Is there some native function to create bolean matrices
> No, but you have several other ways, you may test to find the one that is the less greedy.
>
> I propose this one:
>
> a = (ones(1,n) == 1)
>
> Apart from this, I think most (if not all) functions that require boolean also accept numbers In the same way as and() (but I may be mistaken).
>
> Regards
>
> --
> Christophe Dang Ngoc Chan
> Mechanical calculation engineer
>
> General
> This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
>



---
El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190905/a5f5100d/attachment.htm>


More information about the users mailing list