Field tactic with partial inverse function - coq

Coq defines the multiplicative inverse function 1/x as a total function R -> R, both in Rdefinitions.v and in Field_theory.v. The value 1/0 is left undefined, all calculation axioms ignore it.
However this is a problem in constructive mathematics, because all total functions R -> R must be continuous. And we cannot connect the positive and negative infinities at zero. Therefore the constructive inverse is rather a partial function :
Finv : forall x : R, (0 < x \/ x < 0) -> R
This is for example how it is defined in the C-CoRN library.
Now is there a way to use the field tactic with those partial inverse functions ? A direct Add Field does not work.

The answer is no. The Add Field command relies on a function of type R -> R that represents the inverse and such a function cannot be defined constructively.

Related

Identify powers in an algebraic expression for a Buckingham Pi calculation in MatLab

This is a continuation of an earlier question I asked here.
If I create a symbolic expression in MatLab
syms L M T
F = M*L/T^2
I want to identify the powers of each dimension M, L, or T. In this case, the answer should be
for M, 1
for L, 1
for T, -2
There is a relatively easy way to do this if the expression F were a polynomial in MatLab employing the coeffs function. However, my expression is clearly not a polynomial as far as MatLab is concerned.
In the end, I will be working with at least two parameters so I will put them in a cell array since I anticipate cellfun will be useful.
V = L/T
param = {F,V};
The final output should be a table where the rows correspond to each dimension, L M and T and the columns are for each parameter F and V.
syms L M T
F = M*L/T^2
[C,T] = coeffs(expand(log(F),'IgnoreAnalyticConstraints',true))
[exp(T).' C.']
It returns the table:

Boolean expression in linear program

I have to express an AND condition in linear program. The Boolean variable z takes a value 1 if both Boolean variables x and y takes a value 1. Otherwise, z takes a value 0. How do I write it in linear program?
In a pure linear program boolean expressions are not possible.
If you are in an (mixed-)integer program and x,y,z are all binary variables then you can implement the AND by the following.
z >= x+y-1
z <= x
z <= y
Here the first ensures z=1 if x=y=1 and the last two forces z=0 if any of the two is not 1.
As #Erwin Kalvelagen pointed out in the comments this is better relaxed than the formulation using 2z <= x+y.

Evaluating an integral numerically using Matlab

fun= #(x)exp(- a*(d+1).*(t-x)./(d-(t-x)) ) *b.*exp(-b*x);
int= integral(fun,0,t);
Since I did not find a closed form solution, I am using the above code in Matlab to numericaly evaluate the integral.
I am evaluating this integral for different values of d.
The problem is that when I take d<t I get inf. Any idea what is the problem ? and what approach can be used to evaluate the integral in this case ?
Note that a, b, d, and t are all positive. Ex: a=0.1, b=1, t=4.
If you look at the denominator of the first term of fun you see that it depends on t, x and d. So what happens if d == t and x == 0? The denominator goes to 0.0. If d > t there is no positive value for x that will cause the denominator to go to 0.0.
If we let d == t and plot that first term for values of x = 3:.001:5 we see this:
That discontinuity causes the values to be in the range [-Inf, Inf]. Now if we plot exp of these values we see this:

Why do people use hash(k) = c * k with a prime c

Given an integer m, a hash function defined on T is a map T -> {0, 1, 2, ..., m - 1}. If k is an element of T and m is a positive integer, we denote hash(k, m) its hashed value.
For simplicity, most hash functions are of the form hash(k, m) = f(k) % m where f is a map from T to the set of integers.
In the case where m = 2^p (which is often used to the modulo m operation is cheap) and T is a set of integers, I have seen many people using f(k) = c * k with c being a prime number.
I understand if you want to choose a function of the form f(k) = c * k, you need to have gcd(c, m) = 1 for every hash table size m. Even though using a prime number fits the bill, c = 1 is also good.
So my question is the following: why do people still use f(k) = prime * k as their hash function? What kind of nice property does it have?
You don't need it to be prime. One of the most efficient hash functions with provable collision resistance just multiplies with a random number: https://en.wikipedia.org/wiki/Universal_hashing#Avoiding_modular_arithmetic. You do however need it to be odd.

Does f(x) = 2*x + 1 belong to $o(X)$?

Suppose a function f: R -> R defined as
f(x) = mx + c for some m, c > 0 and x in R. Does f(x) belong to o(x)?
If the answer is "NO", can we conclude that o(x) does not properly contain the set of sub-linear functions?
The reason I'm asking this:
It is easy to see that f(x) is sub-linear because
f(x1) + f(x2) = mx1 + c + mx2 + c > m(x1+x2) + c = f(x1+x2).
But lim x-> infinity f(x)/x = 2. In this sense f(x) is not in o(x). But o(x) represents the set of sub linear functions. That's where my confusion comes from.
No, f(x) = 2x + 1 ∉ o(x).
I think your confusion comes from the definition of sublinear. Linear algebra and computer science use two different meanings here:
In linear algebra, sublinear functions are a generalization of linear functions, i.e. every linear function is a sublinear function. As you have shown in the question, your f(x) satisfies the subadditivity criterion.
In computer science, linear and sublinear describe the asymptotic behavior. A sublinear function is a function which grows slower than every linear function, given a large enough input. Thus, no linear function is a sublinear function.
Thus, your f(x) is sublinear w.r.t. linear algebra, but it is not sublinear w.r.t. computer science.