aboutsummaryrefslogtreecommitdiff
path: root/src/hyper/pages/function.ht
blob: b0da8ec28830c2ee08fc4b2a0a65c03446d37858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
% Copyright The Numerical Algorithms Group Limited 1991.
% Certain derivative-work portions Copyright (C) 1988 by Leslie Lamport.
% All rights reserved.

\begin{page}{FunctionPage}{Functions in \Language{}}
%
In \Language{}, a function is an expression in one or more variables.
(Think of it as a function of those variables).
You can also define a function by rules or use a built-in function
\Language{} lets you convert expressions to compiled functions.
\beginscroll
\beginmenu
\menulink{Rational Functions}{RationatFunctionPage} \tab{22}
Quotients of polynomials.

\menulink{Algebraic Functions}{AlgebraicFunctionPage} \tab{22}
Those defined by polynomial equations.

\menulink{Elementary Functions}{ElementaryFunctionPage} \tab{22}
The elementary functions of calculus.

\menulink{Simplification}{FunctionSimplificationPage} \tab{22}
How to simplify expressions.

\menulink{Pattern Matching}{ugUserRulesPage} \tab{22}
How to use the pattern matcher.
\endmenu
\endscroll
\newline
Additional Topics:
\beginmenu

\menulink{Operator Algebra}{OperatorXmpPage}\tab{22}
The operator algebra facility.

\endmenu
\autobuttons \end{page}

\begin{page}{RationatFunctionPage}{Rational Functions}
\beginscroll
To create a rational function, just compute the
quotient of two polynomials:
\spadpaste{f := (x - y) / (x + y)\bound{f}}
Use the functions \spadfun{numer} and \spadfun{denom}:
to recover the numerator and denominator of a fraction:
%
\spadpaste{numer f\free{f}}
\spadpaste{denom f\free{f}}
%
Since these are polynomials, you can apply all the
\downlink{polynomial operations}{PolynomialPage}
to them.
You can substitute values or
other rational functions for the variables using
the function \spadfun{eval}. The syntax for \spadfun{eval} is
similar to the one for polynomials:
\spadpaste{eval(f, x = 1/x)\free{f}}
\spadpaste{eval(f, [x = y, y = x])\free{f}}
\endscroll
\autobuttons
\end{page}

\begin{page}{AlgebraicFunctionPage}{Algebraic Functions}
\beginscroll
Algebraic functions are functions defined by algebraic equations. There
are two ways of constructing them: using rational powers, or implicitly.
For rational powers, use \spadopFrom{**}{RadicalCategory}
(or the system functions \spadfun{sqrt} and
\spadfun{nthRoot} for square and nth roots):
\spadpaste{f := sqrt(1 + x ** (1/3))\bound{f}}
To define an algebraic function implicitly
use \spadfun{rootOf}. The following
line defines a function \spad{y} of \spad{x} satisfying the equation
\spad{y**3 = x*y - y**2 - x**3 + 1}:
\spadpaste{y := rootOf(y**3 + y**2 - x*y + x**3 - 1, y)\bound{y}}
You can manipulate, differentiate or integrate an implicitly defined
algebraic function like any other \Language{} function:
\spadpaste{differentiate(y, x)\free{y}}
Higher powers of algebraic functions are automatically reduced during
calculations:
\spadpaste{(y + 1) ** 3\free{y}}
But denominators, are not automatically rationalized:
\spadpaste{g := inv f\bound{g}\free{y}}
Use \spadfun{ratDenom} to remove the algebraic quantities from the denominator:
\spadpaste{ratDenom g\free{g}}
\endscroll
\autobuttons \end{page}

\begin{page}{ElementaryFunctionPage}{Elementary Functions}
\beginscroll
\Language{} has most of the usual functions from calculus built-in:
\spadpaste{f := x * log y * sin(1/(x+y))\bound{f}}
You can substitute values or another elementary functions for the variables
with the function \spadfun{eval}:
\spadpaste{eval(f, [x = y, y = x])\free{f}}
As you can see, the substitutions are made 'in parallel' as in the case
of polynomials. It's also possible to substitute expressions for kernels
instead of variables:
\spadpaste{eval(f, log y = acosh(x + sqrt y))\free{f}}
\endscroll
\autobuttons \end{page}

\begin{page}{FunctionSimplificationPage}{Simplification}
\beginscroll
Simplifying an expression often means different things at
different times, so \Language{} offers a large number of
`simplification' functions.
The most common one, which performs the usual trigonometric
simplifications is \spadfun{simplify}:
\spadpaste{f := cos(x)/sec(x) * log(sin(x)**2/(cos(x)**2+sin(x)**2)) \bound{f}}
\spadpaste{g := simplify f\bound{g}\free{f}}
If the result of \spadfun{simplify} is not satisfactory, specific
transformations are available.
For example, to rewrite \spad{g} in terms of secants and
cosecants instead of sines and cosines, issue:
%
\spadpaste{h := sin2csc cos2sec g\bound{h}\free{g}}
%
To apply the logarithm simplification rules to \spad{h}, issue:
\spadpaste{expandLog h\free{h}}
Since the square root of \spad{x**2} is the absolute value of
\spad{x} and not \spad{x} itself, algebraic radicals are not
automatically simplified, but you can specifically request it by
calling \spadfun{rootSimp}:
%
\spadpaste{f1 := sqrt((x+1)**3)\bound{f1}}
\spadpaste{rootSimp f1\free{f1}}
%
There are other transformations which are sometimes useful.
Use the functions \spadfun{complexElementary} and \spadfun{trigs}
to go back and forth between the complex exponential and
trigonometric forms of an elementary function:
%
\spadpaste{g1 := sin(x + cos x)\bound{g1}}
\spadpaste{g2 := complexElementary g1\bound{g2}\free{g1}}
\spadpaste{trigs g2\free{g2}}
%
Similarly, the functions \spadfun{realElementary} and
\spadfun{htrigs} convert hyperbolic functions in and out of their
exponential form:
%
\spadpaste{h1 := sinh(x + cosh x)\bound{h1}}
\spadpaste{h2 := realElementary h1\bound{h2}\free{h1}}
\spadpaste{htrigs h2\free{h2}}
%
\Language{} has other transformations, most of which
are in the packages
\spadtype{ElementaryFunctionStructurePackage},
\spadtype{TrigonometricManipulations},
\spadtype{AlgebraicManipulations},
and \spadtype{TranscendentalManipulations}.
If you need to apply a simplification rule not built into the
system, you can use \Language{}'s \downlink{pattern
matcher}{ugUserRulesPage}.
\endscroll
\autobuttons
\end{page}