Usage: Difference between revisions

From iMath
Jump to navigation Jump to search
 
(14 intermediate revisions by the same user not shown)
Line 3: Line 3:
The best way to learn how to use iMath is to look at the iMath-tour.odt document corresponding to your version of iMath in this  [http://sourceforge.net/projects/ooo-imath/files folder].
The best way to learn how to use iMath is to look at the iMath-tour.odt document corresponding to your version of iMath in this  [http://sourceforge.net/projects/ooo-imath/files folder].


== iMath Options ==
Usage with Impress is very similar to usage with Writer. The main difference is that Math objects in an Impress document cannot be anchored in any specific order. Therefore, the recalculation order of the iMath formulas inside each Impress page is defined by the object names. The object names can be set in the context menu (Properties) or in the Navigator. The user is responsible to name the Math objects in such a way that calculation will happen in the desired order.
 
== Some background on numerics ==
 
=== Number types ===
 
There are two very different modes of numeric calculation available in iMath. As long as you use only integers and rational numbers, iMath (or rather, the underlying CLN library) will calculate exact results. As soon as you introduce floating point numbers (just writing 2.0 instead of 2 is enough), iMath will switch to approximate calculations with a precision of 17 digits (this is the default of the underlying GiNaC library). Not only the precision, but also the size of floating point numbers is limited. You can have an exponent of maximum 32 bits length.
 
To see the difference, enter these two expression (turn on auto-formatting):
  2.0^{-10^3}
  2^{-10^3}
If you want to benchmark your CPU, you can increase the exponent of -10 ...


The behaviour of iMath can be changed by setting options. There are three ways of doing this
When you use VAL() or ITERATE() everything is converted to floats.
# Globally for all documents
# Specifically for one document
# Specifically for one formula line


=== Global Options ===
For further details, consult [http://www.ginac.de/tutorial/Numbers.html#Numbers GiNaC] and [http://www.ginac.de/CLN/cln.html#Ordinary-number-types CLN].


The global iMath options are accessed through the standard Office dialog Extras-Options. They appear under the section Writer.
=== Automatic evaluation of expressions ===


* Include files
GiNaC does some automatic simplifications whenever you create an expression. Here are some examples:
** Include init.imath: This should always be marked unless you know exactly what you are doing. It reads important definitions of built-in iMath functions
  1/15 + 3/8 -> 53/120
** Include units.imath: This file needs to be included if you intend working with units other than the standard SI units (Newton, Pascal, etc.)
  2^{-10^3} -> 1/1071508607186267320948...
** Include substitutions.imath: This file contains a small library of mainly trigonometric substitutions. See the iMath-tour document for a usage example
  a + a -> 2 a
** Include further files: Here you can specify your own files that might contain definitions which you want to have available in all your iMath documents
You can see these simplifications if you turn on auto-formatting. Only simplifications that are mathematically safe are performed. For details, consult the [http://www.ginac.de/tutorial/Automatic-evaluation.html#Automatic-evaluation GiNaC documentation].
* Formatting
** Units: Here you can specify a list of units separated by ';' which should be used for printing physical quantities. If no such list is specified, the SI base units are used. A useful list of units for mechanical engineering might be <code>{%mm; %N; %Nm; %Nosqmm}</code>. The order in which the units are specified is important! Simple units should be specified first, more complex ones later on. The reason is that the complex units usually imply the simpler ones, for example, <code>N</code> implies <code>mm</code> because <code>1 N</code> equals <code>1 kg m/s^2</code>.


=== Document-specific options ===
=== Some pitfalls ===


The document-specific options are accessed through document properties File-Properties-User defined properties. Note that because of a bug in Office, a new document does not show any user-defined properties until it has been saved and re-opened once.
The expression %e^(-710) creates a floating point overflow error (not underflow as might be expected). This is because CLN calculates it as 1 / %e^710.  


=== Formula-specific options
There is a difference between VAL(%e)^{-10^18} and VAL(%e^{-10^18}). In the first case, the exponent is converted to a float before doing the exponentiation, because the basis is already a float. In the second case, the exponent is an integer and stays integer - but only 32-bit integer exponents are allowed. So you get an error. You can write VAL(%e^{-10^18.0}) instead.


The formula-specific options can be accessed through the context menu (this is the preferred way) or by editing the formula text (see [[Reference#Options]] for details).
== iMath Options ==


=== Available options ===
The behaviour of iMath can be changed by setting options. There are three ways of doing this
# Globally for all documents from the Tools - Options - LibreOffice Writer - iMath global defaults dialog
# Specifically for one document from the [[Document settings|iMath - Settings]]
# Specifically for one formula line with the keyword [[OPTIONS]]

Latest revision as of 19:11, 15 November 2020

How to use iMath

The best way to learn how to use iMath is to look at the iMath-tour.odt document corresponding to your version of iMath in this folder.

Usage with Impress is very similar to usage with Writer. The main difference is that Math objects in an Impress document cannot be anchored in any specific order. Therefore, the recalculation order of the iMath formulas inside each Impress page is defined by the object names. The object names can be set in the context menu (Properties) or in the Navigator. The user is responsible to name the Math objects in such a way that calculation will happen in the desired order.

Some background on numerics

Number types

There are two very different modes of numeric calculation available in iMath. As long as you use only integers and rational numbers, iMath (or rather, the underlying CLN library) will calculate exact results. As soon as you introduce floating point numbers (just writing 2.0 instead of 2 is enough), iMath will switch to approximate calculations with a precision of 17 digits (this is the default of the underlying GiNaC library). Not only the precision, but also the size of floating point numbers is limited. You can have an exponent of maximum 32 bits length.

To see the difference, enter these two expression (turn on auto-formatting):

 2.0^{-10^3}
 2^{-10^3}

If you want to benchmark your CPU, you can increase the exponent of -10 ...

When you use VAL() or ITERATE() everything is converted to floats.

For further details, consult GiNaC and CLN.

Automatic evaluation of expressions

GiNaC does some automatic simplifications whenever you create an expression. Here are some examples:

 1/15 + 3/8 -> 53/120
 2^{-10^3} -> 1/1071508607186267320948...
 a + a -> 2 a

You can see these simplifications if you turn on auto-formatting. Only simplifications that are mathematically safe are performed. For details, consult the GiNaC documentation.

Some pitfalls

The expression %e^(-710) creates a floating point overflow error (not underflow as might be expected). This is because CLN calculates it as 1 / %e^710.

There is a difference between VAL(%e)^{-10^18} and VAL(%e^{-10^18}). In the first case, the exponent is converted to a float before doing the exponentiation, because the basis is already a float. In the second case, the exponent is an integer and stays integer - but only 32-bit integer exponents are allowed. So you get an error. You can write VAL(%e^{-10^18.0}) instead.

iMath Options

The behaviour of iMath can be changed by setting options. There are three ways of doing this

  1. Globally for all documents from the Tools - Options - LibreOffice Writer - iMath global defaults dialog
  2. Specifically for one document from the iMath - Settings
  3. Specifically for one formula line with the keyword OPTIONS