{"id":25059954,"url":"https://github.com/stla/symbolicqspray","last_synced_at":"2025-03-31T11:15:08.778Z","repository":{"id":231791188,"uuid":"782743697","full_name":"stla/symbolicQspray","owner":"stla","description":"Multivariate polynomials whose coefficients are fractions of multivariate polynomials.","archived":false,"fork":false,"pushed_at":"2024-04-13T19:01:25.000Z","size":125,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-14T00:24:36.841Z","etag":null,"topics":["multivariate-polynomials","r","symbolic-computation"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stla.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-04-05T23:37:40.000Z","updated_at":"2024-04-16T13:28:57.575Z","dependencies_parsed_at":"2024-04-16T13:28:54.948Z","dependency_job_id":"f626d5de-5812-462d-9d9f-f82edd93d430","html_url":"https://github.com/stla/symbolicQspray","commit_stats":null,"previous_names":["stla/symbolicqspray"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FsymbolicQspray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FsymbolicQspray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FsymbolicQspray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2FsymbolicQspray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stla","download_url":"https://codeload.github.com/stla/symbolicQspray/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246458010,"owners_count":20780678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["multivariate-polynomials","r","symbolic-computation"],"created_at":"2025-02-06T15:56:01.441Z","updated_at":"2025-03-31T11:15:08.755Z","avatar_url":"https://github.com/stla.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"The 'symbolicQspray' package\"\nauthor: \"Stéphane Laurent\"\ndate: \"`r Sys.Date()`\"\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n***Multivariate polynomials with symbolic parameters.*** \n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/stla/symbolicQspray/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/stla/symbolicQspray/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE, collapse = TRUE, message = FALSE)\n```\n\n___\n\nThese notes about the **symbolicQspray** package assume that the reader is a \nbit familiar with the [**qspray** package][qspray] and with the \n[**ratioOfQsprays** package][ratioOfQsprays].\n\nA `symbolicQspray` object represents a multivariate polynomial whose \ncoefficients are fractions of polynomials with rational coefficients. \nActually (see our discussion in the next section), a `symbolicQspray` object \nrepresents a *multivariate polynomial with parameters*. The parameters are \nthe variables of the fractions of polynomials, and so they are symbolically \nrepresented.\n\nTo construct a `symbolicQspray` polynomial, use `qlone` (from the **qspray** \npackage) to introduce the parameters and use `Qlone` to introduce the variables \nof the polynomial:\n\n```{r}\nlibrary(symbolicQspray)\nf \u003c- function(a1, a2, X1, X2, X3) {\n  (a1/(a2^2+1)) * X1^2*X2  +  (a2+1) * X3  +  a1/a2\n}\n# parameters, the variables occurring in the coefficients:\na1 \u003c- qlone(1)\na2 \u003c- qlone(2)\n# variables:\nX1 \u003c- Qlone(1)\nX2 \u003c- Qlone(2)\nX3 \u003c- Qlone(3)\n# the 'symbolicQspray':\n( Qspray \u003c- f(a1, a2, X1, X2, X3) )\n```\n\nThe fractions of polynomials such as the first coefficient `a1/(a2^2+1)` \nin the above example are [**ratioOfQsprays**][ratioOfQsprays] objects, \nand the numerator and the denominator of a `ratioOfQsprays` are \n[**qspray**][qspray] objects.\n\nArithmetic on `symbolicQspray` objects is available:\n\n```{r}\nQspray^2\nQspray - Qspray\n(Qspray - 1)^2\nQspray^2 - 2*Qspray + 1\n```\n\n\n## Evaluating a `symbolicQspray`\n\nSubstituting the \"exterior\" variables (the variables occurring in the ratios of \npolynomials, also called the *parameters* - see below) yields a `qspray` object:\n\n```{r}\na \u003c- c(2, \"3/2\")\n( qspray \u003c- evalSymbolicQspray(Qspray, a = a) )\n```\n\nSubstituting the \"main\" variables yields a `ratioOfQsprays` object:\n\n```{r}\nX \u003c- c(4, 3, \"2/5\")\n( ratioOfQsprays \u003c- evalSymbolicQspray(Qspray, X = X) )\n```\n\nThere is a discutable point here. A `symbolicQspray` object represents a \npolynomial with `ratioOfQsprays` coefficients. So one could consider \nthat the polynomial variables `X`, `Y` and `Z` represent some indeterminate\n`ratioOfQsprays` fractions, and that it should be possible to replace them \nwith `ratioOfQsprays` objects. However this is not allowed.\nWe will discuss that, just after checking the consistency:\n\n```{r}\nevalSymbolicQspray(Qspray, a = a, X = X)\nevalQspray(qspray, X)\nevalRatioOfQsprays(ratioOfQsprays, a)\na \u003c- gmp::as.bigq(a); X \u003c- gmp::as.bigq(X)\nf(a[1], a[2], X[1], X[2], X[3])\n```\n\nNow let's turn to our promised discussion. Why is replacing the values of the \npolynomial variables with some `ratioOfQsprays` objects not allowed?\n\nActually my motivation to do this package was inspired by the \n[**Jack polynomials**][jack]. In the context of Jack polynomials, the variables \n`X`, `Y` and `Z` represent indeterminate *numbers*, and the coefficients \nare *numbers depending on a parameter* (the Jack parameter), and it turns out \nthat they are fractions of polynomials of this parameter. \nSo I consider that a `symbolicQspray` is *not* a polynomial on the field \nof fractions of polynomials: I consider it is a polynomial with \n*rational coefficients depending on some parameters*. \n\nAlso note that evaluating the `ratioOfQsprays` object \n`evalSymbolicQspray(Qspray, X = X)` at `a` would make no sense if we took \nsome `ratioOfQsprays` objects for the values of `X`.\n\n\n## Querying a `symbolicQspray` \n\nThe package provides some functions to perform elementary queries on a \n`symbolicQspray`:\n\n```{r, collapse=TRUE}\nnumberOfVariables(Qspray)\nnumberOfParameters(Qspray)\nnumberOfTerms(Qspray)\ngetCoefficient(Qspray, c(2, 1)) # coefficient of X^2.Y\ngetConstantTerm(Qspray)\nisUnivariate(Qspray)\nisConstant(Qspray)\n```\n\n\n## Transforming a `symbolicQspray`\n\nYou can differentiate a `symbolicQspray` polynomial:\n\n```{r}\nderivSymbolicQspray(Qspray, 2) # derivative w.r.t. Y\n```\n\nYou can permute its variables:\n\n```{r}\nswapVariables(Qspray, 2, 3) == f(a1, a2, X1, X3, X2)\n```\n\nYou can perform polynomial transformations of its variables:\n\n```{r}\nchangeVariables(Qspray, list(X1+1, X2^2, X1+X2+X3)) == \n  f(a1, a2, X1+1, X2^2, X1+X2+X3)\n```\n\nYou can also perform polynomial transformations of its parameters:\n\n```{r}\nchangeParameters(Qspray, list(a1^2, a2^2)) == f(a1^2, a2^2, X1, X2, X3)\n```\n\n\n## Showing a `symbolicQspray` \n\nYou can change the way a `symbolicQspray` is printed by using \n`showSymbolicQsprayOption`:\n\n```{r, collapse=TRUE}\nshowSymbolicQsprayOption(Qspray, \"a\") \u003c- \"x\"\nshowSymbolicQsprayOption(Qspray, \"showMonomial\") \u003c- \n  showMonomialXYZ(c(\"A\", \"B\", \"C\"))\nshowSymbolicQsprayOption(Qspray, \"quotientBar\") \u003c- \" / \"\nQspray\n```\n\nWhen this is possible, the result of an arithmetic operation between two \n`symbolicQspray` objects inherits the show options of the first operand:\n\n```{r, collapse=TRUE}\nset.seed(421)\n( Q \u003c- rSymbolicQspray() ) # a random symbolicQspray\nQspray + Q\n```\n\nThis behavior is the same as the ones implemented in **qspray** and in \n**ratioOfQsprays**. You should be familiar with these two packages in order \nto use **symbolicQspray**. \n\n\n## Application: Jacobi polynomials\n\nThe [Jacobi polynomials][jacobi] are univariate polynomials depending on two\nparameters that we will denote by `alpha` and `beta`. They are implemented in \nthis package:\n\n```{r}\nJP \u003c- JacobiPolynomial(2)\nisUnivariate(JP)\nnumberOfParameters(JP)\nshowSymbolicQsprayOption(JP, \"showRatioOfQsprays\") \u003c-\n  showRatioOfQspraysXYZ(c(\"alpha\", \"beta\"))\nJP\n```\n\nThe implementation constructs these polynomials by using the \n[recurrence relation][jacobirecurrence].\nThis is a child game, one just has to copy the first two terms and this \nrecurrence relation:\n\n```{r, eval=FALSE}\nJacobiPolynomial \u003c- function(n) {\n  stopifnot(isPositiveInteger(n))\n  if(n == 0) {\n    Qone()\n  } else if(n == 1) {\n    alpha \u003c- qlone(1)\n    beta  \u003c- qlone(2)\n    X     \u003c- Qlone(1)\n    (alpha + 1) + (alpha + beta + 2) * (X - 1)/2\n  } else {\n    alpha \u003c- qlone(1)\n    beta  \u003c- qlone(2)\n    X     \u003c- Qlone(1)\n    a \u003c- n + alpha\n    b \u003c- n + beta\n    c \u003c- a + b\n    K \u003c- 2 * n * (c - n) * (c - 2)\n    lambda1 \u003c- ((c - 1) * (c * (c - 2) * X + (a - b) * (c - 2*n))) / K\n    lambda2 \u003c- (2 * (a - 1) * (b - 1) * c) / K\n    (lambda1 * JacobiPolynomial(n - 1) - lambda2 * JacobiPolynomial(n - 2))\n  }\n}\n```\n\nIt is clearly visible from the recurrence relation that the coefficients of the\nJacobi polynomials are indeed fractions of polynomials in `alpha` and `beta`. \nBut they actually are *polynomials* in `alpha` and `beta`. Actually I don't \nknow, this is a conjecture I made because I observed this fact for some small \nvalues of `n`. We can check it with the function \n`hasPolynomialCoefficientsOnly`:\n\n```{r}\nJP \u003c- JacobiPolynomial(7)\nhasPolynomialCoefficientsOnly(JP)\n```\n\nUp to a factor, the [Gegenbauer polynomials][gegenbauer] with parameter `alpha`\ncoincide with the Jacobi polynomials with parameters `alpha - 1/2` and \n`alpha - 1/2`. Let's derive them from the Jacobi polynomials, as an exercise. \nThe factor can be implemented as follows (see Wikipedia for its formula):\n\n```{r}\nrisingFactorial \u003c- function(theta, n) {\n  toMultiply \u003c- c(theta, lapply(seq_len(n-1), function(i) theta + i))\n  Reduce(`*`, toMultiply)\n}\ntheFactor \u003c- function(alpha, n) {\n  risingFactorial(2*alpha, n) / risingFactorial((2*alpha + 1)/2, n)\n}\n```\n\nNow let's apply the formula given in the Wikipedia article:\n\n```{r}\nGegenbauerPolynomial \u003c- function(n) {\n  alpha \u003c- qlone(1)\n  P \u003c- changeParameters(\n    JacobiPolynomial(n), list(alpha - \"1/2\", alpha - \"1/2\")\n  )\n  theFactor(alpha, n) * P\n}\n```\n\nLet's check that the recurrence relation given in the Wikipedia article is\nfulfilled:\n\n```{r}\nn \u003c- 5\nalpha \u003c- qlone(1)\nX \u003c- Qlone(1)\n(n + 1) * GegenbauerPolynomial(n+1) == \n  2*(n + alpha) * X * GegenbauerPolynomial(n) - \n    (n + 2*alpha - 1) * GegenbauerPolynomial(n-1)\n```\n\n\n## Application to Jack polynomials\n\nThe **symbolicQspray** package is used in the [**jack** package][jack] to \ncompute the Jack polynomials with a symbolic Jack parameter. The Jack \npolynomials exactly fit to the polynomials represented by the `symbolicQspray`\nobjects: their coefficients are fractions of polynomials by definition, of one\nvariable: the Jack parameter.\n\n\n\u003c!-- -------------------- links -------------------- --\u003e\n\n[qspray]: https://github.com/stla/qspray \"the 'qspray' package on Github\"\n\n[ratioOfQsprays]: https://github.com/stla/ratioOfQsprays \"the 'ratioOfQsprays' package on Github\"\n\n[jack]: https://github.com/stla/jackR \"the 'jack' package on Github\"\n\n[gegenbauer]: https://en.wikipedia.org/wiki/Gegenbauer_polynomials \"Gegenbauer polynomials on Wikipedia\"\n\n[jacobi]: https://en.wikipedia.org/wiki/Jacobi_polynomials \"Jacobi polynomials on Wikipedia\"\n\n[jacobirecurrence]: https://en.wikipedia.org/wiki/Jacobi_polynomials#Recurrence_relations \"recurrence relation between Jacobi polynomials\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fsymbolicqspray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstla%2Fsymbolicqspray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fsymbolicqspray/lists"}