-. y (Not)

Back to: Vocabulary

Gives the complement of numeric y.

For booleans (zero or one), this is boolean not; for probabilities (from zero to one), this is the complementary probability. The general result is equivalent to one minus y.

This following is an animation of boolean "not" that might be useful to those new to J

Embedded application/x-shockwave-flash

Monadic Examples

   -. 0 1                         NB. Boolean "not"
1 0
   -. 0.25 0.3333333 0.80         NB. Complement of probabilities ("1-p" versus "p")
0.75 0.6666667 0.2

Common uses

Invert boolean result:

   -.'encephalogram' e. 'aeiouAEIOU'                   NB. Which characters are not vowels
0 1 1 0 1 1 0 1 0 1 1 0 1
   str#~-.str e. 'aeiouAEIOU' [ str=. 'encephalogram'  NB. Show only non-vowels
ncphlgrm

This latter example is more elegantly accomplished using the dyadic form - see below.

Reverse meaning of trigger of an "if." statement:

   if. -. aa -: bb do. ...         NB. (fragment) If "aa" is not equivalent to "bb" do ...

Calculate probability of event not happening given probability of it happening:

   %6         NB. Probability of six turning up on roll of fair 6-sided die 
0.16666667
   -.%6       NB. Probability of six not turning up on roll of same...
0.83333333
   (-.%6)^4   NB. Probability of no sixes turning up on roll of 4 dice
0.48225309
   -.(-.%6)^4 NB. Probability of at least one six turning up on roll of 4 dice
0.51774691

See Also


x -. y (Less or Without)

Back to: Vocabulary

Remove items of y from x.

In terms of set theory, the expression A-.B could be illustrated like this:

AwithoutB.png.

Practically, this helps avoid circumlocutions like the second "Common Use" shown above, i.e. we could remove all vowels from a string this way:

   'encephalogram' -. 'aeiouAEIOU'
ncphlgrm

Common uses

Read a text file but exclude all CRs (carriage return characters):

   fl=. CR-.~fread 'file.txt'

After partitioning the fl variable above on its last character, presumably LF, to treat it as a vector of lines, remove any blank lines.

   fl=. <;._2 fl,LF#~LF~:{:fl   NB. Enclose each line delimited by LF (ensuring there is a terminal LF).
   fl=. fl-.a:                  NB. Remove empties which are enclosed empty vectors, aka "ace" or "a:".

See Also


CategoryVoc

Vocabulary/minusdot (last edited 2011-06-06 20:08:31 by IanClark)