# numericValue vs simpleFunction

**URL:** https://cl.desmos.com/t/numericvalue-vs-simplefunction/5528
**Category:** Articles
**Tags:** computation
**Created:** [April 3, 2024, 11:06pm UTC](https://cl.desmos.com/t/numericvalue-vs-simplefunction/5528 "2024-04-03T23:06:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JayChow](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/jaychow/32/1674_2.png) [@JayChow](https://cl.desmos.com/u/JayChow)
#### Post date: [April 3, 2024, 11:06pm UTC](https://cl.desmos.com/t/numericvalue-vs-simplefunction/5528/1 "2024-04-03T23:06:40Z")

</div>

Computing values in CL requires a bit more than entering simple arithmetic (e.g. `1+1` won’t get you anywhere). For computations in CL, we primarily use `numericValue` and `simpleFunction`. Here’s what each does:

- `numericValue` takes a string and computes it’s numeric value
- `simpleFunction` creates a function using any number of variables that can be evaluated at different values

## When do I use `numericValue` vs `simpleFunction`?

The difference in use between the two functions boils down to a few simple points. Here’s when to use each:

### `numericValue`

- The computation only needs to be done once.
- You either know exactly what numbers are being computed, or if inputs are variables, you know all of the possible inputs.

### `simpleFunction`

- The computation is repeated several times.
- The inputs are highly variable.

For simple or non repeated calculations, `numericValue` is much simpler to write:

```auto
numericValue(`1+2`)
simpleFunction(`x+y`,`x`,`y`).evaluateAt(1,2)

```

The more you repeat the calculation, especially with lengthly computations, `simpleFunction` becomes more and more useful:

```auto
fn = simpleFunction(`x^{2}+6x+9`,`x`)
evaluate1= fn.evaluatAt(1)
evaluate2= fn.evaluatAt(10)
evaluate3= fn.evaluatAt(100)
evaluate4= fn.evaluatAt(1000)
evaluate5= fn.evaluatAt(10000)

```

Additionally, numericValue can break mysteriously when given really big or really small numbers:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/6/6c5fdbb5a5761472869191c6a415050931573e26.png)

## One more thing…

If you want to take it one step further, check out `evaluationFrame`! This function allows you to make changes or combine parts of a calculation in a different way without rewriting the whole thing.

### Step 1: Add your functions

```auto
frame = evaluationFrame()
  .define(`f`,simpleFunction(`x+1`,`x`))
  .define(`g`,simpleFunction(`2x`,`x`))
  .define(`h`,simpleFunction(`x^{2}`,`x`))

```

### Step 2: evaluate your functions

| Code | Function | Output |
| --- | --- | --- |
| `.evaluate(`f(g(h(3)`)` | 2(3)^{2}+1 | 19 |
| `.evaluate(`g(h(f(3)`)` | 2(3+1)^{2} | 32 |
| `.evaluate(`h(g(f(3)`)` | (2(3+1))^{2} | 64 |
| `.evaluate(`f(h(g(3)`)` | (2\cdot3)^{2}+1 | 37 |
