Function Repository Resource:

LinearFunctionQ

Source Notebook

Determine whether an expression represents a linear function of a given set of variables

Contributed by: Paco Jain (Wolfram Research)

ResourceFunction["LinearFunctionQ"][expr,var]

returns True if expr is a linear function of the symbol var, and returns False otherwise.

ResourceFunction["LinearFunctionQ"][expr,{var1,var2, }]

returns True if expr is a linear function of each of the symbols vari, considered together, and returns False otherwise.

Details and Options

If expr is of the form Equal[lhs,rhs], ResourceFunction["LinearFunctionQ"][expr,] is equivalent to ResourceFunction["LinearFunctionQ"][lhs-rhs,]

Examples

Basic Examples (2) 

Test whether an expression represents a linear function of a given variable:

In[1]:=
ResourceFunction["LinearFunctionQ"][a x + b, x]
Out[1]=
In[2]:=
ResourceFunction["LinearFunctionQ"][4 x - Pi, x]
Out[2]=

Test for linearity with respect to a list of variables:

In[3]:=
ResourceFunction["LinearFunctionQ"][(x + 1) Log[y], {x}]
Out[3]=
In[4]:=
ResourceFunction["LinearFunctionQ"][(x + 1) Log[y], {x, y}]
Out[4]=
In[5]:=
ResourceFunction["LinearFunctionQ"][(x + 2 y), {x, y}]
Out[5]=

Scope (1) 

Variables listed in the second argument are considered together in the test for linearity:

In[6]:=
ResourceFunction["LinearFunctionQ"][x y, {x, y} ]
Out[6]=

Possible Issues (1) 

Expressions that are constant with respect to a variable are not considered linear:

In[7]:=
ResourceFunction["LinearFunctionQ"][4 , y]
Out[7]=
In[8]:=
ResourceFunction["LinearFunctionQ"][a Log[x], {y}]
Out[8]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 08 March 2019

Related Resources

License Information