ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 13 Jan 2024 16:22:36 +0100Unspecified function with some properties and substitutionhttps://ask.sagemath.org/question/75440/unspecified-function-with-some-properties-and-substitution/This is an unformal question.
suppose that I have an undefined function $U()$ such that if $y\geq x$ then $U(y) \geq U(x)$.
I know that $U(16) = .2 U(10)+.8 U(20)$ .
I have to evaluate formaly
$EU_1=0.1 U(10) + 0.4U(16) + 0.5U(20)$
where $EU_1$ is the expected utility of the lotery $l = [(10,0.1),(16,0.4),(20,0.5)]$. So first I want to substitute $U(16)$ in $EU_1$. On my sheet of paper this seems simple, but I do not know if I am able to write all this (with the substitution) in Sage ? Could some one help me.Thu, 11 Jan 2024 16:27:18 +0100https://ask.sagemath.org/question/75440/unspecified-function-with-some-properties-and-substitution/Answer by Max Alekseyev for <p>This is an unformal question.</p>
<p>suppose that I have an undefined function $U()$ such that if $y\geq x$ then $U(y) \geq U(x)$.</p>
<p>I know that $U(16) = .2 U(10)+.8 U(20)$ .</p>
<p>I have to evaluate formaly </p>
<p>$EU_1=0.1 U(10) + 0.4U(16) + 0.5U(20)$ </p>
<p>where $EU_1$ is the expected utility of the lotery $l = [(10,0.1),(16,0.4),(20,0.5)]$. So first I want to substitute $U(16)$ in $EU_1$. On my sheet of paper this seems simple, but I do not know if I am able to write all this (with the substitution) in Sage ? Could some one help me.</p>
https://ask.sagemath.org/question/75440/unspecified-function-with-some-properties-and-substitution/?answer=75442#post-id-75442There are mutiple approaches possible, depending on the type of known relations and expression to evaluate. If they are linear over the values of $U()$ you can employ a linear algebra over the vectors of used $U()$ values. For a given example, we can work with vectors of coefficients of $U(10),U(16),U(20)$, and substitution of $U(16)$ into $EU_1$ can be performed by matrix multiplication:
eu_1 = vector([0.1,0.4,0.5])
eu_2 = Matrix([ [1,0.2,0], [0, 0, 0], [0, 0.8, 1] ]) * eu_1
Here we get `eu_2` equal `(0.180000000000000, 0.000000000000000, 0.820000000000000)` with the coefficient of $U(16)$ (i.e., the second component) nullified.
----
If relations and expressions are (not necessarily linear) polynomials, a possible approach is to represent each used $U()$ value as a polynomial variable, and each known relation as a polynomial over those variables. Then defined a polynomial ring with the lexicographical term order (with variables to be substituted coming first), define an ideal generated by the relations, and perform reduction of a polynomial of interest with respect to this ideal:
K.<u16,u10,u20> = PolynomialRing(RR, order='lex')
J = K.ideal( [u16 - .2*u10 - .8*u20] )
eu_1 = 0.1*u10 + 0.4*u16 + 0.5*u20
eu_2 = eu_1.reduce(J)
Here we get `eu_2` equal `0.180000000000000*u10 + 0.820000000000000*u20`, that is, `u16` got substituted.Thu, 11 Jan 2024 16:50:25 +0100https://ask.sagemath.org/question/75440/unspecified-function-with-some-properties-and-substitution/?answer=75442#post-id-75442Comment by Cyrille for <p>There are mutiple approaches possible, depending on the type of known relations and expression to evaluate. If they are linear over the values of $U()$ you can employ a linear algebra over the vectors of used $U()$ values. For a given example, we can work with vectors of coefficients of $U(10),U(16),U(20)$, and substitution of $U(16)$ into $EU_1$ can be performed by matrix multiplication:</p>
<pre><code>eu_1 = vector([0.1,0.4,0.5])
eu_2 = Matrix([ [1,0.2,0], [0, 0, 0], [0, 0.8, 1] ]) * eu_1
</code></pre>
<p>Here we get <code>eu_2</code> equal <code>(0.180000000000000, 0.000000000000000, 0.820000000000000)</code> with the coefficient of $U(16)$ (i.e., the second component) nullified.</p>
<hr>
<p>If relations and expressions are (not necessarily linear) polynomials, a possible approach is to represent each used $U()$ value as a polynomial variable, and each known relation as a polynomial over those variables. Then defined a polynomial ring with the lexicographical term order (with variables to be substituted coming first), define an ideal generated by the relations, and perform reduction of a polynomial of interest with respect to this ideal:</p>
<pre><code>K.<u16,u10,u20> = PolynomialRing(RR, order='lex')
J = K.ideal( [u16 - .2*u10 - .8*u20] )
eu_1 = 0.1*u10 + 0.4*u16 + 0.5*u20
eu_2 = eu_1.reduce(J)
</code></pre>
<p>Here we get <code>eu_2</code> equal <code>0.180000000000000*u10 + 0.820000000000000*u20</code>, that is, <code>u16</code> got substituted.</p>
https://ask.sagemath.org/question/75440/unspecified-function-with-some-properties-and-substitution/?comment=75466#post-id-75466Thanks MaxSat, 13 Jan 2024 16:22:36 +0100https://ask.sagemath.org/question/75440/unspecified-function-with-some-properties-and-substitution/?comment=75466#post-id-75466