when I try to solve this inequality x^3 + 3*x > 3 I get this output:
octave:5> eqn = x^3 + 3*x > 3
eqn = (sym)
3
x + 3⋅x > 3
octave:6> solve(eqn, x)
ans = (sym)
⎛ 3 ⎞
x < ∞ ∧ CRootOf⎝x + 3⋅x - 3, 0⎠ < x
But when I try to solve simpler inequality everything works fine:
eqn = abs(x^2-3)>3
eqn = (sym)
│ 2 │
│x - 3│ > 3
octave:4> solve(eqn, x)
ans = (sym) (-∞ < x ∧ x < -√6) ∨ (√6 < x ∧ x < ∞)
What can I do with this CRoot?
Related
When I was learning diceloss, I didn't understand how to write this code:
tp = torch.sum(temp_target[...,:-1] * temp_inputs, axis=[0,1])
What does temp_target[...,:-1] mean?
The code for the entire diceloss calculation is as follows:
def Dice_loss(inputs, target, beta=1, smooth = 1e-5):
n, c, h, w = inputs.size()
nt, ht, wt, ct = target.size()
temp_inputs = torch.softmax(inputs.transpose(1, 2).transpose(2, 3).contiguous().view(n, -1, c),-1)
temp_target = target.view(n, -1, ct)
tp = torch.sum(temp_target[...,:-1] * temp_inputs, axis=[0,1])
fp = torch.sum(temp_inputs , axis=[0,1]) - tp
fn = torch.sum(temp_target[...,:-1] , axis=[0,1]) - tp
score = ((1 + beta ** 2) * tp + smooth) / ((1 + beta ** 2) * tp + beta ** 2 * fn + fp + smooth)
dice_loss = 1 - torch.mean(score)
return dice_loss
I can not get main to print anything besides the variables are equal to zero which means my greedy1 function is not passing my variable and I do not know what is wrong.
def greedy1(total):
if (total >= 25):
q = total // 25
remainderCentsQ = total % 25
d = remainderCentsQ // 10
remainderCentsD = total % 10
n = remainderCentsD // 5
remainderCentsN = total % 5
p = remainderCentsN // 1
return (q, d, n, p)
elif (total >= 10):
q = 0
d = total // 10
remainderCentsD = total % 10
n = remainderCentsD // 5
remainderCentsN = total % 5
p = remainderCentsN // 1
return (q, d, n, p)
elif (total >= 5):
q = 0
d = 0
n = total // 5
remainderCentsN = total % 5
p = remainderCentsN // 1
return (q, d, n, p)
else:
q = 0
d = 0
n = 0
p = total // 1
return (q, d, n, p)
def printCoins1(total, q, d, n, p):
print("For " + str(total) + " cents change, I give\n" + str(q) + " quarters\n" + str(d) + " dimes\n" + str(n) + " nickels\n" + str(p) + " pennies")
def main():
total = int(input("How many cents change? "))
q = 0
d = 0
n = 0
p = 0
greedy1(total)
printCoins1(total, q, d, n, p)
main()
Inside your main function, you're calling greedy1 function with total that returns the tuple. But you're not storing this return values back to your variables q, d, n, p.
your main() should look like this:
def main():
total = int(input("How many cents change? "))
(q, d, n, p) = greedy1(total)
printCoins1(total, q, d, n, p)
#Sayas has given the correct answer however there is some redundant code , so I will improve it in my answer
def main():
total = int(input("How many cents change? "))
printCoins1(total, *greedy1(total))
This question already has answers here:
T(n) = T(n/10) + T(an) + n, how to solve this?
(3 answers)
Closed 2 years ago.
Given: T(n) = T(n/10) + T(an) + n for some a (which I know nothing about its value), and that: T(n) = 1 if n < 10.
I want to check if the following is possible (for some a values, and I want to find the smallest possible a):
For every c > 0 there is n0 > 0 such that for every n > n0, T(n) >= c * n Or in other words T(n)=omega(n)
Any help is appreciated.
Suppose that a < 9/10. Let c = max(1/(9/10 - a), 1), so that c ≥ 1 and 1/c ≤ 9/10 - a. Then for 1 ≤ n < 10,
T(n) = 1 ≤ n ≤ cn.
Inductively, for n ≥ 10,
T(n)
= T(n/10) + T(an) + n
≤ cn/10 + can + n
= c(1/10 + a + 1/c)n
≤ c(1/10 + a + 9/10 - a)n
= cn.
Now suppose that a = 9/10. For 1 ≤ n < 10, we know log10 n < 1 and therefore
T(n) = 1 > n log10 n - n.
Inductively, for n ≥ 10,
T(n)
= T(n/10) + T(9n/10) + n
> (n/10) log10 (n/10) - (n/10) + (9n/10) log10 (9n/10) - (9n/10) + n
= (n/10) log10 (n/10) + (9n/10) log10 (9n/10)
> (n/10) log10 (n/10) + (9n/10) log10 ( n/10)
= (n/10) (log10 n - 1) + (9n/10) (log10 n - 1)
= n log10 n - n.
Given c > 0, pick n0 such that log10 n0 - 1 = c, i.e., n0 = exp10(c + 1). Then for all n > n0,
T(n) > n log10 n - n = n(log10 n - 1) > n(log10 n0 - 1) = cn.
For every c > 0 there is n0 > 0 such that for every n > n0, T(n) >= c*n
We assume T(n) >= cn holds for some a and every c > 0.
By substituting the recurrence in the inequality and solving for a, you will get:
T(n) >= c*n
(c*n/10) + (c*a*n) + n >= c*n
a >= (9/10) - (1/c)
Since our desired outcome is to hold for all c (formally apply limit c tends to infinity, which is where RHS will maximize), we get a >= (9/10). Therefore, smallest value of a is (9/10) which will satisfy T(n) >= c*n for all c.
After this, you can prove by induction, that this is indeed the case.
In each function, you need to find the highest impacting variable of the equation. On the big scale, the smallest possible N affecting this function is any Constant.
I have the following Haskell code, a function that checks how many digits are the same in a number and based on how many of them were the same takes a value. I keep getting the error:
Instances of (Ord (Int -> Int -> Int), Num (Int -> Int -> Int)) required for definition of digits
digits :: Int->Int->Int
digits x y
|(equal < 2) = 0
|(equal == 2) = 1
|(equal == 3) = 5
|(equal == 4) = 20
|(equal == 5) = 300
|(equal == 6) = 8000
|(equal == 7) = 10000
|otherwise = 100000
where
equal :: Int -> Int -> Int
equal 0 0 = 0
equal a b
|(a `mod` 10 == b `mod` 10) = 1 + equal (a `div` 10) (b `div` 10)
|otherwise = 1 + equal (a `div` 10) (b `div` 10)
What am I doing wrong? Also what does the error mean exactly?
EDIT: Did it like this and it works like a charm!
digits :: Int->Int->Int
digits x y
|(c < 2) = 0
|(c == 2) = 1
|(c == 3) = 5
|(c == 4) = 20
|(c == 5) = 300
|(c == 6) = 8000
|(c == 7) = 10000
|otherwise = 100000
where c = equal x y
where
equal :: Int -> Int -> Int
equal 0 0 = 0
equal a b
|(a `mod` 10 == b `mod` 10) = 1 + equal (a `div` 10) (b `div` 10)
|otherwise = 0 + equal (a `div` 10) (b `div` 10)
I am trying to write a formula in Excel VBA to calculate: RR = ((A / (A + B)) / (C / (C + D)))
When any of the four arguments (A, B, C, D) are 0, I want to change their value to 0.5 in the calculation.
Is there an easy way of doing this? I believe my formatting is wrong or I'm going about it the wrong way. Any helpful tips would be greatly appreciated.
I've tried:
Function RR(A, B, C, D) As Double
If A = 0 And B = 0 Then
A = 0.5
B = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf A = 0 Then
A = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf B = 0 Then
B = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf C = 0 Then
C = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf D = 0 Then
D = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf A = 0 And D = 0 Then
A = 0.5 And D = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
Else: RR = ((A / (A + B)) / (C / (C + D)))
End If
End Function
Try this one:
Function RR(A, B, C, D) As Double
If A = 0 Then A = 0.5
If B = 0 Then B = 0.5
If C = 0 Then C = 0.5
If D = 0 Then D = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
End Function