add an invariant to a Z notation schema - formal-methods

Question description
the required invariant
I'm a beginner at Z notation I have tried , but I don't know what functions should I use

Related

Recursive type aliases with Pyright

Checking the following code with Pyright:
from typing import Union, TypeVar
T = TypeVar('T')
X_or_RecurListOf = Union[T, list['X_or_RecurListOf']]
x: X_or_RecurListOf[str] = ['asd']
produces the error:
5:28 - error: Expression of type "list[str]" cannot be assigned to declared type "X_or_RecurListOf[str]"
  Type "list[str]" cannot be assigned to type "X_or_RecurListOf[str]"
    "list[str]" is incompatible with "str"
      TypeVar "_T#list" is invariant
        Type "str" cannot be assigned to type "X_or_RecurListOf[Type[T#X_or_RecurListOf]]"
          Type "str" cannot be assigned to type "T#X_or_RecurListOf"
          "str" is incompatible with "list[X_or_RecurListOf]" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 infos
Completed in 0.677sec
Am I doing something wrong?
Or have I misunderstood the announcement for support of recursive types in Pyright?
Oh, I've found what Pyright stumbles over!
It wants to have the type parameter in the recursive definition:
X_or_RecurListOf = Union[T, list['X_or_RecurListOf[T]']] - pay attention to the [T]!
I don't see why this is necessary but it works for me, especially as I really meant X_or_RecurListOf[T] and not X_or_RecurListOf[Any].

Error: Kotlin: The floating-point literal does not conform to the expected type Float

I was making a simple maths calculator in kotlin, an error appeared on my screen when I tried to initialize the value of one of the variables used as 0.00 for float integer.
var x:Float= readLine()!!.toFloat()
var y:Float= readLine()!!.toFloat()
var sum:Float=0.00// the error message is showcased in this line
sum=x+y
println("Addition " + sum)
This is a key difference between Java and Kotlin. Kotlin does not do numeric type promotion like Java does. The comments to your question are showing you how to deal with this, by either matching up the two types Double and/or Float to begin with, or by explicitly converting one or the other so that the two types match up.
Your problems goes away if you make use of Kotlin's ability to infer variable types by taking the type specifications off of your variable definitions. The fact that Kotlin infers types is one reason it does not promote numeric types. Mixing the two would lead to a lot of confusion.
Here's an example of how to fix and simplify your code's type mismatch issues using type inference:
var x = readLine()!!.toFloat()
var y = readLine()!!.toFloat()
var sum = x + y
println("Addition " + sum)
I understand that this may be just test code that you're using to understand Kotlin better. With that said, I'll point out that this code will crash if your user types in non-numeric input. You could fix this by putting a try/catch around your input lines, and providing an nice error message. You might want to put each input in a loop, continuing to ask for an input until the user does provide a response that is of the expected format.

NCalc evaluation is wrong?

I am trying to evaluate the following expression:
7088.800/(((((((24.65995+24.43061+24.54517+24.65192)/4)-32.0)*5/9)+273.15)/288.15)^.5)
If you are asking yourself why I didn't use Sqrt() instead of ^0.5 it's because I'm doing some things with the string beforehand that require there be no letters.
I am using this simple code:
Expression.CacheEnabled = False
x = New Expression(xEquation)
y = New Expression(yEquation)
System.Diagnostics.Debug.Write(x.Error)
System.Diagnostics.Debug.Write(y.Error)
Return New PointF(x.Evaluate, y.Evaluate)
The answer I get is: 7088.800
The correct answer is:7336.46922305(according to google)
I am using .net 3.5 and ncalc 1.3.8
I suspect it doesn't like the amount of brackets there are but I can't find any mention of that being a problem anywhere...
Thanks!
I cannot get Ncalc or Ncalc-edge (v1.4.1) to use the exponentiation operator ^ and produce the correct result. E.g., "4 ^ 2" gives 6. It does not accept ** as an operator.
A little bit of investigation shows that it uses ^ as the Xor operator, in the style of C#. C# does not have an exponentiation operator, so you will have to devise a way of parsing your actual input string and using Sqrt.
There are currently were some requests on the Ncalc discussion forum regarding this, such as Override ^ operator (link now dead, and it's not even available on the Wayback Machine).

Maple Integration of two variables

Im trying to find out how to type fig. 1 into maple:
because when i do it myself i get fig. 2
This is about forced periodic vibrations.
It looks like you are integrating over "Tao" assuming everything else constant for integration. Why don't you redefine a new variable, say y = w*T and let maple evaluate?
If it is just for typing as a text, you can first type in Math format and comment it out with # sign.

In lambda calculus, can variable be expression in general?

For better understanding of functional programming, I am reading the wiki page for lambda calculus here.
The definition says:
If x is a variable and M ∈ Λ, then (λx.M) ∈ Λ
Intuitively I thought variable are / represented by single-letter id's. But since here we deal with strict math definitions, I just want to double confirm this understanding: in general, can expression be classified as variable?
e.g. if x is a variable, is expression (x + x) a variable in lambda calculus? i.e. is it ok to write (λ(x+x).M) as an lambda calculus abstraction?
(Concern is in some context this is true. e.g. Here: An expression such as 4x^3 is a variable)
No, (x + x) is no variable (indeed it's not even a expression in naive lambda calculus).
I think you mix the terms variables and expressions somehow (or want some kind of pattern-matching?).
So let's follow the core-definition of lambda-calculus and expressions:
The definition itself is not that hard (indeed you linked it yourself with the wiki-page).
It's mentioned right from the start:
you have a set of variables V: (v_1, v_2, ...) (of course you can name them as you want - it's only important that you remmber that these are considered different symbols in your calculus)
the symbols λ, ., ( and )
This is it - thats all of the "Tokens" for this grammar/calculus.
Now there are a couple of rules how you can form Expressions from these:
each Variable is a expression
Abstraction: if E is a expression and x is a Variable then (λx.E) is a expression (here x and E are templates or Metavariables - you have to fill them with some real Expression to make this an Expression!)
Application: if A and B are expressions than (A B) is a expression.
So possible expressions are:
v_50
(λv_4.v_5)
((λv_4.v_5) v_50)
....
This is all when it comes to expressions.
You see: if you don't allow (x+x) as a symbol or name for a variable from the start it can never be a variable - indeed no expression is a variable even if there are some expressions consisting only of one said variable - if you called something expression it will never be a variable (again) ;)
PS: of course there are a couple of conventions to keep the parentheses a bit down - but for a start you don't need those.