REPL maths and notation

by on under programming
5 minute read

Maths, notation, calculators and REPL programming

Notation

  • Prefix notation also called polish notation. Example: + 5 5
  • Postfix notation also called reverse polish notation. Example: 5 5 +
  • Infix notation, this is what most people use daily. Example: 5 + 5

Algebra…? is this a notation or expression or convention or a daft question? Seems it’s classed as a language of its own.

Operators and operands.

Buffers in polish notation are like computer registers/buffer.

Calculators

fx-991ES PLUS

This Casio calculator is set by default to give fractional output. You can change it to decimal output using the below commands. Reference

Go to [Shift ] [Setup]

Hit [Math IO]

Select [Line O]

Last output is stored in variable: Ans

Old Windows XP calculator emulator programs.

HP PDA Windows CE scientific calculator programs.

REPL and maths in programming languages

REPL environment as a calculator.

You will run into int based calculations unless specifying decimal variables/input for division etc.

C#

The M suffix on the numbers is how you indicate that a constant should use the decimal type. Otherwise, the compiler assumes the double type.

.NET Core

Console application example

Console.WriteLine((decimal)5 / (decimal)6);

Console.WriteLine((int)5 / (decimal)6);

Console.WriteLine(5 / 6);

Console.WriteLine(5 / 6.1);

object obj1 = 5;
Console.WriteLine(obj1.GetType());

object obj2 = 6.1;
Console.WriteLine(obj2.GetType());

object obj3 = 6.1m;
Console.WriteLine(obj3.GetType());

int int1 = 5;
Console.WriteLine(int1.ToString());

decimal decimal1 = 6.1m;
Console.WriteLine(int1 / decimal1);

Output

dotnet run
0.8333333333333333333333333333
0.8333333333333333333333333333
0
0.819672131147541
System.Int32
System.Double
System.Decimal
5
0.819672131147540983606557377

.NET Framework

Interactive window example

> 5/6
0
> 5m/6m
0.8333333333333333333333333333
> 5.0/6.0
0.83333333333333337
> 5/6.0
0.83333333333333337

Mono

Run Mono’s REPL using command: csharp

csharp
Mono C# Shell, type "help;" for help

Enter statements below.
csharp> 

R

Run R programming language in interactive mode using command: R

In interactive mode the last output is in variable: .Last.Value

SQL

select 6+8 as ans

MATLAB

In interactive mode the last output is in variable: ans

C#, LINQ and SQL

BC

bc or as i call it best calculator.

In interactive mode the last output is in variable: last

Can also be used on Termux on Android see my blog post: Everyday Termux uses

dc useful for polish or reverse polish notation.

Python

Python 2.7

>>> 5/6
0

Python 3.6

>>> 5/6
0.8333333333333334

C++

C

Graphing

First floor weight

This was going to be a separate blog post but i’ll throw it in here.

Calculating the maximum weight a section of floor supported by joists can handle.

Quality documentation in simple HTML

anyway 1.5 kN per square meter as per the BS6399-1
F = M*A
so he is correct that assuming A (acceleration) is gravity 9.81 m/s^2
M = F/A
1500/9.81 = 152 kg per square meter

I have at least 222 kg within a 1 meter squared area. However the weight is positioned near a load bearing wall.

comments powered by Disqus