
(FPCore (x y z) :precision binary64 :pre TRUE (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (cos(y))) + (z * (sin(y))) END code
x \cdot \cos y + z \cdot \sin y
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (x * (cos(y))) + (z * (sin(y))) END code
x \cdot \cos y + z \cdot \sin y
(FPCore (x y z) :precision binary64 :pre TRUE (fma z (sin y) (* (cos y) x)))
double code(double x, double y, double z) {
return fma(z, sin(y), (cos(y) * x));
}
function code(x, y, z) return fma(z, sin(y), Float64(cos(y) * x)) end
code[x_, y_, z_] := N[(z * N[Sin[y], $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (z * (sin(y))) + ((cos(y)) * x) END code
\mathsf{fma}\left(z, \sin y, \cos y \cdot x\right)
Initial program 99.8%
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (fma x 1.0 (* (sin y) z))))
(if (<= z -1.5998878487717716e-87)
t_0
(if (<= z 1.3906905842088115e-61) (* x (cos y)) t_0))))double code(double x, double y, double z) {
double t_0 = fma(x, 1.0, (sin(y) * z));
double tmp;
if (z <= -1.5998878487717716e-87) {
tmp = t_0;
} else if (z <= 1.3906905842088115e-61) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(x, 1.0, Float64(sin(y) * z)) tmp = 0.0 if (z <= -1.5998878487717716e-87) tmp = t_0; elseif (z <= 1.3906905842088115e-61) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * 1.0 + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.5998878487717716e-87], t$95$0, If[LessEqual[z, 1.3906905842088115e-61], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((x * (1)) + ((sin(y)) * z)) IN LET tmp_1 = IF (z <= (139069058420881154967487957630223034015355744194129779251587240099952514292987109389899646542932568675618170646032168982972712282179196417877818123690699010641669275401000049896538257598876953125e-255)) THEN (x * (cos(y))) ELSE t_0 ENDIF IN LET tmp = IF (z <= (-159988784877177164685523371169830722870522374072384409119026858684832480050318864005140114871679013601761552483193181404403016128515199488354968070059220853336754264519220820635743157089849151568897638446024723319315030689580225953250192105770111083984375e-341)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, 1, \sin y \cdot z\right)\\
\mathbf{if}\;z \leq -1.5998878487717716 \cdot 10^{-87}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.3906905842088115 \cdot 10^{-61}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if z < -1.5998878487717716e-87 or 1.3906905842088115e-61 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites77.3%
Applied rewrites77.3%
if -1.5998878487717716e-87 < z < 1.3906905842088115e-61Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites61.0%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (cos y))))
(if (<= x -1.2014353339475216e-53)
t_0
(if (<= x 1.3907246641268288e-133) (* z (sin y)) t_0))))double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.2014353339475216e-53) {
tmp = t_0;
} else if (x <= 1.3907246641268288e-133) {
tmp = z * sin(y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (x <= (-1.2014353339475216d-53)) then
tmp = t_0
else if (x <= 1.3907246641268288d-133) then
tmp = z * sin(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (x <= -1.2014353339475216e-53) {
tmp = t_0;
} else if (x <= 1.3907246641268288e-133) {
tmp = z * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -1.2014353339475216e-53: tmp = t_0 elif x <= 1.3907246641268288e-133: tmp = z * math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -1.2014353339475216e-53) tmp = t_0; elseif (x <= 1.3907246641268288e-133) tmp = Float64(z * sin(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -1.2014353339475216e-53) tmp = t_0; elseif (x <= 1.3907246641268288e-133) tmp = z * sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.2014353339475216e-53], t$95$0, If[LessEqual[x, 1.3907246641268288e-133], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (x * (cos(y))) IN LET tmp_1 = IF (x <= (13907246641268287719553288589367698732274009277678938853341083963550402305825730272558285284260707557226592286720658421468340914383077588215032524302117800378662076704866440675793204111827833749549383931163536547600078549247750976353053708772891633938598045310131695191357079148094045872458853184477607279647119117250357415993544663024295005016028881072998046875e-494)) THEN (z * (sin(y))) ELSE t_0 ENDIF IN LET tmp = IF (x <= (-1201435333947521567179383940228922831410793169252770766996959593329040310462231836384689301534482831918011668944531164721304996863097958037513990348088555037975311279296875e-224)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.2014353339475216 \cdot 10^{-53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.3907246641268288 \cdot 10^{-133}:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if x < -1.2014353339475216e-53 or 1.3907246641268288e-133 < x Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites61.0%
if -1.2014353339475216e-53 < x < 1.3907246641268288e-133Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites40.4%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0031420532090521234)
t_0
(if (<= y 2.23898532760956)
(+
x
(*
y
(+ z (* y (fma -0.5 x (* -0.16666666666666666 (* y z)))))))
t_0))))double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0031420532090521234) {
tmp = t_0;
} else if (y <= 2.23898532760956) {
tmp = x + (y * (z + (y * fma(-0.5, x, (-0.16666666666666666 * (y * z))))));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.0031420532090521234) tmp = t_0; elseif (y <= 2.23898532760956) tmp = Float64(x + Float64(y * Float64(z + Float64(y * fma(-0.5, x, Float64(-0.16666666666666666 * Float64(y * z))))))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0031420532090521234], t$95$0, If[LessEqual[y, 2.23898532760956], N[(x + N[(y * N[(z + N[(y * N[(-0.5 * x + N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (x * (cos(y))) IN LET tmp_1 = IF (y <= (2238985327609559927708460236317478120326995849609375e-51)) THEN (x + (y * (z + (y * (((-5e-1) * x) + ((-1666666666666666574148081281236954964697360992431640625e-55) * (y * z))))))) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-314205320905212338866707710849368595518171787261962890625e-59)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0031420532090521234:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.23898532760956:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \mathsf{fma}\left(-0.5, x, -0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -0.0031420532090521234 or 2.2389853276095599 < y Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites61.0%
if -0.0031420532090521234 < y < 2.2389853276095599Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites51.5%
(FPCore (x y z) :precision binary64 :pre TRUE (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (z * y) + x END code
\mathsf{fma}\left(z, y, x\right)
Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites52.7%
Applied rewrites52.7%
(FPCore (x y z) :precision binary64 :pre TRUE (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * (1) END code
x \cdot 1
Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites61.0%
Taylor expanded in y around 0
Applied rewrites39.6%
(FPCore (x y z) :precision binary64 :pre TRUE (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = y * z END code
y \cdot z
Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites52.7%
Taylor expanded in x around 0
Applied rewrites16.5%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))