{ "cells": [ { "outputs": [], "cell_type": "markdown", "source": [ "# **7.** Example\n", "\n", "This is an example for Examples.jl.\n", "The source file can be found [here](https://github.com/fredrikekre/Examples.jl/blob/master/examples/example.jl).\n", "The generated markdown can be found here: [`example.md`](./example.md), the\n", "generated notebook can be found here:\n", "[`example.ipynb`](https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/latest/generated/example.ipynb), and the\n", "plain script output can be found here: [`example.jl`](./example.jl)." ], "metadata": {} }, { "outputs": [], "cell_type": "markdown", "source": [ "### Rational numbers in Julia\n", "Rational number in julia can be constructed with the `//` operator:" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "2//5" }, "metadata": {}, "execution_count": 1 } ], "cell_type": "code", "source": [ "x = 1//3\n", "y = 2//5" ], "metadata": {}, "execution_count": 1 }, { "outputs": [], "cell_type": "markdown", "source": [ "Operations with rational number returns a new rational number" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "11//15" }, "metadata": {}, "execution_count": 2 } ], "cell_type": "code", "source": [ "x + y" ], "metadata": {}, "execution_count": 2 }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "2//15" }, "metadata": {}, "execution_count": 3 } ], "cell_type": "code", "source": [ "x * y" ], "metadata": {}, "execution_count": 3 }, { "outputs": [], "cell_type": "markdown", "source": [ "Everytime a rational number is constructed, it will be simplified\n", "using the `gcd` function, for example `2//4` simplifies to `1//2`:" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "1//2" }, "metadata": {}, "execution_count": 4 } ], "cell_type": "code", "source": [ "2//4" ], "metadata": {}, "execution_count": 4 }, { "outputs": [], "cell_type": "markdown", "source": [ "and `2//4 + 2//4` simplifies to `1//1`:" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "1//1" }, "metadata": {}, "execution_count": 5 } ], "cell_type": "code", "source": [ "2//4 + 2//4" ], "metadata": {}, "execution_count": 5 } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.7.0" }, "kernelspec": { "name": "julia-0.7", "display_name": "Julia 0.7.0", "language": "julia" } }, "nbformat": 4 }