TLC and Python

https://learn.foundry.com/nuke/8.0/content/user_guide/expressions/converting_expressions.html

# to use a Nuke expression in Python code.
nuke.expression()# to use a Nuke expression in TCL.
expression
# to run TCL code in Python.
nuke.tcl()

# to run Python code in TCL
python

# (square brackets) to embed TCL in a Nuke expression (or a string knob)
[ ]

# to embed Python in a Nuke expression.
[python {…}]

Variables & Expressions

# This makes a decimal number a whole number ( 2.75 = 2 )
int(x)

# This makes negative numbers positive.
abs(x)

# Make s a value a string, good for text
str(x)

TLC

[value variable]

# Get the frame variables
frame first_frame last_frame

format.x format.y – xxx

# Get the horizontal and vertical number
width height

# Get the left and bottom bounding box location
bbox.x bbox.y

# Get the right and top bounding box location
bbox.r bbox.t

# Get the width and height bounding box location
bbox.w bbox.h

Strings

string = “One, Two, Three, Four”

Conditions

IF THEN

Python:

if expression:
     statement(s)
else:
     statement(s)

TLC:
A > B ? True : False
[if {A > B} {True} {False}]

FOR LOOPS

for x in range(0, 10):
     print x

string = ['one', Two, '3', 'four']
for x in string:
     print x

WHILE LOOPS

loops = 10
while (loops <= 10):
     loops = loops + 1

Expressions

http://www.nukepedia.com/written-tutorials/expressions-101

Gradient x / width     y / height     1 - (y / height)

Lines  sin(x)     sin(x) + 1     ( sin(x) + 1 ) / 2     ( sin(x / 4 ) + 1 ) / 2

Radial Gradient sqrt(x * x + y * y )      300 - sqrt(x * x + y * y )     (300 - sqrt( x * x + y * y ) ) / 300

Radial Rings sin(sqrt(x * x + y * y ))    sin(sqrt(x * x + y * y ) / 4)

Random

(random(123,frame*0.1)*0.5)+0.5 | (random(seed,frame*frequency)*amplitude)+valueOffset

https://www.cameroncarson.com/nuke-wave-expressions

RANDOM WAVE

random((frame+offset)/waveLength) * (maxVal-minVal) + minVal 

NOISE WAVE

(noise((frame+offset)/waveLength)+1)/2 * (maxVal-minVal) + minVal

SINE WAVE

(sin(2*pi*(frame+offset)/waveLength)+1)/2 * (maxVal-minVal) + minVal

TRIANGLE WAVE

(asin(sin(2*pi*(frame+offset)/waveLength))/pi+0.5) * (maxVal-minVal) + minVal

SQUARE WAVE

int(sin(2*pi*(frame+offset)/waveLength)+1) * (maxVal-minVal) + minVal

SAWTOOTH WAVE

((frame+offset) % waveLength)/waveLength * (maxVal-minVal) + minVal

SAWTOOTH (PARABOLIC) WAVE

sin((pi*(frame+offset)/(2*waveLength)) % (pi/2)) * (maxVal-minVal) + minVal

SAWTOOTH (PARABOLIC REVERSED) WAVE

cos((pi*(frame+offset)/(2*waveLength)) % (pi/2)) * (maxVal-minVal) + minVal

SAWTOOTH (EXPONENTIAL) WAVE

(exp(2*pi*((frame+offset) % waveLength)/waveLength)-1)/exp(2*pi) * (maxVal-minVal) + minVal

BOUNCE WAVE

abs(sin(pi*(frame + offset)/waveLength))* (maxVal-minVal) + minVal

BLIP

((frame+(offset+waveLength)) % (waveLength+blipLength)/(waveLength)) *(waveLength/blipLength) - (waveLength/blipLength) >= 0 ? maxVal : minVal

SINEBLIP

((int((frame+offset) % waveLength)) >= 0 ? ((int((frame+offset) % waveLength)) <= (0+(blipLength-1)) ? ((sin(pi*((frame+offset) % waveLength)/blipLength)/2+1/2) * (2*maxVal-2*minVal) + (2*minVal-maxVal)) : minVal) : minVal)

 

Bounding box

bbox.x bbox.y bbox.r bbox.t

Get the input width and height

.width .height

Get input first and last frame

.first_frame and .last_frame

Name of the node

.name

Will look for the original node

.root

Python

Get Script Name

os.path.basename(nuke.root().name()).split('_v')[0]

Get Version

os.path.basename(nuke.root().name()).split(getUserVersion)[1].split('.nk')[0]

Get File

inspect.getfile(inspect.currentframe())

Get Folder

os.path.dirname(inspect.getfile(inspect.currentframe()))

Rendering tips

Adding “/5″ to the end of you render frames will render every 5th frame i.e. 1-100/5

Mathematical Functions

FunctionPurposeOperator UsageRelated FunctionsDeepExpression Compatible
abs (x)Returns the absolute value of the floating-point number x.xSee also: fabs.
acos (x)Calculates the arc cosine of x; that is the value whose cosine is x.If x is less than -1 or greater than 1, acos returns nan (not a number).See also: cos, cosh, asin, atan.
asin (x)Calculates the arc sine of x; that is the value whose sine is x.If x is less than -1 or greater than1, asin returns nan (not a number).See also: sin, sinh, acos, atan.
atan (x)Calculates the arc tangent of x; that is the value whose tangent is x. The return value is between -PI/2 and PI/2.xSee also: tan, tanh, acos, asin, atan2.
atan2 (x, y)Calculates the arc tangent of the two variables x and y. This function is useful to calculate the angle between two vectors.x, ySee also: sin, cos, tan, asin, acos, atan, hypot.
ceil (x)Round x up to the nearest integer.xSee also: floor, trunc, rint.
clamp (x, min, max)Return x clamped to [min … max].x, min, maxSee also: min, max.
clamp (x)Return x clamped to [0.0 … 1.0].xSee also: min, max.
cos (x)Returns the cosine of x.x in radiansSee also: acos, sin, tan, cosh.
cosh (x)Returns the hyperbolic cosine of x, which is defined mathematically as (exp(x) + exp(-x)) / 2.xSee also: cos, acos, sinh, tanh.
curve (frame)Returns the y value of the animation curve at the given frame.optional: frame, defaults to current frame.See also: value, y.
degrees (x)Convert the angle x from radians into degrees.xSee also: radians.
exp (x)Returns the value of e (the base of natural logarithms) raised to the power of x.xSee also: log, log10.
exponent (x)Exponent of x.xSee also: mantissa, ldexp.
fBm (x, y, z, octaves, lacunarity, gain)Fractional Brownian Motion. This is the sum of octaves calls to noise(). For each of them the input point is multiplied by pow(lacunarity,i) and the result is multiplied by pow(gain,i). For normal use, lacunarity should be greater than 1 and gain should be less than 1.x, y, z, octaves, lacunarity, gainSee also: noise, random, turbulence.
fabs (x)Returns the absolute value of the floating-point number x.xSee also: abs.
false ()Always returns 0See also: true.
floor (x)Round x down to the nearest integer.xSee also: ceil, trunc, rint.
fmod (x, y)Computes the remainder of dividing x by y. The return value is x – n y, where n is the quotient of x / y, rounded towards zero to an integer.x, ySee also: ceil, floor.
frame ()Return the current frame number.See also: x.
from_byte (color component)Converts an sRGB pixel value to a linear value.color_componentSee also: to_sRGB, to_rec709f, from_rec709f.
from_rec709f (color component)Converts a rec709 byte value to a linear brightnesscolor_componentSee also: form_sRGB, to_rec709f.
from_sRGB (color component)Converts an sRGB pixel value to a linear value.color_componentSee also: to_sRGB, to_rec709f, from_rec709f.
hypot (x, y)Returns the sqrt(x*x + y*y). This is the length of the hypotenuse of a right-angle triangle with sides of length x and y.x, ySee also: atan2.
int (x)Round x to the nearest integer not larger in absolute value.xSee also: ceil, floor, trunc, rint.
ldexp (x)Returns the result of multiplying the floating-point number x by 2 raised to the power exp.x, expSee also: exponent.
lerp (a, b, x)Returns a point on the line f(x) where f(0)==a and f(1)==b. Matches the lerp function in other shading languages.a, b, xSee also: step, smoothstep.
log (x)Returns the natural logarithm of x.xSee also: log10, exp.
log10 (x)Returns the base-10 logarithm of x.xSee also: log, exp.
logb (x)Same as exponent().xSee also: mantissa, exponent.
mantissa (x)Returns the normalized fraction. If the argument x is not zero, the normalized fraction is x times a power of two, and is always in the range 1/2 (inclusive) to 1 (exclusive). If x is zero, then the normalized fraction is zero and exponent() Returns zero.xSee also: exponent.
max (x, y, … )Return the greatest of all values.x, y, (…)See also: min, clamp.
min (x, y, … )Return the smallest of all values.x, y, (…)See also: max, clamp.
mix (a, b, x)Same as lerp().a, b, xSee also: step, smoothstep, lerp.
noise (x, y, z)Creates a 3D Perlin noise value. This produces a signed range centerd on zero. The absolute maximum range is from -1.0 to 1.0. This produces zero at all integers, so you should rotate the coordinates somewhat (add a fraction of y and z to x, etc.) if you want to use this for random number generation.x, optional y, optional zSee also: random, fBm, turbulence.
pi ()Returns the value for pi (3.141592654…).
pow (x, y)Returns the value of x raised to the power of y.x, ySee also: log, exp, pow.
pow2 (x)Returns the value of x raised to the power of 2.x, ySee also: pow.
radians (x)Convert the angle x from degrees into radians.xSee also: degrees.
random (x, y, z)Creates a pseudo random value between 0 and 1. It always generates the same value for the same x, y and z. Calling random with no arguments creates a different value on every invocation.optional x, optional y, optional zSee also: noise, fBm, turbulence.
rint (x)Round x to the nearest integer.xSee also: ceil, floor, int, trunc.
sin (x)Returns the sine of x.x in radiansSee also: asin, cos, tan, sinh.
sinh (x)Returns the hyperbolic sine of x, which is defined mathematically as (exp(x) – exp(-x)) / 2.xSee also: sin, asin, cosh, tanh.
smoothstep (a, b, x)Returns 0 if x is less than a, returns 1 if x is greater or equal to b, returns a smooth cubic interpolation otherwise. Matches the smoothstep function in other shading languages.a, b, xSee also: step, lerp.
sqrt (x)Returns the non-negative square root of x.xSee also: pow, pow2.
step (a, x)Returns 0 if x is less than a, returns 1 otherwise. Matches the step function other shading languages.a, xSee also: smoothstep, lerp.
tan (x)Returns the tangent of x.x in radiansSee also: atan, cos, sin, tanh, atan2.
tanh (x)Returns the hyperbolic tangent of x, which is defined mathematically as sinh(x) / cosh(x).xSee also: tan, atan, sinh, cosh.
to_byte (color component)Converts a floating point pixel value to an 8-bit value that represents that number in sRGB space.color_componentSee also: form_sRGB, to_rec709f, from_rec709f.
to_rec709f (color component)Converts a floating point pixel value to an 8-bit value that represents that brightness in the rec709 standard when that standard is mapped to the 0-255 range.color_componentSee also: form_sRGB, from_rec709f.
to_sRGB (color component)Converts a floating point pixel value to an 8-bit value that represents that number in sRGB space.color_componentSee also: form_sRGB, to_rec709f, from_rec709f.
true ()Always Returns 1.See also: false
trunc (x)Round x to the nearest integer not larger in absolute value.xSee also: ceil, floor, int, rint.
turbulence (x, y, z, octaves, lucanarity, gain)This is the same as fBm() except the absolute value of the noise() function is used.x, y, z, octaves, lucanarity, gainSee also: fBm, noise, random.
value (frame)Evaluates the y value for an animation at the given frame.optional: frame, defaults to current frame.See also: y, curve.
x ()Return the current frame number.See also: frame.
y (frame)Evaluates the y value for an animation at the given frame.optional: frame, defaults to current frame.See also: value, curve.
[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

MOTOOLS

MOTools for Nuke – Are a collection for gizmos and script I have creates over the years. Feel free to copy, edit and change.

  • Script files with other authors will be in the header of the file. Please be curious and extend the authors info.
[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]
[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

AutoExtract

This will auto extract an EXR file into separate renders.

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

AutoCrop_BBox

Drops a crop node which auto crops to the bounding box

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

AutoSlate

Auto creates a slate with user inputs

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

AutoWrite

Create an Auto Write node with user inputs. Based on the _v### script saving.

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Cam_MayatoNuke_EXR

Creates a cameras using EXR from Maya

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Cam_VraytoNuke_EXR

Creates a cameras using EXR from Vray

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

ChromaticAberration_Fast

Creates Chromatic Aberration quick and dirty technique.

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

ChromaticAberration_Fast

Creates Chromatic Aberration quick and dirty technique.

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

ColorChecker

Based on * this is for testing colors

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Convert6by1toLatLog

Convert 6×1 to Lat/Log

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

ConvertLatLogto6by1

Convert Lat/Log to 6 x 1

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Dust_Motes

Random noise based dust

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Easy_Vignette

Simple vignette gizmo

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Help_How_Operations_Work

How Operations Work

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Help_How_Premult_Work

How Premult Work

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

NormalMaker

Fake normal maker

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

PointPosition

Uses World point position for a mask

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Rebuild_Arnold_Basic

Creates a basic rebuild beauty from Arnold render elements

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Rebuild_Vray_Basic

Creates a basic rebuild beauty from Vray render elements

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Rebuild_Vray_Raw

Creates a RAW rebuild beauty from Vray render elements

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

Repeater

Repeater for textures. Will tile same size or expand.

[siteorigin_widget class=”SiteOrigin_Widget_Image_Widget”][/siteorigin_widget]

SunFlare

Sun Flare

Maya (Arnold) to Nuke best EXR setting for time

Compression Types:
Run Length Encoding (RLE) : This is a basic form of compression that is comparable to that used by standard Targa files.
Zip (16 Scanline) : deflate compression applied to blocks of 16 scanlines at time. This tends to be the most effective style of compression to use with rendered images that do not have film grain applied.
Zips (1 Scanline) : deflate compression with zlib wrapper applied to individual scanlines (not based on the ZIP file format despite its name).

Tiled:
Not great for compositing packages such as Nuke or Fusion

AutoCrop :
If you have a lot of black space this might help cropping out un-used pixels.

Merge AOVs :
This create one EXR file instead multiple pre channel/pass

Arnold to Nuke EXR

Bit DepthCompressionGBTitledCropLoad SecMemWrite sec
32bitZip (16 scanline)1.7Tiledno3.231.6 GB59.2
32 bitZip (16 scanline)1.76Scanlineno1.061.6 GB56.5
32 bitZipS (1 Scanline)1.7Tiledno1.831.6 GB67.86
32 bitZipS (1 Scanline)1.76Scanlineno0.018.18 KB52.92
32 bitZipS (1 Scanline)1.76ScanlineYes0.078.18 KB52.92
32 bitnone14Scanlineno0.088.18 KB174.92
16 bitZip (16 scanline)0.51Tiledno0.781.6 GB51.26
16 bitZipS (1 Scanline)0.53Scanlineno0.058.18 KB43.1
16 bitZipS (1 Scanline)
0.53Scanlineyes0.058.18 KB42.95

Linear vs​ Non-Linear​

Simply, it means that numerical intensity values correspond proportionally to their perceived intensity. At a 50% gray will be in the middle of a gradient range.​​

This means that the colors can be added and multiplied correctly. A color space without that property is called ”Non-linear”​

Linear – Values arranged along a straight line.
Example: 1…2…3…4…5…6
Non-Linear – Values NOT arranged along a straight line.
Example: 1…2…5…8…9…10

Integer vs Floating Point

Simply, it means that numerical intensity values correspond proportionally to their perceived intensity. At a 50% gray will be in the middle of a gradient range.

This means that the colors can be added and multiplied correctly. A color space without that property is called ”Non-linear”

Integer – Whole number that are not fractioned
Example: 1 , 2 , 100 , 256

Floating Point – A number that is not an Integer.
Example: 0.1 , 0.58 , 1.44 , 2.0

Clamped vs Unclamped

Simply, it means that numerical intensity values correspond proportionally to their perceived intensity. At a 50% gray will be in the middle of a gradient range.

This means that the colors can be added and multiplied correctly. A color space without that property is called ”Non-linear”

Q: Wait does this mean I can have a color that is more that 1?

A: Yes, a lot of times, highlights for example, are way over 1 in color. Because ALL the colors are not clamped to 0-1 you can use exposures to alter you image without degrading it.

Example :  Direct sunlight might have a color value of 2-10 while the viewing the sun might have a value of 10-100.

Q: So can I have negitive numbers, ones that are lower than -1?

A: Because Linear colors are based on math yes you can. Much like the first answer this mean you can use exposure to darken your image with out degrading it.

Example: The render might be too dark. but with linear workflows there might be a good chance to bring those blacks up into view-able ranges.

What is a ​“Channel”

In order to create color we need three primary colors RGB. Each of these need a channels to store information. Basic RGB images have 3 channels, some times they have a alpha which increases the channel count to 4. Most image formats only have a 4 channel max.

*Photoshop file allows more than 4 channels. R, G, B, A , Masks+

8 Bit Gray | 1 Channel

Gray – 8 Bits



256 Colors
8 Bit CMYK | 4 Channel

Cyan – 8 Bits
Magenta – 8 Bits
Yellow – 8 Bits
Black – 8 Bits

4.3 Billion Colors
8 Bit RGB | 3 Channel

Red – 8 Bits
Green – 8 Bits
Blue – 8 Bits

16.7 Million Colors
16 Bit RGB | 4 Channel

Red – 16 Bits
Green – 16 Bits
Blue – 16 Bits
Alpha – 16 Bits


281 Trillion Colors
8 Bit RGBA | 4 Channel

Red – 8 Bits
Green – 8 Bits
Blue – 8 Bits
Alpha – 8 Bits
16.7 Million Colors + 256 Alpha
32 Bit RGB | 4 Channel

Red – 32 Bits
Green – 32 Bits
Blue – 32 Bits
Alpha – 32 Bits


80 Octillion Colors

What is a ​“Layer”

Layers are collections of channels. Most common collection is RGBA.

Color is made from a single RGB channels

Everything is​ A over B

Node based compositing works on simple A over B​

Each channel is composited instead of overall color

Using math to blend colors together​

Each channel​ is composited together using a alpha value.

Compositing is should ALWAYS done in linear space

Look-Up Table (LUT) is mathematically precise way of taking specific linear image and modifying them to new RGB values to be seen on a different imaging system.

Because compositing is base on math if you were to composite with say sRGB, the math wont work out correctly. This is why LUTs are (sRGB, Rec079, Instagram filters, The matrix green coloring) used at the end for viewing only.

Here is what/how i’ve found to install Nuke on a windows machine

  • Requires Admin : setx NUKE_PATH *Your nuke Plugin Folder* /m
  • Requires Admin : setx foundry_LICENSE “4101@LICENSESERVER” /m

Installing from the Command Line

https://learn.foundry.com/nuke/content/getting_started/installation/installing_nuke_win.html

 

Farm Rendering Error Codes:
0 – Success
1 – Error (no further detail, but typically happens with invalid/inconsistent parameters passed into Nuke) Check Log
100 – Licence error – Cant find the License server, this could be a network issue.

 

Farm Install Error Codes:
Failure: Command exited with code: 1
Command Stderr: ERROR: Access to the registry path is denied.
(System.Exception)
Solution: Command must be ran as a Admin

 

Use this if you are manually loading in a color correction from 3dsmax.

  1. Load the LUT
    1. NUKE: Load using the Vectorfield Gizmo
  1. Non LUT’s
    1. You can recreate the 3dsmax&VRay style with custom gizmos like :
    1. LINK : https://forums.chaosgroup.com/forum/v-ray-for-3ds-max-forums/v-ray-for-3ds-max-tutorials-tips-tricks/62729-tone-mapping-in-nuke
    2. Or use a expression Node
Expressions, Change the BurnAmount to a number between 0-1
r*(1+r*(BurnAmount**2))/(1+r)
g*(1+g*(BurnAmount**2))/(1+g)
b*(1+b*(BurnAmount**2))/(1+b)

If you’ve never had the …pleasure… of rendering out massive amount of mattes this may not wow you.

Cryptomatte is a tool created at Psyop by Jonah Friedman and Andy Jones. It creates ID mattes automatically with support for motion blur, transparency, and depth of field, using organizational information already available at render time. This organizational information is usually names, object namespaces, and material names.

https://github.com/Psyop/Cryptomatte

set cut_paste_input [stack 0]
version 5.2300
Group {
inputs 0
name Grad
selected true
xpos -4063
ypos -2354
addUserKnob {20 User}
addUserKnob {41 format T Constant2.format}
addUserKnob {41 LLColor T Expression2.LLColor}
addUserKnob {41 LRColor T Expression2.LRColor}
addUserKnob {41 URColor T Expression2.URColor}
addUserKnob {41 ULColor T Expression2.ULColor}
}
Constant {
inputs 0
channels rgb
name Constant2
xpos -469
ypos -253
}
Expression {
temp_name0 LLCorner
temp_expr0 (1-x/width)*(1-y/height)
temp_name1 LRCorner
temp_expr1 (x/width)*(1-y/height)
temp_name2 URCorner
temp_expr2 (x/width)*(y/height)
temp_name3 ULCorner
temp_expr3 (1-x/width)*(y/height)
expr0 LLColor.r*LLCorner+LRColor.r*LRCorner+URColor.r*URCorner+ULColor.r*ULCorner
expr1 LLColor.g*LLCorner+LRColor.g*LRCorner+URColor.g*URCorner+ULColor.g*ULCorner
expr2 LLColor.b*LLCorner+LRColor.b*LRCorner+URColor.b*URCorner+ULColor.b*ULCorner
name Expression2
xpos -469
ypos -174
addUserKnob {20 User}
addUserKnob {18 LLColor}
LLColor {1 0 0}
addUserKnob {18 LRColor}
LRColor {0 1 0}
addUserKnob {18 URColor}
URColor {0 0 1}
addUserKnob {18 ULColor}
ULColor {0 0 0}
}
Output {
name Output1
xpos -469
ypos -74
}
end_group

Ivan Busquets via http://community.foundry.com/discuss/topic/97059

Adding Mathematical Functions to Expressions in Nuke

atop = AB+B(1-A)
average = (A+B)/2)
color-burn = Darken B towards A
color-dodge = brighten B towards A
conjoint-over = A+B(1-a/b), A if a>b
copy = A
difference = abs(A-B)
disjoint-over = A+B(1-a)/b, A+B if a+b<1
divide = A/B, 0 if A<0 and B<0
exclusion = A+B-2AB
from = B-A
geometric = 2AB/(A+B)
hard-light = multiply if A<0.5, screen if A>0.5
hypot = sqrt (A*A+B*B)
in = Ab
mask = Ba
matte = Aa+B(1-a)
max = max (A,B)
min = min (A,B)
minus = A-B
multiply = AB, A if A<0 and B<0
out = A(1-b)
over = A+B(1-a)
overlay = multiply if B<0.5, screen if B>0.5
plus = A+B
screen = A or B ≤1? A+B-AB: max(A,B)
soft-light = Image B gets lit up.
stencil = B(1-a)
under = A(1-b)+B
xor = A(1-b)+B(1-a)

http://help.thefoundry.co.uk/nuke/content/comp_environment/expressions/adding_math_functions.html