
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.1e+135) (not (<= z 8.5e+67))) (* (cos y) z) (+ (* x (sin y)) (* z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e+135) || !(z <= 8.5e+67)) {
tmp = cos(y) * z;
} else {
tmp = (x * sin(y)) + (z * 1.0);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-2.1d+135)) .or. (.not. (z <= 8.5d+67))) then
tmp = cos(y) * z
else
tmp = (x * sin(y)) + (z * 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e+135) || !(z <= 8.5e+67)) {
tmp = Math.cos(y) * z;
} else {
tmp = (x * Math.sin(y)) + (z * 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.1e+135) or not (z <= 8.5e+67): tmp = math.cos(y) * z else: tmp = (x * math.sin(y)) + (z * 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.1e+135) || !(z <= 8.5e+67)) tmp = Float64(cos(y) * z); else tmp = Float64(Float64(x * sin(y)) + Float64(z * 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.1e+135) || ~((z <= 8.5e+67))) tmp = cos(y) * z; else tmp = (x * sin(y)) + (z * 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.1e+135], N[Not[LessEqual[z, 8.5e+67]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+135} \lor \neg \left(z \leq 8.5 \cdot 10^{+67}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z \cdot 1\\
\end{array}
\end{array}
if z < -2.1000000000000001e135 or 8.50000000000000038e67 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6494.2
Applied rewrites94.2%
if -2.1000000000000001e135 < z < 8.50000000000000038e67Initial program 99.7%
Taylor expanded in y around 0
Applied rewrites87.5%
Final simplification89.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.1e-60) (not (<= z 2.5e-62))) (* (cos y) z) (* (sin y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-60) || !(z <= 2.5e-62)) {
tmp = cos(y) * z;
} else {
tmp = sin(y) * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.1d-60)) .or. (.not. (z <= 2.5d-62))) then
tmp = cos(y) * z
else
tmp = sin(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.1e-60) || !(z <= 2.5e-62)) {
tmp = Math.cos(y) * z;
} else {
tmp = Math.sin(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.1e-60) or not (z <= 2.5e-62): tmp = math.cos(y) * z else: tmp = math.sin(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.1e-60) || !(z <= 2.5e-62)) tmp = Float64(cos(y) * z); else tmp = Float64(sin(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.1e-60) || ~((z <= 2.5e-62))) tmp = cos(y) * z; else tmp = sin(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.1e-60], N[Not[LessEqual[z, 2.5e-62]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{-60} \lor \neg \left(z \leq 2.5 \cdot 10^{-62}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot x\\
\end{array}
\end{array}
if z < -1.0999999999999999e-60 or 2.5000000000000001e-62 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6483.1
Applied rewrites83.1%
if -1.0999999999999999e-60 < z < 2.5000000000000001e-62Initial program 99.7%
lift-+.f64N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f6456.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6456.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6456.7
Applied rewrites56.7%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
lower-sin.f6476.1
Applied rewrites76.1%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -15200.0) (not (<= y 10.2))) (* (cos y) z) (fma (fma (fma -0.16666666666666666 (* y x) (* -0.5 z)) y x) y z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -15200.0) || !(y <= 10.2)) {
tmp = cos(y) * z;
} else {
tmp = fma(fma(fma(-0.16666666666666666, (y * x), (-0.5 * z)), y, x), y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -15200.0) || !(y <= 10.2)) tmp = Float64(cos(y) * z); else tmp = fma(fma(fma(-0.16666666666666666, Float64(y * x), Float64(-0.5 * z)), y, x), y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -15200.0], N[Not[LessEqual[y, 10.2]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * N[(y * x), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -15200 \lor \neg \left(y \leq 10.2\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot x, -0.5 \cdot z\right), y, x\right), y, z\right)\\
\end{array}
\end{array}
if y < -15200 or 10.199999999999999 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6452.6
Applied rewrites52.6%
if -15200 < y < 10.199999999999999Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6496.6
Applied rewrites96.6%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.7
Applied rewrites51.7%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.7
Applied rewrites51.7%
Taylor expanded in x around inf
Applied rewrites13.8%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqr-neg-revN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
*-commutativeN/A
associate-*r*N/A
sqrt-prodN/A
lower-fma.f64N/A
Applied rewrites24.0%
Taylor expanded in y around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
lower-neg.f644.2
Applied rewrites4.2%
herbie shell --seed 2024320
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))