Skip to main content

Restrictions and Conditionals

Desmos uses braces {} for domain and range restrictions as well as simple conditional expressions.

Restrictions​

Append a condition in braces to an expression. Restrictions also work with implicit equations and inequalities.

1
y=x{x<0}y=x\{x<0\}
2
x=1{y≥0}x=1\{y\geq0\}
3
x>0{x2+y2>4}x>0\{x^2+y^2>4\}
Loading graph…
Open in Desmos ↗

Multiple conditions​

Comma-separated conditions inside one pair of braces behave like “or.” Separate pairs of braces behave like “and.”

1
x2+y2=1{x>0,y>0}x^2+y^2=1\{x>0,y>0\}
2
x2+y2=4{x>0}{y>0}x^2+y^2=4\{x>0\}\{y>0\}
Loading graph…
Open in Desmos ↗

and or​

In the past, creating complex conditions required workarounds using min\mathrm{min} and max\mathrm{max}, but now you can use and\mathrm{and} and or\mathrm{or} directly.

1
x2+y2≤25{x>0and⁡y>0}x^{2}+y^{2}\le25\left\{x>0\operatorname{and}y>0\right\}
2
x2+y2≤25{x<0or⁡y<0}x^{2}+y^{2}\le25\left\{x<0\operatorname{or}y<0\right\}
Loading graph…
Open in Desmos ↗

Conditional expressions​

Use {condition 1: value 1, condition 2: value 2, …} to switch values according to conditions.

1
y={x<0:x+1,0≤x<1:1,1≤x:x}y=\{x<0:x+1,0\leq x<1:1,1\leq x:x\}
2
a=⋯a=\cdots
3
(x−1)2+(y+1)2={a<0:1,a>0:4}(x-1)^2+(y+1)^2=\{a<0:1,a>0:4\}
Loading graph…
Open in Desmos ↗

You can also nest {} like this:

1
y={x<0:{x<−1:−1,x≥−1:x},x≥0:x2}y=\left\{x<0:\left\{x<-1:-1,x\ge-1:x\right\},x\ge0:x^{2}\right\}

How braces work​

{condition 1: value 1, condition 2: value 2, …} works in this order:

  1. Evaluate the conditions from left to right and return the value for the first condition that is true.
  2. If the value for a condition is omitted, return 11.
  3. If no condition is true, do not graph or evaluate the entire expression containing the braces.

Therefore,

1
y=x{x<0}y=x\{x<0\}

graphs y=x⋅1y=x\cdot1 only when x<0x<0. Likewise,

1
y=x{x>0}{y>0}y=x\{x>0\}\{y>0\}

graphs y=x⋅1⋅1y=x\cdot1\cdot1 only when both x>0x>0 and y>0y>0.