
(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 9 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 x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.3e+150) (not (<= z 2.35e+27))) (* z (cos y)) (fma x (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e+150) || !(z <= 2.35e+27)) {
tmp = z * cos(y);
} else {
tmp = fma(x, sin(y), z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e+150) || !(z <= 2.35e+27)) tmp = Float64(z * cos(y)); else tmp = fma(x, sin(y), z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e+150], N[Not[LessEqual[z, 2.35e+27]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+150} \lor \neg \left(z \leq 2.35 \cdot 10^{+27}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\end{array}
\end{array}
if z < -2.30000000000000001e150 or 2.34999999999999988e27 < z Initial program 99.8%
add-cube-cbrt99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 89.2%
if -2.30000000000000001e150 < z < 2.34999999999999988e27Initial program 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 86.9%
Final simplification87.8%
(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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -3e+56)
t_0
(if (<= y -0.019)
t_1
(if (<= y 0.215)
(+ (* -0.5 (* y (* y z))) (+ z (* x y)))
(if (<= y 3.6e+33) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -3e+56) {
tmp = t_0;
} else if (y <= -0.019) {
tmp = t_1;
} else if (y <= 0.215) {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
} else if (y <= 3.6e+33) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = z * cos(y)
t_1 = x * sin(y)
if (y <= (-3d+56)) then
tmp = t_0
else if (y <= (-0.019d0)) then
tmp = t_1
else if (y <= 0.215d0) then
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
else if (y <= 3.6d+33) then
tmp = t_1
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 t_1 = x * Math.sin(y);
double tmp;
if (y <= -3e+56) {
tmp = t_0;
} else if (y <= -0.019) {
tmp = t_1;
} else if (y <= 0.215) {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
} else if (y <= 3.6e+33) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = x * math.sin(y) tmp = 0 if y <= -3e+56: tmp = t_0 elif y <= -0.019: tmp = t_1 elif y <= 0.215: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) elif y <= 3.6e+33: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -3e+56) tmp = t_0; elseif (y <= -0.019) tmp = t_1; elseif (y <= 0.215) tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); elseif (y <= 3.6e+33) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = x * sin(y); tmp = 0.0; if (y <= -3e+56) tmp = t_0; elseif (y <= -0.019) tmp = t_1; elseif (y <= 0.215) tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); elseif (y <= 3.6e+33) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3e+56], t$95$0, If[LessEqual[y, -0.019], t$95$1, If[LessEqual[y, 0.215], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6e+33], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -3 \cdot 10^{+56}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.019:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 0.215:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{+33}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.00000000000000006e56 or 3.6000000000000003e33 < y Initial program 99.6%
add-cube-cbrt99.0%
fma-def99.0%
pow299.0%
Applied egg-rr99.0%
Taylor expanded in x around 0 67.3%
if -3.00000000000000006e56 < y < -0.0189999999999999995 or 0.214999999999999997 < y < 3.6000000000000003e33Initial program 99.6%
add-cube-cbrt98.4%
fma-def98.4%
pow298.4%
Applied egg-rr98.4%
Taylor expanded in z around 0 76.9%
pow-base-176.9%
associate-*r*76.9%
*-lft-identity76.9%
Simplified76.9%
if -0.0189999999999999995 < y < 0.214999999999999997Initial program 100.0%
Taylor expanded in y around 0 99.5%
expm1-log1p-u93.4%
expm1-udef93.4%
unpow293.4%
associate-*l*93.4%
Applied egg-rr93.4%
expm1-def93.4%
expm1-log1p99.5%
Simplified99.5%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.7e+150) (not (<= z 2.15e+27))) (* z (cos y)) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+150) || !(z <= 2.15e+27)) {
tmp = z * cos(y);
} else {
tmp = z + (x * sin(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 ((z <= (-3.7d+150)) .or. (.not. (z <= 2.15d+27))) then
tmp = z * cos(y)
else
tmp = z + (x * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+150) || !(z <= 2.15e+27)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.7e+150) or not (z <= 2.15e+27): tmp = z * math.cos(y) else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.7e+150) || !(z <= 2.15e+27)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.7e+150) || ~((z <= 2.15e+27))) tmp = z * cos(y); else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.7e+150], N[Not[LessEqual[z, 2.15e+27]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+150} \lor \neg \left(z \leq 2.15 \cdot 10^{+27}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -3.69999999999999987e150 or 2.15000000000000004e27 < z Initial program 99.8%
add-cube-cbrt99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 89.2%
if -3.69999999999999987e150 < z < 2.15000000000000004e27Initial program 99.8%
Taylor expanded in y around 0 86.9%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -23000000000.0) (not (<= y 0.014))) (* z (cos y)) (+ (* -0.5 (* y (* y z))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -23000000000.0) || !(y <= 0.014)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (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 ((y <= (-23000000000.0d0)) .or. (.not. (y <= 0.014d0))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -23000000000.0) || !(y <= 0.014)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -23000000000.0) or not (y <= 0.014): tmp = z * math.cos(y) else: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -23000000000.0) || !(y <= 0.014)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -23000000000.0) || ~((y <= 0.014))) tmp = z * cos(y); else tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -23000000000.0], N[Not[LessEqual[y, 0.014]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -23000000000 \lor \neg \left(y \leq 0.014\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -2.3e10 or 0.0140000000000000003 < y Initial program 99.6%
add-cube-cbrt98.9%
fma-def98.9%
pow298.9%
Applied egg-rr98.9%
Taylor expanded in x around 0 61.8%
if -2.3e10 < y < 0.0140000000000000003Initial program 100.0%
Taylor expanded in y around 0 98.0%
expm1-log1p-u92.2%
expm1-udef92.2%
unpow292.2%
associate-*l*92.2%
Applied egg-rr92.2%
expm1-def92.2%
expm1-log1p98.0%
Simplified98.0%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (<= x -1e+154) (* x y) (if (<= x 1.9e+88) z (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e+154) {
tmp = x * y;
} else if (x <= 1.9e+88) {
tmp = 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 <= (-1d+154)) then
tmp = x * y
else if (x <= 1.9d+88) then
tmp = 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 <= -1e+154) {
tmp = x * y;
} else if (x <= 1.9e+88) {
tmp = z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e+154: tmp = x * y elif x <= 1.9e+88: tmp = z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e+154) tmp = Float64(x * y); elseif (x <= 1.9e+88) tmp = z; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1e+154) tmp = x * y; elseif (x <= 1.9e+88) tmp = z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e+154], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.9e+88], z, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+154}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+88}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.00000000000000004e154 or 1.8999999999999998e88 < x Initial program 99.8%
Taylor expanded in y around 0 59.6%
Taylor expanded in y around inf 44.2%
if -1.00000000000000004e154 < x < 1.8999999999999998e88Initial program 99.8%
add-cube-cbrt99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 46.4%
Final simplification45.7%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (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 = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 55.7%
Final simplification55.7%
(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 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%
add-cube-cbrt99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 37.2%
Final simplification37.2%
herbie shell --seed 2023200
(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))))