case

Coq case analysis and rewrite with function returning subset types

混江龙づ霸主 提交于 2020-01-02 07:14:04
问题 I was working is this simple exercise about writing certified function using subset types. The idea is to first write a predecessor function pred : forall (n : {n : nat | n > 0}), {m : nat | S m = n.1}. and then using this definition give a funtion pred2 : forall (n : {n : nat | n > 1}), {m : nat | S (S m) = n.1}. I have no problem with the first one. Here is my code Program Definition pred (n : {n : nat | n > 0}) : {m : nat | S m = n.1} := match n with | O => _ | S n' => n' end. Next

Coq case analysis and rewrite with function returning subset types

こ雲淡風輕ζ 提交于 2020-01-02 07:13:24
问题 I was working is this simple exercise about writing certified function using subset types. The idea is to first write a predecessor function pred : forall (n : {n : nat | n > 0}), {m : nat | S m = n.1}. and then using this definition give a funtion pred2 : forall (n : {n : nat | n > 1}), {m : nat | S (S m) = n.1}. I have no problem with the first one. Here is my code Program Definition pred (n : {n : nat | n > 0}) : {m : nat | S m = n.1} := match n with | O => _ | S n' => n' end. Next

Postgres nested if in case query

一个人想着一个人 提交于 2020-01-01 05:24:12
问题 Could you tell my why the following isnt working in postgres sql?: See updated code below UPDATE: I expect the query to return "0.30" as float. This construct is only for testing purposes, i have some complex querys which depend on this conditional structure... BUt i dont know how to fix it.. Result is: ERROR: syntax error at or near "1" LINE 4: if 1=1 then UPDATE: This construction appears in a function... so I want to do following: CREATE FUNCTION f_test(myvalue integer) RETURNS float AS $$

Using tsql greater than sign in CASE Expression

北战南征 提交于 2019-12-30 17:24:07
问题 (case [dbo].[YearsInService]([DateEngaged],getdate()) when (0) then (0) when (1) then (4) when (2) then (8) when (3) then (12) when (4) then (32) when (5) then (40) when (6) then (48) when (7) then (56) when (8) then (104) when (9) then (117) when (10) then (150) else (-1) end) Now in my the last line, how can i say that 10 and above should be returned as 150? 回答1: You can't, the CASE YourFunction WHEN ... is for equalities only. If you need to use "greater than", you'll need to rewrite your

multiple CASE statements on interval within nested functions

白昼怎懂夜的黑 提交于 2019-12-30 11:03:51
问题 Although I have come up with a work-around using multiple if / else if statements, I am curious in knowing what looks wrong with my case statements, illustrated below: function [ar_vo,bucket] = revEng(v) ... s=solve(solve>0) * sqrt(T); ar_vo=s; bucket=ri(ar_vo); %%%%%%%%%%%%%%%%%%%%% function bucket = ri(ar_vo) % switch(ar_vo) % case ((ar_vo >= 0)&&(ar_vo < 0.005)) (1) % bucket=1; % case ((ar_vo >= 0.005)&&(ar_vo < 0.02)) (2) % bucket=2; % case ((ar_vo >= 0.02)&&(ar_vo < 0.05)) (3) % bucket=3

Mysql Storing a variable with the result of an SELECT CASE

て烟熏妆下的殇ゞ 提交于 2019-12-30 10:52:33
问题 im learning how to use the SELECT CASE but i don't understand very well, here is the code: SET @vgls=1; SET @lgls=1; SET @st=SELECT CASE WHEN @vgls=@lgls THEN "emp" WHEN @vgls>@lgls THEN "loc" WHEN @vgls<@lgls THEN "vis" END; SELECT @st; It gives me the following error: [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to you MySQL server version for the right syntax to use near 'SELECT CASE WHEN @vgls=@lgls THEN "emp" WHEN @vgls>@lgls THEN "loc" WHEN @vg'

Using string representations of enum values in switch-case

夙愿已清 提交于 2019-12-30 03:58:06
问题 Why is it not possible to use enum values as strings in a switch case? (Or what is wrong with this:) String argument; switch (argument) { case MyEnum.VALUE1.toString(): // Isn't this equal to "VALUE1" ? // something break; case MyEnum.VALUE2.toString(): // something else break; 回答1: You can only use strings which are known at compile time. The compiler cannot determine the result of that expression. Perhaps you can try String argument = ... switch(MyEnum.valueOf(argument)) { case VALUE1: case

Alias Column name in mutiple case statement

久未见 提交于 2019-12-29 09:58:18
问题 I am trying to retrieve a value for a alias column using case statement. CASE WHEN FieldA = 'TestA' THEN FieldA1 WHEN FieldB = 'TestB' THEN FieldB1 ELSE NULL END AS Alias1 But when I try to use this alias to retrievce value for another alias , I am getting an error CASE WHEN Alias1 = FieldA1 THEN FieldA0 WHEN Alias1 = FieldB1 THEN FieldA1 ELSE NULL END AS Alias2 Error message I get is : Can you suggest a way to get rid of the error or any alternative approach which fulfills my requirements

final variable case in switch statement

廉价感情. 提交于 2019-12-29 05:46:31
问题 final int a = 1; final int b; b = 2; final int x = 0; switch (x) { case a:break; // ok case b:break; // compiler error: Constant expression required } /* COMPILER RESULT: constant expression required case b:break; ^ 1 error */ Why am I getting this sort of error? If I would have done final int b = 2 , everything works. 回答1: b may not have been initialized and it is possible to be assigned multiple values. In your example it is obviously initialized, but probably the compiler doesn't get to

Can you GROUP BY with a CASE WHEN THEN alias name?

青春壹個敷衍的年華 提交于 2019-12-28 06:27:27
问题 I have a SELECT statement being calculated from a CASE WHEN THEN state (or could use multiple IF statements) aliased as 'Length', and I need to correctly GROUP the results together. The SELECT seems to be working, but the group groups them wrong. Here is my statement: SELECT CASE WHEN DATEDIFF(o.EndDate, o.StartDate) < 30 THEN '<1 Month' WHEN DATEDIFF(o.EndDate, o.StartDate) < 90 THEN '1 - 2 Months' WHEN DATEDIFF(o.EndDate, o.StartDate) < 210 THEN '3 - 4 Months' ELSE '>4 Months' END AS