
(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}
\\
\left(x + \sin y\right) + 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (+ x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x + 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 = (z * cos(y)) + (x + sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x + Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x + math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x + sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x + sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + \left(x + \sin y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (or (<= x -2e-32) (not (<= x 1.5e-89))) (+ x t_0) (+ (sin y) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if ((x <= -2e-32) || !(x <= 1.5e-89)) {
tmp = x + t_0;
} else {
tmp = sin(y) + 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 ((x <= (-2d-32)) .or. (.not. (x <= 1.5d-89))) then
tmp = x + t_0
else
tmp = sin(y) + 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 ((x <= -2e-32) || !(x <= 1.5e-89)) {
tmp = x + t_0;
} else {
tmp = Math.sin(y) + t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if (x <= -2e-32) or not (x <= 1.5e-89): tmp = x + t_0 else: tmp = math.sin(y) + t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if ((x <= -2e-32) || !(x <= 1.5e-89)) tmp = Float64(x + t_0); else tmp = Float64(sin(y) + t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if ((x <= -2e-32) || ~((x <= 1.5e-89))) tmp = x + t_0; else tmp = sin(y) + t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[x, -2e-32], N[Not[LessEqual[x, 1.5e-89]], $MachinePrecision]], N[(x + t$95$0), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;x \leq -2 \cdot 10^{-32} \lor \neg \left(x \leq 1.5 \cdot 10^{-89}\right):\\
\;\;\;\;x + t_0\\
\mathbf{else}:\\
\;\;\;\;\sin y + t_0\\
\end{array}
\end{array}
if x < -2.00000000000000011e-32 or 1.5e-89 < x Initial program 99.9%
Taylor expanded in x around inf 98.8%
if -2.00000000000000011e-32 < x < 1.5e-89Initial program 99.8%
Taylor expanded in x around 0 98.1%
Final simplification98.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.45e+95)
t_0
(if (<= z -4.6e+52)
(+ x z)
(if (<= z -600000000.0)
t_0
(if (<= z 3.6e-13)
(+ x (sin y))
(if (<= z 1.05e+134) (+ x z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.45e+95) {
tmp = t_0;
} else if (z <= -4.6e+52) {
tmp = x + z;
} else if (z <= -600000000.0) {
tmp = t_0;
} else if (z <= 3.6e-13) {
tmp = x + sin(y);
} else if (z <= 1.05e+134) {
tmp = x + z;
} 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 <= (-2.45d+95)) then
tmp = t_0
else if (z <= (-4.6d+52)) then
tmp = x + z
else if (z <= (-600000000.0d0)) then
tmp = t_0
else if (z <= 3.6d-13) then
tmp = x + sin(y)
else if (z <= 1.05d+134) then
tmp = x + z
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 <= -2.45e+95) {
tmp = t_0;
} else if (z <= -4.6e+52) {
tmp = x + z;
} else if (z <= -600000000.0) {
tmp = t_0;
} else if (z <= 3.6e-13) {
tmp = x + Math.sin(y);
} else if (z <= 1.05e+134) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -2.45e+95: tmp = t_0 elif z <= -4.6e+52: tmp = x + z elif z <= -600000000.0: tmp = t_0 elif z <= 3.6e-13: tmp = x + math.sin(y) elif z <= 1.05e+134: tmp = x + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.45e+95) tmp = t_0; elseif (z <= -4.6e+52) tmp = Float64(x + z); elseif (z <= -600000000.0) tmp = t_0; elseif (z <= 3.6e-13) tmp = Float64(x + sin(y)); elseif (z <= 1.05e+134) tmp = Float64(x + z); 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 <= -2.45e+95) tmp = t_0; elseif (z <= -4.6e+52) tmp = x + z; elseif (z <= -600000000.0) tmp = t_0; elseif (z <= 3.6e-13) tmp = x + sin(y); elseif (z <= 1.05e+134) tmp = x + z; 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, -2.45e+95], t$95$0, If[LessEqual[z, -4.6e+52], N[(x + z), $MachinePrecision], If[LessEqual[z, -600000000.0], t$95$0, If[LessEqual[z, 3.6e-13], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.05e+134], N[(x + z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.45 \cdot 10^{+95}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{+52}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -600000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-13}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+134}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.4499999999999999e95 or -4.6e52 < z < -6e8 or 1.05e134 < z Initial program 99.9%
Taylor expanded in z around inf 81.9%
if -2.4499999999999999e95 < z < -4.6e52 or 3.5999999999999998e-13 < z < 1.05e134Initial program 99.8%
Taylor expanded in y around 0 77.6%
+-commutative77.6%
Simplified77.6%
if -6e8 < z < 3.5999999999999998e-13Initial program 100.0%
Taylor expanded in z around 0 93.6%
+-commutative93.6%
Simplified93.6%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.4) (not (<= z 6.6e-73))) (+ x (* z (cos y))) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4) || !(z <= 6.6e-73)) {
tmp = x + (z * cos(y));
} else {
tmp = 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.4d0)) .or. (.not. (z <= 6.6d-73))) then
tmp = x + (z * cos(y))
else
tmp = x + sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4) || !(z <= 6.6e-73)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.4) or not (z <= 6.6e-73): tmp = x + (z * math.cos(y)) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.4) || !(z <= 6.6e-73)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.4) || ~((z <= 6.6e-73))) tmp = x + (z * cos(y)); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.4], N[Not[LessEqual[z, 6.6e-73]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \lor \neg \left(z \leq 6.6 \cdot 10^{-73}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -3.39999999999999991 or 6.60000000000000007e-73 < z Initial program 99.8%
Taylor expanded in x around inf 98.1%
if -3.39999999999999991 < z < 6.60000000000000007e-73Initial program 100.0%
Taylor expanded in z around 0 94.6%
+-commutative94.6%
Simplified94.6%
Final simplification96.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e-27) (not (<= x 1.75e-69))) (+ x z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-27) || !(x <= 1.75e-69)) {
tmp = x + z;
} else {
tmp = z * 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 ((x <= (-3.6d-27)) .or. (.not. (x <= 1.75d-69))) then
tmp = x + z
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-27) || !(x <= 1.75e-69)) {
tmp = x + z;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e-27) or not (x <= 1.75e-69): tmp = x + z else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e-27) || !(x <= 1.75e-69)) tmp = Float64(x + z); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e-27) || ~((x <= 1.75e-69))) tmp = x + z; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e-27], N[Not[LessEqual[x, 1.75e-69]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-27} \lor \neg \left(x \leq 1.75 \cdot 10^{-69}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -3.5999999999999999e-27 or 1.7500000000000001e-69 < x Initial program 99.9%
Taylor expanded in y around 0 88.4%
+-commutative88.4%
Simplified88.4%
if -3.5999999999999999e-27 < x < 1.7500000000000001e-69Initial program 99.8%
Taylor expanded in z around inf 68.5%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 69.4%
+-commutative69.4%
Simplified69.4%
Final simplification69.4%
(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.9%
+-commutative99.9%
*-commutative99.9%
add-cube-cbrt99.7%
associate-*l*99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 49.5%
Final simplification49.5%
herbie shell --seed 2023314
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))