# Can you encode if-then-else in arithmetic

Is there a general way to encode if-then-else/ITE in arithmetic, i.e. using the usual mathematical operators?

Example: let $f(x) = x^2$ if $x < 10^{30}$ and $log x$ otherwise, shortly written as $f(x) = ITE(x<10^{30},x^2,log x)$.

-

1
what are "the usual mathematical operators"? That's probably different from "in arithmetic". – Alon Amit Jan 4 '11 at 20:40

## 2 Answers

If you allow the use of indicator or characteristic functions, then the answer is yes. For your example, if you let $A = \{x \in \mathbb{R}| x < 10^{30}\}$, then $f(x) = x^2 \cdot \chi_{A}(x) + \log x \cdot \chi_{A^{C}}(x)$ where $\chi_A$ and $\chi_A^{C}$ are the characteristic functions of $A$ and $A$ complement, respectively.

-

1
And you can use the $\text{sgn}$ function for the indicator, in case of sets like $x \lt 10^{30}$. – Aryabhata Jan 4 '11 at 20:55

This seems related to: Representing IF ... THEN ... ELSE ... in math notation Although, since none of the answers there do a particularly good job at answering the question posted here, I'll just add a little bit more:

On top of what Jason wrote, you may also write:

• Let $f:\mathbb{R} \rightarrow \mathbb{R}$ be the function defined by $f(x)=x^2$ for $x<10^{30}$ and $f(x)=\log x$ otherwise.

• $f(x) = \begin{cases} x^2 & \text{if } x<10^{30} \\ \log x & \text{otherwise.} \end{cases}$

These have the advantage that you don't need to introduce an auxiliary function (such as a characteristic function).

The latter is typeset in LaTeX using:

`$f(x) = \begin{cases} x^2 & \text{if } x<10^{30} \\ \log x & \text{otherwise.} \end{cases}$`

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 17, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9065113663673401, "perplexity_flag": "middle"}