
(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 8 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 (sin y) x (* z (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), x, (z * cos(y)));
}
function code(x, y, z) return fma(sin(y), x, Float64(z * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -7.8e+18)
t_0
(if (<= z 7.8e+82) (+ (* 1.0 z) (* x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -7.8e+18) {
tmp = t_0;
} else if (z <= 7.8e+82) {
tmp = (1.0 * z) + (x * sin(y));
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (z <= (-7.8d+18)) then
tmp = t_0
else if (z <= 7.8d+82) then
tmp = (1.0d0 * z) + (x * 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 = z * Math.cos(y);
double tmp;
if (z <= -7.8e+18) {
tmp = t_0;
} else if (z <= 7.8e+82) {
tmp = (1.0 * z) + (x * Math.sin(y));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -7.8e+18: tmp = t_0 elif z <= 7.8e+82: tmp = (1.0 * z) + (x * math.sin(y)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -7.8e+18) tmp = t_0; elseif (z <= 7.8e+82) tmp = Float64(Float64(1.0 * z) + Float64(x * sin(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -7.8e+18) tmp = t_0; elseif (z <= 7.8e+82) tmp = (1.0 * z) + (x * sin(y)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.8e+18], t$95$0, If[LessEqual[z, 7.8e+82], N[(N[(1.0 * z), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+82}:\\
\;\;\;\;1 \cdot z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.8e18 or 7.79999999999999951e82 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6486.5
Applied rewrites86.5%
if -7.8e18 < z < 7.79999999999999951e82Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites91.0%
Final simplification89.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -1.35e+171)
t_0
(if (<= y -0.84)
(* z (cos y))
(if (<= y 1.45e-11)
(fma (* (fma -0.16666666666666666 (* y y) 1.0) x) y z)
t_0)))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -1.35e+171) {
tmp = t_0;
} else if (y <= -0.84) {
tmp = z * cos(y);
} else if (y <= 1.45e-11) {
tmp = fma((fma(-0.16666666666666666, (y * y), 1.0) * x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -1.35e+171) tmp = t_0; elseif (y <= -0.84) tmp = Float64(z * cos(y)); elseif (y <= 1.45e-11) tmp = fma(Float64(fma(-0.16666666666666666, Float64(y * y), 1.0) * x), y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -1.35e+171], t$95$0, If[LessEqual[y, -0.84], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.45e-11], N[(N[(N[(-0.16666666666666666 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -1.35 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.84:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot y, 1\right) \cdot x, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.3499999999999999e171 or 1.45e-11 < y Initial program 99.6%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.6
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-/.f64N/A
lower-sin.f6491.7
Applied rewrites91.7%
Taylor expanded in x around inf
Applied rewrites63.3%
if -1.3499999999999999e171 < y < -0.839999999999999969Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6461.1
Applied rewrites61.1%
if -0.839999999999999969 < y < 1.45e-11Initial program 100.0%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
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
lower-*.f64N/A
lower-*.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
Applied rewrites99.0%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -7.8e+18) t_0 (if (<= z 7.8e+82) (fma (sin y) x (* 1.0 z)) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -7.8e+18) {
tmp = t_0;
} else if (z <= 7.8e+82) {
tmp = fma(sin(y), x, (1.0 * z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -7.8e+18) tmp = t_0; elseif (z <= 7.8e+82) tmp = fma(sin(y), x, Float64(1.0 * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.8e+18], t$95$0, If[LessEqual[z, 7.8e+82], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.8e18 or 7.79999999999999951e82 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6486.5
Applied rewrites86.5%
if -7.8e18 < z < 7.79999999999999951e82Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites91.0%
Final simplification89.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.84)
t_0
(if (<= y 4.7e+14)
(fma (* (fma -0.16666666666666666 (* y y) 1.0) x) y z)
t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.84) {
tmp = t_0;
} else if (y <= 4.7e+14) {
tmp = fma((fma(-0.16666666666666666, (y * y), 1.0) * x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -0.84) tmp = t_0; elseif (y <= 4.7e+14) tmp = fma(Float64(fma(-0.16666666666666666, Float64(y * y), 1.0) * x), y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.84], t$95$0, If[LessEqual[y, 4.7e+14], N[(N[(N[(-0.16666666666666666 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -0.84:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot y, 1\right) \cdot x, y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.839999999999999969 or 4.7e14 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6445.3
Applied rewrites45.3%
if -0.839999999999999969 < y < 4.7e14Initial program 100.0%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
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
lower-*.f64N/A
lower-*.f6498.3
Applied rewrites98.3%
Taylor expanded in x around inf
Applied rewrites98.3%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e+184) (* x y) (if (<= x 2.6e+215) (* 1.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+184) {
tmp = x * y;
} else if (x <= 2.6e+215) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
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 (x <= (-1.95d+184)) then
tmp = x * y
else if (x <= 2.6d+215) then
tmp = 1.0d0 * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e+184) {
tmp = x * y;
} else if (x <= 2.6e+215) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e+184: tmp = x * y elif x <= 2.6e+215: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e+184) tmp = Float64(x * y); elseif (x <= 2.6e+215) tmp = Float64(1.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e+184) tmp = x * y; elseif (x <= 2.6e+215) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e+184], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.6e+215], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+184}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{+215}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.94999999999999985e184 or 2.6e215 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6460.1
Applied rewrites60.1%
Taylor expanded in x around inf
Applied rewrites42.0%
if -1.94999999999999985e184 < x < 2.6e215Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6467.1
Applied rewrites67.1%
Taylor expanded in y around 0
Applied rewrites45.4%
(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.f6453.7
Applied rewrites53.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.f6453.7
Applied rewrites53.7%
Taylor expanded in x around inf
Applied rewrites16.1%
herbie shell --seed 2024332
(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))))