Defining a function with history

### 8.3.5 Defining a function with history

The as_function_of command creates a function defined by an expression, even if the desired variable already has a value.

- as_function_of takes two arguments:
  - x, a variable.
  - exprvar, another variable containing an expression which itself may involve x.
- as_function_of(exprvar,x) returns a function defined by the expression that exprvar contains.

#### Example

a:=sin(x)

sin | ⎛ ⎝ | x | ⎞ ⎠

b:=sqrt(1+a^2)

| √ |
1+sin2x

c:=as_function_of(b,a)

(a)->{ return(sqrt(1+a^2)); } |  |  |  |  |  |  |  |  |  |

c(x)

| √ |
1+x2

##### Remark.

If the variable b has been assigned several times, the first assignment of b following the last assignment of a will be used. Moreover, the order used is the order of validation of the commandlines, which may not be reflected by the Xcas interface if you reused previous commandlines.

#### Example

a:=2:; b:=2*a+1:; b:=3*a+2:; c:=as_function_of(b,a)

(a)->{ return(sqrt(1+a^2)); } |  |  |  |  |  |  |  |  |  |

So c(x) is equal to 2x+1. But:

a:=2:; b:=2*a+1:; a:=2:; b:=3*a+2:; c:=as_function_of(b,a)

(a)->{ return(sqrt(2+3*a^2)); } |  |  |  |  |  |  |  |  |  |

So c(x) is equal to 3x+2.

Hence the line where a is defined must be reevaluated before the good definition of b.