It is said that multiplication is a short notation of repeated addition, which is absolutely true and, with a limitation to integers, a fairly obvious fact.

**4 × 3 = 3 + 3 + 3 + 3 = 4 + 4 + 4 = 3 × 4 = 12**

These two fundamental multiplication properties can be written as follows

commutative property: **a × b = b × a**

example: **3 × 4 = 4 × 3**

distributive property: **a × (b + c) = a × b + a × c**

example: **3 × 4 = 3 × (1 + 3) = 3 × 1 +3 × 3 = 3 + 9 = 12**

Mathematicians, defining the arithmetic of negative numbers, wanted to be consistent with the already developed arithmetic of positive numbers and zero. Based on the interpretation of the short notation of repeated addition, we can easily justify the following:

**−3 × 4 = (−3) + (−3) + (−3) + (−3) = −12**

"By adding debt to debt," we get more debt - intuitive. Now using the

commutative property of multiplication we get:

**4 × (−3) = −3 × 4 = −12**

At this point, the intuition is a bit more difficult, but the consistency has been preserved. Time to go to the main point - let's try to answer the question:

**−3 × (−4) = ?**

To solve the above, we will use a trick based on the distributive property of multiplication over addition.

**−3 × 0 = 0**

**−3 × 0 = −3 × (−4 + 4) = 0**

**−3 × (−4 + 4) = −3 × (−4) + (−3) × 4 = 0**

**−3 × (−4) + (−12) = 0**

**−3 × (−4) = 12**

The above has nothing to do with intuition, but it is consistent, i.e. based on the arithmetic of positive numbers and zero, the commutative property of multiplication, the distributive property of multiplication over addition, we are able to justify why multiplying negative numbers must be a positive number.

Suppose we multiply two numbers, where the interpretation of the first is the value of profit or losses, while the meaning of the second one is the multiplication (increase / decrease) of the first value. In this situation, multiplying two negative numbers means reducing the loss, ie the total positive effect of the action.

profit × increase = positive effect

profit × decrease = negative effect

loss × increase = negative effect

**loss × decrease = positive effect**

The above explanation can be described as intuitive

Finally a video from Mathologer explaining the above problem (that was a base for the above post).

Let's run the negative numbers multiplication test using the Scalar calculator.

Test fully successful Thank you for reading! All the best

The syntax for defining user functions is as follows.

**FunctionName(param1 <, param2, ...>) = expression**

It is much easier to understand this on the basis of an example - it is really easy. Please note that **you can easily define a function depending on the function you have already defined.** It gives you great flexibility.

**Scalar code result:**

scalar > f(x) = sqrt(x) scalar > g(x) = f(x)^2 scalar > h(x) = g(x)^2 scalar > h(4) e1 = 16 scalar > g(4) e2 = 4 scalar > f(4) e3 = 2 scalar > Showing command history

**Scalar script:**

f(x) = sqrt(x) g(x) = f(x)^2 h(x) = g(x)^2 h(4) g(4) f(4)

I am sure, that from time to time, you will want to check what you have already defined. This is possible using context help. Long click on the "example /?" button, then select the user items option.

Each defined function is available in the Scalar namespace. Nothing prevents you from referring to these names anywhere in the application. **In particular, it allows you to draw graphs of your own functions.**

Nothing special in this case as Scalar has no restrictions. Simply use the similar syntax to the presented in the below example.

**Scalar code result:**

scalar > f(x,y) = sin(x) + cos(y) scalar > f(pi/6, pi/4) e1 = 1.2071067811865475 scalar > 1/2 + sqrt(2)/2 e2 = 1.2071067811865475 scalar > f(x,y,z) = x*y*z scalar > f(1,2,3) e3 = 6 scalar > f(4,5,f(1,2,3)) e4 = 120

**Scalar script:**

f(x,y) = sin(x) + cos(y) f(pi/6, pi/4) 1/2 + sqrt(2)/2 f(x,y,z) = x*y*z f(1,2,3) f(4,5,f(1,2,3))

Scalar provides a special syntax for defining functions with **any (variable) number of parameters.**

**FunctionName(...) = expression**

**"(...)"** is obligatory as it indicates that you create function with variable number of parameters.

**Additionally Scalar provides special keywords that help to build expression defining variadic functions.**

**[npar]**- number of parameters provided by the user on calculation request**par(i)**- value of parameter at index "i"

Please refer to the below example

**Scalar code result:**

scalar > f(...) = [npar] scalar > f(2) e1 = 1 scalar > f(3,1) e2 = 2 scalar > f(4,2,5,6) e3 = 4 scalar > f(...) = sum(i,1,[npar],par(i)) scalar > f(1,2,3,4,5) e4 = 15 scalar > 1+2+3+4+5 e5 = 15

**Scalar script:**

f(...) = [npar] f(2) f(3,1) f(4,2,5,6) f(...) = sum(i,1,[npar],par(i)) f(1,2,3,4,5) 1+2+3+4+5

Thank you for your time

All the bets!

**In Scalar you can simply write x = 2, y = 2 * x**, etc. Try it yourself. Pay particular attention to the fact that when defining the argument y, which depends on the argument x, the change in the value of x affects the value of y. In other words, Scalar remembers the expressions that define the arguments and uses these expressions at the time of requesting the value.

**Scalar code result:**

scalar > x = 2 scalar > x e1 = 2 scalar > 2*x + 4 e2 = 8 scalar > y = 2*x + 4 scalar > y e3 = 8 scalar > x = 3 scalar > y e4 = 10

**Scalar script:**

x = 2 x 2*x + 4 y = 2*x + 4 y x = 3 y

In terms of dependencies between arguments Scalar does not define any restrictions. You can create wide and deep dependency trees. This is well illustrated by the example below.

**Scalar code result:**

scalar > a = 3 scalar > b = 3*a + 2 scalar > c = a*b scalar > d = a + b + c scalar > d e1 = 47 scalar > a = 4 scalar > d e2 = 74 scalar > a = 5 scalar > d e3 = 107

**Scalar script:**

a = 3 b = 3*a + 2 c = a*b d = a + b + c d a = 4 d a = 5 d

In certain situations, it is convenient to check how user elements are defined. Use the list command to do this.

**list**

Please note that Scalar assigns the results of the calculations to the constant, while the arguments are marked separately.

**Scalar code result:**

scalar > list Type Name/Value ---- ---------- Constant: e1 = 47.0 ----- d Constant: e2 = 74.0 ----- d Constant: e3 = 107.0 ----- d Argument: a = 5.0 ----- a = 5 Argument: b = 17.0 ----- b = 3*a + 2 Argument: c = 85.0 ----- c = a*b Argument: d = 107.0 ----- d = a + b + c

**Scalar script:**

list

You can also use context help to verify the elements definition. Long click on the "example /?" button, then in the dialog select the user items.

The difference between the user constant and the user argument is fundamental. T**he constant only remembers the value, the argument remembers the expression, thanks to which the value can be calculated. **You can define your own constant by adding the const command at the beginning.

**const **def

**Scalar code result:**

scalar > x = 3 scalar > const y = x^2 scalar > y e1 = 9 scalar > x = 10 scalar > y e2 = 9 scalar > list Type Name/Value ---- ---------- Constant: y = 9.0 ----- y = x^2 Constant: e1 = 9.0 ----- y Constant: e2 = 9.0 ----- y Argument: x = 10.0 ----- x = 10

**Scalar script:**

x = 3 const y = x^2 y x = 10 y list

It's all for today. Thank you

The most frequently used numbers are 2 and 5. It is also well visible the effect of multi-use of the digit 0 considering particular user perspective. The digit, that is used the least often, is 7.

Digit | Clicks [%] | Users [%] |

0 | 12.8% | 7.8% |

1 | 12.5% | 11.0% |

2 | 17.5% | 16.0% |

3 | 11.3% | 12.0% |

4 | 6.5% | 8.0% |

5 | 15.3% | 14.4% |

6 | 9.9% | 10.7% |

7 | 3.9% | 6.1% |

8 | 5.3% | 7.3% |

9 | 5.1% | 6.6% |

Sequence: 2, 5, 0, 1, 3, 6, 4, 8, 9, 7

Digit | Clicks [%] | Users [%] |

2 | 17.5% | 16.0% |

5 | 15.3% | 14.4% |

0 | 12.8% | 7.8% |

1 | 12.5% | 11.0% |

3 | 11.3% | 12.0% |

6 | 9.9% | 10.7% |

4 | 6.5% | 8.0% |

8 | 5.3% | 7.3% |

9 | 5.1% | 6.6% |

7 | 3.9% | 6.1% |

Sequence: 2, 5, 3, 1, 6, 4, 0, 8, 9, 7

Digit | Clicks [%] | Users [%] |

2 | 17.5% | 16.0% |

5 | 15.3% | 14.4% |

3 | 11.3% | 12.0% |

1 | 12.5% | 11.0% |

6 | 9.9% | 10.7% |

4 | 6.5% | 8.0% |

0 | 12.8% | 7.8% |

8 | 5.3% | 7.3% |

9 | 5.1% | 6.6% |

7 | 3.9% | 6.1% |

By removing the digits 0 and 3, we get the same order in terms of per clicks and per users perspectives.

Sequence position | Digits by Clicks | Digit by Users |

1 | 2 | 2 |

2 | 5 | 5 |

3 | 0 | 3 |

4 | 1 | 1 |

5 | 3 | 6 |

6 | 6 | 4 |

7 | 4 | 0 |

8 | 8 | 8 |

9 | 9 | 9 |

10 | 7 | 7 |

Interesting! All the best!

Entering numbers in the form of fractions is done using the following syntax:

**a_b**: a - numerator, b - denominator, converted to decimal:**a/b****a_b_c**: a - whole, b - numerator, c - denominator, converted to decimal:**a+c/b**

Please follow the below example:

**Scalar code result:**

scalar > 1_3 e1 = 0.3333333333333333 scalar > 1_3 + 1_6 e2 = 0.5 scalar > 2_3_4 e3 = 2.75 scalar > 100_2_10 e4 = 100.2 scalar > 8^1_3 e5 = 2 scalar > -5_13_3 e6 = -9.333333333333332

**Scalar script:**

1_3 1_3 + 1_6 2_3_4 100_2_10 8^1_3 -5_13_3

Result of any expression can be presented as a fraction. Please use below syntax:

**frac** expression

**The conversion procedure in some cases may give an approximate result.** That is why it is worth observing the epsilon parameter.

Please follow below examples:

**Scalar code result:**

scalar > frac 0.5 e1 = 1/2 eps = 0 scalar > frac -1.3 e2 = -1-3/10 eps = 0 scalar > frac 1.3 e3 = 1+3/10 eps = 0 scalar > 3-2/13 e4 = 2.8461538461538463 scalar > frac 2.8461538461538463 e5 = 2+11/13 eps = 0 scalar > frac pi e6 = 3+14159265358979/100000000000000 eps = 0.0000000000000031086244689504383

**Scalar script:**

frac 0.5 frac -1.3 frac 1.3 3-2/13 frac 2.8461538461538463 frac pi

The decimal to fraction conversion algorithm is carried out in a few steps. The first step is to try to find an accurate representation through an optimized search method. You can control the search range using the parameter available in the application options.

**To Fraction Init Search Size** - Maximum number for initial search of denominator - default value 10000

Thank you for reading and thank you for using Scalar. If you like my app **please make me a gift posting a review on Google Play store - links below.**

All the best!

]]>- Convert decimal system
**to other numeral systems** - Convert
**other numeral systems**into a decimal system - Enter values simultaneously in
**different numeral systems** - Acquire
**information about the digits of a given numbe**r on the basis of the indicated numeral system

Stay tuned, this is exciting

Conversion of the number to different numeral systems is done at the end, i.e. after determining the value of the expression. User indicates in which numeral system the result should be presented. General syntax:

**<NumeralSystem> expression**

- binary:
**bin expression** - octal:
**oct expression** - decimal:
**expression** - hexadecimal:
**hex expression** - base-n:
**base.n expression**

Please follow the below examples

**Scalar code result:**

scalar > bin 127 e1 = b.1111111 eps = 0 scalar > oct 127 e2 = o.177 eps = 0 scalar > hex 127 e3 = h.7F eps = 0 scalar > base.3 127 e4 = b3.11201 eps = 0 scalar > base.16 127 e5 = h.7F eps = 0 scalar > base.9 (1+3)*4 e6 = b9.17 eps = 0

**Scalar script:**

bin 127 oct 127 hex 127 base.3 127 base.16 127 base.9 (1+3)*4

The mathematical engine of Scalar always works in one numeral system, so before it is possible to determine the result of an expression, all values given in different numeral systems are converted to one decimal standard. In Scalar you can enter numbers using any numeral system. General syntax:

**<NumericalSystemPrefix.>NumberLiteral**

- binary:
**b.XXXX** - octal:
**o.XXXX** - decimal:
**XXXX** - hexadecimal:
**h.XXXX** - base-n:
**b<n>.XXXX**

Please follow the below examples

**Scalar code result:**

scalar > hex 123 e1 = h.7B eps = 0 scalar > h.7b e2 = 123 scalar > 123-h.7b e3 = 0 scalar > hex h.7b e4 = h.7B eps = 0 scalar > bin h.7b e5 = b.1111011 eps = 0 scalar > b1.11111 e6 = 5 scalar > b1.11111 - 5 e7 = 0

**Scalar script:**

hex 123 h.7b 123-h.7b hex h.7b bin h.7b b1.11111 b1.11111 - 5

Scalar is very flexible, thus there is no limitation in terms of entering number in various numeral systems.

**Scalar code result:**

scalar > b1.11111*5 e1 = 25 scalar > x = b16.7b + b1.11111 scalar > x e2 = 128 scalar > 2*x e3 = 256 scalar > hex 2*x e4 = h.100 eps = 0 scalar > h.100 e5 = 256 scalar > base.1 32 e6 = b1.11111111111111111111111111111111 eps = 0

**Scalar script:**

b1.11111*5 x = b16.7b + b1.11111 x 2*x hex 2*x h.100 base.1 32

Using a standard alphabet, i.e. alphabetical order of letters, you can enter numbers in a numeral system with **base between 1 and 36**. In case of any larger bases, please use the function **base (n, ...)** that accepts many parameters.

**Scalar code result:**

scalar > base.3 56 e1 = b3.2002 eps = 0 scalar > base(3, 2, 0, 0, 2) e2 = 56 scalar > base(256, 2, 0, 0, 2) e3 = 33554434 scalar > base(256, 54, 125, 36, 2) e4 = 914170882 scalar > base.23 10000000 e5 = b23.1CGKDE eps = 0 scalar > b23.1cgkde e6 = 10000000

**Scalar script:**

base.3 56 base(3, 2, 0, 0, 2) base(256, 2, 0, 0, 2) base(256, 54, 125, 36, 2) base.23 10000000 b23.1cgkde

During the conversion of the result to the indicated numeral system, only the integer part is converted. Please follow the epsilon remark to be sure what part was not converted.

**Scalar code result:**

scalar > pi^e e1 = 22.45915771836104 scalar > bin pi^e e2 = b.10110 eps = 0.45915771836104113 scalar > e^pi e3 = 23.140692632779263 scalar > bin e^pi e4 = b.10111 eps = 0.14069263277926325 scalar > bin -e^pi e5 = -b.10111 eps = 0.14069263277926325

**Scalar script:**

pi^e bin pi^e e^pi bin e^pi bin -e^pi

Scalar provides several clever functions that allow **to obtain information about the digits of a given number.** Long press the "example /?" button and enter "numeral" in the search field. You will be presented with the list of functions.

**ndig10(x)**- number of digits of a number in base 10**ndig(x, base)**- number of digits of a number in any base**dig10(x, position)**- digit of a number in base 10 at specified position**dig(x, position, base)**- digit of a number in any base at specified position

And a few examples:

**Scalar code result:**

scalar > base.3 1234567 e1 = b3.2022201111201 eps = 0 scalar > ndig10(1234567) e2 = 7 scalar > ndig(1234567, 3) e3 = 13 scalar > dig10(1234567, 5) e4 = 5 scalar > dig(1234567, 5, 3) e5 = 2 scalar > dig(h.abfd, 3, 16) e6 = 15

**Scalar script:**

base.3 1234567 ndig10(1234567) ndig(1234567, 3) dig10(1234567, 5) dig(1234567, 5, 3) dig(h.abfd, 3, 16)

Thank you for reading and thank you for using Scalar. If you like my app **please make me a gift posting a review on Google Play store.**

Best regards

]]>Let's start with the list of functions and options available in Scalar, which are linked to prime numbers. On the calculator screen, long click on the **"example /?"** button. As a result you will get the help dialog containing search option. Enter "prime" keyword.

Scalar functions list:

**ispr(n)**- prime number test (is number a prime?)**Pi(n)**- prime-counting function - Pi(x)**nfact(x**) - prime decomposition - number of distinct prime factors**factval(number, factorid)**- prime decomposition - factor value at position between 1 … nfact(n) - ascending order by factor value**factexp(number, factorid)**- prime decomposition - factor exponent / multiplicity at position between 1 … nfact(n) - ascending order by factor value**factor expr**- prime factorization - calculate expression, return result in the form of prime factors**fact expr**- the same as factor

Prime test function **ispr(n)** returns 1 if the number is prime and 0 otherwise. Using sigma summation operator **sum(arg, from, to, expr)** plus combination with **ispr(n)** it is very easy to count primes in a given range. Please refer to the below example:

**Scalar code result:**

scalar > ispr(1) e15 = 0 scalar > ispr(2) e16 = 1 scalar > ispr(3) e17 = 1 scalar > ispr(4) e18 = 0 scalar > sum(n,1,1000,ispr(n)) e19 = 168 scalar > Pi(1000) e20 = 168 scalar > Pi(10000000) e21 = 664579

**Scalar script:**

ispr(1) ispr(2) ispr(3) ispr(4) sum(n,1,1000,ispr(n)) Pi(1000) Pi(10000000)

Above example shows also the **Pi(n)** prime-counting function.

This time I will show visually the quality of various approximations of **Pi(n)** prime-counting function:

**Pi(n)**- prime-counting function - definition can be found here,**li(n)**- logarithmic integral - a special function - please refer to the definition here,**n/ln(n)**- Gauss-Legendre approximation of Pi(n)

**Prime-counting function in the range between 2 and 100**

**Scalar graph script:**

var = n from = 2 to = 100 exp1 = Pi(n) exp2 = n/ln(n) exp3 = li(n) by = 1 curs = 1

**Prime-counting function in the range between 2 and 2000**

**Scalar graph script: **

var = n from = 2 to = 2000 exp1 = Pi(n) exp2 = n/ln(n) exp3 = li(n) by = 1 curs = 1

**Prime-counting function in the range between 2 and 150000000**

** Scalar graph script: **

var = n from = 2 to = 150e6 exp1 = Pi(n) exp2 = n/ln(n) exp3 = li(n) by = 1e6 curs = 1

To get prime factors for a given number just use **factor **or **fact** Scalar command. Please refer to the below screenshots:

**Scalar code result:**

scalar > fact 324 e8 = 2^2 * 3^4 eps = 0 scalar > nfact(324) e9 = 2 scalar > factval(324,1) e10 = 2 scalar > factexp(324,1) e11 = 2 scalar > factval(324,2) e12 = 3 scalar > factexp(324,2) e13 = 4 scalar > e10^e11 * e12^e13 e14 = 324

**Scalar script:**

fact 324 nfact(324) factval(324,1) factexp(324,1) factval(324,2) factexp(324,2)

**Scalar code result:**

scalar > fact 324 e1 = 2^2 * 3^4 eps = 0 scalar > fact 254*5 e2 = 2^1 * 5^1 * 127^1 eps = 0 scalar > fact 1254685755845 e3 = 5^1 * 250937151169^1 eps = 0 scalar > n=2598 scalar > fact n e4 = 2^1 * 3^1 * 433^1 eps = 0

**Scalar script:**

fact 324 fact 254*5 fact 1254685755845 n=2598 fact n

Counting primes is a time consuming task.

In order to significantly accelerate the calculation Scalar implements Sieve of Eratosthenes. The only thing you have to do is to go to the settings screen and enter in the "Max num in primes cache" option the range that will be examined. After doing so, Scalar will build the cache that will be saved in memory for further usage.

Say bye bye for prolonging progress bar!

**Best regards! **