
(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 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}
\\
\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 (if (<= x -2.6e+33) (+ x z) (if (<= x 5e+32) (+ (sin y) (* z (cos y))) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e+33) {
tmp = x + z;
} else if (x <= 5e+32) {
tmp = sin(y) + (z * cos(y));
} else {
tmp = x + 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 (x <= (-2.6d+33)) then
tmp = x + z
else if (x <= 5d+32) then
tmp = sin(y) + (z * cos(y))
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.6e+33) {
tmp = x + z;
} else if (x <= 5e+32) {
tmp = Math.sin(y) + (z * Math.cos(y));
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.6e+33: tmp = x + z elif x <= 5e+32: tmp = math.sin(y) + (z * math.cos(y)) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.6e+33) tmp = Float64(x + z); elseif (x <= 5e+32) tmp = Float64(sin(y) + Float64(z * cos(y))); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.6e+33) tmp = x + z; elseif (x <= 5e+32) tmp = sin(y) + (z * cos(y)); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.6e+33], N[(x + z), $MachinePrecision], If[LessEqual[x, 5e+32], N[(N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+33}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+32}:\\
\;\;\;\;\sin y + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -2.5999999999999997e33 or 4.9999999999999997e32 < x Initial program 100.0%
Taylor expanded in y around 0 88.7%
+-commutative88.7%
Simplified88.7%
if -2.5999999999999997e33 < x < 4.9999999999999997e32Initial program 99.9%
Taylor expanded in x around 0 92.5%
Final simplification90.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -5.8e+63)
t_0
(if (<= z 5e-222)
(+ z (+ x y))
(if (<= z 2.15e-193) (sin y) (if (<= z 3.3e+56) (+ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -5.8e+63) {
tmp = t_0;
} else if (z <= 5e-222) {
tmp = z + (x + y);
} else if (z <= 2.15e-193) {
tmp = sin(y);
} else if (z <= 3.3e+56) {
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 <= (-5.8d+63)) then
tmp = t_0
else if (z <= 5d-222) then
tmp = z + (x + y)
else if (z <= 2.15d-193) then
tmp = sin(y)
else if (z <= 3.3d+56) 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 <= -5.8e+63) {
tmp = t_0;
} else if (z <= 5e-222) {
tmp = z + (x + y);
} else if (z <= 2.15e-193) {
tmp = Math.sin(y);
} else if (z <= 3.3e+56) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -5.8e+63: tmp = t_0 elif z <= 5e-222: tmp = z + (x + y) elif z <= 2.15e-193: tmp = math.sin(y) elif z <= 3.3e+56: 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 <= -5.8e+63) tmp = t_0; elseif (z <= 5e-222) tmp = Float64(z + Float64(x + y)); elseif (z <= 2.15e-193) tmp = sin(y); elseif (z <= 3.3e+56) 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 <= -5.8e+63) tmp = t_0; elseif (z <= 5e-222) tmp = z + (x + y); elseif (z <= 2.15e-193) tmp = sin(y); elseif (z <= 3.3e+56) 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, -5.8e+63], t$95$0, If[LessEqual[z, 5e-222], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.15e-193], N[Sin[y], $MachinePrecision], If[LessEqual[z, 3.3e+56], N[(x + z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5 \cdot 10^{-222}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{-193}:\\
\;\;\;\;\sin y\\
\mathbf{elif}\;z \leq 3.3 \cdot 10^{+56}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -5.7999999999999999e63 or 3.30000000000000002e56 < z Initial program 99.9%
Taylor expanded in z around inf 85.9%
if -5.7999999999999999e63 < z < 5.00000000000000008e-222Initial program 100.0%
Taylor expanded in y around 0 63.0%
+-commutative63.0%
+-commutative63.0%
associate-+l+63.0%
Simplified63.0%
if 5.00000000000000008e-222 < z < 2.1500000000000001e-193Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around 0 100.0%
if 2.1500000000000001e-193 < z < 3.30000000000000002e56Initial program 100.0%
Taylor expanded in y around 0 79.4%
+-commutative79.4%
Simplified79.4%
Final simplification76.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -1000000000.0)
t_0
(if (<= z 1.32e-20) (+ x (sin y)) (if (<= z 3e+56) (+ x z) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -1000000000.0) {
tmp = t_0;
} else if (z <= 1.32e-20) {
tmp = x + sin(y);
} else if (z <= 3e+56) {
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 <= (-1000000000.0d0)) then
tmp = t_0
else if (z <= 1.32d-20) then
tmp = x + sin(y)
else if (z <= 3d+56) 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 <= -1000000000.0) {
tmp = t_0;
} else if (z <= 1.32e-20) {
tmp = x + Math.sin(y);
} else if (z <= 3e+56) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -1000000000.0: tmp = t_0 elif z <= 1.32e-20: tmp = x + math.sin(y) elif z <= 3e+56: 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 <= -1000000000.0) tmp = t_0; elseif (z <= 1.32e-20) tmp = Float64(x + sin(y)); elseif (z <= 3e+56) 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 <= -1000000000.0) tmp = t_0; elseif (z <= 1.32e-20) tmp = x + sin(y); elseif (z <= 3e+56) 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, -1000000000.0], t$95$0, If[LessEqual[z, 1.32e-20], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3e+56], N[(x + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -1000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.32 \cdot 10^{-20}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 3 \cdot 10^{+56}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -1e9 or 3.00000000000000006e56 < z Initial program 99.9%
Taylor expanded in z around inf 83.4%
if -1e9 < z < 1.32000000000000004e-20Initial program 100.0%
Taylor expanded in z around 0 94.9%
+-commutative94.9%
Simplified94.9%
if 1.32000000000000004e-20 < z < 3.00000000000000006e56Initial program 100.0%
Taylor expanded in y around 0 83.7%
+-commutative83.7%
Simplified83.7%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (if (<= x -3.4e-98) (+ x z) (if (<= x 0.9) (+ z (+ x y)) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.4e-98) {
tmp = x + z;
} else if (x <= 0.9) {
tmp = z + (x + y);
} else {
tmp = x + 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 (x <= (-3.4d-98)) then
tmp = x + z
else if (x <= 0.9d0) then
tmp = z + (x + y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.4e-98) {
tmp = x + z;
} else if (x <= 0.9) {
tmp = z + (x + y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.4e-98: tmp = x + z elif x <= 0.9: tmp = z + (x + y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.4e-98) tmp = Float64(x + z); elseif (x <= 0.9) tmp = Float64(z + Float64(x + y)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.4e-98) tmp = x + z; elseif (x <= 0.9) tmp = z + (x + y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.4e-98], N[(x + z), $MachinePrecision], If[LessEqual[x, 0.9], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-98}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;x \leq 0.9:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if x < -3.4000000000000001e-98 or 0.900000000000000022 < x Initial program 100.0%
Taylor expanded in y around 0 80.4%
+-commutative80.4%
Simplified80.4%
if -3.4000000000000001e-98 < x < 0.900000000000000022Initial program 99.9%
Taylor expanded in y around 0 51.8%
+-commutative51.8%
+-commutative51.8%
associate-+l+51.8%
Simplified51.8%
Final simplification67.6%
(FPCore (x y z) :precision binary64 (if (<= x -3.75e-90) x (if (<= x 7e-70) y x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.75e-90) {
tmp = x;
} else if (x <= 7e-70) {
tmp = y;
} else {
tmp = 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 (x <= (-3.75d-90)) then
tmp = x
else if (x <= 7d-70) then
tmp = y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.75e-90) {
tmp = x;
} else if (x <= 7e-70) {
tmp = y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.75e-90: tmp = x elif x <= 7e-70: tmp = y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.75e-90) tmp = x; elseif (x <= 7e-70) tmp = y; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.75e-90) tmp = x; elseif (x <= 7e-70) tmp = y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.75e-90], x, If[LessEqual[x, 7e-70], y, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.75 \cdot 10^{-90}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-70}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -3.7499999999999999e-90 or 6.99999999999999949e-70 < x Initial program 100.0%
Taylor expanded in x around inf 61.6%
if -3.7499999999999999e-90 < x < 6.99999999999999949e-70Initial program 99.9%
Taylor expanded in y around 0 50.1%
+-commutative50.1%
+-commutative50.1%
associate-+l+50.1%
Simplified50.1%
Taylor expanded in y around inf 16.7%
Final simplification43.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.5e+33) x (if (<= x 1.25e+23) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+33) {
tmp = x;
} else if (x <= 1.25e+23) {
tmp = z;
} else {
tmp = 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 (x <= (-1.5d+33)) then
tmp = x
else if (x <= 1.25d+23) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+33) {
tmp = x;
} else if (x <= 1.25e+23) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.5e+33: tmp = x elif x <= 1.25e+23: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.5e+33) tmp = x; elseif (x <= 1.25e+23) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.5e+33) tmp = x; elseif (x <= 1.25e+23) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.5e+33], x, If[LessEqual[x, 1.25e+23], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+33}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+23}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.49999999999999992e33 or 1.25e23 < x Initial program 99.9%
Taylor expanded in x around inf 77.4%
if -1.49999999999999992e33 < x < 1.25e23Initial program 99.9%
Taylor expanded in z around inf 61.9%
Taylor expanded in y around 0 37.7%
Final simplification54.8%
(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 62.1%
+-commutative62.1%
Simplified62.1%
Final simplification62.1%
(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%
Taylor expanded in x around inf 38.1%
Final simplification38.1%
herbie shell --seed 2023290
(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))))