-
-
Notifications
You must be signed in to change notification settings - Fork 52
Expressions, Variables, and Reserved Words
YAFU is also an interactive math environment, similar in spirit to PARI/GP, MATLAB, or bc. You can write expressions, assign to variables, and use a small amount of control flow.
Use quit or exit to leave the application.
# 1) As a command-line argument
yafu "2+2"
yafu "siqs(rsa(200))"
# 2) Via stdin
echo "2+2" | yafu
yafu < in.txt
# 3) From a script or batchfile
yafu -script do_stuff.txt
yafu -batchfile numbers_to_factor.txtWhether you need quotes depends on your shell. All expression syntax that works in the interactive prompt also works in these invocations.
An expression is any (nested) series of functions and operators. Nesting is unlimited, as long as the total expression is < 2048 characters. Whitespace is removed before parsing. Use proper infix notation: -1(7*8) will not work, but -1*(7*8) will.
| Operator | Meaning |
|---|---|
+ - * / % ^
|
standard arithmetic |
! |
factorial (postfix) |
# |
primorial (postfix) |
<< >>
|
binary left / right shift |
( )
|
grouping |
YAFU supports input and output in different bases via the reserved words IBASE and OBASE. Hex and decimal work today; binary, octal, and arbitrary bases are planned.
- Set
IBASEand all subsequent input is interpreted in that base. - Set
OBASEand all output appears in that base. - Override per-number on input:
0x...for hex,0d...for decimal. - Hex letters must be ALL CAPS.
- Names: lowercase alphanumerics,
_, and`. Must start with[a-z]or_. - Cannot collide with reserved words.
These are global variables YAFU keeps track of. You can change them in interactive mode to influence subsequent operations. Most of them have command-line / yafu.ini equivalents listed in Configuration and Command-Line Options.
| Reserved word | Controls |
|---|---|
B1pm1 |
P-1 stage 1 bound |
B2pm1 |
P-1 stage 2 bound |
B1pp1 |
P+1 stage 1 bound |
B2pp1 |
P+1 stage 2 bound |
B1ecm |
ECM stage 1 bound |
B2ecm |
ECM stage 2 bound |
rhomax |
max iterations in Pollard rho |
nprp |
number of witnesses in Rabin–Miller PRP tests |
IBASE |
input numeric base |
OBASE |
output numeric base |
pfile |
non-zero → primes() writes to file |
pscreen |
non-zero → primes() writes to screen |
verbose |
verbosity level inside the interactive environment |
threads |
thread count for multi-threaded algorithms |
Some basic programming constructs are available: for loops and if/else. (See the source / docfile.txt for syntax details — they are mentioned only briefly.)
You can drive YAFU with a list of inputs using -batchfile <name>. Each line of the file can be any valid YAFU expression.
If you also provide an expression on the command line containing the special character @, each line of the batchfile is substituted into the expression in place of @. If @ is absent, the command-line expression is ignored and the file's lines are used directly.
Lines are removed from the batchfile as they complete, so the file acts as a work queue you can interrupt and resume.
# Factor each number in in.bat
yafu "factor(@)" -batchfile in.bat
# Treat each line of in.bat as a complete expression
./yafu "@" -batchfile in.bat
# equivalently:
./yafu -batchfile in.bat-
help— show the contents ofdocfile.txt. -
help <funcname>— detailed help for a single function.
The docfile needs to be in the same directory as the executable for in-program help to work.