Merge branch 'master' of git://factorcode.org/git/factor
commit
e530198446
|
@ -7,6 +7,7 @@ IN: math.constants
|
||||||
: euler ( -- gamma ) 0.57721566490153286060 ; inline
|
: euler ( -- gamma ) 0.57721566490153286060 ; inline
|
||||||
: phi ( -- phi ) 1.61803398874989484820 ; inline
|
: phi ( -- phi ) 1.61803398874989484820 ; inline
|
||||||
: pi ( -- pi ) 3.14159265358979323846 ; inline
|
: pi ( -- pi ) 3.14159265358979323846 ; inline
|
||||||
|
: 2pi ( -- pi ) 2 pi * ; inline
|
||||||
: epsilon ( -- epsilon ) 2.2204460492503131e-16 ; inline
|
: epsilon ( -- epsilon ) 2.2204460492503131e-16 ; inline
|
||||||
: smallest-float ( -- x ) HEX: 1 bits>double ; foldable
|
: smallest-float ( -- x ) HEX: 1 bits>double ; foldable
|
||||||
: largest-float ( -- x ) HEX: 7fefffffffffffff bits>double ; foldable
|
: largest-float ( -- x ) HEX: 7fefffffffffffff bits>double ; foldable
|
||||||
|
|
|
@ -23,7 +23,7 @@ M: real sqrt
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
GENERIC# ^n 1 ( z w -- z^w )
|
GENERIC# ^n 1 ( z w -- z^w ) foldable
|
||||||
|
|
||||||
: (^n) ( z w -- z^w )
|
: (^n) ( z w -- z^w )
|
||||||
make-bits 1 [ [ dupd * ] when [ sq ] dip ] reduce nip ; inline
|
make-bits 1 [ [ dupd * ] when [ sq ] dip ] reduce nip ; inline
|
||||||
|
|
|
@ -8,6 +8,8 @@ IN: math.miller-rabin
|
||||||
|
|
||||||
: >odd ( n -- int ) dup even? [ 1 + ] when ; foldable
|
: >odd ( n -- int ) dup even? [ 1 + ] when ; foldable
|
||||||
|
|
||||||
|
: >even ( n -- int ) 0 clear-bit ; foldable
|
||||||
|
|
||||||
TUPLE: positive-even-expected n ;
|
TUPLE: positive-even-expected n ;
|
||||||
|
|
||||||
:: (miller-rabin) ( n trials -- ? )
|
:: (miller-rabin) ( n trials -- ? )
|
||||||
|
@ -97,6 +99,7 @@ PRIVATE>
|
||||||
} 1&& ;
|
} 1&& ;
|
||||||
|
|
||||||
: next-safe-prime ( n -- q )
|
: next-safe-prime ( n -- q )
|
||||||
|
1 - >even 2 /
|
||||||
next-safe-prime-candidate
|
next-safe-prime-candidate
|
||||||
dup >safe-prime-form
|
dup >safe-prime-form
|
||||||
dup miller-rabin
|
dup miller-rabin
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: alien.c-types kernel math namespaces sequences
|
USING: alien.c-types kernel math namespaces sequences
|
||||||
io.backend io.binary combinators system vocabs.loader
|
io.backend io.binary combinators system vocabs.loader
|
||||||
summary math.bitwise byte-vectors fry byte-arrays
|
summary math.bitwise byte-vectors fry byte-arrays
|
||||||
math.ranges ;
|
math.ranges math.constants math.functions ;
|
||||||
IN: random
|
IN: random
|
||||||
|
|
||||||
SYMBOL: system-random-generator
|
SYMBOL: system-random-generator
|
||||||
|
@ -69,6 +69,17 @@ PRIVATE>
|
||||||
: with-secure-random ( quot -- )
|
: with-secure-random ( quot -- )
|
||||||
secure-random-generator get swap with-random ; inline
|
secure-random-generator get swap with-random ; inline
|
||||||
|
|
||||||
|
: uniform-random-float ( min max -- n )
|
||||||
|
64 random-bits >float [ over - 2.0 -64 ^ * ] dip
|
||||||
|
* + ;
|
||||||
|
|
||||||
|
: normal-random-float ( mean sigma -- n )
|
||||||
|
0.0 1.0 uniform-random-float
|
||||||
|
0.0 1.0 uniform-random-float
|
||||||
|
[ 2 pi * * cos ]
|
||||||
|
[ 1.0 swap - log -2.0 * sqrt ]
|
||||||
|
bi* * * + ;
|
||||||
|
|
||||||
USE: vocabs.loader
|
USE: vocabs.loader
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: byte-arrays combinators images kernel locals math
|
USING: byte-arrays combinators images kernel locals math math.affine-transforms
|
||||||
math.functions math.polynomials math.vectors random sequences
|
math.functions math.polynomials math.vectors random sequences
|
||||||
sequences.product ;
|
sequences.product ;
|
||||||
IN: perlin-noise
|
IN: perlin-noise
|
||||||
|
@ -70,14 +70,14 @@ IN: perlin-noise
|
||||||
[ faded second lerp ] 2bi@
|
[ faded second lerp ] 2bi@
|
||||||
faded third lerp ;
|
faded third lerp ;
|
||||||
|
|
||||||
: noise-map ( table scale dim -- map )
|
: noise-map ( table transform dim -- map )
|
||||||
[ iota ] map [ v* 0.0 suffix noise ] with with product-map ;
|
[ iota ] map [ a.v 0.0 suffix noise ] with with product-map ;
|
||||||
|
|
||||||
: normalize ( sequence -- sequence' )
|
: normalize-0-1 ( sequence -- sequence' )
|
||||||
[ supremum ] [ infimum [ - ] keep ] [ ] tri
|
[ supremum ] [ infimum [ - ] keep ] [ ] tri
|
||||||
[ swap - ] with map [ swap / ] with map ;
|
[ swap - ] with map [ swap / ] with map ;
|
||||||
|
|
||||||
: noise-image ( table scale dim -- image )
|
: noise-image ( table transform dim -- image )
|
||||||
[ noise-map normalize [ 255.0 * >fixnum ] B{ } map-as ]
|
[ noise-map normalize-0-1 [ 255.0 * >fixnum ] B{ } map-as ]
|
||||||
[ swap [ L f ] dip image boa ] bi ;
|
[ swap [ L f ] dip image boa ] bi ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue