
(FPCore (x y z) :precision binary64 (+ (* 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)
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]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* 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)
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]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * 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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -5.8e+154)
t_0
(if (<= y -0.14)
t_1
(if (<= y -5.8e-5)
t_0
(if (<= y 0.000155) (+ x (* y z)) (if (<= y 2.8e+20) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -5.8e+154) {
tmp = t_0;
} else if (y <= -0.14) {
tmp = t_1;
} else if (y <= -5.8e-5) {
tmp = t_0;
} else if (y <= 0.000155) {
tmp = x + (y * z);
} else if (y <= 2.8e+20) {
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 * sin(y)
t_1 = x * cos(y)
if (y <= (-5.8d+154)) then
tmp = t_0
else if (y <= (-0.14d0)) then
tmp = t_1
else if (y <= (-5.8d-5)) then
tmp = t_0
else if (y <= 0.000155d0) then
tmp = x + (y * z)
else if (y <= 2.8d+20) 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.sin(y);
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -5.8e+154) {
tmp = t_0;
} else if (y <= -0.14) {
tmp = t_1;
} else if (y <= -5.8e-5) {
tmp = t_0;
} else if (y <= 0.000155) {
tmp = x + (y * z);
} else if (y <= 2.8e+20) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -5.8e+154: tmp = t_0 elif y <= -0.14: tmp = t_1 elif y <= -5.8e-5: tmp = t_0 elif y <= 0.000155: tmp = x + (y * z) elif y <= 2.8e+20: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -5.8e+154) tmp = t_0; elseif (y <= -0.14) tmp = t_1; elseif (y <= -5.8e-5) tmp = t_0; elseif (y <= 0.000155) tmp = Float64(x + Float64(y * z)); elseif (y <= 2.8e+20) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -5.8e+154) tmp = t_0; elseif (y <= -0.14) tmp = t_1; elseif (y <= -5.8e-5) tmp = t_0; elseif (y <= 0.000155) tmp = x + (y * z); elseif (y <= 2.8e+20) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.8e+154], t$95$0, If[LessEqual[y, -0.14], t$95$1, If[LessEqual[y, -5.8e-5], t$95$0, If[LessEqual[y, 0.000155], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.8e+20], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -5.8 \cdot 10^{+154}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.14:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.000155:\\
\;\;\;\;x + y \cdot z\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+20}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -5.79999999999999959e154 or -0.14000000000000001 < y < -5.8e-5 or 2.8e20 < y Initial program 99.6%
Taylor expanded in x around 0 64.9%
if -5.79999999999999959e154 < y < -0.14000000000000001 or 1.55e-4 < y < 2.8e20Initial program 99.8%
+-commutative99.8%
add-cube-cbrt99.4%
associate-*r*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in z around 0 68.2%
if -5.8e-5 < y < 1.55e-4Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification84.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -9.5e+153)
t_0
(if (<= y -130.0)
t_1
(if (<= y -5.5e-5)
t_0
(if (<= y 0.0155) (fma y z x) (if (<= y 1.8e+21) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -9.5e+153) {
tmp = t_0;
} else if (y <= -130.0) {
tmp = t_1;
} else if (y <= -5.5e-5) {
tmp = t_0;
} else if (y <= 0.0155) {
tmp = fma(y, z, x);
} else if (y <= 1.8e+21) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -9.5e+153) tmp = t_0; elseif (y <= -130.0) tmp = t_1; elseif (y <= -5.5e-5) tmp = t_0; elseif (y <= 0.0155) tmp = fma(y, z, x); elseif (y <= 1.8e+21) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.5e+153], t$95$0, If[LessEqual[y, -130.0], t$95$1, If[LessEqual[y, -5.5e-5], t$95$0, If[LessEqual[y, 0.0155], N[(y * z + x), $MachinePrecision], If[LessEqual[y, 1.8e+21], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+153}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -130:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.0155:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+21}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -9.4999999999999995e153 or -130 < y < -5.5000000000000002e-5 or 1.8e21 < y Initial program 99.6%
Taylor expanded in x around 0 64.9%
if -9.4999999999999995e153 < y < -130 or 0.0155 < y < 1.8e21Initial program 99.8%
+-commutative99.8%
add-cube-cbrt99.4%
associate-*r*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in z around 0 68.2%
if -5.5000000000000002e-5 < y < 0.0155Initial program 100.0%
Taylor expanded in y around 0 100.0%
fma-def100.0%
Simplified100.0%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.2e-31) (not (<= z 2.1e-129))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.2e-31) || !(z <= 2.1e-129)) {
tmp = x + (z * sin(y));
} else {
tmp = x * cos(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 <= (-1.2d-31)) .or. (.not. (z <= 2.1d-129))) then
tmp = x + (z * sin(y))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.2e-31) || !(z <= 2.1e-129)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.2e-31) or not (z <= 2.1e-129): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.2e-31) || !(z <= 2.1e-129)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.2e-31) || ~((z <= 2.1e-129))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.2e-31], N[Not[LessEqual[z, 2.1e-129]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-31} \lor \neg \left(z \leq 2.1 \cdot 10^{-129}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.2e-31 or 2.1e-129 < z Initial program 99.8%
Taylor expanded in y around 0 89.7%
if -1.2e-31 < z < 2.1e-129Initial program 99.9%
+-commutative99.9%
add-cube-cbrt99.7%
associate-*r*99.7%
fma-def99.7%
pow299.7%
Applied egg-rr99.7%
Taylor expanded in z around 0 91.9%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-5) (not (<= y 8200000000.0))) (* z (sin y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-5) || !(y <= 8200000000.0)) {
tmp = z * sin(y);
} else {
tmp = x + (y * z);
}
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 <= (-5.8d-5)) .or. (.not. (y <= 8200000000.0d0))) then
tmp = z * sin(y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-5) || !(y <= 8200000000.0)) {
tmp = z * Math.sin(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-5) or not (y <= 8200000000.0): tmp = z * math.sin(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-5) || !(y <= 8200000000.0)) tmp = Float64(z * sin(y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.8e-5) || ~((y <= 8200000000.0))) tmp = z * sin(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-5], N[Not[LessEqual[y, 8200000000.0]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-5} \lor \neg \left(y \leq 8200000000\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -5.8e-5 or 8.2e9 < y Initial program 99.7%
Taylor expanded in x around 0 58.2%
if -5.8e-5 < y < 8.2e9Initial program 100.0%
Taylor expanded in y around 0 98.7%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (<= z 1.96e+59) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.96e+59) {
tmp = x;
} else {
tmp = y * z;
}
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.96d+59) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.96e+59) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.96e+59: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.96e+59) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.96e+59) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.96e+59], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.96 \cdot 10^{+59}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 1.96000000000000007e59Initial program 99.9%
+-commutative99.9%
add-cube-cbrt99.3%
associate-*r*99.3%
fma-def99.3%
pow299.3%
Applied egg-rr99.3%
Taylor expanded in y around 0 51.0%
if 1.96000000000000007e59 < z Initial program 99.8%
+-commutative99.8%
add-cube-cbrt98.6%
associate-*r*98.5%
fma-def98.5%
pow298.5%
Applied egg-rr98.5%
Taylor expanded in z around inf 79.1%
pow-base-179.1%
*-lft-identity79.1%
*-commutative79.1%
Simplified79.1%
Taylor expanded in y around 0 38.2%
*-commutative38.2%
Simplified38.2%
Final simplification48.6%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (y * z);
}
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 * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 56.6%
Final simplification56.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
+-commutative99.8%
add-cube-cbrt99.2%
associate-*r*99.2%
fma-def99.2%
pow299.2%
Applied egg-rr99.2%
Taylor expanded in y around 0 44.6%
Final simplification44.6%
herbie shell --seed 2023224
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))