Unlike other operators, the boolean operators can return only a zero or a one. Despite this, they can be very useful. You have already seen an example in Figure 12-3 showing how a boolean operator made a variable upper limit of summation possible. Chapter 12, “Operators,” shows how a boolean operator makes it possible to determine the array index of a particular element.

The following table lists the boolean operators and their meaning with numbers

Boolean operators

The four operators>, and ~ can not take complex numbers because the concepts of greater than and less than lose their meaning in the complex plane.

Using boolean operators

As shown in Figure 12-12, the boolean operators can also be used to compare string expressions .

Comparing strings using boolean operators.

Mathcad compares two strings character by character by determining the ASCII codes of the component characters. For example, the string “Euler” precedes the string “Mach” in ASCII order and so the expression (“Euler” <“Mach”) evaluates to 1. See the table of ASCII codes in Appendix A, “Reference.” to determine the character ordering Mathcad uses in comparing strings. Using a boolean operator to compare a string to a number produces a type mismatch error.

Customizing operators

You can think of operators and functions as really being the same thing. A function takes “arguments” and returns a result. An operator, likewise, takes “operands” and returns a result. The differences are merely cosmetic:

• Functions have names you can spell, like tan or spline; operators are generally symbols like “+” or “x”.

• Arguments to a function are enclosed by parentheses, they come after the function’s name, and they’re separated by commas. Operands on the other hand, can appear elsewhere. For example, you’ll often see {(x, y) but you’ll rarely see x f y . Similarly, you’ll often find “x + y” but you’ll rarely find “+(x, y)”.

Since operators and functions are fundamentally the same, and since you can define tour own functions, there’s no reason why you can’t define your own customized operators as well. With Mathcad Professional, you’ll be able to do just that.

The first section describes how to define a new operator. This is followed by a section on how to use the operator you’ve just defined. The last section brings together these ideas by showing how functions can themselves be displayed as if they were operators.

Defining a custom operator

You define an operator just as if you were defining a function. You’d type the operator name followed by a pair of parentheses. The operands (two at the most) would go between the parentheses. On the other side of the : = you’d type an expression describing what you want the operator to do with its operands. These steps are described in detail in the section “Defining variables and functions” in

Since operators tend to have names that aren’t found on a keyboard, a problem arises when you try and type the name. For example, suppose you want to define a new division operator using” +”. You first have to know how to put a “+” into your worksheet. The simplest way to do this is to drag the symbol from the “Math Symbols” QuickSheet.

We recommend that you save your custom operators by dragging them into a Quick- Sheet. Open the QuickSheets from the Resource Center as described in Chapter 2, “On-)line Resources.” Then click on “Personal QuickSheets” from the topics in the table of contents. Click on “My Operators.” Then drag the definitions into the this QuickSheet.

The next time you need them, you’ll be able to drag them off the same QuickSheet rather than having to redefine them.

At this point, you’ve defined a function which behaves in every way like the user defined functions described in Chapter 7, “Equations and Computation.” You could, if you wanted to, type” .;-( 1, 2) = ” in your worksheet and see the result “OS’ on the other side of the equal sign.

The difference between functions and operators lies not so much in the w,ay they’re defined but in the way they’re displayed. This is discussed further in the next section.

Using a custom operator

Once you’ve defined a new operator, you can use it in your calculations just as you would use one of Mathcad’s built-in operators. You can’t, however, just type the name of your operator since Mathcad has no way of knowing whether you intend to use your new operator or whether you just want to define a variable having the same name.

The procedure for inserting a custom operator depends on whether the operator has one operand (like “-1” or “5′” for example) or two (like “1.;-2”). In either case, you’ll need to click on the button for the Evaluation and Boolean Palette on the Math Palette. This opens a palette that you’ll need in the following procedures.

Another way to display an operator having two operands is to use the other button showing the letters “x”, “f” and “s” arranged like a water molecule. If you follow the preceding steps using this operator, you’ll see the tree shaped display shown in the lower-left corner of Figure 12-13.

To insert an operator having only one operand, decide first whether you want the . operator to appear before the operand, as in” -1 “, or after the operand as in “5 !”. The .A former is called a prefix operator; the latter is a postfix operator. The example below shows how to use a prefix operator. The steps for creating a postfix operator are almost identical.

In the following example, the symbol “-,” comes from the Symbol font. Before you can reproduce the steps in this example, you’ll first have to define an operator “-,(x)”. To do so, follow the steps for defining +(x, y) in the previous section, substituting the symbol “-,” for “+” and using only one argument instead of two.

Be careful when you use operators this way. Since the placeholders look identical, there are no visual cues to tell you where the operands go and where the operator goes.

The most convenient way to use operators like this is create them once and then save them in a QuickSheet. To do this, open the QuickSheets from the Resource Center (choose Resource Center on the Help menu). Then click on “Math Symbols” to see a selection of common math symbols. You can drag any of these to your worksheet to help you define a new operator. Once you’ve defined the new operator, click on “Personal QuickSheets” and drag its definition into the QuickSheet. When you need to use this operator again, just open your Personal QuickSheet and drag it back off.

Display of functions as operators

As noted earlier, there is really no fundamental difference between functions and operators. The steps given in the section “Defining a custom operator” on page 252 exactly parallel the steps given on page 133 for defining a function.

Since you define an operator just as if it were a function, you might expect to be able to display that operator as if it were a function as well. Figure 12-14 shows that this is indeed true. Although notation like “+(1, 2)” is unconventional, nothing stops you from using it if you prefer it.

Conversely, you can display a function as if it were an operator. For example, many publishers prefer to omit parentheses around the arguments to certain functions (sin x rather than sin (x) ). You can do the same thing by treating the sin function as an operator with one operand and following the steps in the section “Using a custom operator.” The lower half of Figure 12-14 shows an example of this.

Displaying an operator as afunction and afunction as an operator.