Package fractional. February 15, 2016



Similar documents
Package retrosheet. April 13, 2015

Package sendmailr. February 20, 2015

Package mcmcse. March 25, 2016

Accentuate the Negative: Homework Examples from ACE

Package jrvfinance. R topics documented: October 6, 2015

Package polynom. R topics documented: June 24, Version 1.3-8

Package ggrepel. February 8, 2016

Package bizdays. March 13, 2015

Package hazus. February 20, 2015

Package PACVB. R topics documented: July 10, Type Package

Package rivr. October 16, 2015

Package OECD. R topics documented: January 17, Type Package Title Search and Extract Data from the OECD Version 0.2.

Package sudokualt. July 4, 2016

Package searchconsoler

Package LexisPlotR. R topics documented: April 4, Type Package

Package Formula. April 7, 2015

Package tagcloud. R topics documented: July 3, 2015

Package syuzhet. February 22, 2015

Package urltools. October 11, 2015

Package uptimerobot. October 22, 2015

Package whoapi. R topics documented: June 26, Type Package Title A 'Whoapi' API Client Version Date Author Oliver Keyes

Package TSfame. February 15, 2013

Package schoolmath. R topics documented: February 20, Type Package

Package SHELF. February 5, 2016

Package date. R topics documented: February 19, Version Title Functions for handling dates. Description Functions for handling dates.

Package dfoptim. July 10, 2016

Package DCG. R topics documented: June 8, Type Package

Package HHG. July 14, 2015

Package decompr. August 17, 2016

Addition Methods. Methods Jottings Expanded Compact Examples = 15

8 Square matrices continued: Determinants

COMPSCI 210. Binary Fractions. Agenda & Reading

Package EasyHTMLReport

Package StockChina. January 30, 2016

Package GEOquery. August 18, 2015

Package png. February 20, 2015

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Package dunn.test. January 6, 2016

Continued Fractions and the Euclidean Algorithm

Package sjdbc. R topics documented: February 20, 2015

Handout #1: Mathematical Reasoning

Package optirum. December 31, 2015

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Package ChannelAttribution

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

Package VideoComparison

5.1 Radical Notation and Rational Exponents

Package RCassandra. R topics documented: February 19, Version Title R/Cassandra interface

Package MBA. February 19, Index 7. Canopy LIDAR data

Package MixGHD. June 26, 2015

Here are some examples of combining elements and the operations used:

CHAPTER 5 Round-off errors

Indices and Surds. The Laws on Indices. 1. Multiplication: Mgr. ubomíra Tomková

Sources: On the Web: Slides will be available on:

Package hive. January 10, 2011

Package HadoopStreaming

Package neuralnet. February 20, 2015

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

Activity 1: Using base ten blocks to model operations on decimals

Package CRM. R topics documented: February 19, 2015

Package httprequest. R topics documented: February 20, 2015

Package fastghquad. R topics documented: February 19, 2015

A.2. Exponents and Radicals. Integer Exponents. What you should learn. Exponential Notation. Why you should learn it. Properties of Exponents

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Solving Rational Equations

Package ATE. R topics documented: February 19, Type Package Title Inference for Average Treatment Effects using Covariate. balancing.

CORE Assessment Module Module Overview

Package R4CDISC. September 5, 2015

Method To Solve Linear, Polynomial, or Absolute Value Inequalities:

Package PKI. February 20, 2013

Siemens S7 Status Word

Package pxr. February 20, 2015

Session 7 Fractions and Decimals

Access Tutorial 2: Tables

So let us begin our quest to find the holy grail of real analysis.

Package PKI. July 28, 2015

Numerical Matrix Analysis

Package tvm. R topics documented: August 21, Type Package Title Time Value of Money Functions Version Author Juan Manuel Truppia

Introduce Decimals with an Art Project Criteria Charts, Rubrics, Standards By Susan Ferdman

Package GSA. R topics documented: February 19, 2015

Package robfilter. R topics documented: February 20, Version 4.1 Date Title Robust Time Series Filters

Creating Basic Excel Formulas

Vocabulary Words and Definitions for Algebra

A Second Course in Mathematics Concepts for Elementary Teachers: Theory, Problems, and Solutions

Numbering Systems. InThisAppendix...

Package TimeWarp. R topics documented: April 1, 2015

Chapter 7 - Roots, Radicals, and Complex Numbers

Package plan. R topics documented: February 20, 2015

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Classroom Tips and Techniques: The Student Precalculus Package - Commands and Tutors. Content of the Precalculus Subpackage

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Package pdfetch. R topics documented: July 19, 2015

Package pinnacle.api

Student Outcomes. Lesson Notes. Classwork. Discussion (10 minutes)

Lecture 3: Finding integer solutions to systems of linear equations

Package hoarder. June 30, 2015

Package hexview. R topics documented: February 20, Version Title Viewing Binary Files

Hands on S4 Classes. Yohan Chalabi. R/Rmetrics Workshop Meielisalp June ITP ETH, Zurich Rmetrics Association, Zurich Finance Online, Zurich

Package hive. July 3, 2015

Package BioFTF. February 18, 2016

Transcription:

Type Package Title Vulgar Fractions in R Version 0.1.3 Author Bill Venables Package fractional February 15, 2016 Maintainer Bill Venables <bill.venables@gmail.com> The main function of this package allows numerical vector objects to be displayed with their values in vulgar fractional form. This is convenient if patterns can then be more easily detected. In some cases replacing the components of a numeric vector by a rational approimation can also be epected to remove some component of round-off error. The main functions form a re-implementation of the functions 'fractions' and 'rational' of the MASS package, but using a radically improved programming strategy. License GPL (>= 2) Suggests stats, MASS, knitr, rmarkdown, ggplot2, dplyr Imports Rcpp LazyData TRUE LinkingTo Rcpp RoygenNote 5.0.1 NeedsCompilation yes VignetteBuilder knitr Repository CRAN Date/Publication 2016-02-15 16:03:13 R topics documented: fractional.......................................... 2 Math.fractional....................................... 3 numerators......................................... 4 numerical.......................................... 5 Ops.fractional........................................ 6 rat.............................................. 7 1

2 fractional unfractional......................................... 8 vfractional.......................................... 8 Inde 10 fractional Representation of a numeric vector in vulgar fractional form The object is flagged so that if it is coerced to character, or printed, the numerical quantities are represented by a rational approimation. In other respects the numerical object behaves as normally. fractional(, eps = 1e-06, maconv = 20, sync = FALSE) as.character(, eps = attr(, "eps"), maconv = attr(, "maconv"),...) ## S3 method for class charfrac print(,...) print(,...) eps maconv sync A numeric object An absolute error tolerance An upper limit on the number of convergents to use in the continued fractions. A logical value. Should the numerical value be changed to match the rational approimation, as closely as possible with floating point, (TRUE)? Or, should it be left and used in its original state (FALSE)?... Currently ignored. A numeric object of class "fractional". Methods (by generic) as.character: S3 method for coercion to character, producing an object inheriting from class "charfrac" print: Print method for class "charfrac" objects, unquoted. print: Print method for "fractional" objects

Math.fractional 3 See Also fractions for a similar functionality. (M <- solve(cbind(1, contr.helmert(5)))) (Mf <- fractional(m)) ## print method right justifies (Mc <- as.character(mf)) ## print method left justifies (Mn <- numerical(mc)) set.seed(123) u <- matri(runif(10), 2, 5) (uf <- fractional(u)) (us <- fractional(u, sync = TRUE)) ## may look different! unfractional(uf) - unfractional(us) ## rational approimation errors Math.fractional Method for the group generic function for the elementary mathematical functions Allows graceful operations with mathematical functions. Math(,...) A numerical object flagged as fractional... Passed on to further methods (but usually not required) A numeric object with the results of the computations, but NOT flagged as of class "fractional". (M <- fractional(solve(cbind(1, contr.helmert(5))))) (M0 <- abs(m)*sign(m)) ## fractional flag lost

4 numerators numerators Etract the parts of a fractional object Generic function for etracting numerators with methods for "fractional" or "charfrac" objects Generic function for etracting denominators with methods for "fractional" or "charfrac" objects numerators() ## S3 method for class charfrac numerators() numerators() ## Default S3 method: numerators() denominators() ## S3 method for class charfrac denominators() denominators() ## Default S3 method: denominators() An object of class "fractional" or "charfrac" An integer vector of numerators An integer vector of denominators Methods (by class) charfrac: numerators method function for "charfrac" objects fractional: numerators method function for "fractional" objects

numerical 5 default: Default numerators method for numeric objects charfrac: denominators method function for "charfrac" objects fractional: denominators method function for "fractional" objects default: Default denominators method for numeric objects (pi_appro <- vfractional(base::pi, eps = 0, maconv = 1:10)) numerators(pi_appro) denominators(pi_appro) numerical Convert a fractional object to the equivalent numeric object Convert an object of class "fractional" or "charfrac" to a purely numeric object. This is effectively a method function for the.primitive generic function as.numeric but written as a separate function for purely technical reasons. numerical(vulgar) numerical(vulgar) ## S3 method for class charfrac numerical(vulgar) ## Default S3 method: numerical(vulgar) vulgar character string form of a class fractional object. A numeric object as represented by its (usually fractional) display. Methods (by class) fractional: Method for "fractional" objects charfrac: Method for "charfrac" objects default: Default method for numerical generic

6 Ops.fractional suppresspackagestartupmessages(library(dplyr)) m <- 2*diag(5) m[abs(row(m) - col(m)) == 1] <- -1 m ## How much roundoff error does inverting entail? (mi <- solve(m) %>% fractional) ## patterned inverse mi * ma(denominators(mi)) ## clearer pattern m1 <- solve(mi) range(m1 - m) ## roundoff still present m2 <- m1 %>% numerical ## remove roundoff error - hopefully! identical(m2, m) ## no roundoff Ops.fractional Method for the group generic function for the arithmetic operators Provides arithmetic operations for numeric objects or of class "fractional". Ops(e1, e2) e1 e2 A numeric objet, possibly of class "fractional" A numeric objet, possibly of class "fractional" The result of the arithmetic operation, flagged as class "fractional" (M <- fractional(1:10/7)) M + 1 1 + M + M^2

rat 7 rat Calculate Rational Approimation Using Continued Fraction Methods This is a behind-the-scenes function not likely to be used other than internally within the package. It computes the rational approimations for each value in the principal argument. rat(, eps = 1e-06, maconv = 20L).ratr(, eps = 1e-06, maconv = 20) ratr(, eps = 1e-06, maconv = 20) eps maconv A numeric vector for which rational approimations are required. An absolute error tolerance on the approimation An upper limit on the number of convergents that the continued fraction epansion may employ. The fraction is terminated once the desired accuracy is met (or the upper limit is about to be eceeded). A 3 column matri giving, respectively, the numerators, denominators and number of convergents needed to achieve the error tolerance, in the columns Functions rat: C++ version of the same function used for speed.ratr: Workhorse function for a single value See Also rat which has the same functionality, but is coded in C++. fractional(base::pi) ratr(base::pi) set.seed(123) (u <- matri(runif(10), 2, 5)) (ru <- ratr(u, eps = 1.0e-3, maconv = 6)) (abs_error <- matri(abs(u - ru[, 1]/ru[, 2]), 2, 5))

8 vfractional unfractional Demote a fractional object back to a numeric one Given an object of class "fractional" this simple function removes the attributes that signal that it is to be treated as a fractional object, thus returning it to its original numeric status alone unfractional() A "fractional" object A simple numeric object like (tst <- fractional(matri(0:9/10, 2, 5))) (tst <- unfractional(tst)) vfractional Vectorized form for fractional A function which allows any or all of the first three arguments of fractional to be vectors, with short vectors recycled in the usual way. Note that the return value is a character string vector and may not be used in arithmetic operations vfractional(, eps = 1e-06, maconv = 20) eps maconv as for fractional as for fractional, but may be a vector as for fractional but may be a vector

vfractional 9 A character string vector of class "charfrac" oldopt <- options(scipen = 15) pi_appro <- vfractional(base::pi, eps = 0, maconv = 1:10) within(data.frame(pi_appro, stringsasfactors = FALSE), { value = numerical(pi_appro) error = signif(base::pi - value, 3) n = seq_along(value) - 1 })[, c("n", "pi_appro", "value", "error")] options(oldopt)

Inde.ratr (rat), 7 as.character.fractional (fractional), 2 denominators (numerators), 4 fractional, 2 fractions, 3 Math.fractional, 3 numerators, 4 numerical, 5 Ops.fractional, 6 print.charfrac (fractional), 2 print.fractional (fractional), 2 rat, 7, 7 ratr (rat), 7 unfractional, 8 vfractional, 8 10