1 USING: help.markup help.syntax kernel math math.functions
5 ARTICLE: "math-vectors-arithmetic" "Vector arithmetic"
6 "Vector/vector binary operations:"
15 "Vector unary operations:"
25 "Vector/scalar and scalar/vector binary operations:"
39 "Saturated arithmetic (only on " { $link "specialized-arrays" } "):"
45 "Inner product and norm:"
54 "Comparing entire vectors:"
60 ARTICLE: "math-vectors-shuffle" "Vector shuffling, packing, and unpacking"
62 "These operations are primarily meant to be used with " { $vocab-link "math.vectors.simd" } " types. The software fallbacks for types not supported by hardware will not perform well."
73 "See the " { $vocab-link "math.vectors.conversion" } " vocabulary for packing, unpacking, and converting vectors." ;
75 ARTICLE: "math-vectors-logic" "Vector component- and bit-wise logic"
77 "See " { $link "math-vectors-simd-logic" } " for notes about using comparison and logical operations with SIMD vector types."
80 "Element comparisons:"
104 "Element logical operations:"
114 "Entire vector tests:"
121 { $subsections vshuffle } ;
123 ARTICLE: "math-vectors-misc" "Miscellaneous vector functions"
132 ARTICLE: "math-vectors-simd-logic" "Componentwise logic with SIMD vectors"
133 "Processor SIMD units supported by the " { $vocab-link "math.vectors.simd" } " vocabulary represent boolean values as bitmasks, where a true result's binary representation is all ones and a false representation is all zeroes. This is the format in which results from comparison words such as " { $link v= } " return their results and in which logic and test words such as " { $link vand } " and " { $link vall? } " take their inputs when working with SIMD types. For a float vector, false will manifest itself as " { $snippet "0.0" } " and true as a " { $link POSTPONE: NAN: } " literal with a string of on bits in its payload:"
135 "USING: math.vectors math.vectors.simd prettyprint ;"
136 "float-4{ 1.0 2.0 3.0 0/0. } float-4{ 1.0 -2.0 3.0 0/0. } v= ."
137 "float-4{ NAN: -20000000 0.0 NAN: -20000000 0.0 }"
139 "For an integer vector, false will manifest as " { $snippet "0" } " and true as " { $snippet "-1" } " (for signed vectors) or the largest representable value of the element type (for unsigned vectors):"
141 "USING: math.vectors math.vectors.simd prettyprint alien.c-types ;
143 int-4{ 1 2 3 0 } int-4{ 1 -2 3 4 } v=
144 uchar-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 }
145 uchar-16{ 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 } v<
148 uchar-16{ 255 255 255 255 255 255 255 255 0 0 0 0 0 0 0 0 }"
150 "This differs from Factor's native representation of boolean values, where " { $link f } " is false and every other value (including " { $snippet "0" } " and " { $snippet "0.0" } ") is true. To make it easy to construct literal SIMD masks, " { $link t } " and " { $link f } " are accepted inside SIMD literal syntax and expand to the proper true or false representation for the underlying type:"
152 "USING: math.vectors math.vectors.simd prettyprint alien.c-types ;
155 "int-4{ 0 0 -1 0 }" }
156 "However, extracting an element from a boolean SIMD vector with " { $link nth } " will not yield a valid Factor boolean. This is not generally a problem, since the results of vector comparisons are meant to be consumed by subsequent vector logical and test operations, which will accept SIMD values in the native boolean format."
158 "Providing a SIMD boolean vector with element values other than the proper true and false representations as an input to the vector logical or test operations is undefined. Do not count on operations such as " { $link vall? } " or " { $link v? } " using bitwise operations to construct their results."
160 "This applies to the output of the following element comparison words:"
167 { $link vunordered? }
169 "This likewise applies to the " { $snippet "mask" } " argument of " { $link v? } " and to the inputs and outputs of the following element logic words:"
177 "Finally, this applies to the inputs of these vector test words:"
184 ARTICLE: "math-vectors" "Vector operations"
185 "Any Factor sequence can be used to represent a mathematical vector, however for best performance, the sequences defined by the " { $vocab-link "specialized-arrays" } " and " { $vocab-link "math.vectors.simd" } " vocabularies should be used."
187 "math-vectors-arithmetic"
189 "math-vectors-shuffle"
193 ABOUT: "math-vectors"
196 { $values { "v" { $sequence number } } { "w" { $sequence number } } }
197 { $description "Negates each element of " { $snippet "v" } "." } ;
200 { $values { "v" { $sequence number } } { "w" "a sequence of non-negative real numbers" } }
201 { $description "Takes the absolute value of each element of " { $snippet "v" } "." } ;
204 { $values { "v" "a sequence of non-negative real numbers" } { "w" "a sequence of non-negative real numbers" } }
205 { $description "Takes the square root of each element of " { $snippet "v" } "." }
206 { $warning "For performance reasons, this does not work with negative inputs, unlike " { $link sqrt } "." } ;
209 { $values { "v" { $sequence real } } { "w" { $sequence real } } }
210 { $description "Takes the " { $link floor } " of each element of " { $snippet "v" } "." } ;
213 { $values { "v" { $sequence real } } { "w" { $sequence real } } }
214 { $description "Takes the " { $link ceiling } " of each element of " { $snippet "v" } "." } ;
217 { $values { "v" { $sequence real } } { "w" { $sequence real } } }
218 { $description "Truncates each element of " { $snippet "v" } "." } ;
221 { $values { "n" number } { "v" { $sequence number } } { "w" { $sequence number } } }
222 { $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ;
225 { $values { "v" { $sequence number } } { "n" number } { "w" { $sequence number } } }
226 { $description "Adds " { $snippet "n" } " to each element of " { $snippet "v" } "." } ;
229 { $values { "n" number } { "v" { $sequence number } } { "w" { $sequence number } } }
230 { $description "Subtracts each element of " { $snippet "v" } " from " { $snippet "n" } "." } ;
233 { $values { "v" { $sequence number } } { "n" number } { "w" { $sequence number } } }
234 { $description "Subtracts " { $snippet "n" } " from each element of " { $snippet "v" } "." } ;
237 { $values { "n" number } { "v" { $sequence number } } { "w" { $sequence number } } }
238 { $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ;
241 { $values { "v" { $sequence number } } { "n" number } { "w" { $sequence number } } }
242 { $description "Multiplies each element of " { $snippet "v" } " by " { $snippet "n" } "." } ;
245 { $values { "n" number } { "v" { $sequence number } } { "w" { $sequence number } } }
246 { $description "Divides " { $snippet "n" } " by each element of " { $snippet "v" } "." }
247 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
250 { $values { "v" { $sequence number } } { "n" number } { "w" { $sequence number } } }
251 { $description "Divides each element of " { $snippet "v" } " by " { $snippet "n" } "." }
252 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
255 { $values { "n" number } { "v" { $sequence number } } { "w" { $sequence number } } }
256 { $description "Raises " { $snippet "n" } " to the power of each element of " { $snippet "v" } "." } ;
259 { $values { "v" { $sequence number } } { "n" number } { "w" { $sequence number } } }
260 { $description "Raises each element of " { $snippet "u" } " to the power of " { $snippet "v" } "." } ;
263 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
264 { $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise." } ;
267 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
268 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise." } ;
271 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
272 { $description "Adds and subtracts alternate elements of " { $snippet "v" } " and " { $snippet "u" } " component-wise. Elements at even indexes are subtracted, while elements at odd indexes are added." }
275 "USING: math.vectors prettyprint ;"
276 "{ 1 2 3 } { 2 3 2 } v+- ."
282 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
283 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise; any components which become negative are set to zero." } ;
286 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
287 { $description "Multiplies " { $snippet "u" } " and " { $snippet "v" } " component-wise." } ;
290 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
291 { $description "Divides " { $snippet "u" } " by " { $snippet "v" } " component-wise." }
292 { $errors "May throw an error if a division by zero occurs; see " { $link "division-by-zero" } "." } ;
295 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
296 { $description "Raises " { $snippet "u" } " to the power of " { $snippet "v" } " component-wise." } ;
299 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
300 { $description "Creates a sequence where each element is the maximum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
301 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmax ." "{ 1 6 5 }" } } ;
304 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
305 { $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
306 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ;
309 { $values { "v" { $sequence real } } { "min" { $sequence real } } { "max" { $sequence real } } { "w" { $sequence real } } }
310 { $description "Creates a sequence where each element is clamped to the minimum and maximum elements of the " { $snippet "min" } " and " { $snippet "max" } " sequences." }
313 "USING: math.vectors prettyprint ;"
314 "{ -10 30 120 } { 0 0 0 } { 100 100 100 } vclamp ."
320 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "x" real } }
321 { $description "Computes the dot product of two vectors." } ;
324 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "x" real } }
325 { $description "Computes the Hermitian inner product of two vectors." } ;
328 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
329 { $description "Adds " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." }
333 "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
334 "SPECIALIZED-ARRAY: uchar"
335 "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } vs+ ."
336 "uchar-array{ 170 255 220 }"
338 "Without saturation:"
340 "USING: alien.c-types math.vectors prettyprint specialized-arrays ;"
341 "SPECIALIZED-ARRAY: uchar"
342 "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } v+ ."
343 "uchar-array{ 170 14 220 }"
348 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
349 { $description "Subtracts " { $snippet "v" } " from " { $snippet "u" } " component-wise with saturation." } ;
352 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence number } } }
353 { $description "Multiplies " { $snippet "u" } " and " { $snippet "v" } " component-wise with saturation." } ;
356 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
357 { $description "Takes the bitwise and of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
358 { $notes "Unlike " { $link bitand } ", this word may be used on a specialized array of floats or doubles, in which case the bitwise representation of the floating point numbers is operated upon." } ;
361 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
362 { $description "Takes the bitwise and-not of " { $snippet "u" } " and " { $snippet "v" } " component-wise, where " { $snippet "x and-not y" } " is defined as " { $snippet "not(x) and y" } "." }
363 { $notes "This word may be used on a specialized array of floats or doubles, in which case the bitwise representation of the floating point numbers is operated upon." } ;
366 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
367 { $description "Takes the bitwise or of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
368 { $notes "Unlike " { $link bitor } ", this word may be used on a specialized array of floats or doubles, in which case the bitwise representation of the floating point numbers is operated upon." } ;
371 { $values { "u" { $sequence real } } { "v" { $sequence real } } { "w" { $sequence real } } }
372 { $description "Takes the bitwise exclusive or of " { $snippet "u" } " and " { $snippet "v" } " component-wise." }
373 { $notes "Unlike " { $link bitxor } ", this word may be used on a specialized array of floats or doubles, in which case the bitwise representation of the floating point numbers is operated upon." } ;
376 { $values { "v" { $sequence integer } } { "n" "a non-negative integer" } { "w" { $sequence integer } } }
377 { $description "Shifts each element of " { $snippet "v" } " to the left by " { $snippet "n" } " bits." }
378 { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
381 { $values { "v" { $sequence integer } } { "n" "a non-negative integer" } { "w" { $sequence integer } } }
382 { $description "Shifts each element of " { $snippet "v" } " to the right by " { $snippet "n" } " bits." }
383 { $notes "Undefined behavior will result if " { $snippet "n" } " is negative." } ;
386 { $values { "v" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
387 { $description "Shifts the entire SIMD array to the left by " { $snippet "n" } " bytes, filling the vacated right-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ;
390 { $values { "v" "a SIMD array" } { "n" "a non-negative integer" } { "w" "a SIMD array" } }
391 { $description "Shifts the entire SIMD array to the right by " { $snippet "n" } " bytes, filling the vacated left-hand bits with zeroes. This word may only be used in a context where the compiler can statically infer that the input is a SIMD array." } ;
394 { $values { "u" sequence } { "v" sequence } { "w" sequence } }
395 { $description "Creates a new sequence of the same type as and twice the length of " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." }
397 { $example "USING: kernel math.vectors prettyprint ;
399 { \"A\" \"B\" \"C\" \"D\" } { \"1\" \"2\" \"3\" \"4\" } vmerge ."
400 "{ \"A\" \"1\" \"B\" \"2\" \"C\" \"3\" \"D\" \"4\" }"
404 { $values { "u" sequence } { "v" sequence } { "h" sequence } { "t" sequence } }
405 { $description "Creates two new sequences of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements of " { $snippet "u" } " and " { $snippet "v" } "." }
406 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction per output value." }
408 { $example "USING: kernel math.vectors prettyprint ;
410 { \"A\" \"B\" \"C\" \"D\" } { \"1\" \"2\" \"3\" \"4\" } (vmerge) [ . ] bi@"
411 "{ \"A\" \"1\" \"B\" \"2\" }
412 { \"C\" \"3\" \"D\" \"4\" }"
416 { $values { "u" sequence } { "v" sequence } { "h" sequence } }
417 { $description "Creates a new sequence of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the first half of " { $snippet "u" } " and " { $snippet "v" } "." }
418 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
420 { $example "USING: kernel math.vectors prettyprint ;
422 { \"A\" \"B\" \"C\" \"D\" } { \"1\" \"2\" \"3\" \"4\" } (vmerge-head) ."
423 "{ \"A\" \"1\" \"B\" \"2\" }"
427 { $values { "u" sequence } { "v" sequence } { "t" sequence } }
428 { $description "Creates a new sequence of the same type and size as " { $snippet "u" } " and " { $snippet "v" } " by interleaving the elements from the tail half of " { $snippet "u" } " and " { $snippet "v" } "." }
429 { $notes "For hardware-supported SIMD vector types this word compiles to a single instruction." }
431 { $example "USING: kernel math.vectors prettyprint ;
433 { \"A\" \"B\" \"C\" \"D\" } { \"1\" \"2\" \"3\" \"4\" } (vmerge-tail) ."
434 "{ \"C\" \"3\" \"D\" \"4\" }"
437 { vmerge (vmerge) (vmerge-head) (vmerge-tail) } related-words
440 { $values { "u" "a SIMD array" } { "n" "a non-negative integer" } { "v" "a SIMD array" } }
441 { $description "Outputs a new SIMD array of the same type as " { $snippet "u" } " where every element is equal to the " { $snippet "n" } "th element of " { $snippet "u" } "." }
444 "USING: alien.c-types math.vectors math.vectors.simd prettyprint ;"
445 "int-4{ 69 42 911 13 } 2 vbroadcast ."
446 "int-4{ 911 911 911 911 }"
451 { $values { "v" "a SIMD array" } { "perm" "an array of integers, or a byte-array" } { "w" "a SIMD array" } }
452 { $description "Permutes the elements of a SIMD array. Duplicate entries are allowed in the permutation. The " { $snippet "perm" } " argument can have one of two forms:"
454 { "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." }
455 { "A byte array or SIMD vector of the same byte length as the vector. This will perform a variable bytewise shuffle." }
459 "USING: alien.c-types math.vectors math.vectors.simd prettyprint ;"
460 "int-4{ 69 42 911 13 } { 1 3 2 3 } vshuffle ."
461 "int-4{ 42 13 911 13 }"
464 "USING: alien.c-types combinators math.vectors math.vectors.simd"
465 "namespaces prettyprint prettyprint.config ;"
468 ": endian-swap ( size -- vector )"
470 " { 1 [ uchar-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 } ] }"
471 " { 2 [ uchar-16{ 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14 } ] }"
472 " { 4 [ uchar-16{ 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 } ] }"
475 "int-4{ 0x11223344 0x11223344 0x11223344 0x11223344 }"
476 "4 endian-swap vshuffle"
477 "16 number-base [ . ] with-variable"
478 "int-4{ 0x44332211 0x44332211 0x44332211 0x44332211 }"
483 { $values { "v" { $sequence number } } { "x" "a non-negative real number" } }
484 { $description "Computes the squared length of a mathematical vector." } ;
487 { $values { "k" sequence } { "x" "a non-negative real number" } }
488 { $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙₁ (" { $snippet "L^1" } ") vector space, usually written ∥・∥₁." }
491 "USING: math.vectors prettyprint ;"
492 "{ 1 2 3 4 } l1-norm ."
498 { $values { "k" sequence } { "x" "a non-negative real number" } }
499 { $contract "Implementation for the default " { $link norm } ", in 𝑙₂ (" { $snippet "L^2" } ") vector space, usually written ∥・∥₂." } ;
502 { $values { "k" sequence } { "x" "a non-negative real number" } }
503 { $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙₂ (" { $snippet "L^2" } ") vector space, usually written ∥・∥₂. " }
504 { $notes "This is generally the \"default norm\", and when referring to an unqualified norm, so it is an alias for the " { $link l2-norm } " implementation." }
507 "USING: math.vectors math.functions prettyprint ;"
508 "{ 1 2 3 4 } norm 5.4772255 10e-8 ~ ."
513 HELP: l-infinity-norm
514 { $values { "k" sequence } { "x" "a non-negative real number" } }
515 { $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙∞ (" { $snippet "L^∞" } ") vector space, usually written ∥・∥∞. For a mathematical vector, this is simply its " { $link maximum } "." }
518 "USING: math.vectors prettyprint ;"
519 "{ 1 2 3 4 } l-infinity-norm ."
525 { $values { "k" { $sequence number } } { "p" "a positive real number" } { "x" "a non-negative real number" } }
526 { $contract "Computes the norm (size) of " { $snippet "k" } " in 𝑙ₚ (" { $snippet "L^p" } ") vector space, usually written ∥・∥ₚ." } ;
528 { norm-sq l1-norm l2-norm norm l-infinity-norm p-norm } related-words
531 { $values { "v" { $sequence "at least 1 non-zero number" } } { "w" { $sequence number } } }
532 { $description "Outputs a vector with the same direction as " { $snippet "v" } ", but length 1." } ;
535 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "x" "a non-negative real number" } }
536 { $description "Outputs the Euclidean distance between two vectors." } ;
539 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "axis" "a sequence of 0/1" } { "w" { $sequence number } } }
540 { $description "Using " { $snippet "w" } " as a template, creates a new sequence containing corresponding elements from " { $snippet "u" } " in place of 0, and corresponding elements from " { $snippet "v" } " in place of 1." }
541 { $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 3 } { 4 5 6 } { 0 1 0 } set-axis ." "{ 1 5 3 }" } } ;
544 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence boolean } } }
545 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is less than the latter or " { $link f } " otherwise." }
546 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
549 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence boolean } } }
550 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is less than or equal to the latter or " { $link f } " otherwise." }
551 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
554 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence boolean } } }
555 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when they are equal or " { $link f } " otherwise." }
556 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
559 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence boolean } } }
560 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is greater than the latter or " { $link f } " otherwise." }
561 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
564 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence boolean } } }
565 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when the former is greater than or equal to the latter or " { $link f } " otherwise." }
566 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
569 { $values { "u" { $sequence number } } { "v" { $sequence number } } { "w" { $sequence boolean } } }
570 { $description "Compares each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", returning " { $link t } " in the result vector when either value is Not-a-Number or " { $link f } " otherwise." }
571 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean results when using SIMD types." } ;
574 { $values { "u" { $sequence boolean } } { "v" { $sequence boolean } } { "w" { $sequence boolean } } }
575 { $description "Takes the logical AND of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } "." }
576 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
579 { $values { "u" { $sequence boolean } } { "v" { $sequence boolean } } { "w" { $sequence boolean } } }
580 { $description "Takes the logical AND-NOT of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } ", where " { $snippet "x AND-NOT y" } " is defined as " { $snippet "NOT(x) AND y" } "." }
581 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
584 { $values { "u" { $sequence boolean } } { "v" { $sequence boolean } } { "w" { $sequence boolean } } }
585 { $description "Takes the logical OR of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } "." }
586 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
589 { $values { "u" { $sequence boolean } } { "v" { $sequence boolean } } { "w" { $sequence boolean } } }
590 { $description "Takes the logical XOR of each corresponding element of " { $snippet "u" } " and " { $snippet "v" } "." }
591 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
594 { $values { "v" { $sequence boolean } } { "w" { $sequence boolean } } }
595 { $description "Takes the logical NOT of each element of " { $snippet "v" } "." }
596 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
599 { $values { "mask" { $sequence boolean } } { "true" { $sequence number } } { "false" { $sequence number } } { "result" { $sequence number } } }
600 { $description "Creates a new sequence by selecting elements from the " { $snippet "true" } " and " { $snippet "false" } " sequences based on whether the corresponding bits of the " { $snippet "mask" } " sequence are set or not." }
601 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types." } ;
604 { $values { "mask" { $sequence boolean } } { "true-quot" { $quotation ( -- vector ) } } { "false-quot" { $quotation ( -- vector ) } } { "result" sequence } }
605 { $description "If all of the elements of " { $snippet "mask" } " are true, " { $snippet "true-quot" } " is called and its output value returned. If all of the elements of " { $snippet "mask" } " are false, " { $snippet "false-quot" } " is called and its output value returned. Otherwise, both quotations are called and " { $snippet "mask" } " is used to select elements from each output as with " { $link v? } "." }
606 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs and results when using SIMD types."
608 "For most conditional SIMD code, unless a case is exceptionally expensive to compute, it is usually most efficient to just compute all cases and blend them with " { $link v? } " instead of using " { $snippet "vif" } "." } ;
610 { v? vif } related-words
613 { $values { "v" { $sequence boolean } } { "?" boolean } }
614 { $description "Returns true if any element of " { $snippet "v" } " is true." }
615 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
618 { $values { "v" { $sequence boolean } } { "?" boolean } }
619 { $description "Returns true if every element of " { $snippet "v" } " is true." }
620 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
623 { $values { "v" { $sequence boolean } } { "?" boolean } }
624 { $description "Returns true if every element of " { $snippet "v" } " is false." }
625 { $notes "See " { $link "math-vectors-simd-logic" } " for notes on dealing with vector boolean inputs when using SIMD types." } ;
627 { 2map v+ v- v* v/ } related-words
629 { 2reduce vdot } related-words
631 { vs+ vs- vs* } related-words
633 { v< v<= v= v> v>= vunordered? vand vor vxor vnot vany? vall? vnone? v? } related-words
635 { vbitand vbitandn vbitor vbitxor vbitnot } related-words