{ "cells": [ { "cell_type": "markdown", "id": "56c86acf-abf5-4d6d-b17c-ba9ea0b0e593", "metadata": {}, "source": [ "# Standard behaviours\n", "\n", "`forallpeople` has chosen a \"convention over configuration\" approach. While units environments are intended to be customizable for each individual person's preference, certain behaviours have been designed as \"standard\" and are described below." ] }, { "cell_type": "code", "execution_count": 2, "id": "18b67e30-2e44-4414-b1b0-40c4b0733044", "metadata": {}, "outputs": [], "source": [ "import forallpeople as si\n", "si.environment('default')" ] }, { "cell_type": "markdown", "id": "24f3d555-e842-46fa-a803-40e0754a778c", "metadata": {}, "source": [ "## 1. Conventional Arithmetic\n", "\n", "`forallpeople` defines the methods required for conventional arithmetic between `Physical` instances.\n", "\n", "* Addition and subtraction are possible between physical quantities of the same dimension.\n", "* Multiplication and division are possible between any physical quantities and result in new dimensions.\n", "* Exponentiation is possible with integers and floats\n", "* Floor division and modulo are _currently_ not defined because of the ambiguity created with the other standard behaviours (see: Using Floor and Modulo, below)" ] }, { "cell_type": "code", "execution_count": 3, "id": "7ff23908-38d9-486a-83bf-1dc30a77fc6e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "223.000 kg" ], "text/latex": [ "$223.000\\ \\mathrkm{g}$" ], "text/markdown": [ "223.000 kg" ], "text/plain": [ "223.000 kg" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "a = 500 * si.kg\n", "b = 23 * si.kg\n", "c = 300 * si.kg\n", "display(a + b - c)" ] }, { "cell_type": "code", "execution_count": 4, "id": "04162841-557b-4920-9eb5-c00cf4e6bbe2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "9.810 m⋅s-2" ], "text/latex": [ "$9.810\\ \\mathrm{m} \\cdot \\mathrm{s}^{-2}$" ], "text/markdown": [ "9.810 m⋅s-2" ], "text/plain": [ "9.810 m·s⁻²" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "d = 9.81 * si.m / si.s**2\n", "display(d)" ] }, { "cell_type": "markdown", "id": "3cbe3b87-7df1-46ae-92d9-862ac28d280c", "metadata": {}, "source": [ "## 2. Auto-scaling of base units and derived units" ] }, { "cell_type": "code", "execution_count": 5, "id": "063a4b18-d8bc-4cc8-9bbb-dfd8fff51e08", "metadata": {}, "outputs": [ { "data": { "text/html": [ "5.000 Mg" ], "text/latex": [ "$5.000\\ \\mathrMm{g}$" ], "text/markdown": [ "5.000 Mg" ], "text/plain": [ "5.000 Mg" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(5000 * si.kg) # Auto-scaling to Mg" ] }, { "cell_type": "code", "execution_count": 6, "id": "7e6ece95-d7d4-4f53-90ee-63595a37f7a4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "4.000 GHz" ], "text/latex": [ "$4.000\\ \\mathrm{GHz}$" ], "text/markdown": [ "4.000 GHz" ], "text/plain": [ "4.000 GHz" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(4_000_000_000 / si.s) # Auto-scaling to GHz" ] }, { "cell_type": "code", "execution_count": 7, "id": "6e32f117-9e07-4533-841a-041c1893a661", "metadata": {}, "outputs": [ { "data": { "text/html": [ "112.000 nm" ], "text/latex": [ "$112.000\\ \\mathrnm{m}$" ], "text/markdown": [ "112.000 nm" ], "text/plain": [ "112.000 nm" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(0.000000112 * si.m) # Auto-scaling to nm" ] }, { "cell_type": "markdown", "id": "82211e99-0165-465d-8224-1409f452ab6a", "metadata": {}, "source": [ "